All content posted on this blog is solely the responsibility and perspective of the author. This site is not endorsed or supported by any commercial entity.
Auto Draft
In previous posts, I have mentioned how I am using CloudFlare\’sFlexible SSL to help secure this site. From those posts you will remember that Flexible SSL means that your browsing session is encrypted between your browser and CloudFlare but possibly not encrypted between CloudFlare and the actual server which holds the data. This causes the data flow to look like:
Auto Draft
In the case of this web-site, for example, Blogger does not support HTTPS on custom domains, so the HTTP connection shown above exists here as well.
NOTE: As mentioned earlier, this site does not contain any personal information or allow anyone to login. Therefore the underlying HTTP connection is of no security consequence. If you can hack into this site, I encourage you to submit a report to the Google Bug Bounty program and get paid for your discovery.
Those of us that understand networking can see from above that it should be possible to bypass CloudFlare and get directly to the unencrypted HTTP port on the Apache server. This is indeed true if you can determine the actual IP address of the Apache server.
This could potentially be a security hole that needs to be patched. Fortunately, through the magic of scripting and the Uncomplicated Firewall (UFW) or any other firewall, we can shutdown this hole.
If you are running on a Linux server, take a look at this little script I have put together. The basic flow of this script is to:
1) Download a list of known CloudFlare IP addresses – provided by CloudFlare
2) Parse each entry into a UFW command to permit access from CloudFlare to a specific port
The results of this script are that the Apache server will only accept connections coming from the CloudFlare network. This does not encrypt the connection between CloudFlare and your Apache server, but it does prevent anyone from bypassing CloudFlare.
Here is the script:
#!/bin/bash
function to_int {
local -i num=”10#${1}”
echo “${num}”
}
function port_is_ok {
local port=”$1″
local -i port_num=$(to_int “${port}” 2>/dev/null)
if (( $port_num < 1 || $port_num > 65535 )) ; then
echo “*** ${port} is not a valid port” 1>&2
port_is_ok=0
return 0
fi
#echo \’ok\’
port_is_ok=1
return 1
}
function addRules {
for a in `curl -s https://www.cloudflare.com/ips-v4`
do
#echo ufw allow to any port $PORT proto tcp from $a
ufw allow to any port $PORT proto tcp from $a
done
}
function removeRules {
for a in `ufw status numbered | grep $PORT/tcp | cut -c45-`
do
#echo ufw –force delete allow to any port $PORT proto tcp from $a
ufw –force delete allow to any port $PORT proto tcp from $a
done
}
if [ “`whoami`” != “root” ]; then
echo ABORT: This script must be run as root
exit 1
fi
port_is_ok $2
#echo $port_is_ok
if [ $port_is_ok -eq 0 ]; then
echo “Usage: $0 ”
exit 0
fi
PORT=$2
case “$1” in
“add”)
addRules
;;
“remove”)
removeRules
;;
“refresh”)
removeRules
addRules
;;
*)
echo “ABORT: Usage $0 ”
exit 1
;;
esac
You can see from the “usage” line, that the command format for this script is:
Usage:
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.