
مختبر أمني قائم على Docker يوضح استغلال ثغرة Apache Struts2 S2-045 (CVE-2017-5638) والدفاع ضدها، ويشمل تطبيقات قابلة للاستغلال وأخرى مُصححة مع حماية WAF للتدريب العملي.
مختبر أمني قائم على Docker يعرض كلاً من الاستغلال و الدفاع ضد ثغرة Apache Struts2 S2-045 (CVE-2017-5638). يحتوي هذا المختبر على:
⚠️ تحذير أمني: يحتوي هذا المختبر على أكواد استغلال عاملة و كود ضعيف. استخدمه فقط في بيئات معزولة. لا تعرضه للشبكات العامة.
┌─────────────────────────────────────────────────────────────┐
│ 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/ │
└─────────────────────────────────────────────────────────────┘
# 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
المخرجات المتوقعة:
"status":"healthy" و "strutsVersion":"6.3.0.2 (patched - not vulnerable to S2-045)""status":"healthy" و "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
⚠️ تحذير: التطبيق الضعيف قابل للاستغلال بشكل متعمد. قم بتشغيله فقط في بيئات معزولة.
# 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
طلب شرعي:
200INFOطلب مشبوه/غير صحيح:
403 Forbidden أو 400 Bad Requestاستغلال ناجح:
أمثلة على السجلات:
حظر Nginx لنوع Content-Type مشبوه (مختبر الدفاع):
[WAF] Blocked suspicious Content-Type pattern - Request ID: abc123
تسجيل بيانات الطلب من التطبيق (مختبر الدفاع):
[REQUEST] ID=abc123 Content-Type=multipart/form-data Method=POST URI=/upload
[UPLOAD] Processing file upload for request abc123
استغلال ناجح (التطبيق الضعيف):
HTTP/1.1 200 OK
...
root
(Command output appears in response body)
127.0.0.1 فقط (لا وصول خارجي)0.0.0.0S2-045 (CVE-2017-5638) كانت ثغرة حرجة في Apache Struts2 للإصدارات 2.3.5 - 2.3.31 و 2.5 - 2.5.10 حيث:
يُظهر التطبيق الضعيف (المنفذ 8081) هذه الثغرة. يُظهر مختبر الدفاع (المنفذ 8080) كيفية الحماية منها.
.
├── docker-compose.yml # تنسيق الحاويات
├── README.md # هذا الملف
├── EXPLOITATION_GUIDE.md # دليل استغلال مفصل
├── TECHNICAL_DETAILS.md # تفاصيل التنفيذ الفنية
├── GLOSSARY.md # مسرد مصطلحات الأمان
├── nginx/
│ ├── nginx.conf # تكوين nginx الرئيسي
│ └── waf-rules.conf # قواعد WAF لأنماط S2-045
├── app/ # مختبر الدفاع (مُصحّح)
│ ├── Dockerfile # بناء Tomcat + Maven
│ └── struts-app/
│ ├── pom.xml # مشروع Maven (Struts 6.3.x)
│ └── src/main/
│ ├── java/ # فئات الإجراءات
│ ├── resources/ # تكوين Struts + Log4j
│ └── webapp/ # عروض JSP + web.xml
├── app-vulnerable/ # التطبيق الضعيف (للاستغلال)
│ ├── Dockerfile # بناء Tomcat + Maven
│ └── struts-app/
│ ├── pom.xml # مشروع Maven (Struts 2.3.31)
│ └── src/main/
│ ├── java/ # فئات الإجراءات
│ ├── resources/ # تكوين Struts + Log4j
│ └── webapp/ # عروض JSP + web.xml
├── exploit/ # أدوات الاستغلال
│ ├── Dockerfile # حاوية الاستغلال
│ ├── demo_exploit.sh # نص Bash للاستغلال
│ └── exploit.py # نص Python للاستغلال
├── simulator/
│ ├── Dockerfile # Alpine + curl
│ └── simulate.sh # نص الاختبار
└── logs/ # دليل السجلات المثبت
├── nginx/
├── app/ # سجلات مختبر الدفاع
└── app-vulnerable/ # سجلات التطبيق الضعيف
# 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
تم تنظيم المشروع كما يلي:
app/ - تطبيق مختبر الدفاع (Struts 6.3.x، مُصحّح)app-vulnerable/ - التطبيق الضعيف (Struts 2.3.31)exploit/ - أدوات ونصوص الاستغلالnginx/ - تكوين وكيل Nginx العكسي مع قواعد WAFsimulator/ - محاكي أنماط الهجومlogs/ - سجلات التطبيق (مُستبعدة من Git)# 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
إخلاء مسؤولية: هذا المختبر لأغراض تعليمية فقط. استخدمه بمسؤولية وفي بيئات خاضعة للرقابة فقط.
| الحاوية | الغرض | المنفذ |
|---|
nginx | وكيل عكسي مع قواعد WAF، تحديد معدل | 127.0.0.1:8080 |
app | Tomcat 9 + Struts 6.3.x (مُصحّح، مختبر دفاع) | داخلي فقط |
app-vulnerable | Tomcat 9 + Struts 2.3.31 (ضعيف، للاستغلال) | 127.0.0.1:8081 |
exploit | حاوية عرض الاستغلال | لا يوجد |
simulator | يرسل طلبات اختبار (عادية + أنماط مشبوهة) | لا يوجد |
| الميزة | التطبيق الضعيف (المنفذ 8081) | مختبر الدفاع (المنفذ 8080) |
|---|
| إصدار Struts | 2.3.31 (ضعيف) | 6.3.0.2 (مُصحّح) |
| حماية WAF | ❌ لا يوجد | ✅ قواعد WAF لـ Nginx |
| تحديد المعدل | ❌ لا يوجد | ✅ 10 طلبات/ثانية |
| حدود حجم الطلب | ❌ لا يوجد | ✅ 10 ميجابايت للجسم، 8 كيلوبايت للرؤوس |
| تسجيل الأمان | ⚠️ ضئيل | ✅ شامل |
| حقن OGNL | ✅ قابل للاستغلال | ❌ محظور/مُصحّح |
| إمكانية تنفيذ الأوامر عن بُعد | ✅ نعم | ❌ لا |
| حالة الاستخدام | عرض الاستغلال | تدريب الدفاع |