I wrote a small program in assembly which is supposed to print "AAAA". It works fine when I run it directly, but when I run it as a shellcode in a c program, it doesn't work. Please help.
When I compile and execute the following code:
char shellcode[] = {0x31,0xc0,0xb0,0x04,0x31,0xdb,0xb3,0x01,0x68,0x41,0x41,0x41,0x41,0x89,0xe1,0x31,0xd2,0xb2,0x04,0xcd,0x80,0x31,0xc0,0xb0,0x01,0x31,0xdb,0xb3,0x01,0xcd,0x80};
int main(){
(*(void(*)())shellcode)();
return 0;
}
Compiled as:
$gcc -g -Wall -fno-stack-protector -z execstack code.c -o code
Execution:
$./code
$