LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-20-2023, 09:27 AM   #1
dalacor
Member
 
Registered: Feb 2019
Distribution: Slackware
Posts: 170

Rep: Reputation: Disabled
Iptables Block port scans and bogus TCP Flags


These three websites have some examples of rules to apply to block port scans and ddos.

https://github.com/BrentonEarl/Iptab...firewall.basic

https://www.booleanworld.com/depth-g...inux-firewall/

https://javapipe.com/blog/iptables-ddos-protection/

I have input the ones that I am asking about:

Code:
Website 3:

### 1: Drop invalid packets ### 
/sbin/iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP

### 4: Block packets with bogus TCP flags ### 
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP
/sbin/iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP

Website 2:

iptables -A INPUT -p tcp -m tcp --tcp-flags ALL FIN,PSH,URG -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP

Website 1:

# Block port scans
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
$IPTABLES -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
$IPTABLES -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
As you can see the different website have slightly different flags for Bogus/Port Scanning Traffic. How do I verify what is actually correct as I don't want to drop legitimate traffic? Unfortunately, a lot of websites have a lot of obsolete or inaccurate information on Iptables. So I am not sure why Website 3 doesn't have all the flags that say website 1 mentions. I have only applied the rules from Website 3, but would like to apply from the other two websites.

Last edited by dalacor; 03-20-2023 at 10:20 AM. Reason: Changed focus of topic to just one question
 
Old 03-20-2023, 07:39 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
The examples between Web 3 and Wen1&2 are for different purpose. The Web3 block the all incoming type of traffic, such as going-through and going-in.
 
Old 03-22-2023, 07:18 AM   #3
dalacor
Member
 
Registered: Feb 2019
Distribution: Slackware
Posts: 170

Original Poster
Rep: Reputation: Disabled
If you are referring to the difference between prerouting and Input, I get that. Website 3 makes perfect sense to block unwanted traffic at Prerouting stage as these rules are applied before the Input, Forward rules.

to use an example of what I am actually asking:

Website three TCP Flags are as follows - --tcp-flags FIN,SYN FIN,SYN -j DROP
Whereas Website one TCP flags are as follows - --tcp-flags SYN,FIN SYN,FIN -j DROP

As you can see the FIN, SYN is reversed to SYN, FIN in each example. What I want to understand is what the difference is between these two sets of flags for example. I don't know if one of the websites is wrong or both are correct and are blocking a different attack. I want to learn what each set of flags is blocking and whether I have covered all the rules necessary to drop unwanted traffic.
 
Old 03-22-2023, 08:01 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
> I don't know if one of the websites is wrong or both are correct.
Both is the same from TCP flags point of view, blocking TCP SYN or TCP FIN packet.
 
Old 03-23-2023, 06:50 AM   #5
dalacor
Member
 
Registered: Feb 2019
Distribution: Slackware
Posts: 170

Original Poster
Rep: Reputation: Disabled
Thank you. I will see if I can find a website that explains what each of these flag settings actually do.
 
  


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
Encrypting One TCP Port and only One TCP Port? mpapet Linux - Networking 5 08-22-2017 02:20 PM
Accessing TCP flags in TCP packets on Linux using C !! vishamr2000 Programming 2 10-16-2006 09:46 AM
Renamed bogus "/var/mail/macleanl" into "/var/mail/BOGUS.macleanl.xPVB" paul_mat Linux - Networking 1 07-04-2006 12:50 PM
Block ping scans (iptables) robeb Linux - Security 9 06-12-2002 03:21 AM
FYI: increasing amount of port TCP/1433 scans unSpawn Linux - Security 0 05-22-2002 11:07 AM

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

All times are GMT -5. The time now is 05:39 AM.

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