
Laboratorio di sicurezza basato su Docker che dimostra lo sfruttamento e la difesa di Apache Struts2 S2-045 (CVE-2017-5638), con applicazioni vulnerabili e patchate con protezione WAF per formazione pratica.
Un laboratorio di sicurezza basato su Docker che dimostra sia lo sfruttamento che la difesa contro la vulnerabilità Apache Struts2 S2-045 (CVE-2017-5638). Questo laboratorio include:
⚠️ Avviso di Sicurezza: Questo laboratorio contiene exploit funzionanti e codice vulnerabile. Da usare solo in ambienti isolati. NON esporre a reti pubbliche.
┌─────────────────────────────────────────────────────────────┐
│ Host (127.0.0.1 only) │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Simulator │───▶│ Nginx Proxy │ │
│ │ (curl-based) │ │ + WAF Rules │ │
│ └─────────────────┘ └────────┬────────┘ │
│ │ │
│ ┌───────┴────────┐ │
│ │ │ │
│ ┌───────▼──────┐ ┌───────▼──────┐ │
│ │ Defense App │ │ Vulnerable │ │
│ │ (Struts 6.3) │ │ App (2.3.31) │ │
│ │ Port: 8080 │ │ Port: 8081 │ │
│ └──────────────┘ └──────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ Exploit │───▶ Vulnerable App (8081) │
│ │ Container │ │
│ └─────────────────┘ │
│ │
│ Logs mounted to: ./logs/nginx/, ./logs/app/, │
│ ./logs/app-vulnerable/ │
└─────────────────────────────────────────────────────────────┘
| Contenitore | Scopo | Porta |
|---|---|---|
nginx | Proxy inverso con regole WAF, limitazione della velocità | 127.0.0.1:8080 |
app | Tomcat 9 + Struts 6.3.x (corretto, laboratorio di difesa) | Solo interno |
app-vulnerable | Tomcat 9 + Struts 2.3.31 (vulnerabile, per sfruttamento) | 127.0.0.1:8081 |
exploit | Contenitore dimostrativo di sfruttamento | N/D |
simulator | Invia richieste di test (pattern benigni + sospetti) | N/D |
# Clone the repository
git clone https://github.com/ACharaf06/cybersec.git
cd cybersec
# Build all containers (this may take several minutes on first run)
docker compose build
# Start the defense lab (nginx + patched app)
docker compose up -d nginx app
# Start the vulnerable app (for exploitation demo)
docker compose up -d app-vulnerable
# Verify services are running
docker compose ps
# Wait for services to be healthy (about 60 seconds)
sleep 60
# Check health endpoints
curl http://127.0.0.1:8080/struts-lab/health # Defense lab
curl http://127.0.0.1:8081/struts-lab/health # Vulnerable app
Output Previsto:
"status":"healthy" e "strutsVersion":"6.3.0.2 (patched - not vulnerable to S2-045)""status":"healthy" e "strutsVersion":"2.3.31 (VULNERABLE to S2-045)"# Run the simulator container (tests defense mechanisms)
docker-compose run --rm simulator
# Or run individual tests manually:
# Legitimate upload
curl -X POST -F "[email protected]" http://127.0.0.1:8080/struts-lab/upload
# Suspicious Content-Type (will be blocked by WAF)
curl -v -X POST \
-H "Content-Type: multipart/form-data; boundary=----SUSPICIOUS" \
http://127.0.0.1:8080/struts-lab/upload
# Run the exploit container (demonstrates S2-045 exploitation)
docker-compose --profile exploit run --rm exploit
# Or use the Python exploit script directly
python3 exploit/exploit.py http://127.0.0.1:8081/struts-lab 'whoami'
# Or use the bash script
./exploit/demo_exploit.sh
⚠️ Avviso: L'applicazione vulnerabile è intenzionalmente sfruttabile. Eseguire solo in ambienti isolati.
# Defense lab logs
tail -f logs/nginx/access.log # Nginx access logs
tail -f logs/nginx/error.log # WAF blocks
tail -f logs/app/struts-lab.log # Defense app logs
# Vulnerable app logs
tail -f logs/app-vulnerable/struts-lab.log # Vulnerable app logs
# All logs combined
docker-compose logs -f
Richiesta Legittima:
200INFORichiesta Sospetta/Malformata:
403 Forbidden o 400 Bad RequestSfruttamento Riuscito:
Esempi di Log:
Nginx blocca Content-Type sospetto (Laboratorio di Difesa):
[WAF] Blocked suspicious Content-Type pattern - Request ID: abc123
Log dei metadati della richiesta nell'app (Laboratorio di Difesa):
[REQUEST] ID=abc123 Content-Type=multipart/form-data Method=POST URI=/upload
[UPLOAD] Processing file upload for request abc123
Sfruttamento riuscito (App Vulnerabile):
HTTP/1.1 200 OK
...
root
(Command output appears in response body)
| Caratteristica | App Vulnerabile (Porta 8081) | Laboratorio di Difesa (Porta 8080) |
|---|---|---|
| Versione Struts | 2.3.31 (vulnerabile) | 6.3.0.2 (corretto) |
| Protezione WAF | ❌ Nessuna | ✅ Regole WAF Nginx |
| Limitazione di Velocità | ❌ Nessuna | ✅ 10 richieste/s |
| Limiti Dimensione Richiesta | ❌ Nessuno | ✅ 10MB corpo, 8KB intestazioni |
| Registrazione di Sicurezza | ⚠️ Minima | ✅ Completa |
| Iniezione OGNL | ✅ Sfruttabile | ❌ Bloccata/Corretta |
| RCE Possibile | ✅ Sì | ❌ No |
| Caso d'Uso | Dimostrazione sfruttamento | Formazione difensiva |
127.0.0.1 (nessun accesso esterno)