我正在开发一个基本的 shellcode,它将在 32 位程序中被调用后生成一个 shell。这是我正在使用的shellcode:
xor %eax,%eax
push %eax
push $0x68732f2f
push $0x6e69622f
mov %esp,%ebx
push %eax
push %ebx
mov %esp,%ecx
mov $0xb,%al
int $0x80
(来源:http : //shell-storm.org/shellcode/files/shellcode-827.php)
当我在被利用的程序中对其进行硬编码时,我成功地使用了这个 shellcode:
char *shellcode = "\x31[...]x80";
int main(void)
{
(*(void(*)()) shellcode)();
return 0;
}
但是当我尝试从标准输入读取 shellcode 时,我得到了一个分段错误。这是使用的程序:
#include [...]
typedef void (*func)(void);
int main(void)
{
char input[4096];
read(0, input, 4096);
((func)&input)();
return 0;
}
当我用 gdb 调试这个程序时,我可以看到一切都按计划进行,直到这条指令:
int $0x80
程序什么都不做,像什么都没发生一样继续下一条指令,这使程序崩溃。
起初我以为这是因为我没有禁用某些执行预防,但我正在使用以下标志进行编译:
gcc shell.c -o shell -fno-stack-protector -m32 -z execstack
我真的可以求助于它,我一整天都被困在它上面。