reverse-engineering-rust-malware

使用 IDA Pro 和 Ghidra 对 Rust 编译的恶意软件进行逆向工程,掌握处理非空终止字符串、提取 crate 依赖项和 Rust 特有控制流分析的专项技术。

9 stars

Best use case

reverse-engineering-rust-malware is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

使用 IDA Pro 和 Ghidra 对 Rust 编译的恶意软件进行逆向工程,掌握处理非空终止字符串、提取 crate 依赖项和 Rust 特有控制流分析的专项技术。

Teams using reverse-engineering-rust-malware should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/reverse-engineering-rust-malware/SKILL.md --create-dirs "https://raw.githubusercontent.com/killvxk/cybersecurity-skills-zh/main/skills/reverse-engineering-rust-malware/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/reverse-engineering-rust-malware/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How reverse-engineering-rust-malware Compares

Feature / Agentreverse-engineering-rust-malwareStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

使用 IDA Pro 和 Ghidra 对 Rust 编译的恶意软件进行逆向工程,掌握处理非空终止字符串、提取 crate 依赖项和 Rust 特有控制流分析的专项技术。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 对 Rust 恶意软件进行逆向工程

## 概述

由于 Rust 的跨平台编译能力、内存安全保证,以及对逆向工程师造成的复杂性,它在恶意软件开发中越来越受欢迎。Rust 二进制文件包含完整的静态链接标准库,生成的二进制文件体积较大且包含大量样板代码。主要挑战包括:非空终止字符串(Rust 使用胖指针,包含指针和长度两部分)、单态化(monomorphization)导致泛型代码重复、复杂的错误处理(Result/Option 解包链),以及不熟悉的调用约定。与 C/C++ 二进制文件相比,将 Rust 反编译为 C 代码的效果很差。Ghidra crate 提取脚本和针对 Rust 特有模式(2024-2025 年)的专项培训有助于应对这些挑战。典型的 Rust 恶意软件包括 BlackCat/ALPHV 勒索软件、Hive 勒索软件变种和 Buer Loader。

## 前置条件

- IDA Pro 8.0+ 或 Ghidra 11.0+
- Rust 工具链,用于参考编译
- Python 3.9+,用于辅助脚本
- 理解 Rust 内存模型(所有权、借用)
- 熟悉 Rust 字符串类型(String、&str、CString)

## 实践步骤

### 步骤 1:识别并解析 Rust 二进制文件元数据

```python
#!/usr/bin/env python3
"""分析 Rust 恶意软件二进制元数据并提取 crate 依赖项。"""
import re
import sys
import json


def identify_rust_binary(data):
    """检查二进制文件是否为 Rust 编译并提取版本信息。"""
    indicators = {
        "rust_panic_strings": bool(re.search(rb'panicked at', data)),
        "rust_unwrap": bool(re.search(rb'called.*unwrap.*on.*None', data)),
        "core_panic": bool(re.search(rb'core::panicking', data)),
        "std_rt": bool(re.search(rb'std::rt::lang_start', data)),
        "cargo_path": bool(re.search(rb'\.cargo[/\\]registry', data)),
        "rustc_version": None,
    }

    version = re.search(rb'rustc\s+(\d+\.\d+\.\d+)', data)
    if version:
        indicators["rustc_version"] = version.group(1).decode()

    is_rust = sum(1 for v in indicators.values() if v) >= 2
    return is_rust, indicators


def extract_crates(data):
    """从二进制字符串中提取 Rust crate(依赖项)名称。"""
    crate_pattern = re.compile(
        rb'(?:crates\.io-[a-f0-9]+/|\.cargo/registry/src/[^/]+/)'
        rb'([\w-]+)-(\d+\.\d+\.\d+)'
    )
    crates = {}
    for match in crate_pattern.finditer(data):
        name = match.group(1).decode()
        version = match.group(2).decode()
        crates[name] = version

    # 检查常见的恶意软件相关 crate
    suspicious_crates = {
        "reqwest": "HTTP 客户端",
        "hyper": "HTTP 库",
        "tokio": "异步运行时",
        "aes": "AES 加密",
        "chacha20": "ChaCha20 加密",
        "rsa": "RSA 加密",
        "ring": "密码学库",
        "base64": "Base64 编码",
        "winapi": "Windows API 绑定",
        "winreg": "注册表访问",
        "sysinfo": "系统信息",
        "screenshots": "屏幕截图",
        "clipboard": "剪贴板访问",
        "keylogger": "键盘记录",
    }

    capabilities = []
    for crate_name, description in suspicious_crates.items():
        if crate_name in crates:
            capabilities.append({
                "crate": crate_name,
                "version": crates[crate_name],
                "capability": description,
            })

    return crates, capabilities


def extract_rust_strings(data):
    """提取字符串时处理 Rust 的非空终止格式。"""
    # Rust 字符串以指针+长度方式存储,但字符串字面量
    # 通常在 .rodata 段中以连续序列存放
    strings = []
    ascii_pattern = re.compile(rb'[\x20-\x7e]{8,500}')
    for match in ascii_pattern.finditer(data):
        s = match.group().decode('ascii')
        # 过滤出与恶意软件相关的字符串
        keywords = ['http', 'socket', 'encrypt', 'decrypt', 'shell',
                    'exec', 'cmd', 'upload', 'download', 'persist',
                    'registry', 'mutex', 'pipe', 'inject']
        if any(kw in s.lower() for kw in keywords):
            strings.append(s)

    return strings


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print(f"用法: {sys.argv[0]} <rust二进制文件>")
        sys.exit(1)

    with open(sys.argv[1], 'rb') as f:
        data = f.read()

    is_rust, indicators = identify_rust_binary(data)
    print(f"[{'+'if is_rust else '-'}] Rust 二进制文件: {is_rust}")
    print(json.dumps(indicators, indent=2, default=str))

    crates, capabilities = extract_crates(data)
    print(f"\n[+] Crate(共 {len(crates)} 个):")
    for name, ver in sorted(crates.items()):
        print(f"  {name} v{ver}")

    if capabilities:
        print(f"\n[!] 可疑能力:")
        for cap in capabilities:
            print(f"  {cap['crate']} -> {cap['capability']}")

    strings = extract_rust_strings(data)
    if strings:
        print(f"\n[+] 可疑字符串(共 {len(strings)} 个):")
        for s in strings[:20]:
            print(f"  {s}")
```

## 验证标准

- 正确识别二进制文件为 Rust 编译并附带版本信息
- 提取 crate 依赖项以揭示恶意软件能力
- Rust 特有字符串提取处理了胖指针格式
- 识别主入口点和核心逻辑函数
- 定位加密、网络和持久化相关代码

## 参考资料

- Binary Defense - 从 Rust 恶意软件中提取秘密: https://binarydefense.com/resources/blog/digging-through-rust-to-find-gold-extracting-secrets-from-rust-malware
- Ghidra Rust 分析扩展: https://cir.nii.ac.jp/crid/1050302237609671296
- Fuzzing Labs - 逆向现代二进制文件: https://fuzzinglabs.com/reversing-modern-binaries/
- Bishop Fox - Rust 恶意软件开发: https://bishopfox.com/blog/rust-for-malware-development

Related Skills

reverse-engineering-ransomware-encryption-routine

9
from killvxk/cybersecurity-skills-zh

对勒索软件加密例程进行逆向工程,以识别密码学算法、密钥生成缺陷,以及通过静态和动态分析挖掘潜在的解密机会。

reverse-engineering-malware-with-ghidra

9
from killvxk/cybersecurity-skills-zh

使用 NSA 的 Ghidra 反汇编器和反编译器对恶意软件二进制文件进行逆向工程,在汇编和伪 C 代码层面理解其内部逻辑、密码学例程、C2 协议和规避技术。适用于恶意软件逆向工程、反汇编分析、反编译、二进制分析或理解恶意软件内部机制等请求。

reverse-engineering-ios-app-with-frida

9
from killvxk/cybersecurity-skills-zh

使用 Frida 动态插桩对 iOS 应用进行逆向工程,在无源代码的情况下理解内部逻辑、 提取加密密钥、绕过安全控制并发现隐藏功能。适用于授权 iOS 渗透测试、分析专有协议、 理解混淆逻辑或从 iOS 二进制文件中提取运行时机密。适合 iOS 逆向工程、Frida iOS Hook、 Objective-C/Swift 方法追踪或 iOS 二进制分析相关请求。

reverse-engineering-dotnet-malware-with-dnspy

9
from killvxk/cybersecurity-skills-zh

使用 dnSpy 反编译器和调试器对 .NET 恶意软件进行逆向工程,分析 C#/VB.NET 源代码,识别混淆技术,提取配置信息,理解包括信息窃取器、远程访问木马(RAT)和加载器在内的恶意功能。适用于 .NET 恶意软件分析、C# 恶意软件反编译、托管代码逆向工程或 .NET 混淆分析等请求。

reverse-engineering-android-malware-with-jadx

9
from killvxk/cybersecurity-skills-zh

使用 JADX 反编译器对恶意 Android APK 文件进行逆向工程,分析 Java/Kotlin 源代码,识别包括数据窃取、C2 通信、权限提升和覆盖攻击在内的恶意功能。检查 Manifest 权限、Receiver、Service 及原生库。适用于 Android 恶意软件分析、APK 逆向工程、移动端恶意软件调查或 Android 威胁分析等请求。

performing-static-malware-analysis-with-pe-studio

9
from killvxk/cybersecurity-skills-zh

使用 PEStudio 对 Windows PE(可移植可执行文件)恶意软件样本进行静态分析, 检查文件头、导入表、字符串、资源和指标,无需执行二进制文件。 识别可疑特征,包括加壳、反分析技术和恶意导入。适用于静态恶意软件分析、 PE 文件检查、Windows 可执行文件分析或执行前恶意软件分级等请求场景。

performing-malware-triage-with-yara

9
from killvxk/cybersecurity-skills-zh

使用 YARA 规则对文件模式、字符串、字节序列和结构特征进行匹配,快速分级和分类恶意软件样本, 识别已知恶意软件家族及可疑指标。涵盖规则编写、扫描和与分析流程的集成。适用于 YARA 规则创建、 恶意软件分类、模式匹配、样本分级或基于签名的检测等请求场景。

performing-malware-persistence-investigation

9
from killvxk/cybersecurity-skills-zh

系统性地调查 Windows 和 Linux 系统上的所有持久化机制,以识别恶意软件如何在重启后存活并维持访问。

performing-malware-ioc-extraction

9
from killvxk/cybersecurity-skills-zh

恶意软件 IOC(失陷指标)提取是指通过分析恶意软件,识别可操作的失陷指标,包括文件哈希、网络指标(C2 域名、IP 地址、URL)、注册表修改、互斥体名称、嵌入字符串和行为产物。

performing-malware-hash-enrichment-with-virustotal

9
from killvxk/cybersecurity-skills-zh

使用 VirusTotal API 富化恶意软件文件哈希,获取检测率、行为分析、YARA 匹配和上下文威胁情报,用于事件分类和 IOC 验证。

performing-firmware-malware-analysis

9
from killvxk/cybersecurity-skills-zh

分析固件镜像中嵌入的恶意软件、后门和未授权修改,目标包括路由器、IoT 设备、UEFI/BIOS 和嵌入式系统。涵盖固件提取、文件系统分析、二进制逆向工程和 Bootkit 检测。适用于固件安全 分析、IoT 恶意软件调查、UEFI Rootkit 检测或嵌入式设备入侵评估等请求场景。

performing-automated-malware-analysis-with-cape

9
from killvxk/cybersecurity-skills-zh

部署和操作 CAPEv2 沙箱,进行自动化恶意软件分析,具备行为监控、载荷提取、配置解析和反规避能力。