1. 程式人生 > >b3_python interact with metasploit(msf)

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'換行符