Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:27654
HistoryFeb 13, 2012 - 12:00 a.m.

Advisory: sudo 1.8 Format String Vulnerability

2012-02-1300:00:00
vulners.com
9

Phenoelit Advisory <wir-haben-auch-mal-was-gefunden #0815 ±-++>

[ Authors ]
joernchen <joernchen () phenoelit de>

    Phenoelit Group &#40;http://www.phenoelit.de&#41;

[ Affected Products ]
sudo 1.8.0 - 1.8.3p1 (http://sudo.ws)

[ Vendor communication ]
2012-01-24 Send vulnerability details to sudo maintainer
2012-01-24 Maintainer is embarrased
2012-01-27 Asking maintainer how the fixing goes
2012-01-27 Maintainer responds with a patch and a release date
of 2012-01-30 for the patched sudo and advisory
2012-01-30 Release of this advisory

[ Description ]

    Observe src/sudo.c:

void
sudo_debug(int level, const char *fmt, …)
{
va_list ap;
char *fmt2;

if &#40;level &gt; debug_level&#41;
    return;

/* Backet fmt with program name and a newline to make it a single 
write */
easprintf&#40;&amp;fmt2, &quot;&#37;s: &#37;s&#92;n&quot;, getprogname&#40;&#41;, fmt&#41;;
va_start&#40;ap, fmt&#41;;
vfprintf&#40;stderr, fmt2, ap&#41;;
va_end&#40;ap&#41;;
efree&#40;fmt2&#41;;

}

    Here getprogname&#40;&#41; is argv[0] and by this user controlled. So 
    argv[0] goes to fmt2 which then gets vfprintf&#40;&#41;ed to stderr. The
    result is a Format String vulnerability.   

[ Example ]
/tmp $ ln -s /usr/bin/sudo %n
/tmp $ ./%n -D9
*** %n in writable segment detected***
Aborted
/tmp $

   A note regarding exploitability: The above example shows the result
   of FORTIFY_SOURCE which makes explotitation painful but not 
   impossible &#40;see [0]&#41;. Without FORTIFY_SOURCE the exploit is straight
   forward:
     1. Use formatstring to overwrite the setuid&#40;&#41; call with setgid&#40;&#41;
     2. Trigger with formatstring -D9 
     3. Make use of SUDO_ASKPASS and have shellcode in askpass script
     4. As askpass will be called after the formatstring has 
        overwritten setuid&#40;&#41; the askepass script will run with uid 0
     5. Enjoy the rootshell

[ Solution ]
Update to version 1.8.3.p2

[ References ]
[0] http://www.phrack.org/issues.html?issue=67&amp;id=9

[ end of file ]