All of lore.kernel.org
 help / color / mirror / Atom feed
From: Earl A.Killian <netfilter@lists.killian.com>
To: "Robert P. J. Day" <rpjday@mindspring.com>
Cc: netfilter@lists.netfilter.org
Subject: efficient source address filtering and logging?
Date: Tue, 28 Oct 2003 09:25:51 -0800	[thread overview]
Message-ID: <16286.42655.163600.954714@teak.killian.com> (raw)
In-Reply-To: <20031028165927.11207.15406.Mailman@netfilter-sponsored-by.noris.net>

 > Date: Tue, 28 Oct 2003 09:59:16 -0500 (EST)
 > From: "Robert P. J. Day" <rpjday@mindspring.com>
 > 
 >   i'd like to find a short, efficient way to filter incoming packets with
 > bogus source addresses, but i don't see an elegant way of doing it.
 > 
 >   as we all know, there are a number of clearly bogus source addresses on
 > incoming packets:
 > 
 >   - broadcast
 >   - your own IP address
 >   - any of the private class A, B or C addresses
 >   - class D addresses
 > 
 > and on and on.  so it's natural to want to discard them and, just for fun,
 > log them as well.
 > 
 >   for elegance, i can create a user-defined chain called, say,
 > "reject_bad_source_addresses" to which i jump with every incoming packet.  
 > this user-defined chain will test for all of the bad source addresses, one
 > at a time, and DROP/REJECT each one.  however, if i want to log all of 
 > these rejections, i'd have to double the number of rules in this chain,
 > so that each test would first LOG that packet, then be followed by a 
 > second rule to DROP it.  kind of a pain.
 > 
 >   if i could rewrite the rules all backwards, i could have the 
 > user-defined chain full of ACCEPT rules, and only terminate the chain with 
 > a rule for LOG, followed by one for DROP.  but i don't see how that's 
 > possible.

Here's what my firewall generator produces (for a complex system
description).  Perhaps it will give you some ideas?  Or perhaps you
see a flaw?  I've excerpted just the relevant stuff.  This is machine
generated output, so perhaps it is not the prettiest...

