jeffersonferreira-ti/log_analyzer
GitHub: jeffersonferreira-ti/log_analyzer
一款基于 Python 的日志分析工具,通过启发式规则与风险评分自动化识别日志中的安全与运营问题。
Stars: 0 | Forks: 0
## 🧠 问题背景
日志包含关键证据 —— 但很难快速解读。
| 问题 | 影响 |
|---|---|
| 日志量巨大 | 分析困难 |
| 反复出现的故障被忽略 | 未检测到的事件 |
| 孤立事件缺乏上下文 | 诊断不准确 |
| 缺乏关联性 | 视野碎片化 |
## 🚀 解决方案
**Log Analyzer v2.0** 将日志转化为结构化的调查分析。
除了检测模式外,该系统现在还可以:
- 构建 **事件时间线**
- 解释 **风险驱动因素**
- 识别 **多来源间的关联**
- 组织数据以进行真正的 **故障排除**
## ⚙️ Pipeline
```
Logs → Ingestão → Parser → Heurísticas → Score → Classificação → Investigação → JSON Report
```
## 🔍 功能特性
### 📂 日志接入
- 读取 `.log` 和 `.txt`
- 支持多文件
- 故障处理
### 🧩 智能解析
支持真实日志:
- Linux 认证日志 (`auth.log`, `secure`)
- Apache/Nginx 日志
- 导出的 Windows 日志
- 通用兜底
提取内容:
- 时间戳
- 级别
- 消息
- IP
### 🧠 启发式分析
检测:
- `repeated_failed_logins`
- `repeated_errors`
- `suspicious_ip_activity`
- `critical_events_present`
- `excessive_warning_or_error_volume`
### 📊 风险评分
| 分数 | 分类 |
|---|---|
| 0–19 | NORMAL |
| 20–49 | ATTENTION |
| 50–79 | SUSPICIOUS |
| 80+ | CRITICAL |
## 🧪 真实用例
### 📌 场景
环境包含:
- 反复的 SSH 登录失败
- 反复出现的应用程序错误
- 关键系统事件
- 可疑的 IP 活动
### 📊 结果
```
Total Score: 91
Classification: CRITICAL
🧠 Análise Investigativa
📅 Timeline Highlights
3x Database connection failed between 10:01:15 and 10:01:20
3x Failed login from 192.168.1.50 between 10:01:22 and 10:01:42
CRITICAL Unexpected system reboot detected
⚠️ Risk Drivers
Repeated SSH authentication failures from a single IP suggest possible brute-force activity
Recurring application errors indicate persistent instability
A critical system event significantly increased overall risk
High volume of warning/error events suggests broader instability
🔗 Correlations
IP 192.168.1.50 is strongly associated with authentication failures
Authentication failures occurred close to a critical system event
Database errors were detected before system instability
Events cluster temporally before the reboot
```
## 🧾 JSON 报告 (v2.0)
包括:
- 总体分析
- Top IP
- Top 错误
- 按文件分组
- 事件时间线
- 风险驱动因素
- 事件间的关联性
简要示例:
```
{
"analysis_summary": {
"total_score": 91,
"classification": "CRITICAL"
},
"timeline_highlights": [
"3x Failed login from 192.168.1.50 between 10:01:22 and 10:01:42"
],
"risk_drivers": [
"Repeated SSH authentication failures from a single IP suggest possible brute-force activity."
],
"correlations": [
{
"type": "ip_correlation",
"description": "IP 192.168.1.50 appears repeatedly in authentication failures and is a likely source of suspicious activity."
}
]
}
```
## 🖥️ CLI
```
python main.py
```
选项:
```
python main.py --source ./data/samples
python main.py --summary-only
python main.py --no-report
python main.py --output ./reports/analysis.json
```
## 🏗️ 架构
```
log_analyzer/
├── app/
│ ├── ingestor/
│ ├── parser/
│ ├── analyzer/
│ ├── reporting/
│ └── models/
├── data/
│ ├── samples/
│ └── output/
├── main.py
├── config.py
└── requirements.txt
```
## ⚠️ 局限性
- 不替代 SIEM
- 启发式方法简单
- 无高级关联
- 非持续性(批处理分析)
## 🗺️ 路线图
| 版本 | 重点 | 状态 |
|---|---|---|
| v1.0 | 核心 | ✅ |
| v1.1 | 评分 | ✅ |
| v1.2 | JSON + CLI | ✅ |
| v1.3 | 真实日志 | ✅ |
| v1.4 | 丰富的 JSON | ✅ |
| v2.0 | 调查(时间线 + 驱动因素 + 关联性) | ✅ |
| v2.1 | 持续监控 | 💡 |
## 🎯 目标
展示:
- 真实场景下的日志分析
- 识别运营和安全模式
- 事件关联性
- 调查推理
## 🧩 事件摘要
此分析表明了一种场景:
- 反复的身份验证失败暗示存在潜在的暴力破解活动
- 反复出现应用程序错误表明服务不稳定
- 在这些问题发生后不久,出现了一个关键系统事件(重启)
总而言之,这些信号指向一个 **具有安全性和稳定性双重隐患的高风险运营事件**。
## 👨💻由 **Jefferson Ferreira** 开发。
[](https://www.linkedin.com/in/jefferson-ferreira-ti/)
[](https://github.com/jeffersonferreira-ti)
Log Analyzer v2.0 · 2026
标签:Python, 安全运营, 异常检测, 扫描框架, 无后门, 日志分析, 运维监控, 风险评估