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
CVE-2021-3156-Baron-Samedit — Exploitation and mitigation analysis of CVE-2021-3156 heap-based buffer overflow in sudo | Kitploit
Tools/GitHubGitHub/kranti08/cve-2021-3156-baron-samedit
Privilege EscalationVulnerability AnalysisExploitationPenetration TestingLearning & EducationBinary ExploitationLabs & Practice
GitHub
Share
kranti08/cve-2021-3156-baron-samedit

CVE-2021-3156-Baron-Samedit

Exploitation and mitigation analysis of CVE-2021-3156 heap-based buffer overflow in sudo

View Repository
545 months agoNot yet reviewed

CVE-2021-3156 – Baron Samedit

Heap-Based Buffer Overflow in sudo | Exploitation & Mitigation Analysis

CVE Severity OS Status Language

Overview

CVE-2021-3156, known as Baron Samedit, is a heap-based buffer overflow vulnerability in the sudo program. It allows any unprivileged local user to gain root privileges on vulnerable systems without authentication.

This project documents the full exploitation and mitigation of this vulnerability as part of the Software Vulnerabilities: Exploitation and Mitigation course at the University of Luxembourg.


Vulnerability Details

PropertyDetails
CVE IDCVE-2021-3156
NicknameBaron Samedit
TypeHeap-Based Buffer Overflow
Componentsudo (sudoedit mode)
ImpactLocal Privilege Escalation to Root
Affected Versionssudo ≤ 1.8.31 (Ubuntu), ≤ 1.9.5p1 (others)
Patched Versionsudo 1.8.31-1ubuntu1.5
CVSS Score7.8 (High)

Environment & Setup

OS:           Ubuntu 20.04.1
sudo version: 1.8.31-1ubuntu1 (vulnerable)
libc version: 2.31
User:         Non-root account

To reproduce the vulnerable state:

sudo apt install sudo=1.8.31-1ubuntu1

How the Vulnerability Works

The vulnerability is triggered when sudo is executed in sudoedit mode with carefully crafted command-line arguments that overflow internal heap buffers.

The exploit uses four critical parameters fine-tuned through memory analysis:

ParameterSizePurpose
A56 bytesOverflow the initial buffer
B54 bytesOverflow a second heap chunk
Nulls63 bytesStructure memory alignment
LC_ALL212 bytesControl heap layout via environment variable

Exploit Structure

exploit_launcher.c — Main Exploit

Triggers the vulnerability through 5 steps:

  1. Target Specification — Hardcoded values calculated for Ubuntu 20.04.1 with sudo 1.8.31 and libc-2.31
  2. Argument Construction — Creates crafted command-line arguments with backslashes to trigger the overflow
  3. Environment Setup — Fills environment with backslashes and a special string to load the malicious library
  4. Locale Variable — Crafts LC_ALL to control heap memory layout
  5. Execution — Calls sudoedit with the malicious arguments and environment

exploit_payload.c — Malicious Payload

Executed automatically when the exploit succeeds via _init function:

  1. Sets all user/group IDs to 0 (root)
  2. Spawns a root shell

Exploitation Result

$ make
$ ./exploit_it

[!] CVE-2021-3156 Exploit
[+] Target: Ubuntu 20.04.1 (sudo 1.8.31, libc-2.31)
[+] Parameters: A=56, B=54, Nulls=63, LC_ALL=212
[+] Launching exploit...
[+] Exploit successful. Root privileges obtained.
# whoami
root

✅ Successfully escalated from unprivileged user to root.


Mitigation & Patch Verification

Upgrade sudo to the patched version:

sudo apt install sudo=1.8.31-1ubuntu1.5

After upgrading, the same exploit failed to execute and root privileges were not granted — confirming the patch is effective.

Key takeaway: Keeping system utilities like sudo up to date is critical for preventing privilege escalation attacks.


Files

├── exploit_launcher.c    # Main exploit triggering the heap overflow
├── exploit_payload.c     # Malicious payload spawning root shell
├── libnss_X/             # Malicious library loaded during exploitation
└── Makefile              # Build configuration

Build & Run

# Build
make

# Run exploit
./exploit_it

References

  • Qualys Security Advisory
  • NVD – CVE-2021-3156

Download Tool

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    916
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    558
  • 3

    redforge

    cybersecurity91/redforge

    Browser-side red team toolkit with 102 offline tools for recon, payload generation, credential attacks, crypto, encoding and engagement reporting.

    370
  • 4

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    360
  • 5

    looking-glass

    anonghosty/looking-glass

    CSIRT platform that ingests Shadowserver reports into MongoDB and replays them as interactive maps, analysis, findings, advisories and executive dashboards.

    317
  • 6

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    The system of action for AI-native cybersecurity—where intent becomes governed execution, evidence becomes operational memory, and every operation improves the next.

    289

Explore all tools

Browse our collection of tools

View all tools →