Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. $i = $j = $k = 0;
  4. $ccontent = file_get_contents('./yoyo.txt'); // this file contains the malware code, see: http://pastebin.com/M57UWwzD
  5.  
  6. function scanAndRemove($dir)
  7. {
  8.     global $ccontent, $i, $j, $k;
  9.  
  10.     if (!is_readable($dir))
  11.     {
  12.         return;
  13.     }
  14.  
  15.     foreach(scandir($dir) as $file)
  16.     {
  17.         if(in_array($file, array('.', '..')))
  18.         {
  19.             continue;
  20.         }
  21.  
  22.         $path = $dir . DIRECTORY_SEPARATOR . $file;
  23.  
  24.         if (is_dir($path))
  25.         {
  26.             scanAndRemove($path);
  27.         }
  28.         else
  29.         {
  30.             $k++;
  31.             if (substr($file, -4) == '.php')
  32.             {
  33.                 $j++;
  34.                 $source = file_get_contents($path);
  35.                 $source = str_replace($ccontent, '', $source, $count);
  36.  
  37.                 if($count)
  38.                 {
  39.                     $i++;
  40.                     //echo $path . PHP_EOL;
  41.                     file_put_contents($path, $source);
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
  47.  
  48. scanAndRemove('/home/{username}');
  49.  
  50. echo 'Total files: ' . $k . PHP_EOL;
  51. echo 'Total PHP files: ' . $j . PHP_EOL;
  52. echo 'Total infected files: ' . $i;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement