ECB oracle: byte-by-byte recovery
Imagine the site appends a secret to your inputted text, encrypts it, and returns the ciphertext:
oracle(x) = AES-ECB-shifrlash(KALIT, PKCS7(x || SIR))
Both the key and the SECRET are unknown to you. But in ECB, each 16-byte block is encrypted independently — and this is exactly what allows recovering the SECRET byte by byte.
Attack idea (for the first byte):
- Send
x = "AAAAAAAAAAAAAAA"(15 As). The first block will consist of15 ta A + SIR[0]. - Now send
x = "AAAAAAAAAAAAAAA" + nomzodand compare the first blocks. The matching candidate is exactlySIR[0]. - Once SECRET[0] is known, you find SECRET[1] by sending 14 As, and so on.
We don't have a live server, therefore the responses to all necessary requests have been obtained in advance and written to the attached javoblar.json file. The file is a simple JSON dictionary:
{
"<so'rov baytlarining SHA-256 hex xeshi>": "<javob shifrmatni hex>",
...
}
The requests are stored by hash, because the requests themselves contain the discovered parts of the SECRET — they cannot be left in plaintext. To get the response, search for your request like this: jadval[hashlib.sha256(x).hexdigest()].
The table contains the following requests:
b"A" * k, wherek = 0..31— to determine the length of the SECRET;b"A" * (15 - (i % 16)) + SIR[:i] + nomzod— for eachiposition and each candidate.
Candidate alphabet (the SECRET consists only of these characters): uppercase Latin letters, lowercase Latin letters, numbers and _ { } characters — 65 in total.
Attention: when finding the i-byte, the block number to be compared is equal to i // 16 (32 characters starting from 32*blok in the hex string). Use only the letter A as padding — the table contains exactly such requests.