CloudFlare for IP Address Filtering

Filter IP addresses for common security solutions

TLDR:

Short blog post documenting steps to quickly block IP addresses for cybersecurity SaaS solutions which perform scanning and sandboxing analysis using CloudFlare's features.

Introduction, Background, or Why?

During Adversary Simulation projects, or even just Red Team Operations, we are often tasked try our best to 'penetrate' a target organization. The process of the 'penetration' provides the target organization with the benefit of being able to test their implemented cybersecurity controls and investments to see how well their People, Processes, and Technology can fend off an attack. To be able to perform such simulations, we need 'attack infrastructure'.

Different operators have their own way of deploying infrastructure. There are various sources documenting how to set up Attack Infrastructure. Jeff Dimmock has a documented Red Team Infrastructure Wiki over on GitHub[2]. Depending on how Attack Infrastructure is deployed, it can greatly aid or even harm an operation.

Security solutions have been getting better and a lot of innovation has been taking place in the space for cybersecurity products. During Red Team Operations we often see solutions such as E-mail Content Scanning, Link Scanning, Attachment Scanning, and various other types of automated analysis or sandboxing technology. To combat and prevent cybersecurity solutions which use a SaaS delivery model from being able to analyse our implants and phishing websites, Jason Lang (@curi0usjack) released a list of Bad IP addresses[1]. The community has also been contributing and adding more known Bad IP addresses for security vendors. This list has been referred to by many Red Teamers and is still effective and in use today.

The Bad IP Addresses list was previously deployed using .htaccess or iptables rules. However, there's been a common theme where a lot of Red Teams use LetsEncrypt - because it's free. Instead, CloudFlare offers free SSL certificates on front of your domains if you use their services. Not only does it provide accelerated content delivery due to their CDN, it can help you automate the SSL deployment process, and also provides a plethora of extended features. These features include Firewall Rules to restrict access to your origin servers.

Using CloudFlare Firewall Rules for IP Filtering

Steps to add Firewall Rules

TLDR: Create two firewall rules under CloudFlare to block a set of Bad IP addressess known for cybersecurity solutions.

1) Go to Firewall > Firewall Rules > Create a Firewall Rule

2) Put in a rule name for (1), then select 'IP Source Address' for (2), then change Operator to 'is in' for (3). Check that the Expression Preview (4) is as shown, then for the final action put 'Block' (5). Finally, click on 'edit expression' (6).

3) You will now have a blank expression to start inserting IP addresses as shown below:

From here, we can utilize the previously shared Bad IP list by Jason Lang, and stick it all in. I've formatted it into two separate expressions due to the size limitations of each expression.

Rule 1:

(ip.src in {3.0.0.0/16 3.112.0.0/16 3.120.0.0/16 3.16.0.0/16 3.40.0.0/16 3.8.0.0/16 3.80.0.0/12 3.82.0.0/16 3.89.0.0/16 8.34.0.0/16 8.35.0.0/16 13.0.0.0/8 18.130.0.0/15 18.132.0.0/14 18.144.0.0/12 18.160.0.0/11 18.192.0.0/11 18.224.0.0/12 18.240.0.0/13 18.248.0.0/14 18.252.0.0/15 20.184.0.0/16 20.185.0.0/16 20.186.0.0/16 20.187.0.0/16 20.188.0.0/16 20.189.0.0/16 20.190.0.0/16 20.191.0.0/16 20.36.0.0/16 20.37.0.0/16 20.38.0.0/16 20.39.0.0/16 20.40.0.0/16 20.41.0.0/16 20.42.0.0/16 20.43.0.0/16 20.44.0.0/16 23.100.0.0/16 23.101.0.0/16 23.102.0.0/16 23.103.0.0/16 23.20.0.0/16 23.249.49.0/24 23.249.50.0/24 23.249.51.0/24 23.249.52.0/24 23.249.53.0/24 23.249.54.0/24 23.249.55.0/24 23.96.0.0/16 23.97.0.0/16 23.98.0.0/16 23.99.0.0/16 27.0.0.0/16 34.0.0.0/8 35.0.0.0/8 35.153.0.0/16 35.154.0.0/15 35.156.0.0/14 35.160.0.0/12 35.176.0.0/14 35.180.0.0/15 35.182.0.0/16 40.112.0.0/16 40.113.0.0/16 40.114.0.0/16 40.115.0.0/16 40.116.0.0/16 40.117.0.0/16 40.118.0.0/16 40.119.0.0/16 40.121.0.0/16 40.122.0.0/16 40.123.0.0/16 40.124.0.0/16 40.125.0.0/16 40.126.0.0/16 40.127.0.0/16 40.64.0.0/16 40.65.0.0/16 40.66.0.0/16 40.67.0.0/16 40.68.0.0/16 40.69.0.0/16 40.70.0.0/16 40.71.0.0/16 40.74.0.0/16 40.75.0.0/16 40.76.0.0/16 40.77.0.0/16 40.78.0.0/16 40.79.0.0/16 40.80.0.0/16 40.81.0.0/16 40.82.0.0/16 40.83.0.0/16 40.84.0.0/16 40.85.0.0/16 40.86.0.0/16 40.87.0.0/16 40.88.0.0/16 40.89.0.0/16 40.90.0.0/16 40.91.0.0/16 41.74.192.0/21 41.74.200.0/23 41.74.202.0/24 41.74.203.0/24 41.74.204.0/22 46.137.0.0/16 46.51.0.0/16 50.112.0.0/16 50.16.0.0/16 50.18.0.0/16 50.19.0.0/16 51.104.0.0/16 51.105.0.0/16 51.136.0.0/16 51.137.0.0/16 51.140.0.0/16 51.141.0.0/16 51.142.0.0/16 51.143.0.0/16 51.144.0.0/16 51.145.0.0/16 51.163.158.0/23 52.0.0.0/8 54.0.0.0/8 62.140.10.0/24 62.140.7.0/24 63.128.21.0/24 63.245.192.0/23 63.245.204.0/24 63.245.205.0/24 63.245.206.0/24 63.32.0.0/16 64.235.144.0/24 64.252.0.0/16 64.4.0.0/16 64.74.215.0/24 65.154.226.0/24 65.197.254.0/24 65.201.134.0/24 65.52.0.0/16 65.54.0.0/16 65.55.0.0/16 66.93.208.240/28 67.202.0.0/16 67.219.240.0/23 67.219.242.0/23 67.219.244.0/23 67.219.246.0/23 67.219.248.0/23 67.219.250.0/23 67.219.252.0/23 67.231.144.0/24 67.231.145.0/24 67.231.146.0/24 67.231.147.0/24 67.231.148.0/24 67.231.149.0/24 67.231.151.0/24 67.231.158.0/24 70.132.0.0/16 70.37.0.0/16 70.42.131.0/24 71.152.0.0/16 72.21.0.0/16 72.44.0.0/16 72.5.231.0/24 72.5.65.0/24 74.201.127.0/24 74.217.90.0/24 75.101.0.0/16 79.125.0.0/16 84.33.17.128/25 85.115.60.0/24 87.238.0.0/16 89.38.150.0/24 91.199.104.0/24 91.212.136.0/24 91.220.42.0/24 92.0.0.0/8 93.0.0.0/8 94.0.0.0/8 94.245.0.0/16 95.0.0.0/8 95.183.244.0/24 95.45.252.0/29 96.0.0.0/8 96.127.0.0/16 96.45.32.0/20 96.45.32.0/21 96.45.40.0/21 97.0.0.0/8 98.0.0.0/8 99.0.0.0/8 99.79.0.0/16 99.80.0.0/16 99.82.0.0/16 99.84.0.0/16 99.86.0.0/16 100.20.0.0/16 100.24.0.0/16 103.13.69.0/24 103.246.0.0/16 103.4.0.0/16 103.8.0.0/16 103.96.20.0/22 104.129.204.0/24 104.208.0.0/16 104.209.0.0/16 104.210.0.0/16 104.211.0.0/16 104.214.0.0/16 104.215.0.0/16 104.40.0.0/13 104.40.0.0/16 104.41.0.0/16 104.42.0.0/16 104.43.0.0/16 104.44.0.0/16 104.45.0.0/16 104.46.0.0/16 104.47.0.0/16 107.20.0.0/16 107.23.0.0/16 111.221.0.0/16 122.248.0.0/16 124.47.150.0/24 124.47.189.0/24 131.253.0.0/16 134.170.0.0/16 137.116.0.0/16 137.117.0.0/16 137.135.0.0/16 138.91.0.0/16 143.127.10.0/23 143.127.100.0/24 143.127.102.0/24 143.127.103.0/24 143.127.119.0/24 143.127.136.0/24 143.127.138.0/24 143.127.139.0/24 143.127.14.0/23 143.127.2.0/24 143.127.241.0/24 143.127.242.0/23 143.127.87.0/24 143.127.89.0/24 143.127.93.0/24 143.204.0.0/16 146.101.76.0/23 146.101.78.0/24 148.163.148.0/22 148.163.156.0/23 150.70.0.0/22 150.70.104.0/22 150.70.110.0/24 150.70.112.0/20 150.70.12.0/22 150.70.160.0/20 150.70.176.0/20 150.70.192.0/21 150.70.224.0/20 150.70.240.0/20 150.70.31.0/24})

Rule 2:

