Why Filename Matching Is No Longer Enough
The earliest webshell detection relied on file signatures: names like shell.php, cmd.jsp, c99.php stood out immediately. Attackers quickly adapted — naming backdoors index.php, about.aspx, config.jsp, placed in normal directories, indistinguishable by filename.
Parameter obfuscation went further: ?cmd=whoami became ?a=x&b=1, with both names and values base64-encoded. Any rule keyed on filenames or fixed parameters fails outright.
What remains hard to disguise is behavioral shape. However parameters are obfuscated, a webshell that executes commands must receive instructions, must invoke system functions, and must produce response patterns different from normal business traffic. All of that is visible in the HTTP request shape.
The Three-Dimension Scoring Model
PcapDecoder's webshell detector looks only at requests on TCP 80 / 8080 (payload beginning with POST ), accumulating up to 40 points per dimension:
Dimension 1: Target script extension (40 points)
The URI path (minus querystring) ends with .php / .asp / .aspx / .jsp / .cfm. Alone this has almost no discriminative power — legitimate applications use these extensions — but it provides necessary context: if later signals hit, the attack occurred on executable script.
Dimension 2: Behavioral parameters (40 points)
The URI or request body (after \r\n\r\n) contains one of cmd= / exec= / pass= / command= / shell=. These are default conventions across webshell management tools; even when users change them, they typically change how values are transported rather than the parameter names.
Dimension 3: Code-execution traces (40 points)
The body contains calls such as eval( / base64_decode( / system( / passthru( / shell_exec(. A normal form submission does not send PHP function names as parameter values — seeing this basically confirms the request content is meant to be executed server-side.
How confidence is computed
confidence = min(100, sum of the three dimensions), and only ≥60 enters the report.
The threshold means something specific: two dimensions must hit. Extension alone (40) is not reported because legitimate applications match; extension plus behavioral parameters (80), or extension plus code execution (80), is reported. Severity splits by score: ≥80 is dangerous (2), 60–79 is suspicious (1).
Why aggregate per source
Scoring packet by packet produces a flood of duplicates — one webshell session may send dozens of POSTs. The detector aggregates by (source IP, destination IP, URI), unions all signals observed across that interaction, and recomputes the score.
This solves two problems:
- No duplicates: one session yields one finding with multiple evidence packets;
- No misses: command execution and parameter upload may occur in different requests. A first request with only
cmd=(60, borderline) plus a second carryingbase64_decode((union reaches 100) is classified dangerous after aggregation.
How-to: From Finding to Location
Step 1: Look at URI and score. The webshell group lists each finding's URI, hit signals, total score and evidence packet number. Start with ≥80 — those are effectively confirmed.
Step 2: Follow the stream for the full interaction. Jump to the packet number and use follow-stream on that URI's bidirectional traffic. What to examine:
- the actual body structure (is
cmd=followed by a system command?); - response size and shape (command output is usually plain text and webshell responses tend to be conspicuously short);
- request rhythm (interactive webshells are "send one, wait for one", unlike the batch concurrency of normal page loads).
Step 3: Confirm the victim host. The destination IP is the web server. Check that server's other outbound activity in the window — if it starts connecting to unknown IPs or running DNS tunneling after the webshell activity, it has moved into post-exploitation.
Step 4: Locate the entry point. Webshells do not appear from nowhere. Walk back to upload behavior before the first webshell appearance: POSTs to file upload endpoints, FTP writes, SMB copies. This determines the fix — was a backdoor uploaded, or was a vulnerability exploited?
Known Evasions and Limits
Being honest about limits is more useful than inflating capability:
Encoding and compression defeat literal matching. A gzip-compressed or wholesale base64-encoded body hides plaintext markers like cmd=. The current implementation caps the text window at 64KB, so anything beyond does not participate in matching.
Only cleartext 80 / 8080 is covered. Webshells on 443 live inside TLS and are invisible; reading them requires the keylog path.
Tool fingerprints are a separate line. AntSword, China Chopper and Behinder have their own traffic characteristics (specific headers, specific cryptographic handshakes). PcapDecoder maintains an independent fingerprint library covering 20+ tools — complementary to this behavioral detector: fingerprints catch known tools, behavior catches unknown or modified ones.
It does not replace log-based detection. Server access logs and file integrity monitoring see whether a request actually materialized as a file; packet capture only sees network-layer behavior. Both are needed for a complete determination.
Response Guidance
- Isolate the victim host: once a webshell is confirmed, disconnect it immediately — do not just delete the file, since multiple backdoors may exist;
- Hunt for all backdoors: scan by modification time and code patterns (
eval,assert, direct$_POSTexecution) across the whole filesystem; - Find and patch the entry point: if the entry was an upload flaw, fix the validation rather than deleting a file;
- Rotate every credential: webshells usually accompany credential theft; rotate database passwords and API keys configured on the server;
- Trace lateral movement: how long has this server been controlled? Inspect its internal connections during that period to check whether it served as a pivot.
Related reading: Detecting Lateral Movement, Detecting Authentication Brute Force.
