Remove Malicious code from Wordpress or Joomla

Hacking of sites is not a new phenomenon. Every day thousands of sites get hacked and serve as vehicles for hackers to carry forward with their vicious plans. Out of these most of the hacks are executed by bots that crawl the internet to find websites/servers with exploits and vulnerabilities and harness them to inject malicious code or functionality into the site. Prime purpose for this is Black Hat SEO or get traffic but some do it just for fun.

Recently some of my older sites that were built on Joomla (never use Joomla) were hacked where the hacker injected a piece of code into ever single php file of the application recursively. In this case manual cleaning and removal of code would amount to insane about of work and also is not feasible. I searched through the net and have found a nice php script that does the finding and removing very efficiently. It is a good quick start to recovery and gets rid of the malicious code very effectively. Following is the code that you can use.

Just create a new php file on your server and paste this code in it. Change the ‘Malicious Code’ to the actual malicious code and execute the script.

Disclaimer: This script worked for me and might also work in most of the cases. Even then I would recommend that you take a backup of everything before executing. I shall not be liable or responsible for any damage or loss of data due to using this script.

"; $clean_source = str_replace($find,'',$filesource); file_put_contents($path.'/'.$file,$clean_source); } }else{ continue; } } } } closedir($handle); } $return = ob_get_contents(); ob_end_clean(); return $return; } ?>

Published: December 11 2012

blog comments powered by Disqus