#
# filter/FORWARD - packets received and routed for transmission
#
-A FORWARD -j logdropresvd -s 0/8
-A FORWARD -j logdropresvd -d 0/8
-A FORWARD -j logdropresvd -s 169.254/16
-A FORWARD -j logdropresvd -d 169.254/16
-A FORWARD -j logdropresvd -s 192.0.2/24
-A FORWARD -j logdropresvd -d 192.0.2/24
-A FORWARD -j logdropspoof -s 127/8
-A FORWARD -j logdropspoof -d 127/8
-A FORWARD -j logdropspoof -s 10/8
-A FORWARD -j logdropspoof -d 10/8
-A FORWARD -j logdropspoof -s 176.16/12
-A FORWARD -j logdropspoof -d 176.16/12
-A FORWARD -j forward_eth2 -i eth2
-A FORWARD -j forward_eth1 -i eth1
-A FORWARD -j forward_eth3 -i eth3
-A FORWARD -j forward_eth0 -i eth0
#
# filter/INPUT - packets received and routed to me
#
-A INPUT -j ACCEPT -i lo
-A INPUT -j logdropresvd -s 0/8
-A INPUT -j logdropresvd -d 0/8
-A INPUT -j logdropresvd -s 169.254/16
-A INPUT -j logdropresvd -d 169.254/16
-A INPUT -j logdropresvd -s 192.0.2/24
-A INPUT -j logdropresvd -d 192.0.2/24
-A INPUT -j logdropspoof -s 127/8
-A INPUT -j logdropspoof -d 127/8
-A INPUT -j logdropspoof -s 10/8
-A INPUT -j logdropspoof -d 10/8
-A INPUT -j logdropspoof -s 176.16/12
-A INPUT -j logdropspoof -d 176.16/12
-A INPUT -j input_eth2 -i eth2
-A INPUT -j input_eth1 -i eth1
-A INPUT -j input_eth3 -i eth3
-A INPUT -j input_eth0 -i eth0
#
# filter/OUTPUT - packets generated by me for transmission
#
-A OUTPUT -j ACCEPT -o lo
-A OUTPUT -j logdropresvd -s 0/8
-A OUTPUT -j logdropresvd -d 0/8
-A OUTPUT -j logdropresvd -s 169.254/16
-A OUTPUT -j logdropresvd -d 169.254/16
-A OUTPUT -j logdropresvd -s 192.0.2/24
-A OUTPUT -j logdropresvd -d 192.0.2/24
-A OUTPUT -j logdropspoof -s 127/8
-A OUTPUT -j logdropspoof -d 127/8
-A OUTPUT -j logdropspoof -s 10/8
-A OUTPUT -j logdropspoof -d 10/8
-A OUTPUT -j logdropspoof -s 176.16/12
-A OUTPUT -j logdropspoof -d 176.16/12
-A OUTPUT -j output_eth2 -o eth2
-A OUTPUT -j output_eth1 -o eth1
-A OUTPUT -j output_eth3 -o eth3
-A OUTPUT -j output_eth0 -o eth0
#
# Accept established connections, log/drop invalid ones, return for new ones
#
-A checkstate -j ACCEPT -m state --state ESTABLISHED,RELATED
-A checkstate -j RETURN -m state --state NEW
-A checkstate -j LOG -p tcp --log-ip-options --log-tcp-options --log-prefix "TCP-INVALID "
-A checkstate -j DROP -p tcp
-A checkstate -j LOG -p udp --log-ip-options --log-prefix "UDP-INVALID "
-A checkstate -j DROP -p udp
-A checkstate -j LOG -p icmp --log-ip-options --log-prefix "ICMP-INVALID "
-A checkstate -j DROP -p icmp
-A checkstate -j LOG --log-ip-options --log-prefix "INVALID "
-A checkstate -j DROP
#
# filter/forward_eth0 - packets received on interface eth0 destined for retransmission
#
-A forward_eth0 -j logdrop1918 -s 192.168/16
-A forward_eth0 -j logdropmulti -s 224/3
-A forward_eth0 -j logdropmulti -d 224/3
-A forward_eth0 -j logdropspoof -s 1.2.3.33
-A forward_eth0 -j logdropspoof -s 1.2.3.41
-A forward_eth0 -j checkstate
-A forward_eth0 -j forward_eth0_eth1_tcp -o eth1 -p tcp
-A forward_eth0 -j DROP
#
# tcp packets from forward_eth0_eth1
#
-A forward_eth0_eth1_tcp -j ACCEPT -p tcp -m multiport -d 1.2.3.42 --dports http,https
-A forward_eth0_eth1_tcp -j ACCEPT -p tcp -m multiport -d 1.2.3.43 --dports http,https,smtp,smtps,submission,imaps
-A forward_eth0_eth1_tcp -j DROP
#
# filter/forward_eth1 - packets received on interface eth1 destined for retransmission
#
-A forward_eth1 -j logdrop1918 -s 192.168/16
-A forward_eth1 -j logdropmulti -s 224/3
-A forward_eth1 -j logdropmulti -d 224/3
-A forward_eth1 -j logdropspoof -s 1.2.3.33
-A forward_eth1 -j logdropspoof -s 1.2.3.41
-A forward_eth1 -j checkstate
-A forward_eth1 -j forward_eth1_eth0 -o eth0
-A forward_eth1 -j DROP
#
# filter/forward_eth1_eth0 - packets forwarded from eth1 to eth0
#
-A forward_eth1_eth0 -j ACCEPT -p udp
-A forward_eth1_eth0 -j ACCEPT -p tcp
-A forward_eth1_eth0 -j forward_eth1_eth0_icmp -p icmp
-A forward_eth1_eth0 -j DROP
[snip]
#
# Log and drop RFC1918 net
#
-A logdrop1918 -j LOG --log-ip-options --log-prefix "INET-RFC1918 "
-A logdrop1918 -j DROP
#
# Log and drop MULTI net
#
-A logdropmulti -j LOG --log-ip-options --log-prefix "INET-MULTI "
-A logdropmulti -j DROP
#
# Log and drop reserved nets
#
-A logdropresvd -j LOG --log-ip-options --log-prefix "INET-RESVD "
-A logdropresvd -j DROP
#
# Log and drop spoof attempt
#
-A logdropspoof -j LOG --log-ip-options --log-prefix "ANTI-SPOOF "
-A logdropspoof -j DROP
[snip]


       reply	other threads:[~2003-10-28 17:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20031028165927.11207.15406.Mailman@netfilter-sponsored-by.noris.net>
2003-10-28 17:25 ` Earl A.Killian [this message]
2003-10-28 14:59 efficient source address filtering and logging? Robert P. J. Day
2003-10-28 15:26 ` James Pattie
2003-10-28 15:32   ` Robert P. J. Day
2003-10-28 15:30 ` Alistair Tonner
2003-10-28 15:33   ` Robert P. J. Day
2003-10-28 16:26 ` Chris Brenton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16286.42655.163600.954714@teak.killian.com \
    --to=netfilter@lists.killian.com \
    --cc=netfilter@lists.netfilter.org \
    --cc=rpjday@mindspring.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.