Transparent ROP Exploit Mitigation using Indirect Branch - - PowerPoint PPT Presentation

transparent rop exploit mitigation using indirect branch
SMART_READER_LITE
LIVE PREVIEW

Transparent ROP Exploit Mitigation using Indirect Branch - - PowerPoint PPT Presentation

Transparent ROP Exploit Mitigation using Indirect Branch Tracing Alexandros Perrakis Manolis Karabinakis Stelios Ninidakis Vulnerabilities Buffer overflow


slide-1
SLIDE 1

Alexandros ¡Perrakis ¡ Manolis ¡Karabinakis ¡ Stelios ¡Ninidakis ¡

Transparent ¡ROP ¡Exploit ¡ Mitigation ¡using ¡Indirect ¡ Branch ¡Tracing ¡

slide-2
SLIDE 2
  • Buffer ¡overflow ¡
  • Integer ¡overflow ¡
  • Use ¡after ¡free ¡
  • Function ¡point ¡overflow ¡

¡ ¡

Vulnerabilities ¡

slide-3
SLIDE 3

Buffer ¡overflow-­‑executable ¡stack ¡

Shellcode ¡ NEW ¡ RET ¡ Vulnerable ¡Buffer ¡ ¡ Local ¡Var. ¡ Ret ¡ Address ¡

slide-4
SLIDE 4

A ¡simple ¡example: ¡ ¡ ¡ ¡ ¡ ¡ ¡ Attacker ¡gets ¡access ¡with ¡that ¡program ¡ by ¡simply ¡overflow ¡the ¡buffer ¡. ¡ In ¡that ¡way ¡he ¡controls ¡the ¡ret ¡address ¡ where ¡he ¡ ¡can ¡locate ¡ ¡his ¡own ¡code(malicious) ¡in ¡the ¡stack. ¡ ¡ ¡

Buffer ¡overflow-­‑executable ¡stack ¡

slide-5
SLIDE 5

Canary ¡value ¡

  • Produced ¡by ¡the ¡compiler ¡
  • Checked ¡at ¡run-­‑time ¡
  • Canary ¡is ¡a ¡random ¡value ¡

¡

Problems: ¡

  • Can ¡be ¡disclosed ¡
  • Can ¡be ¡brute-­‑forced ¡

¡ ¡ Vulnerable ¡Buffer ¡ ¡ Local ¡Var. ¡ Ret ¡ Address ¡

slide-6
SLIDE 6

¡ ¡ ¡ ¡ ¡ ¡ ¡

  • W ¡⊕ ¡X ¡

¡Can ¡be ¡either ¡Writable ¡or ¡Executable(not ¡both) ¡

  • Strong ¡defense ¡mechanism ¡against ¡buffer ¡overflow ¡

¡ ¡

W⊕ ¡X ¡ ¡

Stack ¡ Heap ¡ Data ¡ Text ¡ High ¡Address ¡ Low ¡Address ¡ Executable ¡ Executable ? ¡ Executable ? ¡ Executable ? ¡

slide-7
SLIDE 7
  • Part ¡of ¡all ¡modern ¡operating ¡systems ¡
  • Prevents ¡the ¡execution ¡of ¡injected ¡binary ¡code ¡
  • Marks ¡areas ¡of ¡memory ¡as ¡executable ¡or ¡not ¡
  • Offers ¡no ¡protection ¡against ¡attacks ¡that ¡rely ¡
  • n ¡re-­‑usable ¡code ¡

¡

How ¡about ¡ ¡DEP(Data ¡Execution ¡ Prevention) ¡

slide-8
SLIDE 8

¡

  • Randomizes ¡ ¡the ¡load ¡addresses ¡of ¡executables ¡and ¡DLLs. ¡
  • Makes ¡more ¡difficult ¡for ¡an ¡attacker ¡to ¡predict ¡target ¡

addresses ¡

  • A ¡mistaken ¡guess ¡is ¡not ¡usually ¡recoverable ¡due ¡to ¡the ¡

application ¡crashing ¡ ¡ ¡ Bypassing ¡ASLR: ¡

  • More ¡importantly ¡If ¡ ¡a ¡process ¡is ¡fully ¡randomized ¡its ¡still ¡

possible ¡to ¡calculate ¡the ¡base ¡address ¡of ¡a ¡DLL ¡at ¡runtime. ¡

  • Brute ¡forced. ¡

¡ ¡

ASLR(Address ¡Space ¡Layout ¡ Randomization) ¡

slide-9
SLIDE 9

Various ¡protection ¡approaches: ¡

  • Performing ¡anomaly ¡detection ¡by ¡checking ¡for ¡an ¡

