Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two new firewalld actions #1367

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4e8974c
Update firewallcmd-allports.conf
TorontoMedia Mar 17, 2016
c9efc1a
Update firewallcmd-multiport.conf
TorontoMedia Mar 17, 2016
1fd29f6
Create firewallcmd-rich-logging.conf
TorontoMedia Mar 17, 2016
f6e3482
Create firewallcmd-rich-rules.conf
TorontoMedia Mar 17, 2016
d8e5626
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 17, 2016
100821e
Update ChangeLog
TorontoMedia Mar 17, 2016
30cb656
Update ChangeLog
TorontoMedia Mar 17, 2016
a211f23
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 17, 2016
bdbb50c
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 17, 2016
cf0f002
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 17, 2016
d62fe2b
Update firewallcmd-allports.conf
TorontoMedia Mar 21, 2016
dd5e643
Update firewallcmd-multiport.conf
TorontoMedia Mar 21, 2016
46d7d3a
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 21, 2016
7ef4449
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 21, 2016
a88dd88
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 21, 2016
6b3912f
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 21, 2016
2861c8e
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 22, 2016
a72895d
Update firewallcmd-allports.conf
TorontoMedia Mar 22, 2016
77262af
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 22, 2016
8f43560
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 22, 2016
107da73
Update firewallcmd-multiport.conf
TorontoMedia Mar 22, 2016
d088d0e
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 22, 2016
c82a91b
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 22, 2016
9bbdba0
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 22, 2016
307352e
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 22, 2016
4689da5
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 24, 2016
7ff3f08
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 24, 2016
4f8aa45
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 24, 2016
9444010
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 24, 2016
ed20d28
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 24, 2016
bb6283e
Update firewallcmd-rich-rules.conf
TorontoMedia Mar 24, 2016
221fef2
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 24, 2016
8e24915
Update firewallcmd-rich-logging.conf
TorontoMedia Mar 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
Fail2Ban: Changelog
===================

ver. 0.9.5 (2015/XX/XXX) - wanna-be-released
ver. 0.9.5 (2016/XX/XXX) - wanna-be-released
-----------

- Fixes:

- New Features:

* New Actions:
- action.d/firewallcmd-rich-rules and action.d/firewallcmd-rich-logging
- Enhancements:
* journald journalmatch for pure-ftpd (gh-1362)

Expand Down
9 changes: 1 addition & 8 deletions config/action.d/firewallcmd-allports.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Fail2Ban configuration file
#
# Author: Donald Yandt
# Because of the --remove-rules in stop this action requires firewalld-0.3.8+


[INCLUDES]

before = iptables-blocktype.conf
before = iptables-common.conf

[Definition]

Expand All @@ -18,7 +15,6 @@ actionstop = firewall-cmd --direct --remove-rule ipv4 filter <chain> 0 -j f2b-<n
firewall-cmd --direct --remove-rules ipv4 filter f2b-<name>
firewall-cmd --direct --remove-chain ipv4 filter f2b-<name>


# Example actioncheck: firewall-cmd --direct --get-chains ipv4 filter | sed -e 's, ,\n,g' | grep -q '^f2b-recidive$'

actioncheck = firewall-cmd --direct --get-chains ipv4 filter | sed -e 's, ,\n,g' | grep -q '^f2b-<name>$'
Expand All @@ -30,7 +26,6 @@ actionunban = firewall-cmd --direct --remove-rule ipv4 filter f2b-<name> 0 -s <i
[Init]

# Default name of the chain
#
name = default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a default name for the fail2ban chain ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix that. I don't know why I got the input chain mixed up with the f2b chains.


chain = INPUT_direct
Expand All @@ -40,7 +35,6 @@ chain = INPUT_direct
# Author: Donald Yandt
# Uses "FirewallD" instead of the "iptables daemon".
#
#
# Output:

# actionstart:
Expand All @@ -50,4 +44,3 @@ chain = INPUT_direct
# success
# $ sudo firewall-cmd --direct --add-rule ipv4 filter INPUT_direct 0 -j f2b-recidive
# success

12 changes: 4 additions & 8 deletions config/action.d/firewallcmd-multiport.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
# Author: Donald Yandt
# Because of the --remove-rules in stop this action requires firewalld-0.3.8+


[INCLUDES]

