
Laboratorio de seguridad basado en Docker que demuestra la explotación y defensa de Apache Struts2 S2-045 (CVE-2017-5638), con aplicaciones vulnerables y parcheadas y protección WAF para formación práctica.
Un laboratorio de seguridad basado en Docker que demuestra tanto explotación como defensa contra la vulnerabilidad Apache Struts2 S2-045 (CVE-2017-5638). Este laboratorio incluye:
⚠️ Advertencia de seguridad: Este laboratorio contiene exploits funcionales y código vulnerable. Utilice solo en entornos aislados. NO exponga a redes públicas.
┌─────────────────────────────────────────────────────────────┐
│ 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/ │
└─────────────────────────────────────────────────────────────┘
| Contenedor | Propósito | Puerto |
|---|---|---|
nginx | Proxy inverso con reglas WAF, limitación de velocidad | 127.0.0.1:8080 |
app | Tomcat 9 + Struts 6.3.x (parcheado, laboratorio de defensa) | Solo interno |
app-vulnerable | Tomcat 9 + Struts 2.3.31 (vulnerable, para explotación) | 127.0.0.1:8081 |
exploit | Contenedor de demostración de explotación | N/A |
simulator | Envía solicitudes de prueba (patrones benignos + sospechosos) | N/A |
# 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
Expected Output:
"status":"healthy" y "strutsVersion":"6.3.0.2 (patched - not vulnerable to S2-045)""status":"healthy" y "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
⚠️ Warning: The vulnerable application is intentionally exploitable. Only run in isolated environments.
# 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
Solicitud legítima:
200INFOSolicitud sospechosa/malformada:
403 Forbidden o 400 Bad RequestExplotación exitosa:
Ejemplos de registros:
Nginx bloqueando Content-Type sospechoso (Laboratorio de defensa):
[WAF] Blocked suspicious Content-Type pattern - Request ID: abc123
Registro de metadatos de solicitud de la aplicación (Laboratorio de defensa):
[REQUEST] ID=abc123 Content-Type=multipart/form-data Method=POST URI=/upload
[UPLOAD] Processing file upload for request abc123
Explotación exitosa (Aplicación vulnerable):
HTTP/1.1 200 OK
...
root
(Command output appears in response body)
| Característica | Aplicación vulnerable (Puerto 8081) | Laboratorio de defensa (Puerto 8080) |
|---|---|---|
| Versión de Struts | 2.3.31 (vulnerable) | 6.3.0.2 (parcheado) |
| Protección WAF | ❌ Ninguna | ✅ Reglas WAF de Nginx |
| Límite de velocidad | ❌ Ninguno | ✅ 10 solicitudes/s |
| Límites de tamaño de solicitud | ❌ Ninguno | ✅ Cuerpo 10MB, encabezados 8KB |
| Registro de seguridad | ⚠️ Mínimo | ✅ Completo |
| Inyección OGNL | ✅ Explotable | ❌ Bloqueada/Parcheada |
| RCE Posible | ✅ Sí | ❌ No |
| Caso de uso | Demostración de explotación | Entrenamiento defensivo |
127.0.0.1 (sin acceso externo)