Cyber Apocalypse 2023: Multipage Recyclings
A writeup on Multipage Recyclings
- Given materials: Get it here!
- Description: As your investigation progressed, a clue led you to a local bar where you met an undercover agent with valuable information. He spoke of a famous astronomy scientist who lived in the area and extensively studied the relic. The scientist wrote a book containing valuable insights on the relic’s location, but encrypted it before he disappeared to keep it safe from malicious intent. The old man disclosed that the book was hidden in the scientist’s house and revealed two phrases that the scientist rambled about before vanishing.
- Category: Crypto - Easy
The server script is shown below:
|
|
We also have an output file:
|
|
Problem statement
This code defines a class called CAES
that implements the AES encryption algorithm in ECB mode. The CAES
class has methods to blockify
a message into 16-byte blocks, xor
two byte arrays, and encrypt
a message using AES in ECB mode. Additionally, it has a method called leak
that generates a random integer r
and returns the encryption of two randomly chosen adjacent 16-byte blocks. The main
function of this code creates an instance of the CAES class, generates a message by padded FLAG*4
, encrypts the message, and generates a leak using the leak
method of the CAES
class. Finally, the main function writes the ciphertext
, the randomly chosen integer r
, and the leak
to a file called output.txt
.
Initial analysis
The encryption method
The encrypt()
method is not in ECB mode, it’s similar to CBC, which can be visualized by this graph:
The leaked data
The leak
method extracts 2 consecutives blocks of ciphertext and encrypted them using ECB mode. Our leaked data is of ciphertext block 3th and 4th. By using the graph above, we can easily see where the leak data comes from and how to use it to break the system, here is the new graph:
Solution method
The work is simple, just to xor the c[4]
with Leak[0]
and xor c[5]
with Leak[1]
, then we can recover the plaintext m[4]
and m[5]
, respectively. They must be parts of, or entire flag (in any order).
Here is the script:
|
|
Results
Here is the result: b'_w34k_w17h_l34kz}HTB{CFB_15_w34k'
Then the final flag would be: HTB{CFB_15_w34k_w34k_w17h_l34kz}