├── .gitignore ├── README.rst ├── autofilter └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | autofilter.conf 2 | var/ 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | autofilter (version 2.0) 2 | ======================== 3 | 4 | Automatically mitigate layer 7 DDoS attacks. 5 | 6 | Automatically mitigate layer 7 DDoS attacks by adding abusive IPs to nginx blacklist. IP considered as belonging to bot when passed a threshold of requests per minute. 7 | Custom thresholds can be set for every country code, CIDR subnet or single IP. Different request weight counted for requests to static and requests to dynamic content. 8 | 9 | Installation 10 | ------------ 11 | 12 | - ``cd /opt`` 13 | - ``git clone https://github.com/makhomed/autofilter.git autofilter`` 14 | 15 | Also you need to install python3, unbound, dnspython and netaddr: 16 | 17 | .. code-block:: none 18 | 19 | # yum install python3 20 | # yum install unbound 21 | # vim /etc/unbound/unbound.conf 22 | interface: 127.0.0.1 23 | do-ip6: no 24 | # systemctl enable unbound 25 | # systemctl start unbound 26 | 27 | # pip3 install dnspython 28 | # pip3 install netaddr 29 | 30 | Upgrade 31 | ------- 32 | 33 | - ``cd /opt/autofilter`` 34 | - ``git pull`` 35 | 36 | Configuration 37 | ------------- 38 | 39 | Configuration file ``/opt/autofilter/autofilter.conf`` is optional. 40 | 41 | If no config file provided - default built-in config is used: 42 | 43 | .. code-block:: none 44 | 45 | block ALL 24h 46 | 47 | limit ALL 128 32 48 | 49 | Configuration file allow comments, from symbol ``#`` to end of line. 50 | 51 | Configuration file has only two directives: ``limit`` and ``block``. 52 | 53 | ``limit`` directive has syntax: ``limit ``. 54 | 55 | ```` can be ``ALL``, or country code, for example, ``UA`` or ``RU`` or ``CN``. 56 | Also ```` can be IP address, ipv4 or ipv6 or IP network in CIDR notation. 57 | 58 | ```` is total request count after which specific ip address will be blocked. 59 | 60 | ```` is request count to only one uri after which specific ip address will be blocked. 61 | 62 | Each threshold is integer number or special value ``none``. 63 | 64 | Request count measured as one-minute sum of request weight for each request from each ip. 65 | One request to static resource or one nginx-level redirect measured as weight 0.01, 66 | all other requests considered as requests to backend, and has weight 1.0. 67 | 68 | If some specific ip generates load above threshold - this ip will be blocked as bot. 69 | 70 | Search engine bots from Google, Yandex and Bing are detected automatically and will be never blocked. 71 | 72 | By default ``limit ALL 128 32`` if other value not specified in config. 73 | 74 | ``block`` directive has syntax: ``block