mcpField
E
extracting-config-from-agent-tesla-rat

extracting-config-from-agent-tesla-rat

github.com/mukul975セキュリティ35.2k46 回インストール8 週間前に更新
リポジトリ

extracting-config-from-agent-tesla-rat について

Agent Tesla RAT の .NET アセンブリから設定を復元するマルウェア解析スキルです。認可された分析向けに、難読化解除や、情報窃取先、認証情報、対象アプリ、関連設定の抽出を扱います。

主な機能

  1. 01.NET アセンブリの逆コンパイル
  2. 02設定文字列の復号
  3. 03情報窃取先の抽出
  4. 04対象アプリ一覧の復元
  5. 05永続化方式と指標の分析

活用シーン

  1. 01サンドボックスでの Agent Tesla 検体解析
  2. 02ネットワーク遮断向け指標の回収
  3. 03マルウェアの情報窃取手段の記録
  4. 04認可されたレッドチーム分析の支援

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill extracting-config-from-agent-tesla-rat

インストール後、Claude Code で/extracting-config-from-agent-tesla-ratを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
assets/
template.md
references/
api-reference.md
standards.md
workflows.md
scripts/
agent.py

詳細

Agent Tesla RAT からの設定抽出

概要

Agent Tesla は .NET ベースのリモートアクセス型トロイの木馬(RAT)兼キーロガーであり、2024 年にはマルウェア亜種の上位 10 位にランクインし、世界中の企業ネットワークの 6.3% に影響を与えました。盗み出した認証情報を、SMTP メール、FTP アップロード、Telegram ボット API、Discord Webhook のいずれかを使って送信します。マルウェアの設定は .NET アセンブリ内に埋め込まれており、通常は文字列暗号化、リソース暗号化、あるいは .NET リフレクション(ファイルレス)を介して Agent Tesla をメモリ上で復号・実行するカスタムローダーによって難読化されています。設定の抽出には、dnSpy または ILSpy で .NET アセンブリを逆コンパイルし、設定文字列の復号ルーチンを特定したうえで、SMTP サーバーのアドレス、認証情報、FTP エンドポイント、Telegram ボットトークン、標的となったアプリケーションを取り出す作業が含まれます。

使用するタイミング

  • 認可を受けたセキュリティテストの一環として、Agent Tesla RAT から設定を抽出する場合
  • 管理された環境でマルウェアのサンプルや攻撃の痕跡を分析する場合
  • レッドチーム演習やペネトレーションテストの業務を実施する場合
  • 攻撃手法の理解に基づいて検知機能を構築する場合

前提条件

  • .NET の逆コンパイル用の dnSpy または ILSpy
  • 自動抽出用の dnlib または pythonnet を含む Python 3.9 以降
  • .NET の難読化解除用の de4dot
  • .NET IL コードとリフレクションの理解
  • 動的解析用のサンドボックス(ANY.RUN、CAPE)

ワークフロー

ステップ 1: 難読化を解除し、設定を抽出する
#!/usr/bin/env python3
"""Extract Agent Tesla RAT configuration from .NET assemblies."""
import re
import sys
import json
import base64
import hashlib
from pathlib import Path


def extract_strings_from_dotnet(filepath):
    """Extract readable strings from .NET binary for config analysis."""
    with open(filepath, 'rb') as f:
        data = f.read()

    # Extract US (User Strings) heap from .NET metadata
    strings = []

    # Look for common Agent Tesla config patterns
    patterns = {
        "smtp_server": re.compile(rb'smtp[\.\-][\w\.\-]+\.\w{2,}', re.I),
        "email": re.compile(rb'[\w\.\-]+@[\w\.\-]+\.\w{2,}'),
        "ftp_url": re.compile(rb'ftp://[\w\.\-:/]+', re.I),
        "telegram_token": re.compile(rb'\d{8,10}:[A-Za-z0-9_-]{35}'),
        "telegram_chat": re.compile(rb'(?:chat_id=|chatid[=:])[\-]?\d{5,15}', re.I),
        "discord_webhook": re.compile(rb'https://discord\.com/api/webhooks/\d+/[\w-]+'),
        "password": re.compile(rb'(?:pass(?:word)?|pwd)[=:]\s*[\w!@#$%^&*]{4,}', re.I),
        "port": re.compile(rb'(?:port|smtp_port)[=:]\s*\d{2,5}', re.I),
    }

    results = {}
    for name, pattern in patterns.items():
        matches = pattern.findall(data)
        if matches:
            results[name] = [m.decode('utf-8', errors='replace') for m in matches]

    # Extract Base64-encoded strings (common obfuscation)
    b64_pattern = re.compile(rb'[A-Za-z0-9+/]{20,}={0,2}')
    b64_decoded = []
    for match in b64_pattern.finditer(data):
        try:
            decoded = base64.b64decode(match.group())
            text = decoded.decode('utf-8', errors='strict')
            if text.isprintable() and len(text) > 5:
                b64_decoded.append(text)
        except Exception:
            pass

    if b64_decoded:
        results["base64_decoded_strings"] = b64_decoded[:30]

    return results


def decrypt_agenttesla_strings(data, key_hex):
    """Decrypt Agent Tesla encrypted configuration strings."""
    key = bytes.fromhex(key_hex)
    # Agent Tesla V1: Simple XOR with key
    decrypted_strings = []

    # Find encrypted blobs (high-entropy byte sequences)
    blob_pattern = re.compile(rb'[\x80-\xff]{16,256}')
    for match in blob_pattern.finditer(data):
        blob = match.group()
        # Try XOR decryption
        decrypted = bytes(b ^ key[i % len(key)] for i, b in enumerate(blob))
        try:
            text = decrypted.decode('utf-8', errors='strict')
            if text.isprintable() and len(text.strip()) > 3:
                decrypted_strings.append(text.strip())
        except UnicodeDecodeError:
            pass

    # V2: SHA256-based key derivation then AES
    sha256_key = hashlib.sha256(key).digest()

    return decrypted_strings


def analyze_exfiltration_config(config):
    """Analyze extracted configuration for exfiltration methods."""
    methods = []

    if config.get("smtp_server"):
        methods.append({
            "type": "SMTP",
            "servers": config["smtp_server"],
            "emails": config.get("email", []),
        })

    if config.get("ftp_url"):
        methods.append({
            "type": "FTP",
            "urls": config["ftp_url"],
        })

    if config.get("telegram_token"):
        methods.append({
            "type": "Telegram",
            "tokens": config["telegram_token"],
            "chat_ids": config.get("telegram_chat", []),
        })

    if config.get("discord_webhook"):
        methods.append({
            "type": "Discord",
            "webhooks": config["discord_webhook"],
        })

    return methods


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print(f"Usage: {sys.argv[0]} <agent_tesla_sample>")
        sys.exit(1)

    config = extract_strings_from_dotnet(sys.argv[1])
    methods = analyze_exfiltration_config(config)

    report = {"raw_config": config, "exfiltration_methods": methods}
    print(json.dumps(report, indent=2))

検証基準

  • 窃取データの送信方法を特定できている(SMTP/FTP/Telegram/Discord)
  • 設定からサーバーのアドレスと認証情報を抽出できている
  • 標的アプリケーションの一覧を復元できている
  • キーロガーとスクリーンショット取得の設定が文書化されている
  • 永続化の仕組みを特定できている
  • ネットワークブロックに利用できる IOC を抽出できている

参考資料

コメント