• No results found

Advanced Security for Systems Engineering VO 03: Advanced Attacks on Applications 1

N/A
N/A
Protected

Academic year: 2021

Share "Advanced Security for Systems Engineering VO 03: Advanced Attacks on Applications 1"

Copied!
35
0
0

Loading.... (view fulltext now)

Full text

(1)

Advanced Security for Systems Engineering – VO 03:

Advanced Attacks on Applications 1

(2)

Capture-the-Flag Team defragmented.brains

■ Take part in many international

hacking competitions

■ Diverse bunch, different skills

and skill levels

■ Join our mailinglist:

[email protected]. ac.at

(3)
(4)

Memory Corruption Bugs

After decades of research, problem still prevalent.

■ Morris Worm (11/2/1988) exploited a buffer overrun in fingerd

■ 31 years, and thousands of research papers later: memory corruptions

bugs still relevant

■ 2015: More than 1 billion devices affected by Stagefright vulnerability

■ 2017: WanaCry ransomware infects 200.000 computers within a day

via EternalBlue (SMB heap exploit, stockpiled by the NSA, leaked by The Shadow Brokers)

■ Hard to exploit due to mitigation techniques nowadays

(5)

Memory Corruption Bugs: Vulnerability Categories

■ Stack overflow

■ Heap overflow

■ Double free

■ Use after free

■ Buffer underrun

■ Format string vulnerability

■ Integer overflow

■ Signed/unsigned conversion error

■ Type confusion error

(6)

Memory Corruption Bugs: Main Culprits

■ Computer and OS Architecture

Memory space contains control flow information as well as user data

■ Function return address stored on stack

■ Heap management info interleaved with user data

■ Function pointers: exception handler pointer, virtual function

table, etc.

■ Type-unsafe Programming Languages

C or C++ allow arbitrary writes in process’ memory space

(7)

Memory Corruption Bugs: Results of successful exploits

■ Denial of Service

■ Induce process crash, prevent clients from accessing service

■ Information Disclosure

■ Leaking private information (e.g., passwords, private keys)

■ Often 1st step in circumventing mitigation techniques (e.g.,

leaking process space address information)

■ Control Flow Hijacking

■ Maliciously alter the process’ behaviour: “Arbitrary Code

(8)

Memory Corruption Bugs: Control Flow Hijacking

1. Modify control flow data / metadata with user input

■ Function return address

■ Function pointer

■ Virtual method table

■ Heap metadata

■ Global Offset Table (GOT) or Import Address Table (IAT)

2. Redirect Control Flow

■ to injected (machine) code

(9)

Process Execution

Registers (x86): ■ %eip: points to next instruction being executed ■ %esp: points to end of stack Stack: store for information about currently active subroutine

(10)

Stack Layout: Before Function Call

1 v o i d g r a y ( ) 2 { 3 . . . 4 yellow(a1, a2); 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ Function gray pushes

parameters for function yellow on the stack

(11)

Stack Layout: During Function Call

1 v o i d g r a y ( ) 2 { 3 . . . 4 yellow(a1, a2); 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ Call instruction pushes %eip

register (return address) on the stack

(12)

Stack Layout: Function Prologue

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ Save gray’s frame pointer

(%ebp)

■ Update frame pointer

(13)

Stack Layout: Function Prologue

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 char buf[3]; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

(14)

Stack Layout: Function Prologue

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 int l1, l2; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ Local Variables allocated

traditionally in order of declaration

(15)

Stack Layout: Before Function Call

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l2 = blue(l1, buf); 14 r e t u r n l 2 ; 15 }

■ Save caller-saved registers

(16)

Stack Layout: During Function Call

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l2 = blue(l1, buf); 14 r e t u r n l 2 ; 15 }

(17)

Stack Layout: After Function Call

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 return l2; 15 }

■ Stack frame for blue and

params have already been freed (by incrementing %esp)

(18)

Stack Layout: Function Epilog

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ Callee-saved registers of gray

restored

■ Frame pointer of gray restored

■ Return address on stack will

(19)

Stack Layout: After Function Call

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 ... 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ ... and execution continues

right after the call to yellow

(20)

Stack Layout: Purpose of Frame Pointer

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ Positive offset added to %ebp

to address parameter

■ Negative offset added to %ebp

(21)

Stack Layout: Frame Pointer

1 v o i d g r a y ( ) 2 { 3 . . . 4 y e l l o w ( a1 , a2 ) ; 5 . . . 6 } 7 8 i n t y e l l o w ( i n t p1 , i n t p2 ) 9 { 10 c h a r b u f [ 3 ] ; 11 i n t l 1 , l 2 ; 12 13 l 2 = b l u e ( l 1 , b u f ) ; 14 r e t u r n l 2 ; 15 }

■ %ebp can often be optimized

away

(22)

Stack Buffer Overflow: Vulnerable Program

1 i n t main ( i n t a r g c , c h a r∗∗ a r g v ) 2 { 3 c h a r v a l ; 4 v a l = y e l l o w ( 5 , a r g v [ 1 ] ) ; 5 p r i n t f (” a u t h : %c ” , v a l ) ; 6 } 7 8 i n t y e l l o w ( i n t l e n , c h a r∗ t e x t ) 9 { 10 c h a r a u t h e n t i c a t e d = ’N ’ ; 11 c h a r b u f [ 3 ] ; 12 . . . 13 s t r c p y ( buf , t e x t ) ; 14 . . . 15 r e t u r n a u t h e n t i c a t e d ;

(23)

Stack Buffer Overflow: Local Variable Spill

■ buf[3] overflows with user

(24)

Stack Buffer Overflow: Disrupt Control Flow

What if we spill input further up the stack?

■ Return address gets

overwritten

■ Program segfaults after

(25)

Stack Buffer Overflow: Stack Content Before Overflow

Stack content right before call to strcpy

■ At 0xbffff36c the char array buf starts

■ At 0xbffff37c the original return address is stored

(26)

Stack Buffer Overflow: Stack Content After Overflow

Stack content right after call to strcpy

■ buf is filled with the string "AAA" (ascii code for ’A’: 0x41)

■ The rest of the input string "AAAABBBBCCCCDDDDEEEE" overflows

■ The original return address at 0xbffff37c is overwritten with

(27)

Stack Buffer Overflow: Redirect Control Flow

We can redirect control flow to (almost) arbitrary locations in the process’ memory space.

(28)

Stack Buffer Overflow: Arbitrary Code Execution

Inject own malicious code

(“shellcode”) into the process’ memory space:

■ Provide the shellcode as part

of the input string, it gets

copied in the buffer buf

■ Overwrite return address to

point to the beginning of

buf[3]

(29)

Stack Buffer Overflow Attack: Summary

■ Fill buffer with own code (shellcode)

■ Overwrite return address

■ Return address points to shellcode

■ When leaving the current function

■ Overwritten return address will be loaded into %eip register

(instruction pointer)

■ %eip register points to shellcode

(30)

Stack Buffer Overflow: Recapitulation

(31)

Stack Buffer Overflow: Recapitulation

(32)

Stack Buffer Overflow: NOP-Sled

New return address needs to point to buffer: Exact location not known.

■ Prepend NOP-Sled to shellcode as “landing zone”

(33)

Literature / Links

■ Aleph One (1996): Smashing the Stack for Fun and Profit, Phrack

49.

■ Bulba and Kil3r (2000): Bypassing Stackguard and Stackshield,

Phrack 56.

■ Richarte (2002): Four different tricks to bypass Stackshield and

Stackguard protection.

■ Corelan Team: Exploit writing tutorial part 6 : Bypassing Stack

Cookies, SafeSeh, SEHOP, HW DEP and ASLR.

■ Meer (2010): Memory Corruption Attacks. The Almost Complete

(34)

Literature / Links

■ Veen (2012): Memory Errors: The Past, the Present, and the Future.

■ Szekers (2013): SoK: Eternal War in Memory.

■ Chris Anley (2007), The Shellcoder’s Handbook: Discovering and

Exploiting Security Holes.

■ Intel 64 and IA-32 Software Developers Manual Combined Volumes.

(35)

Thank you!

References

Related documents

African Americans like Frederick Douglass were born into slavery and experienced at a young age the projected identity of being less than human by their white oppressors. Northup

Also, the Swedish national board of housing, building and planning (Boverket) will require an assessment of life cycle greenhouse gas emissions in the permit process

Member, Joint Review Committee for Respiratory Therapy Education, American Association for Respiratory Therapy Representative, 1982 to 1987.. Vice-Chairman, Joint Review Committee

PDPH vzniká vtedy, keď sa punkciou vytvorí otvor v dura mater. Cez tento otvor vyteká mozgomiešný mok zo subarachnoideálneho priestoru do priestoru epidurálneho v

Characteristics of health misinformation, including the types (true or false, textual or pictorial, and dread or wish) and the cues involved in the information, have

(h) PRIMA FACIE EVIDENCE OF PHYSICAL IMPAIRMENT FOR OTHER SILICA- RELATED CLAIMS.- No person shall bring or maintain a silica claim related to an alleged silica-related condition,

TVIS (Trekantområdets Varmetransmissions- selskab I/S) is a heat transmission company for the municipalities of Fredericia, Kolding, Middelfart, Børkop and Vejle.. These

For this reason, while the imbalance between Turkish and Russian geo- political power obviously goes a long way towards ex- plaining the AK Party government’s muted response to