Skip to content

nacm/SIEM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI-SIEM: Real-Time Threat & Anomaly Detection System

Open-source Security Information and Event Management (SIEM) system for small to medium businesses. Provides real-time threat detection, anomaly analysis, and centralized security monitoring using ELK Stack, Grafana, and machine learning.

🎯 Features

  • Real-time Log Ingestion: Centralized log collection from multiple sources via Logstash
  • Elasticsearch Search: Fast indexing and searching of security events
  • Kibana Visualization: Comprehensive log analysis and visualization
  • Grafana Dashboards: Advanced security metrics and threat indicators
  • Anomaly Detection: ML-based detection using Isolation Forest algorithm
  • Threat Intelligence: Pattern-based threat detection and correlation
  • Alerting System: Real-time alerts with deduplication and rules engine
  • πŸ”₯ Automated Response: Automatic IP/port blocking for detected threats
  • Containerized Deployment: Docker Compose for easy deployment
  • 100% Open Source: No licensing costs, self-hosted

πŸ“‹ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Log Sources                               β”‚
β”‚  (Web Servers, Firewalls, OS Logs, Applications)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚    Logstash         β”‚
        β”‚ (Log Processing)    β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚    Elasticsearch (Data Lake)        β”‚
        β”‚  - siem-logs-* (Raw Events)        β”‚
        β”‚  - siem-threats-* (Detected)        β”‚
        β”‚  - siem-anomalies-* (Anomalies)    β”‚
        β”‚  - siem-alerts-* (Alerts)           β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                     β”‚          β”‚          β”‚
    β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ Kibana β”‚          β”‚ Grafanaβ”‚ β”‚ Anomaly  β”‚ β”‚  Threat    β”‚
    β”‚ (Viz)  β”‚          β”‚(Dash)  β”‚ β”‚Detection β”‚ β”‚ Detection  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚            β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚                β”‚
                    β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
                    β”‚   Redis (Queue/Cache)    β”‚
                    β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                        β”‚                β”‚
                    β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
                    β”‚  Alerting Engine         β”‚
                    β”‚ (Rules, Notifications)   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Components

Component Purpose Technology Port
Elasticsearch Data storage & indexing Elasticsearch 8.11 9200
Kibana Log visualization Kibana 8.11 5601
Logstash Log processing pipeline Logstash 8.11 5000
Grafana Security dashboards Grafana 10.2 3000
Redis Caching & message queue Redis 7 6379
Anomaly Detector ML-based anomaly detection Python 3.11 Internal
Threat Detector Pattern-based threat detection Python 3.11 Internal
Alerting Engine Alert processing & routing Python 3.11 Internal
Automated Response ⚑ NEW Auto-blocks malicious IPs/ports Python 3.11 Internal

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • 4+ GB RAM
  • 20+ GB disk space
  • Linux/macOS/Windows with Docker Desktop

Installation

  1. Clone and navigate to project:
cd /path/to/AI-SIEM
  1. Update credentials (Important for production!):
# Edit docker-compose.yml and update these environment variables:
# - ELASTIC_PASSWORD
# - GF_SECURITY_ADMIN_PASSWORD
# - REDIS_PASSWORD
  1. Create Redis data directory:
mkdir -p redis/data
chmod 755 redis/data
  1. Start all services:
docker-compose up -d
  1. Verify services:
docker-compose ps
# All services should show "Up"

Access Interfaces

Service URL Default Credentials
Kibana http://localhost:5601 elastic / change_me_elastic_password
Grafana http://localhost:3000 admin / change_me_grafana_password
Elasticsearch http://localhost:9200 elastic / change_me_elastic_password
Logstash http://localhost:9600 (No auth)

πŸ“ Configuration

1. Logstash Log Ingestion

Location: logstash/pipeline/main.conf

Configure inputs for your log sources:

input {
  # TCP input
  tcp {
    port => 5000
    codec => json
  }
  
  # File input
  file {
    path => "/var/log/siem/*.log"
  }
}

Supported formats: JSON, Syslog, Plain text, CSV

2. Grafana Dashboards

Location: grafana/dashboards/

Pre-configured dashboards:

  • Security Threat Overview: Real-time threat statistics
  • (Add more dashboards in grafana/dashboards/ directory)

3. Alert Rules

Location: alerting/config/alert_rules.yml

Customize alert severity, thresholds, and notification channels.

4. Anomaly Detection

Location: anomaly-detection/main.py

