search
HomeSystem TutorialLINUXThe evasive module protects your website from application layer DOS attacks

The evasive module protects your website from application layer DOS attacks

Apr 30, 2024 pm 05:34 PM
linuxapachelinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

There are many attack methods that can cause a website to go offline. More complex methods require technical knowledge in database and programming. A simpler method is called a "Denial Of ServiceDenial Of Service" (DOS) attack. The name of this attack method comes from its intention: to cause normal service requests from ordinary customers or website visitors to be denied.

evasive 模块保护您的网站免受应用层 DOS 攻击

Generally speaking, there are two forms of DOS attacks:

  1. The third and fourth layers of the OSI model, namely network layer attacks
  2. Seven layers of the OSI model, namely application layer attacks

The first type of DOS attack, the network layer, occurs when a large amount of junk traffic flows to the web server. When spam traffic exceeds the capacity of the network, the website goes down.

The second type of DOS attack is at the application layer and utilizes legitimate service requests rather than junk traffic. When the number of page requests exceeds the capacity of the web server, even legitimate visitors will be unable to use the website.

This article will focus on mitigating application layer attacks, since mitigating network layer attacks requires a large amount of available bandwidth and the cooperation of upstream providers, which is not usually possible by configuring a network server.

By configuring an ordinary web server, web pages can be protected from application layer attacks, at least with moderate protection. Preventing this form of attack is very important, as Cloudflare[1] recently reported[2] that the number of network layer attacks is decreasing, while the number of application layer attacks is increasing. Increase.

This article will introduce how to use the Apache2 module mod_evasive[4] developed by zdziarski[3].

In addition, mod_evasive will block attackers' attempts to guess (i.e., brute force attacks) by trying hundreds of username and password combinations.

mod_evasive logs the number of requests from each IP address. When this number exceeds one of several thresholds for the corresponding IP address, an error page appears. Error pages require far fewer resources than an online website that can respond to legitimate visits.

Install mod_evasive on Ubuntu 16.04

The default software library of Ubuntu 16.04 includes mod_evasive, named "libapache2-mod-evasive". You can use apt-get to complete the installation:

apt-get update
apt-get upgrade
apt-get install libapache2-mod-evasive

Now we need to configure mod_evasive.

Its configuration file is located at /etc/apache2/mods-available/evasive.conf. By default, all module settings are commented out after installation. Therefore, the module will not interfere with website traffic until the configuration file is modified.

<ifmodule mod_evasive20.c>
   #DOSHashTableSize    3097
   #DOSPageCount        2
   #DOSSiteCount        50
   #DOSPageInterval     1
   #DOSSiteInterval     1
   #DOSBlockingPeriod   10

   #DOSEmailNotify      you@yourdomain.com
   #DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
   #DOSLogDir           "/var/log/mod_evasive"
</ifmodule>

The meaning of the first part of the parameters is as follows:

  • DOSHashTableSize - The current list of IP addresses that are accessing the website and their number of requests.
  • DOSPageCount - The number of requests for each page within a certain time interval. The time interval is defined by DOSPageInterval.
  • DOSPageInterval - mod_evasive counts the time interval for page requests.
  • DOSSiteCount - Same as DOSPageCount, but counts the number of requests to any page within the site from the same IP address.
  • DOSSiteInterval - mod_evasive counts the time interval for website requests.
  • DOSBlockingPeriod - The length of time (in seconds) that an IP address has been blacklisted.

If the default configuration shown above is used, an IP address will be blacklisted under the following circumstances:

  • The same page is requested more than twice per second.
  • Request more than 50 different pages per second.

If an IP address exceeds these thresholds, it will be blacklisted for 10 seconds.

This may not seem like a long time, but mod_evasive will always monitor page requests for blacklisted IP addresses and reset their blacklist start time. As long as an IP address keeps trying to DOS attack the website, it will always be on the blacklist.

The remaining parameters are:

  • DOSEmailNotify - Email address used to receive DOS attack information and IP address blacklisting.
  • DOSSystemCommand - Command to run when a DOS attack is detected.
  • DOSLogDir - The directory used to store temporary files for mod_evasive.
Configuration mod_evasive

默认的配置是一个很好的开始,因为它不会阻塞任何合法的用户。取消配置文件中的所有参数(DOSSystemCommand 除外)的注释,如下所示:

<ifmodule mod_evasive20.c>
   DOSHashTableSize   3097
   DOSPageCount       2
   DOSSiteCount       50
   DOSPageInterval    1
   DOSSiteInterval    1
   DOSBlockingPeriod  10

   DOSEmailNotify       JohnW@example.com
   #DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
   DOSLogDir            "/var/log/mod_evasive"
</ifmodule>

必须要创建日志目录并且要赋予其与 apache 进程相同的所有者。这里创建的目录是 /var/log/mod_evasive ,并且在 Ubuntu 上将该目录的所有者和组设置为 www-data ,与 Apache 服务器相同:

mkdir /var/log/mod_evasive
chown www-data:www-data /var/log/mod_evasive

在编辑了 Apache 的配置之后,特别是在正在运行的网站上,在重新启动或重新加载之前,最好检查一下语法,因为语法错误将影响 Apache 的启动从而使网站宕机。

Apache 包含一个辅助命令,是一个配置语法检查器。只需运行以下命令来检查您的语法:

apachectl configtest

如果您的配置是正确的,会得到如下结果:

Syntax OK

但是,如果出现问题,您会被告知在哪部分发生了什么错误,例如:

