Communitygithub.com

构建C2重定向器基础设施

使用nginx(proxy_pass)和Apache(mod_rewrite)构建哑管道和流量过滤型C2重定向器,从Malleable C2配置文件中推导过滤规则,并叠加Let's Encrypt TLS。

构建C2重定向器基础设施 是什么?

该技能详细指导如何为授权红队演习构建C2(命令与控制)重定向器基础设施。C2重定向器是位于受害植入体与真实团队服务器之间的中间主机,用于隐藏团队服务器、抵御发现和封禁风险,同时抵御蓝队分析。技能涵盖两种重定向器类型:一是使用socat或iptables的'哑管道',用于快速端口转发但不进行过滤;二是使用nginx proxy_pass和Apache mod_rewrite的'智能过滤型重定向器',它通过解析HTTP请求(URI、User-Agent、HTTP头)并仅转发与Malleable C2配置文件匹配的流量,从而有效防御扫描器、沙盒和蓝队分析。技能详细介绍了使用cs2modrewrite从Cobalt Strike Malleable C2配置文件自动生成nginx或Apache过滤规则的方法。此外,技能还包含了使用Let's Encrypt(certbot)实现TLS终端、应用OPSEC控制(如GeoIP地理围栏、User-Agent验证、HTTP头过滤、域名分类/前置CDN)以及基础设施轮换和退役的最佳实践。该技能特别适合需要部署持久性、低归因C2基础设施,以承受蓝队侦察、域名封禁或提前发现的红队操作人员,同时也适用于希望学习如何检测外部代理C2(T1090.002)技术的防御方。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/building-c2-redirector-infrastructure

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

构建C2重定向器基础设施 是做什么的?

仅限授权使用: 本技能仅适用于授权的红队演练、对抗模拟演习和防御性研究。命令与控制基础设施具有双重用途;部署重定向器来控制您未明确授权测试的系统上的恶意软件是违法的。请确保在已签署规则约定书的商定范围内进行操作,并在演练结束后及时销毁基础设施。

概述

C2重定向器是一个位于受害者植入体与真实团队服务器之间的中间主机。信标连接到重定向器的公共域名/IP;重定向器检查每个请求,然后将合法的C2流量代理回隐藏的团队服务器,或者将所有其他流量(扫描器、蓝队分析师、沙盒)重定向到良性诱饵站点。这可以保护团队服务器免受发现、封禁和溯源,并允许操作人员轮换公开边缘节点而无需重建后端。该技术对应于MITRE ATT&CK T1090.002(代理:外部代理)——攻击者通过中间节点路由C2以隐藏真实来源。

重定向器有两种类型。哑管道(socat、iptables NAT)盲目转发端口,提供隔离但不进行过滤。智能/过滤型重定向器(nginx proxy_pass、Apache mod_rewrite 配合 [P] 标志,或专用工具如RedWarden)解析HTTP请求,仅转发与植入体的Malleable C2配置文件匹配的流量(正确的URI、User-Agent、HTTP头),而将所有其他流量发送302重定向到真实网站。过滤逻辑直接源自C2框架的流量配置文件,因此两者必须保持同步。像cs2modrewrite这样的工具可以从Cobalt Strike Malleable C2配置文件自动生成Apache/nginx规则。

本技能涵盖了使用nginx和Apache构建哑管道和过滤型重定向器、从Malleable配置文件推导过滤规则、使用Let's Encrypt叠加TLS、以及应用OPSEC控制(分类域名、域名前置/CDN前置、HTTP头验证、地理/UA过滤)以构建弹性且低归因的基础设施。

何时使用

  • 搭建一个必须能够承受蓝队排查和域名封禁请求的红队C2。
  • 在演练期间将隐藏的团队服务器与任何互联网面对的主机隔离开。
  • 过滤植入体流量,使只有配置文件匹配的请求才能到达后端,并将扫描器引流走。
  • 为HTTP(S)监听器添加TLS终端、域名分类和CDN/域名前置。
  • 向防御方讲解外部代理C2(T1090.002)的构建原理,以便他们能够检测到它。

