This is an old revision of the document!
In our basic topology scenario, due to small budget our company still uses the old Cisco equipment for routing and filtering, but this time the second branch closed and added instead a visitor network (may be used by people that come at interview). After seeing some attacks done in our internal network like DoS, we decided to test different approaches: started with TCP intercept, continuing with CBAC and in the end implemented successfully the better security solution - zone based firewall (ZBF).
The new end-point machine called kali is a Kali Linux version 2019.3 and represents the possible attacker. The old network from branch 2 is reused (3.3.3.0/24) for visitors - with the first IP from subnet assigned to router and the second one for end-device. Note that we may refer to the router as firewall during the course of the lab.
Again, the router model is 7200 (version: c7200-adventerprisek9-mz.124-9.T4 - link here).
You have to do the following:
- add IPs for network between the server and the network equipment (use range 1.1.1.0/24)
- add IPs for network between the client and kali and the network equipment (use ranges 2.2.2.0/24 and 3.3.3.0/24) First IP is allocated for router and the second one for client1/kali machine
- add routes to make sure the endpoints can ping each other
kali - root:toor
server and client1 - eve:eve (with sudo access)
cisco_7200 - enable passwd: cisco
Mapping ip-student: check your machine ip here
This first scenario is just for getting used to DoS attacks in our topology and hping3 command. Suppose that an attacker (called Trudy) wants to make a server unavailable using a SYN flood attack (which is fairly easy to create). This is done by sending TCP segments with SYN flag and no intention to complete the handshake. The server hangs by waiting for these connections to be finished until the timeout expires, but creates problems with legitimate TCP connections which can be denied.
TCP intercept is a features found in IOS that is used for SYN flood protection. There are 2 modes of protection:
- intercept: the router does mitm by intercepting the user's connection request and pretends to be the server, by completing the connection. Only if the 3-way handshake is completed successfully, the second TCP connection is set with the server.
Note: This process is transparent to both server and client
Suppose a SYN flood attack happens. The router has a buffer for all opened connections on behalf of client, that will timeout after a period of time (it sends to client a RST) due to no completed 3-way handshake and removed from the connection table. By using this approach, the server remains unaffected by the attack and valid requests are answered.
- watch: the disadvantage of intercept is that most of the times the router does this mitm for fair clients and adds overhead. A solution can be watch mode, which is a reactive approach that is monitoring connections, keeping track of half-open ones. Again, after a timeout (default 30 seconds) if a connection is not completed, the router sends a RST to server to remove it. This will remove all unwanted incompleted connections and allows legitimate ones to complete.
In this lab, we will use hping3 to simulate the attack. On server machine we have SimpleHTTPServer up and running on port 8080.
For TCP intercepting, we need firstly to add on router an ACL to permit tcp for any ip:
cisco_7200(config)#ip access-list extended TCP_INTERCEPT cisco_7200(config-ext-nacl)#permit tcp any host 1.1.1.2 eq 8080
Enable TCP intercept in global config mode and specify the traffic to be analyzed (using ACL from above):
cisco_7200(config)#ip tcp intercept list TCP_INTERCEPT
The default mode is intercept, which is the one we are goind to use here. To change it to watch:
cisco_7200(config)#ip tcp intercept mode watch
Note that a mix of them is not possible.
There are also 3 timeouts that can be also configured: watch (default 30 secs - waiting time for 3-way handshake to complete), finrst (default 5 secs - waiting time for a connection to finish) and connection (default 24 hours - the maximum time of connection management. This is for sure one with handshake completed, but it can be in idle mode).
A high and low threshold values can be configured to deal with a big number of requests. After the high value is reached, it begins to drop connections until the low one. Default for high is 1100 and for low 900. To set them in production, you need careful baseline analysis to avoid dropping legitimate connections. These can be changed using:
cisco_7200(config)#ip tcp intercept max-incomplete high 100 cisco_7200(config)#ip tcp intercept max-incomplete low 10
The default method in aggressive mode is to drop oldest connections first until the connections number is below the minimum value. This can be also changed to random:
cisco_7200(config)#ip tcp intercept drop-mode random
Let's stress the webserver using hping3 command:
root@kali:# hping3 -n -c 1000 -d 120 -S -w 64 -p 8080 --flood 1.1.1.2
Explanations for the flags used:
Monitor the connections on router device (see that all are marked as incomplete):
cisco_7200#sh tcp intercept connections Incomplete: Client Server State Create Timeout Mode 3.3.3.2:47922 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47923 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47920 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47921 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47926 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47927 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47924 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47925 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47930 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47931 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I 3.3.3.2:47928 1.1.1.2:8080 SYNRCVD 00:00:00 00:00:00 I [...] *Oct 29 02:29:33.847: %TCP-6-INTERCEPT: getting aggressive, count (1100/1100) 1 min 0
See that each conn has SYNRCVD state, because a SYN-ACK was sent by the router and the mode is I (intercept).
Note that this will drop any other connection request sent to server (in our case, there were generated ~500k in few secs, but only 1100 left for analysis). This can be seen here:
cisco_7200#sh tcp intercept statistics Intercepting new connections using access-list TCP_INTERCEPT 1100 incomplete, 0 established connections (total 1100)
After 1 minute, the connections will drop until low value and the rest are retransmitted to client with SYN+ACK until timeout (due to aggresive mode, the value is reduced by half):
cisco_7200# *Oct 29 02:30:54.195: %TCP-6-INTERCEPT: calming down, count (0/900) 1 min 0
CBAC stands for Context-Based Access Control and represents a feature of Cisco products that is used for verifying protocol of application layer and dynamic modification of firewall rules that are based on it.
Using this feature, the number of connections opened by outside machines can be limited (to stop a DoS attack). This task proposes to create a CBAC rule that is used for monitoring TCP connections and added on outbound interface to UbuntuVM (traffic to that machine).
Create firstly an inspect rule for tcp and apply it to an interface:
CISCO_7200(config)#ip inspect name INSPECT_TCP_CONN tcp CISCO_7200(config)#int fa0/0 CISCO_7200(config-if)#ip inspect INSPECT_TCP_CONN out
Try now to access the webserver from KaliVM. It should work.
CBAC has 2 types of logging functions: alerts and audits.
Alerts are messages concerning CBAC operations (like alert for DoS attack or low resources). They are enabled by default and displayed to console. To disable, use:
CISCO_7200(config)#ip inspect alert-off
Audits are used to keep track of connections inspected by CBAC. Used for statistics about connections. There are disabled by default and to enable use:
CISCO_7200(config)#ip inspect audit-trail
root@KaliVM:# hping3 -n -c 10 -w 64 -S -p 80 10.20.20.2
On the next step, we want to limit the number of half-opened TCP connections (3-way handshake is not finished) - see image from here.
Using the command from below, only a maximum of 4 half-opened TCP connections are accepted by one host, the other ones being dropped and blocked for 1 minute (block-time 1, where is in minuted):
CISCO_7200(config)#ip inspect tcp max-incomplete host 4 block-time 1
On attacker (KaliVM) start a 10 connections using hping3 command:
root@KaliVM:# hping3 -n -c 10 -w 64 -S -p 80 10.20.20.2
You will see on the kali VM that the first 4 are allowed and the rest of 6 are blocked:
root@KaliVM:/# hping3 -n -c 10 -w 64 -S -p 80 10.20.20.2 HPING 10.20.20.2 (eth0 10.20.20.2): S set, 40 headers + 0 data bytes len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=0 win=29200 rtt=31.6 ms len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=1 win=29200 rtt=14.9 ms len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=2 win=29200 rtt=22.8 ms len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=3 win=29200 rtt=21.9 ms --- 10.20.20.2 hping statistic --- 10 packets transmitted, 4 packets received, 60% packet loss
Also, log entries are generated on Cisco device:
CISCO_7200(config)# *Oct 8 20:33:16.127: %FW-4-HOST_TCP_ALERT_ON: Max tcp half-open connections (4) exceeded for host 10.20.20.2 CISCO_7200(config)# *Oct 8 20:33:16.131: %FW-2-BLOCK_HOST: Blocking new TCP connections to host 10.20.20.2 for 1 minute (half-open count 4 exceeded).
A big drawback of the solution presented above is that it can become very complex when there is need to manage multiple interfaces. Also, it does not offer rules per host or network, all being bound to inbound or outbound traffic. Zone based firewall (or ZBF) is the next proposed security solution.
The model of ZBF is as following:
ZBF allows the configuration of policies at a granular level, per protocol, host. Each policy can take one of these three actions:
The table from below summaries the actions taken by ZBF when monitoring traffic:
The configuration steps are as followed:
In the setup presented above, we will consider:
A. Create zones on firewall:
CISCO_7200(config)#zone security LAN CISCO_7200(config-sec-zone)#description Local Area Network CISCO_7200(config-sec-zone)#exit CISCO_7200(config)#zone security DMZ CISCO_7200(config-sec-zone)#description Public Servers Network CISCO_7200(config-sec-zone)#exit CISCO_7200(config)#zone security PUBLIC CISCO_7200(config-sec-zone)#description Internet Access CISCO_7200(config-sec-zone)#exit
B. Add the pairs between zones:
CISCO_7200(config)#zone-pair security LAN-TO-INTERNET source LAN destination PUBLIC CISCO_7200(config-sec-zone-pair)#exit CISCO_7200(config)#zone-pair security LAN-TO-DMZ source LAN destination DMZ CISCO_7200(config-sec-zone-pair)#exit CISCO_7200(config)#zone-pair security PUBLIC-TO-DMZ source PUBLIC destination DMZ CISCO_7200(config-sec-zone-pair)#exit
C. Go directly to step 6 and configure interfaces to each zones:
CISCO_7200(config)#int e1/0 CISCO_7200(config-if)#zone-member security DMZ CISCO_7200(config)#int e1/1 CISCO_7200(config-if)#zone-member security LAN CISCO_7200(config-if)#int e1/2 CISCO_7200(config-if)#zone-member security PUBLIC
This will apply to zone-pairs defined above the default policy rule and all traffic is denied:
root@UbuntuVM:~# ping 10.20.20.2 PING 10.20.20.2 (10.20.20.2) 56(84) bytes of data. ^C --- 10.20.20.2 ping statistics --- 7 packets transmitted, 0 received, 100% packet loss, time 6148ms
D. Define what type of traffic is of interest and should be allowed to pass the firewall. In our case, we would like to let our LAN members to access anything from Internet and DMZ, including TCP and ICMP.
CISCO_7200(config)#class-map type inspect match-any TCP-ICMP-CMAP CISCO_7200(config-cmap)#match protocol tcp CISCO_7200(config-cmap)#match protocol icmp
The class map from above is going to match any protocols defined within it OR match all of them. You can force some source IP addresses to match by using an ACL.
E. Define firewall policies: add to policy map the class map defined on point D)
CISCO_7200(config)#policy-map type inspect LAN-TO-INTERNET-PMAP CISCO_7200(config-pmap)#class TCP-ICMP-CMAP CISCO_7200(config-pmap-c)#inspect
F. Add to LAN-TO-INTERNET zone-pair the policy map:
CISCO_7200(config)#zone-pair security LAN-TO-INTERNET CISCO_7200(config-sec-zone-pair)#service-policy type inspect LAN-TO-INTERNET-PMAP
After sending successfully 2 icmp-echo-requests from KaliVM to InternetVM (from LAN to PUBLIC) - the traffic is allowed, the policy using is as follows:
CISCO_7200#show policy-map type inspect zone-pair policy exists on zp LAN-TO-INTERNET Zone-pair: LAN-TO-INTERNET Service-policy inspect : LAN-TO-INTERNET-PMAP Class-map: TCP-ICMP-CMAP (match-any) Match: protocol tcp 0 packets, 0 bytes 30 second rate 0 bps Match: protocol icmp 1 packets, 64 bytes 30 second rate 0 bps Inspect Packet inspection statistics [process switch:fast switch] icmp packets: [0:4] Session creations since subsystem startup or last reset 1 Current session counts (estab/half-open/terminating) [1:0:0] Maxever session counts (estab/half-open/terminating) [1:1:0] Last session created 00:00:07 Last statistic reset never Last session creation rate 1 Maxever session creation rate 1 Last half-open session total 0 Class-map: class-default (match-any) Match: any Drop 0 packets, 0 bytes
See the match for protocol icmp (incremented with 1).
To allow access to DMZ for http (web servers) for LAN and PUBLIC zones, there is need to create a class-map for matching only HTTP traffic and a policy-map to allow data inspection.
Class map:
CISCO_7200(config)#class-map type inspect HTTP-ONLY-CMAP CISCO_7200(config-cmap)#match protocol http
Policy map:
CISCO_7200(config)#policy-map type inspect HTTP-ONLY-PMAP CISCO_7200(config-pmap)#class HTTP-ONLY-CMAP CISCO_7200(config-pmap-c)#inspect
Add policy-map to zone-pairs LAN-TO-DMZ and PUBLIC-TO-DMZ:
CISCO_7200(config)#zone-pair security LAN-TO-DMZ CISCO_7200(config-sec-zone-pair)#service-policy type inspect HTTP-ONLY-PMAP CISCO_7200(config-sec-zone-pair)#exit CISCO_7200(config)#zone-pair security PUBLIC-TO-DMZ CISCO_7200(config-sec-zone-pair)#service-policy type inspect HTTP-ONLY-PMAP
This allows KaliVM (supposed for now to be a good person) and InternetVM to access HTTP service from DMZ zone (on UbuntuVM open a temporary service using: nc -k -l 80):
CISCO_7200#show policy-map type inspect zone-pair PUBLIC-TO-DMZ policy exists on zp PUBLIC-TO-DMZ Zone-pair: PUBLIC-TO-DMZ Service-policy inspect : HTTP-ONLY-PMAP Class-map: HTTP-ONLY-CMAP (match-all) Match: protocol http Inspect Packet inspection statistics [process switch:fast switch] tcp packets: [0:2] Session creations since subsystem startup or last reset 1 Current session counts (estab/half-open/terminating) [0:0:0] Maxever session counts (estab/half-open/terminating) [0:1:0] Last session created 00:01:12 Last statistic reset never Last session creation rate 0 Maxever session creation rate 1 Last half-open session total 0 Class-map: class-default (match-any) Match: any Drop 0 packets, 0 bytes
However, this does not limit the number of tcp sessions opened. Using a session-filter, we can block more than X sessions opened (X=4 in this case, as it was for CBAC):
CISCO_7200(config)#parameter-map type inspect TCP-SYN-LIMIT CISCO_7200(config-profile)#tcp max-incomplete host 4 block-time 1
Modify the policy-map to use inspect TCP-SYN-LIMIT:
CISCO_7200(config)#policy-map type inspect HTTP-ONLY-PMAP CISCO_7200(config-pmap)#class HTTP-ONLY-CMAP CISCO_7200(config-pmap-c)#inspect TCP-SYN-LIMIT
After this, we can start our DoS attack on KaliVM (now becomes again Trudy):
root@KaliVM:# hping3 -n -c 10 -w 64 -S -p 80 10.20.20.2 HPING 10.20.20.2 (eth0 10.20.20.2): S set, 40 headers + 0 data bytes len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=0 win=29200 rtt=31.6 ms len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=1 win=29200 rtt=14.9 ms len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=2 win=29200 rtt=22.8 ms len=46 ip=10.20.20.2 ttl=63 DF id=0 sport=80 flags=SA seq=3 win=29200 rtt=21.9 ms --- 10.20.20.2 hping statistic --- 10 packets transmitted, 4 packets received, 60% packet loss
Also, on router we can see some logs generated:
CISCO_7200(config-pmap-c)# *Oct 8 22:24:35.163: %FW-4-HOST_TCP_ALERT_ON: (target:class)-(PUBLIC-TO-DMZ:HTTP-ONLY-CMAP):Max tcp half-open connections (4) exceeded for host 10.20.20.2 CISCO_7200(config-pmap-c)# *Oct 8 22:24:35.167: %FW-2-BLOCK_HOST: (target:class)-(PUBLIC-TO-DMZ:HTTP-ONLY-CMAP):Blocking new TCP connections to host 10.20.20.2 for 1 minute (half-open count 4 exceeded). CISCO_7200(config-pmap-c)#
For TCP intercept, change the mode to watch, high value for threshold to 100 and low to 10. Keep the list TCP_INTERCEPT.
Generate a new SYN flood attack from the kali machine and analyze the statistics and connections:
- are the threshold values used as configured and what is the state of connections ? [1p]
- capture on kali the RST packets using tcpdump (hint: 'tcp[13] & 4!=0' or 'tcp[tcpflags] == tcp-rst') and on server the SYN packets (hint: use 'tcp[13] & 2!=0'). Are SYN packets seen on server using watch mode ? [1p]
The server opened again port 4444 for chatting. Client1 wants to use it, but the attacker wants to initiate another SYN attack.
Change tcp intercept mode to intercept, keep the same threshold values, add to the same acl (TCP_INTERCEPT) a new entry for tcp port 4444. Then, start it using nc on server:
root@serverhq:/# nc -l 4444
And send tcp requests with SYN flag set from kali:
root@kali:~# hping3 -c 100 -n -S -p 4444 --faster 1.1.1.2
Open the connection (before all entries expire - in 15 secs) from client1, send some messages and check the connection from router:
cisco_7200#sh tcp intercept connections Incomplete: Client Server State Create Timeout Mode 3.3.3.2:1886 1.1.1.2:4444 SYNRCVD 00:00:07 00:00:03 I [...] Established: Client Server State Create Timeout Mode 2.2.2.2:39056 1.1.1.2:4444 ESTAB 00:00:04 23:59:55 I
From server, check if it received client1's messages.