I am experimenting with shellcode before digging deep into it so I came across an example from the shellcoders handbook. The example is the following:
char shellcode[] = "\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x4
\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1\xff\xff\xff\x2f\x62\x69
\x6e\x2f\x73\x68";
int main() {
int *ret;
ret = (int *)&ret + 2;
(*ret) = (int)shellcode;
}
the shellcode is supposed to spawn a shell. However I get a segmentation fault error.
I compiled the program using gcc compiler with -fno-stack-protector and -z execstack options. I took a quick look at the readelf command and it was clear that the stack is executable
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4