before = iptables-blocktype.conf
before = iptables-common.conf

[Definition]

actionstart = firewall-cmd --direct --add-chain ipv4 filter f2b-<name>
firewall-cmd --direct --add-rule ipv4 filter f2b-<name> 1000 -j RETURN
firewall-cmd --direct --add-rule ipv4 filter <chain> 0 -m state --state NEW -p <protocol> -m multiport --dports <port> -j f2b-<name>
firewall-cmd --direct --add-rule ipv4 filter <chain> 0 -m conntrack --ctstate NEW -p <protocol> -m multiport --dports <port> -j f2b-<name>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this new form be compatible with older versions of the firewall-cmd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but this is what I've gathered on nf_conntrack support:

  • in modules.py function get_firewall_modules() it just reads from "/proc/modules" and loads dependencies if they exist so no compatibility checks.
  • further research into all the talk about firewalld getting conntrack support suggests that they are talking about nf_conntrack userspace tools and not the kernel conntrack module.
  • all the services have nf_conntrack module names. Example <module name="nf_conntrack_amanda"/>

with that stated and module "state" being depreciated I suggest we move to nf_conntrack.


actionstop = firewall-cmd --direct --remove-rule ipv4 filter <chain> 0 -m state --state NEW -p <protocol> -m multiport --dports <port> -j f2b-<name>
actionstop = firewall-cmd --direct --remove-rule ipv4 filter <chain> 0 -m conntrack --ctstate NEW -p <protocol> -m multiport --dports <port> -j f2b-<name>
firewall-cmd --direct --remove-rules ipv4 filter f2b-<name>
firewall-cmd --direct --remove-chain ipv4 filter f2b-<name>

Expand All @@ -35,20 +36,16 @@ chain = INPUT_direct
# Could also use port numbers separated by a comma.
port = 1:65535


# Option: protocol
# Values: [ tcp | udp | icmp | all ]

protocol = tcp



# DEV NOTES:
#
# Author: Donald Yandt
# Uses "FirewallD" instead of the "iptables daemon".
#
#
# Output:
# actionstart:
# $ firewall-cmd --direct --add-chain ipv4 filter f2b-apache-modsecurity
Expand All @@ -60,4 +57,3 @@ protocol = tcp
# actioncheck:
# $ firewall-cmd --direct --get-chains ipv4 filter f2b-apache-modsecurity | sed -e 's, ,\n,g' | grep -q '^f2b-apache-modsecurity$'
# f2b-apache-modsecurity

65 changes: 65 additions & 0 deletions config/action.d/firewallcmd-rich-logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Fail2Ban configuration file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding short description what is so special about this rich one

#
# Author: Donald Yandt
#
# Because of the rich rule commands requires firewalld-0.3.1+
# This action uses firewalld rich-rules which gives you a cleaner iptables since it stores rules according to zones and not
# by chain. So for an example all deny rules will be listed under <zone>_deny and all log rules under <zone>_log.
#
# Also this action logs banned access attempts so you can filter that and increase ban time for offenders.
#
# If you use the --permanent rule you get a xml file in /etc/firewalld/zones/<zone>.xml that can be shared and parsed easliy
#
# Example commands to view rules:
# firewall-cmd [--zone=<zone>] --list-rich-rules
# firewall-cmd [--zone=<zone>] --list-all
# firewall-cmd [--zone=zone] --query-rich-rule='rule'

[Definition]

actionstart =

actionstop =

actioncheck =

# you can also use zones and/or service names.
#
# zone example:
# firewall-cmd --zone=<zone> --add-rich-rule="rule family='ipv4' source address='<ip>' port port='<port>' protocol='<protocol>' log prefix='f2b-<name>' level='<level>' limit value='<rate>/m' <blocktype>"
# service name example:
# firewall-cmd --zone=<zone> --add-rich-rule="rule family='ipv4' source address='<ip>' service name='<service>' log prefix='f2b-<name>' level='<level>' limit value='<rate>/m' <blocktype>"
# Because rich rules can only handle single or a range of ports we must split ports and execute the command for each port. Ports can be single and ranges seperated by a comma or space for an example: http, https, 22-60, 18 smtp

actionban = ports="<port>"; for p in $(echo $ports | tr ", " " "); do firewall-cmd --add-rich-rule="rule family='ipv4' source address='<ip>' port port='$p' protocol='<protocol>' log prefix='f2b-<name>' level='<level>' limit value='<rate>/m' <blocktype>"; done

