diff --git a/ChangeLog b/ChangeLog index bf9df1b5..9c305340 100644 --- a/ChangeLog +++ b/ChangeLog @@ -92,6 +92,14 @@ ver. 0.9.4 (2016/03/08) - for-you-ladies * sshd filter got new failregex to match "maximum authentication attempts exceeded" (introduced in openssh 6.8) * Added filter for Mac OS screen sharing (VNC) daemon + * IPv6 support: + - IP addresses are now handled as objects rather than strings capable for + handling both address types IPv4 and IPv6 + - iptables related actions have been amended to support IPv6 specific actions + additionally + - hostsdeny and route actions have been tested to be aware of v4 and v6 already + - pf action for *BSD systems has been improved and supports now also v4 and v6 + - Name resolution is now working for either address type - Enhancements: * Do not rotate empty log files diff --git a/MANIFEST b/MANIFEST index 4ebf3fad..11f635c3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -164,6 +164,7 @@ fail2ban/client/jailreader.py fail2ban/client/jailsreader.py fail2ban/exceptions.py fail2ban/helpers.py +fail2ban/ipdns.py fail2ban/__init__.py fail2ban/protocol.py fail2ban/server/action.py @@ -200,6 +201,7 @@ fail2ban/tests/actionstestcase.py fail2ban/tests/actiontestcase.py fail2ban/tests/banmanagertestcase.py fail2ban/tests/clientreadertestcase.py +fail2ban/tests/clientbeautifiertestcase.py fail2ban/tests/config/action.d/brokenaction.conf fail2ban/tests/config/fail2ban.conf fail2ban/tests/config/filter.d/simple.conf diff --git a/THANKS b/THANKS index 64de43a4..c8a019a6 100644 --- a/THANKS +++ b/THANKS @@ -12,6 +12,7 @@ Adrien Clerc ache ag4ve (Shawn) Alasdair D. Campbell +Alexander Koeppe (IPv6 support) Alexandre Perrin (kAworu) Amir Caspi Amy diff --git a/config/action.d/iptables-common.conf b/config/action.d/iptables-common.conf index 45819e3d..a3921021 100644 --- a/config/action.d/iptables-common.conf +++ b/config/action.d/iptables-common.conf @@ -6,6 +6,9 @@ # used in all iptables based actions by default. # # The user can override the defaults in iptables-common.local +# +# Modified: Alexander Koeppe , Serg G. Brester +# made config file IPv6 capable (see new section Init?family=inet6) [INCLUDES] @@ -13,6 +16,7 @@ after = iptables-blocktype.local iptables-common.local # iptables-blocktype.local is obsolete + [Init] # Option: chain @@ -62,3 +66,19 @@ lockingopt = -w # Notes.: Actual command to be executed, including common to all calls options # Values: STRING iptables = iptables + + +[Init?family=inet6] + +# Option: blocktype (ipv6) +# Note: This is what the action does with rules. This can be any jump target +# as per the iptables man page (section 8). Common values are DROP +# REJECT, REJECT --reject-with icmp6-port-unreachable +# Values: STRING +blocktype = REJECT --reject-with icmp6-port-unreachable + +# Option: iptables (ipv6) +# Notes.: Actual command to be executed, including common to all calls options +# Values: STRING +iptables = ip6tables + diff --git a/config/action.d/iptables-ipset-proto6-allports.conf b/config/action.d/iptables-ipset-proto6-allports.conf index 1f1d336f..113f599e 100644 --- a/config/action.d/iptables-ipset-proto6-allports.conf +++ b/config/action.d/iptables-ipset-proto6-allports.conf @@ -12,6 +12,9 @@ # # If you are running on an older kernel you make need to patch in external # modules which probably won't be protocol version 6. +# +# Modified: Alexander Koeppe , Serg G. Brester +# made config file IPv6 capable (see new section Init?family=inet6) [INCLUDES] @@ -23,16 +26,16 @@ before = iptables-common.conf # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # -actionstart = ipset create f2b- hash:ip timeout - -I -m set --match-set f2b- src -j +actionstart = ipset create hash:ip timeout + -I -m set --match-set src -j # Option: actionstop # Notes.: command executed once at the end of Fail2Ban # Values: CMD # -actionstop = -D -m set --match-set f2b- src -j - ipset flush f2b- - ipset destroy f2b- +actionstop = -D -m set --match-set src -j + ipset flush + ipset destroy # Option: actionban # Notes.: command executed when banning an IP. Take care that the @@ -40,7 +43,7 @@ actionstop = -D -m set --match-set f2b- src -j timeout -exist +actionban = ipset add timeout -exist # Option: actionunban # Notes.: command executed when unbanning an IP. Take care that the @@ -48,7 +51,7 @@ actionban = ipset add f2b- timeout -exist # Tags: See jail.conf(5) man page # Values: CMD # -actionunban = ipset del f2b- -exist +actionunban = ipset del -exist [Init] @@ -57,3 +60,12 @@ actionunban = ipset del f2b- -exist # Values: [ NUM ] Default: 600 # bantime = 600 + +ipmset = f2b- +familyopt = + + +[Init?family=inet6] + +ipmset = f2b-6 +familyopt = family inet6 diff --git a/config/action.d/iptables-ipset-proto6.conf b/config/action.d/iptables-ipset-proto6.conf index 3b51ef58..dee7b029 100644 --- a/config/action.d/iptables-ipset-proto6.conf +++ b/config/action.d/iptables-ipset-proto6.conf @@ -12,6 +12,9 @@ # # If you are running on an older kernel you make need to patch in external # modules. +# +# Modified: Alexander Koeppe , Serg G. Brester +# made config file IPv6 capable (see new section Init?family=inet6) [INCLUDES] @@ -23,16 +26,16 @@ before = iptables-common.conf # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # -actionstart = ipset create f2b- hash:ip timeout - -I -p -m multiport --dports -m set --match-set f2b- src -j +actionstart = ipset create hash:ip timeout + -I -p -m multiport --dports -m set --match-set src -j # Option: actionstop # Notes.: command executed once at the end of Fail2Ban # Values: CMD # -actionstop = -D -p -m multiport --dports -m set --match-set f2b- src -j - ipset flush f2b- - ipset destroy f2b- +actionstop = -D -p -m multiport --dports -m set --match-set src -j + ipset flush + ipset destroy # Option: actionban # Notes.: command executed when banning an IP. Take care that the @@ -40,7 +43,7 @@ actionstop = -D -p -m multiport --dports -m # Tags: See jail.conf(5) man page # Values: CMD # -actionban = ipset add f2b- timeout -exist +actionban = ipset add timeout -exist # Option: actionunban # Notes.: command executed when unbanning an IP. Take care that the @@ -48,7 +51,7 @@ actionban = ipset add f2b- timeout -exist # Tags: See jail.conf(5) man page # Values: CMD # -actionunban = ipset del f2b- -exist +actionunban = ipset del -exist [Init] @@ -57,3 +60,12 @@ actionunban = ipset del f2b- -exist # Values: [ NUM ] Default: 600 # bantime = 600 + +ipmset = f2b- +familyopt = + + +[Init?family=inet6] + +ipmset = f2b-6 +familyopt = family inet6 diff --git a/config/action.d/iptables-xt_recent-echo.conf b/config/action.d/iptables-xt_recent-echo.conf index d3d43f86..018d2cf6 100644 --- a/config/action.d/iptables-xt_recent-echo.conf +++ b/config/action.d/iptables-xt_recent-echo.conf @@ -2,7 +2,8 @@ # # Author: Zbigniew Jędrzejewski-Szmek # -# +# Modified: Alexander Koeppe , Serg G. Brester +# made config file IPv6 capable [INCLUDES] @@ -22,30 +23,30 @@ before = iptables-common.conf # iptables-persistent package). # # Explanation of the rule below: -# Check if any packets coming from an IP on the f2b- +# Check if any packets coming from an IP on the # list have been seen in the last 3600 seconds. If yes, update the # timestamp for this IP and drop the packet. If not, let the packet # through. # -# Fail2ban inserts blacklisted hosts into the f2b- list +# Fail2ban inserts blacklisted hosts into the list # and removes them from the list after some time, according to its # own rules. The 3600 second timeout is independent and acts as a # safeguard in case the fail2ban process dies unexpectedly. The # shorter of the two timeouts actually matters. -actionstart = if [ `id -u` -eq 0 ];then -I -m recent --update --seconds 3600 --name f2b- -j ;fi +actionstart = if [ `id -u` -eq 0 ];then -I -m recent --update --seconds 3600 --name -j ;fi # Option: actionstop # Notes.: command executed once at the end of Fail2Ban # Values: CMD # -actionstop = echo / > /proc/net/xt_recent/f2b- - if [ `id -u` -eq 0 ];then -D -m recent --update --seconds 3600 --name f2b- -j ;fi +actionstop = echo / > /proc/net/xt_recent/ + if [ `id -u` -eq 0 ];then -D -m recent --update --seconds 3600 --name -j ;fi # Option: actioncheck # Notes.: command executed once before each actionban command # Values: CMD # -actioncheck = test -e /proc/net/xt_recent/f2b- +actioncheck = test -e /proc/net/xt_recent/ # Option: actionban # Notes.: command executed when banning an IP. Take care that the @@ -53,7 +54,7 @@ actioncheck = test -e /proc/net/xt_recent/f2b- # Tags: See jail.conf(5) man page # Values: CMD # -actionban = echo + > /proc/net/xt_recent/f2b- +actionban = echo + > /proc/net/xt_recent/ # Option: actionunban # Notes.: command executed when unbanning an IP. Take care that the @@ -61,7 +62,12 @@ actionban = echo + > /proc/net/xt_recent/f2b- # Tags: See jail.conf(5) man page # Values: CMD # -actionunban = echo - > /proc/net/xt_recent/f2b- +actionunban = echo - > /proc/net/xt_recent/ [Init] +iptname = f2b- + +[Init?family=inet6] + +iptname = f2b-6 diff --git a/config/action.d/pf.conf b/config/action.d/pf.conf index edcaa175..effd080c 100644 --- a/config/action.d/pf.conf +++ b/config/action.d/pf.conf @@ -3,6 +3,7 @@ # OpenBSD pf ban/unban # # Author: Nick Hilliard +# Modified by: Alexander Koeppe making PF work seamless and with IPv4 and IPv6 # # @@ -12,23 +13,27 @@ # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # -# we don't enable PF automatically, as it will be enabled elsewhere -actionstart = +# we don't enable PF automatically; to enable run pfctl -e +# or add `pf_enable="YES"` to /etc/rc.conf (tested on FreeBSD) +actionstart = echo "table <-> persist counters" | pfctl -f- + echo "block proto from <-> to any port " | pfctl -f- # Option: actionstop # Notes.: command executed once at the end of Fail2Ban # Values: CMD # -# we don't disable PF automatically either -actionstop = +# we only disable PF rules we've installed prior +actionstop = pfctl -sr 2>/dev/null | grep -v - | pfctl -f- + pfctl -t - -T flush + pfctl -t - -T kill # Option: actioncheck # Notes.: command executed once before each actionban command # Values: CMD # -actioncheck = +actioncheck = pfctl -sr | grep -q - # Option: actionban @@ -39,7 +44,7 @@ actioncheck = #