Skip to content
Crypto Write-up Advanced

Exploiting SHA-1-signed messages

The API signed requests by prefixing a secret salt to the message and hashing with SHA-1, which is vulnerable to a length extension attack. An attacker who intercepts a signed request can append extra parameters and compute a valid signature without knowing the salt, allowing them to alter the transaction.

journal.batard.info

Published on journal.batard.info

A few weeks ago, I was asked to review a coworker’s PHP code, which provides an API for a web game. The specifications for this API were sent to a mobile development company, in charge of making an iPhone app for the game.

Nicolas Favre-Felix, on journal.batard.info

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely using a plain hash function (SHA-1) with a secret prefix as a message authentication code, which is vulnerable to length extension attacks.

Impact

An attacker who intercepts a signed request could modify its parameters (e.g., change the recipient and amount) and have the server accept the modified request as valid, potentially leading to unauthorised transactions.

What the attacker needed

Ability to intercept a signed request; Knowledge of the salt length (or guess)

How it was found

  1. Intercept a signed API request containing parameters from, to, and amount.
  2. Note the original signature and the length of the secret salt (guessed as 11 bytes).
  3. Compute the internal state after hashing the original message plus padding.
  4. Use that state to hash a new chunk containing additional parameters (&to=666&amount=99999).
  5. Construct a new message consisting of the original message, padding, and the injected data.
  6. Send the new message with the computed signature; the server accepts it and executes the altered transaction.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A hash function like SHA-1 turns any input into a fixed-length fingerprint. If you use it to sign a message by putting a secret at the start, an attacker can extend the message and still produce a valid fingerprint because SHA-1 processes data in blocks and reuses the internal state. This lets them add extra instructions to a signed request without knowing the secret.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.