Attacking JSON Web Token
Last updated
Last updated
Let's say, this is a normal user web page.
When we register and login with an account, the authentication mechanism is look like this.
When we decode it,
It's using RS256
algorithm and token is using jku
header parameter which contains the JSON Web Key and the URL is to be used for token verification.
The jku header is a URI that refers to a resource for a set of JSON-encoded public keys, one of which corresponds to the key used to digitally sign the JWS.
The jku
header url is look like this,
If an attacker generate a public and private key pairs and create a new token with a new private key (which we generated) and replace jku
header with the url which contains new generated jwks.json
file (host on a web server) and then the token would be accept by the server.
Download or copy that jwks.json
file.
We're using python jwcrypto
module to generate n,e and kid
Install pip3 install jwcrypto
Run python3 jwk-gen-1.py
and the output should look like this
Replace kid
, n
and e
in your jwks.json
file like this,
Now we can create a new token as username admin
NOTE: If the server validate the original url, we can use the Redirect
method like above. If not, you can use just like "jku": "http://yourwebsever.com/jwks.json"
Run that script and we will get a new token like this.
Now create a web server, copy that a new token and replace it in a cookie header in web page.
When we replace the token and refresh page, it will request/download jwks.json
file in our web server.
Now we got admin panel by jku header claiming
method.