Transparent ROP Exploit Mitigation using Indirect Branch - - PowerPoint PPT Presentation
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
- Buffer ¡overflow ¡
- Integer ¡overflow ¡
- Use ¡after ¡free ¡
- Function ¡point ¡overflow ¡
¡ ¡
Vulnerabilities ¡
Buffer ¡overflow-‑executable ¡stack ¡
Shellcode ¡ NEW ¡ RET ¡ Vulnerable ¡Buffer ¡ ¡ Local ¡Var. ¡ Ret ¡ Address ¡
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 ¡
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 ¡
¡ ¡ ¡ ¡ ¡ ¡ ¡
- 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 ? ¡
- 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) ¡
¡
- 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) ¡
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 ¡
- ¡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) ¡
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 ¡
Simple ¡Example: ¡
¡ ¡ ¡ ¡ ¡ ¡
Attacker ¡overflows ¡the ¡valuable ¡buffer ¡and ¡the ¡function ¡ pointer( ¡f ¡) ¡with ¡a ¡with ¡any ¡value ¡he ¡wants. ¡
¡ ¡ ¡ ¡
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. ¡
¡ ¡
ROP(Return ¡Oriented ¡Programming) ¡
- 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 ¡
- 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 ¡
- 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 ¡
- 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 ¡
- 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 ¡
LBR ¡stack ¡Inspection ¡on ¡API ¡Function ¡ Entry ¡
kernel user space
time API call verification
system DLL
LBR check API call system call
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 ¡
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 ¡
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) ¡. ¡
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 ¡ ¡
Gadget ¡Chaining-‑ ¡length ¡ ¡
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 ¡
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
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
- ¡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 ¡
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) ¡. ¡
¡