前置条件

  • 一个或多个可丢弃的云VPS实例(重定向器的边缘节点)以及一个独立的、有防火墙保护的团队服务器主机。
  • 一个已注册且DNS可控的域名,最好具有较长的注册时间和已分类的声誉。
  • 重定向器主机的root权限。安装Web服务器和TLS工具:
    # Debian/Ubuntu 重定向器
    sudo apt update
    sudo apt install -y nginx apache2 socat certbot python3-certbot-nginx git
    # 如果使用 mod_rewrite 重定向器,启用 Apache 代理模块
    sudo a2enmod rewrite proxy proxy_http ssl headers
    
  • C2框架的Malleable C2配置文件(Cobalt Strike .profile、Sliver/Havoc HTTP配置文件),定义了URI、User-Agent和HTTP头。
  • cs2modrewrite 用于从Cobalt Strike配置文件自动生成规则:
    git clone https://github.com/threatexpress/cs2modrewrite
    
  • 对团队服务器设置防火墙,使其仅在C2端口上接受重定向器的源IP。

目标

  • 部署哑管道重定向器(socat/iptables)以实现快速端口分离。
  • 部署基于Malleable配置文件的过滤型nginx反向代理重定向器。
  • 部署Apache mod_rewrite 重定向器,使用 [P] 代理和 302 诱饵回退。
  • 使用 cs2modrewrite 从Cobalt Strike配置文件自动生成重定向器规则。
  • 使用Let's Encrypt终止TLS并强化公开边缘节点。
  • 应用OPSEC:HTTP头/UA验证、地理过滤、诱饵引流和基础设施轮换。

MITRE ATT&CK 映射

技术ID官方名称相关性
T1090.002代理:外部代理重定向器是一个隐藏团队服务器的外部中间代理
T1090.004代理:域名前置CDN前置通过高信誉的受信任域名路由信标流量
T1071.001应用层协议:Web协议C2通过由Malleable配置文件塑造的HTTP/HTTPS隧道传输
T1573.002加密通道:非对称加密重定向器上的TLS终端加密了信标通道
T1583.006获取基础设施:Web服务为弹性C2获取可丢弃的VPS/CDN边缘节点

工作流程

1. 对团队服务器进行防护并设置防火墙

将团队服务器放置在一个私有主机上。将其C2端口限制为仅允许重定向器的IP访问。

# 在团队服务器上:仅允许重定向器 (203.0.113.10) 访问 443/tcp
sudo ufw default deny incoming
sudo ufw allow from 203.0.113.10 to any port 443 proto tcp
sudo ufw allow OpenSSH
sudo ufw enable

2. 哑管道重定向器 (socat / iptables)

用于快速隔离,不进行过滤,直接将C2端口转发到团队服务器。

# socat 前台转发 443 -> 团队服务器
socat TCP4-LISTEN:443,fork,reuseaddr TCP4:10.0.0.2:443

# 或者 iptables DNAT(持久化)
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.0.0.2:443
iptables -t nat -A POSTROUTING -p tcp -d 10.0.0.2 --dport 443 -j MASQUERADE

3. 过滤型nginx反向代理重定向器

仅代理URI与Malleable配置文件匹配的请求;将所有其他请求发送302重定向到诱饵主机。请将location正则表达式和User-Agent替换为您的配置文件中的值。

