📙
AppSec
  • Overview
  • Write Ups Compilations/Resources
  • Main Resources
  • Labs
  • Cross Site Request Forgery
    • Cross Site Request Forgery (CSRF)
      • Write-ups
      • Source Code Examples
      • Labs
  • Missing Access Controls
    • Missing Access Controls
      • Write-ups
      • Source Code Examples
      • Resources
      • Testing Tips
  • LFI / Directory Traversal
    • Local File Inclusion
      • Local File Inclusion Writeups
      • Source Code Examples
      • Labs
  • XXE
    • XML External Entity (XXE)
      • Write-ups
      • Source Code Examples
      • Labs
      • More Writeups
      • Payloads
      • Resources
  • Injection
    • Command Injection
      • Writeups
    • Server-Side Template Injection
      • Server-Side Template Injection Writeups
      • More Write-ups
      • Source Code Examples
      • Labs
      • Resources
      • Payloads
      • Tools
    • SQL Injection
      • SQLI Write-ups
      • Source Code Examples
      • More Write-ups
      • Labs
      • Resources & Tools
  • SSRF
    • Server-Side Request Forgery (SSRF)
      • SSRF Write-ups
      • Source Code Review
  • Unvalidated Redirects and Forwards
    • Unvalidated Redirects and Forwards
      • Writeups
      • Source Code Examples
  • Verbose Error Messages and Stack Traces
    • Verbose Error Messages and Stack Traces
      • Write-ups
Powered by GitBook
On this page
  • Overview
  • Example

Was this helpful?

  1. XXE

XML External Entity (XXE)

PreviousLabsNextWrite-ups

Last updated 4 years ago

Was this helpful?

Overview

XML External Entity (XXE) attacks occur when untrusted XML Input containing a reference to an external entity is processed by an XML parser that is improperly configured. This can lead to the disclosure of internal resources, denial of service, RCE, SSRF, and port scanning.

Many older or poorly configured XML processors evaluate external entity references within XML documents. External entities can be used to disclose internal files using the file URI handler, internal file shares, internal port scanning, remote code execution, and denial of service attacks.

-OWASP

Example

Consider this example from Appsecco's DVNA. The functionality of the page http://127.0.0.1:9090/app/bulkproducts allows for XML files to be uploaded and due to code misconfiguration allows XXE.

The code that handles this XML upload functionality is found in core/appHandler.js. The code uses the libxmljs library to parse the XML String. Line 3 uses the libxmljs.parseXmlString function to parse the user input. This is where the error is occurring, where the library parses the XML input string and saves it to the products variable.

module.exports.bulkProducts =  function(req, res) {
	if (req.files.products && req.files.products.mimetype=='text/xml'){
		var products = libxmljs.parseXmlString(req.files.products.data.toString('utf8'), {noent:true,noblanks:true})
		products.root().childNodes().forEach( product => {
			var newProduct = new db.Product()
			newProduct.name = product.childNodes()[0].text()
			newProduct.code = product.childNodes()[1].text()
			newProduct.tags = product.childNodes()[2].text()
			newProduct.description = product.childNodes()[3].text()
			newProduct.save()
		})
		res.redirect('/app/products')
	}else{
		res.render('app/bulkproducts',{messages:{danger:'Invalid file'},legacy:false})
	}
}

The XML parsing library libxmljs allows for parsing external entities. The flag value noent needs to be set to false {noent:true,noblanks:true}.

The following code shows the fix for this vulnerability by changing that flag value to false.

module.exports.bulkProducts =  function(req, res) {
	if (req.files.products && req.files.products.mimetype=='text/xml'){
		var products = libxmljs.parseXmlString(req.files.products.data.toString('utf8'), {noent:false,noblanks:true})
		products.root().childNodes().forEach( product => {
			var newProduct = new db.Product()
			newProduct.name = product.childNodes()[0].text()
			newProduct.code = product.childNodes()[1].text()
			newProduct.tags = product.childNodes()[2].text()
			newProduct.description = product.childNodes()[3].text()
			newProduct.save()
		})
		res.redirect('/app/products')
	}else{
		res.render('app/bulkproducts',{messages:{danger:'Invalid file'},legacy:false})
	}
}

Start with the following resources then go to the resources page.

What is XXE (XML external entity) injection? Tutorial & Examples | Web Security AcademyWebSecAcademy
Logo
XML External Entity (XXE) Processing | OWASP Foundation
Logo
XXE - XEE - XML External EntityHackTricks
OWASP Top Ten 2017 | A4:2017-XML External Entities (XXE) | OWASP Foundation
Appsecco DVNA source code example
https://appsecco.com/books/dvna-developers-security-guide/solution/a4-xxe.htmlappsecco.com
Logo
Logo