Friday, 3 October 2014

Beware what you click

Usually my (not too many :( ) posts are written for a technical audience (not too big :( ). This time, given the fact October is Cyber Security Month I will try to put some effort to try to explain how you can keep yourself away from annoyances. Well the rule of thumb is actually extremely simple and can be resumed with a simple sentence:

 Beware what you click

Let me repeate it: "beware what you click" :)
Just following this simple rule you can avoid 90% of scam/viruses and phishing attacks.
But lets do a step back. Assuming you know already what is a computer's virus let me explain what is a phishing attack. Phishing scam uses legitimate-looking websites to trick a victim into sharing their username, password or other  sensitive information. Pishers will design their sites to look exactly like e.g. the website of your mail provider, your bank, credit card issuer, or another financial institution. The hope is that you won't realize you are on the wrong site, and just punch your password like you normally would. Then, they use it to log into your accounts and e.g. transfer out your money.
So here some advice for you:
  • Look carefully at a website before giving any information (specially sensitive data)
  • Especially look out for slightly misspelled words
  • If something looks even a little fishy, delete the mail and close the site ASAP
  • Create bookmarks in your browser for commonly used sites (e.g. mail, bank, etc)
  • But overall

     Beware what you click

     
Non GEEK can STOP here :) Now let me show some example of phishing based on an open redirect I found on Google-Github OAuth integration :) This is a variant of the 'Lassie Come Home' OAuth attack I previously talked about.  In https://console.developers.google.com/project is possible to connect a project with Github. So far so good :) The problem is that the Google's OAuth client id registered in github (namely fde1c8c8834c1b0adcc8) has a registered redirect_uri that is too open (namely https://console.developers.google.com/). This is because the same OAuth client id is used for every Google project to connect with github. For example project APPS_A when connects to Github will end up having this request to the github authorization endpoint:

https://github.com/login/
oauth/authorize?client_id=fde1c8c8834c1b0adcc8&redirect_uri=https://console.developers.google.com/project/APPS_A&response_type=code&scope=repo&state=STATE

and APPS_B will have

https://github.com/login/oauth/authorize?client_id=fde1c8c8834c1b0adcc8&redirect_uri=https://console.developers.google.com/project/APPS_B&response_type=code&scope=repo&state=STATE

Note that the same client_id is used in both requests. This is possible because as said above the registered redirect uri is https://console.developers.google.com. Github validates only the start of the URI (as clearly stated here) and considers valid redirect uri if everything else is appended after the registered redirect uri. In our example the registered redirect uri is https://console.developers.google.com/ so github will consider valid https://console.developers.google.com/WHATEVER so in our case https://console.developers.google.com/project/APPS_A and https://console.developers.google.com/project/APPS_B are both valid and Google leverages happily this features :) Another thing to notice is that in Github once you authorize the application once the consent screen is not shown anymore namely the redirect will happen *without* human interaction.

So what an attacker needs to do is to upload an html file in the Google Cloud Storage Bucket and apply some open permission in order to be read by anyone (or by at least by the victim).
The html file will have a fixed uri of https://console.developers.google.com/m/cloudstorage/b/augmented-tract-3923rewrew233.appspot.com/o/aa/test.html. Notice that this is a valid redirect URI for fde1c8c8834c1b0adcc8 since it start with https://console.developers.google.com

So now  is possible to forge the initial OAuth call like this:

https://github.com/login/oauth/authorize?client_id=fde1c8c8834c1b0adcc8&redirect_uri=https://console.developers.google.com/m/cloudstorage/b/augmented-tract-3923rewrew233.appspot.com/o/aa/test.html&response_type=code&scope=repo&state=NtMfd5ccxz-a6GtwuqcQiv1L9Uc this will redirect to https://console.developers.google.com/m/cloudstorage/b/augmented-tract-3923rewrew233.appspot.com/o/aa/test.html?code=ccd04786b8113318c3d7&state=NtMfd5ccxz-a6GtwuqcQiv1L9Uc

Mind that test.html is controlled by the attacker.


To recap the attack looks like this:
  • the attacker forge an url like https://github.com/login/oauth/authorize?client_id=fde1c8c8834c1b0adcc8&redirect_uri=https://console.developers.google.com/m/cloudstorage/b/augmented-tract-3923rewrew233.appspot.com/o/aa/test.html&response_type=code&scope=repo&state=NtMfd5ccxz-a6GtwuqcQiv1L9U
  • the victim clicks the link
  • this will redirect to https://console.developers.google.com/m/cloudstorage/b/augmented-tract-3923rewrew233.appspot.com/o/aa/test.html?code=ccd04786b8113318c3d7&state=NtMfd5ccxz-a6GtwuqcQiv1L9Uc-
This is how a successfully phishing attack can be conducted (if the victim trusts Github or Google would be even simpler since the URL used in the attack are "familiar" domains for the victim).

As a consequence Google decided to tighten the redirect_uri in github (now is https://console.developers.google.com/project)

Final note, (unlikely for me) but good for Google:
otherwise I could as well steal the Authorization Code!!