LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-02-2008, 10:54 AM   #1
dividingbyzero
Member
 
Registered: May 2008
Location: Earth
Distribution: Slackware 12.2
Posts: 52

Rep: Reputation: 16
better to use state firewall or explicitly define what comes back in?


Hi.

Below is by no means a complete firewall, just wondering which approach
is more secure or better to use,

state tracking type firewall:

Code:
iptables -P INPUT DROP
iptables -P OUTPUT DROP

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT

or something like this
Code:
iptables -P INPUT DROP
iptables -P OUTPUT DROP

iptables -A INPUT -p tcp ! --syn --source-port 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
thanks
 
Old 06-02-2008, 12:23 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
[ side note: Don't forget to allow loopback traffic. ]

Short answer is I am not sure it matters much with your tiny ruleset. For a more thorough analysis of some of the pros of a stateful firewall, I refer you to our friend wikipedia.

http://en.wikipedia.org/wiki/Stateful_firewall
 
Old 06-02-2008, 04:58 PM   #3
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by dividingbyzero View Post
Below is by no means a complete firewall, just wondering which approach
is more secure or better to use,

state tracking type firewall:

Code:
iptables -P INPUT DROP
iptables -P OUTPUT DROP

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT

or something like this
Code:
iptables -P INPUT DROP
iptables -P OUTPUT DROP

iptables -A INPUT -p tcp ! --syn --source-port 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
In your first example, only packets which are part of an already established connection (or related to one) will be sent to ACCEPT. In your second example, all packets with a source port of 80 which are not SYN packets will be sent to ACCEPT (really bad idea). The first example is clearly much tighter than the second. And it's also more functional, as your second example doesn't have any way to deal with ICMP error message packets that the HTTP server might throw back at you (RELATED state). BTW, it's a good idea to use stateful filtering for outbound packets too.

Last edited by win32sux; 06-02-2008 at 06:40 PM.
 
Old 06-02-2008, 09:13 PM   #4
dividingbyzero
Member
 
Registered: May 2008
Location: Earth
Distribution: Slackware 12.2
Posts: 52

Original Poster
Rep: Reputation: 16
thanks guys! And the state on OUTBOUND was gonna be a new question but you beat me to it.

So if I have a tcp connection, there isn't a need to explicitly allow icmp on the INPUT like destination-unreachable, etc., since the state check on the inbound will also allow related icmp errors?


Also my firewall will allow in icmp echo-reply, destination-unreachable, and time-exceeded and on the OUTPUT allow echo-request, is this good icmp rules?

thanks
 
Old 06-02-2008, 09:36 PM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by dividingbyzero View Post
thanks guys! And the state on OUTBOUND was gonna be a new question but you beat me to it.
Well, the general idea is pretty much the same.

Quote:
So if I have a tcp connection, there isn't a need to explicitly allow icmp on the INPUT like destination-unreachable, etc., since the state check on the inbound will also allow related icmp errors?
Correct, the RELATED match in your INPUT chain will match any received ICMP errors which are, ummm, related to an outgoing TCP/UDP connection.

Quote:
Also my firewall will allow in icmp echo-reply, destination-unreachable, and time-exceeded and on the OUTPUT allow echo-request, is this good icmp rules?
For incoming ICMP errors related to outgoing TCP/UDP connections you just need to make sure you have a rule for packets in state RELATED in your INPUT chain. To allow your box to respond to pings, you just need to make sure you have a rule in your INPUT chain allowing ICMP echo requests, and the generic ESTABLISHED match in your OUTPUT chain will take care of the echo reply.

Last edited by win32sux; 06-02-2008 at 09:40 PM.
 
Old 06-03-2008, 09:18 PM   #6
dividingbyzero
Member
 
Registered: May 2008
Location: Earth
Distribution: Slackware 12.2
Posts: 52

Original Poster
Rep: Reputation: 16
Thanks, but I read alot that allowing someone to ping you
isn't a good idea. Can you elaborate on this? And if it's a
good idea, what are the benefits of allowing someone to ping
my home machine that isn't a server or anything?


Thanks again

Last edited by dividingbyzero; 06-03-2008 at 09:20 PM.
 
Old 06-04-2008, 12:34 AM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by dividingbyzero View Post
Thanks, but I read alot that allowing someone to ping you
isn't a good idea. Can you elaborate on this? And if it's a
good idea, what are the benefits of allowing someone to ping
my home machine that isn't a server or anything?
When you read that it wasn't a good idea, what were the reasons they provided?

If you don't have any need to have your box respond to ICMP echo requests then don't do it. That's kind of the point of a packet firewall, it lets you allow only the packets which you need. Any other packets represent an unnecessary risk. It's a concept applicable not just to packet filtering, but anything security-related.

Personally, neither my laptop nor desktop respond to ICMP echo requests (or, most of the time, to anything else for that matter). However, I don't believe I've ever installed a server in which I didn't have it respond to ICMP echo requests. Mainly because the convenience outweighed the risk in those cases. But having my desktop/laptop respond to ICMP echo requests does nothing for me regarding convenience.

If you do have a need to respond to ICMP echo requests I would suggest you use the limit or recent matches, as they can help prevent certain types of abuse. Also, specify that you only want to allow ICMP packets which aren't fragmented. There's plenty of examples on the Web.
 
Old 06-04-2008, 02:09 PM   #8
unixfool
Member
 
Registered: May 2005
Location: Northern VA
Distribution: Slackware, Ubuntu, FreeBSD, OpenBSD, OS X
Posts: 782
Blog Entries: 8

Rep: Reputation: 158Reputation: 158
Where I work, we rely on using pings to troubleshoot. What we do is either tell the client to allow pings when troubleshooting is needed (which sometimes slows down the troubleshooting process, as they have to submit a change request to allow pings at the firewall), or create a rule that blocks all but certain types of pings (there are 18 types).

You can also only allow pings to/from certain trusted hosts.

And, as win32sux states, you can threshold icmp and still have certain types allowed. It all depends on your needs.
 
  


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
"Welcome back" block not remembering open/closed state Poetics LQ Suggestions & Feedback 0 01-31-2008 01:22 PM
LXer: State by state, Microsoft responds to creeping threat LXer Syndicated Linux News 0 05-01-2007 07:16 AM
firewall back up javier_ccs Linux - Security 4 01-07-2006 02:04 PM
Explicitly setup a PPTP connection for testing within the network csvke Linux - Networking 0 01-25-2004 07:08 PM
Super DCMA in your State... Or Use a firewall go to jail... merana General 17 04-01-2003 11:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:13 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