(ip.src in {150.70.4.0/22 150.70.64.0/18 150.70.64.0/20 150.70.8.0/22 150.70.80.0/20 150.70.96.0/20 154.59.123.0/24 154.59.126.0/24 155.64.105.0/24 155.64.138.0/24 155.64.16.0/23 155.64.23.0/24 155.64.38.0/24 155.64.40.0/24 155.64.49.0/24 155.64.56.0/24 155.64.63.0/24 157.175.0.0/16 157.55.0.0/16 157.56.0.0/16 160.1.0.0/16 165.255.0.0/17 166.98.152.0/23 166.98.242.0/23 166.98.38.0/24 166.98.67.0/24 166.98.71.0/24 168.61.0.0/16 168.62.0.0/16 168.63.0.0/16 172.96.0.0/16 173.243.128.0/20 173.243.136.0/21 173.94.0.0/16 174.129.0.0/16 175.41.0.0/16 176.32.0.0/16 176.34.0.0/16 177.71.0.0/16 177.72.0.0/16 178.236.0.0/16 180.189.28.0/24 182.75.165.176/30 184.169.0.0/16 184.72.0.0/16 184.73.0.0/16 185.143.0.0/16 185.48.0.0/16 185.58.84.0/22 191.232.0.0/16 191.233.0.0/16 191.234.0.0/16 191.235.0.0/16 191.236.0.0/16 191.237.0.0/16 191.238.0.0/16 191.239.0.0/16 193.149.0.0/16 193.7.204.0/24 193.7.207.0/24 194.104.108.0/24 194.104.111.0/24 195.130.217.0/24 195.189.155.0/24 198.6.32.0/20 198.6.32.0/24 198.6.34.0/24 198.6.44.0/23 198.6.48.0/24 198.6.62.0/24 199.116.168.0/21 199.167.52.0/24 199.167.53.0/24 199.167.55.0/24 199.254.238.0/24 199.30.0.0/16 199.30.228.0/22 202.126.13.0/24 202.189.133.0/24 203.83.0.0/16 204.13.200.0/22 204.141.92.0/24 204.231.0.0/16 204.236.0.0/16 204.246.0.0/16 205.139.110.0/23 205.251.0.0/16 206.165.76.0/24 207.102.138.0/24 207.171.0.0/16 207.211.30.0/24 207.211.31.0/24 207.46.0.0/16 207.68.0.0/16 207.82.80.0/24 208.184.7.0/24 208.80.192.0/21 208.84.65.0/24 208.84.66.0/24 208.86.202.0/24 208.86.203.0/24 208.87.232.0/21 208.87.232.0/24 208.90.236.0/22 208.91.112.0/22 208.91.112.0/23 208.91.114.0/23 209.240.0.0/16 213.199.0.0/16 216.10.192.0/20 216.10.193.0/24 216.137.0.0/16 216.145.219.0/24 216.145.221.0/24 216.182.0.0/16 216.205.24.0/24 216.35.243.0/24 216.35.244.0/24 216.82.240.0/22 216.82.246.0/24 216.82.248.0/22 216.82.252.0/22})

4) After inserting the rule in respectively, you should get the following change in the UI by clicking 'use expression builder':

5) Now just scroll down to the bottom and click 'deploy':

6) Once the deployment is working, it will show up on the UI as shown below:

What it looks like when you're blocked

Using CloudFlare Firewall Rules to Block Bots

Steps to Enable 'Bot Fight' Mode

Navigate to Firewall > Bots, then enable it.

Currently have no clue as to what it really does, as I haven't botted enough to make it think I'm a Bot. However, I think that it can be made useful if there's internet wide scanners who are constantly scanning. CloudFlare's Threat Intel feeds will hopefully block or restrict those IP addresses and make it harder for those services to access your infrastructure.

Whitelisting CloudFlare on your Redirectors or Servers

To ensure that our origin doesn't get discovered, or directly attacked by the Blue Team, or the Cyber Threat Intelligence community, it is best to whitelist CloudFlare and block access to your origin server from any other locations. To do this, we can utilize iptables rules to allow only CloudFlare IP Address Ranges to TCP port 80 and 443.

TLDR: Use iptables to whitelist CloudFlare IP Address Ranges and default deny everything else.

IPTables Commands to Whitelist CloudFlare - only

for i in `curl https://www.cloudflare.com/ips-v4`; do iptables -I INPUT -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
for i in `curl https://www.cloudflare.com/ips-v6`; do ip6tables -I INPUT -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
iptables -A INPUT -p tcp -m multiport --dports http,https -j DROP
ip6tables -A INPUT -p tcp -m multiport --dports http,https -j DROP

Further Ideas

  • Community driven effort to identify IP address ranges used by various CTI providers.

  • Automatically block connections from Brand Protection related providers because many organizations are using these solutions. If the CTI provider cannot even load the webpage, perhaps there's less chance of a domain takedown.

References

[1] Jason Lang's Bad IP List: https://gist.githubusercontent.com/curi0usJack/971385e8334e189d93a6cb4671238b10/raw

[2] Jeff Dimmock's Red Team Infrastructure Wiki: https://github.com/bluscreenofjeff/Red-Team-Infrastructure-Wiki

Last updated