
PHP to Shell, Part 6: Webshell Payloads, and How They Get Caught
Every mechanism in this series — upload, inclusion, deserialization — ends at the same place:
a function call the attacker controls. This closing post covers what that call actually looks
like, why disable_functions is friction rather than a boundary, and the detection patterns
that repeat across every earlier post instead of being specific to any one of them. Nothing
below is a copy-paste kit; the mechanism is the point, and every mechanism is paired with its
detection counterpart in the same breath.
The minimal primitive is almost always a single call
<?php eval($_POST['c']); ?>
That line, or one of a handful of equivalents, is the entire payload. Everything written about “webshells” as a category is really about two separate things: how that one line survives whatever filtering got it there, and what happens to the rest of the request once it runs.
Variants that show up for specific reasons, not as a menu to pick from:
assert()as a string evaluator — historical. Dead as an execution sink on PHP 8.0+, which is why a payload built on it is a reliable sign of either an ancient target or a write-up copied without checking the PHP version.- Backticks or
shell_exec()— when the goal is a shell command rather than PHP expression evaluation, and the target’sdisable_functionslist doesn’t cover them. - Variable function calls —
$_GET['f']($_GET['a'])— useful specifically because the function name itself is a parameter, which defeats a string-matching filter looking for the literal texteval(. include()of something else already on disk — the quietest option, because the webshell’s own source never contains the dangerous call; it just points at whatever got dropped by the upload or inclusion bug from earlier in this series.
disable_functions reduces capability; it is not the boundary
Worth stating directly because reports lean on it as if it were one. Every family below exists specifically because a blocklist enumerates known-dangerous functions, and there’s always another path:
LD_PRELOADviaputenv(), combined with any function that spawns a process (mail(), orerror_log()routed to sendmail) — glibc-specific, needs a readable shared object and a binary inPATH, but neithermail()norerror_log()is on a typical blocklist because neither looks dangerous on its own.pcntl_exec()— routinely missed because a blocklist built aroundexec/systemrarely thinks to also cover thepcntl_*family.imap_open()mailbox-string injection — needs theimapextension, which was unbundled from PHP core as of 8.4, closing this one by default going forward rather than by anyone’s blocklist.
The correct framing for a report: the boundary is “the uploaded file never executes in the first place” — everything in this series before this post — not “the functions it could call are restricted after the fact.”
The detection signal that repeats across all five previous posts
Individually, every earlier post in this series has its own detection notes next to its own mechanism. What’s worth pulling out here is the handful of patterns that catch multiple mechanisms at once, because a control instrumented once against the right signal is worth more than five narrow rules:
A response’s Content-Type doesn’t match its path’s history. Part 2’s polyglot upload and
this post’s webshell share one tell: the moment either one executes, a path that used to
return image/gif or image/jpeg starts returning text/html. A rule that flags any response
from a known-static directory whose content type diverges from that path’s own baseline catches
both without knowing which mechanism got there.
A write and a read/include from the same source, seconds apart. Part 2’s temp-file race and
part 3’s phpinfo-disclosed-temp-file trick are the same correlation stated twice: a POST to an
upload endpoint followed almost immediately by a GET whose include/page-style parameter
targets exactly the path the first request would have written to. A single request carrying a
PHP tag is noise — WAFs see that constantly, legitimately malformed or not. The pair, within
one request lifetime, from one source, is close to unambiguous.
File integrity monitoring on the handful of files that should never exist. .htaccess or
.user.ini appearing anywhere web-writable (part 2), an archive-shaped file hiding in a media
directory (PK\x03\x04 or __HALT_COMPILER();, from parts 3 and 4), a new .php-suffixed file
in an upload or cache directory — these converge from three unrelated mechanisms onto the same
three or four FIM rules. It’s the single highest-value control in this whole series, precisely
because it doesn’t care which upstream bug produced the file.
Serialized-object syntax in a cookie or request body. O:<n>:", a:<n>:{, s:<n>:" —
part 4’s cleanest signature, and it survives only until it’s base64-decoded, which is worth
building the decode step into the rule rather than matching on the raw string alone.
Process-level signal at the moment of actual success. www-data (or the pool user)
spawning a shell, or making an outbound connection, is the one control that doesn’t care what
got the attacker there. It’s also the control that was structurally impossible to test in this
series’ own lab — part 1 built that lab with no egress
at all, which is exactly the property that would stop a webshell from phoning home on a real
box too. A PHP worker has no legitimate reason to open an outbound connection; alerting on one
at all is close to free in false positives.
A rule that never fires is a finding too
Worth closing on, since it came up more than once across this series’ own testing: a negative
result against a hardened configuration is evidence the control is holding, not evidence the
rule is dead weight. AllowOverride None blocking .htaccess abuse in part 2, mod_php never
reading .user.ini in the same post, allow_url_include=Off blocking data:// in part 3 — none
of those produced an exploit, and all three produced a genuine, reproducible fact about which
specific setting was load-bearing. If you’re tracking detection rule health the way you’d track
anything else with a hit rate, track the negative-control hit rate the same way — a WAF rule
that never fires because the upstream control is solid looks identical, from a dashboard, to a
WAF rule nobody deployed correctly. Only testing against a real target, hardened or not, tells
you which one you’re looking at.
That’s the series: an upload filter and a handler map that have to agree before a file becomes
code, an include() that turns into a write-then-read problem once something writes
attacker-controlled bytes somewhere readable, an unserialize() call that’s only as dangerous
as the gadget chain actually installed on the target, the public CVEs that carry each of those
three mechanisms into real exploitation, and the half-dozen detection rules that don’t care
which of the three got an attacker there in the first place.
Related posts
03 ENTRIEShttps://shulkwisec.github.io/php-to-shell/06-webshell-payloads-and-how-they-get-caught/
Printed 2026-11-15


