bad behavior - move from fail2ban to pure lua

This commit is contained in:
bunkerity
2021-05-13 16:21:51 +02:00
parent eb2d0d330d
commit 0b3ff6a9f4
27 changed files with 90 additions and 148 deletions

11
confs/site/log-lua.conf Normal file
View File

@@ -0,0 +1,11 @@
log_by_lua_block {
local use_bad_behavior = %USE_BAD_BEHAVIOR%
local behavior = require "behavior"
if use_bad_behavior then
behavior.count()
end
}

View File

@@ -20,6 +20,7 @@ local use_antibot_cookie = %USE_ANTIBOT_COOKIE%
local use_antibot_javascript = %USE_ANTIBOT_JAVASCRIPT%
local use_antibot_captcha = %USE_ANTIBOT_CAPTCHA%
local use_antibot_recaptcha = %USE_ANTIBOT_RECAPTCHA%
local use_bad_behavior = %USE_BAD_BEHAVIOR%
-- include LUA code
local whitelist = require "whitelist"
@@ -30,6 +31,7 @@ local javascript = require "javascript"
local captcha = require "captcha"
local recaptcha = require "recaptcha"
local iputils = require "resty.iputils"
local behavior = require "behavior"
-- user variables
local antibot_uri = "%ANTIBOT_URI%"
@@ -98,6 +100,12 @@ if use_blacklist_reverse and not blacklist.reverse_cached() then
end
end
-- check if IP is banned because of "bad behavior"
if use_bad_behavior and behavior.is_banned() then
ngx.log(ngx.NOTICE, "[BLOCK] IP " .. ngx.var.remote_addr .. " is banned because of bad behavior")
ngx.exit(ngx.HTTP_FORBIDDEN)
end
-- check if IP is in proxies list
if use_proxies then
local value, flags = ngx.shared.proxies_data:get(iputils.ip2bin(ngx.var.remote_addr))

View File

@@ -4,7 +4,7 @@ server {
%FASTCGI_PATH%
%SERVER_CONF%
%PROXY_REAL_IP%
%MAIN_LUA%
%INCLUDE_LUA%
%USE_MODSECURITY%
%LISTEN_HTTP%
%USE_HTTPS%
@@ -29,7 +29,6 @@ server {
%PERMISSIONS_POLICY%
%COOKIE_FLAGS%
%ERRORS%
%USE_FAIL2BAN%
%USE_CLIENT_CACHE%
%USE_GZIP%
%USE_BROTLI%