pwnable.kr

[pwnable.kr] hash collision

mjk- 2024. 7. 1. 22:25

What is hash collision?

Hash collision happens when the different keys (inputs of the hash function) have the same hash value. Simply, it means the hash code is not unique.

 

SSH & Code

When you log Into the server, you can realize that your current uid is col. This means you must use a col file to execute, but you can read col.c. 

 

Let's look into the col.c file:

In the main function, the first if statement checks whether there is an argument. 

argc (argument count) is the number of strings pointed by argv. Remember that argc will be (1 + #arguments). 

argv is the array of arguments. More explanations here.

 

The second if statement makes sure the first argument is 20 bytes. 

Remember that argv[1] is the first argument, and argv[0] is the program name.

 

The third if statement shows if the global variable "hashcode" matches with the output of check_password(argv[1]).

If it matches, it returns the flag. If it doesn't, it returns "wrong passcode".

 

Then, let's look at the check_password() function:

The function takes the pointer input p, converts it into an integer value, and adds the first five values. 

 

To get a flag, we must find the string argument that its first 5 characters add up to 0x21DD09EC.

With a remainder of 4, 0x21DD09EC = 0x06C5CEC8 * 4 + (0x06C5CEC8 + 0x4)  = 0x06C5CEC8 * 4 + 0x06C5CECC.

Using the little-endian notation and python, we can find the argument and thus the flag.