Re: Fwd: iptables and networking
- To: firstname.lastname@example.org
- Subject: Re: Fwd: iptables and networking
- From: Pascal Hambourg <email@example.com>
- Date: Mon, 01 Jul 2013 13:35:27 +0200
- Message-id: <[🔎] 51D1697F.firstname.lastname@example.org>
- In-reply-to: <51D07700.email@example.com>
- References: <51C1F36D.firstname.lastname@example.org> <1371669370.5346.16.camel@pc-steven.LAN> <51C2DF42.email@example.com> <1371755872.7717.21.camel@pc-steven.LAN> <CAAKASGxwG5q2Ay5g=YByHmRJ0RJOV_vqXO_O2KixqdDJjb3cEg@mail.gmail.com> <CAMDu+mPx-AcvODdjEUM2_g2TtR=aKu0t23Dt+hqEJAf98Ade3w@mail.gmail.com> <51D02F83.firstname.lastname@example.org> <20130630155344.GH1481@uriel.asininetech.com> <51D07700.email@example.com>
One more bit on the use of the 'recent' match against DoS.
Pascal Hambourg a écrit :
> The ruleset using the 'recent' match is based only on TCP packets with
> the NEW state, i.e. the initial SYN. A single SYN packet can be easily
> forged with a spoofed source address. Fail2ban is based on
> authentication failures, which first requires a TCP connection to be
> established with the 3-way handshake. As it involves a positive reply
> from the spoofed address, this is much harder to achieve, unless the
> attacker is in a special position on the network.
The 'recent' match could be used if it was possible to detect the last
packet of the TCP 3-way handshake sent by the client, confirming the
connection is established. Unfortunately it just looks like any other
ACK packet in the stream (same TCP flags, same conntrack ctstate and
ctstatus), except that it is the first ACK (without SYN). Using
connection mark and packet mark, I guess it is possible to detect it :
By default, packet mark and connection mark are 0
If an ACK is received in the original direction and the connection mark
is 0, then set the packet mark and connection mark to 1
Translated into iptables rules :
-A INPUT -p tcp --tcp-flags SYN,ACK,RST ACK -m connmark --mark 0 \
-m ctstate --ctstate ESTABLISHED --ctdir ORIGINAL -j MARK --set-mark 1
-A INPUT -p tcp -m mark --mark 1 -j CONNMARK --set-mark 1
It seems to work, but I have not tested it extensively.
WARNING : --ctdir is inverted in kernels older than 2.6.39 (fix not
backported in any stable/longterm release at kernel.org), so you must
use REPLY instead of ORIGINAL (or negation with !) if you use such kernel.
If your ruleset already use packet marks or connection marks for other
purposes, you may need to apply masks to divide the marks into bitfields.