Skip to content
KitploitKITPLOIT
أدواتالمدونة
إرسال
أدواتالمدونة
إرسال

أدوات الاختراق واختبار الاختراق والأمن السيبراني لترسانتك الأمنية!

Kitploit هو دليل لأدوات الاختراق والأمن السيبراني واختبار الاختراق. اكتشف آخر تحديثات المشاريع للعثور على الثغرات وتحليل الأنظمة وأتمتة الاختبارات وتعزيز أمنك.

··الخلاصات·اتصال·الخصوصية·© 2026 Kitploit

دليل الأدوات

الفئات

عرض جميع الفئات
Loading categories
CVE-2021-3156-Project — بيئة مختبر تعليمية لثغرة CVE-2021-3156 (Baron Samedit) مع هدف sudo هش مُعبأ في Docker، وسقالة استغلال، واختبار كاناري، وتحليل السبب الجذري، ومقارنة مع النسخة المُصحّحة. | Kitploit
أدوات/GitHubGitHub/shams-ul-mehmood/cve-2021-3156-project
تصعيد الامتيازاتتحليل الثغرات الأمنيةالاستغلالالتعلم والتعليماستغلال الملفات الثنائيةمختبرات وتدريب عملي
GitHubshams-ul-mehmood/cve-2021-3156-project

CVE-2021-3156-Project

بيئة مختبر تعليمية لثغرة CVE-2021-3156 (Baron Samedit) مع هدف sudo هش مُعبأ في Docker، وسقالة استغلال، واختبار كاناري، وتحليل السبب الجذري، ومقارنة مع النسخة المُصحّحة.

الأكثر شعبية

عرض الكل →

اكتشف الأدوات الأكثر استخدامًا من قبل مجتمعنا.

استكشف جميع الأدوات

تصفح مجموعتنا من الأدوات

عرض جميع الأدوات →
مشاركة
عرض المستودع
5منذ 21 أياملم تتم المراجعة بعد

CVE-2021-3156 — Baron Samedit

تجاوز سعة المخزن المؤقت في الكومة في sudo → تصعيد الصلاحيات محليًا

قسم الأمن السيبراني في ITSOLERA | تدريب الفريق الأحمر 2026


root@kitploit:~
  ██████╗  █████╗ ██████╗  ██████╗ ███╗   ██╗    ███████╗ █████╗ ███╗   ███╗███████╗██████╗ ██╗████████╗
  ██╔══██╗██╔══██╗██╔══██╗██╔═══██╗████╗  ██║    ██╔════╝██╔══██╗████╗ ████║██╔════╝██╔══██╗██║╚══██╔══╝
  ██████╔╝███████║██████╔╝██║   ██║██╔██╗ ██║    ███████╗███████║██╔████╔██║█████╗  ██║  ██║██║   ██║
  ██╔══██╗██╔══██║██╔══██╗██║   ██║██║╚██╗██║    ╚════██║██╔══██║██║╚██╔╝██║██╔══╝  ██║  ██║██║   ██║
  ██████╔╝██║  ██║██║  ██║╚██████╔╝██║ ╚████║    ███████║██║  ██║██║ ╚═╝ ██║███████╗██████╔╝██║   ██║
  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝    ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚══════╝╚═════╝ ╚═╝   ╚═╝

⚠️ للاستخدام التعليمي / المختبر المعزول فقط يجب إجراء جميع الاختبارات حصريًا داخل حاوية مختبر Docker. لا تقم أبدًا بالتشغيل ضد أنظمة حقيقية أو إنتاجية أو مشتركة.


جدول المحتويات

  1. نظرة عامة على CVE
  2. ما الذي يجعل هذا CVE مميزًا
  3. هيكل المشروع
  4. مخرجات الفريق
  5. البدء السريع
  6. كيف يعمل الاستغلال
  7. اختبار Canary للثغرة
  8. استخدام exploit.py
  9. إعادة تعيين المختبر واللقطة
  10. المقارنة: المُصحَّحة مقابل الهشّة
  11. المراجع

نظرة عامة على CVE


ما الذي يجعل هذا CVE مميزًا

الرؤية الأساسية: يحدث التجاوز في set_cmnd() — وهي الوظيفة التي تحلل الوسائط — والتي تعمل قبل أن يرجع sudo إلى /etc/sudoers على الإطلاق. يمكن لحساب أُنشئ قبل 10 ثوانٍ فقط وبدون أي صلاحيات استغلال هذا الأمر.


هيكل المشروع

