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]
- Headers should be set accordingly, including
refererandorigin - Headless browsers should be modified to become "undetectable"
- Base URL:
/cdn-cgi/challenge-platform/h/bOR/cdn-cgi/challenge-platform/h/g - The first request is
GETtoBASEURL/orchestrate/chl_page/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
POSTtoBASEURL/flow/ov1/${unknown_here}:${unix_epoch}:${unknown_here}/${ray-id}/${cf-challenge-id}with the POST data ofv_${rayid}:encoded information for the challengeand headercf-challenge.- The request replies with header
Cf-Chl-Gen.
- The request replies with header
- The third request is
GETtohttps://challenges.cloudflare.com/{BASEURL}/turnstile/if/ov2/av0/unknown/0/unknown/unknown/theme(dark)/normal- For Turnstile captcha challenge
- The fourth request is
POSTto 2nd URL- This replies with
Cf-Chl-Genheader
- This replies with
- The fifth and sixths request is
POSTto:- 5th:
https://challenges.cloudflare.com/{BASEURL}/flow/ov1/${unknown_here}:${unix_epoch}:${unknown_here}/${ray-id}/${cf-challenge-id}with the POST data ofv_${rayid}:encoded information for the challengeand headerCf-Challenge. - 6th:
https://DOMAIN/{BASEURL}/flow/ov1/${unknown_here}:${unix_epoch}:${unknown_here}/${ray-id}/${cf-challenge-id}with the POST data ofv_${rayid}:encoded information for the challengeand headerCf-Challenge. - These both include the referer header of the turnstile URL
- 5th:
- The final request is
POSTto 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_clearancecookie.
Please be aware there is an unknown timeout (60+ seconds) for turnstile captcha in which clearance is automatically granted!!
- 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:
-
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))