CS官方教程的学习笔记,目前进度到Weaponization。
CobaltStrike 学习笔记
1、Operations
操作
- /sc // show channel
- neo: xxxxxxx //对neo说话
- /msg neo xxxx //给neo发私信
思路
- 多个teamserver各司其职:- staginig
- post-ex
- longhaul
 
- 红队单元- AccessManagementCell
- TargetCell
 
- 团队角色- Access- Get in and expand foothold
 
- Post Exploitation- Data mining,monitor users,key log,etc.
 
- Local Access Manager- Manage Callbacks
- Setup Infrastructure
- Persistence
- Pass sessions to and from global access manager
 
 
- Access
2、Infrastructure
概念
三种payload
- egress //出网口payload
- p2p //通过父payload通信
- alias //对其它payload handler的引用
也就是说,只要egress Beacon可以出网,p2p Beacon可以通过egress Beacon和teamserver通信
Payload Staging
- Stageless - 稳定
 
- Stager - 体积小、适用于资源有限的情况
- 较不安全
- 不稳定
- 更容易被AV发现
 
名词
- Payload controller- MSF
- CS //兼容MSF
 
- Staging protocal- http
- https
- 其它
 
过程
- Stager向Paylod controller发送http/https GET请求,并且URI的cheksum是一个固定值。
- Payload controller校验请求后,响应一个位置独立的blob,在父程序内存中运行- MSF:meterpreter payload
- CS:beacon payload
 
- CS exp可以下载meterpreter payload,meterpreter exp也可以下载beacon payload
payload的行为
- 间隔固定时间给teamserver发get请求,获取指令。
- 如果有指令,发送加密的指令。
- 如果是生成报告的指令,需要发送数据到teamserver,beacon会发送一个带有加密数据的post请求到。
- 以上只是默认设置,可以自己进行配置。
生成HTTPBeacon的参数
- HTTP Hosts //home,域名,ip,ipv6都可以
- HTTP Hosts(Stager) //Stager hosts(参考前面多个teamserver的思路)
- HTTP Port(C2) //beacon发请求的端口
- HTTP Proxy //beacon用的代理,甚至可以让beacon不用系统代理
HTTPS Beacon
- 可以通过malleable C2 Profile配置一个可用的SSL 证书(非常推荐看下面的文档)
Redirectors
- 可以迷惑对手,也可以负载均衡 
- 可以用iptables,socat,apache或nginx反向代理,amazon cloudflare或者其他流量转发工具 - socat TCP4-LISTEN:80,fork TCP4:[team server]:80
 
思路
- 用Redirector作为beacon的home host,和stager host
- 用CDN作为redirector(绝了,真没想到- -)
操作
用Socat作为转发器
- 操作见教程,比较简单实用
- 实用screen,退出ssh的时候不会退出socat
用CDN作为转发器
- 注意 - 需要用有效的SSL证书
- 启用POST、GET
- 如果出现问题,可以在mellable C2 Profile改为 HTTP-GET only C2,即用GET请求回传数据
- 关闭CDN的缓存功能
- 注意有些CDN会修改请求,比如cloud front会改cookie里面的值的顺序,如果我们设置用cookie回传数据,就会出现问题。
 
- 域前置 domain fronting //太6了- -,不过好像一些CDN已经开始避免这种现象 - 大概就是beacon请求a.com,HOST头写成b.com(CDN同时为a.com和b.com提供服务)
- 查DNS的时候查的是a.com,然后请求发到CDN
- CDN收到http请求,会根据HOST头去请求b.com
- 防御方法就是检查URL和HOST,然后把HOST头改成URL里面的域
- 所以绕过防御的方法,就是用https(虽然CDN是MITM,也可以防御。但有个思路是,有些行业是不希望有MITM的,可以尝试)
- 还有一种防御方式,用SNI.也就是https在ssl层会提供的一个东西。
 - Server Consolidation- HTTP Port(Bind)- beacon的http请求先发到redirector的HTTP Port(C2)端口,再被转发到teamserver的HTTP Port(Bind)端口
 
 
DNS Beacon
- 三种Channel- dns- A record (4 bytes/request)
 
- dns6- AAAA record (16 bytes/request)
 
- dns-txt- TXT record (189 bytes/request)
 
 
- dns
- 有些dns服务器会拒绝超长的域名查询,所以DNS Beacon作为备选的尝试
SMB Beacon
- named pip beacon 
- 在windows上使用命名管道的时候,消息会自动封装在SMB协议中(445端口),所以叫SMB Beacon 
- 可以通过 link [host name] [pip],unlink [host] [pid]来主动连接,断开 
TCP Beacon
- 和SMB Beacon类似
External C2
- 自己写程序,从beacon 获取数据,然后发给teamserver,反之亦然,其中可以自己进行处理。这个程序可以写多个,只要最终达成beacon和teamserver的通信就可以。
- 可以通过这个功能适配一些特殊环境- 比如可以通过与另一台电脑上的文件共享,来读写信息.
- 另一种用法
 
3、C2
Malleable C2
修改各种配置,包括
- Network traffic
- In-memory content,characteristics,and behavior
- Process injection behavior
Profile Components
- Options - set key “value”- value 要用双引号
 
 
- set key “value”
- Blocks - http-get{ indicators here }- download tasks
 
- http-post{  indicators here }- upload outputs
 
- http-stager{ indicators here }
 
- http-get{ indicators here }
- Extraneous Indicators 
- Transforms - 自定义如何处理,自定义如何传输(放在uri,post体,header等),作者称之为基于用户定义和储存的加密通信 
- 主要有以下几个部分 - http-get- Client:metadata
- Server:output
 
- http-post- Client:id,output
 
- http-stager
- http-config
- https-certificate
- stage
- post-ex
- process-inject
- code-signer
 
- http-get
 
Chunked Output
- 当不用print的时候,比如uri-append,parameter,header.会自动分块传输,以适应这些位置的大小。
- http-post{ set verb “GET”},http-get{set verb “post”}
Profile Variants
- http-get “variant naame”{ }
Testing Profiles
- 写好profile之后,用c2lint 进行单元测试
- ./c2lint [profile]
The C2 Problem Set
- 不能出网
- IOC(indicator of compromise)检测
- 我们的基础设施被标记为teamserver
HTTP/S Proxy Details
- 使用WinINet AIP - 自动使用用户代理(与IE相同),就算代理有用户名密码
- 如果代理失败,会自动提权
 
- 我们自定义的代理信息会被存到beacon的某个位置,有暴露风险 
Egress&Network Evasion
- Profile Tips:- Don’t use public malleable C2 profile examples in production
- 默认情况下的心跳是get请求,响应200,长度0 //非常可疑,尽量避免
- http-stager //也非常重要,改变stager流量的样子- 推荐Header 改成不是 Content-type:application/octet-stream//因为这是默认项
- 推荐output 进行处理,因为stage数据开头的decoder有指定字节是固定的- prepend一些数据
 
 
- http-config,也改一改- -不然前功尽弃
- Use plausible set useragent value for target network
- if you are in a tough egress situation,可以考虑get-only C2
 
Network Security Monitoring
- Use an Apache,Nginx,or a CDN as a redirector- other benefits:- smooths CS-specific indicators,better JA3S fingerprint
- header的顺序,内容,更没有teamserver 的fingerprint
 
- Invest in your infrastructure- Host redirectors on different providers
- Domains are better with age and categorization
- do not use IPv4 addresses for C2
- Have a valid SSL certificate
 
- Operate “low and slow”- High Beacon sleep interval
 
 
- other benefits:
JA3
- A way of looking at the handshake process of tls traffic and generating a hash on the algorithms that both sides present to each other as potential key lenght and ciphers they can use to communicate.
- And it turns out that these presented ciphers and key lengths aere agreat way to fingerprint the applications on each side of communication.
- 简单来说就是通过https双方协商好的cipher suite判断双方的程序,如果用Apache或Ngingx服务器作为redirector,jar3看起来就不是在和jdkxxx通信,而是apache或nginx
DNS C2 Tracdecraft
- Split-Split DNS- Don’t use DNS C2
 
- Volume of requests- Use DNS C2 as low&slow fallback option only
 
- Bogon IP addresses- Change dns idle in profile
- Avoid ‘mode dns’ as this will send bogon responses
 
- Length of request hostnames and responses- Set dns max txt to limit TXT length
- Set maxdns to limit hostname length
 
Infrastructure OPSEC
- How to find team servers on the internet- Default(self-signed!)SSL certificate- Use a valid SSL certificate
- Use Apache,Nginx,or a CDN as a redirector
- Only allow HTTP/S connections from redirectors
 
- 0.0.0.0 DNS response- Set dns_idle in Malleable C2 to aviod 0.0.0.0
 
- Port 50050 open- Firewalll port 50050 and access via SSH tunnel
 
- Empty index page,404,text/plain Content-Type- Host content on your redirectors
 
- Don’t want your payload fconfig available to all?- Set host_stage to false in Malleable C2
- (disables hosted payload for staging purposes)
 
 
- Default(self-signed!)SSL certificate
- How to verify team server- Connect to it and ask for a payload(staging)
- wget -U “Internet Explorer” http://[server]/vl6D- vl6D这个地方的checksum必须是某个固定的值
 
 
4、Weaponization
- 执行自己想要执行的artifact:exe、dll、ps1
- Static Analysis- heuristics- Compile time
- Compiler
- import table
- metadata resources- clone 其它程序的
 
- signed?
- entropy
 
- correlation- 与样本库中的程序对比相似性
 
 
- heuristics
- Dynamic Analysis- sandbox- TIME
- INCOMPLETE
 
 
- sandbox
- Artifact Kit- Source code Framework to generate EXEs,DLLs and Serevice EXEs
- Obfuscate known bad in unknown executable
- Fool AV product to stop emulating executable
- De-obfuscate known bad execute it
 
- Application Whitelisting- prevent execution of unapproved applications
- Run payload via whitelisted program- MS Office Macro
- PowerShell
- LOLbins
- DLL Sideloading
 
 
- Resource Kit- 混淆web delivery后在victim上执行的命令
 
- In-memory Detections- 1:16s
 
