Hunting Web Backdoors
This is not a vulnerability audit. You are looking for code an attacker
already planted — a webshell, a one-line eval backdoor, a fake plugin, a
malicious line appended to a legitimate file. The weakness that let them in is
auditing-php-applications' job; this skill finds what they left behind.
Two things make it hard. The malicious code is deliberately hidden — obfuscated,
split, or buried in a tree of thousands of legitimate files — so a naive grep
misses it. And the tells (eval, base64_decode, dynamic calls) appear in
plenty of benign code, so a naive grep also drowns you in false positives. The
work is the discrimination.
When to Use
- A web server is suspected or confirmed compromised and you need every shell
- Cleaning a hacked WordPress, Magento, Joomla, or custom PHP site
- Vetting a downloaded plugin, theme, or codebase before deploying it
- A file contains
eval, assert, or system on decoded or request-derived input
- Triaging a web root full of unfamiliar PHP for planted malice
When NOT to Use
- Finding the vulnerability that allowed the upload — use
auditing-php-applications
- Deep single-sample analysis (a specific shell you want to fully reverse,
its C2, its capabilities) — use
analyzing-malware
- The broader incident (scoping, timeline, containment) — use
responding-to-incidents; this skill is the source-tree sweep within it
- Malicious dependencies / package install scripts — use
auditing-supply-chain
- Host-level persistence (cron, systemd, LD_PRELOAD) — use
analyzing-linux-persistence
Never Execute to Deobfuscate
The single rule that must not bend: the obfuscated code is the payload. Do
not run it, do not "just let PHP decode it," do not replace eval( with
echo( and execute the file, do not paste it into an online sandbox that runs
it. Deobfuscation is a static transformation:
- Decode the layers by hand or with a decode-only tool (
base64_decode,
gzinflate, gzuncompress, str_rot13, hex/\xNN, strrev) applied as
string operations, not as executed PHP.
- If you must automate, use a de-obfuscator that decodes without executing
(UnPHP's decoder, a Python reimplementation of the decode chain) — never the
PHP interpreter on the sample.
- Replacing the final
eval( with file_put_contents('out.php', ...) and
running it is executing the payload if any prior layer has side effects.
Decode statically, then read.
"Most webshells are three or four layers of encoding around ten lines of logic"
— peel to the logic, do not detonate the wrapper.
Triage a Directory at Scale
You cannot read every file. Rank candidates by cheap signals, then read the
top of the list:
# 1. PHP where PHP should not be — uploads, cache, images, media dirs
find wp-content/uploads -name '*.php' -o -name '*.php[0-9]' -o -name '*.phtml' 2>/dev/null
# 2. Recently modified, clustered in time (attackers touch many files at once)
find . -name '*.php' -newermt '2026-07-01' -printf '%T+ %p\n' | sort
# 3. High entropy / long single lines — the shape of packed obfuscation
find . -name '*.php' -exec awk 'length>1000{print FILENAME": "length; nextfile}' {} \;
# 4. The dangerous-sink grep — leads, NOT verdicts (see the FP problem below)
grep -rnE '\b(eval|assert|system|passthru|shell_exec|proc_open|popen|create_function)\s*\(' --include='*.php' .
grep -rnE '(base64_decode|gzinflate|gzuncompress|str_rot13|hex2bin)\s*\(' --include='*.php' .
# 5. Request-driven code execution — the webshell core
grep -rnE '\$_(GET|POST|REQUEST|COOKIE|SERVER)\s*\[[^]]*\]\s*\(' --include='*.php' .
grep -rnE '(eval|assert|system|passthru)\s*\(\s*\$_(GET|POST|REQUEST|COOKIE)' --include='*.php' .
The most reliable single lead is variable execution of request data —
$_POST['x'](), ev[a]l($_GET[...]), ass[e]rt($_REQUEST[...]),
call_user_func($_GET['f'], ...). Legitimate code almost never dispatches a
function name straight from a superglobal.
The Grep Is Not Clean Just Because It Is Empty
A source tree that returns nothing for grep eval can still be backdoored.
Attackers defeat the obvious grep deliberately:
- Concatenation:
$a='ev'.'al'; $a($code); or ('e'.'v'.'a'.'l')(...).
- Variable variables / indirection:
$f='system'; $f($_GET['c']);,
${'_'.'GET'}, $$x.
- Char/hex/octal escapes:
"\x65\x76\x61\x6c" is eval;
chr(101).chr(118)....
- Callback sinks:
array_map, array_filter, usort,
preg_replace_callback, register_shutdown_function,
ob_start with a user-controlled callback.
- String-eval that is not
eval: assert($str) (pre-8.0),
preg_replace('/./e', $str, ...) (pre-7.0), create_function('', $str)
(pre-8.0), mb_ereg_replace with e.
- Comment and whitespace insertion between token pieces to break naive
regex.
So grep is a lead generator, not a coverage guarantee. When grep is empty and
you still suspect infection, fall back to: entropy/long-line ranking, mtime
clustering, and diffing against a known-good copy (below).
Append-Infections Are the Ones You Miss
The hardest infection is a backdoor appended to or inserted into a legitimate
file — index.php, wp-config.php, a theme's functions.php, vendor/
autoloaders. The file is 99% real, so it does not stand out by name, location,
or entropy overall. Find these by comparison, not by inspection:
# Diff the tree against a pristine copy of the same CMS/plugin version
# (download the exact version from wordpress.org / the vendor)
diff -rq ./site /known-good/wordpress-6.x/
# WordPress core/plugin integrity via checksums
wp core verify-checksums; wp plugin verify-checksums --all
# git/composer/npm: what changed vs the committed/locked state
git status --porcelain; git diff
If you have no known-good baseline, the tells are: code after the closing
?> of an otherwise-normal file, a lone eval/base64_decode line wedged at
the top of a config file, or a <?php ... ?> block whose style clashes with
the surrounding file.
Version-Gated Tells Date the Code
The presence of a removed language feature tells you something:
preg_replace with the /e modifier — removed in PHP 7.0. Its presence
means the backdoor targets (or predates) PHP 5.x.
create_function() and string-argument assert() as code execution —
removed in PHP 8.0. Common in older shells; on a PHP 8 server they would
fault, which is itself a signal about when the code was planted.
Known Families Are Leads, Not Verdicts
Fingerprints speed triage but do not replace reading the code:
IOC strings in this section are bracket-broken — ev[a]l is eval,
ass[e]rt is assert. Written literally they match Backdoor:PHP/Chopper
and this file, a defensive hunting skill, gets quarantined on download.
The grep patterns above are intact and safe to copy. See "Antivirus false
positives" in the repo README.
- China Chopper — a one-liner:
<?php @ev[a]l($_POST['pass']);?> (or
assert), often under 30 bytes. Tiny, so easy to miss and easy to append.
- WSO, b374k, c99, r57, indoxploit — full-featured panels; grep their
banner strings, characteristic function names, or auth-cookie names as leads.
- Weevely — generates obfuscated, password-gated shells that change per
build; signature matching is weak, so rely on the request-driven-execution
and obfuscation signals instead.
A signature hit confirms a shell. It does not confirm you found them all —
attackers plant several, and the second one rarely matches the first's family.
When You Confirm One, Assume More
- Preserve before you delete. A confirmed shell is evidence — copy it
(hash it) to a holding location before removing it, per
responding-to-incidents. Deletion alone loses the timeline and, if you
miss the entry point, the attacker re-plants within hours.
- Find the entry point. A shell got there somehow — a vulnerable upload,
a known-CVE plugin, stolen credentials. Hand that to
auditing-php-applications (source) or responding-to-incidents
(logs); a cleaned site with the hole still open is re-infected by morning.
- Keep hunting. One shell found is a reason to raise suspicion of the
whole tree, not to close the case. Re-run the sweep after removing the
obvious one.
Rationalizations to Reject
- "grep for eval came back clean, so the tree is clean." Concatenation, hex
escapes, and callback sinks all evade it. Empty grep is not coverage — fall
back to entropy, mtime, and diff-against-known-good.
- "I'll just run it to see what it decodes to." That is executing the
payload. Decode statically, always.
- "It uses
eval, so it's a backdoor." Templating engines, caches, and
frameworks use eval legitimately. The tell is eval on decoded or
request-derived input, not eval itself.
- "It's heavily obfuscated, so it's malicious." Commercial plugins ship
obfuscated (ionCube, Zend Guard, licensing). Obfuscation raises suspicion;
it does not convict. Decode and read the logic.
- "I found the shell and deleted it, done." You found a shell. Preserve it,
find the entry point, and re-sweep — attackers plant redundancy.
- "The file is a core CMS file, it must be safe." Append-infections live in
exactly those files precisely because you assume that. Verify by checksum.
- "No known-shell signature matched." Weevely and custom shells match
nothing. Signatures are leads; behaviour (request-driven execution,
obfuscation) is the evidence.
Reading External Sources
Fetch public advisories, specifications, and vendor reports as Markdown:
curl -sL "https://defuddle.md/<url>" # scheme in the path is optional
This strips page boilerplate — roughly 78% fewer tokens on a prose page — and
returns the full text rather than a summary, so you can grep it and trust a
negative result.
Three things it is not for. Fetch JSON and API responses raw, because
readability extraction mangles structured data. Fetch authenticated or
JavaScript-rendered pages directly, because it retrieves them anonymously. And
never route adversary infrastructure (phishing links, C2, malware hosting),
client-owned hosts, or engagement URLs through it — the request leaves
your machine to a third party, and for live adversary infrastructure it also
tips off the operator.
Some sites block the extractor and return an error blob rather than the page —
{"error":"Failed to fetch: 418 I'm a teapot"} from freedesktop.org, for
instance. That is the fetch being refused, not the source saying the thing
does not exist. Re-fetch the URL directly before drawing any conclusion from
it.
References
auditing-php-applications — the vulnerability that let the shell in
analyzing-malware — deep reverse of a single recovered shell, its C2 and
capabilities
responding-to-incidents — evidence handling, scoping, and the wider IR this
sweep sits inside
analyzing-linux-persistence — host-level persistence beyond the web root
writing-yara-rules — turning a confirmed family into a reusable signature
1---2name: hunting-web-backdoors3description: Hunt planted webshells and backdoors across a web source tree — PHP first (also JSP, ASP, Node) — triaging a directory at scale, statically decoding obfuscation layers without ever executing the payload, finding append-infections and fake plugins, and treating known shell families as leads rather than verdicts. Use when a web server is suspected compromised, cleaning a hacked WordPress/Magento/CMS site, vetting a downloaded PHP codebase or plugin for hidden malicious code, or when a file contains eval on decoded input.4verified: 2026-07-275---67# Hunting Web Backdoors89This is not a vulnerability audit. You are looking for code an attacker10**already planted** — a webshell, a one-line eval backdoor, a fake plugin, a11malicious line appended to a legitimate file. The weakness that let them in is12`auditing-php-applications`' job; this skill finds what they left behind.1314Two things make it hard. The malicious code is deliberately hidden — obfuscated,15split, or buried in a tree of thousands of legitimate files — so a naive grep16misses it. And the tells (`eval`, `base64_decode`, dynamic calls) appear in17plenty of benign code, so a naive grep also drowns you in false positives. The18work is the discrimination.1920## When to Use2122- A web server is suspected or confirmed compromised and you need every shell23- Cleaning a hacked WordPress, Magento, Joomla, or custom PHP site24- Vetting a downloaded plugin, theme, or codebase before deploying it25- A file contains `eval`, `assert`, or `system` on decoded or request-derived input26- Triaging a web root full of unfamiliar PHP for planted malice2728## When NOT to Use2930- **Finding the vulnerability that allowed the upload** — use31 `auditing-php-applications`32- **Deep single-sample analysis** (a specific shell you want to fully reverse,33 its C2, its capabilities) — use `analyzing-malware`34- **The broader incident** (scoping, timeline, containment) — use35 `responding-to-incidents`; this skill is the source-tree sweep within it36- **Malicious dependencies / package install scripts** — use37 `auditing-supply-chain`38- **Host-level persistence** (cron, systemd, LD_PRELOAD) — use39 `analyzing-linux-persistence`4041## Never Execute to Deobfuscate4243The single rule that must not bend: **the obfuscated code is the payload.** Do44not run it, do not "just let PHP decode it," do not replace `eval(` with45`echo(` and execute the file, do not paste it into an online sandbox that runs46it. Deobfuscation is a **static** transformation:4748- Decode the layers by hand or with a decode-only tool (`base64_decode`,49 `gzinflate`, `gzuncompress`, `str_rot13`, hex/`\xNN`, `strrev`) applied as50 string operations, not as executed PHP.51- If you must automate, use a de-obfuscator that decodes without executing52 (UnPHP's decoder, a Python reimplementation of the decode chain) — never the53 PHP interpreter on the sample.54- Replacing the final `eval(` with `file_put_contents('out.php', ...)` and55 running it *is* executing the payload if any prior layer has side effects.56 Decode statically, then read.5758"Most webshells are three or four layers of encoding around ten lines of logic"59— peel to the logic, do not detonate the wrapper.6061## Triage a Directory at Scale6263You cannot read every file. Rank candidates by cheap signals, then read the64top of the list:6566```bash67# 1. PHP where PHP should not be — uploads, cache, images, media dirs68find wp-content/uploads -name '*.php' -o -name '*.php[0-9]' -o -name '*.phtml' 2>/dev/null6970# 2. Recently modified, clustered in time (attackers touch many files at once)71find . -name '*.php' -newermt '2026-07-01' -printf '%T+ %p\n' | sort7273# 3. High entropy / long single lines — the shape of packed obfuscation74find . -name '*.php' -exec awk 'length>1000{print FILENAME": "length; nextfile}' {} \;7576# 4. The dangerous-sink grep — leads, NOT verdicts (see the FP problem below)77grep -rnE '\b(eval|assert|system|passthru|shell_exec|proc_open|popen|create_function)\s*\(' --include='*.php' .78grep -rnE '(base64_decode|gzinflate|gzuncompress|str_rot13|hex2bin)\s*\(' --include='*.php' .7980# 5. Request-driven code execution — the webshell core81grep -rnE '\$_(GET|POST|REQUEST|COOKIE|SERVER)\s*\[[^]]*\]\s*\(' --include='*.php' .82grep -rnE '(eval|assert|system|passthru)\s*\(\s*\$_(GET|POST|REQUEST|COOKIE)' --include='*.php' .83```8485The most reliable single lead is **variable execution of request data** —86`$_POST['x']()`, `ev[a]l($_GET[...])`, `ass[e]rt($_REQUEST[...])`,87`call_user_func($_GET['f'], ...)`. Legitimate code almost never dispatches a88function name straight from a superglobal.8990## The Grep Is Not Clean Just Because It Is Empty9192A source tree that returns nothing for `grep eval` can still be backdoored.93Attackers defeat the obvious grep deliberately:9495- **Concatenation:** `$a='ev'.'al'; $a($code);` or `('e'.'v'.'a'.'l')(...)`.96- **Variable variables / indirection:** `$f='system'; $f($_GET['c']);`,97 `${'_'.'GET'}`, `$$x`.98- **Char/hex/octal escapes:** `"\x65\x76\x61\x6c"` is `eval`;99 `chr(101).chr(118)...`.100- **Callback sinks:** `array_map`, `array_filter`, `usort`,101 `preg_replace_callback`, `register_shutdown_function`,102 `ob_start` with a user-controlled callback.103- **String-eval that is not `eval`:** `assert($str)` (pre-8.0),104 `preg_replace('/./e', $str, ...)` (pre-7.0), `create_function('', $str)`105 (pre-8.0), `mb_ereg_replace` with `e`.106- **Comment and whitespace insertion** between token pieces to break naive107 regex.108109So grep is a *lead generator*, not a coverage guarantee. When grep is empty and110you still suspect infection, fall back to: entropy/long-line ranking, mtime111clustering, and diffing against a known-good copy (below).112113## Append-Infections Are the Ones You Miss114115The hardest infection is a backdoor **appended to or inserted into a legitimate116file** — `index.php`, `wp-config.php`, a theme's `functions.php`, `vendor/`117autoloaders. The file is 99% real, so it does not stand out by name, location,118or entropy overall. Find these by comparison, not by inspection:119120```bash121# Diff the tree against a pristine copy of the same CMS/plugin version122# (download the exact version from wordpress.org / the vendor)123diff -rq ./site /known-good/wordpress-6.x/124125# WordPress core/plugin integrity via checksums126wp core verify-checksums; wp plugin verify-checksums --all127128# git/composer/npm: what changed vs the committed/locked state129git status --porcelain; git diff130```131132If you have no known-good baseline, the tells are: code *after* the closing133`?>` of an otherwise-normal file, a lone `eval`/`base64_decode` line wedged at134the top of a config file, or a `<?php ... ?>` block whose style clashes with135the surrounding file.136137## Version-Gated Tells Date the Code138139The presence of a removed language feature tells you something:140141- `preg_replace` with the `/e` modifier — **removed in PHP 7.0**. Its presence142 means the backdoor targets (or predates) PHP 5.x.143- `create_function()` and string-argument `assert()` as code execution —144 **removed in PHP 8.0**. Common in older shells; on a PHP 8 server they would145 fault, which is itself a signal about when the code was planted.146147## Known Families Are Leads, Not Verdicts148149Fingerprints speed triage but do not replace reading the code:150151> IOC strings in this section are bracket-broken — `ev[a]l` is `eval`,152> `ass[e]rt` is `assert`. Written literally they match `Backdoor:PHP/Chopper`153> and this file, a *defensive* hunting skill, gets quarantined on download.154> The grep patterns above are intact and safe to copy. See "Antivirus false155> positives" in the repo README.156157- **China Chopper** — a *one-liner*: `<?php @ev[a]l($_POST['pass']);?>` (or158 `assert`), often under 30 bytes. Tiny, so easy to miss and easy to append.159- **WSO, b374k, c99, r57, indoxploit** — full-featured panels; grep their160 banner strings, characteristic function names, or auth-cookie names as leads.161- **Weevely** — generates obfuscated, password-gated shells that change per162 build; signature matching is weak, so rely on the request-driven-execution163 and obfuscation signals instead.164165A signature hit confirms *a* shell. It does not confirm you found them all —166attackers plant several, and the second one rarely matches the first's family.167168## When You Confirm One, Assume More1691701. **Preserve before you delete.** A confirmed shell is evidence — copy it171 (hash it) to a holding location before removing it, per172 `responding-to-incidents`. Deletion alone loses the timeline and, if you173 miss the entry point, the attacker re-plants within hours.1742. **Find the entry point.** A shell got there somehow — a vulnerable upload,175 a known-CVE plugin, stolen credentials. Hand that to176 `auditing-php-applications` (source) or `responding-to-incidents`177 (logs); a cleaned site with the hole still open is re-infected by morning.1783. **Keep hunting.** One shell found is a reason to raise suspicion of the179 whole tree, not to close the case. Re-run the sweep after removing the180 obvious one.181182## Rationalizations to Reject183184- *"grep for eval came back clean, so the tree is clean."* Concatenation, hex185 escapes, and callback sinks all evade it. Empty grep is not coverage — fall186 back to entropy, mtime, and diff-against-known-good.187- *"I'll just run it to see what it decodes to."* That is executing the188 payload. Decode statically, always.189- *"It uses `eval`, so it's a backdoor."* Templating engines, caches, and190 frameworks use `eval` legitimately. The tell is `eval` on *decoded or191 request-derived* input, not `eval` itself.192- *"It's heavily obfuscated, so it's malicious."* Commercial plugins ship193 obfuscated (ionCube, Zend Guard, licensing). Obfuscation raises suspicion;194 it does not convict. Decode and read the logic.195- *"I found the shell and deleted it, done."* You found *a* shell. Preserve it,196 find the entry point, and re-sweep — attackers plant redundancy.197- *"The file is a core CMS file, it must be safe."* Append-infections live in198 exactly those files precisely because you assume that. Verify by checksum.199- *"No known-shell signature matched."* Weevely and custom shells match200 nothing. Signatures are leads; behaviour (request-driven execution,201 obfuscation) is the evidence.202203## Reading External Sources204205Fetch public advisories, specifications, and vendor reports as Markdown:206207```bash208curl -sL "https://defuddle.md/<url>" # scheme in the path is optional209```210211This strips page boilerplate — roughly 78% fewer tokens on a prose page — and212returns the full text rather than a summary, so you can grep it and trust a213negative result.214215Three things it is not for. Fetch JSON and API responses raw, because216readability extraction mangles structured data. Fetch authenticated or217JavaScript-rendered pages directly, because it retrieves them anonymously. And218never route **adversary infrastructure** (phishing links, C2, malware hosting),219**client-owned hosts**, or **engagement URLs** through it — the request leaves220your machine to a third party, and for live adversary infrastructure it also221tips off the operator.222223Some sites block the extractor and return an error blob rather than the page —224`{"error":"Failed to fetch: 418 I'm a teapot"}` from freedesktop.org, for225instance. That is the fetch being refused, **not** the source saying the thing226does not exist. Re-fetch the URL directly before drawing any conclusion from227it.228229## References230231- `auditing-php-applications` — the vulnerability that let the shell in232- `analyzing-malware` — deep reverse of a single recovered shell, its C2 and233 capabilities234- `responding-to-incidents` — evidence handling, scoping, and the wider IR this235 sweep sits inside236- `analyzing-linux-persistence` — host-level persistence beyond the web root237- `writing-yara-rules` — turning a confirmed family into a reusable signature