mirror of https://github.com/fail2ban/fail2ban
bulk unban: add new command `actionflush` default for several iptables/iptables-ipset actions (and common include):
iptables-common iptables iptables-allports iptables-multiport-log iptables-multiport iptables-new iptables-ipset-proto4 iptables-ipset-proto6 iptables-ipset-proto6-allports executing `actionflush` command covered for this actions nowpull/1743/head
parent
a1e9cc552c
commit
d03872fbbf
|
@ -26,7 +26,7 @@ actionstart = <iptables> -N f2b-<name>
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -p <protocol> -j f2b-<name>
|
actionstop = <iptables> -D <chain> -p <protocol> -j f2b-<name>
|
||||||
<iptables> -F f2b-<name>
|
<actionflush>
|
||||||
<iptables> -X f2b-<name>
|
<iptables> -X f2b-<name>
|
||||||
|
|
||||||
# Option: actioncheck
|
# Option: actioncheck
|
||||||
|
|
|
@ -16,6 +16,14 @@ after = iptables-blocktype.local
|
||||||
iptables-common.local
|
iptables-common.local
|
||||||
# iptables-blocktype.local is obsolete
|
# iptables-blocktype.local is obsolete
|
||||||
|
|
||||||
|
[Definition]
|
||||||
|
|
||||||
|
# Option: actionflush
|
||||||
|
# Notes.: command executed once to flush IPS, by shutdown (resp. by stop of the jail or this action)
|
||||||
|
# Values: CMD
|
||||||
|
#
|
||||||
|
actionflush = <iptables> -F f2b-<name>
|
||||||
|
|
||||||
|
|
||||||
[Init]
|
[Init]
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,19 @@ before = iptables-common.conf
|
||||||
actionstart = ipset --create f2b-<name> iphash
|
actionstart = ipset --create f2b-<name> iphash
|
||||||
<iptables> -I <chain> -p <protocol> -m multiport --dports <port> -m set --match-set f2b-<name> src -j <blocktype>
|
<iptables> -I <chain> -p <protocol> -m multiport --dports <port> -m set --match-set f2b-<name> src -j <blocktype>
|
||||||
|
|
||||||
|
|
||||||
|
# Option: actionflush
|
||||||
|
# Notes.: command executed once to flush IPS, by shutdown (resp. by stop of the jail or this action)
|
||||||
|
# Values: CMD
|
||||||
|
#
|
||||||
|
actionflush = ipset --flush f2b-<name>
|
||||||
|
|
||||||
# Option: actionstop
|
# Option: actionstop
|
||||||
# Notes.: command executed once at the end of Fail2Ban
|
# Notes.: command executed once at the end of Fail2Ban
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -m set --match-set f2b-<name> src -j <blocktype>
|
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -m set --match-set f2b-<name> src -j <blocktype>
|
||||||
ipset --flush f2b-<name>
|
<actionflush>
|
||||||
ipset --destroy f2b-<name>
|
ipset --destroy f2b-<name>
|
||||||
|
|
||||||
# Option: actionban
|
# Option: actionban
|
||||||
|
|
|
@ -29,12 +29,18 @@ before = iptables-common.conf
|
||||||
actionstart = ipset create <ipmset> hash:ip timeout <bantime><familyopt>
|
actionstart = ipset create <ipmset> hash:ip timeout <bantime><familyopt>
|
||||||
<iptables> -I <chain> -m set --match-set <ipmset> src -j <blocktype>
|
<iptables> -I <chain> -m set --match-set <ipmset> src -j <blocktype>
|
||||||
|
|
||||||
|
# Option: actionflush
|
||||||
|
# Notes.: command executed once to flush IPS, by shutdown (resp. by stop of the jail or this action)
|
||||||
|
# Values: CMD
|
||||||
|
#
|
||||||
|
actionflush = ipset flush <ipmset>
|
||||||
|
|
||||||
# Option: actionstop
|
# Option: actionstop
|
||||||
# Notes.: command executed once at the end of Fail2Ban
|
# Notes.: command executed once at the end of Fail2Ban
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -m set --match-set <ipmset> src -j <blocktype>
|
actionstop = <iptables> -D <chain> -m set --match-set <ipmset> src -j <blocktype>
|
||||||
ipset flush <ipmset>
|
<actionflush>
|
||||||
ipset destroy <ipmset>
|
ipset destroy <ipmset>
|
||||||
|
|
||||||
# Option: actionban
|
# Option: actionban
|
||||||
|
|
|
@ -29,12 +29,18 @@ before = iptables-common.conf
|
||||||
actionstart = ipset create <ipmset> hash:ip timeout <bantime><familyopt>
|
actionstart = ipset create <ipmset> hash:ip timeout <bantime><familyopt>
|
||||||
<iptables> -I <chain> -p <protocol> -m multiport --dports <port> -m set --match-set <ipmset> src -j <blocktype>
|
<iptables> -I <chain> -p <protocol> -m multiport --dports <port> -m set --match-set <ipmset> src -j <blocktype>
|
||||||
|
|
||||||
|
# Option: actionflush
|
||||||
|
# Notes.: command executed once to flush IPS, by shutdown (resp. by stop of the jail or this action)
|
||||||
|
# Values: CMD
|
||||||
|
#
|
||||||
|
actionflush = ipset flush <ipmset>
|
||||||
|
|
||||||
# Option: actionstop
|
# Option: actionstop
|
||||||
# Notes.: command executed once at the end of Fail2Ban
|
# Notes.: command executed once at the end of Fail2Ban
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -m set --match-set <ipmset> src -j <blocktype>
|
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -m set --match-set <ipmset> src -j <blocktype>
|
||||||
ipset flush <ipmset>
|
<actionflush>
|
||||||
ipset destroy <ipmset>
|
ipset destroy <ipmset>
|
||||||
|
|
||||||
# Option: actionban
|
# Option: actionban
|
||||||
|
|
|
@ -26,13 +26,19 @@ actionstart = <iptables> -N f2b-<name>
|
||||||
<iptables> -I f2b-<name>-log -j LOG --log-prefix "$(expr f2b-<name> : '\(.\{1,23\}\)'):DROP " --log-level warning -m limit --limit 6/m --limit-burst 2
|
<iptables> -I f2b-<name>-log -j LOG --log-prefix "$(expr f2b-<name> : '\(.\{1,23\}\)'):DROP " --log-level warning -m limit --limit 6/m --limit-burst 2
|
||||||
<iptables> -A f2b-<name>-log -j <blocktype>
|
<iptables> -A f2b-<name>-log -j <blocktype>
|
||||||
|
|
||||||
|
# Option: actionflush
|
||||||
|
# Notes.: command executed once to flush IPS, by shutdown (resp. by stop of the jail or this action)
|
||||||
|
# Values: CMD
|
||||||
|
#
|
||||||
|
actionflush = <iptables> -F f2b-<name>
|
||||||
|
<iptables> -F f2b-<name>-log
|
||||||
|
|
||||||
# Option: actionstop
|
# Option: actionstop
|
||||||
# Notes.: command executed once at the end of Fail2Ban
|
# Notes.: command executed once at the end of Fail2Ban
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
|
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
|
||||||
<iptables> -F f2b-<name>
|
<actionflush>
|
||||||
<iptables> -F f2b-<name>-log
|
|
||||||
<iptables> -X f2b-<name>
|
<iptables> -X f2b-<name>
|
||||||
<iptables> -X f2b-<name>-log
|
<iptables> -X f2b-<name>-log
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ actionstart = <iptables> -N f2b-<name>
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
|
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
|
||||||
<iptables> -F f2b-<name>
|
<actionflush>
|
||||||
<iptables> -X f2b-<name>
|
<iptables> -X f2b-<name>
|
||||||
|
|
||||||
# Option: actioncheck
|
# Option: actioncheck
|
||||||
|
|
|
@ -25,7 +25,7 @@ actionstart = <iptables> -N f2b-<name>
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -m state --state NEW -p <protocol> --dport <port> -j f2b-<name>
|
actionstop = <iptables> -D <chain> -m state --state NEW -p <protocol> --dport <port> -j f2b-<name>
|
||||||
<iptables> -F f2b-<name>
|
<actionflush>
|
||||||
<iptables> -X f2b-<name>
|
<iptables> -X f2b-<name>
|
||||||
|
|
||||||
# Option: actioncheck
|
# Option: actioncheck
|
||||||
|
|
|
@ -35,6 +35,12 @@ before = iptables-common.conf
|
||||||
# shorter of the two timeouts actually matters.
|
# shorter of the two timeouts actually matters.
|
||||||
actionstart = if [ `id -u` -eq 0 ];then <iptables> -I <chain> -m recent --update --seconds 3600 --name <iptname> -j <blocktype>;fi
|
actionstart = if [ `id -u` -eq 0 ];then <iptables> -I <chain> -m recent --update --seconds 3600 --name <iptname> -j <blocktype>;fi
|
||||||
|
|
||||||
|
# Option: actionflush
|
||||||
|
#
|
||||||
|
# [TODO] Flushing is currently not implemented for xt_recent
|
||||||
|
#
|
||||||
|
actionflush =
|
||||||
|
|
||||||
# Option: actionstop
|
# Option: actionstop
|
||||||
# Notes.: command executed once at the end of Fail2Ban
|
# Notes.: command executed once at the end of Fail2Ban
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
|
|
|
@ -23,7 +23,7 @@ actionstart = <iptables> -N f2b-<name>
|
||||||
# Values: CMD
|
# Values: CMD
|
||||||
#
|
#
|
||||||
actionstop = <iptables> -D <chain> -p <protocol> --dport <port> -j f2b-<name>
|
actionstop = <iptables> -D <chain> -p <protocol> --dport <port> -j f2b-<name>
|
||||||
<iptables> -F f2b-<name>
|
<actionflush>
|
||||||
<iptables> -X f2b-<name>
|
<iptables> -X f2b-<name>
|
||||||
|
|
||||||
# Option: actioncheck
|
# Option: actioncheck
|
||||||
|
|
|
@ -1195,6 +1195,10 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
"`ip6tables -w -A f2b-j-w-iptables-mp -j RETURN`",
|
"`ip6tables -w -A f2b-j-w-iptables-mp -j RETURN`",
|
||||||
"`ip6tables -w -I INPUT -p tcp -m multiport --dports http,https -j f2b-j-w-iptables-mp`",
|
"`ip6tables -w -I INPUT -p tcp -m multiport --dports http,https -j f2b-j-w-iptables-mp`",
|
||||||
),
|
),
|
||||||
|
'flush': (
|
||||||
|
"`iptables -w -F f2b-j-w-iptables-mp`",
|
||||||
|
"`ip6tables -w -F f2b-j-w-iptables-mp`",
|
||||||
|
),
|
||||||
'stop': (
|
'stop': (
|
||||||
"`iptables -w -D INPUT -p tcp -m multiport --dports http,https -j f2b-j-w-iptables-mp`",
|
"`iptables -w -D INPUT -p tcp -m multiport --dports http,https -j f2b-j-w-iptables-mp`",
|
||||||
"`iptables -w -F f2b-j-w-iptables-mp`",
|
"`iptables -w -F f2b-j-w-iptables-mp`",
|
||||||
|
@ -1235,6 +1239,10 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
"`ip6tables -w -A f2b-j-w-iptables-ap -j RETURN`",
|
"`ip6tables -w -A f2b-j-w-iptables-ap -j RETURN`",
|
||||||
"`ip6tables -w -I INPUT -p tcp -j f2b-j-w-iptables-ap`",
|
"`ip6tables -w -I INPUT -p tcp -j f2b-j-w-iptables-ap`",
|
||||||
),
|
),
|
||||||
|
'flush': (
|
||||||
|
"`iptables -w -F f2b-j-w-iptables-ap`",
|
||||||
|
"`ip6tables -w -F f2b-j-w-iptables-ap`",
|
||||||
|
),
|
||||||
'stop': (
|
'stop': (
|
||||||
"`iptables -w -D INPUT -p tcp -j f2b-j-w-iptables-ap`",
|
"`iptables -w -D INPUT -p tcp -j f2b-j-w-iptables-ap`",
|
||||||
"`iptables -w -F f2b-j-w-iptables-ap`",
|
"`iptables -w -F f2b-j-w-iptables-ap`",
|
||||||
|
@ -1273,6 +1281,10 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
"`ipset create f2b-j-w-iptables-ipset6 hash:ip timeout 600 family inet6`",
|
"`ipset create f2b-j-w-iptables-ipset6 hash:ip timeout 600 family inet6`",
|
||||||
"`ip6tables -w -I INPUT -p tcp -m multiport --dports http -m set --match-set f2b-j-w-iptables-ipset6 src -j REJECT --reject-with icmp6-port-unreachable`",
|
"`ip6tables -w -I INPUT -p tcp -m multiport --dports http -m set --match-set f2b-j-w-iptables-ipset6 src -j REJECT --reject-with icmp6-port-unreachable`",
|
||||||
),
|
),
|
||||||
|
'flush': (
|
||||||
|
"`ipset flush f2b-j-w-iptables-ipset`",
|
||||||
|
"`ipset flush f2b-j-w-iptables-ipset6`",
|
||||||
|
),
|
||||||
'stop': (
|
'stop': (
|
||||||
"`iptables -w -D INPUT -p tcp -m multiport --dports http -m set --match-set f2b-j-w-iptables-ipset src -j REJECT --reject-with icmp-port-unreachable`",
|
"`iptables -w -D INPUT -p tcp -m multiport --dports http -m set --match-set f2b-j-w-iptables-ipset src -j REJECT --reject-with icmp-port-unreachable`",
|
||||||
"`ipset flush f2b-j-w-iptables-ipset`",
|
"`ipset flush f2b-j-w-iptables-ipset`",
|
||||||
|
@ -1307,6 +1319,10 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
"`ipset create f2b-j-w-iptables-ipset-ap6 hash:ip timeout 600 family inet6`",
|
"`ipset create f2b-j-w-iptables-ipset-ap6 hash:ip timeout 600 family inet6`",
|
||||||
"`ip6tables -w -I INPUT -m set --match-set f2b-j-w-iptables-ipset-ap6 src -j REJECT --reject-with icmp6-port-unreachable`",
|
"`ip6tables -w -I INPUT -m set --match-set f2b-j-w-iptables-ipset-ap6 src -j REJECT --reject-with icmp6-port-unreachable`",
|
||||||
),
|
),
|
||||||
|
'flush': (
|
||||||
|
"`ipset flush f2b-j-w-iptables-ipset-ap`",
|
||||||
|
"`ipset flush f2b-j-w-iptables-ipset-ap6`",
|
||||||
|
),
|
||||||
'stop': (
|
'stop': (
|
||||||
"`iptables -w -D INPUT -m set --match-set f2b-j-w-iptables-ipset-ap src -j REJECT --reject-with icmp-port-unreachable`",
|
"`iptables -w -D INPUT -m set --match-set f2b-j-w-iptables-ipset-ap src -j REJECT --reject-with icmp-port-unreachable`",
|
||||||
"`ipset flush f2b-j-w-iptables-ipset-ap`",
|
"`ipset flush f2b-j-w-iptables-ipset-ap`",
|
||||||
|
@ -1343,6 +1359,10 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
"`ip6tables -w -A f2b-j-w-iptables -j RETURN`",
|
"`ip6tables -w -A f2b-j-w-iptables -j RETURN`",
|
||||||
"`ip6tables -w -I INPUT -p tcp --dport http -j f2b-j-w-iptables`",
|
"`ip6tables -w -I INPUT -p tcp --dport http -j f2b-j-w-iptables`",
|
||||||
),
|
),
|
||||||
|
'flush': (
|
||||||
|
"`iptables -w -F f2b-j-w-iptables`",
|
||||||
|
"`ip6tables -w -F f2b-j-w-iptables`",
|
||||||
|
),
|
||||||
'stop': (
|
'stop': (
|
||||||
"`iptables -w -D INPUT -p tcp --dport http -j f2b-j-w-iptables`",
|
"`iptables -w -D INPUT -p tcp --dport http -j f2b-j-w-iptables`",
|
||||||
"`iptables -w -F f2b-j-w-iptables`",
|
"`iptables -w -F f2b-j-w-iptables`",
|
||||||
|
@ -1383,6 +1403,10 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
"`ip6tables -w -A f2b-j-w-iptables-new -j RETURN`",
|
"`ip6tables -w -A f2b-j-w-iptables-new -j RETURN`",
|
||||||
"`ip6tables -w -I INPUT -m state --state NEW -p tcp --dport http -j f2b-j-w-iptables-new`",
|
"`ip6tables -w -I INPUT -m state --state NEW -p tcp --dport http -j f2b-j-w-iptables-new`",
|
||||||
),
|
),
|
||||||
|
'flush': (
|
||||||
|
"`iptables -w -F f2b-j-w-iptables-new`",
|
||||||
|
"`ip6tables -w -F f2b-j-w-iptables-new`",
|
||||||
|
),
|
||||||
'stop': (
|
'stop': (
|
||||||
"`iptables -w -D INPUT -m state --state NEW -p tcp --dport http -j f2b-j-w-iptables-new`",
|
"`iptables -w -D INPUT -m state --state NEW -p tcp --dport http -j f2b-j-w-iptables-new`",
|
||||||
"`iptables -w -F f2b-j-w-iptables-new`",
|
"`iptables -w -F f2b-j-w-iptables-new`",
|
||||||
|
@ -1684,6 +1708,11 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
||||||
action.unban(ainfo['ip6'])
|
action.unban(ainfo['ip6'])
|
||||||
self.assertLogged(*tests['ip6-check']+tests['ip6-unban'], all=True)
|
self.assertLogged(*tests['ip6-check']+tests['ip6-unban'], all=True)
|
||||||
self.assertNotLogged(*tests['ip4'], all=True)
|
self.assertNotLogged(*tests['ip4'], all=True)
|
||||||
|
# test flush for actions should supported this:
|
||||||
|
if tests.get('flush'):
|
||||||
|
self.pruneLog('# === flush ===')
|
||||||
|
action.flush()
|
||||||
|
self.assertLogged(*tests['flush'], all=True)
|
||||||
# test stop :
|
# test stop :
|
||||||
self.pruneLog('# === stop ===')
|
self.pruneLog('# === stop ===')
|
||||||
action.stop()
|
action.stop()
|
||||||
|
|
Loading…
Reference in New Issue