Overlows Keep Flowing

Description

Overlows keep flowing | 133 points

Oh no! Another thing in another system broke, causing more overflows. This time you have to tell shutoff() what to shut off. Can you save the fl4gtory?

This is the second challenge in the pwn intro series

ncat --ssl overflows-keep-flowing-0.chals.kitctf.de 1337

Downloads: overflows-keep-flowing.tar.gzarrow-up-right

Analysis

Another ret2win challenge but with an argument of type long long int.

#include <stdio.h>
#include <stdlib.h>

// gcc -no-pie -fno-stack-protector -o overflows-keep-flowing overflows-keep-flowing.c

void shutoff(long long int arg1) {
	printf("Phew. Another accident prevented. Shutting off %lld\n", arg1);
	if (arg1 == 0xdeadbeefd3adc0de) {
		execve("/bin/sh", NULL, NULL);
	} else {
		exit(0);
	}
}

int main() {
	char buf[0xff]; // 255
	gets(buf);
	puts(buf);
	return 0;
}

-no-pie means that addresses will be the same when program is run, meaning remote application has same address. -fno-stack-protector basically allows buffer overflows to happen.

To overflow the buffer we need more then 255 characters, if RIP (x64 Instruction Pointer) is overwritten with address of our choice (shutdown) with the correct argument we can "win".

Let's find padding.

Note: clip directs output to clipboard alias clip="xclip -sel clip"

Now we need return address of shutoff

This can also be found with gdb gdb ./program -> info functions or radare2arrow-up-right r2 ./program -> aaa -> afl

We will also need a pop_rdi gadget to put param1 into register.

Solution

PS

I had trouble making the exploit work on remote, thisarrow-up-right reddit comment helped (by ebeip90arrow-up-right)

If you want to explore difference between x32 and x64 CryptoCatarrow-up-right has great video # 4: Ret2Win with Function Parametersarrow-up-right

Last updated