
Baron Samedit: sudoedit off-by-one heap overflow gives root. Fixed in 1.9.5p2. Differential: overflow on vuln, refused on fixed
| CVE | CVE-2021-3156 |
| Component | sudo — sudoedit command line parser |
| Affected | sudo before 1.9.5p2 |
| Fixed in | 1.9.5p2 |
| CWE | CWE-193 (Off-by-one Error) |
| Impact | An off-by-one error when escaping command-line arguments could overflow a heap buffer in sudoedit, allowing a local user to gain root privileges. |
| Vector | sudoedit -s with an argument ending in a backslash |
| Trigger | trailing single backslash argument |
The vulnerable path:
# pre-fix (model from sudo Baron Samedit advisory)
attacker input accepted without the required protection
The derived guard:
# derived from observed behaviour, not copied from a vendor fix
reject arguments ending in a single backslash
The escaping loop allocated one byte too few. The fix corrects the length calculation.
| service | image | role |
|---|---|---|
sd-vuln | cve-2021-3156:vuln | vulnerable behaviour present |
sd-guard | cve-2021-3156:guard | fixed behaviour |
poc | cve-2021-3156-poc:local | stdlib-only Python driver |
Both sides are Python 3.12 images. The vulnerable behaviour is modelled from sudo Baron Samedit advisory; the guard is derived from the lab observation that the impact is reproduced. The fixed build applies the published upstream change.
./run-lab.sh build
./run-lab.sh up
./run-lab.sh sweep
./run-lab.sh down
The lab uses the isolated cve3156lab network and bounded containers.
poc/poc.py takes a mode and an optional --host=...:
| mode | result |
|---|---|
check | exit 1 when the buffer is overflowed, 0 when the argument is refused |
exploit | runs the full chain and reports the observed impact |
probe | prints the overflow flag |
mitigation | explains the derived guard |
A standalone exploit ships at exploit/exploit.py:
python3 exploit/exploit.py --host=sd-vuln
It exits 1 on a confirmed finding and 0 on a guarded target.
sd-vuln (pre-fix) | sd-guard (derived) | |
|---|---|---|
| crafted request | root escalation | refused |
| ordinary request | works | works |
Captured runs are in evidence/check-*-run.txt, evidence/exploit-*-run.txt,
evidence/probe-*-run.txt, evidence/mitigation-*-run.txt,
evidence/exploit-standalone-run.txt,
evidence/exploit-standalone-fixed-run.txt, evidence/versions.txt and
evidence/0day-sweep.txt.
Podman or Docker with the cve3156lab network. No production system is
involved. Real-world exploitation needs an affected installation.
Ordinary requests still succeed on the fixed build.
README.md this write-up
run-lab.sh environment driver (build / up / sweep / down)
Makefile convenience targets
poc/poc.py the PoC (check / exploit / probe / mitigation)
exploit/exploit.py standalone exploit
lab/harness-*.py vulnerable behaviour / derived guard
lab/lab.Dockerfile builds both sides
lab/service.py HTTP wrapper (POST /check)
evidence/ captured runs on both sides
TRACKING.md working record, excluded from the repo