This shows you the differences between two versions of the page.
sred:laborator_2._cbac_and_zbf [2020/10/30 13:42] horia.stoenescu [Stateful firewall implementations] |
sred:laborator_2._cbac_and_zbf [2022/10/30 20:53] (current) horia.stoenescu Added pointers for exercises |
||
---|---|---|---|
Line 4: | Line 4: | ||
=== Story === | === Story === | ||
- | 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). | + | 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 a better security solution - zone based firewall (ZBF). |
+ | |||
+ | <note tip> | ||
+ | [[https://curs.upb.ro/2022/pluginfile.php/346995/mod_resource/content/1/sred_lab2_stateful_firewall_updated.pdf|Here]] you can find the presentation for lab2. There are made comparisons between each feature and what is the road from simple ACLs to a basic firewall solution. | ||
+ | </note> | ||
+ | |||
+ | === Local host prerequisites === | ||
+ | If you have a Windows/MacOS machine, you need to install on it [[https://www.realvnc.com/en/connect/download/viewer/windows/|vnc viewer]] to access the Linux/Firewall machines and [[https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html|putty]] for Cisco routers/switches. | ||
+ | You can also check this client side pack from Eve-ng for [[https://www.eve-ng.net/index.php/download/#DL-WIN|Windows]] and [[https://www.eve-ng.net/index.php/download/#DL-OSX|MacOS]]. | ||
+ | |||
+ | For Linux OS, you can use Remmina or Remote Desktop Viewer (both should be already installed). Check this link also: [[https://remmina.org/how-to-install-remmina/|Remmina install]]. | ||
=== Lab infra === | === Lab infra === | ||
Line 12: | Line 22: | ||
You have to do the following: | You have to do the following: | ||
+ | |||
+ | - create a new node for the attacker (see [[https://ocw.cs.pub.ro/courses/sred/setup_lab_remote#create_a_new_node|here]] a tutorial), remove connection router - client2 and attach this new machine | ||
- add IPs for network between the server and the network equipment (use range 1.1.1.0/24) | - add IPs for network between the server and the network equipment (use range 1.1.1.0/24) | ||
Line 29: | Line 41: | ||
**server** and **client1** - eve:eve (with sudo access) | **server** and **client1** - eve:eve (with sudo access) | ||
- | **cisco_7200** - enable passwd: cisco | + | **cisco_7200** - no enable password added |
- | + | ||
- | **Mapping ip-student**: check your machine ip [[https://curs.upb.ro/mod/url/view.php?id=84844|here]] | + | |
</note> | </note> | ||
==== Stateful firewall implementations ==== | ==== Stateful firewall implementations ==== | ||
- | === 1. TCP intercept === | + | === t1. TCP intercept === |
This first scenario is just for getting used to [[https://www.paloaltonetworks.com/cyberpedia/what-is-a-denial-of-service-attack-dos|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. | This first scenario is just for getting used to [[https://www.paloaltonetworks.com/cyberpedia/what-is-a-denial-of-service-attack-dos|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. | ||
Line 50: | Line 60: | ||
- **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. | - **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. | ||
+ | |||
+ | If the high threshold value is exceeded, then the timeout is reduced by half (in default case, to 15 seconds). The connections have the state SYNSENT at start, then if the server responds with SYN-ACK the state is changed to SYNRCVD and firewall is waiting for client to send the ACK in order to finish the 3-way handshake. | ||
In this lab, we will use [[https://linux.die.net/man/8/hping3|hping3]] to simulate the attack. On server machine we have SimpleHTTPServer up and running on port 8080. | In this lab, we will use [[https://linux.die.net/man/8/hping3|hping3]] to simulate the attack. On server machine we have SimpleHTTPServer up and running on port 8080. | ||
Line 133: | Line 145: | ||
</code> | </code> | ||
- | === 2. CBAC === | + | Example state watch-mode (with only 1 SYN packet sent from kali): |
+ | <code> | ||
+ | # attacker sends 1 SYN packet to server on port 8080 | ||
+ | root@kali:# hping3 -n -c 1 -d 120 -S -w 64 -p 8080 1.1.1.2 | ||
+ | # at start, the connection is saved with SYNSENT | ||
+ | Router#sh tcp intercept connections | ||
+ | Incomplete: | ||
+ | Client Server State Create Timeout Mode | ||
+ | 3.3.3.2:14482 1.1.1.2:8080 SYNSENT 00:00:00 00:00:30 W | ||
+ | # then, the server responds with SYN+ACK and the connection is updated | ||
+ | Router#sh tcp intercept connections | ||
+ | Incomplete: | ||
+ | Client Server State Create Timeout Mode | ||
+ | 3.3.3.2:1626 1.1.1.2:8080 SYNRCVD 00:00:03 00:00:26 W | ||
+ | # at last, after the timeout, the connection is removed and a RST is sent to server | ||
+ | Router#sh tcp intercept connections | ||
+ | Incomplete: | ||
+ | Client Server State Create Timeout Mode | ||
+ | |||
+ | </code> | ||
+ | |||
+ | <note> | ||
+ | Check [[http://www.employees.org/univercd/Feb-1998/CiscoCD/cc/td/doc/product/software/ios112/intercpt.htm#xtocid2436922|here]] for a full documentation regarding TCP intercept. | ||
+ | </note> | ||
+ | |||
+ | <note important> | ||
+ | Before continuing with CBAC and ZBF, head to [[https://ocw.cs.pub.ro/courses/sred/laborator_2._cbac_and_zbf#exercies|exercises]] section and solve e1 and e2. | ||
+ | </note> | ||
+ | |||
+ | === t2. CBAC === | ||
<note important> | <note important> | ||
- | Before continuing with CBAC, make sure to delete old tcp intercept configuration: | + | Before starting with CBAC, make sure to delete old tcp intercept configuration: |
<code> | <code> | ||
cisco_7200(config)#no ip tcp intercept list | cisco_7200(config)#no ip tcp intercept list | ||
Line 145: | Line 186: | ||
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. | 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). | + | 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 server (traffic to that machine). |
It provides 4 main functions: | It provides 4 main functions: | ||
Line 218: | Line 259: | ||
</note> | </note> | ||
- | === 3. ZBF === | + | <note important> |
+ | Before continuing with the last feature, ZBF, head to [[https://ocw.cs.pub.ro/courses/sred/laborator_2._cbac_and_zbf#exercies|exercises]] section and solve e3 and e4. | ||
+ | </note> | ||
+ | |||
+ | === t3. ZBF === | ||
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. | 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. | ||
Line 331: | Line 376: | ||
Class-map: ICMP-CMAP (match-any) | Class-map: ICMP-CMAP (match-any) | ||
- | Match: protocol tcp | ||
- | 0 packets, 0 bytes | ||
- | 30 second rate 0 bps | ||
Match: protocol icmp | Match: protocol icmp | ||
1 packets, 64 bytes | 1 packets, 64 bytes | ||
Line 360: | Line 402: | ||
Try to send a GET request to server. Does it work? | Try to send a GET request to server. Does it work? | ||
- | === 4. Extra ZBF === | + | === t4. Extra ZBF === |
- | 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. | + | To allow access to DMZ for http (web servers) for VISITOR and LAN zones, there is need to create a class-map for matching only HTTP traffic and a policy-map to allow data inspection. |
Class map: | Class map: | ||
<code> | <code> | ||
- | CISCO_7200(config)#class-map type inspect HTTP-ONLY-CMAP | + | cisco_7200(config)#class-map type inspect HTTP-ONLY-CMAP |
- | CISCO_7200(config-cmap)#match protocol http | + | cisco_7200(config-cmap)#match protocol http |
</code> | </code> | ||
Policy map: | Policy map: | ||
<code> | <code> | ||
- | CISCO_7200(config)#policy-map type inspect HTTP-ONLY-PMAP | + | cisco_7200(config)#policy-map type inspect HTTP-ONLY-PMAP |
- | CISCO_7200(config-pmap)#class HTTP-ONLY-CMAP | + | cisco_7200(config-pmap)#class HTTP-ONLY-CMAP |
- | CISCO_7200(config-pmap-c)#inspect | + | cisco_7200(config-pmap-c)#inspect |
</code> | </code> | ||
- | Add policy-map to zone-pairs LAN-TO-DMZ and PUBLIC-TO-DMZ: | + | Remove the old policy-map from zone-pair VISITOR-TO-DMZ (1 can be attached per pair): |
<code> | <code> | ||
- | CISCO_7200(config)#zone-pair security LAN-TO-DMZ | + | cisco_7200(config)#zone-pair security VISITOR-TO-DMZ |
- | CISCO_7200(config-sec-zone-pair)#service-policy type inspect HTTP-ONLY-PMAP | + | cisco_7200(config)#no service-policy type inspect VISITOR-TO-DMZ-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 | + | |
</code> | </code> | ||
- | 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//): | + | Add policy-map to zone-pairs LAN-TO-DMZ and VISITOR-TO-DMZ: |
<code> | <code> | ||
- | CISCO_7200#show policy-map type inspect zone-pair 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 VISITOR-TO-DMZ | ||
+ | cisco_7200(config-sec-zone-pair)#service-policy type inspect HTTP-ONLY-PMAP | ||
+ | </code> | ||
- | policy exists on zp PUBLIC-TO-DMZ | + | This allows kali (supposed for now to be a good person) and client1 to access HTTP service from DMZ zone on port 8080: |
- | Zone-pair: PUBLIC-TO-DMZ | + | <code> |
+ | cisco_7200#show policy-map type inspect zone-pair VISITOR-TO-DMZ | ||
+ | Zone-pair: VISITOR-TO-DMZ | ||
Service-policy inspect : HTTP-ONLY-PMAP | Service-policy inspect : HTTP-ONLY-PMAP | ||
Line 397: | Line 443: | ||
Class-map: HTTP-ONLY-CMAP (match-all) | Class-map: HTTP-ONLY-CMAP (match-all) | ||
Match: protocol http | Match: protocol http | ||
- | + | Inspect | |
- | Inspect | + | |
Packet inspection statistics [process switch:fast switch] | Packet inspection statistics [process switch:fast switch] | ||
- | tcp packets: [0:2] | + | tcp packets: [0:10] |
Session creations since subsystem startup or last reset 1 | Session creations since subsystem startup or last reset 1 | ||
Current session counts (estab/half-open/terminating) [0:0:0] | Current session counts (estab/half-open/terminating) [0:0:0] | ||
- | Maxever session counts (estab/half-open/terminating) [0:1:0] | + | Maxever session counts (estab/half-open/terminating) [1:1:1] |
- | Last session created 00:01:12 | + | Last session created 00:00:19 |
Last statistic reset never | Last statistic reset never | ||
- | Last session creation rate 0 | + | Last session creation rate 1 |
Maxever session creation rate 1 | Maxever session creation rate 1 | ||
Last half-open session total 0 | Last half-open session total 0 | ||
Line 413: | Line 458: | ||
Class-map: class-default (match-any) | Class-map: class-default (match-any) | ||
Match: any | Match: any | ||
- | Drop | + | Drop (default action) |
0 packets, 0 bytes | 0 packets, 0 bytes | ||
</code> | </code> | ||
+ | |||
+ | <note important> | ||
+ | The port for webserver is a nonstandard one, so the router will not know about it. Make sure to have the PAM from CBAC here. | ||
+ | </note> | ||
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): | 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): | ||
<code> | <code> | ||
- | CISCO_7200(config)#parameter-map type inspect TCP-SYN-LIMIT | + | cisco_7200(config)#parameter-map type inspect TCP-SYN-LIMIT |
- | CISCO_7200(config-profile)#tcp max-incomplete host 4 block-time 1 | + | cisco_7200(config-profile)#tcp max-incomplete host 4 block-time 1 |
</code> | </code> | ||
Modify the policy-map to use inspect TCP-SYN-LIMIT: | Modify the policy-map to use inspect TCP-SYN-LIMIT: | ||
<code> | <code> | ||
- | CISCO_7200(config)#policy-map type inspect HTTP-ONLY-PMAP | + | cisco_7200(config)#policy-map type inspect HTTP-ONLY-PMAP |
- | CISCO_7200(config-pmap)#class HTTP-ONLY-CMAP | + | cisco_7200(config-pmap)#class HTTP-ONLY-CMAP |
- | CISCO_7200(config-pmap-c)#inspect TCP-SYN-LIMIT | + | cisco_7200(config-pmap-c)#inspect TCP-SYN-LIMIT |
</code> | </code> | ||
After this, we can start our DoS attack on KaliVM (now becomes again Trudy): | After this, we can start our DoS attack on KaliVM (now becomes again Trudy): | ||
<code> | <code> | ||
- | root@KaliVM:# hping3 -n -c 10 -w 64 -S -p 80 10.20.20.2 | + | root@kali:~# hping3 -n -c 10 -w 64 -S -p 8080 1.1.1.2 |
- | HPING 10.20.20.2 (eth0 10.20.20.2): S set, 40 headers + 0 data bytes | + | HPING 1.1.1.2 (eth0 1.1.1.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=44 ip=1.1.1.2 ttl=63 DF id=0 sport=8080 flags=SA seq=0 win=64240 rtt=20.3 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=44 ip=1.1.1.2 ttl=63 DF id=0 sport=8080 flags=SA seq=1 win=64240 rtt=20.0 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=44 ip=1.1.1.2 ttl=63 DF id=0 sport=8080 flags=SA seq=2 win=64240 rtt=19.7 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 | + | len=44 ip=1.1.1.2 ttl=63 DF id=0 sport=8080 flags=SA seq=3 win=64240 rtt=19.6 ms |
- | --- 10.20.20.2 hping statistic --- | + | --- 1.1.1.2 hping statistic --- |
10 packets transmitted, 4 packets received, 60% packet loss | 10 packets transmitted, 4 packets received, 60% packet loss | ||
+ | round-trip min/avg/max = 19.6/19.9/20.3 ms | ||
</code> | </code> | ||
Also, on router we can see some logs generated: | Also, on router we can see some logs generated: | ||
<code> | <code> | ||
- | CISCO_7200(config-pmap-c)# | + | 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 | + | *Oct 30 17:26:44.707: %FW-4-HOST_TCP_ALERT_ON: (target:class)-(VISITOR-TO-DMZ:HTTP-ONLY-CMAP):Max tcp half-open connections (4) exceeded for host 1.1.1.2. |
- | CISCO_7200(config-pmap-c)# | + | *Oct 30 17:26:44.711: %FW-2-BLOCK_HOST: (target:class)-(VISITOR-TO-DMZ:HTTP-ONLY-CMAP):Blocking new TCP connections to host 1.1.1.2 for 1 minute (half-open count 4 exceeded). |
- | *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)# | + | |
</code> | </code> | ||
+ | |||
+ | <note> | ||
+ | Suppose we have in VISITOR area another user. After sending a DoS attack for kali to server, the access to host is blocked so no other users can access it (kali and the other one). | ||
+ | </note> | ||
==== Exercies ==== | ==== Exercies ==== | ||
- | === 1. [2p] Let's sit and watch the attack === | + | === e1. [2p] Let's sit and watch the attack === |
For TCP intercept, change the mode to **watch**, high value for threshold to 100 and low to 10. Keep the list TCP_INTERCEPT. | For TCP intercept, change the mode to **watch**, high value for threshold to 100 and low to 10. Keep the list TCP_INTERCEPT. | ||
Line 467: | Line 519: | ||
</note> | </note> | ||
- | === 2. [2p] There is still hope === | + | === e2. [2p] There is still hope === |
The server opened again port 4444 for chatting. Client1 wants to use it, but the attacker wants to initiate another SYN attack. | The server opened again port 4444 for chatting. Client1 wants to use it, but the attacker wants to initiate another SYN attack. | ||
Line 480: | Line 532: | ||
</code> | </code> | ||
- | Open the connection (before all entries expire - in 15 secs) from client1, send some messages and check the connection from router: | + | Open the connection (before all entries expire - in 30 secs) from client1, send some messages and check the connection from router: |
<code> | <code> | ||
cisco_7200#sh tcp intercept connections | cisco_7200#sh tcp intercept connections | ||
Line 494: | Line 546: | ||
From server, check if it received client1's messages. | From server, check if it received client1's messages. | ||
- | === 3. [2p] Back to business === | + | <note> |
+ | This IOS version is a bit buggy, as the timeout has firstly the default value to 0, then after some seconds (see the create time), is [15 seconds - create_time]. Then, after those 15 seconds passed, it is assigned with 15 seconds, so the total time is 30 seconds for keeping a connection. | ||
+ | </note> | ||
+ | |||
+ | === e3. [2p] Back to business === | ||
As seen above on CBAC - part 3, we can modify also the maximum number of half-open connections for TCP and add a block-time (in minutes). Configure value 5 for host and block-time 1, 2 minutes. | As seen above on CBAC - part 3, we can modify also the maximum number of half-open connections for TCP and add a block-time (in minutes). Configure value 5 for host and block-time 1, 2 minutes. | ||
Line 510: | Line 566: | ||
Wait until timeout expires. Access again the website from kali and client1. | Wait until timeout expires. Access again the website from kali and client1. | ||
- | === 4. [2p] Not this time === | + | === e4. [2p] Not this time === |
In the previous exercise, we saw that after the maximum value of half-open connections is reached, the resources can no longer be accessed, even by the valid clients. After cheking some logs, we identified the attacker's ip and interface and decided to block his access. | In the previous exercise, we saw that after the maximum value of half-open connections is reached, the resources can no longer be accessed, even by the valid clients. After cheking some logs, we identified the attacker's ip and interface and decided to block his access. | ||
Line 541: | Line 597: | ||
</code> | </code> | ||
- | === 5. [2p] Extra ZBF === | + | === e5. [2p] Extra ZBF === |
- | Do task 4 from [[https://ocw.cs.pub.ro/courses/sred/laborator_2._cbac_and_zbf#extra_zbf|Extra ZBF]]. | + | Do task t4 from [[https://ocw.cs.pub.ro/courses/sred/laborator_2._cbac_and_zbf#extra_zbf|Extra ZBF]]. |