
Laboratorio di sicurezza basato su Docker che dimostra lo sfruttamento e la difesa di Apache Struts2 S2-045 (CVE-2017-5638) con un'app vulnerabile, un'app corretta, Nginx WAF e script di exploit per una 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)S2-045 (CVE-2017-5638) era una vulnerabilità critica in Apache Struts2 versioni 2.3.5 - 2.3.31 e 2.5 - 2.5.10 in cui:
L'app vulnerabile (porta 8081) dimostra questa vulnerabilità. Il laboratorio di difesa (porta 8080) mostra come proteggersi.
.
├── docker-compose.yml # Orchestrazione dei container
├── README.md # Questo file
├── EXPLOITATION_GUIDE.md # Guida dettagliata allo sfruttamento
├── TECHNICAL_DETAILS.md # Dettagli di implementazione tecnica
├── GLOSSARY.md # Glossario dei termini di sicurezza
├── nginx/
│ ├── nginx.conf # Configurazione principale di nginx
│ └── waf-rules.conf # Regole WAF per pattern S2-045
├── app/ # Laboratorio di difesa (corretto)
│ ├── Dockerfile # Build Tomcat + Maven
│ └── struts-app/
│ ├── pom.xml # Progetto Maven (Struts 6.3.x)
│ └── src/main/
│ ├── java/ # Classi Action
│ ├── resources/ # Configurazione Struts + Log4j
│ └── webapp/ # Viste JSP + web.xml
├── app-vulnerable/ # App vulnerabile (per sfruttamento)
│ ├── Dockerfile # Build Tomcat + Maven
│ └── struts-app/
│ ├── pom.xml # Progetto Maven (Struts 2.3.31)
│ └── src/main/
│ ├── java/ # Classi Action
│ ├── resources/ # Configurazione Struts + Log4j
│ └── webapp/ # Viste JSP + web.xml
├── exploit/ # Strumenti di sfruttamento
│ ├── Dockerfile # Contenitore exploit
│ ├── demo_exploit.sh # Script bash di exploit
│ └── exploit.py # Script Python di exploit
├── simulator/
│ ├── Dockerfile # Alpine + curl
│ └── simulate.sh # Script di test
└── logs/ # Directory log montata
├── nginx/
├── app/ # Log del laboratorio di difesa
└── app-vulnerable/ # Log dell'app vulnerabile
# Stop all containers
docker compose down
# Remove volumes and logs
docker compose down -v
rm -rf logs/
# Full cleanup (including images)
docker compose down --rmi all -v
Il progetto è organizzato come segue:
app/ - Applicazione del laboratorio di difesa (Struts 6.3.x, corretto)app-vulnerable/ - Applicazione vulnerabile (Struts 2.3.31)exploit/ - Strumenti e script di sfruttamentonginx/ - Configurazione del proxy inverso Nginx con regole WAFsimulator/ - Simulatore di pattern di attaccologs/ - Log dell'applicazione (gitignorati)# Rebuild only the vulnerable app
docker compose build app-vulnerable
docker compose up -d app-vulnerable
# Rebuild only the defense app
docker compose build app
docker compose up -d app
# Rebuild exploit container
docker compose build exploit
Disclaimer: Questo laboratorio è solo a scopo educativo. Usalo responsabilmente e solo in ambienti controllati.