Skip to main content

Persistent XSRF on Kubernetes Dashboard using Redhat Keycloak Gatekeeper on Microsof Azure

tl;dr I found an  XSRF in the OAuth implementation of Redhat Keycloak Gatekeeper. This would be a bit worse for people using Gatekeeper to protect their Kubernetes Dashboard (especially in Microsof Azure).

The Issue in Keycloak Gatekeeper

Keycloak Gatekeeper is an OpenID Proxy service for Keycloak, an Identity and Access Management solution developed and opensourced by RedHat (now IBM). 
Solutions like this are often used to protect things like Kubernetes Dashboard (unless you want to do like Tesla and expose your Kubernetes Dashboard unauthenticated to the internet) and this (for the record) is why I came across to the issue. I will postpone a deeper analysis of the Kubernetes Dashboard to a future post. The issue is dead simple and I already talked about this several times. This was also  defined by Egor Homakov as the the Most Common OAuth2 Vulnerability (and it looks he was right :p) .
Basically the Keycloak Gatekeeper  developers forgot to implement a  really important piece (in OAuthland) namely the state parameter. This parameter is, according to the OAuth core specification:

An opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client. The parameter SHOULD be used for preventing cross-site request forgery (CSRF).
The best way to see this XSRF account in action is through a picture:
Now in order to avoid repeating myself, if you want to know more about this vulnerability just read my old blog post. 

The Issue in Microsoft Azure

And what about Microsoft Azure? Well as you know many deployments of Kubernetes cluster are not home brewed. What people do is to leverage AWS/Azure or Google cloud to host their Kubernetes cluster. The connection whit this bug here is that the OAuth implementation of Microsoft Azure suffered from a different OAuth issue that in combination with this would have make the issue way easier to be exploited (making it Persistent as in the title of this blog post).So what's the bug?
Basically the Mictosoft Azure's OAuth server implementation was violating another part of the OAth spec namely the section 4.1.3 of the OAuth 2 core specification aka RFC 6749:

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.
  
As you might imagine they were not the only one and I already talked about it in the past.

Conclusion

Is always really surprising that different implementations make the same mistake again and again. In this case two different parts of the stack made 2 different mistakes making the attack much easier to exploit. To conclude this short post Keycloak Gatekeeper fixed the issue in this commit and you can download the fixed version here and Microsoft Azure fixed the issue already.

P.s. little rant I ended up this little journey with no CVE assigned by Keycloak Gatekeeper or any mention whatsoever and no bounty from Microsoft. This doesn't make a big difference to someone like me that is in this dirty business for many years but it for sure could have been a killer motivation for a young researcher. To be completely honest both teams Keycloak Gatekeeper and MSRC where super nice though.

For more OAuth trickery follow me on Twitter.  

Comments

Popular posts from this blog

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 …

The Curious Case of WebCrypto Diffie-Hellman on Firefox - Small Subgroups Key Recovery Attack on DH

tl;dr Mozilla Firefox prior to version 72 suffers from Small Subgroups Key Recovery Attack on DH in the WebCrypto's API. The Firefox's team fixed the issue removing completely support for DH over finite fields (that is not in the WebCrypto standard). If you find this interesting read further below. Premise In this blog post I assume you are already knowledgeable about Diffie-Hellman over finite fields and related attacks. If not I recommend to read any cryptography book that covers public key cryptography. Here is a really cool simple explanation by David Wong:
I found a cooler way to explain Diffie-Hellman :D pic.twitter.com/DlPvGwZbto — David Wong (@cryptodavidw) January 4, 2020 If you want more details about Small Subgroups Key Recovery Attack on DH I covered some background in one of my previous post (OpenSSL Key Recovery Attack on DH small subgroups (CVE-2016-0701) ). There is also an academic paper where we examine the issue with some more rigors. If you want to read th…

All your Paypal OAuth tokens belong to me - localhost for the win

tl;dr  I was able to hijack the OAuth tokens of EVERYPaypal 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/callbackNOT JUST https://yourouauthclient.com/ or https://yourouauthclient.com/oauth If you are still not convinced here…