Security
eval(base64_decode) in WordPress: Read It Safely, Then Prove the Damage
If you've found eval base64_decode code, written as eval(base64_decode(, at the top of a PHP file on your WordPress site, it's almost certainly malware, and the file was tampered with. The longer answer is how to read what it does without accidentally running it, and how to prove which other files were changed, instead of guessing.
That's this post. First, what the code means in plain English. Then a safe way to decode it. Then the part that actually speeds up a cleanup: using official checksums to separate tampered files from clean ones.
If you'd rather someone else handle the PHP, you can send me the file path and what you're seeing. I reply with a plan and a fixed quote within one business day.
What eval base64_decode actually means
Two PHP functions, stacked:
base64_decodeturns base64 text back into its original form. Base64 is a way to write any data using only letters, numbers and a few symbols. It's a normal PHP function, and plenty of legitimate plugins use it for things like images or API data.evalruns a string of text as PHP code. The PHP manual itself is unusually blunt about it: eval "is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged."
Put them together and you get "unscramble this hidden text, then run it as code." The scrambling exists for one reason: so neither you nor a quick scan can read what the code does. Legitimate modern plugins have little reason to do that.
You'll often see the pair with friends. Google's guide to the cloaked keywords hack lists the usual crew: base64_decode, rot13, eval, strrev and gzinflate. They're layered, like an onion. One more trick: 46esab is "base64" spelled backwards, used with strrev to dodge simple searches.
How to find base64 malware in WordPress
Search the whole site for the patterns. From the WordPress folder, over SSH (a secure command-line connection to your server):
# Read-only: list PHP files that decode and run hidden code in one step.
# Expect a few false positives in big plugins. Every hit deserves a look, not an automatic delete.
grep -rlE --include='*.php' 'eval\s*\(\s*(base64_decode|gzinflate|gzuncompress|str_rot13|strrev)\s*\(' .
# Read-only: the "spelled backwards" trick.
grep -rl --include='*.php' '46esab' .Don't forget the places a file search skips:
- The database. Injected scripts often live in posts, widgets or options.
wp db search(WordPress's command-line tool, WP-CLI) finds strings in the database without changing anything:
# Read-only: search every WordPress table for script tags and eval calls.
wp db search '<script' --all-tables-with-prefix --stats
wp db search 'eval(' --all-tables-with-prefix --statswp-content/uploads. That folder should hold images and PDFs. A.phpfile there is a red flag on its own, whatever is inside it.
Read the code without running it
Here's the rule that keeps you safe: decode, never execute. You want to print the hidden text, not run it.
Two habits people pick up from forums are worth breaking:
- Don't replace
evalwithechoinside the infected file and load the page. It sounds clever, but you're still loading attacker code in a live site, and a later layer may have its owneval. - Don't paste it into a random online decoder. The blob can contain your database password or other site details. Keep it on your machine.
Instead, work on a copy, outside your website folder.
- Copy the infected file somewhere private, like your home folder, not inside
public_html. - Pull out just the encoded string, the long run of letters and numbers between the quotes, and save it as
blob.txt. No<?php, noeval. - Decode it into a text file:
# Safe: turns base64 text back into plain text and writes it to a file. Nothing is executed.
base64 -d blob.txt > layer1.txt
file layer1.txt
less layer1.txt- If the result is binary gibberish, there's usually a compression layer (
gzinflate). PHP can unwrap it and print the result:
# Safe: "echo" prints the decoded text. There is no eval here, so nothing runs.
# Could break: nothing on the site. Run it on your copy, never in the web root.
php -r 'echo gzinflate(base64_decode(file_get_contents("blob.txt")));' > layer2.txt- Repeat until you see readable PHP. Malware often has three or four layers.
What you're likely to find inside
The decoded code usually does one of a handful of things:
- A backdoor: code that runs whatever the attacker sends in a web request, often through
$_POSTor a cookie. - A redirect: code that sends phone visitors or Google visitors to a spam or scam site.
- A spam generator: code that builds fake pages for search engines, the engine behind the Japanese keyword hack.
- A mailer: code that turns your server into a spam sender.
Write down any domains, file names or other paths you see. They point to the next file to check.
Prove what was tampered with: checksums
Decoding one file tells you what one file does. It doesn't tell you what else was changed. And attackers often set file dates back so a "recently modified" search walks right past their work.
Checksums (digital fingerprints of the official files) solve that. WP-CLI can compare your files against WordPress.org's copies.
# Read-only: compare every WordPress core file with the official fingerprints.
# --include-root also warns about unexpected files sitting in the main folder.
wp core verify-checksums --include-root
# Read-only: compare every wordpress.org plugin with its official fingerprints.
wp plugin verify-checksums --allWhat the output means, per the core and plugin docs:
- "File doesn't verify against checksum" means the file was changed. In a core file, that's never normal.
- A warning about a file that shouldn't exist in the root means something was added, which is often the dropper (the file that installed the rest).
- Success means those files match the official copies. That's real proof, not a scanner's opinion.
Two blind spots to know about. Premium plugins and themes aren't on WordPress.org, so they can't be checked this way. For those, download a fresh copy from the vendor and compare folders with diff -rq. And checksums don't cover the database or wp-content/uploads, which is why the searches above matter.
Clean it: replace, don't edit
Once you know which files were tampered with, don't hand-edit the bad lines out. Replace the files with known-good copies.
# Replaces WordPress core files with fresh official copies. Leaves wp-content and wp-config.php alone.
# Could break: nothing in your content, but take a full backup first. Then update to the latest version.
wp core download --version=$(wp core version) --force --skip-contentThe --force flag overwrites existing files, and --skip-content leaves out the default themes and plugins, per the download docs. For plugins, reinstall from the official source. Then run the checksums again. They should come back clean.
Don't stop there, though. The eval line was a symptom. Whatever planted it, whether a hidden admin, a must-use plugin or a cron job, may still be there. If you got your theme from a "free premium" download site, my post on what's hiding inside nulled WordPress themes shows how those backdoors survive deletion. And the hosting-account checks for malware that keeps coming back cover the rest. The full order, files to Google, is in my start-to-finish WordPress hack recovery guide.
Vlad's take
The most useful thing in this post isn't the decoding. It's the checksums. Decoding scratches the curiosity itch, and sometimes it tells you how they got in. But checksums turn "I think it's clean" into "these files match the official copies." When a client asks me how I know a site is clean, that's my answer.
Final thoughts
eval(base64_decode( means hidden code is being run, and in a WordPress file that's almost always malware. Find every instance, decode copies safely outside the web root, then let checksums tell you which files were tampered with. Replace those with official copies, and go looking for whatever planted them.
If you'd rather have it handled, my malware cleanup for hacked WordPress sites does exactly this, plus the Google side. The questionnaire is short whenever you're ready. Standard cleanups start at $350, and they include the backdoor hunt as well as the obvious file.
eval base64_decode FAQs
Is base64_decode always malware?
No. base64_decode is a normal PHP function, and many legitimate plugins use it for images, API responses or stored settings. The red flag is the combination with eval, which runs the decoded text as code, especially when it's wrapped in extra layers like gzinflate or str_rot13. A plain base64_decode in a well-known plugin is usually fine. Check it against an official copy to be sure.
Is it safe to decode base64 malware?
Decoding is safe as long as you only print the result and never execute it. Copy the encoded string to a text file outside your website folder, decode it with base64 -d, and read the output. Avoid swapping eval for echo inside the infected file on a live site, and skip online decoders, since the blob can contain your site's details.
Where does eval base64_decode malware usually hide in WordPress?
Common spots are the top of index.php, wp-config.php and theme functions.php files, inside plugin files, in PHP files placed in wp-content/uploads, and in the must-use plugins folder. It can also sit in the database inside posts, widgets or options. File checksums catch tampered core and wordpress.org plugin files, and wp db search covers the database.
Will deleting the eval line fix my site?
Usually not. The line is a symptom. Something put it there, often a backdoor, a hidden admin account or a scheduled task, and that may re-add it within hours. Replace tampered files with official copies, then check users, must-use plugins, cron jobs and the rest of the hosting account. Change every password afterward, including the database password.
Want a second pair of eyes on your site?
Tell me what's going on in the hacked website repair questionnaire. I reply with a plan and a fixed quote within one business day.