This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Difference between revisions of "Top 10-2017 A4-XML External Entities (XXE)"

From OWASP
Jump to: navigation, search
(Updated Navigation (incl PrevLink and NextLink))
(Prepare OWASP Top 10-2017 Release (Content))
Line 1: Line 1:
 
{{Top_10_2013:TopTemplate
 
{{Top_10_2013:TopTemplate
 +
    |useprev=2017PrevLink
 +
    |prev=A3-{{Top_10_2010:ByTheNumbers
 +
        |3
 +
        |year=2017
 +
        |language=en
 +
    }}
 
     |usenext=2017NextLink
 
     |usenext=2017NextLink
 
     |next=A5-{{Top_10_2010:ByTheNumbers
 
     |next=A5-{{Top_10_2010:ByTheNumbers
              |5
+
        |5
              |year=2017
+
        |year=2017
              |language=en}}
+
        |language=en
     |useprev=2017PrevLink
+
     }}
    |prev=A3-{{Top_10_2010:ByTheNumbers
 
              |3
 
              |year=2017
 
              |language=en}}
 
 
     |year=2017
 
     |year=2017
 
     |language=en
 
     |language=en
 
}}
 
}}
 +
<!--- 2017 XML External Entities (XXE) --->
 +
{{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2017|language=en}}
 +
{{Top_10-2017:SummaryTableTemplate|exploitability=2 |prevalence=2 |detectability=3 |impact=3 |year=2017|language=en}}
 +
{{Top_10_2010:SummaryTableHeaderEndTemplate|year=2017}}
 +
    <td colspan=2 {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}>
 +
<!--- Threat Agent: --->
 +
Attackers can exploit vulnerable XML processors if they can upload XML or include hostile content in an XML document, exploiting vulnerable code, dependencies or integrations. </td>
 +
    <td colspan=2  {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}>
 +
<!--- Security Weakness: --->
 +
By default, many older XML processors allow specification of an external entity, a URI that is dereferenced and evaluated during XML processing. <u>[[Source_Code_Analysis_Tools|SAST]]</u> tools can discover this issue by inspecting dependencies and configuration. <u>[[:Category:Vulnerability_Scanning_Tools|DAST]]</u> tools require additional manual steps to detect and exploit this issue. Manual testers need to be trained in how to test for XXE, as it not commonly tested as of 2017. </td>
 +
    <td colspan=2  {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}>
 +
<!--- Impacts: --->
 +
These flaws can be used to extract data, execute a remote request from the server, scan internal systems, perform a denial-of-service attack, as well as execute other attacks. </td>
 +
{{Top_10_2010:SummaryTableEndTemplate|year=2017}}
 +
 +
{{Top_10:SubsectionTableBeginTemplate|type=main}}
 +
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=isTheApplicationVulnerable|position=firstLeft|year=2017|language=en}}
 +
Applications and in particular XML-based web services or downstream integrations might be vulnerable to attack if:
 +
* The application accepts XML directly or XML uploads, especially from untrusted sources, or inserts untrusted data into XML documents, which is then parsed by an XML processor.
 +
* Any of the XML processors in the application or SOAP based web services has <u>[https://en.wikipedia.org/wiki/Document_type_definition document type definitions (DTDs)]</u> enabled. As the exact mechanism for disabling DTD processing varies by processor, it is good practice to consult a reference such as the <u>[[XML_External_Entity_(XXE)_Prevention_Cheat_Sheet|OWASP Cheat Sheet 'XXE Prevention']]</u>.
 +
* If the application uses SAML for identity processing within federated security or single sign on (SSO) purposes. SAML uses XML for identity assertions, and may be vulnerable.
 +
* If the application uses SOAP prior to version 1.2, it is likely susceptible to XXE attacks if XML entities are being passed to the SOAP framework.
 +
* Being vulnerable to XXE attacks likely means that the application is vulnerable to denial of service attacks including the Billion Laughs attack
 +
 +
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howToPrevent|position=right|year=2017|language=en}}
 +
Developer training is essential to identify and mitigate XXE. Besides that, preventing XXE requires:
 +
* Whenever possible, use less complex data formats such as JSON, and avoiding serialization of sensitive data.
 +
* Patch or upgrade all XML processors and libraries in use by the application or on the underlying operating system. Use dependency checkers. Update SOAP to SOAP 1.2 or higher.
 +
