Chapter 9, "Context-Based Access Control," discussed how you can use this feature from the Cisco IOS Firewall feature set to implement a stateful firewall function. One thing that I did not cover in Chapter 9 was the capability of CBAC to restrict the number of half-open sessions, which typically is used to prevent TCP SYN flood attacks. This feature is similar to TCP Intercept, but it can examine TCP as well as UDP and ICMP sessions. Of course, with UDP and ICMP, because there is no state machine that defines the setup, maintenance, and removal of a connection, CBAC uses timers instead of connection threshold values. The following sections discuss how you can use CBAC to prevent certain kinds of DoS attacks.
CBAC uses timeouts and thresholds to determine how long state information should be kept for a session and when to drop those sessions, based on them not becoming fully established. Of course, "established" is a defined process when it comes to TCP, in which CBAC can examine the TCP flags to determine the state of the connection. With UDP and ICMP, CBAC must use idle timer limits to approximate when a connection ends. The timeouts and thresholds can be defined globally, as I will show you in this section, or can be done within the actual ip inspect command for the traffic that you are inspecting.
TIP
Cisco recommends that you first make changes to the global timeout and threshold values before configuring your inspection rules.
To set the global CBAC timeouts for inspected connections, use the following commands:
Router(config)# ip inspect tcp synwait-time seconds Router(config)# ip inspect tcp finwait-time seconds Router(config)# ip inspect tcp idle-time seconds Router(config)# ip inspect udp idle-time seconds Router(config)# ip inspect dns-timeout seconds
These commands were discussed thoroughly in Chapter 9, so I do not go into any more depth about them here.
NOTE
You can override the idle timeouts in the actual inspection commands. When a timeout is configured in an inspection command for an application or protocol, it takes precedence over the global timeout value. Also, there is no global timeout parameter for ICMP traffic: this is configured with the inspection command for ICMP traffic.
As with TCP Intercept, you can set connection thresholds for CBAC inspection. However, unlike TCP Intercept, connection thresholds for CBAC include TCP and UDP traffic. The next two sections discuss the configuration of the threshold values and how CBAC uses them to prevent DoS attacks when an attacker attempts to open an abnormally high number of connections to tie up resources on critical services.
Setting up connection thresholds is similar to setting thresholds for TCP Intercept. For CBAC, here are the commands you use:
Router(config)# ip inspect max-incomplete high number Router(config)# ip inspect max-incomplete low number Router(config)# ip inspect one-minute high number Router(config)# ip inspect one-minute low number Router(config)# ip inspect tcp max-incomplete host number block-time minutes
You can specify three connection parameter threshold values: maximum half-open sessions, maximum half-open sessions in a 1-minute period, and maximum TCP half-open sessions per host.
The first two commands specify that when the maximum number of half-open sessions reaches the high threshold value, CBAC starts dropping the half-open sessions until it reaches the low threshold value. The defaults for these thresholds are 500 and 400 half-open sessions, respectively.
The third and fourth commands measure the number of new connection attempts in a 1-minute interval. If the maximum number of new connection attempts reaches the high threshold during the time interval, CBAC begins dropping the half-open sessions until it reaches the low threshold. The defaults for these thresholds are 500 and 400 half-open sessions, respectively.
Both sets of these parameters are similar to the thresholds defined with TCP Intercept. The one main difference between CBAC and TCP Intercept is the last CBAC command in the previous code listing: ip inspect tcp max-incomplete host. This command is a more aggressive command that is used to prevent DoS attacks against a specific host. With this command, CBAC uses two different methods, depending on the value of the block-time variable. If the block-time variable is set to 0 minutes, when the host half-open TCP session limit value is exceeded, CBAC deletes the oldest half-open connection request for every newly requested connection request. However, if the block-time value is set to a minute value greater than 0, when the number of half-open sessions exceeds the host parameter, CBAC blocks all new connection requests to the host (destination) until the block-time period expires.
CAUTION
Be careful about assigning a minute value greater than 0 to the block-time value because this also could block legitimate traffic during a DoS attack. My recommendation is to configure a block-time value of 0. Also, you need to be very careful about the threshold that you configure for the host parameter. Assigning too low of a value for a very busy server could cause CBAC to drop legitimate connection requests.
One main difference between TCP Intercept and CBAC inspection is that TCP Intercept can be used only to prevent TCP SYN flood attacks. CBAC, however, can prevent DoS attacks for TCP and UDP DoS attacks. The thresholds that CBAC uses are based on the number of half-open sessions. For TCP, a half-open session is one that has not reached an established state; this includes both SYN and SYN/ACK messages (CBAC can detect both kinds of floods). For UDP, a half-open session is one in which no returning traffic is detected.
After you have assigned your timing and threshold parameters, you can use various show and debug commands (discussed in Chapter 9) to verify your configuration. One option that I mentioned in this chapter is to use audit trails and alerts. Assuming that you have enabled alerts, and you are experiencing a DoS attack, you will see log output similar to the following:
%FW-4-ALERT_ON: getting aggressive, count (83/500) current 1-min rate: 501 %FW-4-ALERT_OFF: calming down, count (0/400) current 1-min rate: 271
In this example, the first alert message displays the number of half-open sessions (501) and the current limit (500). In the last minute, 271 connection attempts were made. From CBAC's perspective, this is the beginning of a DoS attack. The second message, ALERT OFF, indicates that the number of connections, through both dropping and normal setup completion, has fallen below the minimum threshold (400). In this case, the value is 0, indicating that CBAC dropped some and that the rest were initiated normally.
The combination of both an ON and a OFF message indicates a separate attack. These messages are used for both the maximum number of half-open sessions and the maximum number of new connection attempts in a 1-minute interval.
If a DoS attack is geared at a specific host, you would see the following alert messages:
000022: Jan 02 15:42:11.048: %FW-4-HOST_TCP_ALERT_ON: Max tcp half open connections (50) exceeded for host 192.1.1.2 000023: Jan 02 15:42:11.361: %FW-4-BLOCK_HOST: Blocking new TCP connections to host 192.1.1.2 for 2 minutes (half-open count 50 exceeded) 000024: Jan 02 15:44:11.372:%FW-4-UNBLOCK_HOST: New TCP connections to host 192.1.1.2 no longer blocked
In this example, the first message indicates that the maximum number of half-open TCP connections destined to 192.1.1.2 was exceeded (the limit is 50). The second message indicates that the blocking interval was defined at 2 minutes, so subsequent TCP connection requests are denied. The third message indicates that the 2-minute blocking interval has expired and that new connection requests are allowed to 192.1.1.2.
You must be careful about changing the half-open session thresholds and timeout values for CBAC. Setting these values too low might cause CBAC to trigger dropping connections during a period of high activity with legitimate traffic. Likewise, setting them too high might put more of a burden on a device during an attack because more half-open sessions are allowed. Example 17-14 shows the configuration for the network in Figure 17-1 to illustrate CBAC's configuration to prevent DoS attacks.
Router(config)# ip inspect tcp synwait-time 20 Router(config)# ip inspect tcp idle-time 60 Router(config)# ip inspect udp idle-time 20 Router(config)# ip inspect max-incomplete high 400 Router(config)# ip inspect max-incomplete low 300 Router(config)# ip inspect one-minute high 600 Router(config)# ip inspect one-minute low 500 Router(config)# ip inspect tcp max-incomplete host 300 block-time 0
In this example, I have modified the timeout for three parameters. The TCP half-open session timeout was modified from 30 to 20 seconds; this is a small network, so connections should complete fairly quickly. I also have modified the idle timeout for TCP connections, changing it from 3600 seconds (1 hour) to 60 seconds; again, most of the connections are either HTTP or SMTP, so they should not be idle for a long period of time. Because UDP is not used very often, I have modified the UDP idle timer from 30 to 20 seconds.
I also have modified the maximum number of half-open connection threshold values to 400 and 300, as well as the 1-minute interval threshold values to 600 and 500. These were configured after monitoring normal activity in this network.
One of the most difficult parameters to figure out is the maximum number of half-open sessions to a host (server). Normally, determining what this parameter should be is very difficult because on several servers, such as e-mail and www, the connection requests can vary wildly from one server to the next; coming up with a valid threshold value that will work with all devices is very difficult. In this instance, there are only two servers?the e-mail server and web server. I set the maximum number of half-open sessions to 300 per destination. This is kind of high for the small network e-mail server, but it is a more appropriate number for the web server (remember that downloading a web page from a web server might involve a dozen or more connection requests).
NOTE
When you are modifying the timeout and threshold values, carefully monitor CBAC to ensure that you are not making the problem worse instead of better. Too often I have seen this situation in real networks.
Also, remember my warning from Chapter 16, "Intrusion Detection System": when you enable IDS on your router, some components of CBAC are enabled to examine application layer information to detect certain kinds of attacks. One of the enabled components include the timeout and thresholds for CBAC; therefore, you will definitely need to tune these to ensure that your router doesn't use the default values, which might be artificially low for your environment, causing legitimate connections to be dropped.