Hosting & Domaining Forum

Hosting Discussion => Hosting Security and Technology => Topic started by: gopasruhafoni on Nov 07, 2024, 12:13 AM

Title: Automating DDoS Defense
Post by: gopasruhafoni on Nov 07, 2024, 12:13 AM
Recently, I've been experiencing a peculiar issue with my Virtual Dedicated Server (VDS) where it would significantly slow down during nighttime hours, despite having configured Nginx to return error codes 444 and 503 when faced with an excessive request rate of over 3 requests per second.
What's more astonishing is that a single Nginx process would consume more than 50% of the CPU, not to mention the additional resource-intensive processes like php-fpm and MySQL, which would culminate in a system-wide chaos. This led to an alarmingly high Load Average of 8. Furthermore, the Nginx logs would proliferate at an exponential rate, rapidly consuming all available disk space on the VDS and ultimately causing the database to crash.

In response to this predicament, I decided to implement a DDoS mitigation strategy. Fortunately, I was able to leverage the assistance of a GPT chat to help me craft the necessary code.

The underlying principle of this solution is analogous to a scythe that methodically trims the grass, wherein we periodically clean the Nginx logs, wait for a brief interval of 1 minute, and then identify the IP addresses that have exceeded a predetermined threshold of 9 requests per minute. These offending IPs are subsequently banned, with some having initiated as many as 10 to 1000 requests per minute. To avoid inadvertently blocking legitimate traffic, I established a whitelist of IP addresses for search engines and my own IP.

The remaining suspicious IPs are then blocked at the firewall level using iptables. Notably, within a mere 4 hours of a DOS attack, our script successfully blocked an astonishing 8000 IPs. When the system is under minimal load, the protection mechanism is disabled, and the script remains dormant. After a 4-day configuration process with the GPT chat, our solution is now fully operational, with the script launching every minute via cron when the load average exceeds 1, scrutinizing IP ratings, and promptly banning any IP that breaches the threshold.

This experience has led me to realize that substantial investments in DDoS protection, proxying, and other security measures may not always be necessary. By simply deploying this script, one can significantly alleviate concerns about DOS attacks and enjoy a more secure server environment, effectively creating a localized analogue of Cloudflare on one's server.
Title: Re: Automating DDoS Defense
Post by: sahildd on Nov 07, 2024, 03:24 AM
Sure, blocking 8000 IPs is impressive, but are you prepared for the fallout? A script like yours can lead to false positives, inadvertently banning legitimate users and affecting your site's reputation.

Plus, managing iptables manually can become a nightmare as the list grows. Instead of piecemeal solutions, consider integrating a dedicated DDoS protection service (StackPath, Radware, Imperva ...) . They provide real-time monitoring and adaptive filtering that your script simply can't match. Why gamble with your server's health when a robust solution is just an investment away?
Title: Re: Automating DDoS Defense
Post by: flo3d on Nov 07, 2024, 07:20 AM
Kudos to the ingenious creator of the fail2ban script, a ubiquitous security solution deployed on a staggering number of servers worldwide, and seamlessly integrated into the most widely-used control panels. It's likely that the nuances of Distributed Denial-of-Service (DDoS) attacks are lost on you, given your apparent unfamiliarity with the intricacies of cybersecurity. Moreover, it's worth noting that Cloudflare's freemium model can be misleading, as the costs associated with its premium features and services are not immediately transparent, leaving users to wonder what exactly they're paying for.
Title: Re: Automating DDoS Defense
Post by: albert_Cage on Nov 07, 2024, 12:21 PM
It appears that the channel is experiencing a debilitating case of amplification attacks, courtesy of a Distributed Denial of Service (DDoS) onslaught. The throughput is severely bottlenecked, and I'm afraid that even the most robust server-side security measures won't be enough to mitigate this issue. What's being described sounds more akin to a scraper or a spidering tool gone haywire, rather than a genuine DDoS attack.

It's possible that the channel is being hammered by a malicious actor employing a botnet to flood the system with junk traffic, thereby causing a denial of service. In this scenario, traditional security protocols might not be effective in stemming the tide of this digital deluge.