# Uncovering CloudFlare

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)系列
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live) 上**关注**我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来**分享您的黑客技巧**。

</details>

## 揭示 Cloudflare 的常见技术

* 您可以使用一些服务来获取域的**历史 DNS 记录**。也许网页是在以前使用过的 IP 地址上运行的。
* 同样可以通过**检查历史 SSL 证书**来实现，这些证书可能指向原始 IP 地址。
* 还要检查**指向 IP 地址的其他子域的 DNS 记录**，因为可能其他子域指向同一服务器（也许是为了提供 FTP、邮件或任何其他服务）。
* 如果在 Web 应用程序中发现**SSRF**，则可以滥用它以获取服务器的 IP 地址。
* 在浏览器中搜索网页的唯一字符串，例如 shodan（也许还有 Google 和类似的搜索引擎）。也许您可以找到包含该内容的 IP 地址。
* 类似地，您可以使用工具搜索网站的 favicon 图标：<https://github.com/karma9874/CloudFlare-IP> 或 <https://github.com/pielco11/fav-up>
* 这种方法不太频繁地起作用，因为服务器在通过 IP 地址访问时必须发送相同的响应，但您永远不知道。

## 揭示 Cloudflare 的工具

* 在 <http://www.crimeflare.org:82/cfs.html> 或 <https://crimeflare.herokuapp.com> 中搜索域。或使用工具 [CloudPeler](https://github.com/zidansec/CloudPeler)（使用该 API）
* 在 <https://leaked.site/index.php?resolver/cloudflare.0/> 中搜索域
* [**CloudFlair**](https://github.com/christophetd/CloudFlair) 是一个工具，将使用包含域名的 Censys 证书进行搜索，然后在这些证书中搜索 IPv4，并最终尝试在这些 IP 地址上访问网页。
* [**CloakQuest3r**](https://github.com/spyboy-productions/CloakQuest3r)：CloakQuest3r 是一个强大的 Python 工具，精心设计用于揭示由 Cloudflare 和其他替代方案保护的网站的真实 IP 地址，这是一个广泛采用的 Web 安全和性能增强服务。其核心任务是准确识别隐藏在 Cloudflare 保护屏障后面的 Web 服务器的实际 IP 地址。
* [Censys](https://search.censys.io/)
* [Shodan](https://shodan.io/)
* [Bypass-firewalls-by-DNS-history](https://github.com/vincentcox/bypass-firewalls-by-DNS-history)
* 如果您有一组可能包含网页的 IP 地址，您可以使用 <https://github.com/hakluke/hakoriginfinder>。

```bash
# 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
```

## 从云基础设施中揭示 Cloudflare

请注意，即使这是针对 AWS 机器执行的，也可以针对任何其他云提供商执行。

有关此过程的更好描述，请查看：

{% embed url="<https://trickest.com/blog/cloudflare-bypass-discover-ip-addresses-aws/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

```bash
# 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
```

## 通过 Cloudflare 绕过 Cloudflare

### 验证的源拉取

这种机制依赖于**客户端 SSL 证书**来验证**Cloudflare 的反向代理**服务器和**源**服务器之间的连接，这被称为**mTLS**。

客户可以简单地使用 Cloudflare 的证书，而不是配置自己的证书，允许任何来自 Cloudflare 的连接，**无论租户如何**。

{% hint style="danger" %}
因此，攻击者可以简单地在 Cloudflare 中设置一个**域名，使用 Cloudflare 的证书并将其指向**受害者\*\*域名的 IP 地址。这样，设置他的域名完全不受保护，Cloudflare 将不会保护发送的请求。
{% endhint %}

更多信息[**在这里**](https://socradar.io/cloudflare-protection-bypass-vulnerability-on-threat-actors-radar/)。

### 允许 Cloudflare IP 地址列表

这将**拒绝不是来自 Cloudflare** IP 地址范围的连接。这也容易受到先前设置的攻击者只需**在 Cloudflare 中指向自己的域名**到**受害者的 IP**地址并对其进行攻击。

更多信息[**在这里**](https://socradar.io/cloudflare-protection-bypass-vulnerability-on-threat-actors-radar/)。

## 绕过 Cloudflare 进行抓取

### 缓存

有时您只想绕过 Cloudflare 来抓取网页。有一些选项：

* 使用 Google 缓存：`https://webcache.googleusercontent.com/search?q=cache:https://www.petsathome.com/shop/en/pets/dog`
* 使用其他缓存服务，如<https://archive.org/web/>

### 工具

一些工具，如以下工具，可以绕过（或曾经能够绕过）Cloudflare 对抓取的保护：

* <https://github.com/sarperavci/CloudflareBypassForScraping>

### Cloudflare 解决方案

已开发了许多 Cloudflare 解决方案：

* [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr)
* [cloudscraper](https://github.com/VeNoMouS/cloudscraper) [这里有指南](https://scrapeops.io/python-web-scraping-playbook/python-cloudscraper/)
* [cloudflare-scrape](https://github.com/Anorov/cloudflare-scrape)
* [CloudflareSolverRe](https://github.com/RyuzakiH/CloudflareSolverRe)
* [Cloudflare-IUAM-Solver](https://github.com/ninja-beans/cloudflare-iuam-solver)
* [cloudflare-bypass](https://github.com/devgianlu/cloudflare-bypass) \[已存档]
* [CloudflareSolverRe](https://github.com/RyuzakiH/CloudflareSolverRe)

### 加固的无头浏览器 <a href="#option-4-scrape-with-fortified-headless-browsers" id="option-4-scrape-with-fortified-headless-browsers"></a>

使用一个不被识别为自动化浏览器的无头浏览器（您可能需要为此进行定制）。一些选项包括：

* **Puppeteer：** [puppeteer](https://github.com/puppeteer/puppeteer)的[隐身插件](https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-stealth)。
* **Playwright：** [隐身插件](https://www.npmjs.com/package/playwright-stealth)即将推出 Playwright。请关注[这里](https://github.com/berstend/puppeteer-extra/issues/454)和[这里](https://github.com/berstend/puppeteer-extra/tree/master/packages/playwright-extra)的最新动态。
* **Selenium：** [undetected-chromedriver](https://github.com/ultrafunkamsterdam/undetected-chromedriver) 一个优化的 Selenium Chromedriver 补丁。

### 带有内置 Cloudflare 绕过功能的智能代理 <a href="#option-5-smart-proxy-with-cloudflare-built-in-bypass" id="option-5-smart-proxy-with-cloudflare-built-in-bypass"></a>

**智能代理**由专业公司持续更新，旨在规避 Cloudflare 的安全措施（因为这是他们的业务）。

其中一些是：

* [ScraperAPI](https://www.scraperapi.com/?fp_ref=scrapeops)
* [Scrapingbee](https://www.scrapingbee.com/?fpr=scrapeops)
* [Oxylabs](https://oxylabs.go2cloud.org/aff_c?offer_id=7\&aff_id=379\&url_id=32)
* [Smartproxy](https://prf.hn/click/camref:1100loxdG/\[p_id:1100l442001]/destination:https%3A%2F%2Fsmartproxy.com%2Fscraping%2Fweb) 以其专有的 Cloudflare 绕过机制而闻名。

对于寻求优化解决方案的人，[ScrapeOps 代理聚合器](https://scrapeops.io/proxy-aggregator/)脱颖而出。该服务将超过 20 个代理提供商集成到单个 API 中，自动选择最佳和最具成本效益的代理，从而为您的目标域提供了一个更优越的选项，以应对 Cloudflare 的防御措施。

### 反向工程 Cloudflare 反机器人保护 <a href="#option-6-reverse-engineer-cloudflare-anti-bot-protection" id="option-6-reverse-engineer-cloudflare-anti-bot-protection"></a>

反向工程 Cloudflare 的反机器人措施是智能代理提供商使用的一种策略，适用于大规模网页抓取，而无需运行许多无头浏览器的高成本。

**优势：** 该方法允许创建一个极其高效的绕过方式，专门针对 Cloudflare 的检查，非常适合大规模操作。

**劣势：** 缺点在于理解和欺骗 Cloudflare 故意模糊的反机器人系统所涉及的复杂性，需要不断努力测试不同策略并更新绕过方式，因为 Cloudflare 不断加强其保护措施。

在[原始文章](https://scrapeops.io/web-scraping-playbook/how-to-bypass-cloudflare/)中找到更多关于如何执行此操作的信息。

## 参考资料

* <https://scrapeops.io/web-scraping-playbook/how-to-bypass-cloudflare/>

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想在 HackTricks 中看到您的**公司广告**或**下载 PDF 版本的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)！
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFT**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord 群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)\*\* 上关注我们\*\*。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>