AH00526: Syntax error on line 6 of /etc/apache2/mods-enabled/evasive.conf:
DOSSiteInterval takes one argument, Set site interval
Action 'configtest' failed.
The Apache error log may have more information.

如果您的配置通过了 configtest 的测试,那么这个模块可以安全地被启用并且 Apache 可以重新加载:

a2enmod evasive
systemctl reload apache2.service

mod_evasive 现在已配置好并正在运行了。

测试

为了测试 mod_evasive,我们只需要向服务器提出足够的网页访问请求,以使其超出阈值,并记录来自 Apache 的响应代码。

一个正常并成功的页面请求将收到如下响应:

HTTP/1.1 200 OK

但是,被 mod_evasive 拒绝的将返回以下内容:

HTTP/1.1 403 Forbidden

以下脚本会尽可能迅速地向本地主机(127.0.0.1,localhost)的 80 端口发送 HTTP 请求,并打印出每个请求的响应代码。

你所要做的就是把下面的 bash 脚本复制到一个文件中,例如 mod_evasive_test.sh

#!/bin/bash
set -e

for i in {1..50}; do
        curl -s -I 127.0.0.1 | head -n 1
done

这个脚本的部分含义如下:

  • curl - 这是一个发出网络请求的命令。
    • -s - 隐藏进度表。
    • -I - 仅显示响应头部信息。
  • head - 打印文件的第一部分。
    • -n 1 - 只显示第一行。

然后赋予其执行权限:

chmod 755 mod_evasive_test.sh

在启用 mod_evasive 之前,脚本运行时,将会看到 50 行 “HTTP / 1.1 200 OK” 的返回值。

但是,启用 mod_evasive 后,您将看到以下内容:

HTTP/1.1 200 OK
HTTP/1.1 200 OK
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
...

前两个请求被允许,但是在同一秒内第三个请求发出时,mod_evasive 拒绝了任何进一步的请求。您还将收到一封电子邮件(邮件地址在选项 DOSEmailNotify 中设置),通知您有 DOS 攻击被检测到。

mod_evasive 现在已经在保护您的网站啦!


The above is the detailed content of The evasive module protects your website from application layer DOS attacks. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Linux就该这么学. If there is any infringement, please contact admin@php.cn delete
Warehouse: A GUI for Effortlessly Handling Flatpak AppsWarehouse: A GUI for Effortlessly Handling Flatpak AppsMay 09, 2025 am 11:30 AM

A GUI for Effortless Flatpak Management: Introducing Warehouse Managing a growing collection of Flatpak applications can be cumbersome using only the command line. Enter Warehouse, a user-friendly graphical interface designed to streamline Flatpak a

8 Powerful Linux Commands to Identify Hard Drive Bottlenecks8 Powerful Linux Commands to Identify Hard Drive BottlenecksMay 09, 2025 am 11:03 AM

This article provides a comprehensive guide to identifying and resolving hard drive bottlenecks in Linux systems. Experienced server administrators will find this particularly useful. Slow disk operations can severely impact application performance,

4 Best QR Code Generators for Linux Users4 Best QR Code Generators for Linux UsersMay 09, 2025 am 10:27 AM

Efficient QR code generation tool under Linux system In today's digital world, QR codes have become a way to quickly and conveniently share information, simplifying data access from URLs, texts, contacts, Wi-Fi credentials, and even payment information. Linux users can use a variety of tools to create QR codes efficiently. Let's take a look at some popular QR code generators that can be used directly on Linux systems. QRencode QRencode is a lightweight command line tool for generating QR codes on Linux. It is well-received for its simplicity and efficiency and is popular with Linux users who prefer direct methods. Using QRencode, you can use the URL,

elementary OS 8: A User-Friendly Linux for macOS and Windowselementary OS 8: A User-Friendly Linux for macOS and WindowsMay 09, 2025 am 10:19 AM

Elementary OS 8 Circe: A Smooth and Stylish Linux Experience Elementary OS, a Ubuntu-based Linux distribution, has evolved from a simple theme pack into a fully-fledged, independent operating system. Known for its user-friendly interface, elegant de

40  Linux Commands for Every Machine Learning Engineer40 Linux Commands for Every Machine Learning EngineerMay 09, 2025 am 10:06 AM

Mastering Linux is crucial for any machine learning (ML) engineer. Its command-line interface offers unparalleled flexibility and control, streamlining workflows and boosting productivity. This article outlines essential Linux commands, explained fo

Arch Linux Cheat Sheet: Essential Commands for BeginnersArch Linux Cheat Sheet: Essential Commands for BeginnersMay 09, 2025 am 09:54 AM

Arch Linux: A Beginner's Command-Line Cheat Sheet Arch Linux offers unparalleled control but can feel daunting for newcomers. This cheat sheet provides essential commands to confidently manage your system. System Information & Updates These com

How to Install Scikit-learn for Machine Learning on LinuxHow to Install Scikit-learn for Machine Learning on LinuxMay 09, 2025 am 09:53 AM

This guide provides a comprehensive walkthrough of installing and using the Scikit-learn machine learning library on Linux systems. Scikit-learn (sklearn) is a powerful, open-source Python library offering a wide array of tools for various machine l

How to Install Kali Linux Tools in UbuntuHow to Install Kali Linux Tools in UbuntuMay 09, 2025 am 09:46 AM

This guide explains how to leverage Docker for accessing Kali Linux tools, a safer and more efficient alternative to outdated methods like Katoolin. Katoolin is no longer actively maintained and may cause compatibility problems on modern systems. Do

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor