Top Banner
Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University
61

Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Jul 15, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Hacking BlindAndrea Bittau, Adam Belay, Ali Mashtizadeh,

David Mazières, Dan Boneh

Stanford University

Page 2: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Hacking 101

Exploit

GET /0xDEAD HTTP/1.0

shell

$ cat /etc/passwd root:x:0:0:::/bin/sh sorbo:x:6:9:pac:/bin/sh

Page 3: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Crash or no Crash? Enough to build exploit

GET /blabla HTTP/1.0

HTTP/1.0 404 Not Found

GET /AAAAAAAAAAAAAAAA

connection closed

Page 4: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Don’t even need to know what application is running!

Exploit scenarios:

1. Open source

2. Open binary

3. Closed-binary (and source)????

Page 5: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Attack effectiveness

• Works on 64-bit Linux with ASLR, NX and canaries

Server Requests Time (mins)

nginx 2,401 1

MySQL 3,851 20

Toy proprietary service (unknown binary and source) 1,950 5

Page 6: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Attack requirements1. Stack vulnerability, and knowledge of how to

trigger it.

2. Server process that respawns after crash

• E.g., nginx, MySQL, Apache, OpenSSH, Samba.

Page 7: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Background Outline

• Stack Vulnerabilities

• No-eXecute memory (NX)

• Return-Oriented Programming (ROP)

• Address Space Layout Randomization (ASLR)

Page 8: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Stack vulnerabilitiesvoid process_packet(int s) {

char buf[1024];int len;

read(s, &len, sizeof(len));read(s, buf, len);

return;}

Stack:return address

0x400000

buf[1024]handle_client()

Page 9: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Stack vulnerabilitiesvoid process_packet(int s) {

char buf[1024];int len;

read(s, &len, sizeof(len));read(s, buf, len);

return;}

Stack:return address

0x400000

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

handle_client()

Page 10: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Stack vulnerabilitiesvoid process_packet(int s) {

char buf[1024];int len;

read(s, &len, sizeof(len));read(s, buf, len);

return;}

Stack:return address0x41414141

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

??

Page 11: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Stack vulnerabilitiesvoid process_packet(int s) {

char buf[1024];int len;

read(s, &len, sizeof(len));read(s, buf, len);

return;}

Stack:return address

0x500000

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Shellcode:

dup2(sock, 0);dup2(sock, 1);execve(“/bin/sh”, 0, 0);

Page 12: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Stack vulnerabilitiesvoid process_packet(int s) {

char buf[1024];int len;

read(s, &len, sizeof(len));read(s, buf, len);

return;}

Stack:return address

0x600000

0x1029827189123781923719823719287319879181823828

Shellcode:

dup2(sock, 0);dup2(sock, 1);execve(“/bin/sh”, 0, 0);

Page 13: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Exploit protectionsvoid process_packet(int s) {

char buf[1024];int len;

read(s, &len, sizeof(len));read(s, buf, len);

return;}

Stack:return address

0x600000

0x1029827189123781923719823719287319879181823828

Shellcode:

dup2(sock, 0);dup2(sock, 1);execve(“/bin/sh”, 0, 0);

2. Randomize memory addresses (ASLR)

1. Make stack non-executable (NX)

Page 14: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Non-eXecutable (NX) memory

.text (code)

heap

stack

.text (code)

heap

stack

ReadExecute

ReadWrite

ReadExecute

ReadWriteExecute

Page 15: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Non-eXecutable (NX) memory

.text (code)

heap

stack

.text (code)

heap

stack

ReadExecute

ReadWrite

ReadExecute

ReadWriteExecute

Page 16: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Return-Oriented Programming (ROP)

code fragment

.text:

...

...

...

...

dup2(sock, 0);dup2(sock, 1);execve(“/bin/sh”, 0, 0);

Stack:

0x800000

Page 17: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Return-Oriented Programming (ROP)

code fragment

.text:

...

...

...

...

dup2(sock, 0);return;

dup2(sock, 1);return;

execve(“/bin/sh”, 0, 0);return;

Stack:

0x700000

0x600000

0x800000

ROP gadget

0x800000

0x600000

0x700000

Page 18: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Address Space Layout Randomization (ASLR)

code fragment

.text: 0x400000

...

...

...

...

dup2(sock, 0);return;

dup2(sock, 1);return;

execve(“/bin/sh”, 0, 0);return;

Stack:

0x700000

0x600000

0x800000

Page 19: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Address Space Layout Randomization (ASLR)

code fragment

.text: 0x400000 + ??

...

...

...

...

dup2(sock, 0);return;

dup2(sock, 1);return;

execve(“/bin/sh”, 0, 0);return;

