https://github.com/virtualisp/ai-powered-threat-detection-system
A real-time security monitoring system that combines the ELK Stack (Elasticsearch, Logstash, Kibana) with Ollama's AI models (like Phi-3-mini) to automatically detect and analyze security threats in logs. Ideal for identifying brute-force attacks, SQLi, XSS, and moreβwith actionable insights visualized in Kibana dashboards.
https://github.com/virtualisp/ai-powered-threat-detection-system
cybersecurity devsecops docker docker-compose elasticsearch elk elk-stack filebeat kibana llama3 llm log-analysis log-processing logstash nginx ollama phi3 python security-tools threat-detection
Last synced: 7 months ago
JSON representation
A real-time security monitoring system that combines the ELK Stack (Elasticsearch, Logstash, Kibana) with Ollama's AI models (like Phi-3-mini) to automatically detect and analyze security threats in logs. Ideal for identifying brute-force attacks, SQLi, XSS, and moreβwith actionable insights visualized in Kibana dashboards.
- Host: GitHub
- URL: https://github.com/virtualisp/ai-powered-threat-detection-system
- Owner: virtualISP
- Created: 2025-05-14T19:19:58.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-05-14T20:10:20.000Z (8 months ago)
- Last Synced: 2025-06-03T11:37:43.023Z (7 months ago)
- Topics: cybersecurity, devsecops, docker, docker-compose, elasticsearch, elk, elk-stack, filebeat, kibana, llama3, llm, log-analysis, log-processing, logstash, nginx, ollama, phi3, python, security-tools, threat-detection
- Language: Python
- Homepage:
- Size: 189 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π‘οΈ AI-Powered Threat Detection System





**Next-gen security monitoring** that combines the power of **ELK Stack** with **AI analysis** using Ollama's model to detect threats in real-time. Like a cybersecurity guard dog π with a PhD in machine learning!
## β¨ Key Features
| Feature | Benefit |
|---------|---------|
| **π§ AI-Powered Analysis** | Uses Phi-3-mini/TinyLLaMA models for accurate threat classification |
| **β±οΈ Real-time Processing** | Detects threats as they happen (not after the breach!) |
| **π Threat Dashboard** | Beautiful Kibana visualizations with threat heatmaps |
| **π Multi-source Support** | Works with Nginx, Apache, system logs, and more |
| **βοΈ Customizable Rules** | Teach it to recognize new threats in 5 minutes |
## ποΈ System Architecture
```mermaid
graph LR
A[Raw Logs] --> B[Filebeat]
B --> C[Logstash]
C --> D[(Raw Log Index)]
D --> E[AI Analyzer]
E --> F[(AI-Threats Index)]
D --> G[Kibana Log Dashboard]
F --> H[Kibana Threat Dashboard]
```
## π Log Feed (Raw Logs)
**π Location:** Elasticsearch indices matching pattern `logs-*`
### βοΈ Kibana Configuration
1. Create index pattern: `logs-*`, Time field: `@timestamp`
2. Create index pattern: `ai-threats`, Time field: `@timestamp`
## π€ AI-Threat Feed (Analyzed Threats)
**π Location:** Elasticsearch index `ai-threats`
### π§Ύ Sample Document Structure
```json
{
"@timestamp": "2025-05-15T12:00:05Z",
"log": "POST /wp-login.php HTTP/1.1 401 532",
"source_ip": "192.168.1.100",
"threat": "brute_force",
"confidence": 92,
"evidence": "Multiple rapid POST requests to login endpoint",
"recommendation": "Implement rate limiting and CAPTCHA",
"analysis_timestamp": "2025-05-15T12:00:10Z"
}
```
## π Feed Comparison
| π§© Feature | π Log Feed | π€ AI-Threat Feed |
| -------------------- | ------------------- | ------------------------------- |
| **Content** | Raw log data ποΈ | Analyzed threats π¨ |
| **Index Pattern** | `logs-*` π | `ai-threats` π§ |
| **Update Frequency** | Real-time β‘ | Near-real-time (5β10s delay) β±οΈ |
| **Primary Use** | Troubleshooting π οΈ | Threat detection π‘οΈ |
| **Data Volume** | High π | Lower (only threats) π |
## π Accessing the Feeds
### 1. π§ Via Kibana
* **Log Feed**: `Discover β logs-*` π
* **AI-Threat Feed**: `Discover β ai-threats` π§
### 2. π» Via API
```bash
# ποΈ Get raw logs
curl "http://localhost:9200/logs-*/_search?q=tags:security&pretty"
# π¨ Get analyzed threats
curl "http://localhost:9200/ai-threats/_search?q=threat:brute_force&pretty"
```
## π₯οΈ Using the Dashboard
1. **Access Kibana** at `http://localhost:5601`

2. **Recommended Visualizations**:
- π Threat Type Pie Chart
- π Confidence Level Histogram
- π°οΈ Events Timeline
- πΊοΈ Threat Origin World Map
## π Getting Started
### Prerequisites
- Docker π³ 20.10+
- Docker Compose π
- Python π
- Hardware:
- **Recommended**: 16GB RAM, 8 cores (for AI analysis)
- Storage: 20GB SSD (for log retention)
### Installation
1. **Clone the repo**
```bash
git clone https://github.com/virtualISP/AI-Powered-Threat-Detection-System.git
cd AI-Powered-Threat-Detection-System
```
2. **Download AI model** (takes 2-5 minutes)
```bash
docker-compose up ollama && docker exec -it ollama ollama pull phi3:mini
```
3. **Launch the system**
```bash
docker-compose up --build -d
```
4. **Verify services**
```bash
docker-compose ps
```
## βοΈ Configuration Guide
### π§ Key Files
| File | Purpose | Icon |
|------|---------|------|
| `docker-compose.yml` | Main service configuration | π |
| `filebeat/filebeat.yml` | Log collection settings | π‘ |
| `logstash/pipeline/*.conf` | Log processing pipelines | βοΈ |
| `analyzer.py` | AI analysis brain | π§ |
## π§ͺ Testing Your Setup
Try these test logs (run in terminal):
```bash
# SQL Injection πͺ
curl -X POST "http://localhost:9200/logs-*/_doc" -H 'Content-Type: application/json' -d'
{
"@timestamp": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'",
"message": "GET /products?id=1%20UNION%20SELECT%20*%20FROM%20users--"
}'
# Brute Force π
curl -X POST "http://localhost:9200/logs-*/_doc" -H 'Content-Type: application/json' -d'
{
"@timestamp": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'",
"message": "10 failed SSH attempts for root from 45.33.21.10"
}'
```
## π¨ Troubleshooting
| Symptom | Fix |
|---------|-----|
| Ollama model not loading π | Increase memory in `docker-compose.yml` |
| Kibana shows no data π΅οΈ | Check index pattern matches `ai-threats` |
| High CPU usage π₯ | Reduce `POLL_INTERVAL` or switch to `tinyllama` |
**Pro Tip**: Monitor system health with:
```bash
watch -n 1 'docker stats --no-stream'
```
## π€ How to Contribute
1. Fork the repository
2. Create your feature branch (`git checkout -b cool-new-feature`)
3. Commit changes (`git commit -m 'Add some feature'`)
4. Push to branch (`git push origin cool-new-feature`)
5. Open a Pull Request
## π License
MIT Β© VirtualISP β **[βοΈ See LICENSE](resources/LICENSE)**
---
**Happy Threat Hunting!** πΎπ
*"Sleep better knowing your logs are being watched by AI"*