Csaw 2018 Quals Boi

1. Analysis

1.1 Basic

a. From the pwn checksec command, we know the following:

b. After running the binary, we know that the program simply prints the line Are you a big boiiiiii??, and waits for an input. If the input is incorrect (speculation, to be confirmed later on), it will output the current date and time.

1.2 Ghidra

main function (Decompile view)

Refined main function

From this, we know that the program reads in 0x18 (24) bytes of data from the user into the input variable. Next, it checks if the target variable matches a certain value (-0x350c4512). If it matches, run /bin/bash, else run /bin/date.

Variables (Listing view)

We can see that the input is stored lower in the stack at offset -0x38, while the target variable is stored higher at offset -0x24. This makes the input variable 0x38 - 0x24 = 0x14 bytes lower than the target variable. This means that given the proper payload, we can overwrite the value of the target variable in the stack with the matching value.

Remember that the read function defined earlier allows us to write 0x18 into the input variable

The assembly instruction corresponding to the IF statement:

This means that we have to overwrite the target variable value in stack with 0xcaf3baee. Since we are able to write 0x18 bytes of data, while the offset between the input and target is 0x14 bytes, we will be able to achieve this

1.3 GDB

Since there is no PIE enabled, we can skip the starti, which will usually be required to load the runtime addresses.

Lets focus on the following 2 lines, which corresponds to the read function, and the subsequent IF comparison statement:

We can set a breakpoint on the 3rd line (0x00000000004006a8), and view the eax register

  • The breakpoint value simply runs the program till the point where the user inputs a value, before the value at the portion of the stack (target variable) is moved to the eax register

As of now, it contains the value 0xdeadbeef. Now, lets use the payload ` to write the value 0xcaf3baee into the target variable:

We can see that the eax register now contains the value 0xcaf3baee

2. Exploit script

When we execute the exploit, we will pass the checks, and the program will pop a shell for us with the /bin/bash command

Last updated