Web Shell

Web Shell

One-liner: A malicious script uploaded to a web server that provides attackers with remote command execution via a web interface.

🎯 What Is It?

A Web Shell is a script (typically PHP, ASP, JSP, or Python) installed on a compromised web server that allows attackers to execute operating system commands through a web browser. Web shells are used in the Installation stage of the Cyber Kill Chain to maintain persistent access after initial exploitation.

πŸ”¬ How It Works

Attacker                 Compromised Server              Target System
   β”‚                            β”‚                              β”‚
   β”œβ”€β”€Exploits vulnerability───►│                              β”‚
   β”‚  (upload vuln, RCE, etc.)  β”‚                              β”‚
   β”‚                            β”‚                              β”‚
   β”œβ”€β”€Uploads web shell────────►│                              β”‚
   β”‚                            β”œβ”€β”€Shell saved to webroot──────│
   β”‚                            β”‚                              β”‚
   β”œβ”€β”€Accesses via browser─────►│                              β”‚
   β”‚  (https://target/shell.php)β”‚                              β”‚
   β”‚                            β”‚                              β”‚
   β”œβ”€β”€Sends commandsβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”œβ”€β”€Executes on server─────────►│
   β”‚                            β”‚                              β”‚
   │◄──Receives output───────────                              β”‚

Simple PHP Web Shell Example

<?php
// Simple one-liner web shell
system($_GET['cmd']);
?>
# Usage: https://target.com/shell.php?cmd=whoami

Advanced Web Shell Features

πŸ“Š Common Web Shells

Name Language Features
c99 PHP Full-featured file manager, DB access
r57 PHP System info, file manager
China Chopper ASP/PHP 4KB, highly obfuscated
WSO PHP Web Shell by oRb
Weevely PHP Encrypted communications
ASPXSpy ASPX .NET web shell

πŸ›‘οΈ Detection & Prevention

How to Detect

Indicators of Compromise

# Suspicious log entries
POST /uploads/image.php HTTP/1.1 (with unusual parameters)
GET /shell.php?cmd=cat+/etc/passwd HTTP/1.1

# Suspicious processes
www-data spawning /bin/bash
IIS worker spawning cmd.exe

How to Prevent / Mitigate

🎀 Interview Angles

Common Questions

STAR Story

Situation: Detected unusual outbound connections from a web server during routine monitoring.
Task: Investigate and remediate potential compromise.
Action: Analyzed web logs, found suspicious POST requests to an unknown PHP file. Discovered a c99 web shell uploaded via a file upload vulnerability. Contained the server, removed the shell, patched the vulnerability.
Result: Prevented data exfiltration. Implemented file integrity monitoring and upload validation to prevent recurrence.

βœ… Best Practices

πŸ“š References