aoiflux/fsagen
GitHub: aoiflux/fsagen
一款基于种子确定性生成多样化文件系统取证痕迹的工具,用于测试和验证数字取证工具的分析能力。
Stars: 0 | Forks: 1
# 文件系统取证痕迹生成器
用于创建多样化文件系统痕迹的确定性生成器,旨在测试取证工具(Autopsy、EnCase、FTK 等)。使用 YAML manifest 执行简单操作,使用 playbook 模拟复杂的作案手法,或者无需 YAML 直接使用批量生成器快速生成合成语料库。
## 功能
- 使用 `--seed` 实现确定性输出
- Manifest 模式:简单、声明式的文件操作(create/update/append/delete/mace/rename/truncate/rotate/ads/motw)
- Playbook 模式:包含 actor、定时步骤和模板的复杂时间线
- 批量模式:使用 `--bulk` 和 `--depth` 极简生成合成语料库
- 广泛的文件类型支持:文档、日志、归档、媒体、电子邮件、Windows 痕迹
- MACE (atime/mtime) 时间戳控制
- Windows 专属:NTFS ADS 和 Mark-of-the-Web (MoTW)
## 安装
从源码构建:
```
go build -v -o fsagen.exe
```
## 用法
fsagen 可以使用 manifest、playbook 或批量生成器来生成痕迹:
```
fsagen [OPTIONS]
```
**选项:**
- `--seed N` - 用于确定性生成的 PRNG seed(默认:1)
- `--manifest FILE` - 执行 YAML manifest(简单文件操作)
- `--playbook FILE` - 执行 YAML playbook(复杂的作案手法)
- `--generate-schema` - 为 manifest/playbook 写入独立的 JSON schema 并退出
- `--schema-out DIR` - `--generate-schema` 的输出目录(默认:`examples`)
- `--bulk N` - 极简批量生成:每层 N 个项目(无需 YAML)
- `--depth D` - 批量生成的深度(默认:1)
- `--timeline FILE` - 执行后生成取证时间线(格式:csv, txt, bodyfile, macb)
**示例:**
生成用于外部输入验证的 schema 文件:
```
fsagen --generate-schema
```
这会写入:
- `manifest-schema.json`
- `playbook-schema.json`
将 schema 生成到自定义位置:
```
fsagen --generate-schema --schema-out ./schemas
```
使用 manifest 进行简单的批量生成:
```
fsagen --seed 42 --manifest examples/manifest-bulk-simple.yaml ./output
```
使用 playbook 进行复杂的对手模拟:
```
fsagen --seed 100 --playbook examples/playbook-adversary-data-theft.yaml ./crime-scene
```
生成带有取证时间线的痕迹:
```
fsagen --seed 42 --playbook examples/playbook-comprehensive-ransomware.yaml --timeline timeline.csv ./output
```
使用批量生成器(无需 YAML)快速生成合成语料库:
```
fsagen --seed 7 --bulk 3 --depth 2 ./quick-bulk
```
## Manifest schema
由一系列操作组成的 YAML:
- action: `create|update|append|truncate|rotate|delete|mace|rename|ads|motw`
- path: 相对于输出根目录的目标路径
- type: `file|dir`(用于 create)
- ext: 如果 `path` 没有扩展名,则追加此文件扩展名
- content: 字面内容(可选)
- content_len: 确定性随机内容的大小(未提供 content 时的回退方案)
- atime/mtime: 用于 MACE 控制的 RFC3339 时间戳
- new_path: 用于 `rename` 或 `rotate` 的新位置
- stream: ADS 流名称(用于 `ads` action,仅限 Windows)
- zone_id, host_url, referrer_url: 用于 `motw` action(仅限 Windows)
**示例:**
- `examples/manifest-basic.yaml` - 基本的 create/update/delete 操作
- `examples/manifest-bulk-simple.yaml` - 跨多种类型的快速批量文件生成
## Playbook schema
包含时间线和 actor 的 YAML:
- **start**: RFC3339 或 "now"
- **variables**: 用于模板的全局变量(键值对映射)
- **actors**: { name, base, variables } 列表
- name: Actor 标识符
- base: 该 actor 文件的基础目录
- variables: Actor 特定变量(覆盖全局变量)
- **steps**: 时间线步骤
- actor: Actor 名称
- offset: 距离首次发生的 time.Duration(例如,5m, 2h)
- every: 重复间隔(可选)
- repeat: 发生次数(默认 1)
- condition: 步骤级别的条件执行("odd"、"even"、"first"、"last")
- batch_count: 在此步骤中生成 N 个文件(成倍增加操作)
- actions: 带有附加参数的操作列表:
- offset: 相对于步骤发生时间的 time.Duration
- condition: action 级别的条件执行
- template: 预定义的内容模板("email"、"log"、"script"、"doc")
- 所有标准的 manifest 字段(action、path、content 等)
支持的操作:`create|update|append|truncate|rotate|delete|mace|rename|ads|motw`(所有操作在 manifest 和 playbook 中均可使用)。`ads` 和 `motw` 仅限 Windows。除非在 action 中明确提供,否则时间戳均根据时间线计算得出。
**Playbook 模板:**
- `${SEQ}` - 单调递增的序列计数器
- `${RND:N}` 或 `${RANDOM:N}` - 长度为 N 的确定性随机字符串
- `${DATE:layout}` - 使用 Go layout 格式化的当前时间(例如,`${DATE:2006-01-02T15:04:05Z07:00}`)
- `${ACTOR}` - 当前的 actor 名称
- `${VAR:name}` - 变量替换(来自全局或 actor 特定变量)
- `${UUID}` - 基于序列的确定性 UUID
- `${IP}` - 确定性 IP 地址(192.168.x.x 范围)
- `${HASH:N}` - 长度为 N 的确定性类哈希十六进制字符串
- `${BATCH}` - 当前的批次索引(使用 batch_count 时)
- `${ITER}` - 当前的迭代索引(使用 repeat 时)
**高级 Playbook 功能:**
1. **变量**:在全局和 actor 作用域内定义可重用的值
```
variables:
campaign_id: "OP-2024-001"
target_org: "ACME Corp"
actors:
- name: attacker
base: users/victim/Downloads
variables:
ip_addr: "192.0.2.42"
```
2. **条件执行**:控制步骤/action 何时运行
```
steps:
- actor: malware
repeat: 10
condition: even # Only runs on even iterations (0, 2, 4, ...)
actions:
- action: create
path: file-${ITER}.txt
condition: odd # Further filtering at action level
```
3. **批量操作**:在一个步骤中生成多个文件
```
steps:
- actor: ransomware
batch_count: 100 # Creates 100 files
actions:
- action: create
path: encrypted-${BATCH}.locked
content_len: 2048
```
4. **内容模板**:使用预定义的真实内容
```
actions:
- action: create
path: message.eml
template: email # Generates realistic email structure
```
可用模板:`email`、`log`、`script`、`doc`
**Playbook 示例:**
- `examples/playbook-basic.yaml` - 简单的双 actor 工作流
- `examples/playbook-adversary-data-theft.yaml` - 分阶段处理文档、归档、写入窃取日志、篡改时间
- `examples/playbook-log-tampering.yaml` - 创建基线日志、注入篡改条目、篡改时间并删除
- `examples/playbook-persistence-artifacts.yaml` - 投放类似启动项的文件和 .reg 导出文件
- `examples/playbook-email-and-archive.yaml` - 创建电子邮件/图像、归档、删除原始文件
- `examples/playbook-log-rotate-and-truncate.yaml` - 演示日志轮转和截断
- `examples/playbook-windows-ads-motw.yaml` - 添加 NTFS ADS 和 Mark-of-the-Web(仅限 Windows)
- `examples/playbook-comprehensive-ransomware.yaml` - **高级**:包含变量、批处理、条件和模板的完整勒索软件攻击
- `examples/playbook-insider-threat-exfil.yaml` - **高级**:具有重复访问模式的 7 天内部威胁场景
- `examples/playbook-malware-lifecycle.yaml` - **高级**:包含 beaconing 和反取证措施的 48 小时恶意软件感染生命周期
## 关于时间戳的说明
- 通过 `os.Chtimes` 设置 mtime/atime。大多数系统无法直接设置 ctime,其将反映元数据的更改时间。
- 为了模拟删除时目录时间戳的偏差,`delete` 可以包含 `atime/mtime`,在删除后将其应用到父目录。
## 可重现性
- 所有随机值(名称、合成内容)均来自带 seed 的 PRNG。使用相同的 `--seed` 可以在相同平台和文件系统上重现完全一致的输出。
- 无竞态条件:并发操作在保持确定性的同时使用了适当的同步机制。
## 支持的文件类型
生成器可以为以下内容创建具有适当结构的痕迹:
- **文档**:.txt, .md, .docx, .pdf
- **数据**:.csv, .json, .jsonl, .xml, .html
- **日志**:.log, .syslog, .jsonl
- **媒体**:.png, .mp4
- **归档**:.zip
- **电子邮件**:.eml, .mbox
- **Windows**:.reg, .exe, NTFS ADS, MoTW
## 取证时间线生成
生成痕迹后,fsagen 可以自动创建用于分析的取证时间线:
```
fsagen --playbook scenario.yaml --timeline output.csv ./artifacts
```
**时间线格式:**
- **CSV** (`.csv`):包含所有元数据(路径、大小、mode、时间戳、MD5、类型、ADS)的结构化数据
- **TXT** (`.txt`):包含详细文件信息的易读格式
- **Bodyfile** (`.bodyfile`):兼容 The Sleuth Kit 的 mactime 工具
- **MACB** (`.macb`):Modified/Accessed/Changed/Birth 时间线,分别显示所有时间戳事件
**时间线功能:**
- 为所有文件计算 MD5 哈希(大于 100MB 的文件除外)
- 完整捕获时间戳(访问、修改、更改/创建时间)
- NTFS 备用数据流检测(Windows)
- 按修改时间进行时间顺序排序
- 确定性输出(相同的 seed = 相同的时间线)
- **仅时间线模式**:从现有痕迹生成时间线,而无需重新生成它们
**示例工作流:**
```
# 使用 CSV 时间线生成勒索软件场景
fsagen --seed 999 --playbook examples/playbook-comprehensive-ransomware.yaml --timeline ransomware.csv ./scene
# 创建与 mactime 兼容的时间线
fsagen --playbook examples/playbook-malware-lifecycle.yaml --timeline evidence.bodyfile ./analysis
mactime -b evidence.bodyfile -d > detailed-timeline.txt
# 生成用于时序分析的 MACB 时间线
fsagen --playbook examples/playbook-insider-threat-exfil.yaml --timeline investigation.macb ./case
# 仅时间线模式:从现有 artifacts 生成时间线(无重新生成)
fsagen --timeline existing-timeline.csv ./already-generated-folder
```
**仅时间线模式:**
如果您已经生成了痕迹但忘记创建时间线,您可以稍后生成时间线而无需重新生成这些痕迹:
```
# 从现有文件夹生成时间线
fsagen --timeline my-timeline.csv ./existing-artifacts
# 不同格式
fsagen --timeline analysis.txt ./crime-scene
fsagen --timeline evidence.bodyfile ./investigation
fsagen --timeline temporal.macb ./case-folder
```
这会扫描文件夹、收集所有文件元数据、计算 MD5 哈希,并以您选择的格式输出时间线——无需重新生成痕迹。
有关更多时间线生成示例,请参见 `examples/TIMELINE_EXAMPLES.md`。
## 批量生成(无需 YAML)
当您需要快速生成合成语料库而无需描述具体场景时,请使用批量生成器:
```
# 每个层级 N 项,深度达 D 个目录
fsagen --seed 7 --bulk 3 --depth 2 ./quick-bulk
# 你也可以为批量输出生成时间线
fsagen --seed 7 --bulk 3 --depth 2 --timeline timeline.csv ./quick-bulk
```
它的作用:
- 创建最多达到 `--depth` 的目录扇出,每层具有 `--bulk` 个子分支
- 在每层中填充多种文件类型(txt、docx、png、pdf、mp4、csv、json、xml、html、log、reg、zip、exe、jsonl、syslog、md、eml、mbox)
- 基于 `--seed` 生成确定性的名称和内容
预期用途:
- 快速生成规模可观、多样化的数据集,用于工具演示、性能测试或课堂练习
- 在不需要复杂作案手法(MO)时,为时间线/报告流水线提供预热数据
注意:
- 输出大小会随 `--bulk` 和 `--depth` 快速增长。请从小规模开始(例如,`--bulk 2 --depth 1` 或 `--bulk 3 --depth 2`)。
- 批量模式侧重于结构/内容;如果您需要精确的时间线、actor 或条件,请首选 Playbook。
-
### 相关研究论文
https://link.springer.com/chapter/10.1007/978-981-96-9443-3_17
### 推荐引用方式
@InProceedings{10.1007/978-981-96-9443-3_17,
author="Gogia, Gaurav
and Rughani, Parag",
editor="Gohil, Bhavesh N.
and Patel, Sankita J.
and Chaudhary, Naveen Kumar
and Iyengar, S. S.
and Modi, Chirag
and Padhya, Mukti",
title="File System Artefacts Generator (FSAGen): Towards Faster Forensic Tool Testing",
booktitle="Information Security, Privacy and Digital Forensics",
year="2026",
publisher="Springer Nature Singapore",
address="Singapore",
pages="239--248",
abstract="Software testing is one of the most fundamental steps in any software development lifecycle. The larger the scale, the more testing is required to ensure the correctness and reliability of the software. In the case of digital forensics, one of the main problems that researchers face is the availability of datasets for testing the reliability of the product they are evaluating. Different forensic tools with similar features may present different results even with similar inputs. This makes it extremely important to have standardised and reproducible datasets. This research explores synthetic dataset generators and introduces a novel command-line interface (CLI) tool for generating file system artefacts. The tool aims to facilitate the quick and convenient creation of synthetic datasets to aid in the validation of file system forensic tools. By offering a simplified and cross-platform solution, this tool addresses the need for standardised datasets in digital forensics research and enhances the reliability and accuracy of forensic tool evaluations.",
isbn="978-981-96-9443-3"
}
标签:EVTX分析, Go, Ruby工具, 数字取证, 数据生成, 文件系统, 日志审计, 测试工具, 自动化脚本