repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
uncovering-cloudflare.mdMarkdown201 lines14.6 KiBsource raw download

title: "Uncovering CloudFlare" section: "Network Services" sectionSlug: "network-services-pentesting" sourcePath: "src/network-services-pentesting/pentesting-web/uncovering-cloudflare.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/uncovering-cloudflare.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Uncovering CloudFlare#

Common Techniques to Uncover Cloudflare#

For more recon pivots around favicon hashes, CT logs, passive DNS and related-domain discovery:

Readme

Tools to uncover Cloudflare#

# Install and run CF-Hero with extra data sources enabled
# API keys are configured in ~/.config/cf-hero.yaml

go install -v github.com/musana/cf-hero/cmd/cf-hero@latest
cf-hero -f domains.txt -shodan -censys -securitytrails -title "Target title"

Fast validation of candidate origins#

TARGET=target.com
IP=1.2.3.4

# Send the real hostname in SNI + Host and inspect headers/body
curl -sk --resolve ${TARGET}:443:${IP} https://${TARGET}/ -D - -o /tmp/${TARGET}.body

# Compare the certificate directly exposed by the candidate IP
openssl s_client -connect ${IP}:443 -servername ${TARGET} </dev/null \
  | openssl x509 -noout -subject -issuer -ext subjectAltName
# You can check if the tool is working with
prips 1.0.0.0/30 | hakoriginfinder -h one.one.one.one

# If you know the company is using AWS you could use the previous tool to search the
# web page inside the EC2 IPs
DOMAIN=something.com
WIDE_REGION=us
for ir in `curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="EC2") | select(.region|test("^us")) | .ip_prefix'`; do
    echo "Checking $ir"
    prips $ir | hakoriginfinder -h "$DOMAIN"
done

Uncovering Cloudflare from Cloud infrastructure#

Note that even if this was done for AWS machines, it could be done for any other cloud provider.

For a better description of this process check:

?Utm Campaign=Hacktrics&Utm Medium=Banner&Utm Source=Hacktricks

# Find open ports
sudo masscan --max-rate 10000 -p80,443 $(curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="EC2") | .ip_prefix' | tr '\n' ' ') | grep "open"  > all_open.txt
# Format results
cat all_open.txt | sed 's,.*port \(.*\)/tcp on \(.*\),\2:\1,' | tr -d " " > all_open_formated.txt
# Search actual web pages
httpx -silent -threads 200 -l all_open_formated.txt -random-agent -follow-redirects -json -no-color -o webs.json
# Format web results and remove eternal redirects
cat webs.json | jq -r "select((.failed==false) and (.chain_status_codes | length) < 9) | .url" | sort -u > aws_webs.json

# Search via Host header
httpx -json -no-color -list aws_webs.json -header Host: cloudflare.malwareworld.com -threads 250 -random-agent -follow-redirects -o web_checks.json

Bypassing Cloudflare through Cloudflare#

Authenticated Origin Pulls#

This mechanism relies on client SSL certificates to authenticate connections between Cloudflare’s reverse-proxy servers and the origin server, which is called mTLS.[1]

Cloudflare supports global, zone-level, and per-hostname AOP. The important detail for attackers is that global AOP uses a Cloudflare-provided certificate shared across all Cloudflare accounts, so it only proves that the request came from the Cloudflare network, not from the victim's specific zone.[2]

[!CAUTION] Therefore, if the victim trusts the global/shared AOP certificate, an attacker can just place their own domain in Cloudflare, point it to the victim origin IP, and send traffic from Cloudflare to the victim while bypassing the victim's hostname-specific WAF/bot/rate-limit setup.

This is specially interesting when the target only verifies "is this request coming from Cloudflare?" instead of "is this request coming from my Cloudflare configuration?".[2]

Allowlist Cloudflare IP Addresses#

This will reject connections that do not originate from Cloudflare's IP address ranges. However, this is vulnerable to the previous setup too: an attacker can proxy traffic through their own Cloudflare tenant and still reach the victim from a valid Cloudflare source IP.[2]

If you have the origin IP, test both situations:

Cloudflare-managed alternate hostnames#

Sometimes you will not discover the origin IP, but you can still reach the application through Cloudflare-owned hostnames that the target forgot to disable:

This does not reveal the origin IP, but it can bypass hostname-specific WAF, Access, caching, or rate-limit rules that were only tuned for the vanity domain. If you see any of these names leaked in JavaScript, source maps, CSP headers, CI logs, screenshots or public repos, hit them directly and compare the behavior with the main domain.

Bypass Cloudflare for scraping#

Cache#

Sometimes you just want to bypass Cloudflare to only scrape the web page. There are some options for this:[3]

Tools#

Some tools like the following ones can bypass (or were able to bypass) Cloudflare's protection against scraping:

Cloudflare Solvers#

There have been a number of Cloudflare solvers developed:

Fortified Headless Browsers #

Use a headless browser that isn't detected as an automated browser (you might need to customize it for that). Some options are:

Smart Proxy With Cloudflare Built-In Bypass #

Smart proxies proxies are continuously updated by specialized companies, aiming to outmaneuver Cloudflare's security measures (as thats their business).

Som of them are:

For those seeking an optimized solution, the ScrapeOps Proxy Aggregator stands out. This service integrates over 20 proxy providers into a single API, automatically selecting the best and most cost-effective proxy for your target domains, thus offering a superior option for navigating Cloudflare's defenses.

Reverse Engineer Cloudflare Anti-Bot Protection #

Reverse engineering Cloudflare's anti-bot measures is a tactic used by smart proxy providers, suitable for extensive web scraping without the high cost of running many headless browsers.

Advantages: This method allows for the creation of an extremely efficient bypass that specifically targets Cloudflare's checks, ideal for large-scale operations.

Disadvantages: The downside is the complexity involved in understanding and deceiving Cloudflare's deliberately obscure anti-bot system, requiring ongoing effort to test different strategies and update the bypass as Cloudflare enhances its protections.

Find more info about how to do this in the original article.[3]

References#