CVE-2021-3156 — Baron Samedit
Heap-basierter Pufferüberlauf in sudo → Lokale Privilegienerweiterung
ITSOLERA-Abteilung für Cybersicherheit | Red-Team-Praktikum 2026
██████╗ █████╗ ██████╗ ██████╗ ███╗ ██╗ ███████╗ █████╗ ███╗ ███╗███████╗██████╗ ██╗████████╗
██╔══██╗██╔══██╗██╔══██╗██╔═══██╗████╗ ██║ ██╔════╝██╔══██╗████╗ ████║██╔════╝██╔══██╗██║╚══██╔══╝
██████╔╝███████║██████╔╝██║ ██║██╔██╗ ██║ ███████╗███████║██╔████╔██║█████╗ ██║ ██║██║ ██║
██╔══██╗██╔══██║██╔══██╗██║ ██║██║╚██╗██║ ╚════██║██╔══██║██║╚██╔╝██║██╔══╝ ██║ ██║██║ ██║
██████╔╝██║ ██║██║ ██║╚██████╔╝██║ ╚████║ ███████║██║ ██║██║ ╚═╝ ██║███████╗██████╔╝██║ ██║
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚═╝ ╚═╝
⚠️ NUR FÜR BILDUNGSZWECKE / ISOLIERTE LABORNUTZUNG
Sämtliche Tests müssen ausschließlich im Docker-Labcontainer durchgeführt werden.
Niemals gegen reale, produktive oder gemeinsam genutzte Systeme ausführen.
Inhaltsverzeichnis
- CVE-Überblick
- Was diese CVE besonders macht
- Projektstruktur
- Team-Ergebnisse
- Schnellstart
- So funktioniert der Exploit
- Canary-Test der Schwachstelle
- Verwendung von exploit.py
- Labor-Reset & Snapshot
- Vergleich: Gepatcht vs. Verwundbar
- Referenzen
CVE-Überblick
Was diese CVE besonders macht
Wichtige Erkenntnis: Der Überlauf tritt in set_cmnd() auf — der Funktion, die Argumente parst — die ausgeführt wird, bevor sudo jemals /etc/sudoers konsultiert. Ein Konto, das vor 10 Sekunden mit null Berechtigungen erstellt wurde, kann dies ausnutzen.
Projektstruktur
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
Team-Ergebnisse
Mitglied 1 — Laborumgebung & CVE-Verifizierung
Mitglied 2 — Exploit-Entwicklung (PoC-Skript)
Hinweis: Arbeitsfähiger Kernel-/Heap-Exploit-Code ist gemäß ethischer Richtlinien nicht enthalten.
Die TODO-Stubs in exploit.py verweisen auf https://github.com/blasty/CVE-2021-3156
und https://github.com/worawit/CVE-2021-3156 als maßgebliche öffentliche PoCs,
damit Ihr Team sie studieren und integrieren kann.
Mitglied 3 — Ursachenanalyse & Recherche
| Datei | Beschreibung |
|---|
docs/root_cause_analysis.md |
Mitglied 4 — Beweissammlung, Berichterstattung & Integration
| Datei | Beschreibung |
|---|
proof/terminal_logs.txt | Vorlage zur Beweissammlung (mit tatsächlicher Laborausgabe ausfüllen) |
proof/screenshots/ | Verzeichnis für 7 erforderliche Screenshots |
report/CVE-2021-3156_Report.docx | Professioneller Bericht mit 12 Abschnitten: Deckblatt, Executive Summary, CVE-Beschreibung, Ursachenanalyse, CVSS-Aufschlüsselung, Exploit-Schritte, Code-Erklärung, Beweis-Checkliste, Maßnahmen, Zeitverlauf, Referenzen, Haftungsausschluss |
Schnellstart
1. Labor bauen und starten
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
Erwartete Ausgabe:
NAME STATUS
baron_samedit_target running
baron_samedit_patched running
2. Verwundbaren Container betreten
docker exec -it baron_samedit_target bash
3. Verwundbarkeitsbedingungen bestätigen
# 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. Exploit kopieren und ausführen
# 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. Beweise erfassen
# 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
So funktioniert der Exploit
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
Die Ursache in einer Zeile
size_calculation("A\") = 2 bytes ≠ copy("A\") = writes 3 bytes → overflow
Canary-Test der Schwachstelle
Der sicherste Weg, um festzustellen, ob CVE-2021-3156 vorhanden ist — keine Ausnutzung erforderlich:
sudoedit -s '\' 2>&1; echo "Exit: $?"
Verwendung von exploit.py
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
Durchgeführte Vorprüfungen
Labor-Reset & Snapshot
Schnell-Reset (Container behalten, temporäre Dateien löschen)
docker exec baron_samedit_target bash -c "rm -f /tmp/*.txt /tmp/exploit* /home/labuser/exploit.py"
Snapshot speichern
docker commit baron_samedit_target baron-samedit:clean-state
echo "[+] Snapshot saved as baron-samedit:clean-state"
Snapshot wiederherstellen
docker compose down
docker run -it --name baron_samedit_target baron-samedit:clean-state bash
Vollständiger Reset (von Grund auf neu aufbauen)
docker compose down -v
docker compose up -d --build
Vergleich: Gepatcht vs. Verwundbar
Zum Testen im gepatchten Container:
docker exec -it baron_samedit_patched bash
# Then repeat the canary test — should output "invalid argument"
Referenzen
Ethische Hinweise
┌─────────────────────────────────────────────────────────────────┐
│ 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-Abteilung für Cybersicherheit — Red-Team-Praktikum, Sommer 2026