elouahidiahmed/veripurge
GitHub: elouahidiahmed/veripurge
一款遵循 NIST SP 800-88 标准的 PowerShell 工具,用于经验证的 Windows 和 SharePoint Online 数据销毁,并自动生成带有数字签名与时间戳的销毁证明。
Stars: 1 | Forks: 0
# VeriPurge
📖 **English** · [Français](LISEZ-MOI.md)




**经过验证的清除**(针对取证证据)(**Windows** 工作站 + **SharePoint Online** 共享),并自动生成已签名且带有时间戳的**销毁证明**。
## 布局
```
veripurge/
├─ Invoke-Disposition.ps1 # orchestrator (Preview by default, Destroy with -Confirm)
├─ Verify-Certificate.ps1 # re-verifies hash + signature of an issued certificate
├─ New-SigningCertificate.ps1 # generates a self-signed X.509 cert / lists GPG keys
├─ config.example.json # copy to config.json and adapt
├─ modules/
│ ├─ LocalSanitize.psm1 # multi-pass overwrite + manifest (Windows host)
│ ├─ SharePointSanitize.psm1 # delete + empty recycle bins (SPO via PnP)
│ └─ Certificate.psm1 # JSON manifest + HTML certificate + CMS/GPG signature + RFC3161
└─ certificates/ # outputs (created at runtime, git-ignored)
```
## 环境要求
- **以管理员身份运行 PowerShell**(本地部分)。推荐使用 PowerShell **7+**(用于 RFC 3161 时间戳)。
- 对于 SharePoint:`Install-Module PnP.PowerShell -Scope CurrentUser`
- 关于签名:请参阅下方的**签名**部分。
## 为证书签名 (X.509 和/或 GPG)
JSON manifest(事实来源)通过 detached signature 进行密封。后端通过 `config.json` 中的 `signing.method` 进行选择:`"cms"`、`"gpg"` 或 `"both"`。
**a) X.509 / CMS (`.p7s`)** — 无需“机器”证书:在 `Cert:\CurrentUser\My` 中拥有带有私钥的证书即可。生成一个自签名证书(供内部使用):
```
.\New-SigningCertificate.ps1 -Type X509 # prints the thumbprint to paste
```
然后在 `config.json` 中设置:`method:"cms"`, `cms.certThumbprint:""`。
对于具有法律效力的证书,建议使用由您的**组织 PKI** 颁发的证书,或者使用 `.pfx` 文件(设置 `cms.pfxPath`;密码将从 `cms.pfxPasswordEnvVar` 指定的环境变量中读取,绝不以明文形式写在配置文件中)。
**b) GPG / OpenPGP (`.asc`)** — 在 DFIR 中推荐使用,密钥完全由您控制。需要安装 **Gpg4win**。查找/创建您的密钥:
```
.\New-SigningCertificate.ps1 -Type GPG # lists your secret keys
```
然后在 `config.json` 中设置:`method:"gpg"`, `gpg.keyId:""`。
`method:"both"` 将同时生成 `.p7s` **和** `.asc`。`Verify-Certificate.ps1` 会自动检查两者(CMS + `gpg --verify`)。
## 用法
```
# 0) 准备 config
Copy-Item .\config.example.json .\config.json
notepad .\config.json # caseId, paths, SPO site, authorization, signatories...
# 1) DRY RUN(始终优先执行)— 计算 hashes,不进行任何销毁
.\Invoke-Disposition.ps1 -ConfigPath .\config.json
# -> 打开 "PREVIEW MODE" HTML 证书并审查 inventory。
# 2) 真实销毁 — 提示您输入 "DETRUIRE" 进行确认
.\Invoke-Disposition.ps1 -ConfigPath .\config.json -Confirm
# 3) 稍后:重新验证证书的 integrity
.\Verify-Certificate.ps1 -ManifestPath .\certificates\COD-...manifest.json
```
## 内置安全防护
- **默认预览**:没有 `-Confirm` 且输入单词 `DETRUIRE` 的情况下不会进行任何销毁。
- 如果配置中 **`legalHoldActive = true`**,则**中止操作**。
- 如果未提供授权(`dispositionAuthorizationRef`),则**中止操作**。
- 在任何删除操作**之前**捕获 **SHA-256 + MD5** 哈希值。
- 销毁后验证(`Test-Path` → 文件不存在)。
## 每次运行生成的文件(位于 `outputDir` 中)
| 文件 | 用途 |
|---|---|
| `COD--.manifest.json` | 事实来源:元数据 + 清单 + 哈希值 |
| `COD--.manifest.json.p7s` | manifest 的 **Detached** PKCS#7/CMS 数字签名 |
| `COD--.manifest.json.asc` | Detached GPG/OpenPGP 签名(当使用 `gpg`/`both` 时) |
| `COD--.manifest.json.tsr` | RFC 3161 时间戳 token(需要 PowerShell 7+) |
| `COD--.certificate.html` | 人类可读/可打印的证书,用于会签 |
HTML 证书内嵌了 **manifest 的 SHA-256**:任何打印的副本在加密层面上都会与已签名的 manifest 保持绑定。
## ⚠ 各介质类型的局限性(需了解并记录)
- **磁性 HDD**:多遍覆写是有效的(符合 NIST *Purge* 标准)。
- **SSD / NVMe / USB 闪存盘**:磨损均衡 (wear-leveling) 使得逻辑覆写**无法得到保证**。
建议在卷级别使用 **ATA Secure Erase** / **NVMe Format**,或采用 **crypto-erase**(BitLocker:销毁密钥)。当需要彻底粉碎时 → 采用 NIST *Destroy*。
- **SharePoint Online**:您无法控制其物理存储。该脚本会删除并**清空两个阶段的回收站**,但 Microsoft 仍会保留**平台备份(约 14 天)**。
若要实现完全合同意义上的彻底消除,还需向 **Microsoft 提交正式的删除请求**。
这种残留的剩磁已在证书中特意予以记录。
## 运行后步骤
1. 让 HTML 证书完成**会签**(审查员 + 见证人)。
2. 将 manifest + 签名 + 证书归档至案件文件夹中(最好是 WORM/仅追加存储)。
3. 添加最终的**监管链**记录:`Disposition — — certificate ref`。
## 脚本编码
`.ps1`/`.psm1` 文件**必须**保持为 **UTF-8 with BOM** 格式:如果没有 BOM,Windows PowerShell 5.1 会将其作为 ANSI 读取,并导致重音字符出现乱码(在解析**和**运行时均会受影响)。
`.gitattributes` 会在这些文件上强制执行 `eol=crlf`;而 BOM 会由 git 原样保留。
## 贡献
请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。漏洞报告请遵循 [SECURITY.md](SECURITY.md)。
## 许可证
[MIT](LICENSE) © 2026 Ahmed Elouahidi.
标签:AI合规, IPv6, Libemu, PowerShell, SharePoint, Windows 运维, 合规清理, 子域名变形, 数字取证, 数据销毁, 自动化脚本