re-ioc

Extracts threat indicators and writes detection rules for malware analysis.

Installation
Run `npx skills add "https://github.com/dslsdzc/rev-skills" --skill "re-ioc"` to install this skill, then follow its SKILL.md instructions for my next request.

Paste this into Claude Code, Cursor, or any agent that can run commands.

What this skill does
What it does: - Pulls out important clues from analyzed files like file names, web addresses, and computer names - Creates detection rules using a tool called YARA that can find similar bad files - Organizes all the evidence into a standard report format - Tests the detection rules to make sure they work and do not catch good files by mistake When to use it: - You finished analyzing a suspicious file and need to share what you found - You want to create a rule that can find the same malware on other computers - You need to write a report with all the proof of what the file does - You want to list all the web addresses, file names, and other clues the malware uses
SKILL.mdShow the author's original SKILL.md (not in English)
---
name: re-ioc
description: >
  IOC 提取与 YARA 规则、报告结构。
  触发词:IOC、YARA、写规则、分析报告、hash列表
---

# IOC 提取与 YARA 规则

## 何时使用 / 何时不用

- 用:分析完成后产出 IOC 列表(hash/域名/IP/路径/互斥体);写 YARA 规则做样本检测;按标准结构出分析报告
- 用:需要把行为证据整理成可复现、可分享的结论
- 不用:还没完成行为/静态分析(IOC 原料在 [[re-behavior]] / [[re-triage]] 产物里)
- 不用:用户只要一句话结论(仍建议至少给 IOC 与证据路径)

## 工具准备

本技能以静态处理为主(写规则/扫描文件),不运行样本;运行样本只在 [[re-sandbox]] 内(默认沙箱最高原则,见 [[platform-tips]])。

### yara —— 规则引擎

- Linux: `apt install yara` / `dnf install yara` / `pacman -S yara`
- macOS: `brew install yara`
- Windows/WSL: `pip install yara-python`(Python 版,跨平台兜底)
- 验证: `yara --version`;Python: `python -c "import yara; print(yara.__version__)"`

### pefile —— PE 结构解析(写 PE 特征用)

- 全平台: `pip install pefile`
- 验证: `python -c "import pefile; print(pefile.__version__)"`

### VT / grep.app 查询(可选)

- VirusTotal: 网页 https://www.virustotal.com/ 查询 hash/域名;API key 环境变量:
  ```sh
  curl -s --request GET \
    --url "https://www.virustotal.com/api/v3/search?query=<sha256>" \
    -H "x-apikey: $VT_API_KEY" | python3 -m json.tool
  ```
  验证: 带 key 的请求返回 JSON(401 说明 key 无效)
- grep.app: 网页 https://grep.app/ 查公开代码中的特征字符串,无安装
- 注: 上传私有样本到 VT 前确认数据策略;grep.app 查询仅用于字符串/特征参考

### sha256sum / md5sum(IOC 哈希)

- 安装与验证见 [[re-triage]] 工具准备(coreutils / Get-FileHash)

## 操作步骤

按顺序执行,每步记下结果。

1. **提取 IOC(按来源分类)**:
   - 文件级: `sha256sum sample.exe`(sha256 为主,md5 仅辅助);脱壳产物、dropper 落盘文件各算一份
   - 网络级: 行为日志([[re-behavior]] 步骤 4)与 INetSim 记录中的域名、IP、端口;配置/内存里搜出的硬编码 URL(`strings sample | grep -iE 'http|https'`)
   - 系统级: 文件路径(持久化位置、落地路径)、互斥体名(CreateMutex 参数,用 [[re-ghidra]] / [[re-ida]] 查或 procmon 记录)
   - 每类 IOC 记来源证据(日志文件路径 + 行号/时间戳),供报告引用
   - 去重 + 标注可信度(来自行为证据 > 仅静态字符串)

2. **YARA 规则编写(特征选择 + 评分)**:
   - 特征选择标准:唯一性(只出现在该家族/样本)、稳定性(不随版本易变)、可区分(避开常见库字符串)
   - 常用特征类型:字符串(URL/域名/互斥体/机器码)、PE 结构(节名、导入)、字节模式(`{ 4D 5A 90 00 }` 或 `$a = { E8 ?? ?? ?? ?? }` 通配)
   - 评分(写注释标注,命中阈值参考): 每个特征按信息量打分——唯一长字符串 +2、通用 API 名 +0.5、短字节模式 +1;总分 1/3 作为命中阈值参考,最终以验证为准
   - 示例:
     ```yara
     rule Win32_FamilyX_Dropper {
         meta:
             description = "FamilyX dropper 检测"
             author = "analyst"
             score = 4
         strings:
             $url = "http://c2.example.org" ascii wide
             $mutex = "Global\\FamilyX_mutex" ascii wide
             $pe   = { 4D 5A 90 00 }
         condition:
             uint16(0) == 0x5A4D and (2 of them)
     }
     ```
   - 规则名命名规范: 平台_家族_类型(如 `Win32_FamilyX_Dropper`)

