Anatomy of A Remote Kernel Exploit: Dan Rosenberg
Anatomy of A Remote Kernel Exploit: Dan Rosenberg
Kernel Exploit
(Dartmouth Edition)
Dan Rosenberg
▪ Prior work
▪ Future work
▪ Instant root
▫ No need to escalate privileges
▪ Need to transition
▫ Interrupt context to process context to userland
8
3
Windows
Linux
2 *BSD
NetWare
12 Stack Overflow
Heap Overflow
Array Indexing
0
2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
▪ Parsing for this field reads length value from frame and
copies digipeater addresses without bounds checking,
causing a stack overflow
Get EIP
Unrestricted code
execution
Install kernel
backdoor
Restore and
recover
Get EIP
▪ Fairly trivial
Facilities
ROSE Total len =
0x00 FAC_NATIONAL FAC_NATIONAL_DIGIS 0x9090...
header Length = 0xff
XX
Get EIP
▪ Traditionally, return into
shellcode on stack
Unrestricted code
execution ▪ Problem 1: we don't
know where we are
▫ Trampolines are easy
Install kernel
backdoor
▪ Problem 2: softirq stack
is non-executable
Restore and
recover
ALIGN_EAX,
/*2*/ 0xffffffff,
▪ Calling convention has 0xffffffff,
arguments in registers /*1*/ RET,
/*4*/ POP_EDX,
0x00000004,
▪ ROP stub steps: /*3*/ 0xffffffff,
0xffffffff,
▫ Load (%esp & ~0xfff) /*2*/ 0xffffffff,
into %eax 0xffffffff,
Get EIP
▪ We now have traditional
shellcode executing on
the softirq stack!
Unrestricted code
execution ▪ Problem: length is
limited to 0xff (255),
minus what we've
Install kernel already used
backdoor
Get EIP
▪ We can execute
Unrestricted code arbitrary-length
execution payloads now!
Restore and
recover
inet_protos:
hook:
IPPROTO_IP <hook>: push edi
<hook+1>: push esi
IPPROTO_ICMP <hook+2>: push ebx
<hook+3>: push eax
...
...
net_protocol:
icmp_rcv:
handler <icmp_rcv>: push ebp
<icmp_rcv+1>: mov ebp,esp
err_handler <icmp_rcv+3>: push edi
<icmp_rcv+4>: push esi
... ...
Get EIP
Restore and
recover
▪ Problem: ROSE is a
module, we don't know
where the locks live
▪ A plan!
▫ Follow linked list until we find ROSE module
▫ Read module structure, find start of .data section
▫ Scan .data section for byte pattern of two
consecutive spinlocks (distinctive signature)
▫ Release them
struct thread_info {
struct task_struct *task; /* main task structure */
struct exec_domain *exec_domain; /* execution domain */
__u32 flags; /* low level flags */
__u32 status; /* thread synchronous flags */
__u32 cpu; /* current CPU */
int preempt_count; /* 0 => preemptable,
<0 => BUG */
...
};
Install userland
payload
▪ Check for magic tag and
packet type
Continue execution
Install userland
payload
▪ If “trigger” packet, need
to transition to process
context
Continue execution
Install userland
payload
▪ Want working ICMP stack
Continue execution
Inject userland
payload ▪ How to verify?
▫ thread_info →
task_struct → cred
Divert userland
execution ▫ Unstable, annoying...
Continue execution
Continue execution
Continue execution
Divert userland
execution
▪ Give original saved %eip
to userland shellcode for
later
Continue execution
▪ Overwrite pointer with
address of payload on
userland stack
Copyright © 2011 Virtual Security Research, LLC. 71
All Rights Reserved.
Keep on Running
Continue execution
▪ Ralf Baechle
▪ Nelson Elhage
▪ Kees Cook
▪ twiz, sgrakkyu
Company:
http://www.vsecurity.com
Personal:
http://www.vulnfactory.org
Exploit code:
https://github.com/djrbliss/rose-exploit