Malleable-C2-Profiles配置

摘要:
关于Malleable-C2-Profiles,我们需要在日常渗透测试工作中进行大量规避操作。因为我们使用的C2工具可能已经被AV和其他保护软件标记,所以我们需要定制我们的攻击工具。这导致了我们今天的重点,Malleable C2,它是CobaltSteke的一个功能,意味着“可定制”的C2服务器MalleableC2允许我们在通过简单的配置文件与C2通信时更改Beacon的流量特性和行为。

唔,水文水文….

关于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="http://t.zoukankan.com/search?format=rss&amp;q=canary&amp;go=Search&amp;qs=bs&amp;form=QBRE" rel="alternate" title="XML" type="text/xml" /><link href="http://t.zoukankan.com/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="http://t.zoukankan.com/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="http://t.zoukankan.com/search?format=rss&amp;q=canary&amp;go=Search&amp;qs=bs&amp;form=QBRE" rel="alternate" title="XML" type="text/xml" /><link href="http://t.zoukankan.com/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="http://t.zoukankan.com/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 "xcdx11x8fxf8x89x70xe1xabx89x70xe1xabx89x70xe1xabx3dxecx10xabx9cx70xe1xabx3dxecx12xabx0ax70xe1xabx3dxecx13xabx90x70xe1xabxeax2dxe2xaax9bx70xe1xabxeax2dxe4xaaxaex70xe1xabxeax2dxe5xaax9bx70xe1xabx80x08x72xabx82x70xe1xabx89x70xe0xabx03x70xe1xabxe7x2dxe4xaax80x70xe1xabxe7x2dx1exabx88x70xe1xabx89x70x76xabx88x70xe1xabxe7x2dxe3xaax88x70xe1xabx52x69x63x68x89x70xe1xabx00x00x00x00x00x00x00x00";
}

### 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

免责声明:文章转载自《Malleable-C2-Profiles配置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇小程序对mongodb日期显示处理问题Linux添加用户组和删除用户组下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

base64的编码解码的一些坑

1、 //编码 value = base64encode(utf16to8(src)) //解码 value = utf8to16(base64decode(src))这里:base64编码之前先转成utf8,解码出来的也要从utf-8转为utf-16 2、base64编码分为字符串编码成字符串,字符串编码成数组,字符串解码成数组,字符串解码成字符串,等...

CentOS7 监控网络流量

首先,以下介绍的流量监控工具安装之前均需要安装epel源, 安装epel源: [root@bogon ~]# yum -y install epel-release 安装 iftop 工具,查看各个连接的流量情况 [root@bogon ~]# yum -y install iftop [root@bogon ~]# iftop -i ens33 -n -...

记一次阿里云负载测试

环境: 服务器:主服务器A,备服务器B(主服务器配置和带宽都大于备服务器器) 业务:tomcat 端口:443,80 协议:https 域名:www.danny.com 证书:ssl证书,域名绑定了ssl证书并都配置安装在AB服务器中 要求:主要使用A服务器跑业务,B服务器只有在A服务器不可用时才接受访问流量 阿里云负载均衡后台转发服务器组选择: 1.后端...

微服务最强开源流量网关Kong

前言在微服务架构中,由于系统和服务的细分,导致系统结构变得非常复杂, 为了跨平台,为了统一集中管理api,同时为了不暴露后置服务。甚至有时候需要对请求进行一些安全、负载均衡、限流、熔断、灰度等中间操作,基于此类种种的客观需求一个类似综合前置的系统就产生了,这就是API网关(API Gateway)。API网关作为分散在各个业务系统微服务的API聚合点和统一...

网络流(二)最大流的增广路算法

传送门:网络流(一)基础知识篇网络流(二)最大流的增广路算法网络流(三)最大流最小割定理网络流(四)dinic算法网络流(五)有上下限的最大流网络流(六)最小费用最大流问题转载:https://www.cnblogs.com/ZJUT-jiangnan/p/3632525.html 网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出...

阿里云、腾讯云、七牛、网易云CDN简单对比

阿里云、腾讯云、七牛、网易云简单对比如下, 仅做参考: 1、产品功能 产品功能 阿里云视频 腾讯云视频 七牛直播云 网易云视频 服务 直播 点播 转码 互动直播 直播 点播 转码 互动直播 直播 点播 直播、点播、互动直播、互动白板 推流SDK Android/iOS/windows Android/iOS/windows Android/iO...