unusually ¡high ¡frequency ¡of ¡ret ¡instructions ¡

  • Ensuring ¡the ¡integrity ¡of ¡the ¡stack, ¡or ¡
  • Randomizing ¡the ¡locations ¡of ¡code ¡fragments ¡
  • Dynamic ¡binary ¡instrumentation ¡allows ¡these ¡systems ¡to ¡

be: ¡

  • Transparent ¡: ¡
  • Enables ¡the ¡practical ¡applicability ¡of ¡protection ¡

techniques ¡

  • The ¡aim ¡of ¡high ¡runtime ¡overhead ¡
  • Needs ¡mitigation ¡techniques ¡→ ¡minimal ¡overhead ¡and ¡

proper ¡ ¡execution ¡of ¡the ¡protected ¡applications ¡

Runtime ¡ ¡monitoring ¡ ¡solutions ¡

slide-10
SLIDE 10
  • ¡Allows ¡an ¡attacker ¡to ¡execute ¡code ¡in ¡the ¡presence ¡of ¡

security ¡defenses ¡ ¡

  • An ¡attacker ¡gains ¡control ¡of ¡the ¡stack ¡to ¡hijack ¡

program ¡control ¡flow ¡and ¡then ¡executes ¡carefully ¡ chosen ¡instructions ¡sequences, ¡called ¡"gadgets". ¡

  • ¡Each ¡gadget ¡typically ¡ends ¡in ¡a ¡return ¡instruction ¡and ¡

is ¡located ¡in ¡a ¡subroutine ¡within ¡the ¡existing ¡. ¡ ¡

  • Chained ¡together, ¡these ¡gadgets ¡allow ¡an ¡attacker ¡to ¡

perform ¡arbitrary ¡operations ¡on ¡a ¡machine ¡employing ¡

  • defenses. ¡

ROP(Return ¡Oriented ¡Programming) ¡

slide-11
SLIDE 11

What ¡is ¡a ¡gadget? ¡

Sequences ¡of ¡instructions ¡ ending ¡with ¡an ¡indirect ¡

  • branch. ¡

¡ ¡ ¡ ¡

ROP(Return ¡Oriented ¡Programming) ¡

ROP ¡Chain ¡ TEXT ¡Section ¡ (Code) ¡

  • Addr. ¡of ¡G1 ¡
  • Addr. ¡of ¡G2 ¡
  • Addr. ¡of ¡G3 ¡
  • Addr. ¡of ¡GN ¡

G1; ¡ret ¡ G2; ¡ret ¡ G3; ¡ret ¡ GN; ¡ret ¡

slide-12
SLIDE 12

Simple ¡Example: ¡

¡ ¡ ¡ ¡ ¡ ¡

Attacker ¡overflows ¡the ¡valuable ¡buffer ¡and ¡the ¡function ¡ pointer( ¡f ¡) ¡with ¡a ¡with ¡any ¡value ¡he ¡wants. ¡

¡ ¡ ¡ ¡

ROP(Return ¡Oriented ¡Programming) ¡

slide-13
SLIDE 13

Simple ¡Example: ¡

¡ ¡ ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡D: ¡ ¡pop ¡%ecx ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ret ¡

¡

To ¡do ¡so ¡attacker ¡must ¡know ¡how ¡the ¡memory ¡is ¡mapped. ¡ In ¡that ¡way ¡if ¡attacker ¡controls ¡esp(stack ¡point), ¡controls ¡the ¡stack. ¡If ¡ f ¡has ¡ ¡a ¡value ¡D ¡with ¡pop ¡%ecx ¡extracts ¡the ¡value ¡of ¡stack ¡and ¡puts ¡It ¡ in ¡the ¡ecx. ¡After ¡ret ¡continues ¡with ¡the ¡rest ¡of ¡the ¡gadgets. ¡

¡ ¡

ROP(Return ¡Oriented ¡Programming) ¡

slide-14
SLIDE 14
  • Fully ¡transparent ¡
  • Runtime ¡monitoring ¡the ¡executed ¡indirect ¡branches ¡at ¡

critical ¡points ¡

  • Identifies ¡and ¡blocks ¡abnormal ¡control ¡flow ¡transfers ¡
  • Last ¡Branch ¡Recording ¡(LBR) ¡– ¡feature ¡of ¡Intel ¡CPUs ¡
  • Implementation ¡for ¡Windows ¡7 ¡
  • Minimal ¡overhead ¡
  • Identifies ¡“jump-­‑oriented” ¡code ¡that ¡uses ¡gadgets ¡

¡

Kbouncer-­‑Defense ¡to ¡ROP ¡

