b3_python interact with metasploit(msf)

python interact with Metasploit


艾玛

参考资料

需要安装msgpack python模块,因为后面使用到的msfrpc模块依赖于这个模块,这两个模块的安装都可以使用源码安装的方式,因为pip install的方式如果失败的话。

Introduction
This repository contains two modules for communicating with Metasploit’s MSGRPC Server. The followign modules are separated by language:

  • Net-MSFRPC - Perl Metasploit MSGRPC module
  • python-msfrpc - Python Metasploit MSGRPC module

Each of these modules contains their own README files. These README
files contain instructions for building and using each of the types
of modules.

该链接包括两个模块,一个是perl语言实现的,一个是python语言实现的
进入解压缩目录,

python setup.py install

python的pymsf模块可以实现‘python 与 Metasploit’s msgrpc’进行交互。

step 1:

$ msfconsole 
$ load msgrpc Pass=<password>

与msgrpc交互就像与msfconsole交互一样。

  1. 首先,你创建一个msfrpc的类实例,利用这个实例登陆msgrpc服务端(运行在msfconsole中)
  2. 创建一个虚拟的的console(控制台)

而我们考虑的实现思路是:可以通过这边创建一个虚拟的console,
然后将每个漏洞提前写好’.rc’文件,然后在msf里面加载执行这些rc文件

验证方式:
可以将靶机预先提供两个以上的漏洞,并准备好这些漏洞的配置脚本,只需要在执行时加载即可

在实现这个思路之前,我们需要先补充学习:

  • metasploit_ResourceScript.md
  • metasploit_RPC编程

关于其他方案实现 python+metasploit与评注

参考链接

这个方案是通过在启动msfconsole时加载配置文件实现的,操作相对于RPC是很不灵活的,同时我们如何获取msf控制台的输出信息呢?如何得到当前的sessions列表呢?这都是使用这个方式后,需要解决的问题。
因此,我们选择:msf + python + RPC + resource-script + ruby,也就是前面提到的实现思路。

  • 对于每个漏洞的配置文件(.rc文件)我们只写一个,而嵌入ruby语言,使得一个.rc文件可以应对多个hosts
  • 对与控制权,如果只使用os.system的方式发送命令以加载.rc文件的方式启动msf,那么随后的控制权就不在python里面,而使用RPC可以保持这种控制。
  • 我们使用一个脚本用于启动msf完成初始配置,并开启msgrpc服务,使用另一个脚本完成我们的主要攻击操作

参考资料:

在使用RPC时client.call(‘console.read’,[msfcon_id])数据读取问题

一直读取不到console控制台写入命令后的数据,只读取到一开始的控制台打印页数据  
可能的问题:
指令结尾要加'\n'换行符

猜你喜欢

转载自blog.csdn.net/yeshankuangrenaaaaa/article/details/85994275