aditya777-dev/ir-triage-toolkit
GitHub: aditya777-dev/ir-triage-toolkit
一款面向 SOC 分析师的跨平台应急响应自动化工具包,支持一键收集 Linux 和 Windows 的关键取证数据并生成结构化分类报告。
Stars: 2 | Forks: 0
# IR Triage 工具包
### 用于 Linux 和 Windows 日志分类的应急响应自动化脚本
这是一款专为 SOC 分析师构建的跨平台取证 artifacts 收集工具包。只需运行一条命令,即可生成结构化的分类报告,涵盖应急响应人员在处置突发安全事件时所需的关键 artifacts。
## 收集内容
| Artifact | Linux | Windows |
|---|---|---|
| Shell 历史记录 | `~/.bash_history` / `.zsh_history` | PowerShell `ConsoleHost_history.txt` |
| 身份验证 / 登录日志 | `/var/log/auth.log` / `/var/log/secure` | 事件 ID 4624, 4625, 4688 |
| 正在运行的进程 | `ps aux`, `pstree` | `Get-Process`, `tasklist /svc` |
| 网络连接 | `ss -tulnp`, `netstat` | `netstat -ano`, `Get-NetTCPConnection` |
| Cron / 计划任务 | crontab, systemd timers | `schtasks`, `Get-ScheduledTask` |
| 启动 / 持久化 | `rc.local`, systemd, Run keys | 注册表 Run keys, 启动文件夹, WMI |
| Prefetch 文件 | 不适用 | `C:\Windows\Prefetch\` (按最后一次运行排序) |
| 用户账户 | `/etc/passwd`, `/etc/group` | `net user`, `Get-LocalUser` |
| SUID/SGID 文件 | `find / -perm -4000` | 不适用 |
| SSH 密钥 | `authorized_keys` (所有用户) | 不适用 |
| 打开的文件 | `lsof -i` | 不适用 |
| 备用数据流 (Alternate Data Streams) | 不适用 | `Get-Item -Stream *` |
| DNS 缓存 | `/etc/resolv.conf` | `Get-DnsClientCache` |
## 项目结构
```
ir-triage-toolkit/
├── triage.py ← Master wrapper (start here)
├── linux/
│ └── collect_linux.sh ← Linux artifact collector (Bash)
├── windows/
│ └── collect_windows.py ← Windows artifact collector (Python)
├── simulate/
│ ├── simulate_windows.py ← Plant harmless test artifacts on Windows
│ └── simulate_linux.sh ← Plant harmless test artifacts on Linux
├── triage/ ← Reports saved here (auto-created)
├── examples/
│ └── example_triage_report.txt ← Sample output with analyst annotations
├── requirements.txt
└── README.md
```
## 前置条件
| 需求 | 说明 |
|---|---|
| Python 3.8+ | 运行 `triage.py` 和 `collect_windows.py` 所需 |
| Bash | 运行 `collect_linux.sh` 和 `simulate_linux.sh` 所需 |
| PowerShell 5+ | Windows 收集使用 PS cmdlets |
| 管理员 / root | Prefetch、安全事件以及部分 Linux 文件需要提升权限才能访问 |
无需任何第三方 Python 包。本工具包仅使用标准库。
## 快速开始
### 在 Windows 上
```
# 1. Clone the repo
git clone https://github.com/aditya777-dev/ir-triage-toolkit.git
cd ir-triage-toolkit
# 2. (可选) 首先植入无害的 test artifacts
python simulate\simulate_windows.py
# 3. 运行 triage collector
python triage.py
# 4. 查看报告
# 输出保存至: triage\triage_YYYYMMDD_HHMMSS\
```
### 在 Linux 上 (在 VM 中)
```
# 1. Clone the repo
git clone https://github.com/aditya777-dev/ir-triage-toolkit.git
cd ir-triage-toolkit
# 2. (可选) 首先植入无害的 test artifacts
bash simulate/simulate_linux.sh
# 3. 运行 triage collector
python3 triage.py
# 4. 查看报告
# 输出保存至: triage/triage_YYYYMMDD_HHMMSS/
```
## 详细用法
### triage.py (主封装脚本)
```
python triage.py # auto-detect OS, run collection
python triage.py --windows # force Windows mode (useful for testing)
python triage.py --linux # force Linux mode
python triage.py --output /path # custom output directory
```
每次运行都会在 `triage/` 目录内创建一个新的带有时间戳的文件夹,其中包含:
- `windows_triage.txt` 或 `linux_triage.txt` — 完整的 artifact 转储
- `SUMMARY.txt` — 包含分析师后续步骤的快速摘要
### 独立运行 Linux 收集器
```
bash linux/collect_linux.sh # stream to terminal
bash linux/collect_linux.sh > my_report.txt # save to file
sudo bash linux/collect_linux.sh > full_report.txt # root for full access
```
### 独立运行 Windows 收集器
```
python windows\collect_windows.py
python windows\collect_windows.py --output C:\IR\case001
```
## 模拟入侵场景
`simulate/` 目录下的脚本会创建**无害的**测试 artifacts,这样你无需经历真实的安全事件即可运行该工具包并查看具有真实感的报告。
### Windows 模拟
```
# 植入 artifacts
python simulate\simulate_windows.py
# 检查创建的内容
python simulate\simulate_windows.py --status
# 收集并检查
python triage.py
# 完成后移除所有内容
python simulate\simulate_windows.py --cleanup
```
**将被植入的内容:**
- 可疑的 PowerShell 历史记录条目(侦察命令、被注释掉的下载 cradle)
- 位于 `%TEMP%\ir_simulation\` 中带有攻击者风格名称的文本文件(`recon_output.txt`、`implant_sim.ps1`、`c2_config.txt`)
- 一个无害的计划任务,它会将文本输出到日志文件中
### Linux 模拟
```
bash simulate/simulate_linux.sh # plant
bash simulate/simulate_linux.sh --status # verify
python3 triage.py # collect
bash simulate/simulate_linux.sh --cleanup # clean up
```
**将被植入的内容:**
- 可疑的 bash 历史记录条目(侦察、模拟的下载 cradle)
- 位于 `/tmp/ir_simulation/` 和 `/dev/shm/` 中的文件
- 一条被注释掉的 cron 条目(不会执行)
- `~/.ssh/authorized_keys` 中一条被注释掉的 SSH 密钥条目
## 理解输出结果
请首先打开 `triage/triage_/SUMMARY.txt` — 它列出了收集到的每一个 artifact 类别,并为你提供分析师后续步骤。
然后在完整报告中搜索危险信号:
| 关注点 | 重要性 |
|---|---|
| 从 `Temp`、`AppData`、`Public` 运行的进程 | 正规程序极少从这些路径运行 |
| 带有拼写错误的 `svchost` 或系统名称 | 名称伪装(例如 `svchost32.exe`) |
| Prefetch 中 `First Seen = Last Modified` 的新进程 | 在事件发生的窗口期内首次执行 |
| 大量事件 ID 4625 随后伴随 4624 | 暴力破解随后登录成功 |
| 事件 ID 4688 显示运行了 `net user`、`whoami`、`mimikatz` | 典型的攻击者侦察和凭证转储行为 |
| 具有模糊名称的计划任务(`WindowsUpdate`、`SecurityCacheSvc`) | 攻击者伪装成 Windows 组件 |
| 最近添加的 cron 条目或启动脚本 | 持久化行为 |
| SSH `authorized_keys` 被修改 | 攻击者添加了用于再次进入的 SSH 密钥 |
| 连接到非标准端口 (4444, 1234, 8080, 9999) | C2 回调 |
请参阅 `examples/example_triage_report.txt` 获取展示了所有这些指标带有注释的示例。
## 博客文章演练
### 场景
你收到一条告警:你环境中的一台 Windows 服务器在凌晨 2 点正在向端口 4444 上的一个未知 IP 建立出站连接。你需要快速对该主机进行分类,以确定影响范围和时间线。
### 第一步 — 明确需要收集的内容
在编写代码之前,SOC 分析师会从 artifact 类别的角度进行思考:
- **进程** — 正在运行的是什么,它来自哪里?
- **网络** — 是什么在与外界通信?
- **持久化** — 攻击者将如何在重启后存活?
- **时间线** — 这件事发生在什么时候,顺序如何?
- **账户** — 攻击者是否创建或提权了某个账户?
### 第二步 — 运行收集器
```
python triage.py
```
主封装脚本会自动检测 Windows,生成 `collect_windows.py`,实时流式传输输出,并将所有内容保存到带有时间戳的文件夹中。
### 第三步 — 首先阅读 Prefetch 部分
Prefetch 文件能准确告诉你**运行了什么以及何时运行的** — 即使二进制文件随后已被删除。按 `Last Modified`(最新优先)排序并查找:
- 从异常目录运行的程序
- 像 `mimikatz`、`psexec`、`procdump` 这样的工具
- 快速连续执行的侦察二进制文件(`whoami`、`net`、`ipconfig`、`netstat`)
### 第四步 — 与事件日志进行关联比对
将 Prefetch 时间戳与事件日志条目进行交叉比对:
- ID **4624** = 成功登录(谁登录了以及从哪里登录的?)
- ID **4625** = 失败登录(是否发生了暴力破解?)
- ID **4688** = 进程创建(他们运行了什么?)
- ID **4720** = 创建了新账户(后门?)
### 第五步 — 检查持久化
在报告中搜索在事件窗口期内出现的计划任务、注册表 Run keys 和启动文件夹条目。攻击者总是试图在系统重启后生存下来。
### 第六步 — 构建 IOC 列表
在审查结束时,你应该具备:
- **主机 IOC**:恶意文件路径、哈希值、攻击者用户账户
- **网络 IOC**:C2 IP 地址和端口
- **时间线**:逐分钟还原攻击过程
这些内容将用于你的事件工单、SIEM 规则调优以及威胁情报平台。
## 脚本参考
### `collect_linux.sh` — Bash,无依赖
| 部分 | 使用的命令 |
|---|---|
| 系统信息 | `uname`, `uptime`, `df`, `free` |
| 进程 | `ps aux`, `pstree`, `lsof -i` |
| 网络 | `ss`, `netstat`, `ip addr`, `arp`, `ip route` |
| 用户 | `/etc/passwd`, `who`, `w` |
| 登录历史 | `last`, `lastb` |
| 身份验证日志 | `/var/log/auth.log`, `/var/log/secure`, `journalctl` |
| Bash 历史记录 | `~/.bash_history`, `/root/.bash_history` |
| Cron | `crontab -l`, `/etc/cron.*`, `systemctl list-timers` |
| 持久化 | `systemctl list-unit-files`, `authorized_keys`, `/etc/profile.d` |
| 可疑文件 | `find` (SUID, world-writable, /tmp, /dev/shm) |
| 内核模块 | `lsmod` |
### `collect_windows.py` — Python 3,仅使用标准库
| 部分 | 使用的方法 |
|---|---|
| 系统信息 | `platform`, `systeminfo` |
| 进程 | `Get-Process`, `tasklist /svc`, `wmic` |
| 网络 | `netstat -ano`, `Get-NetTCPConnection`, `Get-DnsClientCache` |
| Prefetch | `os.scandir(C:\Windows\Prefetch)` |
| 事件日志 | `Get-WinEvent` (PowerShell) |
| 计划任务 | `schtasks`, `Get-ScheduledTask` |
| 启动/持久化 | `reg query`, 启动文件夹, `Get-Service`, WMI subscriptions |
| 用户 | `net user`, `Get-LocalUser` |
| PS 历史记录 | `ConsoleHost_history.txt` (所有用户) |
| 可疑文件 | 针对 Temp/AppData 使用 `Get-ChildItem`,ADS 检查 |
## 测试环境
- Windows 11 / Windows 10 Pro (Python 3.11, PowerShell 5.1)
- Ubuntu 22.04 LTS (Bash 5.1)
- Kali Linux 2024.1
## 作者
**Aditya Satam** — 有志成为 SOC 分析师
GitHub: [@aditya777-dev](https://github.com/aditya777-dev)
## 许可证
MIT 许可证 — 可免费使用、修改和分享,但需注明出处。
## 免责声明
本工具包仅供授权的应急响应和安全教育使用。请勿在你不拥有或未获得明确书面测试许可的系统上运行。所有模拟脚本仅创建无害的测试 artifacts。
标签:AI合规, HTTP工具, Mr. Robot, PB级数据处理, Windows 调试器, 安全运维, 库, 应急响应, 应用安全, 数字取证, 数字取证, 自动化脚本, 自动化脚本