slide-15
SLIDE 15
  • Continuously ¡records ¡the ¡most ¡recent ¡branches ¡in ¡the ¡LBR ¡

stack ¡

  • Limited ¡size ¡(16 ¡entries) ¡of ¡the ¡LBR ¡stack ¡
  • Stack ¡can ¡be ¡accessed ¡only ¡from ¡kernel-­‑level ¡code ¡
  • Does ¡not ¡provide ¡any ¡means ¡of ¡interrupting ¡execution ¡

whenever ¡the ¡stack ¡gets ¡full ¡

  • Checks ¡only ¡the ¡indirect ¡branches ¡that ¡lead ¡to ¡a ¡syscall ¡

invocation ¡ ¡

¡

LBR ¡

slide-16
SLIDE 16
  • Windows ¡does ¡not ¡expose ¡the ¡syscall ¡interface ¡directly ¡

to ¡user-­‑lvl ¡programs ¡

  • User-­‑level ¡programs ¡– ¡OS ¡interaction ¡with ¡Windows ¡

API, ¡DLLs ¡and ¡Native ¡API ¡ ¡

  • Syscall ¡numbers ¡change ¡between ¡Windows ¡versions ¡

and ¡Service ¡Pack ¡levels ¡

  • Complex ¡implementation ¡of ¡Windows ¡API ¡functions ¡

→indirect ¡branches ¡after ¡the ¡Windows ¡API ¡was ¡called ¡ →LBR ¡stack ¡might ¡be ¡filled ¡with ¡these ¡branches ¡

  • 34% ¡API ¡functions ¡execute ¡less ¡than ¡16 ¡indirect ¡braches ¡

¡

Syscalls ¡vs. ¡API ¡calls ¡

slide-17
SLIDE 17
  • kBouncer ¡inspects ¡the ¡LBR ¡stack ¡at ¡the ¡time ¡an ¡

API ¡function ¡is ¡called, ¡instead ¡upon ¡system ¡call ¡ invocation ¡

  • DANGER: ¡if ¡LBR ¡check ¡implementation ¡is ¡in ¡

user-­‑level ¡code ¡

  • Attacker ¡can ¡bypass ¡checkpoint ¡by ¡jumping ¡
  • ver ¡the ¡hook ¡of ¡the ¡function's ¡prologue, ¡and ¡

then ¡normally ¡executes ¡the ¡function ¡body ¡

¡

LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡

slide-18
SLIDE 18
  • kBouncer ¡solves ¡this ¡issue ¡by ¡ensuring ¡that ¡

syscalls ¡are ¡always ¡invoked ¡solely ¡through ¡their ¡ respective ¡Windows ¡API ¡functions. ¡ i. LBR ¡check ¡at ¡an ¡API ¡funtion's ¡entry ¡ ¡

  • ii. if ¡LBR ¡check ¡is ¡clear, ¡kBouncer ¡writes ¡a ¡

checkpoint ¡

  • iii. When ¡system ¡is ¡later ¡invoked, ¡the ¡system ¡call ¡

handler ¡verifies ¡that ¡a ¡proper ¡checkpoint ¡set ¡by ¡ the ¡expected ¡API ¡function ¡and ¡clears ¡it ¡

  • iv. If ¡the ¡checkpoint ¡was ¡not ¡set, ¡kBouncer ¡reports ¡

a ¡violation ¡ ¡

¡

LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡

slide-19
SLIDE 19

LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡

kernel user space

time API call verification

system DLL

LBR check API call system call

slide-20
SLIDE 20

Threats: ¡

  • Gadgets ¡for ¡Kbouncer ¡: ¡up ¡to ¡20 ¡instruction ¡
  • length. ¡
  • ROP ¡chain ¡length: ¡ ¡8 ¡or ¡more ¡consider ¡ ¡an ¡attack ¡

by ¡Kbouncer. ¡

¡

Checks ¡: ¡

  • Illegal ¡ret ¡Instructions. ¡
  • Sequences ¡of ¡relatively ¡short ¡code ¡fragments ¡

chained ¡through ¡any ¡kind ¡of ¡indirect ¡branches. ¡

KBouncer ¡

slide-21
SLIDE 21

Legitimate ¡code: ¡

¡

  • ret ¡transfers ¡control ¡to ¡the ¡instruction ¡

¡ ¡ ¡right ¡after ¡the ¡corresponding ¡ ¡ ¡ ¡ ¡call ¡è ¡legitimate ¡call ¡site ¡

ROP ¡code: ¡

¡

  • ret ¡transfers ¡control ¡to ¡the ¡first ¡ ¡

¡ ¡ ¡instruction ¡of ¡the ¡next ¡ ¡ ¡ ¡gadget ¡ ¡è ¡arbitrary ¡locations ¡

