LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2005, 05:46 PM   #1
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Rep: Reputation: 16
Firewall question - stumped by 1 rule!


I was following a tutorial on setting up a Linux Firewall (iptables) and it worked flawlessly. However, I'm trying to understand what the following rule does:

Code:
-A bad_tcp_packets -p tcp -m tcp --tcp-flags SYN,ACK SYN,ACK \
-m state --state NEW -j REJECT --reject-with tcp-reset
Could someone please explain what the -m state --state NEW means in the above rule? If I removed it from the rule, would all friendly connection attempts to my server fail?

Thanks.
 
Old 08-06-2005, 07:13 PM   #2
Noth
Member
 
Registered: Jun 2005
Distribution: Debian
Posts: 356

Rep: Reputation: 30
"-m state --state new" tells iptables to use the state module and to only apply that rules to traffic belonging to NEW connections. Anything that is associated with a previous connection would fall under ESTABLISHED, RELATED or possibly INVALID.
 
Old 08-26-2005, 06:24 AM   #3
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Original Poster
Rep: Reputation: 16
Okay, maybe I did not clearly state my problem with the rule:

why is the SYN,ACK SYN,ACK repeated twice in the rule?

Tia.
 
Old 08-26-2005, 08:13 PM   #4
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
This rule is an overkill example of many tutorials. They want to setup a rule for everything and they end up with redundant rules.
Quote:
-A bad_tcp_packets -p tcp -m tcp --tcp-flags SYN,ACK SYN,ACK \
-m state --state NEW -j REJECT --reject-with tcp-reset
why is the SYN,ACK SYN,ACK repeated twice in the rule?
"SYN,ACK SYN,ACK" matchs any packet that has BOTH the SYN and ACK bits set, while "SYN,ACK ACK" matchs any packet with the ACK bit set, but the SYN bit off.
The first set are the bits to test... The second set specifies the bits that must be on. (You may think of it as being a subset of the former).

That rule is 2-times redundant, because of
1- From the nmap manpage:
Quote:
-sS TCP SYN scan: This technique is often referred to as "half-open"
scanning, because you don't open a full TCP connection. You send
a SYN packet, as if you are going to open a real connection and
you wait for a response. A SYN|ACK indicates the port is listen-
ing. A RST is indicative of a non-listener. If a SYN|ACK is
received, a RST is immediately sent to tear down the connection
(actually our OS kernel does this for us).
You don't need to implement a TCP/IP stack with your firewall rules...

2- This rule alone catchs many invalid combinations of TCP flags:
iptables -A bad_tcp -p tcp -m state --state INVALID -j DROP
(I prefer DROP to REJECT)
So you don't need to specify every combination of TCP flags under the sun....

My script uses this:
Quote:
${ipt} -N IN_TCP

# Log/Drop TCP SYN|FIN's
# This will foil the TCP/IP OS Fingerprinting done by Queso,
# and the SYN|FIN|PUSH|URG used by Nmap...
# Note: We need this rule here right before the next one, because no test
# is done for the FIN flag with the --syn option... Earlier iptables(8)
# manpages had a bug in which they stated that --syn will "only match
# TCP packets with the SYN bit set and the ACK and FIN bits cleared".
# This is a bug inherited from the ipchains(8) manpage.
# Really, --syn EQUALS --tcp-flags SYN,RST,ACK SYN
${ipt} -A IN_TCP -p tcp --tcp-flags SYN,FIN SYN,FIN -j ${X_INVALID}

# Make sure that only SYNs are accounted for NEW entries in the state table
# This will halt the FIN, FIN|URG|PUSH (Xmas) & ACK portscans
${ipt} -A IN_TCP -p tcp ! --syn $state NEW -j ${X_INVALID}

# Log/Drop INVALID TCP packets
# This will catch NULL TCP scans (-sN in nmap)
${ipt} -A IN_TCP -p tcp $state INVALID -j ${X_INVALID}

# Accept legitimate TCP traffic
${ipt} -A IN_TCP -p tcp $state ESTABLISHED,RELATED -j ACCEPT

Last edited by primo; 08-26-2005 at 08:15 PM.
 
Old 08-27-2005, 01:59 AM   #5
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Original Poster
Rep: Reputation: 16
Thumbs up

Thanks a ton, primo.

I apparently lost patience while reading the iptables manpage and did not scroll further down to see the explanation. I'm still in the early learning phases so I'm not very conversant with the commands available to me when using manpages.

I put in some effort today to learn ( ) how to search through the manpages and hence found the explanation you have above.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie - firewall rule danimalz Linux - Security 3 07-30-2005 07:25 AM
funny new firewall rule tom_from_van Linux - Security 3 07-19-2005 11:39 AM
APF Firewall Rule Help embsupafly Linux - Security 1 03-08-2005 11:00 PM
is this firewall rule safe? melinda_sayang Linux - Security 1 12-21-2004 07:44 AM
Need A Firewall Rule linuxboy69 Linux - Software 1 11-26-2003 04:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration