An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# πŸ›‘οΈ AI-Powered Threat Detection System

![ELK Stack with AI](https://img.shields.io/badge/ELK-8.12.0-orange?logo=elasticsearch)
![Docker](https://img.shields.io/badge/Docker-20.10.24-blue?logo=docker)
![Ollama](https://img.shields.io/badge/Ollama-0.4.8-red?logo=ollama)
![Python](https://img.shields.io/badge/Python-3.9-green?logo=python)
![License](https://img.shields.io/badge/License-MIT-blue)

**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`
![Kibana Dashboard](resources/Dashboard-screenshot.png)

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"*