flawopen.com/Teardowns/cve-2021-3156-sudo-baron-samedit
Technische Analyse von Baron Samedit (CVE-2021-3156): Wie ein Backslash am Argumentende in sudo jedem lokalen Benutzer unbeschränkten Root-Zugriff verschaffte.
Stellen Sie sich einen Sachbearbeiter vor, der Formulare prüft: Ein Backslash bedeutet 'interpretiere das nächste Zeichen wörtlich'. Endet ein Formular auf einen Backslash, liest er über den Seitenrand hinaus und überschreibt administrative Sicherheitsberechtigungen auf nachfolgenden Dokumenten.
Setuid-BinärdateiHeap-ÜberlaufLokale RechteausweitungDie Grundursache liegt in nicht validierten Grenzparametern in Open-Source-Systemen, die eine Zustandsdesynchronisation und die Umgehung von Sicherheitskontrollen ermöglichen.
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';