flawopen.com/Teardowns/cve-2021-3156-sudo-baron-samedit
Sudo Baron Samedit 漏洞 (CVE-2021-3156) 深度剖析:参数解析逻辑对末尾反斜杠的转义失误,如何让系统任意无特权用户在默认配置下直接拿到 Root 权限。
想象一下公文审核员有一条铁律:遇到反斜杠转义符,就必须把后面的那个字符原样抄下来。有人故意递交了一份以反斜杠结尾的申请表。审核员在纸面上找不到下一个字符,不仅没有停止,反而笔尖直接划出纸张边缘,抄到桌面底下的绝密档案堆上,将档案上的'禁止进入'涂改成了'放行'。
setuid 二进制文件堆缓冲区溢出本地权限提升根本原因在于开源系统中未经验证的边界参数,导致状态不同步并绕过安全控制。
Unprivileged user executes 'sudoedit -s \', bypassing normal argument escaping flags.
The unescape pointer jumps past the null byte delimiter into uninitialized heap memory.
The heap overflow overwrites the sudo_nss service structure in glibc.
Sudo loads an attacker-controlled shared library (/tmp/libnss_x.so.2) as root, granting instant root shell access.
/* VULNERABLE: Unescape loop skips past string termination null byte */
for (to = user_args, from = NewArgv[0]; *from != '\0'; from++) {
if (from[0] == '\\' && !isspace((unsigned char)from[1]))
from++; /* BUG: If from[1] == '\0', loop skips past null terminator! */
*to++ = *from;
}
*to = '\0'; /* Corrupts adjacent heap chunks with root auth structures */
/* FIXED: Explicitly check that from[1] is neither space nor the null byte */
for (to = user_args, from = NewArgv[0]; *from != '\0'; from++) {
if (from[0] == '\\' && from[1] != '\0' && !isspace((unsigned char)from[1]))
from++;
*to++ = *from;
}
*to = '\0';