Source
#include <stdlib.h>
const unsigned char shellcode[] = "\xeb\x19\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0\x04" \
"\xb2\x0e\x59\xb3\x01\xcd\x80\x31\xc0\xb0\x01" \
"\x31\xdb\xcd\x80\xe8\xe2\xff\xff\xff" \
"\x48\x65 \x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c "\
" \x64\x21\x0a ";
int main (int argc, char **argv) {
int (*ret) ();
RET = (int (*) ()) Shellcode;
(int) (*ret) ();
Exit (0);
}
[ZHONGYUNDE@LINUX-HCC3 ~] $GCC DD.C
[Zhongyunde@linux-hcc3 ~]$./a.out
Segmentation fault
[ZHONGYUNDE@LINUX-HCC3 ~] $GCC dd.c-z execstack
[Zhongyunde@linux-hcc3 ~]$./a.out
Hello, world!.
Description: Shellcode here should be treated as a function (in memory have execute permission) bar, have their own stack
1 link must indicate the executable stack, that is, option-Z execstack
2 Shellcode data type must be added const, because a const will be placed into the text section
See: Http://stackoverflow.com/questions/1576489/where-are-constant-variables-stored-in-c