REstorninho/IR-Collector
GitHub: REstorninho/IR-Collector
一个全自动的Windows事件响应脚本,集成了多种取证和威胁狩猎工具,用于快速收集证据和生成报告。
Stars: 0 | Forks: 0
# REDCELL IR 收集器
**Windows 事件响应 PowerShell 脚本 — v2.8**
一个完全自动化的 Windows 取证收集脚本。配置系统以最大化可见性,执行结构化的工件收集,运行威胁狩猎工具,并生成带有风险评分的 HTML 报告。
## 要求
| 要求 | 详情 |
|---|---|
| PowerShell | 5.1+ |
| 权限 | 管理员(必需) |
| 操作系统 | Windows 10/11, Windows Server 2016+ |
| 网络 | 可选 — 若可用,则自动下载工具 |
## 快速开始
```
# 1. 以管理员身份打开 PowerShell
# 2. 导航到脚本所在的文件夹
cd C:\IR
# 3. 运行
.\IR-Collector.ps1
```
脚本会自动检测并下载缺失的工具,进行内存转储,配置系统,并无需交互地运行所有阶段。
## 文件夹结构
脚本可放置在任意位置。所有路径均相对于脚本目录 (`$PSScriptRoot`)。
```
IR-Collector.ps1 ← script principal
tools\ ← ferramentas IR (auto-download)
hayabusa.exe
chainsaw.exe
loki.exe
yara64.exe
procexp64.exe
winpmem_mini_x64.exe
Sysmon64.exe
mappings\ ← Chainsaw mappings (auto-download)
rules\ ← Chainsaw Sigma rules (auto-download)
memdump.raw ← memory dump (gerado automaticamente)
Reports\
_\
IR-Report.html ← relatório HTML
IR-ErrorReport.txt ← erros e avisos
ir_execution.log ← log completo
00_setup\ ← audit policy, sysmon config, detections
01_live\ ← processos, serviços, pipes, conexões
02_eventlogs\ ← EVTX + CSVs de eventos críticos
03_registry\ ← hives + keys de persistência
04_artifacts\ ← Prefetch, Amcache, PSTranscripts, ADS, WMI
05_network\ ← interfaces, firewall, proxy, hosts, wifi
06_users\ ← NTUSER, browser history, downloads
07_kape\ ← output KAPE (se disponível)
08_network2\ ← conexões enriquecidas GeoIP/ASN
09_hunting\ ← Hayabusa, Chainsaw, Loki, YARA, Volatility
```
## 执行阶段
### 系统配置
| 阶段 | 描述 |
|---|---|
| **0 — 审计策略** | 配置完整的高级审计策略。若无此阶段,`Security.evtx` 对 IR 无用。会备份之前的策略。 |
| **0A — PS 日志记录** | 启用 ScriptBlock 记录(事件ID 4104)、模块记录(事件ID 4103)和会话记录到 `C:\PSTranscripts`。 |
| **0B — Sysmon** | 安装或更新 Sysmon64,使用基于 SwiftOnSecurity 的嵌入式配置。支持通过 `-SysmonConfig` 指定自定义配置。 |
| **0C — LOLBins** | 检查 35 个关键系统二进制文件(LOLBins)的数字签名。检测替换/篡改。 |
| **0D — Defender** | 记录 Windows Defender 状态、定义版本和运行模式。检测明文凭据的 AutoLogon。 |
| **0E — 服务器角色** | 自动检测系统角色(工作站、DC、Exchange、SQL、IIS 等),以适应收集过程。 |
| **0F — 入侵检测** | 在主要收集前运行入侵指标检测器。 |
### 入侵检测器(阶段 0F)
| 检测器 | 检测内容 |
|---|---|
| **A1 — Pass-the-Hash/Ticket** | 类型 3/9 的异常无密码登录(事件ID 4624/4625) |
| **A2 — LSASS 访问** | 进程访问 LSASS 进行凭据转储(Sysmon 事件ID 10) |
| **A3 — 可疑服务** | 名称/二进制文件可疑的已安装服务(事件ID 7045) |
| **A4 — 日志清除** | 清除事件日志(事件ID 1102/104) — 证据被销毁 |
| **A6 — RDP 暴力破解** | IP 多次 RDP 认证失败(事件ID 4625) |
| **A7 — SMB 横向移动** | 可疑访问管理共享(C$, ADMIN$) |
| **B1 — 父子关系异常** | 异常的父子关系(例如:Word → PowerShell) |
| **B2 — 网络信标** | 来自脚本/Office 进程的网络连接 |
| **B3 — 进程空洞化** | 进程路径与预期名称不符 |
### 取证收集
| 阶段 | 收集内容 |
|---|---|
| **1 — 现场分类** | 进程、进程树、连接、服务、驱动程序、用户、会话、计划任务、自启动项、SMB、ARP/DNS、命名管道、卷影副本 |
| **2 — 事件日志** | 15 个 EVTX 通道(Security、System、Sysmon、PowerShell、RDP、SMB、WMI、Defender、BITS、DNS 等)+ 关键事件ID 的 CSV |
| **3 — 注册表** | SYSTEM/SOFTWARE/SAM/SECURITY 配置单元 + 运行键、IFEO、AppInit_DLLs、UserAssist |
| **4 — 工件** | Prefetch、Amcache、PS 历史记录、PS 会话记录、LNK、ADS、WMI 仓库 + 订阅 |
| **5 — 网络** | 接口、路由、防火墙规则、代理、hosts 文件、WiFi 配置文件 |
| **6 — 用户** | NTUSER.DAT、浏览器历史记录(Chrome/Edge/Firefox)、最近 30 天下载记录 |
| **7 — KAPE** | 若存在,通过 KAPE 进行额外收集(targets + Zimmerman 模块) |
| **8 — 进程浏览器 + 增强网络** | 带有 GeoIP、反向 DNS、ASN、进程签名的外部连接 |
| **9 — 威胁狩猎** | Hayabusa、Chainsaw、Loki、YARA、Volatility 3、威胁情报(URLhaus) |
### 威胁狩猎工具(阶段 9)
| 工具 | 功能 | 自动下载 |
|---|---|---|
| **Hayabusa** | 使用 Sigma 规则生成 EVTX 事件时间线 | ✅ GitHub |
| **Chainsaw** | Hunt Sigma + 在 EVTX 上进行关键字搜索 | ✅ GitHub(含规则和映射) |
| **Loki** | 基于 YARA/哈希的 IOC 扫描器 | ✅ GitHub |
| **YARA** | 对可疑可执行文件进行模式匹配 | ✅ GitHub |
| **Volatility 3** | 内存转储取证分析(pslist、malfind、netscan 等) | ✅ GitHub(`vol.exe` 独立版或 `vol.py` + Python) |
| **Process Explorer** | 静默在系统托盘启动(通过注册表接受 EULA 和 VT) | ✅ Sysinternals |
| **威胁情报** | 对照 URLhaus + MalwareBazaar 订阅源查询 IP/域名 | — (在线订阅源) |
## 标志
### 跳过阶段
```
-SkipMemory # não faz memory dump automático
-SkipAuditPolicy # não altera Audit Policy nem PS Logging
-SkipSysmon # não instala/actualiza Sysmon
-SkipLOLBins # salta integrity check de binários
-SkipProcExp # não lança Process Explorer
-SkipProcExpInteractive # não lança ProcExp no tray
-SkipHunting # salta Fase 9 (todas as ferramentas de hunting)
-SkipHeavy # salta Fase 8 + Fase 9 (poupa RAM/CPU)
-NoKape # ignora KAPE mesmo que presente
-NoHTMLReport # não gera IR-Report.html
-NoCompress # não comprime evidence package em ZIP
```
### 配置
```
-SysmonConfig "path\custom.xml" # config Sysmon custom
-NoAutoDownload # não descarrega ferramentas em falta
-SkipUpdate # não actualiza regras (usa locais)
-ForceUpdate # força update de todas as regras
-SingleThread # desactiva paralelismo (debug)
-PrepareKit # prepara ferramentas sem correr coleta
```
### Velociraptor 上传
```
-VeloUpload # activa upload automático
-VeloServer "https://192.168.1.10:8000"
-VeloToken "eyJ..."
-VeloOrgId "root" # default: root
```
### 示例
```
# 4. 完整收集(推荐)
.\IR-Collector.ps1
# 5. 快速收集(无需重型工具)
.\IR-Collector.ps1 -SkipHeavy -NoCompress
# 6. 不更改系统设置
.\IR-Collector.ps1 -SkipAuditPolicy -SkipSysmon -SkipMemory
# 7. 无网络环境 – 使用已有工具
.\IR-Collector.ps1 -NoAutoDownload -SkipUpdate
# 8. 自定义 Sysmon 配置
.\IR-Collector.ps1 -SysmonConfig "D:\configs\sysmon_strict.xml"
# 9. 完整收集 + 上传至 Velociraptor
.\IR-Collector.ps1 -VeloUpload -VeloServer "https://192.168.1.10:8000" -VeloToken "eyJ..."
```
## 可选工具
脚本会在首次执行时尝试自动下载所有工具(需要网络)。也可手动放置到 `tools\` 目录。
| 工具 | 手动下载 | 备注 |
|---|---|---|
| Hayabusa | [github.com/Yamato-Security/hayabusa](https://github.com/Yamato-Security/hayabusa/releases) | 包含规则的 `win-x64` 版本 |
| Chainsaw | [github.com/WithSecureLabs/chainsaw](https://github.com/WithSecureLabs/chainsaw/releases) | 完整 ZIP(含 `rules\` 和 `mappings\`) |
| Loki | [github.com/Neo23x0/Loki](https://github.com/Neo23x0/Loki/releases) | |
| YARA | [github.com/VirusTotal/yara](https://github.com/VirusTotal/yara/releases) | `yara64.exe` |
| Volatility 3 | [github.com/volatilityfoundation/volatility3](https://github.com/volatilityfoundation/volatility3/releases) | `vol.exe`(独立版)或 `vol.py` + Python 3 |
| winpmem | [github.com/Velocidex/WinPmem](https://github.com/Velocidex/WinPmem/releases) | 用于自动内存转储 |
| KAPE | [kroll.com/kape](https://www.kroll.com/en/services/cyber-risk/incident-response-litigation-support/kroll-artifact-parser-extractor-kape) | 需手动注册 |
## 输出
执行完成后将生成:
| 文件 | 描述 |
|---|---|
| `IR-Report.html` | 完整报告,包含风险评分、检测结果、时间线和按阶段汇总 |
| `IR-ErrorReport.txt` | 所有错误和警告的带时间戳列表 |
| `ir_execution.log` | 所有执行操作的详细日志 |
| `_.zip` | 完整的证据包(含 SHA256) |
| `manifest_sha256.csv` | 监管链 — 所有收集文件的 SHA256 哈希 |
## 安全说明
- 脚本会为 IR 工具在 Windows Defender 中创建临时排除项,并在结束时**自动移除它们**,即使在出错或中断的情况下(`finally` 块)
- 不会移除已有的排除项
- 脚本在结束时会检查 Defender 状态,并在实时保护被禁用时发出警报
- 所有生成的文件都包含用于监管链的 SHA256 哈希
## 更新日志
| 版本 | 更改 |
|---|---|
| **2.8** | 所有块(KAPE、Hayabusa、Chainsaw、Loki)中的 `$args` 重命名为 `$cmdArgs` — 避免与 PowerShell 自动变量冲突;Hayabusa `--min-level` 从 `informational` 改为 `low`(将 CSV 减少约 10 倍,从约 360MB 降至约 40MB);Loki 使用 `RedirectStandardError` 以避免长时间扫描时缓冲区阻塞 |
| **2.7** | 修复 Volatility 阻塞问题 — 用带 `RedirectStandardOutput`/`RedirectStandardError` 的 `Start-Process` 替换 `& $volCmd 2>$null`;移除 `$volArgs` 脚本块;每个插件通过正确排空 stdout 和 stderr 的 `Invoke-VolPlugin` 运行 |
| **2.6** | 自动下载 Chainsaw 映射;从 ZIP 中提取 `rules\` 和 `mappings\`;通过 winpmem 自动进行内存转储;保护 `$PSScriptRoot` 以便在任何位置执行 |
| **2.5** | 支持 Volatility 中独立的 `vol.exe`;修复注册表中 ProcExp 使用完整路径;无需交互接受 VT 服务条款 |
| **2.4** | 修复 Process Explorer 弹出窗口问题;Chainsaw `--mapping` 必需并有保护 |
| **2.3** | 移除 IR-Monitor;修复 Hayabusa 的 NDJSON 解析 |
标签:AI合规, AMSI绕过, Conpot, IPv6, IR脚本, Libemu, PowerShell, Ruby on Rails, Windows安全, 事件日志, 事件日志分析, 入侵响应, 内存转储, 取证工具, 威胁检测, 安全报告, 数字取证, 数字取证, 服务监控, 注册表分析, 系统配置, 网络安全, 自动化取证, 自动化脚本, 自动化脚本, 进程分析, 隐私保护, 风险评分