Building incident timeline with timesketch

From killvxk/cybersecurity-skills-zh · View interactive version

Building incident timeline with timesketch is an AI agent skill from the GitHub repository killvxk/cybersecurity-skills-zh. 使用 Timesketch 构建协作式取证事件时间线,对多源事件数据进行摄入、规范化和分析,用于攻击链重建和调查文档化。

How to use this skill

Skill file

使用 Timesketch 构建事件时间线

概述

Timesketch 是由 Google 开发的开源协作式取证时间线分析工具,使安全团队能够在事件调查期间可视化和分析来自多个来源的按时间顺序排列的数据。它摄入来自端点、服务器和云服务的日志和制品(Artifact),将其规范化为统一的可搜索时间线,并提供强大的分析能力,包括内置分析器、打标签(Tagging)、素描(Sketch)注释和故事构建。Timesketch 与 Plaso(log2timeline)集成进行制品解析,并支持直接 CSV/JSONL 摄入以在主动事件期间快速构建时间线。

架构与组件

核心组件

数据流

证据来源 --> Plaso/log2timeline --> Plaso 存储文件 (.plaso)
     |                                           |
     v                                           v
  CSV/JSONL --> Timesketch 导入器 --> OpenSearch 索引
                                           |
                                           v
                                    Timesketch Web UI
                                    (搜索、分析、故事)

部署

Docker 部署(推荐)

# 克隆 Timesketch 仓库
git clone https://github.com/google/timesketch.git
cd timesketch

# 运行部署辅助脚本
cd docker
sudo docker compose up -d

# 默认访问:https://localhost:443
# 首次运行时生成管理员凭据

系统要求

数据摄入方法

方法 1:Plaso 集成(全面)

# 使用 log2timeline 处理磁盘镜像
log2timeline.py --storage-file evidence.plaso /path/to/disk/image

# 处理 Windows 事件日志
log2timeline.py --parsers winevtx --storage-file windows_events.plaso /path/to/evtx/

# 处理多个证据来源
log2timeline.py --parsers "winevtx,prefetch,amcache,shimcache,userassist" \
  --storage-file full_analysis.plaso /path/to/mounted/image/

# 将 Plaso 文件导入 Timesketch
timesketch_importer -s "Case-2025-001" -t "Endpoint-WKS01" evidence.plaso

方法 2:CSV 导入(快速摄入)

message,datetime,timestamp_desc,source,hostname
"User login detected","2025-01-15T08:30:00Z","Event Recorded","Security Log","DC01"
"PowerShell execution","2025-01-15T08:31:15Z","Event Recorded","PowerShell","WKS042"
# 直接导入 CSV
timesketch_importer -s "Case-2025-001" -t "Quick-Triage" events.csv

方法 3:JSONL 导入(结构化数据)

{"message": "Suspicious logon from 10.1.2.3", "datetime": "2025-01-15T08:30:00Z", "timestamp_desc": "Event Recorded", "source_short": "Security", "hostname": "DC01"}

方法 4:Sigma 规则集成

# 上传 Sigma 规则用于自动检测
timesketch_importer --sigma-rules /path/to/sigma/rules/

分析工作流程

步骤 1:创建调查素描(Sketch)

1. 登录 Timesketch Web 界面
2. 创建新素描(调查案例)
3. 将相关时间线添加到素描中
4. 设置素描描述和标签

步骤 2:运行内置分析器

Timesketch 包含自动识别以下内容的分析器:

步骤 3:搜索和过滤

# Timesketch 查询语言中的搜索示例

# 查找与特定用户相关的所有事件
source_short:Security AND message:"john.admin"

# 查找 PowerShell 执行事件
data_type:"windows:evtx:record" AND event_identifier:4104

# 查找横向移动(Lateral Movement)指标
source_short:Security AND event_identifier:4624 AND xml_string:"LogonType\">3"

# 在特定时间范围内查找事件
datetime:[2025-01-15T00:00:00 TO 2025-01-15T23:59:59]

# 查找文件创建事件
data_type:"fs:stat" AND timestamp_desc:"Creation Time"

# 按标签搜索
tag:"suspicious" OR tag:"lateral_movement"

步骤 4:构建调查故事

1. 在素描中创建新故事
2. 添加支持每个发现的搜索视图
3. 用调查员注释标注关键事件
4. 将事件链接到 MITRE ATT&CK 技术
5. 按时间顺序记录攻击叙事
6. 导出故事以纳入事件报告

高级功能

协作调查

API 自动化

from timesketch_api_client import config
from timesketch_api_client import client as ts_client

# 连接到 Timesketch
ts = ts_client.TimesketchApi(
    host_uri="https://timesketch.local",
    username="analyst",
    password="password"
)

# 获取素描
sketch = ts.get_sketch(1)

# 搜索事件
search = sketch.explore(
    query_string='event_identifier:4624 AND LogonType:3',
    return_fields='datetime,message,hostname,source_short'
)

# 为事件添加标签
for event in search.get('objects', []):
    sketch.tag_event(event['_id'], ['lateral_movement'])

与 Dissect 集成

# 使用 Dissect 进行更快的制品解析(Plaso 的替代方案)
target-query -f timesketch://timesketch.local/case-001 \
  targets/hostname/ -q "windows.evtx" --limit 0

时间线构建的关键数据源

| 来源 | 解析器 | 取证价值 |

|--------|--------|---------------|

| Windows 事件日志(.evtx) | winevtx | 认证、进程执行、服务 |

| Prefetch 文件 | prefetch | 程序执行历史 |

| MFT ($MFT) | mft | 文件系统活动 |

| 注册表配置单元 | winreg | 系统配置、持久化(Persistence) |

| 浏览器历史 | chrome/firefox | Web 活动、下载 |

| Syslog | syslog | Linux/网络设备事件 |

| CloudTrail 日志 | jsonl | AWS API 活动 |

| Azure 活动日志 | jsonl | Azure 资源操作 |

| 防火墙日志 | csv/jsonl | 网络连接 |

| 代理日志 | csv/jsonl | HTTP/HTTPS 流量 |

MITRE ATT&CK 映射

| 技术 | 时间线指标 |

|-----------|-------------------|

| 初始访问(TA0001) | 第一个恶意事件、钓鱼邮件接收 |

| 执行(T1059) | PowerShell/CMD 事件、进程创建 |

| 持久化(TA0003) | 注册表修改、计划任务、服务 |

| 横向移动(TA0008) | 远程登录、SMB 连接、RDP 会话 |

| 数据外泄(TA0010) | 大量数据传输、云存储上传 |

参考资料

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.