Skip to content

Commit a54beb4

Browse files
CVE threat automation (#280)
Co-authored-by: ben-AI-cybersec <[email protected]> Co-authored-by: Ben Stephens <[email protected]>
1 parent f6adb9b commit a54beb4

12 files changed

Lines changed: 242 additions & 0 deletions
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
---
2+
sidebar_position: 1
3+
title: CVE Threat Automation
4+
---
5+
6+
### CVE Threat Automation - Full Documentation
7+
8+
:::info
9+
**Document Creation:** 23 May 2025. **Last Edited:** 23 May 2025. **Authors:** Muhammad Arsalan Khan
10+
11+
**Effective Date:** 23 May 2025. **Expiry Date:** 23 May 2026.
12+
:::
13+
14+
This document presents each phase of the CVE Threat Automation project in a structured and easy-to-understand format. It is designed to guide cybersecurity teams through the full process from planning to continuous improvement. Cybersecurity teams today face an ever-growing challenge of monitoring and responding to Common Vulnerabilities and Exposures (CVEs). Manually correlating logs, updating threat feeds, and writing detection rules is time-consuming and error-prone.
15+
16+
## Introduction
17+
18+
Cybersecurity teams today face an ever-growing challenge of monitoring and responding to Common Vulnerabilities and Exposures (CVEs). Manually correlating logs, updating threat feeds, and writing detection rules is time-consuming and error-prone.
19+
20+
**CVE Threat Automation** aims to automate threat detection using real-time CVE data integrated with SIEM systems. This initiative focuses on:
21+
- Extracting CVEs from threat intelligence platforms like MISP
22+
- Correlating them with system logs
23+
- Automatically generating detection rules
24+
- Enhancing threat visibility and response time
25+
26+
This documentation outlines each phase of the CVE Threat Automation process from planning to continuous enhancement.
27+
28+
## Phase 1: Planning
29+
30+
The planning phase defines the overall scope and goals of CVE Threat Automation.
31+
32+
### Objectives:
33+
- Identify key CVE sources (NVD, MISP)
34+
- Select target environment (e.g., Wazuh SIEM)
35+
- Determine automation tools (Python, Docker, APIs)
36+
- Design data flow (CVE → Threat Feed → Log Matching → SIEM Rules)
37+
38+
### Outcome:
39+
A clear roadmap that outlines data sources, target logs, platforms involved (MISP, Wazuh), and integration strategy.
40+
41+
## Phase 2: Design
42+
43+
## Introduction
44+
45+
Phase 2 involves setting up the core components of the threat automation system. Writing and organizing the Python script, specifying dependencies, and building the Docker image ensures the application runs consistently across different systems. Docker acts as a lightweight, consistent execution platform, while the script interacts with online CVE databases to gather threat intelligence. This modular approach also makes future maintenance easier.
46+
47+
# Phase 2: Script Setup and Docker Execution
48+
49+
**Objective:**
50+
Write the core CVE Hunter script and configure it for containerized execution using Docker.
51+
52+
**What We Are Doing:**
53+
This phase involves writing Python scripts (`hunter.py`), specifying dependencies in `requirements.txt`, and creating a Dockerfile to run the script in an isolated environment.
54+
55+
**Steps:**
56+
- Create project directory (`~/cve-hunter`)
57+
- Add `hunter.py`, `requirements.txt`, and `Dockerfile`
58+
- Build Docker image with:
59+
```bash
60+
sudo docker build -t cve-hunter .
61+
```
62+
- Run the script using:
63+
```bash
64+
sudo docker run cve-hunter
65+
```
66+
67+
This phase validates our environment by ensuring the script runs inside Docker and interacts with the CVE API.
68+
69+
# Design
70+
71+
![Docker Container Build and Script Execution](./img/docker_run_output.PNG)
72+
73+
74+
This phase translates planning into technical design and architecture.
75+
76+
### Components Designed:
77+
- MISP integration script to extract CVEs
78+
- Log correlation engine (Python script with `hunter_with_log_correlation.py`)
79+
- Detection rule generator for Wazuh
80+
- Docker container for portability
81+
82+
### Tools Used:
83+
- Python 3.10
84+
- Docker
85+
- REST APIs (NVD, MISP)
86+
- VS Code for script editing
87+
88+
### Architecture Diagram:
89+
![Architecture Diagram](./img/Architecture-Diagram.png)
90+
91+
92+
93+
## Phase 3: Implementation
94+
95+
In this stage, the designed components are developed and tested in a local environment.
96+
97+
### Key Activities:
98+
- MISP instance setup using Docker
99+
- Python script development for:
100+
- Fetching CVE data
101+
- Correlating with syslogs
102+
- Rule generation
103+
104+
- Log simulation using test files (`cve_test.log`)
105+
- Integration with Wazuh
106+
107+
![Detected CVEs Output](./img/cve_detection_output.PNG)
108+
109+
### Output:
110+
A working prototype that runs inside a Docker container and maps logs to CVEs.
111+
112+
```python title="hunter_with_log_correlation.py"
113+
import os
114+
115+
cve_signatures = {
116+
"CVE-2021-3156": ["sudoedit", "heap overflow", "segfault"],
117+
"CVE-2023-38408": ["ForwardAgent", "OpenSSH", "remote execution"],
118+
"CVE-2021-4034": ["pkexec", "polkit", "privilege escalation"],
119+
"CVE-2024-8376": ["mosquitto", "MQTT", "denial of service"]
120+
}
121+
122+
log_files = ["/var/log/syslog", "/var/log/auth.log"]
123+
124+
def search_logs_for_cve(cve_id, keywords):
125+
print(f"[🔍] Searching logs for {cve_id}...")
126+
found_any = False
127+
for log_path in log_files:
128+
if os.path.exists(log_path):
129+
with open(log_path, 'r', errors='ignore') as log:
130+
for line_num, line in enumerate(log, 1):
131+
for keyword in keywords:
132+
if keyword.lower() in line.lower():
133+
print(f"[!] Match in {log_path} (line {line_num}): {line.strip()}")
134+
found_any = True
135+
if not found_any:
136+
print("[✓] No matching CVE patterns found in logs.")
137+
print("-" * 50)
138+
139+
def run_log_correlation():
140+
print("[*] Starting CVE log correlation engine...\n")
141+
for cve_id, keywords in cve_signatures.items():
142+
search_logs_for_cve(cve_id, keywords)
143+
144+
if __name__ == "__main__":
145+
run_log_correlation()
146+
```
147+
148+
![Log Correlation Output](./img/log_output.png)
149+
150+
## Phase 4: Integration
151+
152+
153+
This phase integrates individual components to work as a cohesive automated system.
154+
155+
### Integrated Components:
156+
- MISP for threat feeds
157+
- Python script to handle CVE-log correlation
158+
- Wazuh for alerting via custom rules
159+
- GitHub for version control
160+
161+
![Log Correlation Output](./img/log_scan_output.PNG)
162+
163+
### Example Output:
164+
- Log entries matched to CVEs
165+
- Automatically deployed detection rules
166+
- Alert generation in Wazuh dashboard
167+
168+
## Phase 5: Testing
169+
170+
171+
Testing is essential to verify the correctness and reliability of CVE-based detections.
172+
173+
### Testing Strategy:
174+
- Simulate malicious activity in log files
175+
- Insert known vulnerable signatures (e.g., CVE-2021-3156)
176+
- Validate:
177+
- Rule generation
178+
- Wazuh detection
179+
- MISP event matches
180+
181+
![IOC Extraction via Python Script](./img/misp_api_script_output.PNG)
182+
183+
![Exported Threat Intelligence Formats](./img/misp_export_formats.PNG)
184+
185+
![MISP Feed Sync Status](./img/misp_feed_sync.PNG)
186+
187+
![Wazuh Rule 100100 Alert](./img/wazuh_rule_100100.PNG)
188+
189+
### Tools:
190+
- Metasploit for CVE emulation
191+
- Custom test logs
192+
- Wazuh alerts dashboard
193+
194+
## Phase 6: Monitoring
195+
196+
Monitoring focuses on ensuring the system remains operational and accurate over time.
197+
198+
### Metrics Tracked:
199+
- Detection accuracy
200+
- Alert rates and false positives
201+
- Feed freshness from MISP
202+
- Rule application success
203+
204+
### Improvements:
205+
- Logging errors and mismatches
206+
- MISP feed sync validation
207+
- Cron jobs for auto-refreshing rules
208+
209+
## Phase 7: Enhancement
210+
211+
Enhancement involves continuous improvement and scalability.
212+
213+
### Future Additions:
214+
- Enrich CVEs with MITRE ATT&CK mappings
215+
- Add STIX/TAXII compatibility
216+
- Use ML for anomaly scoring
217+
- Broader log sources (syslog, Windows event logs)
218+
219+
### Community Contributions:
220+
Encourage open-source contributions to extend capabilities and threat coverage.
221+
222+
## Conclusion
223+
224+
CVE Threat Automation transforms manual threat detection into a scalable, reliable, and real-time process.
225+
226+
By integrating MISP, Python automation, and Wazuh, we:
227+
- Reduced time to detect CVEs
228+
- Improved accuracy of alerts
229+
- Streamlined rule generation
230+
231+
The framework serves as a blueprint for scalable cybersecurity operations and continues to evolve with advanced threat intelligence integrations.
232+
233+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "CVE Threat Automation",
3+
"position": 80,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "CVE Threat Automation"
7+
}
8+
}
611 KB
Loading
259 KB
Loading
113 KB
Loading
354 KB
Loading
375 KB
Loading
151 KB
Loading
123 KB
Loading
149 KB
Loading

0 commit comments

Comments
 (0)