/
PRACTICAL RETURNORIENTED PROGRAMMING PRACTICAL RETURNORIENTED PROGRAMMING

PRACTICAL RETURNORIENTED PROGRAMMING - PDF document

danya
danya . @danya
Follow
342 views
Uploaded On 2021-06-30

PRACTICAL RETURNORIENTED PROGRAMMING - PPT Presentation

Dino Dai Zovi Session ID RR304Session Classification Advanced WHY AM I HERE Show the practical applications of returnoriented programming to exploitation of memory corruption vulnerabilities vul ID: 849770

oriented return dep memory return oriented memory dep aslr stack executable vulnerabilities vulnerability data exploitation exploit pop programming aurora

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "PRACTICAL RETURNORIENTED PROGRAMMING" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1 PRACTICAL RETURN-ORIENTED PROGRAMMING Di
PRACTICAL RETURN-ORIENTED PROGRAMMING Dino Dai Zovi Session ID: RR-304Session Classification: Advanced WHY AM I HERE? Show the practical applications of return-oriented programming to exploitation of memory corruption vulnerabilities vulnerabilities “Preventing the introduction of malicious is not enough to prevent the execut

2 ion of malicious Demonstratethatwhileex
ion of malicious Demonstratethatwhileexploitmitigationsmake while exploitation of many vulnerabilities impossible or more difficult, they do not prevent all exploitation – Moderncomputingneedsmoreisolationandseparationbetween – Modern separation components (privilege reduction, sandboxing, virtualizati

3 on)The user-separation security model of
on)The user-separation security model of modern OS is not ideally suited to the single-user system Whdllflitihtddit ll – Wh y o a ll o my app li ca ave access t o rea d an d wr it e ll of my data“TheInnocentReturnIntoLibcwithoutx86)”, HovavShacham(ACM AGENDA Current State of Ex p loitation OrientedProgramming BiDEP B Ex

4 ploiting iPhone 3 Current State of Curr
ploiting iPhone 3 Current State of Current State of Exploitation Exploitation 4 A BRIEF HISTORY OF MEMORY CORRUPTION Morris Worm (November 1988) – Exploited a stack buffer overflow in BSD in.fin g erdon VAX g Payload issued execve(“/bin/sh”, 0, 0) system call directlyThomas Lopaticpublishes remote stack buffer overflow expl

5 oitagainstNCSAHTTPDforHP - PA(February19
oitagainstNCSAHTTPDforHP - PA(February1995) exploit - “Smashing the Stack for Fun and Profit” by Aleph One published in Phrack49 (August 1996) Researchers find and exploit stack buffer overflows in a variety of Unix software throughout the late 90’s Many security experts thought (incorrectly) that stack buffer ov

6 erflows were the only exploitable proble
erflows were the only exploitable problem 5 A BRIEF HISTORY OF MEMORY CORRUPTION “JPEG COM Marker Processing Vulnerability in Netscape Demonstratesexploitationofheapbufferoverflowsbyoverwriting – Demonstrates buffer heap free block next/previous linked list pointersApache/IIS Chunked-Encoding Vulnerabilities dem

7 onstrate loitation of inte g er overflo
onstrate loitation of inte g er overflow vulnerabilities pg �Integer overflow = stack of heap memory corruptionIn early 2000’s, worm authors took published exploits and unleashedwormsthatcausedwidespreaddamage unleashed widespread Exploited stack buffer overflow vulnerabilities in Microsoft operating Results

8 in Bill Gates’ “Trustworthy Computing”
in Bill Gates’ “Trustworthy Computing” memo Microsoft’s Secure Development Lifecycle (SDL) combines exploit mitigation 6 EXPLOIT MITIGATION Patching every security vulnerability and writing 100% bug-free code is impossible Eliiiikldhidk – E xp i i ons ac k now d ge t hi s an d attempt to ma k exploitation of remaining vulner

9 abilities impossible or at least more di
abilities impossible or at least more difficult WindowsXPSP2wasthefirstwidespreadoperating system to incorporate exploit mitigationsProtected stack metadata (Visual Studio compiler /GS flag) – Protectedheapmetadata( RtlHeap SafeUnlinking) Protected ( SafeSEH(compile-time exception handler registration)Softw

10 are, Hardware-enforced Data Execution Pr
are, Hardware-enforced Data Execution Prevention (DEP) • WindowsVistaimplementsAddressSpaceLayout • Windows Vista Invented by and first implemented in PaXproject for Linux 7 MITIGATIONS MAKING EXPLOITATION HARDER DEP ASLR SafeSEH Difficul Stack Protection rotect Mitigations Mitigations EXPLOIT TECHNIQUES RENDERED INE

11 FFECTIVE Stackreturnaddressoverwrite Sta
FFECTIVE Stackreturnaddressoverwrite Stackreturnaddressoverwrite frameoverwrite frameoverwrite freemetadataoverwrite freemetadataoverwrite Applicationdata Applicationdata ??? MITIGATIONS REQUIRES OS, COMPILER, AND APPLICATION PARTICIPATION AND ARE ADDITIVE mitigationsprotections,Validation Alii Cil ations ationsStackcookies,Sa

12 feSEHDEP, WHAT MITIGATIONS ARE ACTIVE IN
feSEHDEP, WHAT MITIGATIONS ARE ACTIVE IN MY APP? It is difficult for even a knowledgeable user to determine which mitigations are present in their applications Ihliiildihki? – I s t h e app li cat on comp il e d h stac k protect i on Is the application compiled with SafeSEH?Do all executable modules opt-in to DEP (NXCOMPAT)

13 and ASLR(DYNAMICBASE)? ASLR Is the pr
and ASLR(DYNAMICBASE)? ASLR Is the process running with DEP and/or Permanent DEP?Internet Explorer 8 on Windows 7 is 100% safe, right? IE8Wid7thltitflitititi – IE8 on Wi n d uses th e comp l e t e su it e o f exp l o … as long as you don’t install any 3-party pluginsor ActiveX WhataboutAdobeReader? You don’t want

14 to know… 11 Return Oriented Return - Pr
to know… 11 Return Oriented Return - Programming Programming RETURN-TO-LIBC An attack against non-segments (DEP, W^X, etc) f Arg2 Instead o f return address to return into shellcode, return into a loaded library to simulate a fill Next Arg1 StackGro StackGro on ca ll Data from attacker’s controlled buffer on stack areusedas

15 thefunction ’ s th functions i.e.
thefunction ’ s th functions i.e. call system( “Gettingaroundexecutablestackfix)”,(BUGTRAQ,August RETURN-ORIENTED PROGRAMMING Instead of returning to ftitt moveax 0xc3084189 f unc ons, re t urn followed by a return Can return into middle of existing instructions to simulate different B8 All we need are useable y te

16 sequences an y where “TheInnocentRetur
sequences an y where “TheInnocentReturnIntoLibcwithoutx86)”, HovavShacham(ACM RETURN-ORIENTED PROGRAMMING Various instruction sequences can be combined to form g ad eax eax Gadgets perform higher-level actions Witifi32 bitl add eax,ecx add eax,ecx ret ret mov[eax],ecx mov[eax],ecx e spec ifi c va l to specific memory loc

17 ationAdd/sub/and/or/xorvalue at memoryl
ationAdd/sub/and/or/xorvalue at memorylocationwith r et et Call function in shared Gadgets Gadgets EXAMPLE GADGET pop eaxret pop eaxret pop ecxret pop ecxret mov[ecx],eax mov[ecx],eax STOREIMMEDIATEVALUE STOREIMMEDIATEVALUE GENERATING A RETURN-ORIENTED PROGRAM Scan executable memory regions of common shared libraries for u

18 seful instruction sequences followed by
seful instruction sequences followed by Chain returns to identified sequences to form all of the desiredgadgetsfromaTuring - completegadgetcatalog a Turing The gadgets can be used as a backend to a C compilerSee HovavShacham’spaper for details on GCC compiler backend and demonstration of return-oriented quicksor

19 t h to p revent the execution of malici
t h to p revent the execution of malicious gp computations Bypassing DEP 18 DATA EXECUTION PREVENTION DEP uses the NX/XD bit of x86 processors to enforce the non-execution of memory pages without PROTEXECpermission PROT _ On non-PAE processors/kernels, �READ = EXECPaXproject cleverly simulated NX by desynchronizing

20 instruction anddata TLBs and Requi
instruction anddata TLBs and Requires every module in the process (EXE and DLLs) to be compiled with /NXCOMPAT DEPbtdffdillfthhl can b e d f e w h o l by calling (or returning into) NtSetInformationProcess()XP SP3, Vista SP1, and Windows 7 su pp ort “Permanent pp DEP” that once enabled, cannot be disabled at run-time

21 “BypassingWindowsHardwareEnforcedDataExe
“BypassingWindowsHardwareEnforcedDataExecutionPrevention”, Ski (ifd200) k apean f O cto 5 ) RETURN-ORIENTED EXPLOITS First, attacker must cause stack pointer to point into Thiffikbfffl – Thi s comes f or b u er over fl Exploiting other vulnerabilities (i.e. heap overflows) requires sequence to point ESP into attacker data x

22 chgeax, esp ret ret Attacker-controlled
chgeax, esp ret ret Attacker-controlled data contains a return-oriented Thldb100%t itdi – Th ese pay l oa s may b e 100% re t urn-or d programm i simply act as a temporary payload stage that enables subsequent execution of a traditional machine-code payload 20 RETURN-ORIENTED PAYLOADSTAGE HEAP_CREATE_ENABLE_EXECUTE method

23 hHeap= HeapCreate(HEAP_CREA fPld HAll(hH
hHeap= HeapCreate(HEAP_CREA fPld HAll(hH 0 dPldLth ) p f n P eap oc eap 0 P oa dL eng th CopyMemory(pfnPayload, ESP+offset VirtualAlloc ()method VirtualAlloc , MEM_COMMIT, PAGE_EXECUTE_READWRITE);CopyMemory(lpAddress, ESP+offset VirtualProtect(ESP) method& ~(4096 –1), dPldSi PAGEEXECUTEREADWRITE) d w P oa ze _ _ ; “DEPLIB”,Pa

24 bloNovember DO THE MATH StackPivot Stack
bloNovember DO THE MATH StackPivot StackPivot ReturnOrientedPayloadStage ReturnOrientedPayloadStage TraditionalPayload TraditionalPayload PermanentBypass PermanentBypass DEP WITHOUT FULL ASLR IS VERY WEAK SAUCE No ASLR: – Exploitationrequiresbuildingareusablereturn - a oriented payload stage from any common DLLOne or

25 more modules do not opt-in to ASLR: pay
more modules do not opt-in to ASLR: payload stage from useful instructions found in non- All executable modules opt-in to ASLR:Exploitation requires exploiting a memory disclosure vulnerabilitytorevealtheloadaddressofoneDLL vulnerability and dynamically building t THE “AURORA” IE VULNERABILITY EVENTPARAMscopi

26 ed by createEventObject(oldEvent) don’t
ed by createEventObject(oldEvent) don’t increment CTreeNoderef count CElement EVENTPARAM CTreeNode m_pSrcElement THE “AURORA” IE VULNERABILITY EVENTPARAM member variable and CElementmember variable both point to CTreeNodeobject CElement EVENTPARAM CTreeNode m_pSrcElement THE “AURORA” IE VULNERABILITY When HTML element is re

27 moved from DOM, CElementis freed and CTr
moved from DOM, CElementis freed and CTreeNoderefcountdecremented CElement EVENTPARAM CTreeNode m_pSrcElement THE “AURORA” IE VULNERABILITY If CTreeNoderefcount== 0, the object will be freed and EVENTPARAM points free memory EVENTPARAM CTreeNode m_pSrcElement EXPLOITING THE AURORA VULNERABILITY Attacker can use controlled heap

28 allocations to replace EVENTPARAMCraft
allocations to replace EVENTPARAMCraftedCTreeNode m_pSrcElement EXPLOITING THE AURORA VULNERABILITY object in the heap spray, which points back to itself as a crafted vtable CElement vtable xchgeax,esp pop; CraftedCTreeNode CElement vtable CElement re EXPLOITING THE AURORA VULNERABILITY Attacker triggers virtual function ca

29 ll through crafted CElementvtable, which
ll through crafted CElementvtable, which performs a stack pivot through a return to an ‘xchgeax, esp; ret’ sequence and runs CElement vtable ret CElement vtable retret xchgeax,esp pop; retret Return oriented Return oriented stage Aurora Exploit Demo 31 Exploiting iPhone 32 REVIEW OF IPHONEOS SECURITY MECHANISMS W^X non-execu

30 table memory policy – Memor pa g e can’
table memory policy – Memor pa g e can’t be writable and executable at the same time yg Code-signing enforcement (unless you JailBreak)If a memory page’s backing store is not an executable binary signedbyAppleitcannotbemarkedPROTEXEC signed _ If an executable memory page has been made writable, it cannot later be m

31 ade executable again – Can’t execute a b
ade executable again – Can’t execute a binar that has not been si g ned b y A ygypp Restricts process behavior at run-time by blocking disallowed systemcalls system �Policy against background processes = fork() returns EPERMNo ASLR 33 LACK OF ASLR IS WEAK Lack of ASLR means that all libraries and frameworks can be

32 used as source material for return - or
used as source material for return - orientedprograms Writabledatasegmentsatknownlocationscanbe Writable Return-oriented payloads for iPhonehave already beenpresented 1 been 1 Sends contents of file to remote serverStill restricted by sandbox policy Rt itdldfWidMbil • t d pay l oa n d ARM have also recently be

33 en developed 1and Payloads” Iozzo ( Blac
en developed 1and Payloads” Iozzo ( BlackHat X Payloads” , Iozzo ( BlackHat “ReturnOrientedProgrammingforArchitecture”,Kornau(Diploma, RETURN-ORIENTED ARM ARM (32-bit) vs. Thumb mode (16-bit)Bytes decode to different instructions depending on CPU state BX and BLX instructions can switch modes based on least significant bit of

34 address �(0 = �ARM, 1 = Th
address �(0 = �ARM, 1 = Thumb)Can also switch modes via LDR/LDM/POP instructions that set PC register register Scan all executable segments and disassemble as both ARM and Thumb to look for instruction sequences followed by returns(LDM/POP) returns (LDM/POP) Keep track of CPU state when generating return-orie

35 nted program and switch states as necess
nted program and switch states as necessary in gadgets Return-oriented programming also sidesteps exploitation difficulties presented by separate instruction and data caches 35 ARMV5 GADGETS Simulate a function call and store return value {47} 4 , r 7 , pc } strr0, [r4] Storeimmediatevaluetomemory memory strr4, [r5] Load

36 value from memory into r0ldrr0, [r0] •
value from memory into r0ldrr0, [r0] • Andsoon • And For more details, see “Return Oriented Programming for the ARM Architecture”, Tim Kornau2009 36 Wrapping Up 37 OTHER APPLICATIONS OF RETURN-ORIENTED Embedded processors often have separate instruction and data write-back caches, which make injecting code Return-orient

37 ed programming techniques can be used to
ed programming techniques can be used to flush the caches before executing the payload (Dai Zovi, 2003) x86-64 ABI requires non-executable (NX) data memory“Borrowed code chunks” exploitation technique (Krahmer2005) ShddikdiROMd • ome secure h ar eep co d e n an d Checkowayet al (Usenix2008) demonstrated the use of ROP on

38 thZ80 bdSiAVCAdttihi th e b S a AVC ag
thZ80 bdSiAVCAdttihi th e b S a AVC age secure vo ti ng mac hi ne CONCLUSIONS Return-oriented techniques are increasingly required to exploit vulnerabilities on systems with non-executable data memory protections protections A return-oriented payload stage can be developed to bypass Bypassing DEP under ASLR requires at lea

39 st one non-ASLR Bypassing DEP under full
st one non-ASLR Bypassing DEP under full ASLR requires an executable memory address disclosure vulnerability in addition to memory corruption iPhone’scode signing enforcement requires attackers to develop Attacker’s actions are still limited by the application sandbox is more im p ortant than p reventin g g ppg malicious

40 TAKEAWAYS IT Security – Malware ma y e
TAKEAWAYS IT Security – Malware ma y eventuall y use these techniques to exploit DEP- yy Malware analysts must learn how to analyze return-oriented Software VendorsDo not assume DEP/ASLR make vulnerabilities non-exploitable – Better to assume that all vulnerabilities y ield full code execution y Restrict the actions that

41 may be performed by application componen
may be performed by application components that parse and handle potentially untrusteddataPrivilege reduction (i.e. run under Low Integrity on Vista/7) Sandboxing (see Chromium’sVirtualization? http:// devchromiumorg /developers/design documents/sandbox http:// dev . chromium . org /developers/design documents/sandbox Question