24
Tel +41 55 214 41 60 Fax +41 55 214 41 61 [email protected] www.csnc.ch Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona Exploit Mitigation - PIE

Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

Tel +41 55 214 41 60 Fax +41 55 214 41 61 [email protected] www.csnc.ch

Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona

Exploit Mitigation - PIE

Page 2: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 2 www.csnc.ch

Exploit

Mitigations

DEP

PIE

ASLR

Stack

Canary

ASCII Armor

Partial RIP Overwrite

Brute Force

Heap Overflows

Overflow Local Vars

Arbitrary Write

NOP Slide

Info Disclosure

Ret 2 PLT

ROP

Page 3: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 3 www.csnc.ch

Recap! Exploit Mitigation Exploits

All three exploit mitigations can be defeated by black magic

Easily

Is there a solution?

Page 4: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

Tel +41 55 214 41 60 Fax +41 55 214 41 61 [email protected] www.csnc.ch

Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona

Exploit Mitigation - PIE

Page 5: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 5 www.csnc.ch

The solution

Page 6: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 6 www.csnc.ch

Exploit Mitigation++

• Fix: • Compile as PIE

• PIE: Position Independent Executable

• Will randomize Code and PLT, too

• Note: • Shared libraries are PIC

• (Position Independent Code)

• being loaded

• Always randomized, even without PIE

Page 7: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 7 www.csnc.ch

Exploiting: ASLR for code: PIE

Stack

Heap

Code 0x???????

Mappings

PLT

0x????????

0x???????

Page 8: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 8 www.csnc.ch

Exploiting: ASLR for code: PIE

PIE randomizes Code segment base address

PIE randomizes GOT/PLT base address too

No more static locations!

Page 9: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

Tel +41 55 214 41 60 Fax +41 55 214 41 61 [email protected] www.csnc.ch

Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona

Defeat Exploit Mitigation: PIE

Page 10: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 10 www.csnc.ch

Exploit

Mitigations

DEP

PIE

ASLR

Stack

Canary

ASCII Armor

Partial RIP Overwrite

Brute Force

Heap Overflows

Overflow Local Vars

Arbitrary Write

NOP Slide

Info Disclosure

Ret 2 PLT

ROP

Page 11: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 11 www.csnc.ch

Page 12: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 12 www.csnc.ch

ASLR vs Information Leak

What if they can?

Meet: Memory Leak

Page 13: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

Tel +41 55 214 41 60 Fax +41 55 214 41 61 [email protected] www.csnc.ch

Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona

Memory Leak / Information Disclosure

Page 14: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 14 www.csnc.ch

Memory Leak

Memory leak or information disclosure: Return more data to the attacker than the intended object size

The data usually includes meta-data, like:

Stack pointers

Return addresses

Heap-management data

Etc.

Page 15: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 15 www.csnc.ch

ASLR vs Memory Leak

Server: send(socket, buf1, sizeof(int) * 16, NULL);

Oups, attacker got 64 bytes back

Pointer to stack, code, heap

Can deduce base address

char buf1[16] EIP SFP *ptr

Page 16: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 16 www.csnc.ch

ASLR vs Memory Leak

send(socket, buf1, sizeof(int) * 16, NULL);

char buf1[16] EIP SFP *ptr

char buf1[16] EIP SFP *ptr

Page 17: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 17 www.csnc.ch

Exploiting: ASLR for code: PIE

Stack?

Heap?

Code? 0xbfbfbfbf

0xaabbccdd

0xddeeffaa

Real Stack

Real Heap

Real Code

Page 18: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 18 www.csnc.ch

Exploiting: ASLR for code: PIE

0xbfbfbfbf Real Code

libc

libcurses

Ma

ppe

d lib

rarie

s

Page 19: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 19 www.csnc.ch

Exploiting: ASLR for code: PIE

Attacker: Information disclosure / memory leak

Gains a pointer (Address of memory location)

From pointer: Deduct base address of segment

From base address: Can deduct all other addresses

A note on code -> libraries: Distance between code segment and mapped libraries is usually constant

Page 20: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 20 www.csnc.ch

Exploiting: ASLR for code: PIE

Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038)

As a consequence, the 16x16/24bpp bitmap is now

described by just 4 bytes, which is good for only

a single pixel. The remaining 255 pixels are

drawn based on junk heap data, which may include

sensitive information, such as private user data

or information about the virtual address space.

Page 21: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 21 www.csnc.ch

Page 22: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

Tel +41 55 214 41 60 Fax +41 55 214 41 61 [email protected] www.csnc.ch

Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona

Exploit Mitigation Conclusion

Page 23: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 23 www.csnc.ch

Defeat Exploit Mitigations: TL;DR

Enable ALL the mitigations (DEP, ASLR w/PIE, Stack Protector)

Defeat ALL the mitigations:

ROP shellcode as stager to defeat DEP

Information leak to defeat ASLR

Non stack-based-stack-overflow vulnerability

Page 24: Exploit Mitigation - PIE · Exploiting: ASLR for code: PIE Example: Windows memory disclosure (unpatched, 21.2.17, CVE-2017-0038) As a consequence, the 16x16/24bpp bitmap is now described

© Compass Security Schweiz AG Slide 24 www.csnc.ch

Recap

Information disclosure can eliminiate ASLR protection

Which enables ROP to eliminate DEP