使用內存特征檢測 Cobalt Strike
Beacon 通常是反射加載到內存中,還可以配置各種內存中混淆選項以隱藏其有效負載。
Beacon 可以配置各種內存中混淆選項以隱藏其有效負載。例如,obfuscate-and-sleep 選項會試圖在回調之間屏蔽部分 Beacon 有效負載,以專門避開基于特征的內存掃描。
Obfuscate and Sleep是一個Malleable C2選項,在Cobalt Strike 3.12.引入。啟用后,Beacon將在進入Sleep狀態之前在內存中混淆自身。
那么我們先使用默認的關閉Obfuscate and Sleep來查看CobaltStrike進行進程注入會的具體情況。

然后我們把進程注入到微信中。


注入微信進程

正常執行命令

然后我們在目標主機中使用Process Hacker 2進行檢測查看:

查找調用 SleepEx 的線程來定位內存中的 Beacon,一般在比較活躍的之中。

然后,我們可以將關聯的內存區域進行分析,轉到Memory查看分析這個偏移量。

我們可以對比看一下Beacon的情況:

轉到Memory查看分析這個偏移量并對比一下:

可以看到我們可以看到我們的整個beacon在內存中未加密。
檢測這樣沒有加密的beacon不難,我們在最簡單的做法是,從這個區域挑選一些獨特的字符串并將它們用作我們的檢測的特征就行。

rule cobaltstrike_beacon_strings{meta: author ="Elastic"description ="Identifies strings used in Cobalt Strike Beacon DLL."strings: $a = {70 6F 77 65 72 73 68 65 6C 6C 20 2D 6E 6F 70 20 2D 65 78 65 63 20 62 79 70 61 73 73 20 2D 45 6E 63 6F 64 65 64 43 6F 6D 6D 61 6E 64 20 22 25 73}condition: any of them }
當然上面的我只是舉個例子,在實戰中還得細一點。

國外也有個安全研究人員給出了個yar
rule cobaltstrike_beacon_strings{meta: author = "Elastic" description = "Identifies strings used in Cobalt Strike Beacon DLL."strings: $a = "%02d/%02d/%02d %02d:%02d:%02d" $b = "Started service %s on %s" $c = "%s as %s\\%s: %d"condition: 2 of the }
同時Cobalt Strike給出了一種Bypass方法
# Obfuscate Beacon, in-memory, prior to sleepingset sleep_mask "true";

Set sleep_mask “true”; 設置使beacon在睡眠之前混淆內存中的代碼,睡眠后對自己進行混淆處理

可以看到在混淆內存中的代碼,然后我們使用前面的規則并不能檢測到了beacon

其實如果你刷新幾次也可以發現解密的beacon,因為在每次使用beacon,都會重新加密數據和字符串。

那么我們也可以多檢測幾次也可以檢測到:

因為我現在使用的4.3的Cobalt Strike,使用 13 字節的 XOR 密鑰,

如果是4.2以下Cobalt strike 使用的是使用簡單的單字節 XOR 混淆,使用下面的yar一樣可以檢測:
rule cobaltstrike_beacon_xor_strings{meta: author = "Elastic" description = "Identifies XOR'd strings used in Cobalt Strike Beacon DLL."strings: $a = "%02d/%02d/%02d %02d:%02d:%02d" xor(0x01-0xff) $b = "Started service %s on %s" xor(0x01-0xff) $c = "%s as %s\\%s: %d" xor(0x01-0xff)condition: 2 of them}