This shows you the differences between two versions of the page.
sred:laborator_2._cbac_and_zbf [2020/10/30 01:10] 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 171: | Line 212: | ||
<note> | <note> | ||
- | There is a bug on this IOS version - for a host VAL < 4, the blocked packets is $VAL + 1. | + | There is a bug on this IOS version - for a host VAL < 4, the blocked packets is VAL + 1. |
</note> | </note> | ||
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 247: | Line 292: | ||
In the setup presented above, we will consider: | In the setup presented above, we will consider: | ||
- | * KaliVM is in LAN zone | + | * client1 is in LAN zone |
- | * UbuntuVM is in DMZ zone | + | * server is in DMZ zone |
- | * InternetVM is in PUBLIC zone (it has internet access) | + | * kali is in VISITOR zone |
+ | |||
+ | <note important> | ||
+ | Before going through exercises 3 and 4 (from this tutorial, not your own tasks), remove all CBAC config using: | ||
+ | <code> | ||
+ | cisco_7200(config)#no ip inspect | ||
+ | </code> | ||
+ | </note> | ||
A. Create zones on firewall: | A. Create zones on firewall: | ||
<code> | <code> | ||
- | CISCO_7200(config)#zone security LAN | + | cisco_7200(config)#zone security LAN |
- | CISCO_7200(config-sec-zone)#description Local Area Network | + | cisco_7200(config-sec-zone)#description Local Area Network - client1 |
- | CISCO_7200(config-sec-zone)#exit | + | cisco_7200(config-sec-zone)#exit |
- | CISCO_7200(config)#zone security DMZ | + | cisco_7200(config)#zone security DMZ |
- | CISCO_7200(config-sec-zone)#description Public Servers Network | + | cisco_7200(config-sec-zone)#description local Servers |
- | CISCO_7200(config-sec-zone)#exit | + | cisco_7200(config-sec-zone)#exit |
- | CISCO_7200(config)#zone security PUBLIC | + | cisco_7200(config)#zone security VISITOR |
- | CISCO_7200(config-sec-zone)#description Internet Access | + | cisco_7200(config-sec-zone)#description Visitor area - kali |
- | CISCO_7200(config-sec-zone)#exit | + | cisco_7200(config-sec-zone)#exit |
</code> | </code> | ||
B. Add the pairs between zones: | B. Add the pairs between zones: | ||
<code> | <code> | ||
- | CISCO_7200(config)#zone-pair security LAN-TO-INTERNET source LAN destination PUBLIC | + | cisco_7200(config)#zone-pair security LAN-TO-VISITOR source LAN destination VISITOR |
- | CISCO_7200(config-sec-zone-pair)#exit | + | cisco_7200(config-sec-zone-pair)#exit |
- | CISCO_7200(config)#zone-pair security LAN-TO-DMZ source LAN destination DMZ | + | cisco_7200(config)#zone-pair security LAN-TO-DMZ source LAN destination DMZ |
- | CISCO_7200(config-sec-zone-pair)#exit | + | cisco_7200(config-sec-zone-pair)#exit |
- | CISCO_7200(config)#zone-pair security PUBLIC-TO-DMZ source PUBLIC destination DMZ | + | cisco_7200(config)#zone-pair security VISITOR-TO-DMZ source VISITOR destination DMZ |
- | CISCO_7200(config-sec-zone-pair)#exit | + | cisco_7200(config-sec-zone-pair)#exit |
</code> | </code> | ||
C. Go directly to step 6 and configure interfaces to each zones: | C. Go directly to step 6 and configure interfaces to each zones: | ||
<code> | <code> | ||
- | CISCO_7200(config)#int e1/0 | + | cisco_7200(config)#int e1/0 |
- | CISCO_7200(config-if)#zone-member security DMZ | + | cisco_7200(config-if)#zone-member security DMZ |
- | CISCO_7200(config)#int e1/1 | + | cisco_7200(config)#int e1/1 |
- | CISCO_7200(config-if)#zone-member security LAN | + | cisco_7200(config-if)#zone-member security LAN |
- | CISCO_7200(config-if)#int e1/2 | + | cisco_7200(config-if)#int e1/2 |
- | CISCO_7200(config-if)#zone-member security PUBLIC | + | cisco_7200(config-if)#zone-member security VISITOR |
</code> | </code> | ||
- | This will apply to zone-pairs defined above the default policy rule and all traffic is denied: | + | This will apply to zone-pairs defined above the default policy rule and all traffic is denied (like a firewall - deny all by def): |
<code> | <code> | ||
- | root@UbuntuVM:~# ping 10.20.20.2 | + | eve@client1:~/Desktop$ ping -c 3 1.1.1.2 |
- | PING 10.20.20.2 (10.20.20.2) 56(84) bytes of data. | + | PING 1.1.1.2 (1.1.1.2) 56(84) bytes of data. |
+ | ^C | ||
+ | --- 1.1.1.2 ping statistics --- | ||
+ | 3 packets transmitted, 0 received, 100% packet loss, time 2051ms | ||
- | ^C | + | # same for kali client |
- | --- 10.20.20.2 ping statistics --- | + | |
- | 7 packets transmitted, 0 received, 100% packet loss, time 6148ms | + | |
</code> | </code> | ||
- | 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. | + | 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 VISITOR members to send icmp-echo req to DMZ. |
<code> | <code> | ||
- | CISCO_7200(config)#class-map type inspect match-any TCP-ICMP-CMAP | + | cisco_7200(config)#class-map type inspect match-any ICMP-CMAP |
- | CISCO_7200(config-cmap)#match protocol tcp | + | cisco_7200(config-cmap)#match protocol icmp |
- | CISCO_7200(config-cmap)#match protocol icmp | + | |
</code> | </code> | ||
Line 305: | Line 357: | ||
E. Define firewall policies: add to policy map the class map defined on point D) | E. Define firewall policies: add to policy map the class map defined on point D) | ||
<code> | <code> | ||
- | CISCO_7200(config)#policy-map type inspect LAN-TO-INTERNET-PMAP | + | cisco_7200(config)#policy-map type inspect VISITOR-TO-DMZ-PMAP |
- | CISCO_7200(config-pmap)#class TCP-ICMP-CMAP | + | cisco_7200(config-pmap)#class ICMP-CMAP |
- | CISCO_7200(config-pmap-c)#inspect | + | cisco_7200(config-pmap-c)#inspect |
</code> | </code> | ||
- | F. Add to LAN-TO-INTERNET zone-pair the policy map: | + | F. Add to VISITOR-TO-DMZ zone-pair the policy map: |
<code> | <code> | ||
- | CISCO_7200(config)#zone-pair security LAN-TO-INTERNET | + | cisco_7200(config)#zone-pair security VISITOR-TO-DMZ |
- | CISCO_7200(config-sec-zone-pair)#service-policy type inspect LAN-TO-INTERNET-PMAP | + | cisco_7200(config-sec-zone-pair)#service-policy type inspect VISITOR-TO-DMZ-PMAP |
</code> | </code> | ||
- | 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: | + | After sending successfully 2 icmp-echo-requests from kali to server (from VISITOR to DMZ) - the traffic is allowed, the policy using is as follows: |
<code> | <code> | ||
- | CISCO_7200#show policy-map type inspect zone-pair | + | cisco_7200#show policy-map type inspect zone-pair |
+ | Zone-pair: VISITOR-TO-DMZ | ||
- | policy exists on zp LAN-TO-INTERNET | + | Service-policy inspect : VISITOR-TO-DMZ-PMAP |
- | Zone-pair: LAN-TO-INTERNET | + | |
- | Service-policy inspect : LAN-TO-INTERNET-PMAP | + | Class-map: ICMP-CMAP (match-any) |
- | + | ||
- | Class-map: TCP-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 | ||
30 second rate 0 bps | 30 second rate 0 bps | ||
- | + | Inspect | |
- | Inspect | + | |
Packet inspection statistics [process switch:fast switch] | Packet inspection statistics [process switch:fast switch] | ||
icmp packets: [0:4] | icmp packets: [0:4] | ||
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) [1:0:0] | + | Current session counts (estab/half-open/terminating) [0:0:0] |
- | Maxever session counts (estab/half-open/terminating) [1:1:0] | + | Maxever session counts (estab/half-open/terminating) [0:1:0] |
- | Last session created 00:00:07 | + | Last session created 00:00:12 |
Last statistic reset never | Last statistic reset never | ||
Last session creation rate 1 | Last session creation rate 1 | ||
Line 348: | Line 394: | ||
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> | ||
Line 354: | Line 400: | ||
See the match for protocol icmp (incremented with 1). | See the match for protocol icmp (incremented with 1). | ||
- | === 4. Extra ZBF === | + | Try to send a GET request to server. Does it work? |
- | 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. | + | === t4. Extra ZBF === |
+ | |||
+ | 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 391: | 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 407: | 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 461: | 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 474: | 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 488: | Line 546: | ||
From server, check if it received client1's messages. | From server, check if it received client1's messages. | ||
- | === 3. [2p] SSH sessions === | + | <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> | ||
- | === 4. [2p] TODO === | + | === 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. | ||
+ | |||
+ | From attacker, start 10 connections: | ||
+ | <code> | ||
+ | root@kali:~# hping3 -n -c 10 -w 64 -S -p 8080 1.1.1.2 | ||
+ | </code> | ||
+ | |||
+ | See how from packet 6, all are dropped and the router generates an alert (Max tcp half-open connections (4) exceeded for host 1.1.1.2.). | ||
+ | |||
+ | Try now to acces from kali browser the website - does it work? | ||
+ | |||
+ | Do the same thing for client1. | ||
+ | |||
+ | Wait until timeout expires. Access again the website from kali and client1. | ||
+ | |||
+ | === 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. | ||
+ | |||
+ | Remember that at part 4 on CBAC, we create a PAM for port 8080 for http. | ||
+ | |||
+ | We need now to create an urlfilter using: | ||
+ | <code> | ||
+ | cisco_7200(config)#ip urlfilter exclusive-domain deny 1.1.1.2 | ||
+ | cisco_7200(config)#ip urlfilter allow-mode off | ||
+ | </code> | ||
+ | |||
+ | Then create a new inspection rule for http with urlfilter, add it to the required interface and direction (in/out), then generate GET requests from each machine - client1 and kali. You should find: | ||
+ | <code> | ||
+ | root@kali:~# curl 1.1.1.2:8080 | ||
+ | <html> | ||
+ | <head> | ||
+ | <title>Forbidden</title></head> | ||
+ | <body bgcolor="#ffffff"> | ||
+ | <center><h1><font color="#ff0000">HTTP Error 403 - Forbidden</font></h1> | ||
+ | <b>You do not have permission to access the document or program you requested. | ||
+ | </b></center> | ||
+ | </body></html> | ||
+ | |||
+ | eve@client1:~/Desktop$ curl 1.1.1.2:8080 | ||
+ | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html> | ||
+ | <title>Directory listing for /</title> | ||
+ | <body> | ||
+ | <h2>Directory listing for /</h2> | ||
+ | [...] | ||
+ | </code> | ||
- | === 5. [2p] TODO === | + | === e5. [2p] Extra ZBF === |
+ | Do task t4 from [[https://ocw.cs.pub.ro/courses/sred/laborator_2._cbac_and_zbf#extra_zbf|Extra ZBF]]. | ||