root@kitploit:~
CVE-2021-3156-Project/
│
├── README.md                        ← you are here
│
├── lab/                             ← Member 1: Lab Environment
│   ├── Dockerfile                   ← Ubuntu 20.04 + sudo 1.8.31 (pinned)
│   ├── docker-compose.yml           ← vulnerable target + patched reference
│   ├── evidence_helper.sh           ← pre/post-exploit state capture
│   ├── SETUP.md                     ← step-by-step VM/Docker guide
│   └── config_notes.md              ← CVE conditions & container details
│
├── exploit/                         ← Member 2: Exploit Development
│   ├── exploit.py                   ← Python LPE framework + canary test
│   └── payloads.txt                 ← heap overflow research notes
│
├── docs/                            ← Member 3: Research & Documentation
│   ├── root_cause_analysis.md       ← set_cmnd() deep dive + off-by-one
│   ├── references.md                ← all sources, PoCs, CWE mapping
│   └── mitigation.md                ← sudo upgrade + hardening checklist
│
├── proof/                           ← Member 4: Evidence Collection
│   ├── screenshots/                 ← exploitation screenshots
│   └── terminal_logs.txt            ← command output template + logs
│
└── report/
    └── CVE-2021-3156_Report.docx    ← Member 4: Final professional report

مخرجات الفريق

العضو 1 — بيئة المختبر والتحقق من CVE

العضو 2 — تطوير الاستغلال (سكربت PoC)

ملاحظة: لا يتضمن كود استغلال النواة/الكومة الفعلي التزامًا بالمبادئ الأخلاقية. تشير أكواد TODO في exploit.py إلى https://github.com/blasty/CVE-2021-3156 و https://github.com/worawit/CVE-2021-3156 باعتبارها PoCs العامة الموثوقة لفريقك لدراستها ودمجها.

العضو 3 — تحليل السبب الجذري والبحث

الملفالوصف
docs/root_cause_analysis.mdتفصيلي: عدم تطابق الحجم مقابل النسخ في ، خطأ off-by-one مع أمثلة برمجية، فرق التصحيح، سلسلة الاستغلال، CVSS 7.8 مقياسًا بمقياس، خط زمني لـ10 سنوات، جدول تأثير التوزيعات

العضو 4 — جمع الأدلة والتقارير والتكامل

الملفالوصف
proof/terminal_logs.txtقالب لجمع الأدلة (املأه بالمخرجات الفعلية من المختبر)
proof/screenshots/مجلد لـ7 لقطات شاشة مطلوبة
report/CVE-2021-3156_Report.docxتقرير احترافي من 12 قسمًا: صفحة الغلاف، الملخص التنفيذي، وصف CVE، تحليل السبب الجذري، تفصيل CVSS، خطوات الاستغلال، شرح الكود، قائمة التحقق من الأدلة، التخفيف، الخط الزمني، المراجع، إخلاء المسؤولية

البدء السريع

1. البناء وبدء تشغيل المختبر

root@kitploit:~
cd CVE-2021-3156-Project/lab/

# Build the vulnerable image (downloads Ubuntu 20.04, pins sudo 1.8.31)
docker compose build

# Start both containers
docker compose up -d

# Confirm containers are running
docker compose ps

المتوقع:

root@kitploit:~
NAME                      STATUS
baron_samedit_target      running
baron_samedit_patched     running

2. الدخول إلى الحاوية الهشّة

root@kitploit:~
docker exec -it baron_samedit_target bash

3. تأكيد شروط الثغرة

root@kitploit:~
# Inside the container as labuser

whoami                         # Expected: labuser
id                             # Expected: uid=1000(labuser)...
sudo --version                 # Expected: Sudo version 1.8.31
sudo -l                        # Expected: Sorry, user labuser may not run sudo...
sudoedit -s '\' 2>&1          # Expected: NOT "usage:" → VULNERABLE

4. نسخ وتشغيل الاستغلال

root@kitploit:~
# From host machine
docker cp exploit/exploit.py baron_samedit_target:/home/labuser/

# Inside container
python3 exploit.py --check-only      # verify all prerequisites pass
python3 exploit.py --safe-mode       # canary only, no exploitation
python3 exploit.py --cmd "id"        # LPE → show root identity
python3 exploit.py --cmd "whoami /all" --output /tmp/proof.txt

5. التقاط الأدلة

root@kitploit:~
# Inside container — before exploit
~/evidence_helper.sh > /tmp/before.txt

# After exploit
~/evidence_helper.sh > /tmp/after.txt

# Copy to host
docker cp baron_samedit_target:/tmp/before.txt proof/terminal_logs_before.txt
docker cp baron_samedit_target:/tmp/after.txt  proof/terminal_logs_after.txt

كيف يعمل الاستغلال

root@kitploit:~
Step 1: Run 'sudoedit -s <crafted_argument>'
        ↓
Step 2: sudo calls set_cmnd() to parse arguments in shell mode
        ↓
Step 3: set_cmnd() COUNTS bytes for the cmnd_args buffer (correct size)
        ↓
