惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
量子位
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
爱范儿
爱范儿
博客园 - 【当耐特】
Vercel News
Vercel News
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
博客园 - 叶小钗
博客园_首页
V
Visual Studio Blog
宝玉的分享
宝玉的分享
B
Blog
MyScale Blog
MyScale Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Built a Real-Time DDoS Detection System with Python...
George-Adaba · 2026-04-30 · via DEV Community

👋 Introduction

As a beginner stepping into DevOps and cybersecurity, I wanted to build something practical and impactful — not just theory.

So I built a real-time DDoS detection and mitigation system that:

Monitors live traffic from Nginx logs
Detects suspicious spikes using statistics
Automatically blocks attacking IPs
Sends alerts to Slack
Displays everything on a live dashboard

In this post, I’ll walk you through exactly how it works — in a simple, beginner-friendly way.

🧠 What Problem Am I Solving?

A DDoS (Distributed Denial of Service) attack happens when a server gets flooded with too many requests.

This can:

Slow down your app
Crash your server
Make your service unavailable

👉 My solution:
Build a system that can detect abnormal traffic and stop it automatically

🏗️ Project Architecture

Here’s what I used:

Nginx → Handles incoming traffic
Nextcloud → Sample app (target)
Python daemon → Detects attacks
Docker Compose → Runs everything
Slack Webhook → Sends alerts
Dashboard UI → Shows live metrics
🔍 Step 1: Monitoring Nginx Logs

Nginx logs every request like this:

127.0.0.1 - - [timestamp] "GET /index.html" 200

My system:

Reads logs in real-time
Extracts:
IP address
Timestamp
Status code
⏱️ Step 2: Sliding Window (Core Idea)

To detect attacks, I track requests over time using a sliding window.

Think of it like:

“How many requests happened in the last 60 seconds?”

I used Python’s deque to:

Add new requests
Remove old ones automatically
📊 Step 3: Building a Baseline

Instead of guessing what’s “too much traffic”, I calculate a baseline:

Track requests per second over 30 minutes
Compute:
Mean (average traffic)
Standard deviation

This helps answer:

“What does normal traffic look like?”

🚨 Step 4: Detecting Anomalies

I detect attacks using two methods:

  1. Z-score

If traffic is far above normal:

z-score > 3

  1. Spike detection

If traffic is:

5x the average

👉 If either condition is true → it’s an attack

🔥 Step 5: Blocking Attackers

When an IP is suspicious:

I block it using iptables
Example:
iptables -A INPUT -s -j DROP
🔄 Step 6: Auto-Unban System

Not every spike is an attack forever.

So I implemented a backoff unban system:

10 minutes
30 minutes
2 hours
Permanent (if repeated)
🔔 Step 7: Slack Alerts

I used Slack webhooks to send alerts like:

🚨 Global traffic spike
🚨 IP blocked
✅ IP unbanned
📊 Step 8: Live Dashboard

I built a simple dashboard that shows:

Global requests per second
Top 10 IPs
Banned IPs
CPU & memory usage
Baseline stats

It refreshes every 3 seconds.

🐳 Step 9: Dockerizing Everything

I used Docker Compose to run:

Nginx
Nextcloud
Detector service

This made setup easy and reproducible.

⚠️ Challenges I Faced

  1. Secrets in GitHub

GitHub blocked my push because of a Slack webhook.

👉 Fix:

Moved webhook to environment variables

  1. Container Not Starting

My app kept crashing because config.yaml was missing.

👉 Fix:

Added it to Docker image

  1. No Slack Alerts

The container couldn’t access environment variables.

👉 Fix:

Passed variables via docker-compose.yml
🎯 What I Learned
How real-time log monitoring works
How to detect anomalies using statistics
How to automate security responses
How to use Docker in real projects
Why never to commit secrets
🚀 Final Thoughts

This project helped me move from:

“Just learning DevOps” → “Building real-world systems”

If you’re a beginner, I highly recommend building something like this.

Dashboard URL http://52.203.164.199:5000/
Github Repo https://github.com/George-Adaba/anomaly-detection-ddos.git