actionunban = ports="<port>"; for p in $(echo $ports | tr ", " " "); do firewall-cmd --remove-rich-rule="rule family='ipv4' source address='<ip>' port port='$p' protocol='<protocol>' log prefix='f2b-<name>' level='<level>' limit value='<rate>/m' <blocktype>"; done

[Init]

name = default

# log levels are "emerg", "alert", "crit", "error", "warning", "notice", "info" or "debug"
level = info

# log rate per minute
rate = 1

zone = public

# use command firewall-cmd --get-services to see a list of services available
#
# Examples:
#
# amanda-client amanda-k5-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns freeipa-ldap freeipa-ldaps
# freeipa-replication ftp high-availability http https imaps ipp ipp-client ipsec iscsi-target kadmin kerberos
# kpasswd ldap ldaps libvirt libvirt-tls mdns mosh mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s
# postgresql privoxy proxy-dhcp puppetmaster radius rpc-bind rsyncd samba samba-client sane smtp squid ssh synergy
# telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server

service = ssh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is service entry a mere label or it points to the ports?


# reject types: 'icmp-net-unreachable', 'icmp-host-unreachable', 'icmp-port-unreachable', 'icmp-proto-unreachable',
# 'icmp-net-prohibited', 'icmp-host-prohibited', 'icmp-admin-prohibited' or 'tcp-reset'

blocktype = reject type='icmp-port-unreachable'
57 changes: 57 additions & 0 deletions config/action.d/firewallcmd-rich-rules.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Fail2Ban configuration file
#
# Author: Donald Yandt
#
# Because of the rich rule commands requires firewalld-0.3.1+
# This action uses firewalld rich-rules which gives you a cleaner iptables since it stores rules according to zones and not
# by chain. So for an example all deny rules will be listed under <zone>_deny.
#
# If you use the --permanent rule you get a xml file in /etc/firewalld/zones/<zone>.xml that can be shared and parsed easliy
#
# Example commands to view rules:
# firewall-cmd [--zone=<zone>] --list-rich-rules
# firewall-cmd [--zone=<zone>] --list-all
# firewall-cmd [--zone=zone] --query-rich-rule='rule'

[Definition]

actionstart =

actionstop =

actioncheck =

#you can also use zones and/or service names.
#
# zone example:
# firewall-cmd --zone=<zone> --add-rich-rule="rule family='ipv4' source address='<ip>' port port='<port>' protocol='<protocol>' <blocktype>"
# service name example:
# firewall-cmd --zone=<zone> --add-rich-rule="rule family='ipv4' source address='<ip>' service name='<service>' <blocktype>"
# Because rich rules can only handle single or a range of ports we must split ports and execute the command for each port. Ports can be single and ranges seperated by a comma or space for an example: http, https, 22-60, 18 smtp

actionban = ports="<port>"; for p in $(echo $ports | tr ", " " "); do firewall-cmd --add-rich-rule="rule family='ipv4' source address='<ip>' port port='$p' protocol='<protocol>' <blocktype>"; done

actionunban = ports="<port>"; for p in $(echo $ports | tr ", " " "); do firewall-cmd --remove-rich-rule="rule family='ipv4' source address='<ip>' port port='$p' protocol='<protocol>' <blocktype>"; done

[Init]

name = default

zone = public

# use command firewall-cmd --get-services to see a list of services available
#
# Examples:
#
# amanda-client amanda-k5-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns freeipa-ldap freeipa-ldaps
# freeipa-replication ftp high-availability http https imaps ipp ipp-client ipsec iscsi-target kadmin kerberos
# kpasswd ldap ldaps libvirt libvirt-tls mdns mosh mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s
# postgresql privoxy proxy-dhcp puppetmaster radius rpc-bind rsyncd samba samba-client sane smtp squid ssh synergy
# telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server

service = ssh

# reject types: 'icmp-net-unreachable', 'icmp-host-unreachable', 'icmp-port-unreachable', 'icmp-proto-unreachable',
# 'icmp-net-prohibited', 'icmp-host-prohibited', 'icmp-admin-prohibited' or 'tcp-reset'

blocktype = reject type='icmp-port-unreachable'