Configuration options:

  • Contamination rate: Percentage of anomalies (default: 10%)
  • Retraining interval: Model retraining frequency (default: 6 hours)
  • Feature selection: Change extracted features from logs

πŸ”Œ Sending Logs

TCP/JSON Format

echo '{"event_type": "connection_attempt", "src_ip": "192.168.1.100", "dst_ip": "8.8.8.8", "src_port": 54321, "dst_port": 443, "packet_count": 10, "byte_count": 1024, "severity": "low"}' | nc localhost 5000

Via Filebeat (Agent-based)

Install Filebeat on source systems:

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/auth.log
    - /var/log/syslog

output.logstash:
  hosts: ["<SIEM-SERVER-IP>:5000"]

Via Syslog

Configure your devices/applications to send syslog to port 5000:

facility: local0
server: <SIEM-SERVER-IP>
port: 5000
protocol: udp

πŸ” Detection Engines

Anomaly Detection Engine

Algorithm: Isolation Forest (scikit-learn)

What it detects:

  • Unusual network traffic patterns
  • Abnormal packet rates
  • Unexpected data transfer volumes
  • Statistical outliers in event characteristics

Process:

  1. Fetches historical logs (24 hours)
  2. Trains model on baseline behavior
  3. Monitors incoming events for deviations
  4. Retrains every 6 hours with fresh data

Configuration: anomaly-detection/main.py

Threat Detection Engine

Method: Pattern matching and rule-based detection

What it detects:

  • Brute Force Attacks: 5+ failed logins in 10 minutes
  • Port Scanning: 20+ unique ports in 5 minutes
  • DDoS Attacks: 1000+ requests from single IP in 1 minute
  • Privilege Escalation: Unauthorized elevated access attempts
  • Malware Signatures: Known malicious file hashes
  • Data Exfiltration: Suspicious outbound data transfers

Configuration: threat-detection/main.py

Alerting Engine

Features:

  • Real-time alert generation
  • Alert deduplication (prevent spam)
  • Rule-based filtering
  • Redis-based queueing
  • Extensible notification channels

Configuration: alerting/config/alert_rules.yml

πŸ›‘οΈ Automated Response System

Method: Firewall-based IP and port blocking using iptables

What it blocks:

  • Critical/High Severity Threats: Automatically blocks source IPs
    • Critical threats: 120 minutes block duration
    • High threats: 60 minutes block duration
  • Port Scanning Attacks: Blocks targeted ports temporarily (30 min)
  • DDoS Attacks: Blocks attack source and protects ports

Features:

  • βœ… Automatic IP blocking with iptables
  • βœ… Port-based blocking for service protection
  • βœ… Auto-expiration (blocks automatically unblock after duration)
  • βœ… All actions logged to Elasticsearch
  • βœ… Dry-run mode for testing (no actual blocking)
  • βœ… Real-time monitoring via Redis pub/sub

Configuration:

# In docker-compose.yml:
- AUTO_BLOCK_ENABLED=true    # Enable/disable auto-blocking
- BLOCK_DURATION_MINUTES=60  # Default block duration
- DRY_RUN_MODE=false         # true = log only, false = actually block

Testing:

# Run test suite to simulate attacks
python3 test_blocking.py

# Check blocked IPs
docker logs ai-siem-response --tail 50

# View blocking actions in Elasticsearch
curl "localhost:9200/siem-response-actions-*/_search?pretty"

See: automated-response/README.md for detailed documentation

πŸ“Š Elasticsearch Index Lifecycle

Index Naming Convention

  • siem-logs-YYYY.MM.DD: Raw security events
  • siem-threats-*: Detected threats
  • siem-anomalies-*: Detected anomalies
  • siem-alerts-*: Generated alerts

Index Management

Delete old indices to manage disk space:

# Delete indices older than 30 days
curl -X DELETE http://localhost:9200/siem-logs-$(date -d '30 days ago' +%Y.%m.%d)

πŸ› Troubleshooting

Elasticsearch Health Check

curl http://elastic:change_me_elastic_password@localhost:9200/_cluster/health

View Service Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f anomaly-detector
docker-compose logs -f threat-detector
docker-compose logs -f alerting-engine

Common Issues

Issue Solution
Port already in use Change port mapping in docker-compose.yml
Out of memory Increase Docker memory limit, reduce ES_JAVA_OPTS
No logs appearing Check Logstash configuration, verify log format
Slow queries Index size too large - configure log rotation
Detection not working Ensure at least 1 hour of data in Elasticsearch

πŸ“ˆ Performance Tuning

Elasticsearch

