cs642 computer security
play

CS642: Computer Security Professor Ristenpart - PowerPoint PPT Presentation

Low-level soEware vulnerability protecGon mechanisms CS642: Computer Security Professor Ristenpart h9p://www.cs.wisc.edu/~rist/ rist at cs dot wisc dot


  1. Low-­‑level ¡soEware ¡ vulnerability ¡protecGon ¡ ¡ mechanisms ¡ CS642: ¡ ¡ Computer ¡Security ¡ Professor ¡Ristenpart ¡ h9p://www.cs.wisc.edu/~rist/ ¡ rist ¡at ¡cs ¡dot ¡wisc ¡dot ¡edu ¡ University ¡of ¡Wisconsin ¡CS ¡642 ¡

  2. How ¡can ¡we ¡help ¡prevent ¡exploitaGon ¡of ¡buffer ¡ overflows ¡and ¡other ¡control ¡flow ¡hijacking? ¡ Non-­‑executable ¡memory ¡pages ¡ Return-­‑into-­‑libc ¡exploits, ¡Return-­‑oriented ¡ programming ¡ Address ¡space ¡layout ¡randomizaGon ¡ StackGuard, ¡StackShield ¡ SoEware ¡fault ¡isolaGon ¡ University ¡of ¡Wisconsin ¡CS ¡642 ¡

  3. Process ¡memory ¡layout ¡ unused ¡space ¡ heap ¡ stack ¡ .text ¡ .data ¡ .bss ¡ Env. ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ .text: ¡ ¡ ¡ ¡ ¡ ¡ heap: ¡ ¡ ¡ ¡ ¡ ¡ ¡machine ¡code ¡of ¡executable ¡ ¡dynamic ¡variables ¡ .data: ¡ stack: ¡ ¡ ¡ ¡ ¡ ¡global ¡iniGalized ¡variables ¡ ¡ ¡ ¡ ¡ ¡local ¡variables, ¡track ¡func ¡calls ¡ .bss: ¡ Env: ¡ ¡ ¡ ¡ ¡ ¡“below ¡stack ¡secGon” ¡ ¡ ¡ ¡ ¡ ¡environment ¡variables, ¡ ¡ ¡ ¡ ¡ ¡global ¡uniniGalized ¡variables ¡ ¡arguments ¡to ¡program ¡

  4. Typical ¡return ¡ptr ¡overwrite ¡exploit ¡ unused ¡space ¡ heap ¡ stack ¡ .text ¡ .data ¡ .bss ¡ Env. ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ values ¡ ptr ¡ caller ¡ name ¡ EBP ¡ EIP ¡ temp1 ¡ temp2 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡

  5. Countermeasures? ¡ • Stack ¡canaries ¡ ¡ • Address ¡space ¡layout ¡randomizaGon ¡ • W^X ¡ • Confinement ¡ ¡

  6. ProtecGng ¡the ¡stack ¡ local ¡ caller ¡ … ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ Can ¡we ¡protect ¡the ¡return ¡address ¡ from ¡being ¡overwri9en? ¡ Two ¡approaches: ¡ • Detect ¡manipulaGon ¡(and ¡then ¡fail ¡safe) ¡ • Prevent ¡it ¡completely ¡

  7. DetecGon: ¡stack ¡canaries ¡ local ¡ caller ¡ … ¡ canary ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ Canary ¡value ¡can ¡be: ¡ • Random ¡value ¡(choose ¡once ¡for ¡whole ¡process) ¡ • NULL ¡bytes ¡/ ¡EOF ¡/ ¡etc. ¡(string ¡funcGons ¡won’t ¡copy ¡past ¡canary) ¡ On ¡end ¡of ¡funcGon, ¡check ¡that ¡canary ¡is ¡correct, ¡if ¡not ¡fail ¡safe ¡

  8. DetecGon: ¡stack ¡canaries ¡ local ¡ caller ¡ … ¡ canary ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ StackGuard: ¡ • GCC ¡extension ¡that ¡adds ¡runGme ¡canary ¡checking ¡ • 8% ¡overhead ¡on ¡Apache ¡ ProPolice: ¡ • Modifies ¡how ¡canaries ¡inserted ¡ • Adds ¡protecGon ¡for ¡registers ¡ • Sorts ¡variables ¡so ¡arrays ¡are ¡highest ¡in ¡stack ¡

  9. DetecGon: ¡stack ¡canaries ¡ local ¡ caller ¡ … ¡ canary ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ Discussion: ¡How ¡would ¡you ¡get ¡around ¡it? ¡ h9p://www.phrack.org/issues.html?issue=56&id=5 ¡

  10. Reading ¡the ¡stack, ¡remotely ¡ Request ¡(can ¡trigger ¡buffer ¡overflow ¡in ¡stack) ¡ Apache ¡forks ¡ off ¡child ¡process ¡ to ¡handle ¡request ¡ Response ¡(unless ¡process ¡crashes) ¡ Apache ¡web ¡server ¡ ¡ local ¡ random ¡ caller ¡ … ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ canary ¡ local ¡vars ¡ junk ¡ x ¡ y ¡ z ¡ w For ¡each ¡value ¡x, ¡send ¡request ¡and ¡see ¡if ¡ responded ¡to ¡properly ¡ ¡ Repeat ¡for ¡subsequent ¡bytes ¡of ¡canary ¡ Expected ¡2 7 ¡ + ¡2 7 ¡ + ¡2 7 ¡ ¡ + ¡2 7 ¡ = ¡512 ¡ ¡ requests ¡

  11. DetecGon: ¡copying ¡values ¡to ¡safe ¡ locaGon ¡ local ¡ caller ¡ … ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ Make ¡a ¡copy ¡ addresses ¡ StackShield: ¡ • FuncGon ¡call: ¡copy ¡return ¡address ¡to ¡safer ¡locaGon ¡ ¡ ¡ ¡ ¡ ¡ ¡(beginning ¡of ¡.data) ¡ • Check ¡if ¡stack ¡value ¡is ¡different ¡on ¡funcGon ¡exit ¡ Discussion: ¡How ¡would ¡you ¡get ¡around ¡this? ¡

  12. PrevenGon ¡ local ¡ caller ¡ … ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ Store ¡control ¡flow ¡ addresses ¡ informaGon ¡elsewhere ¡ StackGhost: ¡ • EncrypGng ¡the ¡return ¡address ¡ • XOR ¡with ¡random ¡value ¡on ¡funcGon ¡entrance ¡ • XOR ¡with ¡same ¡value ¡on ¡funcGon ¡exit ¡ • Per-­‑kernel ¡XOR ¡vs. ¡Per-­‑process ¡XOR ¡ • Return ¡address ¡stack ¡

  13. Countermeasures? ¡ • Stack ¡canaries ¡ ¡ • Address ¡space ¡layout ¡randomizaGon ¡ • W^X ¡ • Confinement ¡ ¡

  14. Address ¡space ¡layout ¡randomizaGon ¡(ASLR) ¡ dynamically ¡linked ¡libraries ¡(libc) ¡go ¡in ¡here ¡ heap ¡ stack ¡ .text ¡ .data ¡ .bss ¡ Env. ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡

  15. Address ¡space ¡layout ¡randomizaGon ¡(ASLR) ¡ dynamically ¡linked ¡libraries ¡(libc) ¡go ¡in ¡here ¡ heap ¡ stack ¡ .text ¡ .data ¡ .bss ¡ Env. ¡ random ¡ ¡ random ¡ ¡ random ¡ ¡ 16-­‑bit ¡ 16-­‑bit ¡ 24-­‑bit ¡ offset ¡ offset ¡ offset ¡ PaX ¡implementaGon ¡for ¡example: ¡ ¡Randomize ¡offsets ¡of ¡three ¡areas ¡ • 16 ¡bits, ¡16 ¡bits, ¡24 ¡bits ¡of ¡randomness ¡ • Adds ¡unpredictability… ¡but ¡how ¡much? ¡ •

  16. DefeaGng ¡ASLR ¡ • Large ¡nop ¡sled ¡with ¡classic ¡buffer ¡overflow ¡ ¡(W^X ¡prevents ¡this) ¡ • Use ¡a ¡vulnerability ¡that ¡can ¡be ¡used ¡to ¡leak ¡address ¡informaGon ¡ (e.g., ¡prino ¡arbitrary ¡read) ¡ • Brute ¡force ¡the ¡address ¡

  17. DefeaGng ¡ASLR ¡ Brute-­‑forcing ¡example ¡from ¡reading ¡“On ¡the ¡effecGveness ¡of ¡ Address ¡Space ¡Layout ¡RandomizaGon” ¡by ¡Shacham ¡et ¡al. ¡ request ¡ Apache ¡forks ¡ off ¡child ¡process ¡ to ¡handle ¡request ¡ response ¡ Apache ¡web ¡server ¡ ¡ with ¡Oracle ¡9 ¡PL/SQL ¡ module ¡ There ¡is ¡a ¡buffer ¡overflow ¡in ¡ module ¡that ¡helps ¡process ¡ request ¡

  18. DefeaGng ¡ASLR ¡ Brute-­‑forcing ¡example ¡from ¡reading ¡“On ¡the ¡effecGveness ¡of ¡ Address ¡Space ¡Layout ¡RandomizaGon” ¡by ¡Shacham ¡et ¡al. ¡ request ¡ A9acker ¡makes ¡a ¡ ¡ Apache ¡web ¡server ¡ ¡ guess ¡of ¡where ¡usleep() ¡ with ¡Oracle ¡9 ¡PL/SQL ¡ is ¡located ¡in ¡memory ¡ module ¡ Success ¡will ¡crash ¡the ¡child ¡process ¡ ¡ Failure ¡will ¡crash ¡the ¡child ¡process ¡ ¡ aEer ¡sleeping ¡for ¡0x01010101 ¡ ¡ immediately ¡and ¡therefore ¡kill ¡connecGon ¡ microseconds ¡and ¡kill ¡connecGon ¡ If ¡on ¡64-­‑bit ¡architecture, ¡such ¡brute-­‑force ¡a9ack ¡unlikely ¡to ¡work ¡

  19. Reading ¡the ¡stack, ¡remotely ¡ Request ¡(can ¡trigger ¡buffer ¡overflow ¡in ¡stack) ¡ Apache ¡forks ¡ off ¡child ¡process ¡ to ¡handle ¡request ¡ Response ¡(unless ¡process ¡crashes) ¡ Apache ¡web ¡server ¡ ¡ local ¡ random ¡ caller ¡ … ¡ EBP ¡ EIP ¡ Param1 ¡ var1 ¡ canary ¡ local ¡vars ¡ junk ¡ x ¡ y ¡ z ¡ w x ¡ y ¡ z ¡ w Reading ¡stack ¡for ¡EBP/EIP ¡can ¡give ¡approximate ¡address ¡offset ¡

  20. ASLR ¡ Can ¡also ¡randomize ¡more ¡stuff: ¡ • InstrucGon ¡set ¡randomizaGon ¡ • per-­‑memory-­‑allocaGon ¡randomizaGon ¡ • etc. ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend