Skip to main content
Challenges JWT: RS256 -> HS256 confusion
Cryptography Hard JWT Solves: 7

JWT: RS256 -> HS256 confusion

Author: CyberSamSU
Points
85

RS256 — asymmetric signature: the server signs the token with a private RSA key, and the client verifies it with a public key. There is a flaw in some libraries: if an attacker changes alg in the header from RS256 to HS256, the server verifies the token with HMAC-SHA256 and uses the publicly known public key as the HMAC key. As a result, the attacker can create a valid signature using the public key — this is an algorithm confusion attack.

The attached pubkey.pem — is the server's public key. token.txt contains the original RS256 token and the encrypted flag. Simulated server rule:

javob = flag XOR SHA-256(qabul_qilingan_token)

The SHA-256 key is 32 bytes, and the flag is longer than that — the key is used repeatedly (cyclically): ct[i] ^ kalit[i % 32].

Construct the following forged HS256 token (compact JSON, base64url, without padding):

  • header JSON: {"alg":"HS256","typ":"JWT"}
  • payload JSON: {"login":"talaba","admin":1}
  • signing_input = base64url(header) + "." + base64url(payload)
  • signature = base64url(HMAC_SHA256(kalit=pubkey.pem baytlari, signing_input))
  • token = signing_input + "." + imzo

Important: read the pubkey.pem file exactly as bytes to use as the HMAC key (open('pubkey.pem','rb').read()) — formatting must be fully preserved.

Attached files
pubkey.pem Log in to download
token.txt Log in to download
SHA-256 checksums
pubkey.pem: fc791aeedca995cbb5c5b00b8455a6801ffd3ba06f3eeb28fddbd39a530bbb8a
token.txt: 54f45e9328ec46c3574e6dfd42c64992b1660254ceff5983cf648300504465b8
Theory: learn the topic
Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −8 pts Log in
Hint 2 −17 pts Log in
Hint 3 −25 pts Log in
To submit a flag, log in.

First solvers

1. Абдул 15.09.2026
2. W.o.X 17.09.2026
3. Лазиз 04.10.2026
4. testrejim 09.10.2026
5. Mirjaxon Qaxxarov 27.10.2026
6. Odam 05.11.2026
7. arcanum 11.11.2026