|
| 1 | +--- |
| 2 | +title: Extended ruleset |
| 3 | +pcx_content_type: configuration |
| 4 | +sidebar: |
| 5 | + order: 3 |
| 6 | +head: |
| 7 | + - tag: title |
| 8 | + content: Extended suggested ruleset |
| 9 | +--- |
| 10 | + |
| 11 | +If you are unable to export your current perimeter firewall rules, consider identifying categories of systems or user groups that reside on your Magic Transit prefixes. For example: |
| 12 | + |
| 13 | +- [Endpoints (user devices)](#endpoints-user-devices) |
| 14 | +- [Internal routers](#internal-routerfirewall-ip-addresses) |
| 15 | +- [Web servers](#web-servers) |
| 16 | +- [Non-web servers](#non-web-servers) |
| 17 | + |
| 18 | +For each item above, consider the requirements in terms of their permitted Internet access. For example, permit what is required for legitimate traffic and block the rest. |
| 19 | + |
| 20 | +## Create lists for using Magic Firewall rules |
| 21 | + |
| 22 | +For more information on lists, refer to [Use rule lists](/cloudflare-one/reusable-components/use-rules-list/). |
| 23 | + |
| 24 | +You can also create a list from the dashboard from **Configurations** > **Lists** on your **Account Home**. |
| 25 | + |
| 26 | +## Endpoints (User devices) |
| 27 | + |
| 28 | +Endpoint devices do not operate as servers, which means: |
| 29 | + |
| 30 | +- They receive traffic from standard common ports — for example `80` or `443` — towards their ephemeral ports, above `32768` in modern operating systems (above `1025` in older Windows Server 2003 and Windows XP). |
| 31 | +- Connections flow outwards, not inwards, and therefore do not receive TCP SYN or ACK packets. |
| 32 | +- They typically only need client TCP and UDP, with no requirement for ingress ICMP. |
| 33 | + |
| 34 | +For example, you can create a list for the combination of generic client TCP and client UDP that allows external pings or traceroutes and a catchall rule for all other protocols and traffic. |
| 35 | + |
| 36 | +Create a list named **Endpoints** and specify the list of endpoints or user IP addresses to reference within the rules. |
| 37 | + |
| 38 | +:::note |
| 39 | +Rule 10 in the example ruleset below is acting as a catch-all to block all traffic not permitted in rules 1-3 towards your list of Endpoint IP addresses. If you want to permit other traffic to these destination IP addresses, the new rule must be added before rule 10. |
| 40 | + |
| 41 | +::: |
| 42 | + |
| 43 | +### Suggested rules |
| 44 | + |
| 45 | +**Rule ID**: 1 |
| 46 | +**Description**: Endpoints (clients) will receive traffic destined for ephemeral ports. Blocks inbound SYN-only traffic. (meaning SYN-ACKs are permitted) |
| 47 | +**Match**: `ip.proto eq "tcp" and ip.dst in $endpoints and tcp.dstport in {32768..60999} and not (tcp.flags.syn and not tcp.flags.ack)` |
| 48 | +**Action**: Allow |
| 49 | + |
| 50 | +**Rule ID**: 2 |
| 51 | +**Description**: Endpoints (clients) will receive traffic destined for ephemeral ports |
| 52 | +**Match**: `ip.proto eq "udp" and ip.dst in $endpoints and udp.dstport in {32768..60999}` |
| 53 | +**Action**: Allow |
| 54 | + |
| 55 | +**Rule ID**: 3 |
| 56 | +**Description**: Permits ICMP traffic to destination IP addresses in `$endpoints` list with ICMP Types: |
| 57 | + |
| 58 | +- Type 0 = Echo Reply |
| 59 | +- Type 3 = Destination Unreachable |
| 60 | +- Type 11 = Time Exceeded |
| 61 | + |
| 62 | +**Match**: `ip.proto eq "icmp" and ip.dst in $endpoints and (icmp.type eq 0 or icmp.type eq 3 or icmp.type eq 11)` |
| 63 | +**Action**: Allow |
| 64 | + |
| 65 | +**Rule ID**: 10 |
| 66 | +**Description**: Otherwise deny all traffic to IP’s in `$endpoints` list |
| 67 | +**Match**: `ip.dst in $endpoints` |
| 68 | +**Action**: Block |
| 69 | + |
| 70 | +## Internal router/Firewall IP addresses |
| 71 | + |
| 72 | +Follow the best practices for internal routers or firewall interface IP addresses on your MT prefixes below. |
| 73 | + |
| 74 | +1. Create [an IP list](/waf/tools/lists/custom-lists/#ip-lists), **Internal routers** for example, with your IP addresses. |
| 75 | +2. Block ICMP if it is not needed. |
| 76 | +3. Permit GRE/ESP as needed if the devices have GRE/IPsec tunnels via the Internet. |
| 77 | + |
| 78 | +### Suggested rules |
| 79 | + |
| 80 | +**Rule ID**: 1 |
| 81 | +**Description**: Permit limited ICMP traffic inbound, including: |
| 82 | + |
| 83 | +- Type 0 - Echo Reply |
| 84 | +- Type 3 - Destination Unreachable |
| 85 | +- Type 8 - Echo |
| 86 | +- Type 11 - Time Exceeded |
| 87 | + |
| 88 | +**Match**: `ip.proto eq "icmp" and ip.dst in $internal_routers and ( (icmp.type eq 0 or icmp.type eq 3) or (icmp.type eq 11) or (icmp.type eq 8) )` |
| 89 | +**Action**: Allow |
| 90 | + |
| 91 | +**Rule ID**: 2 |
| 92 | +**Description**: Block all other traffic destined to these IP addresses |
| 93 | +**Match**: `ip.dst in $internal_routers` |
| 94 | +**Action**: Block |
| 95 | + |
| 96 | +## Web Servers |
| 97 | + |
| 98 | +Web servers require careful consideration of necessary traffic flows. Traffic for the **web server** functionality is required in addition to traffic flows where the web server is acting as a client. |
| 99 | + |
| 100 | +Where possible, permit the required destination IP addresses and ports for web servers and block everything else. Additional services, for example NTP/DNS, may be required along with the ports for the web traffic. |
| 101 | + |
| 102 | +The following is an example of suggested rules, but you should only make changes based on your specific requirements. For example, if you are not proxied by Cloudflare Layer 7 protection and you expect traffic sourced from the web towards your web servers: |
| 103 | + |
| 104 | +1. Create [an IP list](/waf/tools/lists/custom-lists/#ip-lists), **web servers** for example, to list IP addresses for your web servers. |
| 105 | +2. Permit traffic for the web server traffic inbound from the Internet. |
| 106 | +3. Permit traffic for the infrastructure or client traffic flows from the Internet, for example DNS and NTP. |
| 107 | +4. Block all other traffic destined for the web server IP addresses. |
| 108 | + |
| 109 | +### Suggested rules |
| 110 | + |
| 111 | +**Rule ID**: 1 |
| 112 | +**Description**: Allows inbound HTTP/S traffic from the Internet with SYN-only or ACK-only flag (not SYN/ACKs) |
| 113 | +**Match**: `ip.proto eq "tcp" and tcp.srcport in {32768..60999} and ip.dst in $web_servers and tcp.dstport in {80 443} and not (tcp.flags.syn and tcp.flags.ack)` |
| 114 | +**Action**: Allow |
| 115 | + |
| 116 | +**Rule ID**: 2 |
| 117 | +**Description**: Allows UDP replies for DNS and NTP to web servers |
| 118 | +**Match**: `ip.dst in $web_servers and ip.proto eq "udp" and udp.srcport in {53 123} and udp.dstport in {1024..65535}` |
| 119 | +**Action**: Allow if necessary but Disable if under attack |
| 120 | + |
| 121 | +**Rule ID**: 3 |
| 122 | +**Description**: Catch-all to block all other traffic destined for web server IP addresses |
| 123 | +**Match**: `ip.dst in $web_servers` |
| 124 | +**Action**: Block |
| 125 | + |
| 126 | +Alternatively, if you have Cloudflare Layer 7 protection, the Cloudflare Public IP addresses can be permitted as the source IP addresses to the destination IP addresses for the HTTP/HTTPS inbound traffic. This recommendation effectively replaces Rule 1 in the example above. |
| 127 | + |
| 128 | +For a list of Cloudflare's IP addresses, refer to [Cloudflare's IP addresses](https://www.cloudflare.com/ips/). |
| 129 | + |
| 130 | +### Suggested rules for Cloudflare proxied traffic |
| 131 | + |
| 132 | +**Description**: Allow inbound HTTP/S traffic from Cloudflare with SYN or ACK |
| 133 | +**Match**: `ip.proto eq "tcp" and ip.dst in $web_servers and tcp.dstport in {80 443} and not (tcp.flags.syn and tcp.flags.ack) and ip.src in {173.245.48.0/20 103.21.244.0/22 103.22.200.0/22 103.31.4.0/22 141.101.64.0/18 108.162.192.0/18 190.93.240.0/20 188.114.96.0/20 197.234.240.0/22 198.41.128.0/17 162.158.0.0/15 104.16.0.0/13 104.24.0.0/14 172.64.0.0/13 131.0.72.0/22}` |
| 134 | +**Action**: Allow |
| 135 | + |
| 136 | +## Non-web servers |
| 137 | + |
| 138 | +Restrict the source based on whether the server is expecting traffic from the general Internet or from only specific users. |
| 139 | + |
| 140 | +1. Apply rules based on source IP or ports if possible. |
| 141 | +2. Restrict permitted destination ports to only those that are required. |
| 142 | +3. Block incoming SYN to the closed ports. |
| 143 | + |
| 144 | +### Suggested rules |
| 145 | + |
| 146 | +- `IP Destination Address { non-web server } and TCP dst port in \<valid ports> — Permit` |
| 147 | +- `IP Destination Address { non-web server } and UDP dst port in \<valid ports> — Permit` |
| 148 | +- `IP Destination Address { web server } — Block` |
0 commit comments