Exploi:ng Memory Corrup:on Vulnerabili:es in the Java Run:me - - PowerPoint PPT Presentation

exploi ng memory corrup on vulnerabili es in the java run
SMART_READER_LITE
LIVE PREVIEW

Exploi:ng Memory Corrup:on Vulnerabili:es in the Java Run:me - - PowerPoint PPT Presentation

Exploi:ng Memory Corrup:on Vulnerabili:es in the Java Run:me Joshua J. Drake December 15 th 2011 Please complete the Speaker Feedback Surveys! This will


slide-1
SLIDE 1

Joshua ¡J. ¡Drake ¡ December ¡15th ¡2011 ¡

Exploi:ng ¡Memory ¡Corrup:on ¡ Vulnerabili:es ¡in ¡the ¡Java ¡Run:me ¡

Please ¡complete ¡the ¡Speaker ¡Feedback ¡Surveys! ¡

This ¡will ¡both ¡help ¡speakers ¡improve ¡and ¡help ¡Black ¡Hat ¡make ¡beHer ¡decisions ¡regarding ¡content ¡and ¡presenters ¡for ¡future ¡

  • events. ¡
slide-2
SLIDE 2

About ¡the ¡Presenter ¡

  • Joshua ¡J. ¡Drake, ¡aka ¡jduck ¡

– Senior ¡Research ¡Consultant ¡with ¡Accuvant ¡LABS ¡

  • Vulnerability ¡Discovery ¡& ¡Exploita:on ¡
  • Binary/Source ¡Audit, ¡Reverse ¡Engineering ¡

¡ ¡ ¡ ¡ ¡ – ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Contributor ¡

  • Formerly ¡Lead ¡Exploit ¡Developer ¡
slide-3
SLIDE 3

Overview ¡

  • Background ¡
  • Hurdles ¡
  • Exploi:ng ¡
  • Demos ¡
  • Conclusion ¡
slide-4
SLIDE 4

Mo:va:on ¡

  • …share ¡informa:on ¡and ¡techniques ¡to ¡make ¡

Java ¡Run:me ¡Environment ¡(JRE) ¡exploita:on ¡

  • easier. ¡

– JRE ¡architecture ¡informa:on ¡ – Various ¡hurdles ¡encountered ¡during ¡dev ¡

  • i.e. ¡CVE-­‑2009-­‑3867, ¡CVE-­‑2009-­‑3869 ¡

– Provide ¡tools ¡for ¡future ¡work ¡

slide-5
SLIDE 5

Background ¡

  • Why ¡Java? ¡
  • Popular? ¡
  • Maybe ¡a ¡‘lil. ¡

More ¡claims ¡here: ¡ hHp://www.java.com/en/about/ ¡

slide-6
SLIDE 6

Background ¡

  • Java ¡is ¡cross-­‑plaborm! ¡
slide-7
SLIDE 7

Background ¡

  • Java ¡SE ¡6 ¡focus ¡

– Tested ¡latest ¡(6u29) ¡ – JRE ¡7 ¡GA ¡is ¡released! ¡

  • Buggy… ¡
  • Slow ¡adop:on… ¡
  • One ¡update ¡already ¡
slide-8
SLIDE 8

Background ¡-­‑ ¡Security ¡

  • 27 ¡updates ¡over ¡about ¡5 ¡years ¡
  • Well ¡over ¡100 ¡CVEs ¡
  • Targeted ¡in ¡73% ¡of ¡exploit ¡kits ¡
  • 10 ¡exploits ¡in ¡

– 4 ¡Windows ¡specific ¡ – 1 ¡meatware ¡aHack ¡(java_signed_applet) ¡ – 3 ¡involve ¡memory ¡corrup:on ¡

slide-9
SLIDE 9

Background ¡

  • What ¡does ¡the ¡“JRE” ¡include? ¡

hHp://java.sun.com/products/hotspot/whitepaper.html ¡-­‑ ¡Recommended ¡Reading ¡

JRE ¡

slide-10
SLIDE 10

Background ¡

  • Java ¡has ¡a ¡plen:ful ¡aHack ¡surface! ¡

– Browser ¡Plug-­‑in ¡

  • Automa:cally ¡installed ¡
  • Applets ¡

– 70% ¡of ¡Metasploit ¡Java ¡exploits ¡use ¡Applets ¡

  • “LiveConnect” ¡Java/Browser ¡interface ¡

– Java ¡Web ¡Start ¡& ¡JNLP ¡ – More ¡

slide-11
SLIDE 11

Background ¡-­‑ ¡Applets ¡

  • AHackers ¡use ¡applets ¡because… ¡

