How to check WordPress files for suspicious PHP code

Search another help topic

If you think your WordPress website has been hacked, you can search its files for code that needs investigation. Functions such as base64_decode, eval, gzinflate and str_rot13 can appear in code used to hide malicious activity.

These names do not prove that a file is malicious. Genuine WordPress files, plugins and themes may also contain them. The key question is whether the code processes legitimate data or executes hidden instructions.

These checks identify files for review. They are not a complete malware scan.

1. Open cPanel Terminal

  1. Follow our guide to open cPanel Terminal.
  2. Confirm your WordPress installation folder.
  3. Run the relevant commands below.

The examples assume WordPress is installed directly in public_html. For an addon domain, check its Document Root in cPanel and replace $HOME/public_html with the correct folder.

The file searches below do not change or execute the files being searched. Do not run suspicious PHP files to see what they do.

2. Search for common suspicious functions

Search PHP files inside wp-content, including its subfolders:

grep -rInEi --include='*.php' -- '(^|[^[:alnum:]_])(base64_decode|eval|gzinflate|str_rot13)[[:space:]]*\(' "$HOME/public_html/wp-content"

This searches for the four names followed by an opening bracket. It allows spaces before the bracket and ignores capitalisation.

Option Purpose
-r Search folders recursively.
-I Skip files detected as binary.
-n Show matching line numbers.
-E Use an extended search pattern.
-i Ignore capitalisation.
--include='*.php' Search files ending in .php.

Search individual names

To search for Base64 decoding:

grep -rInFi --include='*.php' -- 'base64_decode' "$HOME/public_html/wp-content"

To search for eval(:

grep -rInFi --include='*.php' -- 'eval(' "$HOME/public_html/wp-content"

The second example does not match eval ( with a space. Use the combined search above to cover both.

Search the entire website

Malicious code can appear outside wp-content or use another file extension. To search all readable text files in your website folder:

grep -rInEi -- '(^|[^[:alnum:]_])(base64_decode|eval|gzinflate|str_rot13)[[:space:]]*\(' "$HOME/public_html"

For an addon domain stored in example.com inside your account’s home folder:

grep -rInEi -- '(^|[^[:alnum:]_])(base64_decode|eval|gzinflate|str_rot13)[[:space:]]*\(' "$HOME/example.com"

Use the actual document root shown in cPanel.

3. Look for suspicious combinations

Code that decodes or decompresses content and then executes it deserves closer investigation.

Search for some direct combinations:

grep -rInEi --include='*.php' -- '(^|[^[:alnum:]_])eval[[:space:]]*\([[:space:]]*(base64_decode|gzinflate|str_rot13|gzuncompress)[[:space:]]*\(' "$HOME/public_html"

For example, these patterns warrant review:

eval(base64_decode($encoded_payload));
eval(gzinflate(base64_decode($payload)));
eval(str_rot13($payload));

Another serious warning sign is PHP execution using input supplied through a web request:

eval($_POST['code']);

These examples illustrate patterns only. Do not paste them into a PHP file or execute them.

The search checks one line at a time. It can miss code split across lines, indirect function calls and deliberately disguised names.

4. Check other functions in context

Other PHP functions can appear in malicious code, but also have legitimate uses:

Name What to investigate
gzuncompress Decompressed content subsequently executed as code.
shell_exec, system, exec Unexpected commands, particularly those built from web-request input.
file_put_contents Unexpected PHP files being created or existing files overwritten.
strrev, str_rot13 Concealed names or content later used for execution.
assert Legacy code treating strings as executable PHP.
preg_replace Legacy code using the removed /e modifier.

For current PHP versions, old examples need care: string execution through assert() was removed in PHP 8.0, and the /e modifier was removed in PHP 7.0.

Do not classify a file as malware simply because it contains one of these names.

5. Find unexpected or recently changed files

Find PHP-like files in uploads

find "$HOME/public_html/wp-content/uploads" -type f \
  \( -iname '*.php' -o -iname '*.php[0-9]' -o -iname '*.phtml' -o -iname '*.phar' \) \
  -print

Uploads normally contain media, so unexpected PHP files deserve review. However, a small index.php used to prevent directory browsing may be legitimate.

This extension list is not exhaustive.

Find recently modified PHP files

find "$HOME/public_html/wp-content" -type f -iname '*.php' -mtime -7 -print

This lists PHP files modified within the previous seven days. Genuine plugin and theme updates will also appear, and attackers may alter timestamps.

Review important locations

Location What to check
wp-content/mu-plugins/ Unrecognised plugins that WordPress loads automatically.
wp-config.php Unexpected includes or injected code.
Theme functions.php files Unexplained additions, including at the beginning or end.
wp-content/plugins/ Modified files or unfamiliar additions.
advanced-cache.php and object-cache.php Unexplained changes to cache integrations.
wp-admin/ and wp-includes/ Modified or unexpected core files.
.htaccess and .user.ini Unexplained redirects, handlers or auto_prepend_file settings.

Modern WordPress also uses legitimate PHP translation files in wp-content/languages/. Their presence alone is not suspicious.

Understand legitimate matches

Base64 decoding can process authentication credentials or other data. Decompression functions can handle HTTP responses and archives. ROT13 can obscure an email address.

Comments and documentation may also mention eval() without executing it.

A familiar filename does not guarantee a safe file. Attackers can inject code into genuine WordPress files. Compare suspicious files with trusted copies of the same software version.

Check file integrity

WordPress.org checksums let you compare supported files with their official releases.

For an expert-led investigation, the relevant WP-CLI commands are:

wp core verify-checksums --include-root
wp plugin verify-checksums --all

Contact our support team before running WP-CLI against a suspected infected installation. Some commands load WordPress and may execute compromised code. Skipping ordinary plugins does not skip every automatically loaded file.

Core verification runs before WordPress loads. Plugin verification has a different loading process and needs additional care.

Premium, custom and other third-party plugins may not have WordPress.org checksums. Compare those with trusted vendor copies. Checksum differences need investigation, and passing checks does not establish that the whole website is clean.

What to do with the results

  1. Note suspicious file paths, line numbers and unexpected changes.
  2. Preserve copies before editing or deleting anything.
  3. Contact our support team with your website address and findings.

We can help investigate your hosting account and advise on the next steps. Do not automatically delete matching files or lines, as this can break your website without removing the compromise.

A complete investigation may also need to check administrator accounts, scheduled tasks, database content and the original entry point.

Avoid sharing passwords, private configuration values or complete suspicious code in public forums.

Troubleshooting

The search takes too long

Press Ctrl+C to stop. Search a smaller folder, such as wp-content/plugins, before expanding the search.

“Permission denied” appears

Your account cannot read the affected file or folder. Contact our support team so we can investigate.

No matches appear

Wait for the Terminal prompt to return and check the search path. No matches does not mean the website is clean: malware may use other techniques, unreadable files or database content.

Related articles

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London