cfresearch
This repository contains my research from Cloudflare's AntiDDoS, JS Challenge, Captcha Challenges, and Cloudflare WAF.
This was built for educational purposes such as learning how Cloudflare works, how to bypass Cloudflare challenges, and how to prevent attacks that are bypassing Cloudflare.
Location to Cloudflare Scripts - Credits to devgianlu
Other relevant Cloudflare projects [CloudProxy] [cfbypass]
Challenge information
- Headers should be set accordingly, including
referer
andorigin
- Headless browsers should be modified to become "undetectable"
Managed Challenge
- Base URL:
/cdn-cgi/challenge-platform/h/b
OR/cdn-cgi/challenge-platform/h/g
- The first request is
GET
toBASEURL/orchestrate/managed/v1?ray=${rayid}
- This replies with javascript to generate the challenege id and make the second request (to solve the challenge)
- The second request is
POST
toBASEURL/flow/ov1/${unknown_here}:${unix_epoch}:${unknown_here}/${ray-id}/${cf-challenge-id}
with the POST data ofv_${rayid}
:encoded information for the challenge
and headercf-challenge
.- The request replies with header
cf_chl_gen
.
- The request replies with header
- The third request is
GET
toBASEURL/img/${ray-id}/${unix_epoch}/unknown
.- The request replies with an image (possibly containing encoded information).
- The fourth request is
GET
toBASEURL/pat/${ray-id}/${unix_epoch}/unknown/unknown
- This replies with
www-authenticate
header
- This replies with
- The final request is
POST
to target url with POST DATA:md
: Analytic datash
: Challenge processingaw
: Challenge processingcf_ch_cp_return
:unknown|{"managed_clearance":"ni"}
- After sending the final request, you are given a new
cf_clearance
cookie.
Random Directory Attack
- Cloudflare cannot do much against this, but you can create a regexp that matches all URI on your website, and create a firewall rule to match them.
- (Example:
(http.request.full_uri matches "(\/)([a-z]){0,12}\w|(-)([a-z]){0,12}\w(\/)|([a-z]){0,12}\w")
)
- (Example:
Mitigating attacks
-
Cloudflare mitigate attacks at the edge, often utilizing turnstile (CAPTCHA-free challenge)
-
Attacks are mitigated at the edge (automatically) when:
- Request matches (D)DoS WAF rule (Managed, SSL/TLS, Layer 4 rules)
- Request matches user-defined rule (Firewall rule, IP/User-Agent Access rule)
- Request matches ratelimit rule
-
Attacks can be detected in the client-space then mitigated at the edge:
- Bot fight mode (Bot detection/if enabled)
- Page shield (if enabled)
- Managed challenge/JS Challenge/Legacy captcha
-
If attacks are not being mitigated by Cloudflare, consider the following:
- Implement rate-limiting where neccessary (Server-side processing (POST, PUT, DELETE requests))
- Rate-limiting on login handlers is vital (or other methods to protect spam)
- Return managed-challenges to ASNs registered as hosting.
- Implement caching when possible (static pages)
- Try Cloudflare's Railgun
- Railgun caches the parts of webpages that are unchanged on dynamic pages (HTML of user dashboard with user's personal metrics being changes (username, etc.))
- Try Cloudflare's Railgun
- Contact Cloudflare
- Implement rate-limiting where neccessary (Server-side processing (POST, PUT, DELETE requests))