– Applet ¡Java ¡code ¡and ¡JAR ¡contents ¡are ¡100% ¡ aHacker ¡controlled ¡ – Tons ¡of ¡na:ve ¡library ¡code ¡is ¡reachable ¡

  • Images, ¡Sounds, ¡Compressors ¡and ¡more ¡
  • Includes ¡embedded ¡copies ¡of ¡open ¡source ¡(zlib, ¡etc) ¡

Trusted ¡ Untrusted ¡ Signed ¡ Unsigned ¡ Runs ¡with ¡full ¡user ¡privileges ¡ Subject ¡to ¡Java ¡“sandbox” ¡ User ¡is ¡Prompted ¡ No ¡promp:ng ¡

slide-12
SLIDE 12

Background ¡-­‑ ¡Technical ¡

  • Java ¡Virtual ¡Machine ¡(JVM) ¡

– Named ¡“HotSpot” ¡ – WriHen ¡in ¡na:ve ¡code ¡ – Processes ¡Java ¡Bytecode ¡ – Might ¡just-­‑in-­‑:me ¡compile ¡ – Executes ¡or ¡Interprets ¡ resul:ng ¡code ¡

slide-13
SLIDE 13

Background ¡– ¡Security ¡

  • Process ¡Architecture ¡

– Plug-­‑in ¡loads ¡in ¡Browser ¡address ¡space ¡

  • Includes ¡several ¡libraries ¡

– Since ¡Update ¡10 ¡

  • Java.exe ¡runs ¡as ¡an ¡external ¡process ¡ ¡
  • Can ¡Pass ¡op:ons ¡to ¡Java.exe ¡via ¡HTML ¡

– S:ll ¡no ¡DEP ¡ – S:ll ¡no ¡ASLR ¡

slide-14
SLIDE 14

Background ¡– ¡Security ¡

  • All ¡JRE ¡6 ¡releases ¡ship ¡same ¡msvcr71.dll ¡

– v7.10.3052.4 ¡

  • md5 ¡86f1895ae8c5e8b17d99ece768a70732 ¡
  • Loads ¡in ¡all ¡components! ¡

– Browser ¡itself ¡ – Java.exe ¡for ¡applets ¡

  • Public ¡ROP ¡chains ¡target ¡this ¡DLL ¡
slide-15
SLIDE 15

Background ¡-­‑ ¡Technical ¡

  • Two ¡major ¡kinds ¡of ¡heaps ¡

– Java ¡Object ¡heap ¡(more ¡in ¡a ¡sec) ¡ – Na:ve ¡heap ¡(from ¡msvcr71.dll) ¡

  • Just ¡a ¡wrapper ¡around ¡HeapAlloc ¡

– OS-­‑specific ¡allocator ¡security ¡proper:es ¡apply ¡ » ASLR ¡ » Safe-­‑unlinking ¡ » Meta-­‑data ¡valida:on ¡ » etc ¡

Someone ¡had ¡fun! ¡

slide-16
SLIDE 16

Background ¡-­‑ ¡Technical ¡

  • Java ¡Object ¡heap ¡

– Garbage ¡Collected ¡ – Allocated ¡via ¡VirtualAlloc ¡ – Was ¡Read/Write/Execute ¡un:l ¡update ¡18 ¡!! ¡ – Predictable ¡address ¡

  • Between ¡0x22000000 ¡and ¡0x26000000 ¡
  • Due ¡to ¡“Class ¡Data ¡Sharing” ¡?? ¡
slide-17
SLIDE 17

Hurdles ¡

slide-18
SLIDE 18

Hurdles ¡-­‑ ¡I ¡

  • Debugging ¡JVM ¡started ¡from ¡browser ¡
  • Process ¡terminates ¡out ¡from ¡under ¡you! ¡

– Surprise! ¡

  • Why ¡does ¡this ¡happen? ¡

Con:nue ¡aper ¡a ¡while ¡ Single ¡step ¡excep:on?! ¡ Oh ¡no! ¡Process ¡DIED! ¡

slide-19
SLIDE 19

Hurdles ¡-­‑ ¡Watchdog ¡

  • Java ¡Plugin ¡Watchdog ¡

– Watches ¡over ¡external ¡jp2launcher.exe ¡process ¡

Java_java_lang_ProcessImpl_destroy ¡ (inside ¡java.dll) ¡ TerminateProcess ¡

slide-20
SLIDE 20

Hurdles ¡-­‑ ¡Watchdog ¡

  • Prevent ¡the ¡watchdog ¡from ¡interfering! ¡
  • 1. Patch ¡up ¡the ¡“java.dll” ¡binary ¡

– NOP ¡out ¡the ¡TerminateProcess ¡call ¡ – Or ¡just ¡change ¡JNZ ¡-­‑> ¡JMP ¡

  • 2. Use ¡breakpoints, ¡run:me ¡patching, ¡etc ¡

– Must ¡be ¡done ¡each ¡execu:on ¡L ¡

slide-21
SLIDE 21

Hurdles ¡-­‑ ¡Watchdog ¡

slide-22
SLIDE 22

Hurdles ¡– ¡Random ¡AVs ¡

  • Spurious ¡access ¡viola:ons ¡while ¡debugging ¡
  • Not ¡sure ¡why… ¡Let’s ¡speculate. ¡

– Expected ¡AV ¡in ¡JIT’d ¡code? ¡ – Crap ¡code ¡wrapped ¡in ¡catch-­‑all ¡handler? ¡ – If ¡you ¡know ¡or ¡have ¡another ¡idea, ¡speak ¡up! ¡

  • Just ¡pass ¡and ¡pretend ¡its ¡not ¡happening ¡;-­‑P ¡
slide-23
SLIDE 23

Hurdles ¡-­‑ ¡Encoding ¡

  • Java ¡uses ¡UTF-­‑8 ¡for ¡all ¡strings ¡

– Invalid ¡sequences ¡replaced ¡with ¡‘?’ ¡

  • Check ¡this ¡out: ¡(from ¡@mihi42) ¡
slide-24
SLIDE 24

Hurdles ¡-­‑ ¡Encoding ¡

  • Compile ¡and ¡run ¡it… ¡
  • But ¡it ¡was ¡all ¡comments?! ¡
  • Java ¡pre-­‑processes ¡those ¡UTF ¡escapes! ¡
slide-25
SLIDE 25

Hurdles ¡-­‑ ¡Encoding ¡

  • Don’t ¡use ¡strings! ¡Use ¡arrays ¡

– Their ¡values ¡are ¡represented ¡in ¡memory ¡ con:guously ¡

  • BeHer, ¡but ¡there’s ¡s:ll ¡an ¡issue… ¡
slide-26
SLIDE 26

Hurdles ¡– ¡Integers ¡

  • In ¡Java, ¡all ¡integers ¡are ¡signed! ¡
  • Use ¡next ¡larger ¡type ¡

– For ¡0xff ¡byte, ¡use ¡short ¡integer ¡ – For ¡0xffff ¡short, ¡use ¡long ¡integer ¡ – etc ¡

slide-27
SLIDE 27

Hurdles ¡-­‑ ¡Reachability ¡

  • Code ¡that ¡seems ¡unreachable ¡at ¡first ¡

– Was ¡the ¡case ¡in ¡CVE-­‑2009-­‑3869 ¡

  • You ¡can ¡reach ¡more ¡by ¡using ¡Java ¡tricks ¡

– Sub-­‑classing ¡ – Reflec:on ¡ – Abusing ¡complex ¡interfaces ¡

  • i.e. ¡A ¡class ¡that ¡takes ¡an ¡instance ¡as ¡a ¡parameter ¡
slide-28
SLIDE 28

Exploi:ng ¡

(yay) ¡

slide-29
SLIDE 29

Exploi:ng: ¡Setup ¡

  • Used ¡a ¡custom ¡JNI ¡(vuln_jni.dll) ¡for ¡tes:ng ¡

– Covers ¡several ¡common ¡exploit ¡primi:ves ¡

slide-30
SLIDE 30

Exploi:ng: ¡Arbitrary ¡Call ¡

  • Fun ¡and ¡simple.. ¡

– Just ¡need ¡somewhere ¡to ¡jump! ¡ – Good ¡thing ¡JRE ¡6 ¡doesn’t ¡support ¡ASLR! ¡

  • Public ¡ROPs ¡work ¡great ¡

– Nor ¡does ¡it ¡support ¡DEP! ¡

  • Let’s ¡jump ¡into ¡a ¡DLL ¡.data ¡sec:on! ¡
slide-31
SLIDE 31

Exploi:ng: ¡Write4 ¡

  • Surgical! ¡

– Need ¡to ¡target ¡something ¡used ¡for ¡control ¡flow ¡

  • Must ¡know ¡it’s ¡address ¡(within ¡margin ¡of ¡error) ¡
  • A ¡plethora ¡of ¡stuff ¡to ¡surgically ¡overwrite ¡

– Again, ¡lack ¡of ¡ASLR ¡/ ¡DEP ¡FTW ¡

slide-32
SLIDE 32

Vuln.sprinb ¡

  • Here’s ¡the ¡code: ¡
  • Two ¡issues ¡in ¡this ¡func:on ¡

