返回顶部
f

forensics-automation自动化取证

Automated Linux forensic collection and archival. Generate comprehensive system forensic reports (users, network, logs, processes, packages, disk usage, etc.) and automatically upload to Google Drive or email results. Use when you need to: (1) Quickly collect forensic data from a Linux system, (2) Archive forensic reports to Google Drive, (3) Automate forensic collection + sharing in one command, or (4) Build forensic automation into security workflows.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
109
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

forensics-automation

取证自动化技能

Linux系统取证数据的自动化收集与归档。

快速入门

前置条件

需一次性完成Google Drive API设置:

bash

1. 创建GCP项目并启用Google Drive API


2. 创建OAuth 2.0桌面应用凭据(JSON格式)


3. 运行一次性设置


python3 setup_gmail.py

按照OAuth流程操作,授权后粘贴返回的代码

令牌将保存至 ~/.gmail_tokens.json

基本用法

生成取证报告:
bash
bash linux_forensics.sh /tmp

创建:/tmp/forensicsYYYYMMDDHHMMSS.txt

上传至Google Drive:
bash
python3 uploadtodrive.py /tmp/forensics20260324180000.txt

返回:文件ID和可共享的Drive链接

一键操作:生成+上传:
bash
bash forensicsandupload.sh

一次性生成报告并上传

通过邮件发送取证数据:
bash
python3 send_email.py recipient@example.com 取证报告 报告已附上

收集内容

每份取证报告包含:

  • - 系统信息:内核版本、主机名、操作系统详情
  • 用户与组:所有用户账户、sudoers配置
  • 网络:IP地址、路由、监听端口、连接
  • 软件包:已安装软件(apt/rpm)
  • 进程:完整进程列表及参数
  • 系统日志:dmesg、认证日志、系统事件
  • 定时任务:所有用户的计划任务
  • 文件完整性:最近修改的文件(最近7天)
  • 磁盘使用:存储空间分布

脚本详情

linux_forensics.sh

核心取证收集脚本。

bash
bash linux_forensics.sh [输出目录]

示例

bash linux_forensics.sh /tmp

创建 /tmp/forensicsYYYYMMDDHHMMSS.txt(通常约300KB)

功能说明:

  • - 收集全面的系统信息
  • 执行只读命令(安全可执行)
  • 输出至带时间戳的文件,便于追踪
  • 最小依赖(bash、标准Unix工具)

forensicsandupload.sh

编排脚本:一键生成报告并上传至Drive。

bash
bash forensicsandupload.sh

一步完成取证收集与归档

包含2秒速率限制延迟,避免Google API限流

功能说明:

  • - 自动运行linux_forensics.sh
  • 获取最新报告
  • 等待2秒(速率限制)
  • 上传至Google Drive
  • 返回Drive链接

uploadtodrive.py

使用认证会话将任意文件上传至Google Drive。

bash
python3 uploadtodrive.py <文件路径> [文件夹ID]

示例

python3 uploadtodrive.py /tmp/report.txt python3 uploadtodrive.py /tmp/report.txt 1a2b3c4d5e6f7890 # 可选:上传至指定文件夹

返回内容:

  • - Drive上的文件名
  • 文件ID(用于API访问)
  • 可共享链接

send_email.py

通过Gmail API发送邮件。

bash
python3 send_email.py <收件人> <主题> <正文>

示例

python3 send_email.py analyst@company.com 取证报告已就绪 新取证数据已收集并上传至Drive

集成示例

安全运营中心(SOC)

自动化每日取证快照:

bash
#!/bin/bash

每日取证收集定时任务

cd /opt/forensics
bash forensicsandupload.sh

邮件通知安全团队

python3 send_email.py security@company.com \ 每日取证快照 \ 今日取证报告已收集并上传至Google Drive

事件响应

事件期间的快速取证收集:

bash
#!/bin/bash

事件响应脚本

INCIDENT_ID=INC-2026-003
bash linux_forensics.sh /tmp

上传并标记事件ID

REPORT=$(ls -t /tmp/forensics_*.txt | head -1) python3 uploadtodrive.py $REPORT

通知事件指挥官

python3 send_email.py commander@company.com \ 已收集取证数据:$INCIDENT_ID \ 来自 $REPORT 的取证数据已准备就绪,可供分析

合规与审计

月度取证审计:

bash
#!/bin/bash

月度审计任务

MONTH=$(date +%Y-%m)
bash linux_forensics.sh /var/forensics/$MONTH

归档至Drive

REPORT=$(ls -t /var/forensics/$MONTH/forensics_*.txt | head -1) python3 uploadtodrive.py $REPORT AUDITFOLDERID

设置与要求

1. Google Drive API设置(一次性)

bash

创建GCP项目并启用API:


- Google Drive API


- Gmail API(用于邮件集成)

创建OAuth 2.0桌面应用凭据

下载JSON凭据文件

放置于脚本目录或设置CREDS_FILE路径

2. 首次授权

bash
python3 setup_gmail.py

打开浏览器进行OAuth授权

按提示粘贴授权码

令牌保存至 ~/.gmail_tokens.json

3. 验证设置

bash

测试取证收集


bash linux_forensics.sh /tmp

测试Drive上传

python3 uploadtodrive.py /tmp/forensics_*.txt

测试邮件

python3 send_email.py your-email@example.com 测试 取证设置运行正常!

错误处理

常见问题

未找到令牌

请先运行setup_gmail.py进行授权

HTTP错误400:错误请求

刷新令牌可能已失效(约24小时过期)
重新运行setup_gmail.py再次授权

对/var/log的权限被拒绝

部分日志需要提升权限
脚本会优雅跳过不可访问的文件

Google API速率限制

forensicsandupload.sh包含2秒延迟
批量操作时,在上传之间添加sleep 5

性能说明

  • - 取证收集:约1-5秒(取决于系统负载)
  • 报告大小:通常约250-400KB
  • Drive上传:约2-5秒(取决于网络)
  • 邮件发送:约1-2秒
  • 一键操作总计:约10-15秒

安全考量

  1. 1. OAuth令牌存储在~/.gmail_tokens.json中——请确保安全(600权限)
  2. 刷新令牌支持长期自动化,无需重新认证
  3. 脚本为只读运行——不修改系统
  4. Drive链接可共享——请注意文件夹权限

自定义

扩展取证数据收集

编辑linux_forensics.sh添加自定义命令:

bash
echo === 自定义数据 === | tee -a $REPORT
your-command-here >> $REPORT

更改上传目标

指定Google Drive文件夹:

bash
python3 uploadtodrive.py report.txt FOLDER_ID

批量操作

上传多个报告:

bash
for file in /tmp/forensics_*.txt; do
python3 uploadtodrive.py $file
sleep 5 # 速率限制
done

参考

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 linux-forensics-automation-1776028975 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 linux-forensics-automation-1776028975 技能

通过命令行安装

skillhub install linux-forensics-automation-1776028975

下载

⬇ 下载 forensics-automation v1.0.0(免费)

文件大小: 3.54 KB | 发布时间: 2026-4-13 10:51

v1.0.0 最新 2026-4-13 10:51
Initial release of Linux Forensics Automation.

- Automates comprehensive forensic data collection from Linux systems.
- Generates detailed reports covering users, network, processes, logs, packages, and more.
- Supports automatic archival of forensic reports to Google Drive.
- Enables sending forensic reports via email through Gmail API.
- Provides single-command automation for collection and upload.
- Includes error handling, integration examples, and guidance for SOC, incident response, and auditing.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部