After some enumeration, we initially found nothing. However, there is one file we havenโt reversed or exploited yet: the getflag binary.
1 2
level14@SnowCrash:~$ which getflag /bin/getflag
Analyzing the getflag Binary
To begin, letโs open the getflag binary in GDB:
1 2 3 4 5 6 7 8 9
level14@SnowCrash:~$ gdb /bin/getflag GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 ... Reading symbols from /bin/getflag...(no debugging symbols found)...done. (gdb) r Starting program: /bin/getflag You should not reverse this [Inferior 1 (process 3456) exited with code 01] (gdb)
We can see that the binary has ptrace protection, which prevents it from being debugged normally.
Bypassing ptrace Protection
After researching, we found a method to bypass this protection. We can set a catchpoint for the ptrace syscall and modify the eax register to bypass the check.
Steps to Bypass ptrace Protection
Start GDB and set a catchpoint for the ptrace syscall:
Set a breakpoint at the instruction where the user ID is checked:
1 2
(gdb) b *0x08048b0a Breakpoint 3 at 0x8048b0a
run the program
1 2
(gdb) r Starting program: /bin/getflag
Continue execution until the user ID check and modify the eax register:
1 2 3 4 5 6
Breakpoint 3, 0x08048b0a in main () (gdb) set ($eax) = 3014 (gdb) c Continuing. Check flag.Here is your token : ************************************ [Inferior 1 (process 3161) exited normally]