Metasploit框架提供了可讓你用于開發瀏覽器exploit的不同mixin,主要有[Msf::Exploit::Remote::HttpServer](https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-HttpServer), Msf::Exploit::Remote::HttpServer::HTML and [Msf::Exploit::Remote::BrowserExploitServer](https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-BrowserExploitServer). 這篇文章主要涵蓋HttpServer mixin.
HttpServer mixin是所有HTTP服務器 mixin的母親(像 BrowserExploitServer 和 HttpServer::HTML).要使用它,你的模塊需要有一個“on_request_uri”方法,這個方法是HTTP服務器收到來自瀏覽器的HTTP請求時觸發的回調。設置“on_request_uri”的例子:
```ruby
#
# Listens for a HTTP request.
# cli is the socket object, and request is a Rex::Proto::Http::Request object
#
def on_request_uri(cli, request)
print_status("Client requests URI: #{request.uri}")
end
```
“on_request_uri”方法也是您可以創建HTTP響應的地方。這里有幾個選擇可以用來做這一點:
* **send_not_found(cli)** - 發送404到客戶端。確保傳遞cli(套接字)對象。
* **send_redirect(cli, location='/', body='', headers={})** - 將客戶端重定向到一個新的位置。
* **send_response(cli, body, headers={})** - 向客戶端發送響應。這種方法可能是你大部分時間使用的方法。
如果你看過我們的一些exploit模塊,你也可以使用Exploit::Remote::HttpServer::HTML 代替 Exploit::Remote::HttpServer.用法大多相同,區別在于Exploit::Remote::HttpServer::HTML mixin可以讓你訪問一些Javascript函數,如Base64,heap spraying,OS detection,等。
以下是發送HTTP響應的示例:
```ruby
#
# Sends a "Hello, world!" to the client
#
def on_request_uri(cli, request)
html = "Hello, world!"
send_response(cli, html)
end
```
另請注意,為了處理HTTP請求,它必須包含基本的URIPATH,默認情況下是隨機的。這意味著如果你想處理多個URI(如果你需要處理重定向或鏈接的話可能),你還需要確保它們具有基本的URIPATH。要檢索基本的URIPATH,可以使用“get_resource”方法,下面是一個例子:
```ruby
def serve_page_1(cli)
html = "This is page 1"
send_response(cli, html)
end
def serve_page_2(cli)
html = "This is page 2"
send_response(cli, html)
end
def serve_default_page(cli)
html = %Q|
<html>
<a href="#{get_resource.chomp('/')}/page_1.html">Go to page 1</a><br>
<a href="#{get_resource.chomp('/')}/page_2.html">Go to page 2</a>
</html>
|
send_response(cli, html)
end
def on_request_uri(cli, request)
case request.uri
when /page_1\.html$/
serve_page_1(cli)
when /page_2\.html$/
serve_page_2(cli)
else
serve_default_page(cli)
end
end
```
當然,當你編寫Metasploit瀏覽器漏洞的時候,還有很多需要考慮的東西。例如,您的模塊可能需要執行瀏覽器檢測,因為允許Chrome瀏覽器接收IE漏洞是沒有意義的。您可能還需要構建特定于目標的負載,這意味著您的模塊需要知道它的目標是什么,并且必須構建一個方法來相應地定制漏洞利用等。HttpServer和HttpServer::HTML mixin提供各種方法讓你完成所有這些。確保查看API文檔(可以通過運行msf / documentation / gendocs.sh,或者只是在msf目錄中運行“yard”)或者檢查現有的代碼示例(特別是最近的代碼示例)。
為了使事情開始,您可以始終使用以下模板開始開發瀏覽器利用:
```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::HttpServer
def initialize(info={})
super(update_info(info,
'Name' => "HttpServer mixin example",
'Description' => %q{
Here's an example of using the HttpServer mixin
},
'License' => MSF_LICENSE,
'Author' => [ 'sinn3r' ],
'References' =>
[
[ 'URL', 'http://metasploit.com' ]
],
'Platform' => 'win',
'Targets' =>
[
[ 'Generic', {} ],
],
'DisclosureDate' => "Apr 1 2013",
'DefaultTarget' => 0))
end
def on_request_uri(cli, request)
html = "hello"
send_response(cli, html)
end
end
```
如果你想仔細看看mixin可以做什么,請看
https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/exploit/http/server.rb
- 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模塊