Pwnable
Published
Oct 18, 2024
5
-
min read
Pwnable.kr: collision Solution
So beginning with this puzzle, the hint the website provides us with is another SSH command
Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!
ssh col@pwnable.kr -p2222 (pw:guest)
MD5:
MD5 is a hashing algorithm that has been going around since the 1990s. It generates a 128 bit
hash output for any given input. It is generally used to check the authenticity of files or content served over the internet to check whether the data received is exactly what the server meant to sent. To do this we compare the hashes of the received data and the data sent by the server. However it has been broken many times since 2005 and any malicious actor can alter the contents of the data/file while maintaining the same hash which defeats its purpose. This is what we call a collision. When 2 different inputs provide us with the same hash output we have a hash collision.
Walkthrough:
Let's start with the SSH credentials provided to us and login to the server via SSH. Upon logging in we'll be greeted by this.
Now like usual we start searching for the flag. We type ls
into the terminal and are greeted by this
And like before the ls -la
command shows that we cannot open the flag file directly
And exactly like before we have permission to use the col
file which is an executable
And we have the source code for this file in col.c
Reading the source code we can infer the following about the col file
It requires 1 argument to be passed because of the following check
if(argc<2) { … return 0;}
The argument passed must be of length 20 as each character takes 1 byte
This file can open the flag file via a system call to the
cat
commandsystem("/bin/cat flag")
The file can only be opened if the
check_password
function for the argument we passed equals thehashcode
which is set to0x21DD09EC
The
check_password
function appears to be using a reference to a string then changing that to integer array form and then looping through its first 5 integers and then adding them to return a value.
Now 1 integer is worth 4 bytes and we need 5 of them so a total of 20 bytes, which is the exact length of our input being passed on. Looking at the code closely we can say that it combines 4 characters to make an integer then add them. So we just need to calculate 5 integers that when added equal the hashcode and we will be able to successfully read the flag.
0x21DD09EC
is a hexadecimal representation of the number 568134124
which I found with a python one liner
These one liners will be really helpful as we go on. Now to find 5 numbers that add up to create 568134124
I use another small python one-liner
The formatting is a little weird for sure but we get 5 numbers that will add up to form the hashcode
. Each number has 4 bytes here and we need to each number to 4 characters of 1 byte each. Lets first convert them to binary
Not too readable, lets segregate them into bytes
That is more readable. The keen amongst you might be noticing that somehow the 1st byte is different between the 2 numbers instead of the last one. Well this is because the machine is little endian. If you used an external converter instead of the python one liner you might get a different result and would have to change the ordering of bytes to little endian. To check whether the machine is little endian or big endian, you can use this command
Now since we have the bytes time to convert them to characters
And we have the ASCII characters associated with them ready. Now we can simply pass them into our program by piping
or simply
The last line is our flag and we have successfully solved this puzzle