Stack:0x700000

+ ??

0x600000+ ??

0x800000+ ??

Page 20: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Exploit requirements today

1. Break ASLR.

2. Copy of binary (find ROP gadgets / break NX).

• Is it even possible to hack unknown applications?

Page 21: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Blind Return-Oriented Programming (BROP)

1. Break ASLR.

2. Leak binary:

• Remotely find enough gadgets to call write().

• write() binary from memory to network to disassemble and find more gadgets to finish off exploit.

Page 22: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Defeating ASLR: stack reading

• Overwrite a single byte with value X:

• No crash: stack had value X.

• Crash: guess X was incorrect.

• Known technique for leaking canaries.

buf[1024] 0x401183

Return address

Page 23: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Defeating ASLR: stack reading

• Overwrite a single byte with value X:

• No crash: stack had value X.

• Crash: guess X was incorrect.

• Known technique for leaking canaries.

0000000000000000000000000 0x401183

Return address

Page 24: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Defeating ASLR: stack reading

• Overwrite a single byte with value X:

• No crash: stack had value X.

• Crash: guess X was incorrect.

• Known technique for leaking canaries.

0000000000000000000000000 0x001183

Return address

(Was: 0x401183)

Page 25: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Defeating ASLR: stack reading

• Overwrite a single byte with value X:

• No crash: stack had value X.

• Crash: guess X was incorrect.

• Known technique for leaking canaries.

0000000000000000000000000 0x011183

Return address

(Was: 0x401183)

Page 26: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Defeating ASLR: stack reading

• Overwrite a single byte with value X:

• No crash: stack had value X.

• Crash: guess X was incorrect.

• Known technique for leaking canaries.

0000000000000000000000000 0x401183

Return address

(Was: 0x401183)

Page 27: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

??

0x401183

??

??

??

?? return address0x401183

buf[1024]

Stack:

0x401170

0x4011600x4011500x401140

0x401130

Page 28: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

crash

??

??

??

?? return address0x401170

AAAAAAAAAAAAAAAAAA

Stack:

Connection closes

0x401183

0x401170

0x4011600x4011500x401140

0x401130

Page 29: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

crash

crash

??

??

?? return address0x401160

AAAAAAAAAAAAAAAAAA

Stack:

Connection closes

0x401183

0x401170

0x4011600x4011500x401140

0x401130

Page 30: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

crash

crash

no crash

??

?? return address0x401150

AAAAAAAAAAAAAAAAAA

Stack:

Connection hangs

0x401183

0x401170

0x4011600x4011500x401140

0x401130

Page 31: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

crash

crash

no crash

crash

crash return address0x401130

AAAAAAAAAAAAAAAAAA

Stack:

Connection closes

0x401183

0x401170

0x4011600x4011500x401140

0x401130

Page 32: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Three types of gadgets

sleep(10);return;

Stop gadget

abort();return;

Crash gadget

dup2(sock, 0);return;

Useful gadget

• Never crashes •Always crashes •Crash depends on return

Page 33: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Three types of gadgets

sleep(10);return;

Stop gadget

abort();return;

Crash gadget

dup2(sock, 0);return;

Useful gadget

• Never crashes •Always crashes •Crash depends on return

Page 34: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding useful gadgets

dup2(sock, 0);return;

return address0x401170

buf[1024]

other

Stack:Crash!!

0x401170

sleep(10);return;

0x401150

Page 35: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding useful gadgets

dup2(sock, 0);return;

return address0x401170

buf[1024]

0x401150

Stack:0x401170

sleep(10);return;

0x401150No crash

Page 36: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

crash

crash

stop gadget

crash

crash

0x401183

0x401170

0x4011600x4011500x401140

0x401130 return address0x401183

buf[1024]

Stack:

other

Page 37: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

gadget!

crash

stop gadget

crash

crash

Connection hangs0x401183

0x401170

0x4011600x4011500x401140

0x401130 return address0x401170

AAAAAAAAAAAAAAAAAA

0x401150

Stack:

Page 38: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

How to find gadgets?.text:

code fragment

gadget!

crash

stop gadget

crash

crash

Connection closes0x401183

0x401170

0x4011600x4011500x401140

0x401130 return address0x401160

AAAAAAAAAAAAAAAAAA

0x401150

Stack:

Page 39: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

What are we looking for?

write(int sock, void *buf, int len)

Page 40: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

What are we looking for?

pop rdiret

pop rsiret

pop rdxret

call writeret

write(int sock, void *buf, int len)

Page 41: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

What are we looking for?

pop rdiret

pop rsiret

pop rdxret

call writeret

write(int sock, void *buf, int len)

AAAAAbuf[1024]

0x400000ret addr

sockrdi

0x500000 bufrsi

0x600000 lenrdx

0x700000

Page 42: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Pieces of the puzzle

pop rdiret

pop rsiret

pop rdxret

call writeret

stop gadget[call sleep]

Page 43: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Pieces of the puzzle

pop rdiret

pop rsiret

call writeret

stop gadget[call sleep]

call strcmpret

Page 44: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Pieces of the puzzle

pop rdiret

pop rsiret

call writeret

stop gadget[call sleep]

call strcmpret

Page 45: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Pieces of the puzzle

pop rdiret

pop rsipop r15ret

call writeret

stop gadget[call sleep]

call strcmpret

pop rbxpop rbppop r12pop r13pop r14pop r15ret

The BROP gadget

Page 46: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

PLT

Pieces of the puzzle

pop rdiret

pop rsipop r15ret

call writeret

stop gadget[call sleep]

call strcmpret

pop rbxpop rbppop r12pop r13pop r14pop r15ret

The BROP gadget

Page 47: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding the BROP gadget

return address0x401183

buf[1024]

stop gadget

retConnectionhangs

Stack:

Page 48: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding the BROP gadget

return address0x401183

buf[1024]

Stack:

stop gadgetret

Connectioncloses

crash gadget

Page 49: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding the BROP gadget

return address0x401183

buf[1024]

Stack:

stop gadget pop rbxret

Connectionhangs

crash gadget

Page 50: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding the BROP gadget

return address0x401183

buf[1024]

Stack:

stop gadget

pop rbxpop rbp

ret

Connectionhangs

crash gadget

crash gadget

Page 51: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding the BROP gadget

return address0x401183

buf[1024]

Stack:stop gadget

pop rbxpop rbppop r12pop r13pop r14pop r15ret

Connectionhangs

crash gadget

crash gadget

crash gadget

crash gadget

crash gadget

crash gadgetBROP gadget

Page 52: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Attack so far

• Can control first two arguments to calls (using BROP gadget).

• Need to control third argument (using call strcmp).

• Need to find call write

Procedure Linking Table (PLT)

Page 53: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Procedure Linking Table (PLT)

.text

Origin: 0x400000

PLT

Page 54: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Procedure Linking Table (PLT)

.text

Origin: 0x400000

PLTPLTjmp [sleep]push 0jmp dlresolvejmp [write]push 1jmp dlresolvejmp [strcmp]push 2jmp dlresolve

.text

call write...

call write...

call strcmp

libcsleep() {...}write() {...}strcmp() {...}

[GOT dereference]

Page 55: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding the PLT

• Toward beginning of .text

• Each entry is 0x10 bytes apart, 0x10 aligned

• Most don’t crash: syscalls - return EFAULT on bad args.

• Can check if entry + 6 succeeds too (dlresolve slow path)

Page 56: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Fingerprinting strcmp

• Use return address (.text) as readable

Can now control three arguments: strcmp sets RDX to length of string

arg1 arg2 result

readable 0x0 crash

0x0 readable crash

readable readable nocrash

Page 57: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Finding write

• strcmp(origin, origin) // sets RDX / write length to 7 - ELF header.

• set rdi to socket number, rsi to origin/addr

• try calling candidate PLT function.

• check if data received on socket.

• chain writes with different FD numbers to find socket. Use multiple connections.

Page 58: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Launching a shell1. dump binary to network - not blind anymore!

2. dump symbol table to find PLT calls.

3. redirect stdin/out to socket:

• dup2(fd, 0);

• close(0); fcntl(sock, F_DUPFD, 0);

4. read() “/bin/sh” from socket to writable

• writable can be environ (from symbol table)

5. execve(“/bin/sh”, 0, 0)

Page 59: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Braille• Fully automated: from crash to shell.

• 2,000 lines of Ruby.

• Needs function that will trigger overflow:

• nginx: 68 lines.

• mysql: 121 lines.

• proprietary service: 35 lines.

try_exp(data) → true crash false no crash

Page 60: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

Attack complexity

# of requestsfor nginx

dump bin222find write

101

find strcmp61

find BROP gadget469

find PLT702

stack reading846

Page 61: Hacking Blind - Stanford Computer Forum...Hacking Blind Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazières, Dan Boneh Stanford University Hacking 101 Exploit GET /0xDEAD HTTP/1.0

BROP conclusions

• It’s scary what a motivated attacker can do: e.g., hack unknown binaries.

• Hackers can get past point solutions - need principled solutions:

• OS: rerandomize ASLR & canaries per-fork

• Compiler: Encrypt or MAC pointers?

• Application: Dune (privilege separation)?