.\" Automatically generated by Pandoc 3.1.3 .nh .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. .ie "\f[CB]x\f[]"x" \{\ . ftr V B . ftr VI BI . ftr VB B . ftr VBI BI .\} .el \{\ . ftr V CR . ftr VI CI . ftr VB CB . ftr VBI CBI .\} .TH "firehol-action" "5" "Built 30 Mar 2024" "FireHOL Reference" "3.1.7" .hy .SH NAME .PP firehol-action - set up custom filtering actions .SH SYNOPSIS .PP action \f[I]name\f[R] [table \f[I]table_name\f[R]] \f[I]type\f[R] \f[I]type_params\f[R] [ next [ \f[I]type\f[R] \f[I]type_params\f[R] [ next \&... ] ] ] .SH DESCRIPTION .PP The \f[V]action\f[R] helper creates custom actions that can be used everywhere in FireHOL, like this: .IP .nf \f[C] action ACT1 chain accept interface any world server smtp ACT1 router myrouter policy ACT1 \f[R] .fi .PP The \f[V]action\f[R] helper allows linking multiple actions together and having some logic to select which action to execute, like this: .IP .nf \f[C] action ACT1 \[rs] rule src 192.168.0.0/16 action reject \[rs] next rule dst 192.168.0.0/16 action reject \[rs] next rule inface eth2 action drop \[rs] next rule outface eth2 action drop \[rs] next action accept interface any world server smtp ACT1 router myrouter policy ACT1 \f[R] .fi .PP There is no limit on the number of actions that can be linked together. .PP \f[V]type\f[R] can be \f[V]chain\f[R] or \f[V]action\f[R] (\f[V]chain\f[R] and \f[V]action\f[R] are aliases), \f[V]rule\f[R], \f[V]iptrap\f[R], \f[V]ipuntrap\f[R] or \f[V]sockets_suspects_trap\f[R]. .SS Chain type actions .PP This is the simpler action. It creates an iptables(8) chain which can be used to control the action of other firewall rules once the firewall is running. .PP For example, you can setup the custom action ACT1, which by default is ACCEPT, but can be dynamically changed to DROP, REJECT or RETURN (and back) without restarting the firewall. .PP The \f[I]name\f[R] can be any chain name accepted by iptables. You should try to keep it within 5 and 10 characters. .RS .PP \f[B]Note\f[R] .PP The \f[I]name\f[R]s created with this command are case-sensitive. .RE .PP The \f[I]action\f[R] can be any of those supported by FireHOL (see firehol-actions(5)). Only ACCEPT, REJECT, DROP, RETURN have any meaning in this instance. .PP Once the firewall is running you can dynamically modify the behaviour of the chain from the Linux command-line, as detailed below: .IP .nf \f[C] action ACT1 chain accept interface any world server smtp ACT1 client smtp ACT1 \f[R] .fi .PP To insert a DROP action at the start of the chain to override the default action (ACCEPT): .IP .nf \f[C] iptables -t filter -I ACT1 -j DROP \f[R] .fi .PP To delete the DROP action from the start of the chain to return to the default action: .IP .nf \f[C] iptables -t filter -D ACT1 -j DROP \f[R] .fi .RS .PP \f[B]Note\f[R] .PP If you delete all of the rules in the chain, the default will be to RETURN, in which case the behaviour will be as if any rules with the action were not present in the configuration file. .RE .SS Rule type actions .PP \f[V]rule\f[R] type actions define a few conditions that will lead to an action. .PP All optional rule parameters FireHOL supports can be used here (see firehol-params(5)). .IP .nf \f[C] action ACT1 \[rs] rule inface eth0 action accept next rule outface eth0 action accept next action reject interface any world server smtp ACT1 \f[R] .fi .PP In the above example the smtp server can only be accessed from eth0. .PP It is important to remember that actions will be applied for all the traffic, both requests and replies. The type of traffic can be filtered with the \f[V]state\f[R] optional rule parameter, like this: .IP .nf \f[C] action ACT1 \[rs] rule inface eth0 state NEW action reject next action accept interface any world server smtp ACT1 client smtp ACT1 \f[R] .fi .PP In the above example, the smtp server will not accept NEW connections from eth0, but the smtp client will be able to connect to servers on eth0 (and everywhere else). .SS iptrap type actions .PP \f[V]iptrap\f[R] (see [firehol-iptrap(5)][]) is a helper than copies (traps) an IP to an ipset (see [firehol-ipset(5)][]). It does not perform any action on the traffic. .PP Using the \f[V]iptrap\f[R] action, the \f[V]iptrap\f[R] helper can be linked to filtering actions, like this: .IP .nf \f[C] # a simple version of TRAP_AND_REJECT # this uses just 2 ipsets, one for counting packets (policytrap) # and one to store the banned IPs (trap). # it also needs a ipset called whitelist, for excluded source IPs. # it will ban IPs when they have 50+ reject packets action4 TRAP_AND_REJECT \[rs] rule iptrap src policytrap 30 inface \[dq]${wan}\[dq] \[rs] src not \[dq]${UNROUTABLE_IPS} ipset:whitelist\[dq] \[rs] state NEW log \[dq]POLICY TRAP\[dq] \[rs] next iptrap trap src 86400 \[rs] state NEW log \[dq]POLICY TRAP - BANNED\[dq] \[rs] ipset policytrap src no-counters packets-above 50 \[rs] next action reject # a complete TRAP_AND_REJECT # this uses 3 ipset, one for keeping track of the rejected sockets # per source IP (called \[aq]sockets\[aq]), one for counting the sockets # per source IP (called \[aq]suspects\[aq]) and one to store the banned IPs # (called \[aq]trap\[aq]). # it also needs a ipset called whitelist, for excluded source IPs. # it will ban IPs when they have 3 or more rejected sockets action4 TRAP_AND_REJECT \[rs] iptrap sockets src,dst,dst 3600 method hash:ip,port,ip counters \[rs] state NEW log \[dq]TRAP AND REJECT - NEW SOCKET\[dq] \[rs] inface \[dq]${wan}\[dq] \[rs] src not \[dq]${UNROUTABLE_IPS} ipset:whitelist\[dq] \[rs] next iptrap suspects src 3600 counters \[rs] state NEW log \[dq]TRAP AND REJECT - NEW SUSPECT\[dq] \[rs] ipset sockets src,dst,dst no-counters packets 1 \[rs] next iptrap trap src 86400 \[rs] state NEW log \[dq]TRAP AND REJECT - BANNED\[dq] \[rs] ipset suspects src no-counters packets-above 2 \[rs] next action REJECT interface any world policy TRAP_AND_REJECT protection bad-packets ... router wan2lan inface \[dq]${wan}\[dq] outface \[dq]${lan}\[dq] policy TRAP_AND_REJECT protection bad-packets ... \f[R] .fi .PP Since we used the action TRAP_AND_REJECT as an interface policy, it will get all the traffic not accepted, rejected, or dropped by the server and client statements. .PP For all these packets, the action TRAP_AND_REJECT will first check that they are coming in from wan0, that their src IP is not in \f[V]UNROUTABLE_IPS\f[R] list and in the \f[V]whitelist\f[R] ipset, that they are NEW connections, and if all these conditions are met, it will log with the tag \f[V]POLICY TRAP\f[R] and add the src IP of the packets in the \f[V]policytrap\f[R] ipset for 30 seconds. .PP All traffic not matched by the above, will be just rejected. .SS sockets_suspects_trap type actions .PP The type \f[V]sockets_suspects_trap\f[R] will automatically a custom trap using the following template: .IP .nf \f[C] action4 *name* sockets_suspects_trap *SUSPECTS_TIMEOUT* *TRAP_TIMEOUT* *VALID_CONNECTIONS* [*optional params*] next ... \f[R] .fi .PP This will: .IP "1." 3 Create the ipset \f[V]${name}_sockets\f[R] where the matched sockets will be stored for \f[V]SUSPECTS_TIMEOUT\f[R] seconds. .IP "2." 3 Create the ipset \f[V]${name}_suspects\f[R] where the source IPs of the matched sockets will be stored for \f[V]SUSPECTS_TIMEOUT\f[R] seconds. .IP "3." 3 Create the ipset \f[V]${name}_trap\f[R] where the trapped IPs will be stored for \f[V]TRAP_TIMEOUT\f[R] seconds. IPs will be added to this ipset only if more than \f[V]VALID_CONNECTIONS\f[R] have been matched by this IP. .PP \f[V]optional params\f[R] are FireHOL optional rule parameters (firehol-params(5)) that can be used to limit the match for the first ipset (sockets). .PP So, to design the same TRAP_AND_REJECT as above, this statement is needed: .IP .nf \f[C] action4 TRAP_AND_REJECT \[rs] sockets_suspects_trap 3600 86400 2 \[rs] inface \[dq]${wan}\[dq] \[rs] src not \[dq]${UNROUTABLE_IPS} ipset:whitelist\[dq] \[rs] next action REJECT \f[R] .fi .PP The ipsets that will be created will be named: \f[V]TRAP_AND_REJECT_sockets\f[R], \f[V]TRAP_AND_REJECT_suspects\f[R] and \f[V]TRAP_AND_REJECT_trap\f[R]. .RS .PP \f[B]Note\f[R] Always terminate \f[V]sockets_suspects_trap\f[R] with a \f[V]next action DROP\f[R] or \f[V]next action REJECT\f[R], or the traffic will continue to flow. .RE .SH SEE ALSO .IP \[bu] 2 firehol(1) - FireHOL program .IP \[bu] 2 firehol.conf(5) - FireHOL configuration .IP \[bu] 2 firehol-actions(5) - optional rule parameters .IP \[bu] 2 iptables(8) (http://ipset.netfilter.org/iptables.man.html) - administration tool for IPv4 firewalls .IP \[bu] 2 ip6tables(8) (http://ipset.netfilter.org/ip6tables.man.html) - administration tool for IPv6 firewalls .IP \[bu] 2 FireHOL Website (http://firehol.org/) .IP \[bu] 2 FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf) .IP \[bu] 2 FireHOL Online Documentation (http://firehol.org/documentation/) .SH AUTHORS FireHOL Team.