flawopen.com/Teardowns/cve-2021-3156-sudo-baron-samedit
Baron Samedit (CVE-2021-3156) का तकनीकी विश्लेषण: sudo के कमांड-लाइन आर्ग्युमेंट्स में बैकस्लैश की गलती ने कैसे किसी भी सामान्य यूज़र को Root एक्सेस दे दिया।
एक फॉर्म-प्रोसेसिंग क्लर्क की कल्पना करें जिसका एक नियम है: एक बैकस्लैश का मतलब है 'अगले अक्षर को शाब्दिक रूप से लें'। कोई एकल बैकस्लैश पर समाप्त होने वाला फॉर्म देता है। क्लर्क पन्ने के किनारे से आगे पढ़ना जारी रखता है और अगले फॉर्म पर सुरक्षा अनुमतियों को अधिलेखित (overwrite) कर देता है।
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';