<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adewumi Victor</title>
    <description>The latest articles on DEV Community by Adewumi Victor (@adewumicrown).</description>
    <link>https://dev.to/adewumicrown</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3904453%2F4a0c8b14-8f53-4721-8f5d-660aeca00624.jpg</url>
      <title>DEV Community: Adewumi Victor</title>
      <link>https://dev.to/adewumicrown</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adewumicrown"/>
    <language>en</language>
    <item>
      <title>Building a Self-Learning DDoS Guard</title>
      <dc:creator>Adewumi Victor</dc:creator>
      <pubDate>Wed, 29 Apr 2026 13:40:22 +0000</pubDate>
      <link>https://dev.to/adewumicrown/building-a-self-learning-ddos-guard-4jd4</link>
      <guid>https://dev.to/adewumicrown/building-a-self-learning-ddos-guard-4jd4</guid>
      <description>&lt;p&gt;Real-Time Anomaly Detection with&lt;br&gt;
Python&lt;br&gt;
By Victor • HNG DevSecOps Project Case Study&lt;/p&gt;

&lt;p&gt;In the modern web landscape, static rate limiting is often a blunt instrument. While it&lt;br&gt;
can stop basic brute-force attacks, it struggles with sophisticated, low-and-slow DDoS&lt;br&gt;
attacks or sudden legitimate traffic spikes. For my latest HNG DevSecOps project, I&lt;br&gt;
built a dynamic Anomaly Detection &amp;amp; DDoS Engine that learns from your traffic&lt;br&gt;
patterns and defends your AWS infrastructure in real-time.&lt;/p&gt;

&lt;p&gt;The Problem: Why Static Limits Fail&lt;br&gt;
Most developers set a hard limit: "Allow 100 requests per minute." But what happens at&lt;br&gt;
2:00 AM when your server is usually empty? A sudden burst of 90 requests per&lt;br&gt;
minute from a single IP might be an attack, yet it passes under the radar. Conversely,&lt;br&gt;
during a Black Friday sale, 150 requests might be perfectly normal. I needed a system&lt;br&gt;
that understood context.&lt;/p&gt;

&lt;p&gt;The Solution: Statistical Learning&lt;br&gt;
The heart of this engine is a Python-based daemon that "learns" what normal traffic&lt;br&gt;
looks like for every hour of the day. It uses two key mathematical concepts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Rolling Baseline&lt;br&gt;
Instead of hardcoded numbers, the engine maintains a 30-minute rolling window&lt;br&gt;
of traffic metrics. It calculates the mean and standard deviation for every hour&lt;br&gt;
slot. This allows the system to distinguish between a busy Monday afternoon and&lt;br&gt;
a quiet Sunday night.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Z-Score&lt;br&gt;
To identify an anomaly, we calculate the Z-Score of incoming traffic. The formula&lt;br&gt;
is:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;z = (x - μ) / σ&lt;/p&gt;

&lt;p&gt;Where x is the current traffic rate, μ is the learned mean, and σ is the standard&lt;br&gt;
deviation. If the z exceeds 3.0, the system flags the IP as an anomaly.&lt;/p&gt;

&lt;p&gt;The Architecture&lt;br&gt;
The project is deployed on AWS EC2 using a Dockerized stack:&lt;br&gt;
Nginx: Acts as the frontline, logging every request in a structured JSON format.&lt;br&gt;
Nextcloud: Our sample application being protected.&lt;br&gt;
Python Detector: The "Brain." It tails the Nginx logs, performs statistical&lt;br&gt;
analysis, and makes decisions.&lt;/p&gt;

&lt;p&gt;Active Defense with Iptables&lt;br&gt;
Detection is useless without action. When an IP is flagged, the engine doesn't just&lt;br&gt;
send an alert; it executes a system-level command using iptables to DROP all&lt;br&gt;
traffic from that IP. To ensure we don't block legitimate users forever, I implemented&lt;br&gt;
an Unbanner module. It follows an exponential backoff schedule: 10 minutes, then&lt;br&gt;
30 minutes, then 2 hours, before finally issuing a permanent ban for repeat&lt;br&gt;
offenders.&lt;/p&gt;

&lt;p&gt;Real-Time Visibility&lt;br&gt;
I integrated a Slack notification system to keep the DevOps team informed. Whether&lt;br&gt;
it’s a specific IP being banned, a global traffic surge, or an automatic unban, the team&lt;br&gt;
receives a formatted alert within seconds. Additionally, a Flask-based dashboard&lt;br&gt;
provides a live look at current metrics and system health.&lt;br&gt;
•&lt;br&gt;
•&lt;br&gt;
•&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Securing infrastructure is not just about building walls; it's about building systems&lt;br&gt;
that can think. By combining Python’s data processing power with Linux’s networking&lt;br&gt;
tools, I've created a resilient, self-correcting defense mechanism that scales its&lt;br&gt;
sensitivity based on actual usage patterns.&lt;br&gt;
The code for this project is open-source and available on GitHub at &lt;a href="https://github.com/Adewumicrown/hng-anomaly-detector" rel="noopener noreferrer"&gt;https://github.com/Adewumicrown/hng-anomaly-detector&lt;/a&gt; for anyone looking to try it on their own&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>security</category>
      <category>buildinpublic</category>
    </item>
  </channel>
</rss>
