Cobalt Strike从入门到精通之定制配置文件进行高级攻击

在线视频地址

Cobalt Strike的配置文件讲解

简介

Beacon是Cobalt Strike为高级攻击者建模的Payload。使用Beacon通过HTTP,HTTPS或DNS出口网络。而且Beacon非常灵活,支持异步和交互式通信。异步通信既低又慢。Beacon将通讯本地,下载任务,然后进入睡眠状态。交互式通信实时发生。

cobalt Strike 的Beacon(信标)的一些Http特征信息可以由C2配置文件进行修改和定制化,所以可定制的C2配置文件可以指定服务端如何发送,接受数据的规律和格式,防止被WAF,IDS对流量进行识别导致被发现。

可以在启动cs服务端的时候,指定一个配置文件进行加载

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

配置文件详解

检查配置文件

cobalt Strike提供了一个小程序C2lint,用来检查你编写的配置文件是否是可用的,是否有错误,这个程序会检查你的语法是否正确,并且会生成一个简单的交互过程让你预览,cobalt Strike强烈推荐你在正式使用之前用这个小程序来检查一下。

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

编写配置文件

编写一个配置文件最好的方式就是根据现有的配置文件进行修改,现在提供一个github上面的C2-Profiles例子:

https://github.com/rsmudge/Malleable-C2-Profiles

可以看到配置文件大概长这样:

set global_option "value";

protocol-transaction {
	set local_option "value";

	client {
		# customize client indicators
	}

	server {
		# customize server indicators
	}
}

所有的配置信息都是写在{}大括号里面。

例如:


http-get {
        set uri "/fengxuan";
        client {
                metadata {
                        base64;
                        prepend "user=";
                        header "Cookie";
                }
        }
}

这个配置定义了在HTTP协议中Get请求的传输,第一句set uri, 表示,在当请求/fengxuan这个URL的时候,会执行以下的配置。

那么整段配置是什么意思呢?

就是在请求/fengxuan 这个地址的时候,http header中的 user字段里面的内容会进行base64加密然后再进行传输,从这个地址接受的返回包,http header中的 user字段会进行base64解密。

数据传输的标记语法

Statement Action Inverse
append "string" 追加"string"参数 去除strings参数的字符串
base64 Base64 编码 Base64 解码
base64url 对url进行Base64 编码 对url进行Base64 解码
mask XOR mask w/ random key XOR mask w/ same random key
netbios NetBIOS 编码 NetBIOS 解码
netbiosu NetBIOS 编码(大写) NetBIOS 解码(大写)
prepend "string" 添加"string"参数 去除strings参数的字符串

对标记语法处理的四种方式

Statement What
header "header" 把编码过后的参数作用于header中
parameter "key" 把编码过后的参数作用于URL参数中
print 把编码过后的参数作用于POST方式中的body中
uri-append 将编码过后的参数追加到URL中

其他的选项

Option Context Default Value Changes
data_jitter 0 向http get和http post服务器输出中附加随机长度字符串(取决于data_jitter的值)。
dns_idle 0.0.0.0 用于采用DNS信标时的ip地址
dns_max_txt 252 最大的 DNS TXT 返回的长度
dns_sleep 0 在每个dns请求之前的休眠时间. (毫秒值)
dns_stager_prepend Prepend text to payload stage delivered to DNS TXT record stager
dns_stager_subhost .stage.123456. DNS TXT记录阶段使用的子域名。
dns_ttl 1 DNS的TTL值
headers_remove 在客户端请求中去掉的header值
host_stage true Host payload for staging over HTTP, HTTPS, or DNS. Required by stagers.
jitter 0 默认增加的随机值的比例(0-99%)
maxdns 255 上传数据时最大的DNS主机名
pipename msagent_## 使用SMB信标时点对点的名称
pipename_stager status_## Name of pipe to use for SMB Beacon's named pipe stager. Each # is replaced with a random hex value.
sample_name My Profile The name of this profile (used in the Indicators of Compromise report)
sleeptime 60000 默认休眠时间(毫秒值)
smb_frame_header Prepend header to SMB Beacon messages
ssh_banner Cobalt Strike 4.2 SSH client banner
ssh_pipename postex_ssh_#### Name of pipe for SSH sessions. Each # is replaced with a random hex value.
tcp_frame_header Prepend header to TCP Beacon messages
tcp_port 4444 TCP Beacon listen port
uri http-get, http-post [required option] 交互时候的URI地址
uri_x86 http-stager x86 payload stage URI
uri_x64 http-stager x64 payload stage URI
useragent Internet Explorer (Random) 默认的User-Agent
verb http-get, http-post GET, POST 传输的请求协议

编写好的配置文件模板

#
# Etumbot Profile
#   http://www.arbornetworks.com/asert/2014/06/illuminating-the-etumbot-apt-backdoor/
#
# Author: @harmj0y
#
set sample_name "Etumbot";

set sleeptime "5000";
set jitter    "0";
set maxdns    "255";
set useragent "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0)";

http-get {

    set uri "/image/";

    client {

        header "Accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*l;q=0.8";
        header "Referer" "http://www.google.com";
        header "Pragma" "no-cache";
        header "Cache-Control" "no-cache";

        metadata {
            netbios;
            append "-.jpg";
            uri-append;
        }
    }

    server {

        header "Content-Type" "img/jpg";
        header "Server" "Microsoft-IIS/6.0";
        header "X-Powered-By" "ASP.NET";

        output {
            base64;
            print;
        }
    }
}

http-post {
    set uri "/history/";

    client {

        header "Content-Type" "application/octet-stream";
        header "Referer" "http://www.google.com";
        header "Pragma" "no-cache";
        header "Cache-Control" "no-cache";

        id {
            netbiosu;
            append ".asp";
            uri-append;
        }

        output {
            base64;
            print;
        }
    }

    server {

        header "Content-Type" "img/jpg";
        header "Server" "Microsoft-IIS/6.0";
        header "X-Powered-By" "ASP.NET";

        output {
            base64;
            print;
        }
    }
}

c2lint检查

这个过程可以检查并且预览交互过程

注意:有些警告,这个警告有时候会影响运行,不过大多数都不会。

实战

启动服务进行攻击

启动服务并且加载我们的配置文件

获取权限

WireShark分析流量

分析get流量

分析post流量

总结

cobalt strike 的配置文件可以进行高级定制化的攻击,有效防止WAF,和IDS的追查。可以达到长期的维持访问,在APT攻击中还是比较重要的。

如果图文看不懂可以看视频

posted @ 2021-02-22 17:14  风炫安全  阅读(854)  评论(0编辑  收藏  举报