3. **报告结构**(按五段写):
   - 摘要: 一句话结论(样本是什么、判定恶意与否、主要行为)
   - 行为: [[re-behavior]] 的进程/持久化/文件/网络行为 + ATT&CK 映射表
   - 证据: 每一步产物路径 + sha256(样本、日志、内存转储、规则文件)——可复现的关键
   - IOC: 步骤 1 的分类列表 + 可信度
   - 结论: 处置建议(查杀 / 阻断域名 IP / 补丁建议)
   - 按 [[re-analyze]] 的 RE_REPORT 偏好决定格式(简要/完整)

4. **规则验证(yara 扫描样本)**:
   ```sh
   yara rule.yar sample.exe          # 命中 → 规则有效
   yara -s rule.yar sample.exe       # 显示命中的特征串,与样本实际内容核对
   yara rule.yar benign_samples/*    # 误报测试: 已知良性样本目录应 0 命中
   ```
   - 阳性对照:命中后 `yara -s` 核对命中串确属恶意特征
   - 阴性对照:良性样本目录不命中;命中即误报,回步骤 2 调整特征
   - 全库校验:把规则加入本地规则库,重扫全部已分析样本,确认无回归

## 跨域联合

- [[re-malware]]:工作流第 6 步——本技能是恶意样本分析的收尾(IOC 与报告)
- [[re-behavior]]:步骤 1 的 IOC 原料(网络级/系统级 IOC)来自行为分析产物
- [[re-protocol]]:C2 域名/IP/协议指纹进 IOC 列表与 YARA 特征
- [[re-anti-analysis]]:脱壳产物、壳指纹、加壳行为也可作为 YARA 特征来源
- 报告与规则回传给 [[re-analyze]](按 RE_REPORT)与团队共享

## 常见坑与陷阱

- **特征选太泛 → 误报**:现象——规则命中大量无关文件(如只写了个 `http://` 或常见库字符串);原因——特征不唯一,无评分与验证环节;对策——步骤 2 按唯一性选特征并打分,步骤 4 必须做良性样本阴性对照,误报即回改
- **只写 hash 不写行为特征**:现象——hash IOC 对新样本/变种全部失效;原因——hash 只覆盖单一样本,无法泛化到家族;对策——hash 之外至少给 YARA 规则或行为特征(互斥体/域名/字节模式),规则条件用 `2 of them` 而非单特征
- **报告缺证据路径不可复现**:现象——报告结论无法追溯(没有日志/样本路径与 hash);原因——证据未存档或未写进报告;对策——步骤 3 报告的证据段必须逐项给路径 + sha256,IOC 与行为一一对应来源
- **特征串 atom 质量差 → 扫描慢且误报**:现象——规则写好后全库扫描奇慢或命中大量无关文件;原因——YARA 用 4 字节子串做 Aho-Corasick 预过滤,单字节或以 0x00/0xFF/0x90 开头的模式强制海量验证;对策——用 `yr debug atoms`(YARA-X)检查 atom,正则锚定字面量(`/mshta\.exe http:\/\/.../` 而非 `/http:/`),条件顺序由廉到贵(filesize → magic → strings),"能用 uint32 就别加载模块"
- **单样本规则脆弱**:现象——规则只命中当前样本,同家族变种全漏;原因——基于单个样本写规则,且针对加密层(脱壳前内容)写特征;对策——收集 3+ 变体再写;熵 >7 的加壳样本先脱壳,或针对壳的结构特征(节名、opaque predicate)写规则而非加密层;候选串用 yarGen `--excludegood` / FLOSS 生成,回归用 YARA-CI / VT retrohunt
- **元数据不完整不可维护**:现象——规则进入企业规则库后无法审计(不知作者、查什么、参照什么、哪个 hash);原因——缺 author/date/reference/hash 元数据与命名规范;对策——meta 段必带 description(以 "Detects" 开头)、author、date、reference、hash;命名用 `MAL_`/`HKTL_`/`SUSP_` 等前缀 + 平台/家族/变体/日期(如 `MAL_Win_Emotet_Loader_Jan25`)
- **`for all` 循环未绑 filesize → 大文件扫描爆炸**:现象——规则在小样本上飞快,扫几十 MB 大文件卡死/超时;原因——`for all i in (1..#a)` 循环的迭代上限绑定特征命中次数,大文件上 `#a` 可达数千,`for all i in (1..filesize)` 一类写法迭代规模直接随文件大小膨胀;对策——循环条件一律先加 filesize 边界(`filesize < 100KB and for all i in (1..#a): ...`),再放特征条件
- **均匀重复字符串 → 扫描直接报 "too many matches"**:现象——`yara` 扫描报 `string ... caused too many matches` 错误,规则无法运行;原因——特征串是长重复/均匀内容(如 `"2222..."`、宽字符空格填充),预过滤阶段命中数爆炸触发 YARA 保护上限;对策——避免重复字符堆叠的内容做特征,改用带通配的 hex 模式或含多变字节的串,保证 atom 有区分度(与既有 atom 坑配合检查)

Mirrored from the author's public source. Install counts from the open skills registry.

The systems behind these skills get built for partners every week.

Partner with us