Support » Fixing WordPress » Virus Appending Base64 Code to All PHP files

  • I just finished cleaning up two separate installations of WordPress (on two different servers) which had been infected with some malicious code. This is simply to spread the word so that others experiencing the problem know what to do.

    The most obvious symptom of this infection was that, upon logging in to the Admin section, the Dashboard page would load completely and then suddenly go blank. If your browser status bar is visible, you should see the site contacting your domain (as it normally would) then, after the page has loaded, it will state “resolving host” before giving you the blank, white page.

    The fix was actually fairly simple. In WP Admin, navigate to the editor. Go one by one through the PHP files listed on the right, removing the string of base64 code which has been appended at the very top of each file. Once you have cleaned out the malicious code from each file, you will also need to do the same for your wp-config.php file.

    That should do it. When you’ve removed all of the offending bits of code, you should be able to load your Dashboard normally.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Forgot to add: perform the same check on all of your plugins by going to Plugins –> Editor

    In one installation, the plugins had the same code appended in the first line of the *.php plugin files.

    Some kind of same problem is with me .Please help me out :

    I’ve been infected as well. Thanks for the removal tips. I changed all the php files, but that hasn’t stopped the dashboard page from going blank. any ideas?

    Nevermind, I forgot that some plugins have multiple php files, and hadn’t removed the code from all of those files. now everything is fixed. thanks ourstereo.

    This won’t fix the issue… will just make WP look like it is working again.

    If your plugins and theme are affected, all WP files are probably infected. Check em out. You may need to reinstall. Also, when you reinstall, wp-config.php doesn’t get fixed. Delete the offending code in there manually.

    Also, do you have anything else on your server? Look around….that may be affected too.

    Now that you’ve cleaned up your php files…how will you make sure this doesn’t happen again? If you don’t find the root of the problem…it WILL happen again

    The most effective means to isolate infected files would be to download the folders and files from the site, extract a fresh WP download to another folder, then do a diff between the 2 folders (difference comparison).
    Is one of many tools that can do comparison/diff checks on files/folders.

    Been ages since i used an app for that, but i’d say that’s the easiest way to see where a possible point of entry is (if not it’ll help you track down infected files at least) … if you just find minor code additions, but nothing that looks like an exploit, then the vunerability could perhaps be on the server(or with permissions) and not in WP.. in which case no amount of cleaning or replacing files will help, because the hacker will be back exploiting the same vunerability again..

    I think the most important aspect of resolving your problem(s) is to first isolate where and what caused the exploit in the first place, be it the server, wp, permissions or shoddy host setup..

    Have you checked the access logs and/or error logs to see if they hold any interesting or key pieces of information.

    If you’re on a shared host, it may be another site on that same box(server) acting as a point of entry (something to consider)..


    Best of luck to you guys with hacked blogs in any case.

    Yeah I just had this too. Weird.

    For my particular case, the hack was appending a simple line to all PHP files.

    Since the pattern was easy to recognize and sniff (and unique enough that I was able to zap it without doing damage to my other files), I used find and sed to delete that line from all files
    find . -name "*.php" -type f -exec sed -i '/eval(base64_decode(/d' {} \;

    PLEASE BACK UP YOUR FILES before you use this command, it WILL modify all your PHP files.

    In some cases like mine, where the sites I’m cleaning could have been recreated without too much hassle, and the db is backed up elsewhere, this method may be useful to others, so I’m dropping it in here.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Virus Appending Base64 Code to All PHP files’ is closed to new replies.