I thought of this really cool collision free hash function and hashed the flag with it. Theoretically you shouldn’t be able to reverse it…
Category: rev
Solver: computerdores
Flag: GPNCTF{W41t,_h0w_d1d_y0u_s0lv3_th1s?_I_th0ught_1t_w45_4_g00d_h45h}
Writeup
For this Challenge we got a file called hash
that contains a hex string and a binary called hasher
.
Opening the hasher
binary in ghidra, we can see that the main method accepts a string as a parameter to the binary and “hashes” it with the following loop:
for (int i = 1; i <= flag_length; i++) {
flag[i] = flag[i] ^ flag[i - 1];
printf("%02x",flag[i]);
}
Since every byte is xor’ed with the previous byte and flag[0]
is initialized to 0
, we can use the following code to run this loop again and get back the flag:
# the hex string from the hash file
hash = "4717591a4e08732410215579264e7e0956320367384171045b28187402316e1a7243300f501946325a6a1f7810643b0a7e21566257083c63043404603f5763563e43"
# parse the hex string into integers
parsed_hash = [0]
while len(hash) > 0:
parsed_hash.append(int(hash[:2], 16))
hash = hash[2:]
# the loop
for i in range(1, len(parsed_hash)):
print(chr(parsed_hash[i]^parsed_hash[i-1]), end="")
Which prints:
GPNCTF{W41t,_h0w_d1d_y0u_s0lv3_th1s?_I_th0ught_1t_w45_4_g00d_h45h}