# /etc/nginx/sites-available/redirector.conf
server {
    listen 443 ssl;
    server_name cdn.example.com;

    ssl_certificate     /etc/letsencrypt/live/cdn.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cdn.example.com/privkey.pem;

    # 仅代理与配置文件匹配的C2 URI到隐藏的团队服务器
    location ~ ^/(api/v2/jobs|cm/[a-z0-9]+|push) {
        # 要求植入体的精确User-Agent
        if ($http_user_agent != "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36") {
            return 302 https://www.legitimate-decoy.com/;
        }
        proxy_pass https://10.0.0.2;
        proxy_ssl_verify off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    # 所有其他请求 -> 良性诱饵站点
    location / {
        return 302 https://www.legitimate-decoy.com/;
    }
}
sudo ln -s /etc/nginx/sites-available/redirector.conf /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

4. Apache mod_rewrite 重定向器

Apache 的 [P] 标志将匹配的请求代理到团队服务器;不匹配的请求则获得 302 重定向。这是 cs2modrewrite 生成的格式。

# /etc/apache2/sites-available/redirector.conf  (位于 <VirtualHost *:443> 内部)
RewriteEngine On
SSLProxyEngine On
# 要求植入体的User-Agent
RewriteCond %{HTTP_USER_AGENT} "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" [NC]
# 匹配Malleable配置文件中有效的C2 URI (GET/POST/stager)
RewriteCond %{REQUEST_URI} ^/(api/v2/jobs|cm/[a-z0-9]+|push)/?$
# 代理到隐藏的团队服务器,保留URI
RewriteRule ^.*$ https://10.0.0.2%{REQUEST_URI} [P,L]
# 所有其他请求 -> 诱饵站点
RewriteRule ^.*$ https://www.legitimate-decoy.com/ [R=302,L]
sudo a2ensite redirector && sudo apache2ctl configtest && sudo systemctl reload apache2

5. 从Malleable配置文件生成规则

让 cs2modrewrite 直接从您的Cobalt Strike配置文件构建Apache或nginx规则,以确保过滤器精确匹配信标流量。

cd cs2modrewrite
# Apache mod_rewrite 规则
python3 cs2modrewrite.py -i havex.profile -c https://10.0.0.2 \
  -r https://www.legitimate-decoy.com -o /etc/apache2/redirect.rules
# nginx 配置
python3 cs2nginx.py -i havex.profile -c https://10.0.0.2 \
  -r https://www.legitimate-decoy.com -H cdn.example.com > /etc/nginx/sites-available/c2.conf

6. 使用Let's Encrypt终止TLS

签发一个有效证书,以免信标HTTPS抛出TLS警告,并使边缘节点看起来更合法。

sudo certbot --nginx -d cdn.example.com --agree-tos -m [email protected] --redirect
# 验证自动续期
sudo certbot renew --dry-run

7. 应用OPSEC控制

叠加防御层以抵御蓝队分析:验证HTTP头、针对目标国家进行地理围栏、重定向沙盒流量以及轮换边缘节点。在支持的平台上考虑CDN/域名前置(T1090.004)。

# 示例:使用ipset/GeoIP在防火墙丢弃非目标地理位置的流量,
# 在配置文件中要求自定义认证HTTP头,并按计划轮换重定向器
# 域名/IP。检查重定向器是否仅转发匹配的流量:
curl -k https://cdn.example.com/                       # 预期获得 302 重定向到诱饵站点
curl -k -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
  https://cdn.example.com/api/v2/jobs                  # 预期获得代理响应

工具与资源

工具用途来源
nginx过滤型反向代理重定向器https://nginx.org/
Apache mod_rewrite[P] 代理 + 302 诱饵重定向器https://httpd.apache.org/docs/current/mod/mod_rewrite.html
cs2modrewrite从CS配置文件生成Apache/nginx规则https://github.com/threatexpress/cs2modrewrite
RedWarden感知Malleable配置文件的过滤型C2反向代理https://github.com/mgeeky/RedWarden
redi自动化nginx + Let's Encrypt CS重定向器https://github.com/taherio/redi
socat哑管道TCP转发器http://www.dest-unreach.org/socat/
Let's Encrypt / certbot免费TLS证书https://certbot.eff.org/
ired.team红队基础设施参考https://www.ired.team/offensive-security/red-team-infrastructure

验证标准

  • 团队服务器已设置防火墙,仅接受重定向器源IP对C2端口的访问。
  • 重定向器已部署(哑管道和/或过滤型反向代理)。
  • 过滤规则源自实际的Malleable C2配置文件(URI + User-Agent + HTTP头)。
  • 不匹配的请求返回302重定向到良性诱饵站点(使用curl验证)。
  • 匹配的信标请求被代理到隐藏的团队服务器(使用curl验证)。
  • 已签发有效的TLS证书,并确认自动续期。
  • 已应用OPSEC控制(UA/HTTP头验证、地理围栏、诱饵引流)。
  • 在适用的情况下已考虑域名分类/CDN前置。
  • 已记录基础设施轮换和退役计划。
  • 所有活动均在授权的演练范围内进行。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

相关技能