![]() CEG
499/699:
|
|
| 05/03/01 |
An IP packet is a sequence of bytes containing
In packet filtering, only the protocol and the address information of each packet is examined. Its contents and context (its relation to other packets and to the intended application) are ignored. Filtering consists of examining incoming or outgoing packets and allowing or disallowing their transmission or acceptance on the basis of a set of configurable rules, called policies.
Packet filtering policies may be based upon any of the following:
This is the original and most basic type of firewall.
Packet filtering alone is not foolproof security. Its weaknesses are:
An advantage of packet filtering is its relative simplicity and ease of
implementation.
Generally, the filtering rules are expressed as a table of conditions and actions that are applied in a certain order until a decision to route or drop the packet is reached. When a particular packet meets all the conditions specified in a given row S of the table, the action specified in S (whether to route or drop the packet) is carried out. Some systems apply the rules in the sequence specified by the administrator until they find a rule that applies. Others enforce a particular order of rule application based on the criteria in the rules, such as source and destination address, regardless of the order in which the rules were specified by the administrator.
An "outbound connection" is a connection initiated from a client process on an internal machine to a server on an external machine. Note that while the connection as a whole is outbound, it includes both outbound packets (internal client to the external server) and inbound packets (those from the external server to the internal client). Similarly, an "inbound connection" is a connection initiated from a client on an external machine to a server on an internal machine. The "inbound interface" for a packet is the interface on the filtering router that the packet appeared on, while the "outbound interface" is the interface the packet will go out on if it isn't denied by the application of the filtering rules.
tbd
tbd
This example is Linux kernel 2.2.x based, and is taken from the ipchains-howto. Linux kernels 2.4.x have a different mechanism called IP-tables, and uses a program called iptables to set up the filtering rules.
Depending on your background in Unix administrative details, you may or may not understand every bit of the following. Even so, this example is worth studying.
The Arrangement: Masqueraded internal network (various operating systems), which we call "GOOD"; Exposed servers in a separate network (called "DMZ" for Demilitarized Zone); PPP Connection to the Internet (called "BAD").
External Network (BAD)
|
|
ppp0|
---------------
| 192.84.219.1| Server Network (DMZ)
| |eth0
| Filter |----------------------------------------------
| Box |192.84.219.250 | | |
| | | | |
|192.168.1.250| | | |
--------------- -------- ------- -------
| eth1 | SMTP | | DNS | | WWW |
| -------- ------- -------
| 192.84.219.128 192.84.219.129 192.84.218.130
|
Internal Network (GOOD)
ping any network This is useful to
tell if a machine is down. traceroute any network Once again,
useful for diagnosis. Access DNS. To make ping more useful.Anti-spoofing Since we don't have any asymmetric routing, we can simply turn on anti-spoofing for all interfaces.
# for f in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 1 > $f; done
Set filtering rules to DENY all: We still allow local loopback traffic, but deny anything else.
# ipchains -A input -i ! lo -j DENY
# ipchains -A output -i ! lo -j DENY
# ipchains -A forward -j DENY
Set Up Interfaces This is usually done in the boot scripts. Make sure the above steps are done before the interfaces are configured, to prevent packet leakage before the rules are set up.
Insert per-protocol masquerading modules. We need to insert into the Linux kernel the masquerading module for FTP, so that active and passive FTP `just work' from the internal network.
# insmod ip_masq_ftp
Packet Filtering for Through Packets. Create several new chains.
# ipchains -N good-dmz # ipchains -N bad-dmz # ipchains -N good-bad # ipchains -N dmz-good # ipchains -N dmz-bad # ipchains -N bad-goodWith masquerading, it's best to filter in the forward chain. We will split the forward chain into the above chains depending on source/destination interfaces; this breaks the problem down into manageable chunks.
ACCEPTing standard error ICMPs is a common thing to do, so we create a chain for it.
# ipchains -N icmp-accSet Up Jumps From forward Chain Unfortunately, we only know (in the forward chain) the outgoing interface. Thus, to figure out what interface the packet came in on, we use the source address (the anti-spoofing prevents address faking). Note that we log anything which doesn't match any of these (obviously, this should never happen).
ipchains -A forward -s 192.168.1.0/24 -i eth0 -j good-dmz ipchains -A forward -s 192.168.1.0/24 -i ppp0 -j good-bad ipchains -A forward -s 192.84.219.0/24 -i ppp0 -j dmz-bad ipchains -A forward -s 192.84.219.0/24 -i eth1 -j dmz-good ipchains -A forward -i eth0 -j bad-dmz ipchains -A forward -i eth1 -j bad-good ipchains -A forward -j DENY -lDefine the icmp-acc Chain Packets which are one of the error ICMPs that get ACCEPTed, otherwise, control will pass back to the calling chain.
ipchains -A icmp-acc -p icmp --icmp-type destination-unreachable -j ACCEPT ipchains -A icmp-acc -p icmp --icmp-type source-quench -j ACCEPT ipchains -A icmp-acc -p icmp --icmp-type time-exceeded -j ACCEPT ipchains -A icmp-acc -p icmp --icmp-type parameter-problem -j ACCEPTGood (Internal) to DMZ (Servers) Internal restrictions: Allow WWW, ftp, traceroute, ssh to external. Allow SMTP to Mail server. Allow POP-3 to Mail server. Allow DNS to Name server. Allow rsync to Web server. Allow WWW to Web server. Allow ping to packet filter box Could do masquerading from internal network into DMZ, but here we don't. Since no one in the internal network should be trying to do evil things, we log any packets that get denied.
ipchains -A good-dmz -p tcp -d 192.84.219.128 smtp -j ACCEPT ipchains -A good-dmz -p tcp -d 192.84.219.128 pop-3 -j ACCEPT ipchains -A good-dmz -p udp -d 192.84.219.129 domain -j ACCEPT ipchains -A good-dmz -p tcp -d 192.84.219.129 domain -j ACCEPT ipchains -A good-dmz -p tcp -d 192.84.218.130 www -j ACCEPT ipchains -A good-dmz -p tcp -d 192.84.218.130 rsync -j ACCEPT ipchains -A good-dmz -p icmp -j icmp-acc ipchains -A good-dmz -j DENY -lBad (external) to DMZ (servers). DMZ restrictions:. Mail server. SMTP to external. Accept SMTP from internal and external. Accept POP-3 from internal. Name server. Send DNS to external. Accept DNS from internal, external and packet filter box. Web server. Accept HTTP from internal and external. Rsync access from internal. Things we allow from external network to DMZ. Don't log violations, as they may happen.
ipchains -A bad-dmz -p tcp -d 192.84.219.128 smtp -j ACCEPT ipchains -A bad-dmz -p udp -d 192.84.219.129 domain -j ACCEPT ipchains -A bad-dmz -p tcp -d 192.84.219.129 domain -j ACCEPT ipchains -A bad-dmz -p tcp -d 192.84.218.130 www -j ACCEPT ipchains -A bad-dmz -p icmp -j icmp-acc ipchains -A bad-dmz -j DENYGood (internal) to Bad (external). Internal restrictions:. Allow WWW, ftp, traceroute, ssh to external. Allow SMTP to Mail server. Allow POP-3 to Mail server. Allow DNS to Name server. Allow rsync to Web server. Allow WWW to Web server. Allow ping to packet filter box. Many people allow everything from the internal to external networks, then add restrictions. We're being fascist. Log violations. Passive FTP handled by masq. module.
ipchains -A good-bad -p tcp --dport www -j MASQ ipchains -A good-bad -p tcp --dport ssh -j MASQ ipchains -A good-bad -p udp --dport 33434:33500 -j MASQ ipchains -A good-bad -p tcp --dport ftp --j MASQ ipchains -A good-bad -p icmp --icmp-type ping -j MASQ ipchains -A good-bad -j REJECT -lDMZ to Good (internal). Internal restrictions:. Allow WWW, ftp, traceroute, ssh to external. Allow SMTP to Mail server. Allow POP-3 to Mail server. Allow DNS to Name server. Allow rsync to Web server. Allow WWW to Web server. Allow ping to packet filter box. If we were masquerading from the internal network to the DMZ, simply refuse any packets coming the other way. As it is, only allow packets which might be part of an established connection.
ipchains -A dmz-good -p tcp ! -y -s 192.84.219.128 smtp -j ACCEPT ipchains -A dmz-good -p udp -s 192.84.219.129 domain -j ACCEPT ipchains -A dmz-good -p tcp ! -y -s 192.84.219.129 domain -j ACCEPT ipchains -A dmz-good -p tcp ! -y -s 192.84.218.130 www -j ACCEPT ipchains -A dmz-good -p tcp ! -y -s 192.84.218.130 rsync -j ACCEPT ipchains -A dmz-good -p icmp -j icmp-acc ipchains -A dmz-bad -j DENY -lDMZ to bad (external). DMZ restrictions:. Mail server. SMTP to external. Accept SMTP from internal and external. Accept POP-3 from internal. Name server. Send DNS to external. Accept DNS from internal, external and packet filter box. Web server. Accept HTTP from internal and external. Rsync access from internal o
ipchains -A dmz-bad -p tcp -s 192.84.219.128 smtp -j ACCEPT ipchains -A dmz-bad -p udp -s 192.84.219.129 domain -j ACCEPT ipchains -A dmz-bad -p tcp -s 192.84.219.129 domain -j ACCEPT ipchains -A dmz-bad -p tcp ! -y -s 192.84.218.130 www -j ACCEPT ipchains -A dmz-bad -p icmp -j icmp-acc ipchains -A dmz-bad -j DENY -lBad (external) to Good (internal). We don't allow anything (non-masqueraded) from the external network to the internal network
ipchains -A bad-good -j REJECT
Packet Filtering for the Linux Box Itself. If we want to use packet
filtering on packets coming into the box itself, we need to do filtering in the
input chain. We create one chain for each destination interface:
ipchains -N bad-if
ipchains -N dmz-if
ipchains -N good-if
ipchains -A input -d 192.84.219.1 -j bad-if ipchains -A input -d 192.84.219.250 -j dmz-if ipchains -A input -d 192.168.1.250 -j good-ifBad (external) interface. Packet Filter box:. PING any network. TRACEROUTE any network. Access DNS. External interface also receives replies to masqueraded packets, and ICMP errors for them and PING replies.
ipchains -A bad-if -i ! ppp0 -j DENY -l ipchains -A bad-if -p TCP --dport 61000:65096 -j ACCEPT ipchains -A bad-if -p UDP --dport 61000:65096 -j ACCEPT ipchains -A bad-if -p ICMP --icmp-type pong -j ACCEPT ipchains -A bad-if -j icmp-acc ipchains -A bad-if -j DENYDMZ interface. Packet Filter box restrictions:. PING any network. TRACEROUTE any network. Access DNS. DMZ interface receives DNS replies, ping replies and ICMP errors.
ipchains -A dmz-if -i ! eth0 -j DENY ipchains -A dmz-if -p TCP ! -y -s 192.84.219.129 53 -j ACCEPT ipchains -A dmz-if -p UDP -s 192.84.219.129 53 -j ACCEPT ipchains -A dmz-if -p ICMP --icmp-type pong -j ACCEPT ipchains -A dmz-if -j icmp-acc ipchains -A dmz-if -j DENY -lGood (internal) interface. Packet Filter box restrictions:. PING any network. TRACEROUTE any network. Access DNS. Internal restrictions:. Allow WWW, ftp, traceroute, ssh to external. Allow SMTP to Mail server. Allow POP-3 to Mail server. Allow DNS to Name server. Allow rsync to Web server. Allow WWW to Web server. Allow ping to packet filter box. Internal interface receives pings, ping replies and ICMP errors.
ipchains -A good-if -i ! eth1 -j DENY
ipchains -A good-if -p ICMP --icmp-type ping -j ACCEPT
ipchains -A good-if -p ICMP --icmp-type pong -j ACCEPT
ipchains -A good-if -j icmp-acc
ipchains -A good-if -j DENY -l
Finally Delete blocking rules:
ipchains -D input 1
ipchains -D forward 1
ipchains -D output 1
All work should be carried out in Operating Systems and Internet Security (OSIS) Lab, 429 Russ. Use any of the PCs numbered 19 to 30. No other WSU facilities are allowed.
Objective: Setup a simple packet filter. In this lab, you will be setting up one of the Linux machines as a firewall based on IP filtering.
The packet filtering example is taken from the ipchains-howto.
| 05/03/01 12:33:21 PM |
| Copyright © 2001 pmateti@cs.wright.edu |