Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
Tools/GitHubGitHub/shams-ul-mehmood/cve-2021-3156-project
Privilege EscalationVulnerability AnalysisExploitationLearning & EducationBinary ExploitationLabs & Practice
GitHubshams-ul-mehmood/cve-2021-3156-project

CVE-2021-3156-Project

Educational lab environment for CVE-2021-3156 (Baron Samedit) with a Dockerized vulnerable sudo target, exploit scaffold, canary test, root-cause analysis, and patched comparison.

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share
View Repository
171 month agoNot yet reviewed

CVE-2021-3156 — Baron Samedit

Heap-Based Buffer Overflow in sudo → Local Privilege Escalation

ITSOLERA Cybersecurity Department | Red Team Internship 2026


  ██████╗  █████╗ ██████╗  ██████╗ ███╗   ██╗    ███████╗ █████╗ ███╗   ███╗███████╗██████╗ ██╗████████╗
  ██╔══██╗██╔══██╗██╔══██╗██╔═══██╗████╗  ██║    ██╔════╝██╔══██╗████╗ ████║██╔════╝██╔══██╗██║╚══██╔══╝
  ██████╔╝███████║██████╔╝██║   ██║██╔██╗ ██║    ███████╗███████║██╔████╔██║█████╗  ██║  ██║██║   ██║
  ██╔══██╗██╔══██║██╔══██╗██║   ██║██║╚██╗██║    ╚════██║██╔══██║██║╚██╔╝██║██╔══╝  ██║  ██║██║   ██║
  ██████╔╝██║  ██║██║  ██║╚██████╔╝██║ ╚████║    ███████║██║  ██║██║ ╚═╝ ██║███████╗██████╔╝██║   ██║
  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝    ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚══════╝╚═════╝ ╚═╝   ╚═╝

⚠️ FOR EDUCATIONAL / ISOLATED LAB USE ONLY All testing must be performed exclusively inside the Docker lab container. Never run against real, production, or shared systems.


Table of Contents

  1. CVE Overview
  2. What Makes This CVE Special
  3. Project Structure
  4. Team Deliverables
  5. Quick Start
  6. How the Exploit Works
  7. Vulnerability Canary Test
  8. exploit.py Usage
  9. Lab Reset & Snapshot
  10. Patched vs Vulnerable Comparison
  11. References

CVE Overview

PropertyValue
CVE IDCVE-2021-3156
NicknameBaron Samedit
TypeHeap-Based Buffer Overflow → Local Privilege Escalation
Componentsudo — Linux privilege utility (set_cmnd() in src/sudo.c)
CVSS v3 Score7.8 High
VectorCVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Vulnerable Versionssudo 1.8.2 – 1.8.31p2 and 1.9.0 – 1.9.5p1
Patched Versionssudo 1.9.5p2 (1.9 branch) / sudo 1.8.32 (1.8 branch)
Lab Target Versionsudo 1.8.31 on Ubuntu 20.04
Patch KB / AdvisorySA: https://www.sudo.ws/security/advisories/unescape_overflow/
Discovered ByQualys Research Team
Disclosed2021-01-26
In Wild Since (code)~2011-07-09 (sudo 1.8.2) — ~10 years undetected
Auth RequiredLocal user only — NO sudo permissions needed

What Makes This CVE Special

PropertyCVE-2021-3156Typical Sudo LPE
Requires sudoers entry❌ No✅ Yes
Requires sudo group membership❌ No✅ Yes
Requires any prior sudo access❌ No✅ Yes
Works from brand-new user account✅ Yes❌ No
Exploits permission system❌ Bypasses entirely✅ Abuses it
Attack surfaceArgument parser (pre-auth)Permission check

Key insight: The overflow happens in set_cmnd() — the function that parses arguments — which runs before sudo ever consults /etc/sudoers. An account created 10 seconds ago with zero permissions can exploit this.


Project Structure

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 Deliverables

Member 1 — Lab Environment & CVE Verification

FileDescription
lab/DockerfileUbuntu 20.04 with sudo 1.8.31 pinned (vulnerable); Python 3 installed; labuser account with NO sudo access
lab/docker-compose.ymlOrchestrates vulnerable target + patched Ubuntu 22.04 reference container
lab/evidence_helper.shBash script to capture system state (user, sudo version, canary) before/after exploit
lab/SETUP.mdStep-by-step: build → start → enter → verify sudo version → run canary → snapshot
lab/config_notes.mdExplains why no misconfig needed, Docker security settings, credential reference

Member 2 — Exploit Development (PoC Script)

FileDescription
exploit/exploit.pyFull Python framework: check_platform(), check_sudo_version(), run_canary_test(), get_system_info() + three exploit TODO stubs (select_heap_strategy, build_overflow_argument, trigger_overflow_and_escalate) with detailed references to blasty/worawit PoCs
exploit/payloads.txtHeap overflow concepts, COMPRESSION_TRANSFORM equivalent (argument structure), three heap strategies, failed attempt log template, detection signatures

Note: Working kernel/heap exploit code is not included per ethical guidelines. The exploit.py TODO stubs reference https://github.com/blasty/CVE-2021-3156 and https://github.com/worawit/CVE-2021-3156 as the authoritative public PoCs for your team to study and integrate.

Member 3 — Root Cause Analysis & Research

FileDescription
docs/root_cause_analysis.mdDetailed: set_cmnd() size vs copy mismatch, off-by-one with code examples, patch diff, exploit chain, CVSS 7.8 metric-by-metric, 10-year timeline, distribution impact table
docs/references.mdQualys advisory, MITRE, NVD, sudo project, blasty PoC, worawit PoC, ExploitDB, GTFOBins, CWE mapping
docs/mitigation.mdapt-get install --only-upgrade sudo, verification canary, AppArmor hardening, auditd monitoring, hardening table

Member 4 — Proof Collection, Reporting & Integration

FileDescription
proof/terminal_logs.txtEvidence collection template (fill in with actual lab output)
proof/screenshots/Directory for 7 required screenshots
report/CVE-2021-3156_Report.docx12-section professional report: cover page, executive summary, CVE description, root cause analysis, CVSS breakdown, exploitation steps, code explanation, proof checklist, mitigation, timeline, references, disclaimer

Quick Start

1. Build & Start the Lab

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

Expected:

NAME                      STATUS
baron_samedit_target      running
baron_samedit_patched     running

2. Enter the Vulnerable Container

docker exec -it baron_samedit_target bash

3. Confirm Vulnerability Conditions

# 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. Copy and Run the Exploit

Download Tool