Step 4: set_cmnd() COPIES bytes — but reads 1 byte past the null
        terminator of any argument ending with '\'
        ↓
Step 5: Off-by-one overflow writes 1 unexpected byte beyond cmnd_args
        ↓
Step 6: Heap grooming (environment variable layout manipulation) ensures
        a valuable sudo struct sits adjacent to the overflowed buffer
        ↓
Step 7: The overflow byte corrupts a pointer in the adjacent struct
        ↓
Step 8: sudo follows the corrupted pointer → executes attacker-controlled
        command (via SUDO_EDITOR) with root privileges
        ↓
Result: uid=0(root) — from a user with ZERO sudo permissions

السبب الجذري في سطر واحد

root@kitploit:~
size_calculation("A\") = 2 bytes  ≠  copy("A\") = writes 3 bytes → overflow

اختبار Canary للثغرة

الطريقة الأكثر أمانًا لتأكيد وجود CVE-2021-3156 — دون الحاجة إلى أي استغلال:

root@kitploit:~
sudoedit -s '\' 2>&1; echo "Exit: $?"

استخدام exploit.py

root@kitploit:~
Usage: python3 exploit.py [OPTIONS]

Modes (mutually exclusive):
  --check-only        Run all pre-checks only — no exploitation
  --safe-mode         Run canary test only — confirm vulnerability
  --cmd COMMAND       Execute COMMAND as root after successful LPE

Options:
  --verbose, -v       Show detailed heap/system debug output
  --output, -o FILE   Save all output to FILE
  --no-colour         Disable ANSI colour codes (for log files)
  --help              Show this help message

Examples:
  python3 exploit.py --check-only
  python3 exploit.py --safe-mode
  python3 exploit.py --cmd "id"
  python3 exploit.py --cmd "cat /etc/shadow" --output proof/root_output.txt
  python3 exploit.py --cmd "whoami" --verbose

الفحوصات المسبقة التي يتم تنفيذها


إعادة تعيين المختبر واللقطة

إعادة تعيين سريعة (إبقاء الحاوية، مسح الملفات المؤقتة)

root@kitploit:~
docker exec baron_samedit_target bash -c "rm -f /tmp/*.txt /tmp/exploit* /home/labuser/exploit.py"

حفظ لقطة

root@kitploit:~
docker commit baron_samedit_target baron-samedit:clean-state
echo "[+] Snapshot saved as baron-samedit:clean-state"

استعادة اللقطة

root@kitploit:~
docker compose down
docker run -it --name baron_samedit_target baron-samedit:clean-state bash

إعادة تعيين كاملة (إعادة بناء من الصفر)

root@kitploit:~
docker compose down -v
docker compose up -d --build

المقارنة: المُصحَّحة مقابل الهشّة

للاختبار على الحاوية المُصحَّحة:

root@kitploit:~
docker exec -it baron_samedit_patched bash
# Then repeat the canary test — should output "invalid argument"

المراجع


إشعار أخلاقي

root@kitploit:~
┌─────────────────────────────────────────────────────────────────┐
│  This project was created for EDUCATIONAL PURPOSES ONLY as      │
│  part of the ITSOLERA Cybersecurity Red Team Internship 2026.   │
│                                                                 │
│  ✅ DO:  Use against the isolated Docker lab only               │
│  ✅ DO:  Study the vulnerability to understand heap exploits    │
│  ✅ DO:  Contribute findings to the team report                 │
│                                                                 │
│  ❌ DON'T: Run against any real system, VM, or cloud instance   │
│  ❌ DON'T: Share outside the internship programme               │
│  ❌ DON'T: Use for any unauthorised access                      │
└─────────────────────────────────────────────────────────────────┘

قسم الأمن السيبراني في ITSOLERA — تدريب الفريق الأحمر، صيف 2026

تنزيل الأداة
الخاصيةالقيمة
معرف CVECVE-2021-3156
الاسم المستعارBaron Samedit
النوعتجاوز سعة المخزن المؤقت في الكومة → تصعيد الصلاحيات محليًا
المكوّنsudo — أداة صلاحيات لينكس (set_cmnd() في src/sudo.c)
درجة CVSS v37.8 عالية
المتجهCVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
الإصدارات الهشّةsudo 1.8.2 – 1.8.31p2 و 1.9.0 – 1.9.5p1
الإصدارات المُصحَّحةsudo 1.9.5p2 (فرع 1.9) / sudo 1.8.32 (فرع 1.8)
إصدار هدف المختبرsudo 1.8.31 على Ubuntu 20.04
نشرة التصحيح / الاستشارةSA: https://www.sudo.ws/security/advisories/unescape_overflow/
اكتُشفت بواسطةفريق أبحاث Qualys
تاريخ الإفصاح2021-01-26
في البرية منذ (كود)~2011-07-09 (sudo 1.8.2) — ~10 سنوات دون اكتشاف
المصادقة المطلوبةمستخدم محلي فقط — لا حاجة لأي صلاحيات sudo
الخاصيةCVE-2021-3156استغلال sudo LPE نموذجي
يتطلب إدخال sudoers❌ لا✅ نعم
يتطلب عضوية مجموعة sudo❌ لا✅ نعم
يتطلب أي وصول sudo سابق❌ لا✅ نعم
يعمل من حساب مستخدم جديد تمامًا✅ نعم❌ لا
يستغل نظام الصلاحيات❌ يتجاوزه تمامًا✅ يسيء استخدامه
سطح الهجوممحلل الوسائط (قبل المصادقة)فحص الصلاحيات
الملفالوصف
lab/DockerfileUbuntu 20.04 مع تثبيت sudo 1.8.31 (هشّ)؛ Python 3 مثبّت؛ حساب labuser بدون أي وصول sudo
lab/docker-compose.ymlينسّق بين الهدف الهشّ + حاوية مرجعية مُصحَّحة على Ubuntu 22.04
lab/evidence_helper.shسكربت Bash لالتقاط حالة النظام (المستخدم، إصدار sudo، canary) قبل/بعد الاستغلال
lab/SETUP.mdخطوة بخطوة: البناء ← التشغيل ← الدخول ← التحقق من إصدار sudo ← تشغيل canary ← اللقطة
lab/config_notes.mdيشرح لماذا لا حاجة لأي إعدادات خاطئة، إعدادات أمان Docker، مرجع بيانات الاعتماد
الملفالوصف
exploit/exploit.pyإطار عمل Python كامل: check_platform()، check_sudo_version()، run_canary_test()، get_system_info() + ثلاثة أكواد TODO استغلالية (select_heap_strategy، build_overflow_argument، trigger_overflow_and_escalate) مع مراجع تفصيلية لـ PoCs الخاصة بـ blasty/worawit
exploit/payloads.txtمفاهيم تجاوز الكومة، مكافئ COMPRESSION_TRANSFORM (بنية الوسائط)، ثلاث استراتيجيات للكومة، قالب سجل المحاولات الفاشلة، توقيعات الكشف
set_cmnd()
docs/references.mdاستشارة Qualys، MITRE، NVD، مشروع sudo، blasty PoC، worawit PoC، ExploitDB، GTFOBins، تعيين CWE
docs/mitigation.mdapt-get install --only-upgrade sudo، canary للتحقق، تقوية AppArmor، مراقبة auditd، جدول التقوية
المخرجالمعنى
sudoedit: /\: not a regular file✅ هشّة
Segmentation fault / Exit: 139✅ هشّة (تعطل)
sudoedit: invalid argument❌ مُصحَّحة (1.9.5p2+)
usage: sudoedit ...❌ مُصحَّحة
الفحصما الذي يفعله
المنصة (Linux)يضمن أننا على Linux
وجود sudoeditيبحث عن sudoedit في PATH
إصدار sudoيقارن مع النطاق الهشّ (1.8.2–1.8.31p2، 1.9.0–1.9.5p1)
عدم كونك root بالفعليؤكد أن UID ≠ 0 (تصعيد الصلاحيات ذو معنى)
معلومات النظاميجمع إصدار glibc + البنية لاستراتيجية الكومة
Canary الثغرةيشغّل sudoedit -s '\' ويصنّف الاستجابة
الاختبارهشّة (sudo 1.8.31)مُصحَّحة (sudo 1.9.5p2+)
sudo --versionSudo version 1.8.31Sudo version 1.9.x
sudoedit -s '\'not a regular file أو segfaultinvalid argument
exploit.py --safe-modeCanary: PASS → هشّةCanary: FAIL → مُصحَّحة
exploit.py --cmd iduid=0(root)يفشل في مرحلة الفحص
التصحيح موجود؟النشرة غائبةتم تطبيق التصحيح
المصدرالرابط
استشارة Qualyshttps://blog.qualys.com/vulnerabilities-threat-research/2021/01/26/cve-2021-3156-heap-based-buffer-overflow-in-sudo-baron-samedit
MITRE CVEhttps://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3156
NVDhttps://nvd.nist.gov/vuln/detail/CVE-2021-3156
استشارة sudohttps://www.sudo.ws/security/advisories/unescape_overflow/
blasty PoChttps://github.com/blasty/CVE-2021-3156
worawit PoChttps://github.com/worawit/CVE-2021-3156
ExploitDB #49521https://www.exploit-db.com/exploits/49521
Rapid7 Metasploithttps://www.rapid7.com/db/modules/exploit/linux/local/sudo_baron_samedit/
GTFOBins — sudohttps://gtfobins.github.io/gtfobins/sudo/