– CWE-­‑121: ¡Stack ¡Buffer ¡Overflow ¡ – CWE-­‑134: ¡Uncontrolled ¡Format ¡String ¡

slide-33
SLIDE 33

Exploi:ng: ¡Format ¡String ¡

  • One ¡of ¡my ¡personal ¡favorites ¡
  • Java’s ¡C ¡run:me ¡has ¡“%n” ¡disabled ¡

– (Un)fortunately? ¡

  • May ¡s:ll ¡be ¡useful ¡

– Leak ¡memory ¡contents ¡ – Cause ¡buffer ¡overflows ¡(%1024xAAAABBBB) ¡

slide-34
SLIDE 34

Exploi:ng: ¡Stack ¡BOF ¡

  • Pet ¡peeve: ¡NOT ¡A ¡STACK ¡OVERFLOW ¡
  • Tradi:onal ¡methods ¡can ¡be ¡tricky ¡do ¡to ¡UTF8 ¡

issues ¡

– Just ¡pad ¡with ¡stuff ¡and ¡control ¡EIP ¡ – Some ¡characters ¡s:ll ¡aren’t ¡usable ¡

  • CVE-­‑2009-­‑3867 ¡/ ¡CVE-­‑2009-­‑3869 ¡
slide-35
SLIDE 35

Exploi:ng: ¡Heap ¡BOF ¡

  • Heap ¡Buffer ¡Overflow ¡

– Depends ¡on ¡what ¡you ¡corrupt! ¡

  • Unlikely ¡to ¡overflow ¡Java ¡Object ¡Heap ¡data ¡

– An ¡interes:ng ¡area ¡to ¡research ¡=) ¡

  • Na:ve ¡heap ¡protec:ons ¡make ¡for ¡pain ¡and ¡
  • suffering. ¡
slide-36
SLIDE 36

Exploi:ng: ¡CVE-­‑2009-­‑3869 ¡

  • setDiffICM ¡Stack ¡BOF ¡

– Na:ve ¡Method: ¡ ¡

  • Java_sun_awt_image_ImageRepresenta:on_setDiffIC

M ¡

  • Called ¡from ¡ImageRepresenta:on.setPixels ¡
  • sun.awt.* ¡can’t ¡be ¡used ¡in ¡an ¡Applet! ¡

– java.security.AccessControlExcep:on: ¡access ¡denied ¡ (java.lang.Run:mePermission ¡ accessClassInPackage.sun.awt.image) ¡

  • Using ¡a ¡custom ¡ImageFilter ¡we ¡can! ¡
slide-37
SLIDE 37

Exploi:ng: ¡CVE-­‑2010-­‑3552 ¡

  • New ¡Plug-­‑in ¡“docbase” ¡Stack ¡BOF ¡

– No ¡stack ¡cookie?! ¡ – Encoding ¡issues ¡come ¡into ¡play ¡ – Issue ¡occurs ¡in ¡browser ¡address ¡space ¡ – Modern ¡browsers ¡use ¡SetProcessDEPPolicy ¡to ¡ force ¡permanent ¡DEP ¡on. ¡ – Exploit ¡uses ¡a ¡custom ¡ROP ¡chain ¡that ¡predates ¡ White ¡Phosphorous ¡and ¡Corelan ¡Team ¡chains ¡

slide-38
SLIDE 38

Demos! ¡

slide-39
SLIDE 39

Conclusions ¡

  • Exploi:ng ¡JRE ¡6 ¡can ¡be ¡painful, ¡but… ¡
  • It’s ¡easier ¡than ¡it ¡should ¡be. ¡

– Well ¡behind ¡the ¡mi:ga:on ¡curve ¡

  • No ¡ASLR ¡or ¡DEP ¡
  • Predictable ¡memory ¡layout ¡

– Vast ¡aHack ¡surface ¡ – Buggy ¡

  • Check ¡out ¡the ¡examples! ¡
slide-40
SLIDE 40

Recommenda:ons ¡

  • Good: ¡

– Use ¡EMET ¡to ¡force ¡ASLR ¡and ¡DEP ¡ – Prepare ¡for ¡migra:on ¡to ¡JRE ¡7 ¡ – Use ¡64-­‑bit ¡browser ¡/ ¡plug-­‑in ¡

  • BeHer: ¡

– Disable ¡browser ¡plug-­‑ins ¡and ¡JNLP/Web ¡Start ¡

  • Chrome ¡neuters ¡Java ¡by ¡default ¡
  • BEST: ¡UNINSTALL ¡JRE ¡!! ¡

– LULZ: ¡hHp://harmful.cat-­‑v.org/sopware/java ¡

slide-41
SLIDE 41

Future ¡Direc:ons ¡

  • Mapping ¡Java ¡code ¡constructs ¡to ¡Na:ve-­‑land ¡

– How ¡does ¡scope ¡translate? ¡

  • Inves:gate ¡JIT ¡Spraying ¡

– Code ¡region ¡is ¡RWX! ¡

  • More ¡work ¡with ¡JRE ¡7 ¡

– Does ¡the ¡new ¡ASLR/DEP ¡opt-­‑in ¡really ¡help? ¡

slide-42
SLIDE 42

QUESTIONS? ¡

Contact ¡informa:on: ¡

  • @jduck1337 ¡
  • “jduck” ¡on ¡IRC ¡
  • Email: ¡jdrake ¡[circled-­‑a] ¡Accuvant.com ¡

Please ¡complete ¡the ¡Speaker ¡Feedback ¡Surveys! ¡

This ¡will ¡both ¡help ¡speakers ¡improve ¡and ¡help ¡Black ¡Hat ¡make ¡beHer ¡decisions ¡regarding ¡content ¡and ¡presenters ¡for ¡future ¡

  • events. ¡
slide-43
SLIDE 43

References ¡

Slide ¡3 ¡ hHp://kelseywinterkorn.com/ ¡ Slide ¡6 ¡ hHp://www.oracle.com/technetwork/java/javase/system-­‑configura:ons-­‑135212.html ¡ Slide ¡7 ¡ hHp://weblogs.java.net/blog/chet/archive/2007/05/consumer_jre_le.html ¡ hHp://adtmag.com/ar:cles/2011/08/01/java-­‑7-­‑crashing.aspx ¡ Slide ¡8 ¡ hHp://www.isecpartners.com/storage/docs/presenta:ons/EIP-­‑final.pdf ¡ Slide ¡9 ¡ hHp://java.sun.com/products/hotspot/whitepaper.html ¡ Slide ¡10 ¡ hHps://twiHer.com/#!/ifindkarma/status/115962954301714432 ¡ Slide ¡12 ¡ hHp://download.oracle.com/docs/cd/E19455-­‑01/806-­‑3461/ch1intro-­‑3/index.html ¡ Slide ¡16 ¡ hHp://www.blackhat.com/presenta:ons/bh-­‑usa-­‑08/So:rov_Dowd/bh08-­‑so:rov-­‑dowd.pdf ¡ hHp://download.oracle.com/javase/6/docs/technotes/guides/vm/class-­‑data-­‑sharing.html ¡ Slide ¡? ¡ hHp://www.oracle.com/technetwork/java/javase/index-­‑135519.html ¡ hHp://www.oracle.com/technetwork/java/javase/jre-­‑install-­‑137694.html ¡ hHp://www.oracle.com/technetwork/java/javase/releasenotes-­‑136954.html ¡

slide-44
SLIDE 44
slide-45
SLIDE 45

Change ¡Summary ¡

– Update ¡10 ¡

  • New ¡browser ¡plug-­‑in ¡

– Always ¡installed ¡(no ¡custom ¡install ¡op:ons) ¡ – Runs ¡an ¡external ¡java.exe ¡process ¡ – Allows ¡controlling ¡heap ¡size ¡ – Allows ¡selec:ng ¡JRE ¡version ¡

  • Patch-­‑in-­‑place ¡or ¡Sta:c ¡

– Update ¡18 ¡

  • Java ¡Heap ¡no ¡longer ¡RWX! ¡
  • Auto-­‑updater ¡a ¡separate ¡package ¡(can ¡remove) ¡

– Prompt ¡changes? ¡

slide-46
SLIDE 46

Exploi:ng: ¡CVE-­‑2009-­‑3867 ¡

  • getSoundbank ¡file:// ¡URI ¡Stack ¡BOF ¡

– Affects ¡JRE ¡<= ¡6u16, ¡5u21, ¡1.4.2_24, ¡1.3.1_26 ¡

  • KF’s ¡PoC ¡showed ¡cross-­‑plaborm ¡PC ¡control ¡
  • ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡version ¡

– Passes ¡“np” ¡& ¡“sc” ¡applet ¡PARAMs ¡

  • Nops ¡and ¡Shellcode ¡– ¡allows ¡cross-­‑plaborm ¡targe:ng ¡

– Sprays ¡the ¡Java ¡Object ¡Heap ¡ – Overwrites ¡saved ¡PC ¡(no ¡SEH) ¡ – Jumps ¡to ¡Java ¡Object ¡Heap ¡(was ¡s:ll ¡RWX) ¡