Static Packet Filter
A packet-filtering firewall examines each packet against a set of rules. If the rules allow this type of packet through, then it is passed through, otherwise it is dropped or rejected depending on the specifications of the rule. When you choose to drop a connection, the firewall simply ignores the request to communicate. Like when you simply allow your phone to ring until the caller gives up, this leaves the remote host wondering if anything even exists at that location. Rejecting the connection request, on the other hand, is more like if you pick up the phone but immediately put it back down. The firewall, in this case, sends a reset packet to the remote host. The remote host then knows that there is something at the requested address, but that the specific type of connection is denied.
A packet filter must be set up with rules for every type of connection. To make life easier, you define a default final rule that says drop everything. Then you place the rules for allowed traffic above that rule. This way, you stop any traffic that you have not specifically allowed. As an example, let's consider that you have hired a doorman for a party you want to give. You supply the doorman with a list of people who are allowed to enter your party; if a person's name is not on the list, they are not allowed in. This is a much more effective method than trying to supply the doorman with a list of all the people you do not want at your party. If nothing else, the list will be shorter this way.
With a static packet filter, you must be sure to allow traffic back in for any type of traffic you allow out (or vice versa). If you allow your users to connect to Web sites (to port 80), but don't allow traffic from those Web sites (from port 80) back in, nothing will really be accomplished. This requirement can lead to complicated rule sets.
If a static packet-filtering firewall has more complicated rule sets, why would you use one? Simply, it processes traffic more quickly than other methods. If you have a large amount of traffic traveling through your firewall, you may need the speed provided by this type of filter.
How Static Packet Filters Are Implemented in Personal Firewalls
On the Linux platform, ipchains is the most prevalent choice for static packet filters. In a Red Hat Linux 7.2 install, for example, ipchains is set to a medium level of protection by default, and the tool GNOME Lokkit is provided to allow the average user to make minor configuration choices. Lokkit is really designed as a tool for the uncomplicated requirements of a cable modem or DSL connection.
How exactly does ipchains handle packets? I'm glad you asked. There are three lists of rules, or chains, that the ipchains firewall uses to determine how to handle a packet. The first, the input chain, handles traffic coming in to the network card. If the packet is allowed by the input chain rules, it is routed as necessary. If the packet is destined for another host, it will be compared against the rules in the forward chain. If it passes this step, it will be passed to the output chain for evaluation against the rules before being sent out from the ipchains firewall host to its destination.
That description really only applies if you are using an ipchains computer to protect hosts behind it. In our case, we're simply looking at using ipchains to protect the local computer. So, we really only use two chains: input and output. The input chain in our case will apply to all traffic coming into our computer from the Internet. There is only one host that the traffic can be for, our local computer, so it will not be compared against any of the other chains. When we try to send packets out from our computer to the Internet, they will be compared to the rules in the output chain. It really is quite simple.
So, what does this default configuration look like? Well, as I said, the default is "medium." According to the documentation, it will not allow remote connections to the system. Let's take a look at the rules generated and see if we can sort out what they mean. You can get a listing of your chains like the one below by issuing the command ipchains nL -list-numbers.
Chain input (policy ACCEPT): Num target prot opt source destination ports 1 REJECT tcp -y---- 0.0.0.0/0 0.0.0.0/0 * -> 0:1023 2 REJECT tcp -y---- 0.0.0.0/0 0.0.0.0/0 * -> 2049 3 REJECT udp ------ 0.0.0.0/0 0.0.0.0/0 * -> 0:1023 4 REJECT udp ------ 0.0.0.0/0 0.0.0.0/0 * -> 2049 5 REJECT tcp -y---- 0.0.0.0/0 0.0.0.0/0 * -> 6000:6009 6 REJECT tcp -y---- 0.0.0.0/0 0.0.0.0/0 * -> 7100 Chain forward (policy ACCEPT): Chain output (policy ACCEPT):
The first line, "chain input (policy ACCEPT)," states that the default behavior for the chain input is to accept packets. The only items that won't be accepted are those explicitly denied, then, by the rules in this chain (Table 33).
The remaining rules block traffic destined for specific ports on the internal host. Rule one stops any requests to connect via TCP to well-known ports, rule two blocks TCP requests for nfs (network file system), rule five takes out the TCP ports used by Xwindows, and finally rule six blocks TCP for xfs (SGI's journaling file system). Rules three and four simply mirror rules one and two but for UDP.
TABLE 33 Input Chain Rules
Action Source IP Source port Destination IP Destination port Protocol Service
Reject Any Any Any 0-1023 TCP All well-known service ports
Reject Any Any Any 2049 TCP nfs
Reject Any Any Any 0-1023 UDP All well-known service ports
Reject Any Any Any 2049 UDP nfs
Reject Any Any Any 6000-6009 TCP Xwindows
Reject Any Any Any 7100 TCP Xfs
Allow Any Any Any Any Any Anything not defined by rules above is allowed
The output chain handles outgoing traffic, from the client to the world. The default policy for the output chain is ACCEPT, so all traffic initiated by the internal host is allowed.
I would like to point out that none of these rules are set to log information; if they were, we would see an "l" listed in the options field. As we will learn in a later chapter, firewall logs are important for troubleshooting your firewall.
There are two other preconfigured choices you can make when installing or by using the GNOME Lokkit program: High security and Disable firewall. High security disables nearly all network connections, allowing DNS replies and DHCP only so that network interfaces can be activated. Services such as streaming media and instant messaging require a proxy to work when the high security option is chosen. Disable firewall is exactly what it sounds like. You pretty much would only do this if you were running some other firewall software.
Products That Use This Method
As discussed, ipchains is a static packet filter on Linux. The product meets the needs of many unsophisticated users. Even Red Hat suggests that you switch to iptables if you have needs more complicated than those that can be defined using Lokkit.
We generally find static packet filters in hardware devices. As noted earlier in this chapter, the Linksys cable/DSL router has the ability to set up static packet filters. Again, the configuration is simplified for the end user. In fact, unlike ipchains, limited customization is available on the Linksys device.
If static packet filters are so easy to use, straightforward, and fast, why aren't they used more often? As flexible as static packet filters are, they do require more knowledge on the part of the end user to configure them properly. Most of the products that are being targeted at home users really try to make things simple for the user. In order for a static packet filter to be simple, it must be less configurable. It's just so easy to use other methods that most products are leaving static filtering behind.
A static packet filter works at the Network layer of the OSI model. This makes it fastlittle processing of the packet is required, therefore there is little wasted time and overhead. So, on devices where processing power is limited, this is a valuable method.
Static packet filters are transparent to the user. They do not require any special software or configuration on the client computers. You simply request the Internet services you wish to access and the packet filter decides on how to handle the traffic. Of course, if the packet filter blocks traffic, you need to be able to figure that out. Imagine the frustration of trying to surf to your favorite Web site and never getting there. Why?
A static packet filter can be very flexible. A product like ipchains allows a great level of user control, if you're willing to learn how to use the product. The configuration options on my Linksys router, on the other hand, are quite limited. It's really not designed for complex networks.
You'll probably find that the packet filters on the hardware devices for home users are best for blocking large ranges of traffic, not fine-tuning for specific tasks. Ipchains shows that it is possible for a static packet filter to perform complex tasks, it's just that manufacturers are taking away the flexibility to make things easier for you.
Rule sets can become quite complex. For every outgoing packet, you need rules to allow the return traffic. Remember the ephemeral ports discussed in Chapter 2? You would need to allow all traffic in to those ports for traffic that comes from a source port that you wish to use. I would add the further complication that you want to check for the TCP flags that are set on incoming packets. If you see a packet from port 80 to port 1025 on your computer, it should be part of an established TCP session. That means you should see the ACK bit set. If you don't, you probably don't want that packet in. Of course, examining flags isn't foolproof either. What's to stop me from crafting a packet with the ACK bit set just so I can get it past your static packet filter firewall?
Rules that allow traffic to all ports above 1024, the ephemeral ports, are risky for other reasons as well. Some applications have begun to use ports above 1024; Microsoft SQL Server comes to mind. Recently there was a worm discovered that connects to MS SQL Server on its default listening port of 1433. If you allowed all traffic in to 1433, you could inadvertently become infected with this worm. Oh, you think you're safe because you don't run MS SQL server on your home computer. Sorry, turns out that Microsoft released the MS SQL Desktop Edition with Access 2000 and it is vulnerable to this same worm.1 So, maybe you are more vulnerable than you thought.
With the broad rules defined by the preconfigured tools provided by most products, we're blocking or allowing based on all possible IP addresses. If you start to fine-tune your rulestargeting specific hosts that are allowed or deniedyou run into the possibility of someone spoofing an IP address. Let's say you set up an FTP site to allow your mother to grab files from your computer. You know her IP address is 172.16.1.1, so you set up a rule that allows connections to the FTP service from 172.16.1.1 only. What's to stop me, your mean stepsister, from lying and saying my IP address is 172.16.1.1? OK, sure, I won't get any data back from your system (that will go to Mom), but I could send through something that would cause your server to crash. So, in short, I spoof my IP address (fake it) and get past your firewall where I can then wreak havoc. Or at least give you a headache. This would be a little like me giving your mailing address to an aggressive salespersonwhen they send reams of marketing material, it will go to you, not me. You'll be drowning in junk mail and I'll be sipping margaritas in the sun. Well, a girl can dream.
When a TCP packet is too long to traverse a section of the network, the packet is broken down into pieces to send. The original packet is reassembled at the destination. Only the first fragment contains the TCP header with the port information. The remaining fragments contain only the IP header.
Since only the first fragment contains source and destination port information, this is the only packet that a static packet filter rule could evaluate. How should the remaining fragments be handled? The decision made when designing static packet filters was to allow the remaining fragments through. If the first fragment was allowed, the destination host has all the information necessary to reassemble the packet. If the first packet was dropped, there is no harm to the destination because it can never reassemble the packet.
There is only one flaw in this logic. The destination host will hold on to the later fragments, waiting for the first fragment, for a certain amount of time. So, I could deliberately send volumes of fragmented packets to a host and tie up its resources waiting for the first fragment that will never come. If I send enough fragmented packets, I could effectively cause a denial of service (DOS) attack. Special defenses must be built in to static packet filters to counter this attack.
Where Static Packet Filters Fit in the Design of a Secure Environment
Generally speaking, a static packet filter provides an effective first layer of defense. You could use a static packet filter on a hardware device like a router to remove broad types of traffic. You might allow all traffic to and from port 80, but deny all traffic to and from other ports like 137 and 139 that you simply never want to travel across the Internet. Ports 137 and 139 are used by Microsoft Windows for sharing folders and files.
A basic rule set to allow Web, email, and DNS (so that you can use host names instead of IP addresses) would look something like this:
1 Allow internal:anyÅˆany:80 tcp 2 Allow internal:anyÅˆany:53 udp 3 Allow internal:anyÅˆmailserver:25 tcp 4 Allow any:80Åˆinternal:1024-65535 tcp 5 Allow any:53Åˆinternal:1024-65535 udp 6 Allow mailserver:25Åˆinternal:1024-65535 tcp 7 Deny any:anyÅˆany:any any
The first three rules allow the outgoing traffic for Web, DNS, and email. The next three rules allow for the return traffic. The final rule denies anything that hasn't been explicitly allowed by the earlier rules. Since the rules are processed top to bottom, the first rule to match the packet is applied.
Static packet filtering can provide an adequate, simple personal firewall. We are not seeing this strategy used by many personal firewall products, though. If you have decided you need a router and NAT to provide Internet access to multiple hosts, it makes sense to also make use of any packet-filtering functions that may be included (Figure 35). Given the proliferation of more sophisticated personal firewall methods, I wouldn't settle for a static packet filter as my only means of defense.
FIGURE 35 Network design with a static packet filter. Best combined with NAT on a hardware device. Here a router provides both NAT and some basic packet filtering. The hosts behind this device are simply allowed to access the Web, DNS, and email.