- TCP/IP Primer: How Packet Filtering Works
- TCP and UDP Ports
- TCP's Three-way Handshake
- The Cisco Router as a Packet Filter
- An Alternative Packet Filter: IPChains
- The Cisco ACL
- Effective Uses of Packet-Filtering Devices
- Egress Filtering
- Tracking Rejected Traffic
- Problems with Packet Filters
- Dynamic Packet Filtering and the Reflexive Access List
Tracking Rejected Traffic
When creating Cisco router access lists, one of the greatest downfalls of the log keyword is that it only records matches to the rule in question. Therefore, if the rule is a permit rule, you lose the profoundly important information about which packets are being denied. To track the traffic that is being filtered by an implicit deny, add a "deny any" ACL with the log keyword (as seen in the following example) to the bottom of the list in question. Functionally, the deny any log command does the same thing as the assumed implicit deny, but it facilitates the logging of denied traffic. One good application of this concept is to track abnormal traffic that is being filtered by the implicit deny at the end of an egress filter access list. Using this method allows a means to track all outbound traffic that has a source address other than that of your network. This is a great way to keep a handle on any strange things that might be trying to sneak out of your network! Here is a simple example of how you would tell the router to log blocked traffic:
access-list 11 deny any log
Filtering by Port and Destination Address: The Cisco Extended ACL
Another powerful use of packet-filtering technology involves filtering on packet header information and port numbers. These examples can be applied in the form of specific "conduits" that allow one system to access another (extranets), allow access to a specific public access system (web or DNS server), or allow a specific type of traffic into the network (ICMP packet-too-big unreachables). This functionality is enabled on a Cisco router using the extended access list.
The Cisco Extended ACL
The Cisco extended ACL offers additional features that allow more control of network traffic flow. Instead of only being able to filter on source address, we have the additional flexibility of destination address filtering, filtering based on protocol type, filtering on specific layer 4 port number information, flags, and more. With this additional granularity, the effectiveness of the Cisco router as a packet filter is greatly increased, making it viable for many security concerns.
The extended access list syntax is as follows:
access-list number 100-199 or 2000-2699 permit|deny protocol source source-mask source-port destination destination-mask destination port log|log-input options
You should recognize the first entries in the syntax from the standard access list, up to the protocol keyword. This is where you would specify the protocol you are interested in filtering. Possible selections are IP, TCP, UDP, and ICMP. Because TCP, UDP, and ICMP are all forms of IP-based traffic, when you use IP as the protocol on an access list, it permits or denies any of the other three traffic types. If we had used an extended access list to substitute for one of the standard access lists from the previous section, IP would have been the appropriate choice because it would have blocked all IP traffic types (UDP, TCP, and ICMP).
Remember the importance of rule order. Each incoming packet is checked by each access list in order from top to bottom. When a packet matches the criteria in any one of the access lists, an action is performed. If it is a permit filter, the packet is forwarded; if it is a deny filter, the packet is dropped. No rules test the packet beyond the rule that the packet matched. Use the following code to allow a particular packet in (let's say that its IP address is 220.127.116.11) if it is TCP but to deny it entry if it uses any other IP protocol:
access-list 111 deny ip host 18.104.22.168 any access-list 111 permit tcp host 22.214.171.124 any
The first rule would test true for a TCP packet of address 126.96.36.199. Because it is a "deny" rule, the packet would be dropped. The packet would never get to be tested by the second rule. If the two rules were reversed in order, with the TCP rule first, the filter would work correctly.
In the extended access list's syntax, the source address and mask should look familiar; the destination address and mask follow the same format, and simply mean "where it is going" instead of "where it is from." The keyword any can be used to represent the numerical range 0.0.0.025188.8.131.52, or all addresses.
This is the first time you see ports listed as part of an access list. As mentioned previously, ports are an important part of TCP/IP and the access lists. The source port or destination port entry can specify the type of traffic you want to allow or disallow. When specifying a port number or name, you must also include an operator, such as eq (meaning equal to this port number), gt (for any port above this number), lt (for any port less than this number), or my favorite range (to list an entire contiguous range of port numbers; use the syntax range port1 port2, where port1 is the first port in the range and port2 is the last).
Extended access lists are configured and applied just like standard access lists, including the association of an access group to an interface. Many options can be added to the end of the access list, such as log (as mentioned in the standard access list) or log-input (which also displays the input interface and source MAC address), flags to check for, and the established keyword.
"Friendly Net" Revisited
As mentioned previously, allowing access to a given IP address is not a favored practice. The main reason for this is lack of control and the dangers of spoofing. Using a standard ACL to allow access is a problem because the only thing we have control over is which IP address (or range) can access the entire inside network. This means that not only can the host or range of hosts specified access any station on the inside, but it also can do so on any port number. This is not good. Extended access lists can at least help tighten up that control. We can specify the destination host (or range) to which the host can connect, as well as the port on which they can communicate. This way, we can allow an outside trusted host to access our web server (only) on port 80 (only). Take a look at this example:
access-list 111 permit tcp host 100.100.100.1 gt 1023 host 184.108.40.206 eq 80 log
This example assumes that the trusted host is at address 100.100.100.1 and our target web server is at address 220.127.116.11. We only allow traffic from the trusted host on ephemeral ports, and only to port 80 on our web server. We add the log keyword to track traffic that is passing this rule.
This is not secure. All this guarantees is that we have control over those specified items, helping to lessen the ability of outsiders to exploit our defense. This ACL can be subverted in other ways.
Only allowing port 80 traffic doesn't ensure that only web traffic will transpire from the outside host to our web server. As a matter of fact, if a flaw exists to be exploited in our web server, and an attacker can get a Telnet program or other backdoor running on our web server on port 80, the server might as well be wide open. If this system is on a private network and not on a separate screened subnet, we are just a few leaps away from being fully compromised, especially if the web server has a trust relationship with any other mission-critical servers on our network.
Be sure to tightly harden the system if you elect to control access to its resources solely through the use of packet filters, without further authentication. If possible, run a multiple interface router (or packet-filtering device) or multiple levels of packet-filtering devices where you can structure a separate subnet for public access systems.
Filtering TCP and UDP Ports and ICMP Types
Another handy function of the extended access list is the filtering of certain types of traffic. You can control the types of traffic that leave your network, in effect enforcing your security policy. You can allow or disallow certain types of traffic that enter your network. Denying traffic to a list of popular Trojan program ports or to ports that programs use that conflict with your Internet usage or security policies (IRC, Kazaa, instant messaging programs, and so on) can also be an extra layer of defense. As stated previously, it makes more sense to only allow what you need. A more common use of port filtering is allowing traffic types that can enter or leave your network, like the example in the previous section. For a list of mission-critical ports that any environment should consider defending, see Appendix A of the SANS Top 20 Vulnerabilities, available at http://www.sans.org/top20.
Another use for this type of filtering is to allow or disallow certain informative ICMP messages entrance to your network. ICMP is one of the most exploited of the protocols. It is being used for reconnaissance, denial of service attacks (such as smurf), and more. It is recommended that you block incoming echo requests (ping and Windows traceroute), block any outgoing echo replies, and block time exceeded, for maximum security. All the ICMP traffic types can be blocked with extended ACLs. The use of any ICMP blocking filters could affect network traffic control.
ICMP doesn't work like the other protocols. Instead of having port numbers, it uses type and code identifiers. It is basically set up to send error messages for protocols that can't (such as UDP and IP) and to send informational messages (such as router error messages telling that a host is unreachable). ICMP is used by popular end-to-end troubleshooting utilities such as ping and traceroute. ICMP can be controlled by using Cisco access lists with special ICMP keywords or ICMP type numbers, instead of port numbers such as TCP and UDP access lists.
To block ICMP echo requests (ICMP type 8), we could use a line in an extended access list such as this:
router(config)#access-list 111 deny icmp any any echo-request
The main difference between this access list and others we have looked at is the keyword at the end of the line. This keyword represents the ICMP type and code for echo requests. It means, "deny any ICMP traffic from anywhere to anywhere with the type and code set to echo-request." This filter would be applied on the external router interface to the Internet. Other ICMP traffic types can be filtered in the same way using their type-of-service keywords.
A better way to handle the ICMP blocking would be to allow only the types of traffic that you want and then deny the rest. For example, one important ICMP packet type to allow in is the packet-too-big ICMP unreachable messages (type 3, code 4). This is because without this message, you could have major communications issues. What if a host can't receive a packet because it is too large for the router to handle and the router isn't allowed to return information to the host telling it that the packet is too large? How will the sender ever find out what is wrong and successfully communicate with the host? Luckily, in this example, Cisco has an ICMP keyword for the packet-too-big message. This keyword could be applied as follows, permitting the packet-too-big messages, but denying all other ICMP messages:
router(config)#access-list 111 permit icmp any any packet-too-big router(config)#access-list 111 deny icmp any any
The filter would be applied as usual with an ip access-group 111 in command.