"-m state -state NEW" or "--tcp-flags ALL SYN" for tcp?
Hello
Is it better to use "-m state -state NEW" or to use "--tcp-flags ALL SYN" for tcp packets. There are also the lines
iptables -A INPUT/FORWARD -m state --state INVALID -j DROP iptables -A INPUT/FORWARD/OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT in the firewall script.
A tcp packet without a SYN flag can never be in state NEW (according to my tests). Instead iptables discovers this packet as garbage and flags it with INVALID.
Signature · 3 lines
Jörg Schütter http://www.lug-untermain.de/ [email protected] http://www.schuetter.org/joerg/ ICQ: 298982789 http://mypenguin.bei.t-online.de/
Quoted 5 lines · Jörg Schütter
Is it better to use "-m state -state NEW" or to use "--tcp-flags ALL SYN" for tcp packets. There are also the lines
iptables -A INPUT/FORWARD -m state --state INVALID -j DROP iptables -A INPUT/FORWARD/OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT in the firewall script.
It is better to use both at the same time. Note you have --syn alias that a bit less restrictive than ALL SYN as it implies SYN,RST,ACK SYN, but is OK according to RFC.
NEW state for conntrack does not mean SYN packet for TCP. It means that received TCP packet cannot be associated to an existing conntrack entry. Therefore, if you get ACK scanned, thoses packets will be flagged as NEW ones by conntrack. I agree the fact that for TCP, a NEW has to be a SYN one. That's why you want to enforce both NEW and SYN. I'm used to write rules like this (let's say for FORWARD chain) :
iptables -A FORWARD -m state --state INVALID -j DROP iptables -A FORWARD -m state --state ESTABLISHED,RELATED \ -j ACCEPT iptables -A FORWARD -m state --state NEW -p tcp -d $FTP_SERVER \ --dport 21 --syn -j ACCEPT
Quoted 3 lines
A tcp packet without a SYN flag can never be in state NEW (according to my tests). Instead iptables discovers this packet as garbage and flags it with INVALID.
I do think you should perform some additional tests, because an ACK packet can get flaged as NEW. In fact, in regard to TCP flags, an INVALID state means that flags set used is not allowed by RFC. This means, as an example that SYN-FIN is OK, but an Xmas or a Null set will get INVALID.
If you're really paranoid, you can also enforce that TCP packets flagged as ESTABLISHED should not be SYN ones :
iptables -A FORWARD -m state --state ESTABLISHED -p tcp \ ! --syn -j ACCEPT
And that RELATED one should be SYN ones :
iptables -A FORWARD -m state --state RELATED -p tcp --syn \ -j ACCEPT
And eventually drop SYN packets that would be flagged as ESTABLISHED and RELATED, NEW that would not be SYN ones :
iptables -I FORWARD 2 -m state --state ESTABLISHED -p tcp \ --syn -j DROP iptables -I FORWARD 3 -m state --state NEW,RELATED -p tcp \ ! --syn -j DROP
Signature · 2 lines
http://www.netexit.com/~sid/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE
Quoted 2 lines
Quoted 2 lines
Hi! I'm your friendly neighbourhood signature virus. Copy me to your signature file and help me spread!
Quoted 5 lines
If you're really paranoid, you can also enforce that TCP packets flagged as ESTABLISHED should not be SYN ones :
iptables -A FORWARD -m state --state ESTABLISHED -p tcp \ ! --syn -j ACCEPT
And If you're really really PARANOID try this for new TCP :-)
iptables -A FORWARD -p tcp -m state --state NEW --syn -m length \ --length 40:68 -j ACCEPT
New SYN packets are 40 to 68 bytes (depending on IP options) - without payload.
Regards,
Maciej
Quoted 8 lines · Maciej Soltysiak
Quoted 5 lines
If you're really paranoid, you can also enforce that TCP packets flagged as ESTABLISHED should not be SYN ones :
iptables -A FORWARD -m state --state ESTABLISHED -p tcp \ ! --syn -j ACCEPTAnd If you're really really PARANOID try this for new TCP :-)
iptables -A FORWARD -p tcp -m state --state NEW --syn -m length \ --length 40:68 -j ACCEPT
I know that this assumption works for almost 100% of cases as the SYN packet almost never carries payload (currently) but there is nothing in the RFC prohibiting that, or is there? Just trying to comply with the standards.
rfc793
-----
...
Several examples of connection initiation follow. Although these examples do not show connection synchronization using data-carrying segments, this is perfectly legitimate, so long as the receiving TCP doesn't deliver the data to the user until it is clear the data is valid (i.e., the data must be buffered at the receiver until the connection reaches the ESTABLISHED state). The three-way handshake reduces the possibility of false connections.
...
-----
Ramin
Quoted 6 lines
New SYN packets are 40 to 68 bytes (depending on IP options) - without payload.
Regards,
Maciej