I have a fail2ban rule for Apache2 logs that which looks like this:
[Definition]
failregex = ^[^ ]+ <HOST> .* \[\] "[^\"]*" 408 \d+
This will detect the 408 errors which happen when a TCP connection times out.
The following is the Jail definition that uses the definition above:
[snap-apache-timeout]
enabled = true
filter = snap-apache-timeout-filter
action = snap-firewall-action[scheme=all,period=year,reason=fail2ban: apache timeout]
logpath = %(apache_access_log)s
maxretry = 35
findtime = 3600
As we can see, I set this up as a max-retry of 35 within one hour. In other words, if I get 35+ HTTP 408 errors within one hour, I run the corresponding action which is to block the user's IP address.
Only, I get some of my customers blocked once in a while. I am thinking this in part happens because some closes their browser while some connections were still open in the background (i.e. the user clicks to go to another page and does not wait for it to be loaded but instead just closes the page.)
What do you do against Slowloris? Nothing?
The more I look at it and the more I'm thinking this is not very doable with just the Apache2 408 error (i.e. that's not the same as detecting a really slow connection! Just that the connection is lost once in a while...)
There are logs between two 408 for a given IP address which causes problems. Unfortunately Apache does not show which connection times out. Maybe it's possible to add that to the logs?
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:08:54 +0000] "-" 408 5845 "-" "-"
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:08:39 +0000] "GET /finball/location/exdox_snap5-204/data HTTP/1.1" 200 2569 "exdox.com" "https://exdox.com/dashboard" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:03 +0000] "GET /finball/location/exdox_snap5-204/logo.png/icon-77x77.png?fallback=ok HTTP/1.1" 200 10883 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:05 +0000] "GET /favicon.ico HTTP/1.1" 200 1406 "exdox.com" "-" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:06 +0000] "GET /finball/location/exdox_snap5-204/data/create/20170406 HTTP/1.1" 303 238 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:06 +0000] "GET /finball/location/exdox_snap5-204/data/create/20170406 HTTP/1.1" 303 238 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:11 +0000] "GET /finball/location/exdox_snap5-204/data/create/20170405 HTTP/1.1" 303 237 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:11 +0000] "GET /finball/location/exdox_snap5-204/data/create/20170405 HTTP/1.1" 303 237 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:06 +0000] "GET /finball/location/exdox_snap5-204/data/20170406?a=edit HTTP/1.1" 200 3521 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:12 +0000] "GET /finball/location/exdox_snap5-204/data/20170405?a=edit HTTP/1.1" 200 6516 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:16 +0000] "GET /finball/location/exdox_snap5-204/logo.png/icon-77x77.png?fallback=ok HTTP/1.1" 200 10883 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data/20170405?a=edit" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:17 +0000] "GET /favicon.ico HTTP/1.1" 200 1406 "exdox.com" "-" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:09:56 +0000] "GET /finball/location/exdox_snap5-204/data HTTP/1.1" 200 2569 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data/20170405?a=edit" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:10:01 +0000] "GET /finball/location/exdox_snap5-204/logo.png/icon-77x77.png?fallback=ok HTTP/1.1" 200 10883 "exdox.com" "https://exdox.com/finball/location/exdox_snap5-204/data" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:10:01 +0000] "GET /favicon.ico HTTP/1.1" 200 1406 "exdox.com" "-" "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" TLSv1.2 ECDHE-RSA-AES256-SHA384
exdox.com:443 a.b.c.d - - [07/Apr/2017:15:10:21 +0000] "-" 408 193 "-" "-"
As per @symcbean's answer below, the page mentions the use of the reqtimeout
Apache2 module. I have that installed with the default
settings:
RequestReadTimeout header=20-40,minrate=500
RequestReadTimeout body=10,minrate=500
I do not use the qos
or security
modules as mentioned on that page. Instead, I have fail2ban
to check the logs for 408 errors as shown above. I don't think that's any different from the security
setup shown on that page except that one says "if more than 5 in the last minute".