WordPress Exploit Scanner 0.1

My previous post about hacked WordPress sites caused Donnacha to ask,

After your last post on this subject, I was thinking that it would be a good idea for Automattic to create a plugin that carries out all the checks you suggested people do to find out if they’ve been hacked…

At the time I wasn’t too optimistic about it but after thinking about the idea for a few days I came up with the WordPress Exploit Scanner which does most of what Donnacha wanted.

This WordPress plugin searches the files on your site for a few known strings sometimes used by hackers, and lists them with code fragments taken from the files. It also makes a few checks of the database, looking at the active_plugins blog option, the comments table, and the posts table.
It also allows the blog owner to search for whatever string they like which could come in handy when new exploit code is used in a hack.

You must be running WordPress 2.5.1 or higher to use this plugin. There’s not much point in finding exploited files if you’re running an old version of the software that can be broken into again.

Download the plugin from here: WordPress Exploit Scanner

Thanks to those who tested the plugin, especially Cathal Garvey who provided some great feedback!


You might also like

If you like this post then please subscribe to my full RSS feed. You can also click here to subscribe by email. There are also my fabulous photos to explore too!

Published by

Donncha

Donncha Ó Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Google+ and Twitter.

79 thoughts on “WordPress Exploit Scanner 0.1”


  1. This generic principle could be taken a step further to scan for things like obfuscated code in themes and such. Might be worth considering.

    Looking for base_64_decode would come up with most of the current malware themes out there, for example. I would not extend that to plugins, because many legit plugins use this methodology to store images in the PHP file (Google XML sitemap generator, to pick an example). But a theme generally doesn’t have the complexity level to contain that sort of thing legitimately.


  2. Otto – Among the strings included is the base64 string of (one of?) the url used in the recent Google redirect hack.

    I hadn’t thought to search for base_64_decode but it’s an obvious one I’ll add for the next release!


  3. I use wordpress blogs a lot – and I’ve had some of them hacked.

    The greatest pain is having dozens of wp sites to upgrade – then next week have to upgrade all my sites again because of another and another security patch.

    Thanks for the great plugin – we all need this.

    Doug


  4. Hi, Donncha

    I keep getting the following error-message when doing the files only or files+database search:

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8662604 bytes) in /home/***/public_html/wp-content/plugins/exploit-scanner/exploit-scanner.php on line 82

    The database only search is fine.

    Any ideas?


  5. Regarding the “no much point finding exploits on older versions”… i disagree. There´s several people that have a working install with previous versions, that feature unsupported plugins making it hard to upgrade or just don´t have the skills to migrate to a newer version (it´s not “that” easy, specially for 2.0.x) or an´t afford a specialist. IMHO, if a plugin for older versions is available, it could even encourage people to think about upgrading after seeing all the flaws on their install. But leaving 2.0.x, 2.1.x, 2.2.x and 2.3.x users all by themselves is kinda harsh :) (specially if 2.0.x branch is supposed to be supported for several years, as i read on a blog post when 2.1 came out)


  6. I know you say “Don’t worry if ‘/var/www/html/sandpit/wp-content/plugins/exploit-scanner/exploit-scanner.php’ is listed above. That’s a good sign because this script obviously has all the text to search for and it’s working properly!” at the end, but it is a bit weird (and frightening at first) to have it list itself!

  7. Pingback: Gehackt!

  8. Downloaded, uploaded, plugged it in and it works great.

    I am so glad this plug-in was put together. Thank you.

    BigDadGib


  9. BTW…

    I HAVE been hacked. It was worse than having my house robbed. I felt horrible, violated and angry. That’s why I am so happy for this plug-in.

    Thanks again…
    BigDadGib


  10. I’m impressed! This is a great little security utility, and will help me to check out some of the older blogs I’ve set up for people but haven’t had the time to keep under supervision as much as I’d like.

    But as in all these things, the devil is in the detail. I’m running WP 2.6 B1 on my flagship blog, and of course (as warned) there are lots of hits that certainly aren’t mallicious code. What would be really useful would be a list of possible false positives, and a compilation of known nasties so that those of us who aren’t techies can either try to fix things ourselves, or call in someone who can help.

    Thanks for such a useful tool!


  11. Donncha, thank you so much, it is great to see you respond with such alacrity. This plugin will be indispensable, especially for users unable to use AIDE.

    Between this, and the upcoming security improvements in 2.6, we are getting closer to point at which hackers targeting WordPress will have nowhere left to hide.


  12. This plugin rocks, WP 2.3 version was a spammers delight and many of the residues from that version can be found in files despite upgrades. Especially if the old files/folders were overwritten and not completely removed prior to the upgrade. Thanks.


  13. I keep getting this error message.
    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 22700609 bytes)


  14. Same fatal error for me: “Allowed memory size ..” for the file check, db-check works fine.


  15. Kirby – the out of memory is caused by the recursive function that iterates over the filesystem. I’ll have to try and make that less memory intensive!


  16. Cool plugin, however your statement “You must be running WordPress 2.5.1 or higher to use this plugin. There’s not much point in finding exploited files if you’re running an old version of the software that can be broken into again” what about the people using the stable and still supported 2.0.11 branch? They shouldn’t be left out of this plugin.


  17. Sean – I had quite forgotten about the stable version distributed in Debian. As I said in an earlier comment, I have checksums for specific files in a specific version (2.5.1).

    I couldn’t maintain multiple versions easily, but I’ll change the die() to a warning.


  18. @Donncha: Maybe someone would be willing to help you maintain a 2.0.x branch of your plugin since it will be supported until 2010?


  19. Sean – all things considered, I could probably do it. The 2.0 version barely changes these days so it wouldn’t be too hard to run an md5 check of the files in it and bundle it with the plugin myself.


  20. When I check just the database it seems to work fine. But if I check the files my Firefox 3 browser starts opening up what seems to be an endless parade of untitled tabs, requiring me to go to the task manager (Win XP)to shut it down. I’m using WP 2.5.1


  21. please vote yes in the new lisbon refernedum for your country in spring
    this will allow the jedi peace to spread throughout europe
    please listen to your minister gormley
    he is a practising member of the church of jedi
    please encourage your family to vote yes or else you will be the cubans of europe
    may the force be with you


  22. Donnacha, Great plugin!! unfortunately I get a Fatal error: Allowed memory size of …….

    Could you give us a quick fix or something? I can’t find anything on line 82

    And may I suggest to add (NOT MALICIOUS CODE) button at your report? of course a (DELETE THIS MALICIOUS CODE) and (BACKUP AND DELETE THIS MALICIOUS CODE) is a very welcome update.

    Thanks for the plugin… great job!


  23. BTW, just a small thing, but for the sake of clarity and because Mocona, above, got the names mixed up, and because there has been some confusion before, I’d better stress that there are too of us with similar names in this thread:

    Donncha O Caoimh – well-known WordPress dude from Cork, owner of Holy Shmoly, begetter of MU, taker of photos, creator of plugins etc

    Donnacha from Dublin, living in Edinburgh, WordPress neophyte and disciple

    … because I definitely wouldn’t want Donncha to get the blame for my dumb-ass questions throughout the blogosphere :)


  24. Hi,
    I’ve just downloaded and installed this plugin, from the link on this page:
    http://ocaoimh.ie/exploit-scanner/

    …and when I look at the dashboard on my blog, it says the MD5 is:
    d41d8cd98f00b204e9800998ecf8427e

    …which doesn’t match the one in the readme or on the link above. I think it should be 6a88a18a37c4add7dabd72fc97be13b6.

    Am I doing something or is something amiss?

    (have tried re-downloading and re-installing)

    Cheers,
    Chris


  25. Chris – that’s weird. Did you edit the file with a Windows editor or some other editor that changes file endings? I just downloaded the plugin again to verify that the md5 is ok and it matches.


  26. I’ve just Googled the MD5 that I posted above and got a few more hits than I was expecting!

    From what I can make out, that’s the MD5 of an empty file – so presumably the MD5 check just isn’t working on my server for whatever reason.


  27. I am getting the following in PSpellShell.php. Does this mean I’ve been hacked? I tried replacing it with the default WordPress one, and I still get this error :

    /wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
    rror(“PSpell support was not found.”);

    $data = shell_exec($cmd);
    @unlink($this->_tmpfile);

    $returnData = array();
    $dataArr = preg_split(“/[\r\n]/”, $data, -1, PREG_SPLIT_NO_EMPTY);

    foreach ($dataArr as $dstr) {
    $matches = array();

    // Skip this line.
    if (strpos($dstr, “@”) ===

    ——————————————————————————–

    throwError(“Error opening tmp file.”);

    $data = shell_exec($cmd);
    @unlink($this->_tmpfile);

    $returnData = array();
    $dataArr = preg_split(“/\n/”, $data, -1, PREG_SPLIT_NO_EMPTY);

    foreach($dataArr as $dstr) {
    $matches = array();

    // Skip this line.
    if (strpos($dstr, “@”) === 0)


  28. Very happy to see this! After my blog was hacked (see here: http://www.raphkoster.com/2008/04/15/more-on-the-blog-hacking/ for the gory details of all the attacks), I wrote a blog post asking for essentially this same plug-in. Here were the things I wished for:

    http://www.raphkoster.com/2008/04/16/what-wordpress-needs/

    * Greps every file in your public web directory, recursively, looking for “base64″ and tells you about them. The default WP install has none of these.
    * Warns you on modification date of any file in the install, plus in any themes.
    * Checks header and footer for unusual size changes.
    * Warns you on any files added to install directories that are not something in the vanilla install — e.g., any new php files in wp-admin that aren’t part of the install.
    * Warns you on any .htaccess redirects.
    * Pulls out the list of administrators by querying in wp_usermeta for wp_metavalue containing %administrator% — not whatever the dashboard uses, which appears to correlate to other tables and therefore misses hacked accounts.
    * Generates a table of everything in wp_options that is not a part of the vanilla WP install, so you can check it. Sure, a whole bunch of plugins will show up, but maybe you can check that manually.


  29. Raph: Not true. wp-app.php as well as a lot of the wp-includes/class-*.php files make use of the base64 functions. You’d have to exclude those from your scans, or at least ignore them.


  30. Donncha: I know that SVN uses the MD5 values internally… If that information was exposed (say, through api.wordpress), then you could get the official MD5 sums from the tags repository and compare against those directly.


  31. Otto – I’ve been thinking about it a bit and it probably wouldn’t be too hard once I had a shell script that I could point at a directory and create a file of md5 checksums.

    Shell script shouldn’t be too hard either I guess, so maybe for the next version I’ll grab the current releases – 2.0.x, 2.5.1, and whatever 2.6 beta is out and make an array of checksums..


  32. I think what is needed is a standalone php script to check your current WordPress core against the official released version (same version).

    All code differences should be highlighted.


  33. Donncha: I’ve been thinking about it, and I see some problems with the MD5 concept. The problem is the CR/LF conversion is going to mess things up for you, with different hosts and such. Also, keeping big lists is a losing proposition. Why not use the MD5 idea to check if any files changed?

    Here’s some sample code I threw together. It basically recursively hashes a directory of files, encrypts all the hashes with a password, and then stores them into a file. It can also read the file, repeat the process, and list any changes made. The reason for the password encryption is that if somebody has access to the file, they can just rehash unless there is something else not on the system itself to protect against that.

    $hashvalue) {
    if ($filehashes[$hashkey] != $hashvalue) {
    echo “$hashkey has changed!\n”;
    }
    }
    }

    store_hashes(‘hashes.txt’,’/path/to/wordpress-2.5.1/’,’password’);

    check_hashes(‘hashes.txt’, ‘/path/to/wordpress-2.5.1/’,’password’);


  34. Thanks for a great security tool. Having had my site and sql database hacked I appreciate this extra level of security. I was able to run the scanner all right for the first time. But now I get the followong message : Warning: file_get_contents(/home/xxx/public_html/xxxxxx/include/l110n.php) [function.file-get-contents]: failed to open stream: Permission denied in /home/xxx/public_html/xxx/wp-content/plugins/exploit-scanner/exploit-scanner.php on line 82

    Any views suggestions appreciated

    Thanx


  35. Hey nice Plugin, some sites from my customers had been cracked, i hope this plugin will help.
    Thanks a lot.


  36. hi all i found this after scaner

    “style=\”visibility:hidden” => “CSS styling to hide parts of a web page”,
    “ShellBOT” => “This may be a script used by hackers to get control of your server.”,
    “uname -a” => “Tells a hacker what operating system your server is running”,
    “shell_exec” => “Executes a server command like ls, cd, wget, etc. This may be a script used by hackers.”,
    “YW55cmVzdWx0cy5uZXQ=” => “Base64 encoded text found in PHP code that redirects visitors from Google.”,
    “” => “HTML code used to hide spammy links, but is also legitimate code.”,
    “eval(unescape” => “Could be Javascript code used to hide code inserted by a hacker.”,
    “String.fromCharCode” => “Javascript code used to hide suspicious code, but can also be legitimate code.”,
    ‘$_COOKIE[“yahg”]’ => “YAHG Googlerank.info exploit code. See here for further info.”

    how can i fix this hacks??
    thanks!!


  37. I’m using version 0.3 and when i’m scanning with the “search files onley” ore “files and database” it redirects me to a russian site “http://gpt0. ru/default .cgi”
    That site seems to be ofline, but do i have a problem???

    “database onley” gives a hoorey :)

    Could you help me?

    THX!


    1. That’s weird, and yes, I’d say you have a problem! If you can login to your server, use “grep” to search through it for that site’s url.


      1. Thx for the tip, but it seems that I can’t use grep on my server. (non linux).

        weird thing is, your scanner works in IE, no bad scrips found. only in firefox the redirection occurs ??? Could FF be the problem?
        Searing for the Russian url gave me a site which probably hosts “free virus scanner software” The one you don’t want…

        THX for your time!


  38. I love this plugin. Since my hosting is on linux, I am very stressed out as I don’t know any antivirus solution for this, at least not one that can work with a shared hosting plan. The wordpress exploit scanner just made my life better especially since most of my sites are wordpress powered.

    I want to suggest that future versions should have external definition files with malware code and maybe even auto-update features.


  39. The AntiVirus plugin does a daily virus scan for wordpress, really helpful. Is there a way to manually scan wordpress for a malware?

Leave a Reply