* Disable XML external entity and DTD processing in all XML parsers in the application, as per the <u>[[XML_External_Entity_(XXE)_Prevention_Cheat_Sheet|OWASP Cheat Sheet 'XXE Prevention']]</u>.
 +
* Implement positive ("whitelisting") server-side input validation, filtering, or sanitization to prevent hostile data within XML documents, headers, or nodes.
 +
* Verify that XML or XSL file upload functionality validates incoming XML using XSD validation or similar.
 +
* SAST tools can help detect XXE in source code, although manual code review is the best alternative in large, complex applications with many integrations.
 +
If these controls are not possible, consider using virtual patching, API security gateways, or Web Application Firewalls (WAFs) to detect, monitor, and block XXE attacks.
 +
 +
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=exampleAttackScenarios|position=left|year=2017|language=en}}
 +
Numerous public XXE issues have been discovered, including attacking embedded devices. XXE occurs in a lot of unexpected places, including deeply nested dependencies. The easiest way is to upload a malicious XML file, if accepted:
 +
 +
<b>Scenario #1</b>: The attacker attempts to extract data from the server:
 +
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;">
 +
<nowiki><?xml version="1.0" encoding="ISO-8859-1"?></nowiki>
 +
: <nowiki><!DOCTYPE foo [</nowiki>
 +
: <nowiki><!ELEMENT foo ANY ></nowiki>
 +
: <nowiki><!ENTITY xxe SYSTEM "file:///etc/passwd" >]></nowiki>
 +
: <nowiki><foo>&xxe;</foo></nowiki>
 +
</span></b>{{Top_10_2010:ExampleEndTemplate}}
 +
 +
<b>Scenario #2</b>: An attacker probes the server's private network by changing the above ENTITY line to:
 +
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;">
 +
: <nowiki><!ENTITY xxe SYSTEM "https://192.168.1.1/private" >]></nowiki>
 +
</span></b>{{Top_10_2010:ExampleEndTemplate}}
 +
 +
<b>Scenario #3</b>: An attacker attempts a denial-of-service attack by including a potentially endless file:
 +
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;">
 +
: <nowiki><!ENTITY xxe SYSTEM "file:///dev/random" >]></nowiki>
 +
</span></b>{{Top_10_2010:ExampleEndTemplate}}
 +
 +
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|year=2017|language=en}}
 +
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate|year=2017|language=en}}
 +
* <u>[[:Category:OWASP_Application_Security_Verification_Standard_Project#tab=Home|OWASP Application Security Verification Standard]]</u>
 +
* <u>[[Testing_for_XML_Injection_(OTG-INPVAL-008)|OWASP Testing Guide: Testing for XML Injection]]</u>
 +
* <u>[[XML_External_Entity_(XXE)_Processing|OWASP XXE Vulnerability]]</u>
 +
* <u>[[XML_External_Entity_(XXE)_Prevention_Cheat_Sheet|OWASP Cheat Sheet: XXE Prevention]]</u>
 +
* <u>[[XML_Security_Cheat_Sheet|OWASP Cheat Sheet: XML Security]]</u>
  
 +
{{Top_10_2010:SubSubsectionExternalReferencesTemplate|year=2017|language=en}}
 +
* <u>[https://cwe.mitre.org/data/definitions/611.html CWE-611: Improper Restriction of XXE]</u>
 +
* <u>[https://en.wikipedia.org/wiki/Billion_laughs_attack Billion Laughs Attack]</u>
 +
* <u>[https://secretsofappsecurity.blogspot.tw/2017/01/saml-security-xml-external-entity-attack.html SAML Security XML External Entity Attack]</u>
 +
* <u>[https://web-in-security.blogspot.tw/2014/11/detecting-and-exploiting-xxe-in-saml.html Detecting and exploiting XXE in SAML Interfaces]</u>
  
 
{{Top_10_2013:BottomAdvancedTemplate
 
{{Top_10_2013:BottomAdvancedTemplate
     |type={{Top_10_2010:StyleTemplate}}
+
     |type=box
 +
    |useprev=2017PrevLink
 +
    |prev=A3-{{Top_10_2010:ByTheNumbers
 +
        |3
 +
        |year=2017
 +
        |language=en
 +
    }}
 
     |usenext=2017NextLink
 
     |usenext=2017NextLink
 
     |next=A5-{{Top_10_2010:ByTheNumbers
 
     |next=A5-{{Top_10_2010:ByTheNumbers
              |5
+
        |5
              |year=2017
+
        |year=2017
              |language=en}}
+
        |language=en
     |useprev=2017PrevLink
+
     }}
    |prev=A3-{{Top_10_2010:ByTheNumbers
 
              |3
 
              |year=2017
 
              |language=en}}
 
 
     |year=2017
 
     |year=2017
 
     |language=en
 
     |language=en
 
}}
 
}}
 +
 +
<!-- [[Category:OWASP Top Ten Project]] -->

Revision as of 21:56, 15 December 2017

← A3-Sensitive Data Exposure
2017 Table of Contents

PDF version

A5-Broken Access Control →
Threat Agents / Attack Vectors Security Weakness Impacts
App Specific Exploitability: 2
Prevalence: 2
Detectability: 3
Technical: 3
Business ?
Attackers can exploit vulnerable XML processors if they can upload XML or include hostile content in an XML document, exploiting vulnerable code, dependencies or integrations. By default, many older XML processors allow specification of an external entity, a URI that is dereferenced and evaluated during XML processing. SAST tools can discover this issue by inspecting dependencies and configuration. DAST tools require additional manual steps to detect and exploit this issue. Manual testers need to be trained in how to test for XXE, as it not commonly tested as of 2017. These flaws can be used to extract data, execute a remote request from the server, scan internal systems, perform a denial-of-service attack, as well as execute other attacks.
Is the Application Vulnerable?

Applications and in particular XML-based web services or downstream integrations might be vulnerable to attack if:

  • The application accepts XML directly or XML uploads, especially from untrusted sources, or inserts untrusted data into XML documents, which is then parsed by an XML processor.
  • Any of the XML processors in the application or SOAP based web services has document type definitions (DTDs) enabled. As the exact mechanism for disabling DTD processing varies by processor, it is good practice to consult a reference such as the OWASP Cheat Sheet 'XXE Prevention'.
  • If the application uses SAML for identity processing within federated security or single sign on (SSO) purposes. SAML uses XML for identity assertions, and may be vulnerable.
  • If the application uses SOAP prior to version 1.2, it is likely susceptible to XXE attacks if XML entities are being passed to the SOAP framework.
  • Being vulnerable to XXE attacks likely means that the application is vulnerable to denial of service attacks including the Billion Laughs attack
How to Prevent

Developer training is essential to identify and mitigate XXE. Besides that, preventing XXE requires:

  • Whenever possible, use less complex data formats such as JSON, and avoiding serialization of sensitive data.
  • Patch or upgrade all XML processors and libraries in use by the application or on the underlying operating system. Use dependency checkers. Update SOAP to SOAP 1.2 or higher.
  • Disable XML external entity and DTD processing in all XML parsers in the application, as per the OWASP Cheat Sheet 'XXE Prevention'.
  • Implement positive ("whitelisting") server-side input validation, filtering, or sanitization to prevent hostile data within XML documents, headers, or nodes.
  • Verify that XML or XSL file upload functionality validates incoming XML using XSD validation or similar.
  • SAST tools can help detect XXE in source code, although manual code review is the best alternative in large, complex applications with many integrations.

If these controls are not possible, consider using virtual patching, API security gateways, or Web Application Firewalls (WAFs) to detect, monitor, and block XXE attacks.

Example Attack Scenarios

Numerous public XXE issues have been discovered, including attacking embedded devices. XXE occurs in a lot of unexpected places, including deeply nested dependencies. The easiest way is to upload a malicious XML file, if accepted:

Scenario #1: The attacker attempts to extract data from the server:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<foo>&xxe;</foo>

Scenario #2: An attacker probes the server's private network by changing the above ENTITY line to:

<!ENTITY xxe SYSTEM "https://192.168.1.1/private" >]>

Scenario #3: An attacker attempts a denial-of-service attack by including a potentially endless file:

<!ENTITY xxe SYSTEM "file:///dev/random" >]>
References

OWASP

External

← A3-Sensitive Data Exposure
2017 Table of Contents

PDF version

A5-Broken Access Control →

© 2002-2017 OWASP Foundation This document is licensed under the Creative Commons Attribution-ShareAlike 3.0 license. Some rights reserved. CC-by-sa-3 0-88x31.png