Skip to main content

OAuth 2 attacks and bug bounties - The Postman Always Rings Twice

Trying to continue the OAuth2 attacks saga started few months ago I am going to introduce a new kind of 'attack' named (by me, continuing the movie's name old tradition :D) 'The Postman Always Rings Twice'.
I hope the reason of this name will be clear soon.
In a nutshell the section 4.1.3 of the OAuth 2 core specification aka RFC 6749 says:

The client MUST NOT use the authorization code  more than once.  If an authorization code is used more than once, the authorization server MUST deny the request and SHOULD revoke (when possible) all tokens previously issued based on that authorization code.

Now this is a really simple claim, but it turned out that two major providers as Facebook and Google violated it, until I did report the 'violation'.
For this Facebook decided to reward me with a bug bounty (a while ago) and Google (only) with an honorable mention :(.

Now you might wonder what is so dangerous on violating section 4.1.3 of the spec? Hopefully this thread in the OAuth ietf mailing list will convince you that this can actually be 'dangerous' .

End of story ? Almost, there is some odds and ends :)
Indeed, when Google tried to 'fix' their implementation (after my report) introducing section 4.1.3 I have noticed an interesting behavior of their token endpoint and as turned out I could exploit it.

Indeed while not accepting the authorization code twice the were a bit too verbose on the error message  :).
This alone would not be enough to actually exploit it but the token endpoint of Google has an "interesting" behavior. 
Indeed the authorization code is on the form TOKEN1.TOKEN2  and only TOKEN1 is validated!!!

Now the attack would look like this:
  • register a client id
  • obtain an authorization token in the authorization endpoint (https://accounts.google.com/o/oauth2/auth) e.g. 4/ShttLZGi8w7b0MF5iRsdKBkaBB-6.Qrl8jChpba4TYKs_1NgQtmW51KPvhgI
  • now change the authorization code from 4/ShttLZGi8w7b0MF5iRsdKBkaBB-6.Qrl8jChpba4TYKs_1NgQtmW51KPvhgI to 4/ShttLZGi8w7b0MF5iRsdKBkaBB6.Qrl8jChpba4TYKs_1NgQtmW51KPvhgI<script>alert('hello')</script> and ask for an access token
  • As said this is going to be a valid authorization code and the access token is received due the fact that the authorization code is of the form TOKEN1.TOKEN2  and only TOKEN1 is validated!!!!!
  • So now we have everything to perform the attack :)
  • Indeed re-request the access token using the same forged authorization code (namely 4/ShttLZGi8w7b0MF5iRsdKBkaBB6.Qrl8jChpba4TYKs_1NgQtmW51KPvhgI<script>alert('hello')</script>). The authorization code is no longer accepted since the authorization code can be used only once. The interesting part of all this is how the token endpoint answers to this no longer valid authorization code. Indeed the error response looked like this:  
Token Record:
    Token: "4/ShttLZGi8w7b0MF5iRsdKBkaBB-6.Qrl8jChpba4TYKs_1NgQtmW51KPvhgI<script>alert('hello')<
/script>"
    IssueDomain: "788732372078.apps.googleusercontent.com"
    IssueTimeSec: 1389284562
    ExpirationTime: 1389285162
    TokenUsage: 3
    Scope: "https://www.googleapis.com/auth/plus.login"
    Scope: "https://www.googleapis.com/auth/plus.moments.write"
    Scope: "https://www.googleapis.com/auth/plus.me"
    Scope: "https://www.googleapis.com/auth/plus.profile.agerange.read"
    Scope: "https://www.googleapis.com/auth/plus.profile.language.read"
    Scope: "https://www.googleapis.com/auth/plus.circles.members.read"
    ServiceInfo {
    ServiceId: 226
    Info <
    [security_lso_auth_oauth2.OpenIdConnectRequestProto] <
    is_openid_connect_request: true
    >
    >
    }
    ServiceInfo {
    ServiceId: 226
    Info <
    [security_lso_auth_oauth2.EarlyIssuedTokenProto] <
    auto_approved: true
    access_token: "ya29.1.AADtN_UR3dYRzzCwYHP7uun3WsEWIN8u8JEJ1uHtrIqvJ8HpQFNH3LRL3Vg7Vlvr_uLgk4c9s8xZ"
    >
    >
    }
    Revoked: true
    AuthorizedBy: 0x93e5e8368c
    OAuthCallbackUrl: "http://localhost:8080/redirect"
    OfflineAccess: false
    ClientManagedRevocation: false


    ] 


as you can see the output is not sanitized specifically the part 4/ShttLZGi8w7b0MF5iRsdKBkaBB-6.Qrl8jChpba4TYKs_1NgQtmW51KPvhgI<script>alert('hello')</script> is bounced back without any ouptut sanitization.

This time (finally) Google actually rewarded  me with a bounty :)

Nice catch! I’ve filed a bug asking that HTML special characters be escaped in the JOSN output. I filed this at moderate severity as I don't believe this is exploitable on recent browsers. The response is returned with content type set to application/json and the header X-Content-Type-Options: nosniff is present, which should prevent the browser from interpreting the result as HTML.

Hurray!

Antonio


Comments

Popular posts from this blog

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…

Bug bounty left over (and rant) Part III (Google and Twitter)

tl;dr in this blog post I am going to talk about some bug bounty left over with a little rant.

Here you can find bug bounty left over part I and II
Here you can find bug bounty rant part I and II
Introduction In one of my previous post I was saying that: 

"The rule #1 of any bug hunter... is to have a good RSS feed list."
Well well well allow me in this post to state rule #2 (IMHO)

"The rule #2 of any bug hunter is to DO NOT be to fussy with 'food' specifically with left over"

aka even if the most experience bug hunter was there (and it definitely was my case here, given the fact we are talking about no one less than filedescriptor) do not assume that all the vulnerabilities have been found! So if you want some examples here we go.
Part I - GoogleI have the privilege to receive from time to time Google Vulnerability Research Grant. One of the last I received had many target options to choose from, but one in particular caught my attention, namely Google Issue T…

OpenSSL Key Recovery Attack on DH small subgroups (CVE-2016-0701)

Usual Mandatory Disclaimer: IANAC (I am not a cryptographer) so I might likely end up writing a bunch of mistakes in this blog post...

tl;dr The OpenSSL 1.0.2 releases suffer from a Key Recovery Attack on DH small subgroups. This issue got assigned CVE-2016-0701 with a severity of High and OpenSSL 1.0.2 users should upgrade to 1.0.2f. If an application is using DH configured with parameters based on primes that are not "safe" or not Lim-Lee (as the one in RFC 5114) and either Static DH ciphersuites are used or DHE ciphersuites with the default OpenSSL configuration (in particular SSL_OP_SINGLE_DH_USE is not set) then is vulnerable to this attack.  It is believed that many popular applications (e.g. Apache mod_ssl) do set the  SSL_OP_SINGLE_DH_USE option and would therefore not be at risk (for DHE ciphersuites), they still might be for Static DH ciphersuites.
Introduction So if you are still here it means you wanna know more. And here is the thing. In my last blog post I was …