# On the exposition of SHA-1 attack (known_prefix + user_input + backend_secret)

Changing only user_input, how can I find some information about the constant value of backend_secret?

I give the known prefix of stackexchange, and the backend secret of 107983 (as a string) for this demonstration. You can only change user_input.

user_input="question"

KNOWN_PREFIX="stackexchange"
backend_secret="107983"

# bf24cd561d758104993d3fe6f58b44e6209c7bcd
printf "%s%s%s" "$$KNOWN_PREFIX" "$$user_input" "\$backend_secret" | sha1sum


The probe is obvious, we query for both known_prefix + user_input = A (less the last byte), and known_prefix + user_input = B (less the last byte) [where sha1(A) = sha1(B)].

To do this, SHA-1 would need to already be broken? Is it saying we need to find bf24cd561d758104993d3fe6f58b44e6209c7bxx with sha1(known_prefix + user_input + backend_secret), where xx and user_input can be anything?

If the first byte of backend_secret was the common last byte of A, B, then the results of the two queries are the same (and hence we have learned the first byte of backend_secret)

backend_secret is not known to us, and cannot be changed. The last byte of A and B is the last byte to backend_secret (since sha1(A) = sha1(known_prefix + user_input + backend_secret)). Is the answer saying this can happen if backend_secret is chosen poorly by the backend? Does backend_secret need to be of a specific size?

If they are different, we have learned what the first byte of backend_secret was not (and we can try again with a different collision with a different final last byte).

Since backend_secret is a constant, how can we "try again with a different final last byte"?

• @kelalaka I want explanation for how to use poncho's answer for the general case. My small secret is only example (6 bytes is not too small, it's already 48 bits - an attacker does not know it is made up of only digits). Commented Sep 16, 2023 at 20:50
• You asked, the details, that I gave my time for your understanding, and neither upvoted, nor accepted nor asked still some unclear part. Thank you. Deleted my answer. Commented Oct 1, 2023 at 10:48