Guest User

Untitled

a guest
Sep 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. function writeln ($str) {
  4. echo $str . PHP_EOL;
  5. }
  6.  
  7. $GLOBALS['cured'] = 1;
  8.  
  9. function cure($file) {
  10. $re_infected = '\<\?php \/\*\*\/ eval\(base64_decode\("[a-zA-Z0-9\=\/\+]+"\)\);\?\>';
  11. // $re_infected = '"[a-zA-Z0-9\=\/\+]+';
  12. // writeln($re_infected);
  13. $contents = file_get_contents($file);
  14. // writeln($contents);
  15. $GLOBALS['cured'] += preg_match("/$re_infected/ums", $contents);
  16. // print_r($m);
  17. file_put_contents($file . '.bak.php', $contents);
  18. $contents = preg_replace("/{$re_infected}/iums", '', $contents);
  19. file_put_contents($file, $contents);
  20. }
  21.  
  22. $Directory = new RecursiveDirectoryIterator($argv[1]);
  23. $Iterator = new RecursiveIteratorIterator($Directory);
  24. $Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
  25.  
  26. foreach ($Regex as $file) {
  27. cure($file[0]);
  28. writeln($file[0]);
  29. }
  30. writeln("Cured {$GLOBALS['cured']} files");
Add Comment
Please, Sign In to add comment