transparent rop exploit mitigation using indirect branch
play

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


  1. Transparent ¡ROP ¡Exploit ¡ Mitigation ¡using ¡Indirect ¡ Branch ¡Tracing ¡ Alexandros ¡Perrakis ¡ Manolis ¡Karabinakis ¡ Stelios ¡Ninidakis ¡

  2. Vulnerabilities ¡ • Buffer ¡overflow ¡ • Integer ¡overflow ¡ • Use ¡after ¡free ¡ • Function ¡point ¡overflow ¡ ¡ ¡

  3. Buffer ¡overflow-­‑executable ¡stack ¡ Ret ¡ Local ¡Var. ¡ Vulnerable ¡Buffer ¡ ¡ Address ¡ NEW ¡ Shellcode ¡ RET ¡

  4. Buffer ¡overflow-­‑executable ¡stack ¡ 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. ¡ ¡ ¡

  5. Canary ¡value ¡ • Produced ¡by ¡the ¡compiler ¡ • Checked ¡at ¡run-­‑time ¡ • Canary ¡is ¡a ¡random ¡value ¡ ¡ Problems: ¡ • Can ¡be ¡disclosed ¡ • Can ¡be ¡brute-­‑forced ¡ ¡ ¡ Ret ¡ Local ¡Var. ¡ Vulnerable ¡Buffer ¡ ¡ Address ¡

  6. W ⊕ ¡X ¡ ¡ ¡ ¡ Executable Executable Executable Executable ¡ ¡ ? ¡ ? ¡ ? ¡ ¡ Stack ¡ Heap ¡ Data ¡ Text ¡ ¡ ¡ High ¡Address ¡ Low ¡Address ¡ ¡ • W ¡ ⊕ ¡X ¡ ¡Can ¡be ¡either ¡Writable ¡or ¡Executable(not ¡both) ¡ • Strong ¡defense ¡mechanism ¡against ¡buffer ¡overflow ¡ ¡ ¡

  7. How ¡about ¡ ¡DEP(Data ¡Execution ¡ Prevention) ¡ • 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 ¡ on ¡re-­‑usable ¡code ¡ ¡

  8. ASLR(Address ¡Space ¡Layout ¡ Randomization) ¡ ¡ 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. ¡ • ¡ ¡

  9. Runtime ¡ ¡monitoring ¡ ¡solutions ¡ 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 ¡

  10. ROP(Return ¡Oriented ¡Programming) ¡ • ¡ 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. ¡

  11. ROP(Return ¡Oriented ¡Programming) ¡ What ¡is ¡a ¡gadget? ¡ Sequences ¡of ¡instructions ¡ ROP ¡Chain ¡ TEXT ¡Section ¡ ending ¡with ¡an ¡indirect ¡ (Code) ¡ Addr. ¡of ¡G1 ¡ branch. ¡ G2; ¡ ret ¡ Addr. ¡of ¡G2 ¡ ¡ GN; ¡ ret ¡ Addr. ¡of ¡G3 ¡ ¡ G1; ¡ ret ¡ ¡ G3; ¡ ret ¡ ¡ Addr. ¡of ¡GN ¡

  12. ROP(Return ¡Oriented ¡Programming) ¡ Simple ¡Example: ¡ ¡ ¡ ¡ ¡ ¡ ¡ Attacker ¡overflows ¡the ¡valuable ¡buffer ¡and ¡the ¡function ¡ pointer( ¡f ¡) ¡with ¡a ¡with ¡any ¡value ¡he ¡wants. ¡ ¡ ¡ ¡ ¡

  13. ROP(Return ¡Oriented ¡Programming) ¡ 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. ¡ ¡ ¡

  14. Kbouncer-­‑Defense ¡to ¡ROP ¡ • 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 ¡ ¡

  15. LBR ¡ • 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 ¡ ¡ ¡

  16. Syscalls ¡vs. ¡API ¡calls ¡ • 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 ¡ ¡

  17. LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡ • 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 ¡ over ¡the ¡hook ¡of ¡the ¡function's ¡prologue, ¡and ¡ then ¡normally ¡executes ¡the ¡function ¡body ¡ ¡

  18. LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡ • 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 ¡ ¡ ¡

  19. LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡ API call verification kernel LBR check system DLL user space time API call system call

Recommend


More recommend