46
Protecting buggy software from memory corruption attacks Minemu

Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Protecting buggy software frommemory corruption attacks

Minemu

Page 2: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

GET / HTTP/1.100baseretnarg1arg2

SHELLCODE!@#$%^&*()_&buf

Traditional Stack Smashing

buf[16]

Page 3: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

GET / HTTP/1.100baseretnarg1arg2

SHELLCODE!@#$%^&*()_????

Address Space Layout Randomisation

buf[16]

Page 4: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

GET / HTTP/1.100baseretnarg1arg2

SHELLCODE!@#$%^&*()_&buf

DEP / NX

buf[16]

Page 5: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)
Page 6: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

This is still not enough

- ASLR can be brute forced

- Protecting against heap overflows is much harder than against stack overflows.

Page 7: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

GET / HTTP/1.100baseretnarg1arg2

sh;STACKSMASHER.....ROP1ROP2var1

Return Oriented Programming

buf[16]

pointer to useful code

Page 8: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

But the situation is even worse

Page 9: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

But the situation is even worse

- needs to be enabled at compile time, and there is a lot of old code out there

Page 10: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

But the situation is even worse

- needs to be enabled at compile time, and there is a lot of old code out there

- many packages do not apply these defence mechanisms even today

Page 11: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

But the situation is even worse

- needs to be enabled at compile time, and there is a lot of old code out there

- many packages do not apply these defence mechanisms even today

- flaws in how ASLR/stack cookies are implemented

Page 12: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Can we do more?

Page 13: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Can we do more?

>> DEP prevents untrusted data from being run as code

Page 14: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Can we do more?

>> DEP prevents untrusted data from being run as code

<< ROP replaces untrusted code with pointers to original code.

Page 15: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Can we do more?

>> DEP prevents untrusted data from being run as code

<< ROP replaces untrusted code with pointers to original code.

>> Can we prevent untrusted pointers from being used as jump addresses?

Page 16: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint analysis

0805be60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|0805be70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|0805be80 00 00 00 00 02 00 00 00 d8 4b 06 08 a0 2e 05 08 |.........K......|0805be90 | |0805bea0 | |0805beb0 | |0805bec0 | |0805bed0 00 00 00 00 |.... |0805bee0 ff fa 26 08 ff f0 00 00 00 00 00 00 00 00 00 00 |..&.............|0805bef0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|0805bf00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

94 be 05 08 78 a0 04 08 ef be ad de a4 be 05 08 ....x........... ac be 05 08 2f 62 69 6e 2f 73 68 00 a4 be 05 08 ..../bin/sh..... 00 00 00 00 45 49 4e 44 42 41 5a 45 4e 45 49 4e ....EINDBAZENEIN 44 42 41 5a 45 4e 45 49 4e 44 42 41 5a 45 4e 45 DBAZENEINDBAZENE 41 5a 45 4e 90 be 05 08 ef 1f 05 08 AZEN........

Page 17: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint tracking (1/2):

- remember whether data is trusted or not- untrusted data is 'tainted'- when data is copied, its taint is copied along- taint is ORed for arithmetic operations, except when the result is always 0

Page 18: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint tracking (2/2):

When the code jumps to an address in memory,the source of this address is checked for taint.

eg.:- RET- CALL *%eax- JMP *0x1c(%ebx)

Page 19: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)
Page 20: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint tracking

photo: sammydavisdog@flickr

useful, but slow as hell

Page 21: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Is this slowness fundamental?

memory layoutuse SSE registers to hold taint

minemu

Page 22: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

linuxkernel

USER

Memory layout (linux)

Page 23: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

linuxkernel USER

TAINT

minemu

Memory layout (minemu)

Page 24: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

linuxkernel USER

TAINT

minemu

Memory layout (minemu)

Page 25: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

linuxkernel USER

TAINT

minemu

Memory layout (minemu)

write to x

Page 26: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

linuxkernel USER

TAINT

minemu

Memory layout (minemu)

write to x

x+const

Page 27: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

linuxkernel USER

TAINT

minemu

Memory layout (minemu)

taint data to user memory

user data to taintmemory

Page 28: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

mov EAX, (EDX)

Addressing shadow memory

Page 29: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

mov EAX, (EDX)

address:

EDX

Addressing shadow memory

Page 30: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

mov EAX, (EDX)

address:

EDX

taint:

EDX+ const

Addressing shadow memory

Page 31: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

mov EAX, (EDX+EBX*4)

address:

EDX+EBX*4

taint:

EDX+EBX*4+ const

Addressing shadow memory

Page 32: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Is this slowness fundamental?

memory layoutuse SSE registers to hold taint

minemu

Page 33: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint propagation in SSE registers

T(eax) T(ecx) T(edx) T(ebx)T(eax) T(ecx) T(edx) T(ebx)xmm6

T(esp) T(ebp) T(esi) T(edi)T(esp) T(ebp) T(esi) T(edi)xmm7

xmm5 scratch registerscratch register

128-bit

Page 34: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint propagation in SSE registers

T(eax) T(ecx) T(edx) T(ebx)T(eax) T(ecx) T(edx) T(ebx)xmm6

T(esp) T(ebp) T(esi) T(edi)T(esp) T(ebp) T(esi) T(edi)xmm7

xmm5 scratch registerscratch register

128-bit

add EDX, x

Page 35: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint propagation in SSE registers

T(eax) T(ecx) T(edx) T(ebx)T(eax) T(ecx) T(edx) T(ebx)xmm6

xmm5 scratch registerscratch register

add EDX, x

Page 36: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint propagation in SSE registers

T(eax) T(ecx) T(edx) T(ebx)T(eax) T(ecx) T(edx) T(ebx)xmm6

xmm5 T(x)T(x)

add EDX, x

vector insert

Page 37: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Taint propagation in SSE registers

T(eax) T(ecx) T(edx) T(ebx)T(eax) T(ecx) T(edx) T(ebx)xmm6

xmm5 T(x)T(x)

add EDX, x

or

Page 38: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

EffectivenessApplication Type of vulnerability Security advisorySnort 2.4.0 Stack overflow CVE-2005-3252Cyrus imapd 2.3.2 Stack overflow CVE-2006-2502Samba 3.0.22 Heap overflow CVE-2007-2446Memcached 1.1.12 Heap overflow CVE-2009-2415Nginx 0.6.32 Buffer underrun CVE-2009-2629Proftpd 1.3.3a Stack overflow CVE-2010-4221Samba 3.2.5 Heap overflow CVE-2010-2063Telnetd 1.6 Heap overflow CVE-2011-4862Ncompress 4.2.4 Stack overflow CVE-2001-1413Iwconfig V.26 Stack overflow CVE-2003-0947Aspell 0.50.5 Stack overflow CVE-2004-0548Htget 0.93 Stack overflow CVE-2004-0852Socat 1.4 Format string CVE-2004-1484Aeon 0.2a Stack overflow CVE-2005-1019Exim 4.41 Stack overflow EDB-ID#796Htget 0.93 Stack overflowTipxd 1.1.1 Format string OSVDB-ID#12346

Page 39: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Performance

HTTP

HTTPS

Page 40: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Performance

0

1

2

3

gzip OpenSSH(scp+sshd)

PostgreSQL(pgbench)

MediaWiki(HTTPS)

0

1

2

3

4

5

400.perlbench

401.bzip2

403.gcc

429.mcf

445.gobmk

456.hmmer

458.sjeng

462.libquantum

464.h264ref

471.omnetpp

473.astar

483.xalancbmk

overall

SPECINT 20062.4x overall

Page 41: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Limitations

Page 42: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Limitations

Doesn't prevent memory corruption, onlyacts when the untrusted data is used forarbitrary code execution.

Page 43: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Limitations

Tainted pointer dereferences

->some_field = useful_untainted_value;tainted_pointer

Page 44: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Limitations

Does not protect against non-control-flow exploits:

try_system( *username, *cmd){ user_rights = get_credentials(username); buf[16] = strcpy(buf, username); (user_rights & ) system(cmd);

log_error( , buf);}

void char char

int char 16 ALLOW_SYSTEM

"user attempted login" %s

if

else

Page 45: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

in some cases we can add validation hooks.

in glibc can be hooked to check format strings for taint.

can be hooked to check for taint outside of literals in SQL queries.

_IO_vfprintf()

mysql_query()

Page 46: Minemu - FOSDEM · linux kernel USER TAINT minemu Memory layout (minemu) taint data to user memory user data to taint memory. mov EAX, (EDX) Addressing shadow memory. mov EAX, (EDX)

Minemugit clone https://minemu.org/code/minemu.git

any questions?