xxe xml external entity

28
Web Application Security - Team bi0s © 2017 XXE XML External Entity 25 February 2017 @ Team bi0s 1/ 25 HEERAJ Btech, Third Year, Computer Science Engineering Amrita University

Upload: heeraj-nair

Post on 11-Apr-2017

92 views

Category:

Internet


6 download

TRANSCRIPT

Page 1: Xxe  xml external entity

Web Application Security - Team bi0s © 2017

XXE XML External Entity

25 February 2017

@Team bi0s 1/25

HEERAJBtech, Third Year, Computer Science EngineeringAmrita University

Page 2: Xxe  xml external entity

whoami

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Undergraduate Student @ Amrita

➔ Web Security Enthusiast

➔ CTF{flag_seeker}

➔ @heerajnair

➔ ww.i4info.in

2/25

Page 3: Xxe  xml external entity

Agenda

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Intro to XML & DTD

➔ XML Entity

➔ Parsing XML

➔ Attack Vectors

➔ Demo

3/25

Page 4: Xxe  xml external entity

XML

Web Application Security - Team bi0s © 2017 @Team bi0s

➔EXtensible Markup Language

4/25

Picture:123RF.COM

Page 5: Xxe  xml external entity

Where it is used ?

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Document Formats

➔ Image Formats

➔ Configuration Files

➔ Network Protocols

➔ RSS Feeds … etc . . .

5/25

Picture: c-sharpcorner.com

Page 6: Xxe  xml external entity

Document Type Definition

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ References an ExternalDTD

➔ Define structure with the list of legal elements

6/25

Page 7: Xxe  xml external entity

XML Entity

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Entities help to reduce the entry of repetitive information

Output:Writer: Donald Duck. Copyright: bi0s.

7/25

Page 8: Xxe  xml external entity

XML Entity

Web Application Security - Team bi0s © 2017 @Team bi0s

XML Entity

Internal Entity External Entity

8/25

Page 9: Xxe  xml external entity

Parsing

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Character other than < , > , & , ‘ , “ all are parsable.

➔ PCDATA is text that will be parsed by a parser. ➔ CDATA is text that will not be parsed by a parser.

◆ Ex : <![CDATA[<data>Hello, world!]]>

9/25

Page 10: Xxe  xml external entity

Attack’s Possible

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Denial Of Service

➔ Local File Inclusion

➔ SSRF

➔ Internal scans

➔ Rce (Not Always!!!)

10/25

Page 11: Xxe  xml external entity

Billion Laughs Attack

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Works by expansion property (Simple code(<1kb) will expand up to 3 gigabytes of memory.

11/25

Website: digitalimprint.com

Page 12: Xxe  xml external entity

Attack Vectors

Web Application Security - Team bi0s © 2017 @Team bi0s

Classic XXEWe can view any file which doesn’t contain < , > , & , ‘ , “ as characters.

12/25

Avinash S
Here they used the power/image_size as it is simple to test. But showing this as the first example of XXE can be confusing as many people might not even know what is the purpose of this file. Replace it with the example of etc/passwd (e.g., see #4 of https://www.blackhat.com/docs/us-15/materials/us-15-Wang-FileCry-The-New-Age-Of-XXE.pdf).
Page 13: Xxe  xml external entity

13

Page 14: Xxe  xml external entity

OFFICE OPEN XML

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Zip archive file containing XML and media files

➔ *.docx , *.xlsx , *.pptx

➔ Developed by Microsoft

14/25

Page 15: Xxe  xml external entity

OFFICE OPEN XML

Web Application Security - Team bi0s © 2017 @Team bi0s

15/25

Page 16: Xxe  xml external entity

OFFICE OPEN XML

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Files in OOXML◆ /_rels/.rels◆ [Content_Types].xml◆ Default Main Document

● /word/document.xml● /ppt/presentation.xml● /xl/workbook.xml

16/25

Page 17: Xxe  xml external entity

Direct Feedback Channel

Web Application Security - Team bi0s © 2017 @Team bi0s

What if you are Reading

Some configuration files?

17/25

Page 18: Xxe  xml external entity

Different Protocols

Web Application Security - Team bi0s © 2017 @Team bi0s 18/25

php://filter/convert.base64-encode/resource=/etc/passwd

Page 19: Xxe  xml external entity

Direct Feedback Channel

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ CDATA very helpful to read web configuration, which contain non parsable characters.

But this won’t work !!

19/25

Heeraj Nair
change pic, with fstab
Avinash S
You really want to show spelling mistake of end?
Page 20: Xxe  xml external entity

Direct Feedback Channel

Web Application Security - Team bi0s © 2017 @Team bi0s 20/25

1. XML Request

2. Get th

e DTD

3. Info Back

Parsing

Attacker’s Server

Host

Page 21: Xxe  xml external entity

Direct Feedback Channel

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ We have to use Parameter entities

➢ Parameter.dtd

21/25

Page 22: Xxe  xml external entity

Out Of Band Channel

Web Application Security - Team bi0s © 2017 @Team bi0s 22/25

1. XML Request

2. Get th

e DTD

3. Info Back Parsing

4.GET? data=root:x:0:0:root:

Attacker’s Server

Host

Page 23: Xxe  xml external entity

Out Of Band Channel

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ No Direct Feedback Channel

23/25

Page 24: Xxe  xml external entity

Demo

Web Application Security - Team bi0s © 2017 @Team bi0s

XXE Cheat Sheet: http://web-in-security.blogspot.in/2016/03/xxe-cheat-sheet.html

24/25

Page 25: Xxe  xml external entity

Solution

Web Application Security - Team bi0s © 2017 @Team bi0s

➢ Validation of user input➢ Turn off external DTD fetching ➢ Disable External Entity Parsing

libxml_disable_entity_loader(true);(PHP)

25/25

Page 26: Xxe  xml external entity

26

Page 27: Xxe  xml external entity

Playing With Content Type

Web Application Security - Team bi0s © 2017 @Team bi0s

➔ Server may accept multiple data formats

➔ Results in Json endpoints may be vulnerable to XXE

➔ Content-Type changed to application/xml

➔ JSON has to be converted to XML

27/25

Page 28: Xxe  xml external entity

OFFICE OPEN XML

Web Application Security - Team bi0s © 2017 @Team bi0s

28/25

Open XML File Container

Document Properties

Custom Defined XML

CommentsWordML/

SpreadsheetML etc

Embedded Code/Macros

Images, Video, Sound Files

Charts