For SMB environments (1M events/day):

ES_JAVA_OPTS: -Xms512m -Xmx512m  # Adjust heap size
indices.memory.index_buffer_size: 30%

Logstash

pipeline.batch.size: 125        # Increase for throughput
pipeline.batch.delay: 50        # Milliseconds
queue.type: persisted          # Enable persisted queue

πŸ” Security Best Practices

  1. Change default credentials immediately:

    • Elasticsearch admin password
    • Grafana admin password
    • Redis password
  2. Network isolation:

    • Restrict access to ports 5601, 3000, 9200
    • Use firewall rules
    • Deploy in internal network only
  3. Enable HTTPS:

    • Configure Elasticsearch SSL
    • Set up Kibana proxy with HTTPS
  4. Regular backups:

    • Backup Elasticsearch data
    • Export Grafana dashboards
    • Version control alert rules

πŸ“¦ File Structure

AI-SIEM/
β”œβ”€β”€ docker-compose.yml          # Main configuration
β”œβ”€β”€ elasticsearch/
β”‚   β”œβ”€β”€ config/elasticsearch.yml
β”‚   └── data/                   # Persistent data
β”œβ”€β”€ kibana/
β”‚   └── config/kibana.yml
β”œβ”€β”€ logstash/
β”‚   β”œβ”€β”€ config/logstash.yml
β”‚   └── pipeline/main.conf      # Log processing rules
β”œβ”€β”€ grafana/
β”‚   β”œβ”€β”€ config/grafana.ini
β”‚   β”œβ”€β”€ dashboards/             # Dashboard definitions
β”‚   └── provisioning/           # Automated setup
β”œβ”€β”€ anomaly-detection/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ main.py                 # Detection engine
β”‚   └── requirements.txt
β”œβ”€β”€ threat-detection/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ main.py                 # Threat patterns
β”‚   └── requirements.txt
β”œβ”€β”€ alerting/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ main.py                 # Alert processor
β”‚   β”œβ”€β”€ config/alert_rules.yml  # Alert configuration
β”‚   └── requirements.txt
β”œβ”€β”€ logs/                        # Log input directory
β”œβ”€β”€ sample-data/                 # Test data
β”œβ”€β”€ redis/                       # Redis data
└── README.md

πŸ”„ Data Flow Examples

Example 1: Failed Login Detection

1. Server logs failed auth β†’ Logstash ingests
2. Logstash parses & enriches β†’ Elasticsearch indexes
3. Threat detector queries: failed_auth > 5 in 10min
4. Match found β†’ Threat alert generated
5. Alerting engine β†’ Redis pub/sub β†’ Elasticsearch
6. Dashboard updated β†’ Security team notified

Example 2: Anomaly Detection

1. Network traffic logged β†’ Logstash processes
2. Stored in Elasticsearch siem-logs-*
3. Anomaly detector fetches last 24hrs β†’ trains model
4. New logs arrive β†’ scored against model
5. Unusual packet rate detected β†’ anomaly_score = -0.75
6. Alert generated & published β†’ stored in siem-alerts-*
7. Grafana dashboard reflects new alert

πŸ›  Maintenance

Regular Tasks

Daily:

  • Monitor dashboard for alerts
  • Check service health: docker-compose ps

Weekly:

  • Review logs: docker-compose logs --tail 100
  • Verify model accuracy (anomaly detection)
  • Test alerting system

Monthly:

  • Clean old indices (>90 days)
  • Review and update threat signatures
  • Analyze detection accuracy

Scaling for Growth

Single-node to multi-node Elasticsearch:

  • Increase node.name in elasticsearch.yml
  • Update docker-compose for multiple ES instances
  • Configure cluster settings

Increase log retention:

  • Adjust ILM policies
  • Add more storage volumes
  • Upgrade disk space

πŸ“š Additional Resources

πŸ“„ License

This project uses open-source components:

  • Elasticsearch & Kibana: SSPL License
  • Logstash: SSPL License
  • Grafana: AGPL License
  • Python libraries: Various open-source licenses

🀝 Contributing

Contributions welcome! Areas for enhancement:

  • Additional detection algorithms
  • Integration with more log sources
  • Advanced visualization dashboards
  • Notification channel integrations (Slack, Email)
  • Custom ML models

πŸ“ž Support

For issues or questions:

  1. Check troubleshooting section
  2. Review service logs
  3. Check Elasticsearch health
  4. Verify connectivity between services

Last Updated: December 2025 Version: 1.0.0

About

ELK SIEM Full

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors