Nytro Posted November 29, 2016 Report Posted November 29, 2016 Monday, 28 November 2016 All your Paypal OAuth tokens belong to me - localhost for the win tl;dr I was able to hijack the OAuth tokens of EVERY Paypal OAuth application with a really simple trick. Introduction If you have been following this blog you might have got tired of how many times I have stressed out the importance of the redirect_uri parameter in the OAuth flow. This simple parameter might be source of many headaches for any maintainer of OAuth installations being it a client or a server. Accepting the risk of repeating myself here is two simple suggestions that may help you stay away from troubles (you can always skip this part and going directly to the Paypal Vulnerability section): If you are building an OAuth client, Thou shall register a redirect_uri as much as specific as you can i.e. if your OAuth client callback is https://yourouauthclient.com/oauth/oauthprovider/callback then DO register https://yourouauthclient.com/oauth/oauthprovider/callback NOT JUST https://yourouauthclient.com/ or https://yourouauthclient.com/oauth If you are still not convinced here is how I hacked Google leveraging this mistake. Second suggestion is The ONLY safe validation method for redirect_uri the authorization server should adopt is exact matching Although other methods offer client developers desirable flexibility in managing their application’s deployment, they are exploitable. From “OAuth 2 In Action” by Justin Richer and Antonio Sanso, Copyrights 2016 Again here you can find examples of providers that were vulnerable to this attack Egor Homakov hacking Github me/myself hacking Facebook bypassing the regex redirect_uri validation Paypal Vulnerability So after this long premise the legitimate question is what was wrong with Paypal ? Basically like many online internet services Paypal offers the option to register your own Paypal application via a Dashboard. So far so good :). The better news (for Paypal) is that they actually employs an exact matching policy for redirect_uri So what was wrong ? While testing my own OAuth client I have noticed something a bit fishy. The easier way to describe it is using an OAuth application from Paypal itself (remember the vulnerability I found is universal aka worked with every client!). Basically Paypal has setup a Demo Paypal application to showcases their OAuth functionalities. The initial OAuth request looked like: https://www.paypal.com/signin/authorize?client_id=AdcKahCXxhLAuoIeOotpvizsVOX5k2A0VZGHxZnQHoo1Ap9ChOV0XqPdZXQt&response_type=code&scope=openid profile email address phone https://uri.paypal.com/services/paypalattributes https://uri.paypal.com/services/paypalattributes/business https://uri.paypal.com/services/expresscheckout&redirect_uri=https://demo.paypal.com/loginsuccessful&nonce=&newUI=Y As you can see the registered redirect_uri for this application is https://demo.paypal.com/loginsuccessful What I have found out is that the Paypal Authorization Server was also accepting localhost as redirect_uri. So https://www.paypal.com/signin/authorize?client_id=AdcKahCXxhLAuoIeOotpvizsVOX5k2A0VZGHxZnQHoo1Ap9ChOV0XqPdZXQt&response_type=code&scope=openid profile email address phone https://uri.paypal.com/services/paypalattributes https://uri.paypal.com/services/paypalattributes/business https://uri.paypal.com/services/expresscheckout&redirect_uri=https://localhost&nonce=&newUI=Y was still a valid request and the authorization code was then delivered back to localhost . Cute right? But still not a vulnerability Well the next natural step was to create a DNS entry for my website looking lke http://localhost.intothesymmetry.com/ and try: https://www.paypal.com/signin/authorize?client_id=AdcKahCXxhLAuoIeOotpvizsVOX5k2A0VZGHxZnQHoo1Ap9ChOV0XqPdZXQt&response_type=code&scope=openid profile email address phone https://uri.paypal.com/services/paypalattributes https://uri.paypal.com/services/paypalattributes/business https://uri.paypal.com/services/expresscheckout&redirect_uri=http://localhost.intothesymmetry.com/&nonce=&newUI=Y and you know what? BINGO : So it really looks like that even if Paypal did actually performed exact matching validation, localhost was a magic word and it override the validation completely!!! Worth repeating is this vulnerability worked for any Paypal OAuth client hence was Universal making my initial claim All your Paypal tokens belong to me - localhost for the win not so crazy anymore. For more follow me on Twitter. Disclosure timeline 08-09-2016 - Reported to Paypal security team. 26-09-2016 - Paypal replied this is not a vulnerability!! 26-09-2016 - I replied to Paypal saying ok no problem. Are you sure you do not want to give an extra look into it ? 28-09-2016 - Paypal replied the will give another try. 07-11-2016 - Paypal fixed the issue (bounty awarded) 28 -11-2016 - Public disclosure. Acknowledgement I would like to thank the Paypal Security team for the constant and quick support. Posted by Antonio Sanso at 02:00 Sursa: http://blog.intothesymmetry.com/2016/11/all-your-paypal-tokens-belong-to-me.html Quote