Metasploit框架提供了可讓你用于開發瀏覽器exploit的不同mixin,主要有:
* **[Msf::Exploit::Remote::HttpServer](https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-HttpServer)** - 一個最基本的http服務器
* **Msf::Exploit::Remote::HttpServer::HTML** - 這個模塊提供JavaScript函數在制作不同的html內容時能使用
* **[Msf::Exploit::Remote::BrowserExploitServer](https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-BrowserExploitServer)** - 包括來自HttpServer和HttpServer :: HTML的功能,但還有更多的好東西。這篇文章涵蓋了 [BrowserExploitServer](https://rapid7.github.io/metasploit-framework/Msf/Exploit/Remote/BrowserExploitServer.html) mixin.
### 自動開發程序
BrowserExploitServer mixin是唯一專門為瀏覽器開發的mixin。在使用這個mixin之前,你應該明白它在背后的作用:
1.它會自動收集瀏覽器信息,包括:操作系統名稱,版本,瀏覽器名稱,瀏覽器版本,是否使用代理,Java插件版本,Microsoft Office版本等。如果瀏覽器沒有啟用Javascript,那么它對目標知道的很少。收集的所有信息將存儲在由mixin管理的配置文件中。
2.然后mixin會標記瀏覽器來跟蹤會話。它也將使用相同的標簽來檢索需要的配置文件。
3.在mixin決定是否應該向瀏覽器使用exploit之前,它會檢查模塊是否有任何可exploit的條件。如果不符合條件,則會向瀏覽器發送一個404,放棄操作
4.如果滿足要求,mixin會將該配置文件(在檢測階段收集的瀏覽器信息)傳遞給模塊,然后讓其接管其余部分。
提示:在模塊中,您可以檢查配置文件中的`:source`鍵以確定是否啟用Javascript:如果:source是“script”,則意味著啟用了Javascript。如果是“headers”(如HTTP標頭),那么瀏覽器禁用Javascript。
### 設置可exploit要求
能夠設置瀏覽器的要求是mixin的一個重要特性。它可以讓你的攻擊更聰明,更有針對性,并防止事故發生。這里有一個場景:假設你有一個針對Internet Explorer的漏洞,它只影響特定范圍的MSHTML構建,你可以設置:os_name, :ua_name, :ua_ver, and :mshtml_build 來確保它不會盲目的exploit其他東西.:mshtml_build要求可以在MSHTML文件屬性下的“產品版本”中找到。
可利用的瀏覽器要求在模塊元數據的“BrowserRequirements”下定義。以下是定義運行某個ActiveX控件的易受攻擊目標的示例:
```ruby
'BrowserRequirements' =>
{
source: /script/i,
activex: [
{
clsid: '{D27CDB6E-AE6D-11cf-96B8-444553540000}',
method: 'LoadMovie'
}
],
os_name: /win/i
}
```
您也可以定義目標特定的要求。這也是mixin能夠自動選擇一個目標的方式,你可以用“get_target”方法得到它。下面是一個例子,說明如何定義目標特定的要求,在Win XP上的IE8,在Win 7上的IE 9 :
```ruby
'BrowserRequirements' =>
{
:source => /script|headers/i,
'ua_name' => HttpClients::IE,
},
'Targets' =>
[
[ 'Automatic', {} ],
[
'Windows XP with IE 8',
{
:os_name => 'Windows XP',
'ua_ver' => '8.0',
'Rop' => true,
'Offset' => 0x100
}
],
[
'Windows 7 with IE 9',
{
'os_name' => 'Windows 7',
'ua_ver' => '9.0',
'Rop' => true,
'Offset' => 0x200
}
]
]
```
你可以使用這些 **:os_name**:
| Constant | Purpose |
| -------- | ----- |
| OperatingSystems::Match::WINDOWS | Match all versions of Windows |
| OperatingSystems::Match::WINDOWS_95 | Match Windows 95 |
| OperatingSystems::Match::WINDOWS_98 | Match Windows 98 |
| OperatingSystems::Match::WINDOWS_ME | Match Windows ME |
| OperatingSystems::Match::WINDOWS_NT3 | Match Windows NT 3 |
| OperatingSystems::Match::WINDOWS_NT4 | Match Windows NT 4 |
| OperatingSystems::Match::WINDOWS_2000 | Match Windows 2000 |
| OperatingSystems::Match::WINDOWS_XP | Match Windows XP |
| OperatingSystems::Match::WINDOWS_2003 | Match Windows Server 2003 |
| OperatingSystems::Match::WINDOWS_VISTA | Match Windows Vista |
| OperatingSystems::Match::WINDOWS_2008 | Match Windows Server 2008 |
| OperatingSystems::Match::WINDOWS_7 | Match Windows 7 |
| OperatingSystems::Match::WINDOWS_2012 | Match Windows 2012 |
| OperatingSystems::Match::WINDOWS_8 | Match Windows 8 |
| OperatingSystems::Match::WINDOWS_81 | Match Windows 8.1 |
| OperatingSystems::Match::LINUX | Match a Linux distro |
| OperatingSystems::Match::MAC_OSX | Match Mac OSX |
| OperatingSystems::Match::FREEBSD | Match FreeBSD |
| OperatingSystems::Match::NETBSD | Match NetBSD |
| OperatingSystems::Match::OPENBSD | Match OpenBSD |
| OperatingSystems::Match::VMWARE | Match VMWare |
| OperatingSystems::Match::ANDROID | Match Android |
| OperatingSystems::Match::APPLE_IOS | Match Apple IOS |
你能使用這些 **:ua_name**:
| Constant | Value |
| -------- | ----- |
| HttpClients::IE | "MSIE" |
| HttpClients::FF | "Firefox" |
| HttpClients::SAFARI | "Safari" |
| HttpClients::OPERA | "Opera" |
| HttpClients::CHROME | "Chrome" |
更多這些常量可以在這里找到:https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/constants.rb
全部現在mixin支持的要求可以在這找到(查看 REQUIREMENT_KEY_SET))
https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/exploit/remote/browser_exploit_server.rb#L46
### 設置一個監聽器
在檢測階段和需求檢查之后,mixin將觸發“on_request_exploit”回調方法,這就是您處理HTTP請求,制作HTML并返回漏洞響應的地方。這里是一個如何設置“on_request_exploit”的例子:
```ruby
#
# Listens for the HTTP request
# cli is the socket
# request is the Rex::Proto::Http::Request object
# target_info is a hash that contains all the browser info (aka the profile)
#
def on_request_exploit(cli, request, target_info)
print_status("Here's what I know about the target: #{target_info.inspect}")
end
```
### 使用BrowserExploitServer構建HTML
BrowserExploitServer mixin支持兩種編碼風格:好的舊的HTML或[ERB](http://ruby-doc.org/stdlib-2.1.3/libdoc/erb/rdoc/ERB.html)模板。首先是不言自明的:
```ruby
def on_request_exploit(cli, request, target_info)
html = %Q|
<html>
Hello, world!
</html>
|
send_exploit_html(cli, html)
end
```
[ERB](http://ruby-doc.org/stdlib-2.1.3/libdoc/erb/rdoc/ERB.html) 是一種編寫Metasploit瀏覽器漏洞的新方法。如果你已經寫了一個或兩個Web應用程序,這對你來說并不陌生。當您使用BrowserExploitServer mixin編寫漏洞利用程序時,真正發生的是您正在編寫一個rails模板。以下是使用此功能的示例:
```ruby
def on_request_exploit(cli, request, target_info)
html = %Q|
<html>
Do you feel lucky, punk?<br>
<% if [true, false].sample %>
Lucky!<br>
<% else %>
Bad luck, bro!<Br>
<% end %>
</html>
|
send_exploit_html(cli, html)
end
```
如果要訪問局部變量或參數,請確保將綁定對象傳遞給send_exploit_html:
```ruby
def exploit_template1(target_info, txt)
txt2 = "I can use local vars!"
template = %Q|
<% msg = "This page is generated by an exploit" %>
<%=msg%><br>
<%=txt%><br>
<%=txt2%><br>
<p></p>
Data gathered from source: #{target_info[:source]}<br>
OS name: #{target_info[:os_name]}<br>
UA name: #{target_info[:ua_name]}<br>
UA version: #{target_info[:ua_ver]}<br>
Java version: #{target_info[:java]}<br>
Office version: #{target_info[:office]}
|
return template, binding()
end
def on_request_exploit(cli, request, target_info)
send_exploit_html(cli, exploit_template(target_info, txt))
end
```
BrowserExploitServer mixin在制作exploit的同時還提供了許多其他有用的東西。例如:當您調用“get_payload”方法時,它可以生成特定于目標的有效內容。它還使您可以訪問RopDb mixin,其中包含一組ROP以繞過DEP(數據執行保護)。請務必查看API文檔以獲取更多信息。
為了得到一個開始,下面是一個可以使用的代碼示例,開始開發瀏覽器漏洞:
```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::BrowserExploitServer
def initialize(info={})
super(update_info(info,
'Name' => "BrowserExploitServer Example",
'Description' => %q{
This is an example of building a browser exploit using the BrowserExploitServer mixin
},
'License' => MSF_LICENSE,
'Author' => [ 'sinn3r' ],
'References' =>
[
[ 'URL', 'http://metasploit.com' ]
],
'Platform' => 'win',
'BrowserRequirements' =>
{
:source => /script|headers/i,
},
'Targets' =>
[
[ 'Automatic', {} ],
[
'Windows XP with IE 8',
{
'os_name' => 'Windows XP',
'ua_name' => 'MSIE',
'ua_ver' => '8.0'
}
],
[
'Windows 7 with IE 9',
{
'os_name' => 'Windows 7',
'ua_name' => 'MSIE',
'ua_ver' => '9.0'
}
]
],
'Payload' => { 'BadChars' => "\x00" },
'DisclosureDate' => "Apr 1 2013",
'DefaultTarget' => 0))
end
def exploit_template(target_info)
template = %Q|
Data source: <%=target_info[:source]%><br>
OS name: <%=target_info[:os_name]%><br>
UA name: <%=target_info[:ua_name]%><br>
UA version: <%=target_info[:ua_ver]%><br>
Java version: <%=target_info[:java]%><br>
Office version: <%=target_info[:office]%>
|
return template, binding()
end
def on_request_exploit(cli, request, target_info)
send_exploit_html(cli, exploit_template(target_info))
end
end
```
### JavaScript 混淆
BrowserExploitServer依靠JSObfu mixin來支持JavaScript混淆。在編寫JavaScript時,應該總是這樣寫:
```ruby
js = js_obfuscate(your_code)
```
該#js_obfuscate會返回一個Rex::Exploitation::JSObfu對象。要獲得混淆的JavaScript,請調用以下#to_s方法:
```ruby
js.to_s
```
如果您需要訪問混淆的符號名稱,則可以使用#sym方法
```ruby
# Get the obfuscated version of function name test()
var_name = js.sym('test')
```
請注意,即使您的模塊正在調用#js_obfuscate方法,默認情況下,除非用戶設置JsObfuscate數據存儲選項,否則混淆不會啟動。此選項是一個OptInt,它允許您設置混淆次數(默認值為0)。
```ruby
deregister_options('JsObfuscate')
```
如果您的基于BES的攻擊根本不需要混淆,請務必調用#deregister_options并移除JsObfuscate選項。像這樣:
```ruby
deregister_options('JsObfuscate')
```
要了解有關Metasploit的JavaScript混淆功能的更多信息,請閱讀[How to obfuscate JavaScript in Metasploit](https://github.com/rapid7/metasploit-framework/wiki/How-to-obfuscate-JavaScript-in-Metasploit).
### 相關文章
* https://github.com/rapid7/metasploit-framework/wiki/How-to-write-a-browser-exploit-using-HttpServer
* https://github.com/rapid7/metasploit-framework/wiki/Information-About-Unmet-Browser-Exploit-Requirements
- 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模塊