A CVE Journey: From Crash to Local Privilege Escalation
A stack-based buffer overflow in sudo's password prompt (getln) when pwfeedback is enabled allows an unprivileged user to overwrite the user_details struct and set uid to 0, leading to local privilege escalation. The exploit uses a pseudo-terminal that cannot be written to, causing the write to fail and the buffer pointer not to reset.
iamalsaher.tech
Published on iamalsaher.tech
My journey started with a member in the OpenToAll slack group posting a link for some CVE advisory. Going through the advisory highlights some of the points which made me think I can use this bug for my first CVE POC.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the getln function does not reset the buffer pointer when a write to the terminal fails after a kill character, allowing the pointer to advance beyond the buffer and overwrite adjacent memory.
Impact
An unprivileged user could escalate to root, but only if pwfeedback is enabled.
What the attacker needed
Sudo with pwfeedback enabled; local user account; ability to run sudo
The fix
The bug was fixed in sudo 1.8.31 by correcting the buffer pointer handling.
How it was found
- Set up a Docker container with sudo 1.8.25p1 and pwfeedback enabled in /etc/sudoers.
- Create a pseudo-terminal and open its slave side read-only to make writes fail.
- Run sudo with -S and provide a payload containing kill characters (0x15) to trigger the overflow.
- Overwrite tgetpass_flags to set TGP_ASKPASS and then overwrite user_details.uid to 0.
- Set SUDO_ASKPASS to a script that runs a reverse shell.
- Trigger the overflow to execute the script as root.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
sudo is a program that lets users run commands as root. A bug in how it reads your password when the 'pwfeedback' option is on lets an attacker overflow a buffer and change a stored user ID to zero, which means root. The attacker needs to be able to run sudo and have pwfeedback enabled.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.