Skip to main content
Challenges 'HMAC' signature: length extension
Cryptography Expert Length extension attack on SHA-1 prefix-MAC (H(secret || msg)): recovering internal state Solves: 3

'HMAC' signature: length extension

Author: CyberSamSU
Points
170

The SamDocs service signs download links with 'HMAC', while in reality the developer used plain sig = SHA1(secret || query): secret is an unknown 8..32-byte secret, query is the raw query string before &sig=. The server reads the role parameter by its last value (if repeated, the last one wins). You have the service log and the service's 'oracle' table: signed_api.json.

File: log — nginx lines (each containing a signed request); oracle — {belgi: shifrmatn_hex}. When a request arrives at the server with m (raw bytes: the part up to &sig= after URL decoding) and signature s (lowercase hex, 40 characters) and the signature is valid, the response is encrypted. The key in the table: the first 16 hex characters of belgi = SHA256('oracle|' + m + '|' + s). Response cipher: K = SHA256('key|' + m + '|' + s), keystream SHA256(K || u32_be(0)) || SHA256(K || u32_be(1)) || ..., response = ciphertext XOR stream (JSON).

Task: take the single /api/export request in the log; without knowing the secret length, append &role=admin to it and craft a validly signed request (length extension: m' = m || padding || '&role=admin'). Inside the server response (JSON) there is a new request signed by the server itself (next, next_sig); if you append &scope=vault to it in the same way, the second response contains vault — the flag: BAYROQ{HMAC_UZUNLIK_KENGAYTMA_xxxxxxxxxxxxxxxx} (last 16 characters lowercase hex).

SHA-1 (FIPS 180-4): initial state H = 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0; the message is padded with 0x80, zeros, and the 64-bit big-endian BIT length to 64-byte blocks; in each block, w[0..15] are the big-endian words of the block, w[t] = ROL1(w[t-3]^w[t-8]^w[t-14]^w[t-16]) (t=16..79); 80 rounds: T = ROL5(a) + f + e + K + w[t]; e=d; d=c; c=ROL30(b); b=a; a=T; t<20: f=(b&c)|(~b&d), K=5A827999; t<40: f=b^c^d, K=6ED9EBA1; t<60: f=(b&c)|(b&d)|(c&d), K=8F1BBCDC; otherwise f=b^c^d, K=CA62C1D6; then a..e are added to H (mod 232). Hashlib does not allow setting the internal state — you will write the compression function yourself.

Attached files
signed_api.json Log in to download
Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −17 pts Log in
Hint 2 −34 pts Log in
Hint 3 −51 pts Log in
To submit a flag, log in.

First solvers

1. Odam 25.11.2026
2. Mirjaxon Qaxxarov 25.11.2026
3. Ulugʻbek 26.11.2026