¡

Ret ¡Instructions ¡

slide-22
SLIDE 22

Call-­‑preceded ¡gadgets ¡

¡ Gadgets ¡after ¡a ¡call ¡are ¡still ¡legal ¡. ¡ ¡ Attacker ¡still ¡can ¡use ¡them ¡as ¡legal ¡to ¡construct ¡a ¡ ROP ¡attack. ¡ ¡ BUT ¡there ¡are ¡only ¡6.4% ¡of ¡them(worst ¡case) ¡. ¡

slide-23
SLIDE 23

Raise ¡the ¡bar ¡

  • Prevent ¡the ¡execution ¡of ¡ROP ¡code. ¡
  • Force ¡Attackers ¡to ¡use ¡limited ¡set ¡of ¡ret ¡

gadgets(lower ¡functionality) ¡. ¡

  • Resort ¡to ¡jump ¡oriented ¡code(high ¡complexity). ¡

8 ¡or ¡more ¡consider ¡an ¡attack ¡by ¡Kbouncer. ¡

Gadget ¡Chaining ¡ ¡

slide-24
SLIDE 24

Gadget ¡Chaining-­‑ ¡length ¡ ¡

slide-25
SLIDE 25

Components: ¡

  • An ¡offline ¡gadget ¡extraction ¡and ¡analysis ¡toolkit ¡

¡(identifies ¡any ¡instruction ¡sequences ¡ending ¡in ¡an ¡ indirect ¡branch). ¡

  • A ¡user ¡space ¡thin ¡interposition ¡ ¡layer ¡between ¡

applications ¡and ¡Windows ¡API ¡functions.(communicate ¡ with ¡kernel ¡module). ¡ ¡

  • A ¡kernel ¡Module. ¡

¡(enable ¡LBR ¡feature ¡on ¡the ¡CPU ¡, ¡analyses ¡recorded ¡ indirect ¡branches ¡,write ¡and ¡verify ¡checkpoints ¡if ¡the ¡API ¡ function ¡is ¡legitimate ¡). ¡

Implementation ¡Kbouncer ¡

slide-26
SLIDE 26

Implementation ¡Kbouncer ¡

application call VirtualProtect detour.dll API call: LBR check ntoskrnl.exe system call handler: API call verif cation i user space LBR stack CPU kernel32.dll BOOL VirtualProtect() { ... kBouncer module kernel space

slide-27
SLIDE 27

Average ¡time ¡overhead ¡ is: ¡1% ¡ Maximum ¡time ¡

  • verhead: ¡4% ¡

¡ The ¡total ¡extra ¡time ¡ spent ¡ Across ¡all ¡tests ¡when ¡ ¡ Kbouncer ¡was ¡enable ¡ 0.5 ¡s ¡ (5μs ¡per ¡ check=100.000*5μs) ¡

¡

Runtime ¡overhead ¡of ¡Kbouncer ¡ ¡

profile pipe mailslot file thread comm console sync process

  • Avg. completion time (sec)

2 4 6 8 10 12 14 Normal kBouncer

slide-28
SLIDE 28
  • ¡LBR ¡ ¡only ¡checks ¡the ¡ ¡16 ¡gadgets. ¡
  • Gadgets ¡are ¡no ¡more ¡than ¡20 ¡instructions. ¡

1st ¡way ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡……...

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡……... ¡

<-­‑-­‑-­‑ ¡rop ¡chain ¡length ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡-­‑-­‑-­‑> ¡ ¡ ¡ ¡less ¡than ¡6-­‑8 ¡ ¡ ¡ ¡ ¡ (chain ¡detection ¡threshold) ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Gadget ¡longer ¡than ¡20 ¡instructions ¡ ¡

Limitations ¡and ¡bypassing ¡

slide-29
SLIDE 29

2nd ¡ ¡way ¡to ¡bypass ¡kbouncer. ¡

Find ¡a ¡path ¡that ¡lead ¡to ¡the ¡desired ¡API ¡call ¡as ¡ part ¡of ¡the ¡applications ¡logic. ¡

  • ¡

¡ Must ¡ ¡have ¡>=16 ¡indirect ¡branches ¡ ¡to ¡ ¡ ¡fill ¡the ¡LBR ¡stack ¡. ¡

  • ¡

¡ Must ¡not ¡change ¡the ¡state ¡ ¡ ¡ ¡ ¡of ¡arguments ¡set ¡by ¡previously ¡ ¡ ¡ ¡executed ¡ROP ¡code(Very ¡Hard) ¡. ¡

¡

Limitations ¡and ¡bypassing ¡

slide-30
SLIDE 30

Thank you !