kosijustice/-OpenSSH-Log-Analysis-Splunk-SIEM-Security-Monitoring
GitHub: kosijustice/-OpenSSH-Log-Analysis-Splunk-SIEM-Security-Monitoring
一个完整的 SOC 实战项目,演示如何使用 Splunk Enterprise 对 OpenSSH 日志进行摄取、威胁检测、仪表板监控和自动告警配置的端到端流程。
Stars: 0 | Forks: 0
# -OpenSSH-日志分析-Splunk-SIEM-安全监控
一个真实的 SOC 分析师项目,涵盖使用 Splunk Enterprise 进行日志摄取、威胁检测、仪表板创建、自动告警和字段提取。
\d+\.\d+\.\d+\.\d+)` |
### 正则表达式工作原理
```
Raw log line:
Dec 10 06:55:52 LabSZ sshd[24200]: Received disconnect from 183.62.140.253: 11: Bye Bye [preauth]
↑
regex captures this IP address
Extracted field:
src_ip = 183.62.140.253
```
### 验证查询
```
index=main | rex "from (?P\d+\.\d+\.\d+\.\d+)" | stats count by src_ip | sort -count
```
**预期输出:**
| src_ip | count |
|--------|-------|
| 183.62.140.253 | 5 |
| 112.95.230.3 | 2 |
## 🚨 安全发现
### 威胁汇总表
| # | 严重性 | 威胁类型 | 源 IP | 事件数 | 状态 |
|---|----------|-------------|-----------|-------------|--------|
| 1 | 🔴 **严重** | 已确认的 Root 登录 | `112.95.230.3` | 1 | **立即升级** |
| 2 | 🟠 **高** | 暴力破解 — 密码失败 | `183.62.140.253` | 5+ | 监控中 |
| 3 | 🟠 **高** | 撞库 — 无效用户 | `183.62.140.253` | 3+ | 监控中 |
| 4 | 🟡 **中** | 反复的 Preauth 断开连接 | `112.95.230.3` | 6 | 仪表板面板实时监控 |
### 📸 图 6 — 攻击时间轴 (时间图表)
### 攻击流程图
```
ATTACKER 1: 183.62.140.253
─────────────────────────────────────────────────────────
06:55 AM → Invalid user "test" FAILED ✗
06:55 AM → Failed password FAILED ✗
06:55 AM → Disconnect (preauth) SESSION DROPPED
07:15 AM → Failed password for root FAILED ✗
07:20 AM → Failed password for root FAILED ✗
07:25 AM → Failed password for root FAILED ✗
──────────────────────────────────────
VERDICT: Brute force attack — blocked
ATTACKER 2: 112.95.230.3
─────────────────────────────────────────────────────────
07:02 AM → Invalid user "admin" FAILED ✗
07:02 AM → Failed password FAILED ✗
07:02 AM → Disconnect x3 (preauth) SESSION DROPPED
07:10 AM → Accepted password for ROOT SUCCESS ✅ ⚠️ BREACH
──────────────────────────────────────
VERDICT: CONFIRMED COMPROMISE — root access granted
```
## 📁 SPL 查询参考
### 核心分析查询
```
# 1. 查看所有已索引的事件
index=main sourcetype=syslog
# 2. 按源 IP 统计的密码尝试失败记录
index=main "Failed password"
| rex "from (?P\d+\.\d+\.\d+\.\d+)"
| stats count by src_ip
| sort -count
# 3. 按源 IP 统计的无效用户尝试
index=main "Invalid user"
| rex "from (?P\d+\.\d+\.\d+\.\d+)"
| stats count by src_ip
| sort -count
# 4. 成功登录 — 关键查询
index=main "Accepted password"
| table _time, host, src_ip, user
# 5. Dashboard 面板查询
index=main "Received disconnect from 112.95.230.3: 11: Bye Bye [preauth]"
# 6. 按 IP 统计的攻击时间线
index=main ("Failed password" OR "Invalid user")
| timechart count by src_ip
# 7. 验证字段提取
index=main
| rex "from (?P\d+\.\d+\.\d+\.\d+)"
| stats count by src_ip
# 8. 所有可疑事件组合
index=main ("Failed password" OR "Invalid user" OR "Received disconnect" OR "Accepted password")
| table _time, host, src_ip, sourcetype
| sort _time
```
## 🛡️ 建议
### 立即行动 (0–30 天)
```
# 1. 在防火墙封锁攻击 IP
sudo ufw deny from 183.62.140.253
sudo ufw deny from 112.95.230.3
# 2. 禁用 root SSH 登录
sudo nano /etc/ssh/sshd_config
# 更改:PermitRootLogin yes → PermitRootLogin no
sudo systemctl restart sshd
# 3. 强制仅使用 SSH 密钥认证
# 在 /etc/ssh/sshd_config 中:
# PasswordAuthentication no
# PubkeyAuthentication yes
# 4. 安装 Fail2Ban 以实现自动化 IP 封锁
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
```
### 短期 (30–90 天)
| 行动 | 工具 | 优先级 |
|--------|------|----------|
| 部署内容安全策略 | Nginx config | 高 |
| 启用 HSTS | `add_header Strict-Transport-Security` | 高 |
| 仅强制使用 TLS 1.2/1.3 | `ssl_protocols TLSv1.2 TLSv1.3` | 高 |
| 添加 X-Frame-Options 头 | Nginx config | 中 |
| 加固 SSH 密码套件 | `sshd_config` | 中 |
| 每月自动修补 | Ansible playbook | 中 |
### 长期 (90 天以上)
- 建立具有 SLA 的正式 **漏洞管理计划**:
- 严重 → 24 小时
- 高 → 7 天
- 中 → 30 天
- 低 → 90 天
- 将 Splunk 与 **Wazuh 或 Elastic SIEM** 集成,以获取扩展的遥测数据
- 计划 **每周 Nessus 凭证扫描**,以实现持续覆盖
- 进行外部 **渗透测试**,以验证控制措施的有效性
- 在所有 SSH 访问上实施 **MFA**(硬件密钥 + TOTP)
## 🔑 关键要点
```
✅ Splunk successfully ingested 18 OpenSSH log events and enabled full SPL analysis
✅ Identified two distinct attacking IPs with different TTPs
✅ Confirmed a root-level compromise from 112.95.230.3 — highest severity finding
✅ Built a live dashboard monitoring disconnect events in real-time
✅ Configured daily automated alerts with email delivery and threshold triggers
✅ Implemented src_ip field extraction enabling IP-based analytics across all searches
✅ Delivered complete executive report with supporting screenshots for stakeholders
⚠️ Root login from 112.95.230.3 requires immediate forensic investigation
```
## 🗂️ 仓库结构
```
openssh-splunk-siem-analysis/
│
├── README.md ← This file (full project documentation)
│
├── logs/
│ └── openssh_logs.log ← Sample OpenSSH log file used for analysis
│
├── screenshots/
│ ├── 01_all_events_indexed.png ← Figure 1: 18 events in Splunk
│ ├── 02_failed_password_search.png ← Figure 2: Failed password & invalid user results
│ ├── 03_accepted_password.png ← Figure 3: Critical root login confirmed
│ ├── 04_disconnect_search.png ← Figure 4: 6 disconnect events from 112.95.230.3
│ ├── 05_dashboard.png ← Figure 5: Live OpenSSH monitoring dashboard
│ └── 06_timechart.png ← Figure 6: Attack timeline visualization
│
├── queries/
│ └── spl_queries.txt ← All SPL queries used in this project
│
├── config/
│ └── alert_actions.conf ← Splunk email domain restriction config
│
└── report/
└── Splunk_Security_Report_Final.docx ← Full executive submission report
```
## 🧰 工具与技术
## | 工具 | 版本 | 用途 |
|------|---------|---------|
|  **Splunk Enterprise** | 9.1.6 | SIEM 平台 — 日志摄取、搜索、告警、仪表板 |
|  **Kali Linux** | 2025.1c | 宿主操作系统 |
| **OpenSSH** | 系统默认 | 日志源 — 身份验证环境。
## 📊 框架与合规性一致性
| 框架 | 涵盖的控制措施 |
|-----------|-------------------|
| **NIST CSF 2.0** | ID.RA (风险评估), PR.AC (访问控制), DE.CM (持续监控) |
| **CIS Controls v8** | CIS 2 (资产清单), CIS 8 (审计日志), CIS 12 (网络), CIS 18 (应用安全) |
| **OWASP Top 10 (2021)** | A02 加密失败, A05 安全配置错误 |
| **ISO 27001** | A.12.4 (日志记录), A.16.1 (事件管理) |
| **MITRE ATT&CK** | T1110 (暴力破解), T1078 (有效账户), T1021.004 (远程服务: SSH) |
## 👤 作者





**一个真实的 SOC 分析师项目,涵盖使用 Splunk Enterprise 进行日志摄取、威胁检测、仪表板创建、自动告警和字段提取。**
[📋 查看报告](#-executive-summary) • [🔍 发现](#-security-findings) • [📊 仪表板](#-dashboard--alert-configuration) • [🛠️ 设置](#%EF%B8%8F-environment-setup) • [📁 查询](#-spl-query-reference)
## 📌 目录
- [执行摘要](#-executive-summary)
- [项目目标](#-project-objectives)
- [环境设置](#️-environment-setup)
- [任务 1 — 用户管理](#task-1--user-management)
- [任务 2 — 日志上传与分析](#task-2--log-upload--analysis)
- [任务 3 — 仪表板与告警配置](#task-3--dashboard--alert-configuration)
- [任务 4 — 字段提取](#task-4--field-extraction)
- [安全发现](#-security-findings)
- [SPL 查询参考](#-spl-query-reference)
- [建议](#-recommendations)
- [关键要点](#-key-takeaways)
- [工具与技术](#️-tools--technologies)
- [作者](#-author)
## 📋 执行摘要
作为新加入的安全运营分析师,我的任务是在组织发生一系列可疑事件后分析 OpenSSH 日志文件以识别潜在威胁。本项目演示了一个完整的端到端 SOC 工作流程:
| 组件 | 详情 |
|-----------|--------|
| **平台** | Kali Linux 2025.1c 上的 Splunk Enterprise 9.1.6 |
| **目标日志** | OpenSSH syslog — `openssh_logs.log` |
| **分析主机** | `10.0.2.15` (Linux Kernel 6.16.8+kali-amd64) |
| **索引总事件数** | 18 个事件 |
| **识别出的威胁** | 暴力破解、撞库、已确认的 root 沦陷 |
| **创建的仪表板** | 1 个实时监控仪表板 |
| **配置的告警** | 1 个计划每日告警 (早上 8 点 cron) |
| **字段提取** | `src_ip` — 基于正则表达式的内联提取 |
| **管理的用户** | 4 个带有 WAT 时区和基于角色的访问权限的账户 |
## 🎯 项目目标
- [x] **用户管理** — 创建具有正确角色、时区 (WAT) 和强制密码更改策略的用户账户
- [x] **日志摄取** — 将 OpenSSH 日志文件上传并索引到 Splunk 的 `main` 索引中
- [x] **威胁分析** — 识别异常、可疑 IP 和攻击模式
- [x] **仪表板创建** — 构建用于断开连接事件的实时监控面板
- [x] **告警配置** — 计划带有阈值触发的自动电子邮件告警
- [x] **字段提取** — 配置 `src_ip` 正则表达式提取以进行基于 IP 的分析
- [x] **报告** — 制作带有证据的执行级文档
## 🛠️ 环境设置
### 系统规格
```
OS: Kali Linux 2025.1c (VirtualBox amd64)
SIEM: Splunk Enterprise 9.1.6
Host IP: 10.0.2.15
MAC: 08:00:27:B4:A1:05
Kernel: Linux 6.16.8+kali-amd64
Splunk URL: http://localhost:8000
Index: main
Sourcetype: syslog
```
### Splunk 安装
```
# 下载 Splunk Enterprise 9.1.6
wget -O splunk.deb "https://download.splunk.com/products/splunk/releases/9.1.6/linux/splunk-9.1.6-a28f08fac354-linux-2.6-amd64.deb"
# 安装软件包
sudo dpkg -i splunk.deb
# 修复 libcrypto 兼容性(较新内核上需要)
sudo apt install execstack -y
sudo find /opt/splunk -name "*.so*" -exec execstack -c {} \; 2>/dev/null
# 启动 Splunk 并接受许可
sudo /opt/splunk/bin/splunk start --accept-license
# 开机启用
sudo /opt/splunk/bin/splunk enable boot-start
# 验证运行状态
sudo /opt/splunk/bin/splunk status
```
## 任务 1 — 用户管理
### 用户创建步骤
每个用户都是通过 **Settings → Users → New User** 创建的,配置如下:
| 字段 | 应用值 |
|-------|---------------|
| **时区** | `Africa/Lagos` (WAT — 西非时间, UTC+1) |
| **默认应用** | `launcher (home)` |
| **密码策略** | 首次登录时强制更改 ✓ |
| **角色** | 按职责分配 (见下文) |
### 角色分配
| 用户名 | 角色 | 权限 |
|----------|------|-------------|
| `justice.alucho` | `admin` | 完全系统访问权限 — 用户管理、索引创建、配置 |
| `member2` | `power` | 搜索、仪表板、告警 — 无系统设置权限 |
| `member3` | `power` | 搜索、仪表板、告警 — 无系统设置权限 |
| `member4` | `user` | 只读 — 查看仪表板和基本搜索 |
## 任务 2 — 日志上传与分析
### 上传日志文件
```
Settings → Add Data → Upload → Select File
Source Type: syslog
Index: main
```
### 验证数据摄取
```
index=main sourcetype=syslog
```
预期结果:在所有时间范围内返回 **18 个事件**。
### 📸 证据截图
#### 图 1 — 所有 18 个已索引事件
#### 图 2 — 密码失败和无效用户事件
#### 图 3 — ⚠️ 严重:接受密码 (Root 沦陷)
### 攻击模式分析
#### 日志事件细分
```
Dec 10 06:55:48 Invalid user test from 183.62.140.253
Dec 10 06:55:50 Failed password for invalid user test from 183.62.140.253 port 4269
Dec 10 06:55:52 Received disconnect from 183.62.140.253: 11: Bye Bye [preauth]
Dec 10 07:02:47 Invalid user admin from 112.95.230.3
Dec 10 07:02:49 Failed password for invalid user admin from 112.95.230.3 port 4270
Dec 10 07:02:51 Received disconnect from 112.95.230.3: 11: Bye Bye [preauth]
Dec 10 07:10:00 Accepted password for root from 112.95.230.3 port 12345 ssh2 ⚠️ CRITICAL
Dec 10 07:15:00 Failed password for root from 183.62.140.253 port 54321
Dec 10 07:20:00 Failed password for root from 183.62.140.253 port 54322
Dec 10 07:25:00 Failed password for root from 183.62.140.253 port 54323
```
#### 威胁归因
| IP 地址 | 角色 | 事件数 | 攻击类型 |
|------------|------|--------|-------------|
| `183.62.140.253` | 主要攻击者 | 5+ | 暴力破解 — 无效用户 + root 密码失败 |
| `112.95.230.3` | 次要攻击者 | 6+ | 撞库 → **成功的 root 登录** |
## 任务 3 — 仪表板与告警配置
### 3.1 仪表板创建
**仪表板名称:** `OpenSSH Security Monitoring`
**描述:** 监控可疑的 SSH 登录尝试和断开连接
#### 使用的搜索查询
```
index=main "Received disconnect from 112.95.230.3: 11: Bye Bye [preauth]"
```
**结果:** 确认来自 `112.95.230.3` 的 6 个断开连接事件。
#### 仪表板面板配置
| 设置 | 值 |
|---------|-------|
| 面板标题 | `Disconnect Events from 112.95.230.3` |
| 可视化 | 事件表格 (时间 + 事件) |
| 权限 | 共享在应用中 |
| 应用 | Search & Reporting |
### 📸 图 4 — 收到断开连接搜索结果
### 📸 图 5 — 实时仪表板
### 3.2 告警配置
#### 告警设置
```
Alert Name: SSH Disconnect Alert — 112.95.230.3
Search Query: index=main "Received disconnect from 112.95.230.3: 11: Bye Bye [preauth]"
Schedule: Cron — 0 8 * * * (Daily at 8:00 AM)
Time Window: Last 24 hours
Expires: 24 hours after trigger
```
#### 触发条件
```
Trigger when: Number of results
Condition: is greater than
Value: 2
```
#### 邮件通知
```
Format: Plain Text
Recipients: justice.alucho@domain.com, member2@domain.com,
member3@domain.com, member4@domain.com
Subject: ALERT: Suspicious SSH Activity Detected — 112.95.230.3
Include: Search results attached
```
#### 电子邮件域名限制
```
# 文件:/opt/splunk/etc/system/local/alert_actions.conf
[email]
mailserver = localhost
use_ssl = false
use_tls = false
allowedDomainList = yourdomain.com
```
```
# 应用更改
sudo /opt/splunk/bin/splunk restart
```
## 任务 4 — 字段提取
### 创建 `src_ip` 字段
**导航:** `Settings → Fields → Field Extractions → Add New`
| 设置 | 值 |
|---------|-------|
| 名称 | `src_ip` |
| 目标应用 | `search` |
| 应用于 | `sourcetype = syslog` |
| 类型 | `Inline (Regular Expression)` |
| 正则表达式模式 | `from (?P
**Justice C. Alucho**
*网络安全 SOC 分析师 | 威胁检测与事件响应*
[](https://www.linkedin.com/in/justice-alucho-30aba6145)
[](https://github.com/kosijustice)
[](mailto:kosijustice7alucho@gmail.com)
## 📄 许可证
本项目基于 MIT 许可证授权 — 详情请参阅 [LICENSE](LICENSE) 文件。
*⭐ 如果这个项目对你有帮助,或者展示了正在寻找的技能,请随时为本仓库加星。*
**基于实际的 SOC 分析师经验构建 | 由 Splunk Enterprise 驱动**
下面是我的项目的完整报告
[Splunk-SIEM-Security-Monitoring-Report](https://github.com/kosijustice/-OpenSSH-Log-Analysis-Splunk-SIEM-Security-Monitoring/blob/main/Splunk_Security_Report_Final_main%20-%20Google%20Docs.pdf)标签:AMSI绕过, OISF, OpenSSH, SPL, SPL查询, SSH安全, 仪表盘, 威胁检测, 子域名变形, 字段提取, 安全运营, 安全项目, 扫描框架, 日志摄取, 日志管理, 网络安全, 自动化告警, 隐私保护