豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

barateza/ddos-analysis

Repository files navigation

DDoS Analysis Automation Script

Welcome, fellow defender. This script transforms the tedious process of rooting out malicious traffic into a streamlined, automated investigation tool for Plesk servers. It collects, filters, and reports on HTTP logs across multiple virtual hosts — with optional reputation checks via AbuseIPDB.

Current Version: v1.1.1 — Production Ready Security: Strict mode (set -euo pipefail), secure temp dirs (mktemp), no eval Test Coverage: 100% (61/61 tests passing) Performance: Zero-copy log streaming, snapshot-based connection monitoring


Key Features

Real-Time Attack Detection (--real-time)

  • Live Connection Monitoring: Tracks ESTABLISHED, SYN_RECV, and TIME_WAIT states via ss snapshots
  • SYN-Flood Detection: Automatic alerting when SYN_RECV counts exceed configurable thresholds
  • Target IP Identification: Identifies specific server IPs under attack in multi-IP environments
  • Domain Load Tracking: Live log tailing to identify most-targeted domains as attacks unfold

Post-Mortem Analysis (Default Mode)

  • Forensic Investigation: Extracts entries for a given attack date across all virtual hosts
  • Zero-Copy Streaming: Direct log analysis from gzip/plain text sources — ~90% faster than copy-based approaches
  • IP Reputation: Optional AbuseIPDB integration for automated scoring (Python 3 native parser)
  • Domain-to-IP Correlation: Detailed reports showing precisely which domains each IP targeted

Hourly Pattern Analysis (--hourly-analysis)

  • Baseline Anomaly Detection: Flags spikes using configurable thresholds (default: 200% above baseline)
  • Attack Windows: Precisely identifies start, peak, and recovery times for an incident
  • CSV Export: Generate actionable metrics for spreadsheets and stakeholder reports

Architecture & Safety

  • Dry-Run Mode: Preview every action before execution
  • Dual-Stack Support: Full IPv4 and IPv6 compatibility including internal range filtering
  • Portable: Works across Linux distributions with minimal dependencies

Prerequisites

  • OS: Linux (tested on Ubuntu, Debian, RHEL, CentOS)
  • Permissions: Root access required (system logs and network state)
  • Utilities: bash, grep, find, curl, python3 (AbuseIPDB), ss (real-time mode), awk (hourly analysis)

Quick Start

# Make executable
chmod +x ddos-analysis.sh

# Post-mortem analysis (interactive)
sudo ./ddos-analysis.sh --log-days 3

# Real-time monitoring
sudo ./ddos-analysis.sh --real-time --refresh-rate 2

# With IP reputation lookup
export ABUSEIPDB_API_KEY="your_api_key_here"
sudo ./ddos-analysis.sh --with-abuseipdb-query

Core Options

Flag Purpose
-d, --dry-run Preview actions without modification
-l, --log-days DAYS Time window for log collection (default: 3)
--date DATE Specify attack date (e.g. 15/Jan/2026) for non-interactive use
--target-ip IP Filter investigation to a specific server IP
--no-cleanup Retain timestamped investigation directory on exit
--baseline-threshold % Sensitivity for hourly anomaly detection (default: 200)
--export-csv Export hourly analysis to CSV

Examples

# Non-interactive post-mortem with reputation lookup
./ddos-analysis.sh --date "15/Jan/2026" --target-ip "203.0.113.5" --with-abuseipdb-query

# High-sensitivity real-time monitoring
./ddos-analysis.sh --real-time --syn-threshold 100 --refresh-rate 1

How It Works

Real-Time Mode

  1. Uses ss to track ESTABLISHED and SYN_RECV connection counts
  2. Alerts when SYN_RECV threshold is exceeded
  3. Ranks source IPs by active connection count
  4. Shows which server IPs are receiving the attack
  5. Tails recent access logs to identify most-targeted domains

Post-Mortem Mode

  1. Creates secure working directory under /tmp/ddos_investigation_<random>
  2. Streams access* files from all vhost directories
  3. Filters entries by specified attack date
  4. Counts and sorts top IPs; runs optional AbuseIPDB lookup
  5. Maps each IP to the domains it targeted

Troubleshooting

Problem Fix
Permission denied Run with sudo
ss not found Install iproute2
AbuseIPDB errors Verify ABUSEIPDB_API_KEY is set and python3 is available

Links

About

A high-performance Bash toolset for real-time DDoS detection and post-mortem log analysis with AbuseIPDB integration.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages