Applied Deliberation

Assorted Adventures of Sampsa Kiiskinen

Exercise on Exploiting Overflows

The following program is available on a system you have user access to.

$ stat probe
  File: 'probe'
  Size: 6312            Blocks: 16         IO Block: 4096   regular file
Device: 13h/69d         Inode: 42          Links: 1
Access: (4775/-rwsrwxr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-04-01 16:20:00.000000000 +0300
Modify: 2015-04-01 16:20:00.000000000 +0300
Change: 2015-04-01 16:20:00.000000000 +0300
 Birth: -

The program asks the user for a file path and tells them whether such a file exists. Its reach is not limited to files owned by or shared with the user. As the access flag s indicates, the program is run with elevated privileges, because it must be able to inspect the whole system.


The program looks harmless, but has a bug that allows an apt user to take over the world system. Your task is to

If you are incapable of evil, at least


The source code of the program is shown below.


The program is available as an ELF 64-bit LSB executable for x86-64 architectures.

If you want to compile the program yourself, make sure to turn off all the analysis, optimization and security features your compiler has to offer. They can modify the program in unexpected ways and make the exercise difficult or impossible.

For example GCC 4.8.2 can be instructed as follows.

$ gcc -D_GNU_SOURCE -O0 -fno-stack-protector -o probe -std=c99 -w probe.c

See its manual for unnecessary details.