Length-extension attack
SHA-256 (as well as MD5, SHA-1) is based on the Merkle-Damgård construction: the message is divided into blocks, the internal state passes from block to block, and the final state becomes the hash itself. The vulnerability of this construction is the length-extension attack.
Assumption: the server checks message authenticity using a naive MAC: MAC = sha256(secret || message), where secret is an unknown key. You know message and its MAC, as well as the length of the key. Since the hash is the final internal state, you can continue from this state and generate a valid MAC for secret || message || padding || append without knowing the key.
Given values (also available in the berilgan.txt file):
message = user=guest&role=user&expiry=2026
orig_mac = 21d7b4c85c7b11d997dc97546046c3cbdadf9326c5ce2ee80620f34b69977700
secret_length = 28 bayt
qo'shmoqchi (append) = &role=admin&grant=all
Task: using length-extension, calculate a valid MAC (forged MAC) for a new message with appended append.
Answer: the hex representation of the hash value (lowercase, no spaces).
Padding is the standard SHA-256 padding: 0x80, then zeros, then the message length in bits (64-bit, big-endian). The length is calculated based on the number of secret || message bytes.