๐ฏ Enterprise-Grade Security Intelligence Automation Platform
๐ Bridge your FortiGate firewalls with global threat intelligence
๐ค Automate threat reporting and improve your security posture
๐ Generate professional reports with comprehensive analytics
In today's threat landscape, sharing threat intelligence is crucial for collective defense. This suite automatically:
- ๐ Monitors multiple FortiGate firewalls for malicious activity
- ๐ Reports threats to the global AbuseIPDB database
- ๐ Analyzes attack patterns and trends
- ๐งน Maintains clean firewall states
- ๐ง Delivers professional security reports to your team
- Process unlimited FortiGate devices in a single run
- SSH connection pooling for optimal performance
- Automatic retry logic with exponential backoff
- Chunked data processing for large outputs
- Real-time attack categorization (IPS, DoS, Brute Force)
- Automatic network grouping (/24 for IPv4, /64 for IPv6)
- WHOIS integration with 7-day intelligent caching
- Attack timeline tracking and pattern analysis
- Zero credential exposure architecture
- Private IP automatic filtering (RFC1918, RFC4193)
- Custom whitelist support for your infrastructure
- Complete audit trail logging
- 3 Report Types: Terminal, HTML Email, JSON/CSV
- Outlook-compatible responsive HTML design
- Embedded logo support for branding
- Executive-ready statistics dashboards
- ๐ฏ Features Overview
- ๐๏ธ System Architecture
- ๐ฆ What's New in v2.1
- โก Quick Start
- ๐ Detailed Installation
- โ๏ธ Configuration Guide
- ๐ง Usage & Examples
- ๐ Reports & Analytics
- ๐ก๏ธ Security Features
- ๐ API Integration
- ๐ Attack Categories
- ๐ Performance Tuning
- ๐ Troubleshooting
- ๐ Monitoring & Logs
- ๐ค Contributing
- ๐ License
- ๐ฌ Support & Community
The heart of the suite that orchestrates all operations:
- โ Multi-FortiGate batch processing
- โ Automatic version detection (FortiOS 7.0.x, 7.4.x)
- โ Dual-stack IP support (IPv4/IPv6)
- โ Real-time AbuseIPDB reporting
- โ Comprehensive IP filtering
- โ Automatic cleanup operations
- โ SSH connection management
- โ Rate limit handling
Comprehensive analytics and reporting engine:
- ๐ Automated daily statistics collection
- ๐ Attack pattern analysis and trending
- ๐ WHOIS data enrichment with caching
- ๐ง Professional HTML email reports
- ๐ Attack categorization by type (DoS, IPS, Auth)
- ๐จ Visual charts and graphs
- ๐ Historical data tracking
- ๐ข Top attacker identification
- ๐ Geographic distribution analysis
- ๐พ Automated report scheduling via cron
Multi-format reporting for different audiences:
- ๐ง HTML email reports
- ๐จ Embedded logo support
- ๐ฑ Mobile-responsive design
- ๐ WHOIS data integration
- ๐ด Severity classifications
- ๐ Visual statistics
- โก Performance metrics
- ๐ Scheduled delivery support
- ๐ Credential encryption (Base64, upgradeable to AES)
- ๐ Complete audit logging
- ๐ซ Private IP filtering (RFC compliant)
โ ๏ธ Rate limit compliance- ๐ก๏ธ GDPR compliant (no personal data)
- ๐ Security policy enforcement
- ๐จ Sensitive data detection
- ๐ Multi-factor authentication ready
- ๐ Connection pooling & reuse
- ๐ Automatic retry with backoff
- ๐ Broken pipe recovery
- โก Parallel processing where applicable
- ๐พ Memory-efficient streaming
- ๐ Async operation support
- ๐ฆ Batch operation optimization
- ๐ง Resource management
- ๐๏ธ Quarantine list clearing
- ๐ Address group cleanup (IPv4/IPv6)
- ๐ท๏ธ Firewall object management
- ๐ State synchronization
- ๐ Log rotation support
- ๐๏ธ Cache management
- ๐งช Self-diagnostics
- ๐ Health monitoring
graph TB
subgraph "๐ข FortiGate Infrastructure"
FG1[๐ฅ FortiGate 1]
FG2[๐ฅ FortiGate 2]
FG3[๐ฅ FortiGate 3]
FGN[๐ฅ FortiGate N]
end
subgraph "๐ฅ๏ธ Processing Layer"
ME[๐ค Main Engine<br/>fortigate2AbuseIPDB.py]
SA[๐ Stats Analyzer<br/>generate_stats_report.py]
EG[๐ง Email Generator<br/>fortigate2AbuseIPDB_stats.py]
end
subgraph "๐ External Services"
AB[โ๏ธ AbuseIPDB API]
WH[๐ WHOIS Services]
SM[๐ฎ SMTP Server]
end
subgraph "๐ Data Storage"
LG[๐ Logs]
CA[๐พ Cache]
CF[โ๏ธ Config]
end
FG1 & FG2 & FG3 & FGN -.->|SSH| ME
ME -->|Report IPs| AB
ME -->|Query| WH
ME -->|Write| LG
ME -->|Store| CA
CF -->|Load| ME
LG --> SA
SA -->|Generate| EG
EG -->|Send| SM
style ME fill:#4CAF50
style SA fill:#2196F3
style EG fill:#FF9800
1. ๐ฅ Load Configuration
โโ> FortiGate list, credentials, whitelist
2. ๐ Connect to FortiGates
โโ> SSH with connection pooling
3. ๐ Retrieve Banned IPs
โโ> Parse quarantine/banned-ip lists
4. ๐ก๏ธ Filter IPs
โโ> Private/RFC1918 ranges
โโ> User whitelist
โโ> DNS servers
5. ๐ค Report to AbuseIPDB
โโ> With rate limit handling
6. ๐งน Cleanup Operations
โโ> Clear quarantine
โโ> Remove address groups
โโ> Delete firewall objects
7. ๐ Generate Reports
โโ> Terminal output
โโ> Email reports
โโ> JSON/CSV exports
Feature | v1.0 | v2.1 | Improvement |
---|---|---|---|
๐ฅ๏ธ Multi-FortiGate | Sequential | Batch Processing | 5x faster |
๐ IP Support | IPv4 only | Dual-stack IPv4/IPv6 | 100% coverage |
๐ Reporting | Basic logs | 3 report types | Professional |
๐ Security | Basic | Advanced filtering | Enterprise-ready |
๐ Reliability | Simple retry | Smart retry + pooling | 99.9% uptime |
๐ Analytics | None | Full statistics | Data-driven |
๐จ UI | Terminal only | Terminal + HTML + JSON | Multi-format |
๐ WHOIS | No | Yes with caching | Intelligence |
- ๐ค Automatic version detection for FortiOS compatibility
- ๐ Three report generators for different audiences
- ๐ WHOIS integration with intelligent caching
- ๐ Timeline tracking for trend analysis
- ๐ Pre-commit hooks to prevent credential exposure
- ๐ง Professional HTML emails with branding
- ๐พ JSON/CSV exports for automation
- ๐ฏ Attack categorization (IPS, DoS, Brute Force)
# 1. Clone the repository
git clone https://github.com/paolokappa/FortiGateToAbuseIPDB.git
cd FortiGateToAbuseIPDB
# 2. Install dependencies
pip3 install -r requirements.txt
# 3. Set up credentials
./setup_credentials.sh
# 4. Configure FortiGates
cp fortigate.list.example fortigate.list
nano fortigate.list # Add your FortiGate IPs
# 5. Add your API key
cp config.example.py config_local.py
nano config_local.py # Add your AbuseIPDB API key
# 6. Run!
python3 fortigate2AbuseIPDB.py
Component | Minimum | Recommended | Notes |
---|---|---|---|
๐ง OS | Linux/Unix | Ubuntu 20.04+ | Also supports CentOS, Debian |
๐ Python | 3.6 | 3.8+ | Type hints require 3.6+ |
๐พ RAM | 512MB | 2GB | More for large deployments |
๐ฝ Storage | 100MB | 1GB | Including logs |
๐ Network | 1 Mbps | 10 Mbps | SSH + API calls |
- FortiOS Version: 7.0.0+ (7.4.x recommended)
- Access Level: Admin or super_admin
- SSH: Enabled on management interface
- Required Commands:
get system status diagnose user quarantine list # FortiOS 7.0.x diagnose user banned-ip list # FortiOS 7.4.x diagnose user quarantine clear diagnose user banned-ip clear config firewall address/address6 config firewall addrgrp/addrgrp6
# Using HTTPS
git clone https://github.com/paolokappa/FortiGateToAbuseIPDB.git
# Using SSH (if you have keys set up)
git clone git@github.com:paolokappa/FortiGateToAbuseIPDB.git
cd FortiGateToAbuseIPDB
# Create virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip3 install -r requirements.txt
# Verify installation
python3 -c "import paramiko, requests; print('โ
Dependencies OK')"
Option A: Using Setup Script (Recommended)
chmod +x setup_credentials.sh
./setup_credentials.sh
Option B: Manual Setup
# Create credentials file
echo -n "your_username" | base64 > fortigate_creds.dat
echo -n "your_password" | base64 >> fortigate_creds.dat
# Secure the file
chmod 600 fortigate_creds.dat
# Copy template
cp fortigate.list.example fortigate.list
# Edit with your FortiGates
nano fortigate.list
Format:
# IP_ADDRESS HOSTNAME
192.168.1.1 fw-headquarters.example.com
10.0.0.1 fw-branch01.example.com
172.16.0.1 fw-datacenter.example.com
# Copy configuration template
cp config.example.py config_local.py
# Add your credentials
nano config_local.py
config_local.py:
# Your AbuseIPDB API key
ABUSEIPDB_API_KEY = 'your_actual_api_key_here'
# SMTP configuration (optional, for email reports)
SMTP_CONFIG = {
'smtp_server': 'mail.example.com',
'smtp_port': 587,
'smtp_user': 'alerts@example.com',
'smtp_pass': 'your_password',
'sender': 'fortigate@example.com',
'recipient': 'security@example.com',
}
# Copy template
cp ip_whitelist.txt.example ip_whitelist.txt
# Add your IP ranges
nano ip_whitelist.txt
Example:
# Your organization's public IPs
203.0.113.0/24
198.51.100.0/24
2001:db8::/32
# Partner networks
192.0.2.0/24
# Test configuration
python3 fortigate2AbuseIPDB.py --test
# Check log creation
tail -f /var/log/fortigate_quarantine.log
FortiGateToAbuseIPDB/
โโโ ๐ config_local.py # Your actual credentials (never committed)
โโโ ๐ config.example.py # Template for others
โโโ ๐ fortigate.list # Your FortiGate devices
โโโ ๐ fortigate.list.example # Template
โโโ ๐ fortigate_creds.dat # Encrypted SSH credentials
โโโ ๐ ip_whitelist.txt # Your IP whitelist
โโโ ๐ ip_whitelist.txt.example # Template
โโโ ๐ .gitignore # Prevents credential exposure
CONFIG = {
# SSH Configuration
'ssh_timeout': 30, # Connection timeout (seconds)
'command_timeout': 60, # Command execution timeout
'ssh_keepalive_interval': 10, # Keepalive interval
'max_retries': 3, # Retry attempts on failure
'retry_delay': 2, # Delay between retries
# Processing Configuration
'delay_between_fortigates': 5, # Delay between devices
'api_call_delay': 0.5, # Delay between API calls
# Paths
'log_file': '/var/log/fortigate_quarantine.log',
'whois_cache_file': '/tmp/fortigate_whois_cache.pkl',
}
# AbuseIPDB Settings
ABUSEIPDB_CONFIG = {
'api_key': 'your_key_here',
'check_url': 'https://api.abuseipdb.com/api/v2/check',
'report_url': 'https://api.abuseipdb.com/api/v2/report',
'max_age_days': 90,
'rate_limit_minutes': 15,
}
Automatically Filtered (Never Reported):
Type | Ranges | Description |
---|---|---|
๐ Private IPv4 | 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 |
RFC 1918 |
๐ Link-Local | 169.254.0.0/16 | APIPA |
๐ Loopback | 127.0.0.0/8 | Localhost |
๐ก Multicast | 224.0.0.0/4 | Multicast |
๐ CGN | 100.64.0.0/10 | Carrier-grade NAT |
๐ Private IPv6 | fc00::/7 fd00::/8 |
Unique Local |
๐ Link-Local v6 | fe80::/10 | Link-local |
๐ Loopback v6 | ::1/128 | Localhost |
๐ก Multicast v6 | ff00::/8 | Multicast |
DNS_WHITELIST = {
# Google DNS
'8.8.8.8', '8.8.4.4',
'2001:4860:4860::8888', '2001:4860:4860::8844',
# Cloudflare
'1.1.1.1', '1.0.0.1',
'2606:4700:4700::1111', '2606:4700:4700::1001',
# Quad9
'9.9.9.9', '149.112.112.112',
'2620:fe::fe', '2620:fe::9',
# OpenDNS
'208.67.222.222', '208.67.220.220',
}
For enhanced security, use environment variables:
# Export in your shell profile
export ABUSEIPDB_API_KEY="your_api_key"
export FORTIGATE_SSH_USER="admin"
export FORTIGATE_SSH_PASS="password"
export SMTP_PASSWORD="email_password"
# Use in Python
import os
API_KEY = os.getenv('ABUSEIPDB_API_KEY')
# Standard run
python3 fortigate2AbuseIPDB.py
# Verbose mode
python3 fortigate2AbuseIPDB.py -v
# Test mode (no reporting)
python3 fortigate2AbuseIPDB.py --test
# Terminal report
python3 generate_stats_report.py
# Email report
python3 fortigate2AbuseIPDB_stats.py
# Export to JSON
python3 generate_stats_report.py --json
# Export to CSV
python3 generate_stats_report.py --csv
# Both exports, quiet mode
python3 generate_stats_report.py --json --csv --quiet
# Edit crontab
crontab -e
# Add scheduled tasks
# Process FortiGates every 4 hours
0 */4 * * * /usr/bin/python3 /opt/FortiGateToAbuseIPDB/fortigate2AbuseIPDB.py
# Daily email report at 8 AM
0 8 * * * /usr/bin/python3 /opt/FortiGateToAbuseIPDB/fortigate2AbuseIPDB_stats.py
# Weekly CSV export on Mondays
0 9 * * 1 /usr/bin/python3 /opt/FortiGateToAbuseIPDB/generate_stats_report.py --csv
# Monthly cleanup (first day of month)
0 2 1 * * find /var/log -name "fortigate_*.log" -mtime +30 -delete
Create Service File: /etc/systemd/system/fortigate-abuseipdb.service
[Unit]
Description=FortiGate to AbuseIPDB Integration
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
User=security
Group=security
WorkingDirectory=/opt/FortiGateToAbuseIPDB
ExecStart=/usr/bin/python3 /opt/FortiGateToAbuseIPDB/fortigate2AbuseIPDB.py
StandardOutput=journal
StandardError=journal
SyslogIdentifier=fortigate-abuseipdb
# Security
PrivateTmp=yes
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
ReadWritePaths=/var/log /tmp
[Install]
WantedBy=multi-user.target
Create Timer: /etc/systemd/system/fortigate-abuseipdb.timer
[Unit]
Description=Run FortiGate to AbuseIPDB every 4 hours
Requires=fortigate-abuseipdb.service
[Timer]
OnBootSec=10min
OnUnitActiveSec=4h
Persistent=true
[Install]
WantedBy=timers.target
Enable and Start:
# Reload systemd
sudo systemctl daemon-reload
# Enable timer
sudo systemctl enable fortigate-abuseipdb.timer
# Start timer
sudo systemctl start fortigate-abuseipdb.timer
# Check status
sudo systemctl status fortigate-abuseipdb.timer
sudo systemctl list-timers
# Dockerfile
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY *.py ./
COPY config_local.py ./
COPY fortigate.list ./
COPY fortigate_creds.dat ./
COPY ip_whitelist.txt ./
# Create log directory
RUN mkdir -p /var/log
# Run as non-root user
RUN useradd -m -u 1000 fortigate
USER fortigate
CMD ["python3", "fortigate2AbuseIPDB.py"]
# docker-compose.yml
version: '3.8'
services:
fortigate-abuseipdb:
build: .
volumes:
- ./logs:/var/log
- ./cache:/tmp
environment:
- TZ=Europe/Zurich
restart: unless-stopped
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
================================================================================
๐ FORTIGATE SECURITY REPORT ๐
================================================================================
๐ ATTACK OVERVIEW
----------------------------------------
Total Attacks Blocked: 12,457 ๐ซ
Unique Attacking IPs: 3,892 ๐
IPv4 Attacks: 11,203 ๐
IPv6 Attacks: 1,254 ๐
๐ฏ ATTACK CATEGORIES
----------------------------------------
Brute Force 8,901 (71.5%) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
IPS 2,750 (22.1%) โโโโโโโโโโโ
DoS 806 ( 6.4%) โโโ
๐ก๏ธ FILTERING STATISTICS
----------------------------------------
Private IPs Skipped: 145 ๐
User Whitelist Skipped: 23 โ
DNS Servers Skipped: 8 ๐
Total Filtered: 176 ๐
๐ TOP 5 FORTIGATES BY ACTIVITY
----------------------------------------
1. fw-headquarters 4,567 attacks
โโ IPS: 1,250 | DoS: 310 | Auth: 3,007
2. fw-datacenter 3,892 attacks
โโ IPS: 980 | DoS: 412 | Auth: 2,500
3. fw-branch-nyc 2,103 attacks
โโ IPS: 320 | DoS: 84 | Auth: 1,699
4. fw-branch-lon 1,456 attacks
โโ IPS: 150 | DoS: 0 | Auth: 1,306
5. fw-branch-tok 439 attacks
โโ IPS: 50 | DoS: 0 | Auth: 389
โ ๏ธ TOP ATTACKING NETWORKS
----------------------------------------
1. ๐ฉ๐ช 185.230.13.0/24
Attacks: 912 | ISP: BadActor GmbH | ASN: AS12345
Top IPs: .5 (125), .7 (98), .13 (87)
2. ๐ท๐บ 77.90.135.0/24
Attacks: 756 | ISP: CyberCrime LLC | ASN: AS66666
Top IPs: .10 (201), .15 (150), .3 (100)
3. ๐จ๐ณ 123.456.789.0/24
Attacks: 623 | ISP: Unknown | ASN: AS99999
Top IPs: .1 (200), .2 (150), .3 (100)
๐
ATTACK TIMELINE (Last 7 Days)
----------------------------------------
2025-09-07: โโโโโโโโโโโโโโโโ 2,105 (IPS:450 DoS:155 Auth:1,500)
2025-09-08: โโโโโโโโโโโโ 1,623 (IPS:320 DoS:103 Auth:1,200)
2025-09-09: โโโโโโโโโโโโโโ 1,899 (IPS:400 DoS:99 Auth:1,400)
2025-09-10: โโโโโโโโ 1,102 (IPS:200 DoS:102 Auth:800)
2025-09-11: โโโโโโโโโโโโโโ 1,822 (IPS:380 DoS:122 Auth:1,320)
2025-09-12: โโโโโโโโโโโโโโโโ 2,234 (IPS:500 DoS:134 Auth:1,600)
2025-09-13: โโโโโโโโโโโโ 1,672 (IPS:350 DoS:91 Auth:1,231)
================================================================================
Generated: 2025-09-13 14:30:45 | Duration: 2.3s | Cached WHOIS: 892
================================================================================
The HTML email report includes:
- ๐ Executive Dashboard with key metrics
- ๐จ Visual Statistics with color coding
- ๐ Top Threats Table with WHOIS data
- ๐ฅ FortiGate Status by device
- ๐ Trend Indicators (โโ)
- ๐ข Company Branding (logo support)
- ๐ฑ Mobile Responsive design
- ๐ฏ Severity Classifications:
- ๐ด CRITICAL (>1000 attacks)
- ๐ HIGH (500-1000)
- ๐ก MEDIUM (100-500)
- ๐ข LOW (<100)
{
"metadata": {
"generated": "2025-09-13T14:30:45.123456",
"version": "2.1.0",
"duration_seconds": 2.3,
"fortigates_processed": 11
},
"summary": {
"total_attacks": 12457,
"unique_attackers": 3892,
"attack_breakdown": {
"ipv4": 11203,
"ipv6": 1254
},
"categories": {
"brute_force": 8901,
"ips": 2750,
"dos": 806
},
"filtered": {
"private_ips": 145,
"whitelisted": 23,
"dns_servers": 8
}
},
"top_attackers": [
{
"network": "185.230.13.0/24",
"total_attacks": 912,
"unique_ips": 23,
"top_ips": [
{"ip": "185.230.13.5", "count": 125},
{"ip": "185.230.13.7", "count": 98}
],
"whois": {
"country": "DE",
"organization": "BadActor GmbH",
"asn": "AS12345",
"abuse_email": "abuse@badactor.de"
}
}
],
"fortigate_stats": {
"fw-headquarters": {
"total": 4567,
"breakdown": {
"ips": 1250,
"dos": 310,
"brute_force": 3007
},
"last_seen": "2025-09-13T14:25:00"
}
},
"timeline": {
"2025-09-07": {"total": 2105, "ips": 450, "dos": 155, "brute_force": 1500},
"2025-09-08": {"total": 1623, "ips": 320, "dos": 103, "brute_force": 1200}
}
}
Rank,Network_CIDR,Total_Attacks,Unique_IPs,Top_IP,Top_IP_Attacks,Country,Organization,ASN
1,185.230.13.0/24,912,23,185.230.13.5,125,DE,BadActor GmbH,AS12345
2,77.90.135.0/24,756,18,77.90.135.10,201,RU,CyberCrime LLC,AS66666
3,123.456.789.0/24,623,15,123.456.789.1,200,CN,Unknown,AS99999
- Never commit credentials to version control
- Use environment variables for sensitive data
- Rotate credentials regularly (90 days recommended)
- Use strong passwords (16+ characters)
- Enable MFA where possible
- Audit access logs regularly
Layer 1: Git Hooks
โโโ Pre-commit hook blocks secrets
โโโ Automatic detection of credentials
โโโ Forces placeholder usage
Layer 2: Configuration Separation
โโโ config_local.py (never committed)
โโโ .gitignore protection
โโโ Fallback to safe defaults
Layer 3: Encryption
โโโ Base64 encoding (basic)
โโโ Upgradeable to AES-256
โโโ SSH key authentication support
Layer 4: Access Control
โโโ File permissions (600)
โโโ User/group restrictions
โโโ SELinux/AppArmor support
FortiGate Cause | Category | AbuseIPDB IDs | Description |
---|---|---|---|
๐ก๏ธ IPS | Intrusion Prevention | 15, 21 | Hacking, Web App Attack |
๐ฃ DOS/DoS | Denial of Service | 4 | DDoS Attack |
๐ Administrative | Authentication | 18, 22 | Brute Force, SSH |
๐ Web Attack | Web Application | 21 | Web App Attack |
๐ Port Scan | Reconnaissance | 14 | Port Scan |
๐ SQL | Database | 16 | SQL Injection |
๐ค Bot | Automated | 19 | Bad Web Bot |
๐ญ Spoofing | Identity | 17 | Spoofing |
- No personal data collection
- IP addresses are considered infrastructure data
- Audit logs contain only technical information
- Data retention policies supported
- โ OWASP Top 10 compliant
- โ CIS Controls aligned
- โ NIST Framework compatible
- โ ISO 27001 ready
Report Endpoint
POST https://api.abuseipdb.com/api/v2/report
Headers:
Key: YOUR_API_KEY
Accept: application/json
Body:
ip: "192.0.2.1"
categories: "18,22"
comment: "FortiGate detected brute force SSH attack"
Check Endpoint
GET https://api.abuseipdb.com/api/v2/check
Parameters:
ipAddress: "192.0.2.1"
maxAgeInDays: 90
verbose: true
Plan | Reports/Day | Checks/Day | Same IP Cooldown |
---|---|---|---|
Free | 1,000 | 1,000 | 15 minutes |
Basic | 3,000 | 5,000 | 15 minutes |
Premium | 10,000 | 10,000 | 5 minutes |
Enterprise | Unlimited | Unlimited | None |
The suite intelligently queries WHOIS data:
- Caching: 7-day cache to reduce queries
- Fallback Servers: Multiple WHOIS servers
- Smart Parsing: Extracts key fields
- Error Handling: Graceful degradation
WHOIS_SERVERS = [
'whois.iana.org', # Primary
'whois.ripe.net', # Europe
'whois.arin.net', # North America
'whois.apnic.net', # Asia-Pacific
'whois.lacnic.net', # Latin America
'whois.afrinic.net', # Africa
]
# Optimal SSH settings
SSH_CONFIG = {
'ssh_timeout': 30, # Balance between reliability and speed
'command_timeout': 60, # Sufficient for large outputs
'keepalive_interval': 10, # Prevent connection drops
'max_retries': 3, # Handle transient failures
'retry_delay': 2, # Exponential backoff base
}
# Process multiple FortiGates efficiently
BATCH_CONFIG = {
'batch_size': 5, # Concurrent connections
'queue_timeout': 300, # Max queue wait
'worker_threads': 4, # Parallel processors
}
- Stream large outputs instead of loading into memory
- Use generators for IP processing
- Implement connection pooling
- Clear caches periodically
Operation | Average Time | Max Time | Optimization |
---|---|---|---|
SSH Connect | 2.5s | 10s | Connection pooling |
Get Banned IPs | 1.2s | 5s | Command optimization |
Report to API | 0.5s | 2s | Batch reporting |
WHOIS Lookup | 1.0s | 5s | 7-day cache |
Cleanup | 3.0s | 10s | Parallel execution |
Total/FortiGate | 8.2s | 30s | - |
Symptoms:
ERROR: Failed to create SSH connection to 192.168.1.1
Solutions:
- โ Verify SSH is enabled on FortiGate
- โ
Check network connectivity:
ping 192.168.1.1
- โ
Test SSH manually:
ssh admin@192.168.1.1
- โ
Verify credentials in
fortigate_creds.dat
- โ
Check FortiGate SSH settings:
config system global set admin-ssh-port 22 set admin-ssh-grace-period 120 set admin-ssh-password enable end
Symptoms:
ERROR: Failed to report 192.0.2.1: 429 - Rate limit exceeded
Solutions:
- โ Normal for same IP within 15 minutes
- โ Script continues with other IPs
- โ Consider upgrading AbuseIPDB plan
- โ Implement local deduplication
Symptoms:
Email sent successfully!
(But no email in inbox)
Solutions:
- โ Check spam/junk folders
- โ Verify SMTP settings
- โ
Test SMTP connection:
telnet smtp.server.com 587
- โ Check firewall rules for port 587/465
- โ Verify sender is authorized
- โ Check recipient address
Symptoms:
INFO: No banned IPs found
Solutions:
- โ
Verify FortiGate has quarantined IPs:
diagnose user banned-ip list # FortiOS 7.4 diagnose user quarantine list # FortiOS 7.0
- โ Check FortiGate version detection
- โ Ensure proper permissions
- โ Verify command syntax for your FortiOS version
Enable verbose logging for troubleshooting:
# In any script, add:
import logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
Or set environment variable:
export FORTIGATE_DEBUG=1
python3 fortigate2AbuseIPDB.py
# View recent errors
grep ERROR /var/log/fortigate_quarantine.log | tail -20
# Check FortiGate processing
grep "Processing FortiGate" /var/log/fortigate_quarantine.log
# Monitor in real-time
tail -f /var/log/fortigate_quarantine.log
# Search for specific IP
grep "192.0.2.1" /var/log/fortigate_quarantine.log
# Count operations
grep -c "Successfully reported" /var/log/fortigate_quarantine.log
Metric | Alert Threshold | Check Frequency |
---|---|---|
๐ด Script Failures | Any failure | Every run |
๐ API Errors | >10% of requests | Hourly |
๐ก SSH Timeouts | >5 per run | Daily |
๐ข IPs Reported | <10 per day | Daily |
๐ต Cache Hit Rate | <50% | Weekly |
# /etc/logrotate.d/fortigate-abuseipdb
/var/log/fortigate_quarantine.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 640 security security
postrotate
systemctl reload rsyslog > /dev/null 2>&1 || true
endscript
}
# prometheus.yml
scrape_configs:
- job_name: 'fortigate-abuseipdb'
static_configs:
- targets: ['localhost:9090']
metrics_path: '/metrics'
We welcome contributions! Here's how to help:
- ๐ด Fork the repository
- ๐ฟ Create feature branch (
git checkout -b feature/AmazingFeature
) - ๐ป Write your code following style guide
- โ Add tests if applicable
- ๐ Update documentation
- ๐พ Commit changes (
git commit -m 'Add AmazingFeature'
) - ๐ค Push to branch (
git push origin feature/AmazingFeature
) - ๐ฏ Open Pull Request
- ๐ Follow PEP 8
- ๐ Add docstrings to functions
- ๐ก Use type hints
- ๐ Max line length: 100 characters
- ๐ค Use descriptive variable names
# Run unit tests
python -m pytest tests/
# Check code style
flake8 *.py
# Type checking
mypy *.py
# Security scan
bandit -r *.py
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Paolo Kappa
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: kappa@goline.ch
- ๐ Security: Report vulnerabilities via GitHub Security Advisories
![]() Paolo Kappa ๐ป ๐ ๐ง |
- ๐ข AbuseIPDB for their threat intelligence platform
- ๐ฅ Fortinet for FortiGate firewalls
- ๐ Python community for amazing libraries
- ๐ Security community for continuous support
- โ Coffee for late-night coding sessions
Component | Status | Version | Last Update |
---|---|---|---|
๐ฏ Core Engine | 2.1.0 | Sep 2025 | |
๐ Stats Analyzer | 2.1.0 | Sep 2025 | |
๐ง Email Reports | 2.1.0 | Sep 2025 | |
๐ Documentation | 2.1.0 | Sep 2025 |
- ๐ Web dashboard
- ๐ Real-time monitoring
- ๐ Bi-directional sync
- ๐ค Machine learning for pattern detection
- โ๏ธ Cloud deployment options
- ๐ Integration with SIEM platforms
- ๐ฑ Mobile app for monitoring
- ๐ Multi-language support
- ๐ Performance: Use SSD for log storage
- ๐ Security: Rotate credentials every 90 days
- ๐ Analytics: Export weekly reports for trending
- ๐ Automation: Use systemd timers over cron
- ๐ง Emails: Use app-specific passwords for SMTP
- ๐ Network: Use dedicated management VLAN
- ๐พ Backup: Regular backup of configuration
- ๐ Documentation: Keep FortiGate list updated