0day writeup: XXE in uber.com
An unauthenticated API endpoint accepted a base64-encoded SAMLResponse parameter containing XML, which was parsed with external entity support enabled. An attacker could send a crafted XML document to make the server read local files and exfiltrate them out-of-band, including backup logs of user accounts.
The original lives on httpsonly.blogspot.com
We do not hold its text, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
In May 2016 I was looking through Uber's bug bounty programme and came across an HTTP application exposed at https://backup.uberinternal.com:4285/. The service behind it was a Code42 product, enterprise backup software. The application exposes an API on port 4285.
That is the interesting part of the target. A backup server is not a peripheral service. It holds copies of the files of every user in the organisation, so anything that lets an unauthenticated outsider read files on that host is a serious finding.
Setup
The only precondition was network access to the API on port 4285. I had no account and no credentials on the Uber instance, and the whole point of the exercise was to find a way in without them.
Bruteforcing credentials was not an option, and there were no published CVEs for this vendor at the time. The reason for the absence of CVEs became clear later: the bug I found was a 0day.
Finding it
I queried the api/serverEnv API on the target:
https://backup.uberinternal.com:4285/api/serverEnv
From the response it became clear that Uber was running the last version of the product, 5.2.0. With no known vulnerabilities to reuse, the only way to break the service and earn a bounty was to find a 0day myself.
I went to Code42's publicly available documentation, extracted every documented API method, and started bruteforcing them to see which ones could be reached without authentication. One API call stood out as reachable by any external user, documented at https://www.crashplan.com/apidocviewer/#SsoAuthLoginResponse.
The documentation stated that /api/SsoAuthLoginResponse accepts a GET parameter named SAMLResponse. Its value is a base64-encoded string that is meant to contain XML authentication data. That is the classic shape of a SAML endpoint: the service provider receives an assertion from an identity provider, decodes it and parses the XML. An endpoint that parses attacker-supplied XML before authentication is exactly where an XML External Entity attack belongs.
Exploitation
Step 1: Confirm out-of-band parsing
I constructed a trivial XML document with external entities pointing at my own VPS, using a non-standard port because ports 80 and 443 were filtered by the firewall on the target side. I sent it as the base64-encoded SAMLResponse value and got a response back from my server. The server was vulnerable to an XXE out-of-band (OOB) attack.
I have deliberately not published the final HTTP request, since the exploitation string is straightforward once the mechanism is known.
Step 2: Understand the OOB channel
Because the application was written in Java, I knew I could read directories, so I immediately launched the xxe-ftp server to extract data. Credit for that tool goes to the people at OnSec; their research on XXE OOB exploitation against Java 1.7 is at http://lab.onsec.ru/2014/06/xxe-oob-exploitation-at-java-17.html.
The mechanism, for anyone who has not used it, is this. The attacker's host runs a script that acts as an HTTP server to receive the OOB payload on port 8088, and as an FTP server that accepts connections on port 8077. The FTP server captures what the parser sends, which is how file contents leave the target without ever appearing in an HTTP response.
Step 3: Prove impact on Uber
As a proof of concept for Uber, I retrieved the contents of the /home/ directory of the server. That was enough of an impact illustration for my report on HackerOne.
Step 4: Go further, with permission
Uber's security team was engaged with the finding: they contacted the vendor and confirmed that the vulnerability was a 0day. They also asked me to elaborate on the vulnerability. Since I like to demonstrate impact, I did not need to be asked twice.
Given permission to show further exploitation, I quickly found the folder where backup logs were stored. A screenshot of one of the local files on the server showed information about a recently backed-up user.
It was clear from this that I could read the backup files of a little more than all domain accounts of a company that has the Code42 service at its perimeter.
Step 5: Scope the exposure
To understand the impact of this 0day in the wider world, I searched Shodan for port 4285. One globally known security firm had this application installed on its perimeter.
Root cause
The /api/SsoAuthLoginResponse endpoint takes a base64-encoded SAMLResponse from an unauthenticated GET request, decodes it and hands the XML to a parser that resolves external entities. Because the endpoint is part of the SSO login flow, it has to parse the assertion before it knows who the caller is, so the parser runs with the privileges of the service and with no authentication in front of it.
The report does not describe the parser configuration, so the exact setting that was missing is not stated; what is clear is that external entities were resolved, including over non-standard ports, which is what made the OOB channel work.
Impact
An unauthenticated attacker who can reach port 4285 could read files from the backup server. On Uber's instance I demonstrated reading the /home/ directory and then located the folder holding backup logs, which contained information about recently backed-up users. The report states that this gives access to the backups of a little more than all domain accounts of a company that has the Code42 service at its perimeter. The impact is therefore bounded by what the service account can read on that host, and by whether the service is reachable from outside.
The Shodan search showed that reachability is not hypothetical: at least one globally known security firm had the application on its perimeter.
Fix
Code42 updated the software and the vulnerability was patched in version 5.2.0.1. The report does not describe the code change itself.
Timeline
| Date | Event |
|---|---|
| May 6th, 2016 | Report sent to Uber through HackerOne |
| May 23rd, 2016 | Code42 updated their software; vulnerability patched in [redacted] |
| Jun 28th, 2016 | $9000 bounty received from Uber |
| Aug 24th, 2016 | Code42 asked to wait until the update is installed on all their clients |
| Jan 24th, 2017 | Code42 notified that the write-up would be published; no reaction |
In August 2016 Code42 asked for a delay, with a denial of responsibility: they preferred the blog post not be written until their latest version had been installed by all customers, noting that the fix was in the latest release but not yet deployed everywhere.
Variants to test
- Other SAML endpoints. Look for any endpoint that accepts a base64-encoded
SAMLResponseorSAMLRequestand parses it before authentication. A positive result is an out-of-band callback to your listener when the entity is resolved. - Other documented API methods. The report's method was to extract every documented API method and bruteforce them for unauthenticated access. A positive result is any method that answers without a session and takes XML or a base64 blob.
- Non-standard ports. If 80 and 443 are filtered, point the entity at a high port on your own host. A positive result is a connection from the target on that port.
- Directory listing via the OOB channel. On Java targets, try reading a directory rather than a single file. A positive result is a directory listing arriving over the FTP listener.
- Backup and log directories. Once file read works, look for the folders where the product stores backup logs and metadata. A positive result is a file naming recently backed-up users, which turns a file read into a data exposure finding.
- Shodan for the product's management port. Search for the port the product exposes and check which organisations have it on the perimeter. A positive result is an internet-facing instance of the same product version.
What happened, in plain words
In May 2016 I was browsing Uber's bug bounty programme. A bug bounty programme is a deal a company makes with outside researchers: find a security problem in our systems, tell us privately, and we pay you a reward (the bounty) if it is real. I found an internet-facing web application at https://backup.uberinternal.com:4285/. Behind it was a product made by Code42, enterprise backup software. Enterprise backup software is the kind of program a company installs so that the files on every employee's computer are copied to a central server, so that nothing is lost if a laptop dies or is stolen.
That central server is the interesting target. It is not a side service like a marketing page. It holds copies of the files of every user in the organisation. So anything that lets an outsider who has never logged in read files on that machine is a serious problem.
The application exposes an API on port 4285. An API (Application Programming Interface) is the set of addresses a program offers so that other programs can talk to it. Think of a restaurant: the dining room is the website you see, and the API is the kitchen window where orders are passed in and dishes come out. Each address in the API is called an endpoint, and each endpoint does one job, like "list the users" or "start a backup". A port is a numbered door on a computer; one machine can run many services, and each listens on its own port number, the way one building can have many numbered doors. Port 4285 is the door this backup product listens on.
Setup
The only precondition was network access to the API on port 4285. I had no account and no credentials on the Uber instance, and the whole point of the exercise was to find a way in without them.
Bruteforcing credentials was not an option. Bruteforcing means trying huge numbers of username and password combinations until one works; it is slow, noisy, and usually blocked. There were also no published CVEs for this vendor at the time. A CVE is a public catalogue entry for a known security flaw in a specific product, with an ID number, so that everyone can look it up and patch it. If a flaw has a CVE, you can often find a description of how to exploit it. If it does not, you have to find the flaw yourself. The reason for the absence of CVEs became clear later: the bug I found was a 0day. A 0day ("zero-day") is a flaw that is not publicly known and has no fix yet, so defenders have had zero days to prepare.
Finding it
I queried the api/serverEnv API on the target:
https://backup.uberinternal.com:4285/api/serverEnv
This is a single web address. https:// means the connection is encrypted. backup.uberinternal.com is the name of the server. :4285 is the port, the numbered door described above. /api/serverEnv is the endpoint, the specific job being asked for. The name suggests it reports information about the server's environment, that is, its configuration and version details. I accessed the API and read what came back.
From the response it became clear that Uber was running the last version of the product, 5.2.0. Knowing the exact version matters because it tells you which known flaws might apply, and here it told me that the newest release was in use, so there was nothing old and patched to fall back on. With no known vulnerabilities to reuse, the only way to break the service and earn a bounty was to find a 0day myself.
I went to Code42's publicly available documentation, extracted every documented API method, and started bruteforcing them to see which ones could be reached without authentication. Here "bruteforcing" does not mean guessing passwords. It means taking the full list of endpoints from the manual and simply requesting each one in turn, to see which ones answer without a login. It is like walking down a corridor trying every door handle: most are locked, but you only need one that opens. One API call stood out as reachable by any external user, documented at https://www.crashplan.com/apidocviewer/#SsoAuthLoginResponse.
The documentation stated that /api/SsoAuthLoginResponse accepts a GET parameter named SAMLResponse. A GET parameter is a value appended to the end of a web address after a question mark, like the search terms in a search engine URL; the server reads it and acts on it. Its value is a base64-encoded string that is meant to contain XML authentication data. Base64 is a way of writing any chunk of data using only ordinary letters, digits and a couple of symbols, so that it can travel safely inside a web address without being mangled. XML is a text format for structured data, built out of tags in angle brackets, similar in spirit to HTML but meant for data rather than for pages.
That is the classic shape of a SAML endpoint. SAML is a standard for single sign-on: instead of every application checking your password itself, a central identity provider logs you in once and then hands the application a signed statement, called an assertion, saying who you are. The application that receives the assertion is called the service provider. It receives the assertion, decodes it and parses the XML. Parsing means reading the text and turning it into a structured object the program can work with.
An endpoint that parses attacker-supplied XML before authentication is exactly where an XML External Entity attack belongs. An XML External Entity attack, usually shortened to XXE, abuses a feature of XML: a document can declare an "entity", which is a named placeholder, and the value of that placeholder can be a file on the server or a URL. When the parser reads the document, it helpfully fetches whatever the entity points at and substitutes the contents. If the attacker controls the document, the attacker controls what gets fetched. The everyday comparison is a form that says "attach the document named here": if you can write the name, you can make the clerk fetch any document in the building, not just the one you were supposed to send.
Exploitation
Step 1: Confirm out-of-band parsing
I constructed a trivial XML document with external entities pointing at my own VPS, using a non-standard port because ports 80 and 443 were filtered by the firewall on the target side. A VPS is a virtual private server, a machine you rent on the internet that you fully control. A firewall is a filter on network traffic; here it was blocking the usual web ports 80 and 443 on outgoing connections, so I used a different port number to get through. I sent the document as the base64-encoded SAMLResponse value and got a response back from my server. The server was vulnerable to an XXE out-of-band (OOB) attack.
Out-of-band means the result does not come back in the normal reply to my request. In many XXE cases the application never shows you the file it read; it just fetches it and uses it internally. So instead you make the server contact a machine you own, and you watch that machine. If your server sees a connection, you know the parser resolved your entity. It is like asking a stranger to post a letter to your own address: you do not need them to tell you they did it, the letter arriving is the proof.
I have deliberately not published the final HTTP request, since the exploitation string is straightforward once the mechanism is known.
Step 2: Understand the OOB channel
Because the application was written in Java, I knew I could read directories, so I immediately launched the xxe-ftp server to extract data. Java is a programming language, and the standard Java XML parser has a particular behaviour: it can be made to list the contents of a directory, not just read a single file. Credit for that tool goes to the people at OnSec; their research on XXE OOB exploitation against Java 1.7 is at http://lab.onsec.ru/2014/06/xxe-oob-exploitation-at-java-17.html.
The mechanism, for anyone who has not used it, is this. The attacker's host runs a script that acts as an HTTP server to receive the OOB payload on port 8088, and as an FTP server that accepts connections on port 8077. HTTP is the protocol browsers use to fetch pages; FTP is an older protocol for transferring files. The FTP server captures what the parser sends, which is how file contents leave the target without ever appearing in an HTTP response.
My FTP listener records the username, and so I receive the file. The file never has to be shown to me by the web application at all.
Step 3: Prove impact on Uber
As a proof of concept for Uber, I retrieved the contents of the /home/ directory of the server. A proof of concept is the smallest demonstration that shows a flaw is real, rather than just theoretical. /home/ is the folder on a Linux server where each user's personal files live, so listing it shows whose accounts exist on the machine. That was enough of an impact illustration for my report on HackerOne. HackerOne is the platform where bug bounty reports are submitted and discussed with the company.
Step 4: Go further, with permission
Uber's security team was engaged with the finding: they contacted the vendor and confirmed that the vulnerability was a 0day. They also asked me to elaborate on the vulnerability. Since I like to demonstrate impact, I did not need to be asked twice.
Given permission to show further exploitation, I quickly found the folder where backup logs were stored. A log is a running record a program writes of what it has done. A screenshot of one of the local files on the server showed information about a recently backed-up user.
It was clear from this that I could read the backup files of a little more than all domain accounts of a company that has the Code42 service at its perimeter. A domain account is a user account managed centrally by a company's directory service, so "all domain accounts" means essentially every employee. "At their perimeter" means the service is reachable from the public internet, not only from inside the office network.
Step 5: Scope the exposure
To understand the impact of this 0day in the wider world, I searched Shodan for port 4285. Shodan is a search engine for internet-connected devices and services: instead of indexing web pages, it indexes what is listening on ports across the internet. One globally known security firm had this application installed on its perimeter.
Root cause
The /api/SsoAuthLoginResponse endpoint takes a base64-encoded SAMLResponse from an unauthenticated GET request, decodes it and hands the XML to a parser that resolves external entities. Because the endpoint is part of the SSO login flow, it has to parse the assertion before it knows who the caller is, so the parser runs with the privileges of the service and with no authentication in front of it. Privileges here means the permissions the service itself has on the machine; whatever the service can read, the parser can read on the attacker's behalf.
A DTD is the part of an XML document that declares entities and structure; if the parser is told to ignore DTDs, the entity trick has nothing to work with. The report does not describe the parser configuration, so the exact setting that was missing is not stated; what is clear is that external entities were resolved, including over non-standard ports, which is what made the OOB channel work.
Impact
An unauthenticated attacker who can reach port 4285 could read files from the backup server. On Uber's instance I demonstrated reading the /home/ directory and then located the folder holding backup logs, which contained information about recently backed-up users. The report states that this gives access to the backups of a little more than all domain accounts of a company that has the Code42 service at its perimeter. The impact is therefore bounded by what the service account can read on that host, and by whether the service is reachable from outside.
The Shodan search showed that reachability is not hypothetical: at least one globally known security firm had the application on its perimeter.
Fix
Code42 updated the software and the vulnerability was patched in version 5.2.0.1. The report does not describe the code change itself.
Timeline
| Date | Event |
|---|---|
| May 6th, 2016 | Report sent to Uber through HackerOne |
| May 23rd, 2016 | Code42 updated their software; vulnerability patched in [redacted] |
| Jun 28th, 2016 | $9000 bounty received from Uber |
| Aug 24th, 2016 | Code42 asked to wait until the update is installed on all their clients |
| Jan 24th, 2017 | Code42 notified that the write-up would be published; no reaction |
In August 2016 Code42 asked for a delay, with a denial of responsibility: they preferred the blog post not be written until their latest version had been installed by all customers, noting that the fix was in the latest release but not yet deployed everywhere.
Variants to test
- Other SAML endpoints. Look for any endpoint that accepts a base64-encoded
SAMLResponseorSAMLRequestand parses it before authentication. A positive result is an out-of-band callback to your listener when the entity is resolved. - Other documented API methods. The report's method was to extract every documented API method and bruteforce them for unauthenticated access. A positive result is any method that answers without a session and takes XML or a base64 blob.
- Non-standard ports. If 80 and 443 are filtered, point the entity at a high port on your own host. A positive result is a connection from the target on that port. Egress filtering is the control on outgoing traffic from a network.
- Directory listing via the OOB channel. On Java targets, try reading a directory rather than a single file. A positive result is a directory listing arriving over the FTP listener.
- Backup and log directories. Once file read works, look for the folders where the product stores backup logs and metadata. A positive result is a file naming recently backed-up users, which turns a file read into a data exposure finding.
- Shodan for the product's management port. Search for the port the product exposes and check which organisations have it on the perimeter. A positive result is an internet-facing instance of the same product version.
Glossary
- 0day (zero-day): a security flaw that is not publicly known and has no fix yet, so defenders have had no time to prepare.
- API (Application Programming Interface): the set of addresses a program offers so other programs can talk to it.
- Assertion: in SAML, the signed statement from the identity provider saying who the user is.
- Base64: an encoding that turns any data into ordinary letters, digits and a few symbols so it can travel safely in a URL or text field.
- Bug bounty programme: a scheme where a company pays outside researchers for privately reported security flaws.
- Bruteforcing: trying many possibilities in bulk, such as many passwords, or here, requesting every documented endpoint in turn.
- CVE: a public catalogue entry with an ID for a known security flaw in a specific product.
- Directory: a folder on a computer's file system.
- Domain account: a user account managed centrally by a company's directory service, typically one per employee.
- DTD: the part of an XML document that declares entities and structure.
- Egress filtering: control over outgoing network traffic from a network.
- Endpoint: one specific address in an API that performs one job.
- Entity (XML): a named placeholder in an XML document whose value can be a file or URL that the parser fetches.
- Firewall: a filter on network traffic that allows or blocks connections.
- FTP: an older protocol for transferring files between machines.
- GET parameter: a value appended to a web address after a question mark, which the server reads.
- HackerOne: the platform where bug bounty reports are submitted and discussed with the company.
- HTTP: the protocol browsers use to fetch pages and talk to web servers.
- Identity provider: the central service that logs a user in and vouches for their identity to other applications.
- Java: a programming language; its standard XML parser has particular behaviours relevant to XXE.
- Log: a running record a program writes of what it has done.
- Out-of-band (OOB): getting the result of an attack through a separate channel, such as a connection to your own server, rather than in the normal reply.
- Parser: the part of a program that reads text in a format such as XML and turns it into structured data.
- Port: a numbered door on a computer through which a particular service listens.
- Proof of concept: the smallest demonstration that a flaw is real rather than theoretical.
- SAML: a standard for single sign-on, where a central identity provider hands applications a signed assertion about the user.
- Service provider: in SAML, the application that receives and checks the assertion.
- Shodan: a search engine that indexes internet-connected devices and services by port and banner.
- Single sign-on (SSO): logging in once centrally and being recognised by many applications.
- VPS: a virtual private server you rent on the internet and fully control.
- XML: a text format for structured data built out of tags in angle brackets.
- XXE (XML External Entity attack): abusing XML's entity feature so the parser fetches files or URLs chosen by the attacker.