Modifying return values
Posted: Sat Feb 28, 2004 5:31 pm
I was reading the article "Smashing the Stack for Fun and Profit" from Phrack 49 and was trying to get one buffer overflow example gave to work.
I'm trying to jump paste the x = 1 assignment. He worked on Linux but I'm on FreeBSD and things are different.
Code: Select all
void function(void) {
char buffer1[5];
char buffer2[10];
int *ret;
ret = buffer1 + 12;
(*ret) += 8;
}
int main(void) {
int x;
x = 0;
function();
x = 1;
printf("%d\n",x);
}
Code: Select all
(gdb) disassemble main
Dump of assembler code for function main:
0x8048504 <main>: push %ebp
0x8048505 <main+1>: mov %esp,%ebp
0x8048507 <main+3>: sub $0x8,%esp
0x804850a <main+6>: and $0xfffffff0,%esp
0x804850d <main+9>: mov $0x0,%eax
0x8048512 <main+14>: sub %eax,%esp
0x8048514 <main+16>: movl $0x0,0xfffffffc(%ebp)
0x804851b <main+23>: call 0x80484e4 <function>
0x8048520 <main+28>: movl $0x1,0xfffffffc(%ebp)
0x8048527 <main+35>: sub $0x8,%esp
0x804852a <main+38>: pushl 0xfffffffc(%ebp)
0x804852d <main+41>: push $0x80485c8
0x8048532 <main+46>: call 0x8048360 <printf>
0x8048537 <main+51>: add $0x10,%esp
0x804853a <main+54>: leave
0x804853b <main+55>: ret
0x804853c <main+56>: nop
0x804853d <main+57>: nop
0x804853e <main+58>: nop
0x804853f <main+59>: nop
End of assembler dump.