flawopen.com/Teardowns/cve-2021-3156-sudo-baron-samedit
Autopsie technique de Baron Samedit (CVE-2021-3156) : comment un caractère d'échappement mal géré dans sudo a offert les privilèges root à tout utilisateur local.
Imaginez un employé qui traite des formulaires avec la consigne : un antislash signifie 'traitez le caractère suivant littéralement'. Quelqu'un soumet une fiche se terminant par un antislash. L'employé continue d'écrire au-delà de la page et recopie par-dessus le document officiel suivant.
binaire setuiddébordement de tasélévation locale de privilègesLa cause fondamentale provient de paramètres de limites non validés dans les systèmes open source, permettant une désynchronisation d'état et le contournement des contrôles de sécurité.
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';