Raiel
Raiel

Reputation: 21

Exercise about stack overflow

I'm trying to learn stack overflows but I have a problem with an exercise. In the vulnerable program the part of the code that must receive my shellcode is:

 int array[8];
 index = (int) strtol(argv[1], NULL, 10);
 value = (int) strtoul(argv[2], NULL, 16);
 array[index] = value;

I found easily the index of the array to use to overwrite RET. Then I tried to find the offset of the return address in the vulnerable program like this:

./victim 12 $(printf "%0512x" 0)

I tried a lot of different lengths, but at every possible length I get a segmentation fault. This is weird, because my book says that I should be able to get a segmentation fault only where the saved return address is. I'm a beginner, so probably I'm doing some basic mistake. Can anyone help me to solve this problem? Thanks in advance for any help.

Upvotes: 2

Views: 953

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272687

You are getting a segmentation fault because you're only providing your program with a single argument, but yet you're calling strtoul on argv[2], which is a NULL pointer.

Upvotes: 1

Related Questions