蜜罐日志与攻击画像:结构化日志、特征抽取与可视化流程

3 阅读2分钟

导语

日志不是目的,情报才是。要把 attack_logger/persist 的输出转成可搜索、可报警、可视化的情报流。


目录

  1. 事件模型与字段说明
  2. 特征抽取规则(规则化特征)
  3. 攻击画像:向量化与分类方法
  4. 可视化与示例脚本(Pandas)
  5. 报警策略与联动机制

1. 事件模型与字段(必须)

统一事件字段(JSON):

  • session_id, protocol, event_type(auth_attempt/command/file_access/interaction/request)
  • time, remote_ip, remote_port, username, command, file_path, raw_base64, meta

示例:

{"session_id":"...","protocol":"ssh","event_type":"command","time":"...","remote_ip":"x.x.x.x","command":"wget http://..."}

2. 特征抽取规则(可实现)

  • 扫描特征:短时间内同源访问大量路径或端口 -> num_unique_paths / num_ports
  • 爆破特征:重复认证尝试短时间高频 -> auth_attempts_per_minute
  • 交互式行为:存在 wget|curl|cat /etc/passwd|chmod 等命令 -> interactive_flag=1
  • 文件探查:大量 RETR/STOR 或访问 /etc -> file_probe_score

3. 攻击画像(向量化与分类)

为每个 remote_ip 生成向量:

V = [num_ports_scanned, num_auth_attempts, commands_entropy, interactive_ratio, time_span_hours]

基于阈值或简单聚类(KMeans)分为:scanner / brute_forcer / intruder / noisy_bot。


4. 可视化与示例脚本(Pandas)

示例:统计每小时 auth attempts

import pandas as pd
df = pd.read_json("events.jsonl", lines=True)
df['time'] = pd.to_datetime(df['time'])
hourly = df[df.event_type=='auth_attempt'].set_index('time').resample('H').size()
print(hourly.tail())

建议图表:Top IPs、时间序列、协议占比、命令词云、地理分布(IP->geo)。


5. 报警策略与联动

  • 阈值告警:同一 IP 在 5 分钟内 auth_attempts > 50 -> 报警并临时封锁(防火墙规则)。
  • 横向关联告警:同一 IP 在不同协议上出现交互式命令 -> 升级为高优先级告警。
  • 自动化响应:告警触发后 snapshot 会话、导出原始 raw_base64、并推送 SOC 工单。