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 ¡ values ¡ ptr ¡ caller ¡ name ¡ EBP ¡ EIP ¡ temp1 ¡ temp2 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡ Why ¡should ¡the ¡machine ¡interpret ¡ ¡ stack ¡data ¡as ¡instrucGons? ¡

  5. W^X ¡ ¡(W ¡xor ¡X) ¡ • The ¡idea: ¡mark ¡memory ¡page ¡as ¡either ¡ – Writable ¡or ¡Executable ¡(not ¡both) ¡ • Specifically: ¡ ¡make ¡heap ¡and ¡stack ¡non-­‑ executable ¡ caller ¡ name ¡ EBP ¡ EIP ¡ temp1 ¡ temp2 ¡ values ¡ ptr ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡

  6. W^X ¡ ¡(W ¡xor ¡X) ¡ • AMD64: ¡ ¡NX ¡bit ¡(Non-­‑Executable) ¡ ¡ ¡ ¡ ¡ ¡IA-­‑64: ¡ ¡ ¡ ¡ ¡ ¡XD ¡bit ¡(eXecute ¡Disabled) ¡ ¡ ¡ ¡ ¡ARMv6: ¡ ¡ ¡XN ¡bit ¡(eXecute ¡Never) ¡ – Extra ¡bit ¡in ¡each ¡page ¡table ¡entry ¡ – Processor ¡refuses ¡to ¡execute ¡code ¡if ¡bit ¡= ¡1 ¡ – Mark ¡heap ¡and ¡stack ¡segments ¡as ¡such ¡ caller ¡ name ¡ EBP ¡ EIP ¡ temp1 ¡ temp2 ¡ values ¡ ptr ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡

  7. W^X ¡ ¡(W ¡xor ¡X) ¡ SoEware ¡emulaGon ¡of ¡NX ¡bits ¡ • ExecShield ¡(RedHat ¡Linux) ¡ • PaX ¡ ¡(Page-­‑eXec) ¡(uses ¡NX ¡bit ¡if ¡available) ¡ mprotect() ¡ • Process ¡can ¡set ¡permissions ¡on ¡memory ¡pages ¡

  8. Will ¡W^X ¡stop: ¡ AlephOne’s ¡stack ¡overflow ¡exploit? ¡ Yes ¡ Stack ¡smash ¡that ¡overwrites ¡pointer ¡to ¡ Yes ¡ point ¡at ¡shell ¡code ¡in ¡Heap ¡or ¡Env ¡variable? ¡ Heap ¡overflow ¡with ¡same ¡shell ¡locaGon? ¡ Yes ¡ Double ¡free ¡with ¡same ¡shell ¡locaGon? ¡ Yes ¡

  9. LimitaGons ¡of ¡W^X ¡ SoEware ¡emulaGon ¡… ¡ • May ¡not ¡be ¡perfect ¡and ¡is ¡slow ¡ • E.g., ¡double-­‑free ¡or ¡format-­‑string ¡vulnerability ¡ may ¡allow ¡turning ¡off ¡protecGons ¡ Breaking ¡compaGbility ¡ • GCC ¡stack ¡trampolines ¡ ¡(calling ¡convenGons, ¡ nested ¡funcGons) ¡ • Just-­‑in-­‑Gme ¡(JIT) ¡compilaGon ¡using ¡heap ¡ ¡ Exploits ¡designed ¡to ¡only ¡run ¡exisGng ¡code ¡

  10. What ¡about ¡circumvenGng ¡W^X? ¡ Exploits ¡designed ¡to ¡only ¡run ¡exisGng ¡code ¡

  11. Return-­‑into-­‑libc ¡exploits ¡ • libc ¡is ¡standard ¡C ¡library, ¡included ¡in ¡all ¡ processes ¡ • system() ¡-­‑-­‑-­‑ ¡execute ¡commands ¡on ¡system ¡

  12. Return-­‑into-­‑libc ¡exploits ¡ Overwrite ¡EIP ¡with ¡address ¡of ¡system() ¡funcGon ¡ junk2 ¡just ¡some ¡filler: ¡returned ¡to ¡aEer ¡system ¡call ¡ first ¡argument ¡to ¡system() ¡is ¡ptr ¡to ¡“/bin/sh” ¡ addr ¡of ¡ ¡ addr ¡of ¡ junk junk ¡ “/bin/sh ” ¡ system() ¡ 2 ¡ caller ¡ name ¡ EBP ¡ EIP ¡ temp1 ¡ temp2 ¡ local ¡vars ¡ Low ¡memory ¡ ¡ High ¡memory ¡ addresses ¡ addresses ¡

  13. Return-­‑into-­‑libc ¡exploits ¡ This ¡simple ¡exploit ¡has ¡a ¡few ¡deficiencies ¡(from ¡a9acker’s ¡pov): ¡ ¡-­‑ ¡Crashes ¡aEer ¡exiGng ¡called ¡/bin/sh ¡( ¡easy ¡to ¡fix ¡with ¡exit() ¡) ¡ ¡-­‑ ¡system() ¡drops ¡privileges ¡by ¡default ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ junk ¡ prini ¡ execl ¡ “%3\$n” ¡ “./wrap” ¡ “./wrap” ¡ HERE ¡ wrap.c ¡: ¡ execl( ¡“./wrap”, ¡ ¡“./wrap”, ¡0 ¡) ¡ Writes ¡ main() ¡{ ¡ 0 ¡here ¡ ¡ ¡ ¡setuid(0); ¡ ¡ ¡ ¡setgid(0); ¡ prini( ¡“%3$n”, ¡… ¡) ¡ %3n ¡means ¡“write ¡number ¡of ¡bytes ¡in ¡format ¡ ¡ ¡ ¡system(“bin/sh”); ¡ string ¡up ¡to ¡the ¡format ¡token ¡into ¡third ¡parameter” ¡ } ¡

  14. Return-­‑into-­‑libc ¡exploits ¡ These ¡exploits ¡only ¡execute ¡instrucGons ¡marked ¡executable ¡ W^X ¡cannot ¡stop ¡such ¡an ¡a9ack ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ addr ¡of ¡ junk ¡ prini ¡ execl ¡ “%3\$n” ¡ “./wrap” ¡ “./wrap” ¡ HERE ¡ wrap.c ¡: ¡ execl( ¡“./wrap”, ¡ ¡“./wrap”, ¡0 ¡) ¡ Writes ¡ main() ¡{ ¡ 0 ¡here ¡ ¡ ¡ ¡setuid(0); ¡ ¡ ¡ ¡setgid(0); ¡ prini( ¡“%3$n”, ¡… ¡) ¡ %3n ¡means ¡“write ¡number ¡of ¡bytes ¡in ¡format ¡ ¡ ¡ ¡system(“bin/sh”); ¡ string ¡up ¡to ¡the ¡format ¡token ¡into ¡third ¡parameter” ¡ } ¡

  15. Return-­‑into-­‑libc ¡exploits ¡ Return-­‑into-­‑libc ¡may ¡seem ¡limited: ¡ -­‑ Only ¡useful ¡for ¡calling ¡libc ¡funcGons ¡ -­‑ Okay ¡in ¡last ¡example, ¡but ¡not ¡always ¡sufficient ¡ -­‑ Before ¡W^X, ¡exploit ¡could ¡run ¡arbitrary ¡code ¡ Can ¡we ¡ not ¡inject ¡any ¡malicious ¡code ¡and ¡yet ¡ have ¡an ¡exploit ¡that ¡runs ¡ arbitrary ¡code ? ¡

  16. Return-­‑oriented ¡programming ¡(ROP) ¡ Second ¡return-­‑into-­‑libc ¡exploit: ¡ ¡ ¡ ¡ ¡ ¡ ¡self-­‑modifying ¡exploit ¡buffer ¡to ¡call ¡a ¡sequence ¡of ¡libc ¡calls ¡ Logical ¡extreme: ¡ ¡ ¡chain ¡together ¡a ¡long ¡sequence ¡of ¡calls ¡to ¡code ¡ But ¡we ¡want ¡arbitrary ¡code, ¡not ¡sequence ¡of ¡ ¡libc ¡calls: ¡ ¡chain ¡together ¡a ¡long ¡sequence ¡of ¡calls ¡to ¡code ¡snippets ¡

  17. Return-­‑oriented ¡programming ¡(ROP) ¡ (*) ¡ From ¡Shacham ¡“The ¡Geometry ¡of ¡Innocent ¡Flesh ¡on ¡the ¡Bone…” ¡2007 ¡ If ¡this ¡is ¡on ¡stack ¡and ¡(*) ¡is ¡return ¡pointer ¡aEer ¡buffer ¡overflow, ¡then ¡ ¡ the ¡result ¡will ¡be ¡loading ¡0xdeadbeef ¡into ¡edx ¡register ¡

  18. Return-­‑oriented ¡programming ¡(ROP) ¡ From ¡Shacham ¡“The ¡Geometry ¡of ¡Innocent ¡Flesh ¡on ¡the ¡Bone…” ¡2007 ¡

  19. From ¡ ¡ Shacham ¡ ¡ “The ¡Geometry ¡of ¡ ¡Innocent ¡Flesh ¡on ¡ ¡ the ¡Bone…” ¡2007 ¡

  20. ROP ¡where ¡do ¡we ¡get ¡code ¡snippets? ¡ c7  45   d4  01 movl $0x00000001, -44(%ebp) 00  00   00 � add %dh, %bh f7  c7    07  test $0x00000007, %edi  00 movl $0x0F000000, (%edi) 00   00   0f � } 95 xchg %ebp, %eax setnzb -61(%ebp) } 45 inc%ebp } ret c3 Buchanan ¡et ¡al., ¡Blackhat ¡2008 ¡

  21. W^X ¡wrapup ¡ W^X ¡does ¡not ¡prevent ¡arbitrary ¡code ¡execuGon, ¡ but ¡does ¡make ¡it ¡harder! ¡ What ¡else ¡can ¡we ¡do? ¡

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