面向 Cloudflare Turnstile / Challenge 的多方案研究与授权测试工具集,支持 Mac / Windows / Linux。
本项目仅供学习研究与已授权的自动化测试使用。使用时须遵守当地法律法规及目标站点服务条款。
2025–2026 年 Cloudflare 检测已分层:网络信誉、TLS/HTTP 指纹、JS Challenge、Turnstile 交互,以及自动化协议特征。单靠 HTTP 客户端无法完成 Turnstile。
本仓库提供 5 套可运行方案 与 1 个类封装入口,覆盖单会话研究、批量任务、纯 CDP 控制,以及浏览器解出后的 TLS 层会话复用。
开源场景下更稳妥的基线:
有头真实 Chrome
+ 可选住宅或高质量出口 IP
+ UC 断连重连 或 纯 CDP
+ 需要交互时使用操作系统级点击
不建议作为 Turnstile 主路径:
真无头模式硬刚 Managed Turnstile
纯 curl_cffi / tls-client 直打 Turnstile
单独依赖 playwright-stealth 作为“一键方案”
| 限制 | 说明 |
|---|---|
| 无 JS 运行时 | 无法完成 Turnstile / 新版 Challenge PoW |
| 无 DOM / Web API | 缺少 navigator、WebGL、canvas 信号 |
| 无交互能力 | Managed 模式需要真实点击复选框 |
| TLS 只是其中一个信号 | 仅匹配 JA3/JA4 并不足够 |
| 项目 | 要求 |
|---|---|
| Python | 3.9+ |
Python 依赖见 requirements.txt(含 SeleniumBase、nodriver、curl_cffi、OpenCV headless、pyvirtualdisplay 等)。
git clone https://github.com/1837620622/cloudflare-bypass-2026.git
cd cloudflare-bypass-2026
pip install -r requirements.txt
请先安装 Google Chrome,再运行浏览器方案。
git clone https://github.com/1837620622/cloudflare-bypass-2026.git
cd cloudflare-bypass-2026
sudo bash install_linux.sh
手动安装:
sudo apt-get update
sudo apt-get install -y xvfb libglib2.0-0 libnss3 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libxkbcommon0 libgbm1 libasound2
python3 -m pip install -r requirements.txt
说明
# Install dependencies / 安装依赖
pip install -r requirements.txt
# Method 1 — UC Mode (recommended default) / 方案1 默认推荐
python bypass.py https://example.com
python bypass.py https://example.com -p http://127.0.0.1:7890 -t 90
# Method 5 — CDP Mode / 方案5 CDP
python bypass_cdp.py https://example.com
# Method 3 — nodriver / 方案3
python bypass_nodriver.py https://example.com
请将示例 URL 替换为你有权测试的目标地址。
bypass.py(默认)单浏览器 UC 模式:断连打开页面,并在检测到挑战时进行系统级点击。
python bypass.py https://example.com
python bypass.py https://example.com -p http://127.0.0.1:7890
python bypass.py https://example.com -t 90 --incognito
simple_bypass.py适用于多代理或多浏览器批处理。操作系统级点击在同一桌面上不具备多窗口安全;并行时可能互相干扰。
python simple_bypass.py https://example.com
python simple_bypass.py https://example.com -r -f proxy.txt -c
python simple_bypass.py https://example.com -P -b 3 -t 30 -n 5 -c
bypass_nodriver.py无 chromedriver 的 CDP 控制。挑战点击使用 verify_cf()(OpenCV 模板匹配)。上游许可证为 AGPL-3.0。
pip install "nodriver>=0.50.0" opencv-python-headless
python bypass_nodriver.py https://example.com
python bypass_nodriver.py https://example.com -p http://127.0.0.1:7890
闭源商用分发 AGPL 组件前请自行完成合规评估。
bypass_curl_cffi.py(不适用于 Turnstile)仅 HTTP/TLS 指纹仿冒。适用于低防护或旧版 Challenge,或在 UA 与出口 IP 一致 的前提下复用浏览器解出的 Cookie。
python bypass_curl_cffi.py https://example.com
python bypass_curl_cffi.py https://example.com -f chrome146
python bypass_curl_cffi.py https://example.com -p http://127.0.0.1:7890
常用指纹包括:chrome120、chrome124、chrome131、chrome136、chrome142、chrome146、firefox135、firefox144、safari17_0、safari18_0、edge101。
bypass_cdp.pySeleniumBase CDP 模式:优先 solve_captcha(),失败时回退 gui_click_captcha()。2026 年与 UC 并列的升级路径。
python bypass_cdp.py https://example.com
python bypass_cdp.py https://example.com -p http://127.0.0.1:7890 -t 90
| 参数 | 说明 | 默认 |
|---|---|---|
-p, --proxy |
bypass_seleniumbase.py面向对象的 UC 封装,便于嵌入更大工程。
python bypass_seleniumbase.py https://example.com -p http://127.0.0.1:7890
bypass.py)from bypass import bypass_cloudflare
result = bypass_cloudflare(
"https://example.com",
proxy="http://127.0.0.1:7890",
timeout=90,
save_cookies=True,
)
if result["success"]:
print(result["cf_clearance"])
print(result["user_agent"])
print(result["cookies"])
else:
print(result["error"])
bypass_seleniumbase.py)from bypass_seleniumbase import bypass_and_get_cookies
result = bypass_and_get_cookies(
"https://example.com",
proxy="http://127.0.0.1:7890",
session_name="demo",
)
if result["success"]:
print(result["cf_clearance"])
from bypass_nodriver import bypass_sync
result = bypass_sync("https://example.com", timeout=60.0)
from bypass_curl_cffi import bypass_cloudflare_http
# Optional: reuse browser-solved cookies
result = bypass_cloudflare_http(
"https://example.com",
fingerprint="chrome146",
cookies={"cf_clearance": "..."}, # optional
)
文件:proxy.txt,每行一个代理:
127.0.0.1:7890
http://127.0.0.1:7890
socks5://127.0.0.1:1080
http://user:pass@host:port
绝大多数免费公共代理无法稳定支持 HTTPS 隧道。研究与生产环境请使用经验证的住宅或高质量代理。
启用保存时,Cookie 写入 output/cookies/。
JSON 示例
{
"url": "https://example.com",
"cookies": {
"cf_clearance": "..."
},
"user_agent": "Mozilla/5.0 ...",
"timestamp": "20260714_120000",
"method": "seleniumbase_uc"
}
cf_clearance 常与 IP + User-Agent 绑定。更换任一端通常需要重新求解。
cloudflare-bypass-2026/
├── bypass.py # Method 1: SeleniumBase UC (default)
├── simple_bypass.py # Method 2: parallel + proxy rotation
├── bypass_nodriver.py # Method 3: nodriver CDP
├── bypass_curl_cffi.py # Method 4: TLS fingerprint (non-Turnstile)
├── bypass_cdp.py # Method 5: SeleniumBase CDP Mode
├── bypass_seleniumbase.py # UC class wrapper
├── install_linux.sh # Linux bootstrap
├── requirements.txt # Python dependencies
├── proxy.txt # Sample proxy list
├── LICENSE
├── README.md
└── output/ # Runtime cookie exports (created on use)
优先使用哪个方案?
优先 bypass.py 或 bypass_cdp.py。需要无 chromedriver 的 CDP 时用 bypass_nodriver.py。批量与代理轮换用 simple_bypass.py。Turnstile 不要使用 bypass_curl_cffi.py。
为什么避免真无头模式?
无头自动化特征更容易被识别。无桌面的 Linux 请使用 Xvfb / 虚拟显示,而不是 Chrome 真无头。
cf_clearance 有效期多久?
通常数十分钟到数小时,取决于站点策略;常与 IP、UA 绑定,换代理后往往需要重解。
Linux 报 X11 / display 失败
sudo bash install_linux.sh
# or / 或
sudo apt-get install -y xvfb
pip install pyvirtualdisplay
代理不可用
确认代理支持 HTTPS CONNECT 与鉴权。公开免费列表对本场景大多不可用。
nodriver 提示缺少 OpenCV
pip install opencv-python-headless
是否存在通杀方案?
没有。防御持续演进。结果取决于目标配置、出口信誉、浏览器还原度与时机。本工具不宣称通杀。
欢迎洽谈赞助展示、定制开发与技术咨询。
| 渠道 | 联系方式 |
|---|---|
| 微信 | 1837620622 (传康Kk) |
| 邮箱 | [email protected] |
| Xianyu / Bilibili | 万能程序员 |
请优先微信联系,并备注「商务合作」。
LICENSE)。如果本项目对你有帮助,欢迎 Star 支持。
| 参考资料 |
| Business | 商务合作 |
| License | 许可证 |
| # | 脚本 | 策略 | Turnstile | 适用场景 |
|---|
| 1 | bypass.py | SeleniumBase UC Mode | 是 | 默认单会话主路径 |
| 2 | simple_bypass.py | UC + 并行 / 代理轮换 | 是 | 批量任务;并行时可能争抢系统鼠标 |
| 3 | bypass_nodriver.py | nodriver 纯 CDP | 是 | 无 chromedriver;需 OpenCV;注意 AGPL |
| 4 | bypass_curl_cffi.py | TLS 指纹 / Cookie 复用 | 否 | 仅旧版 Challenge 或 Cookie 复用 |
| 5 | bypass_cdp.py | SeleniumBase CDP Mode | 是 | UC 后继路径 |
| — | bypass_seleniumbase.py | UC 类封装 | 是 | 可 import 的二次开发封装 |
| 优先级 | 选择 | 说明 |
|---|
| 1 | bypass.py 或 bypass_cdp.py | 主入口 |
| 2 | bypass_nodriver.py | 强备选;注意许可证 |
| 3 | simple_bypass.py | 吞吐与轮换;GUI 点击宜串行 |
| 4 | 浏览器解出后复用 curl_cffi | 须保持 UA 与出口 IP 一致 |
| 避免 | 纯 HTTP 直打 Turnstile | 无法执行 JS / 交互 |
| 功能 | 说明 |
|---|
| SeleniumBase UC 模式 | 驱动断连重连 + 操作系统级验证码点击 |
| SeleniumBase CDP 模式 | 纯 CDP 路径,减少 WebDriver 附加特征 |
| nodriver CDP | 无需 chromedriver;verify_cf() 模板点击(OpenCV) |
| 并行 / 代理轮换 | simple_bypass.py 中的批量任务与代理文件轮换 |
| 超时控制 | 主流程端到端超时 |
| Cookie 导出 | 按需导出 JSON 与 Netscape 格式 |
| 跨平台 | macOS、Windows、Linux(Linux 无头主机需 Xvfb) |
| 浏览器 |
| Google Chrome(非 amd64 Linux 使用 Chromium) |
| 显示环境 | 优先有头 GUI;Linux 服务器:Xvfb / 虚拟显示 |
| 操作系统 | macOS、Windows、Linux |
| 可选代理 | 支持 HTTPS CONNECT 的 HTTP / HTTPS / SOCKS5 代理 |
| 参数 | 说明 | 默认 |
|---|
url | 目标 URL | 必填 |
-p, --proxy | 代理地址 | 无 |
-t, --timeout | 总超时秒数 | 60 |
-r, --reconnect | 断连秒数 | 5 |
--incognito | 无痕模式 | 关闭 |
--no-save | 不保存 Cookie | 关闭 |
| 参数 | 说明 | 默认 |
|---|
-p, --proxy | 固定代理 | 无 |
-f, --proxy-file | 代理列表文件 | proxy.txt |
-r, --rotate | 顺序轮换 | 关闭 |
-P, --parallel | 并行浏览器 | 关闭 |
-b, --batch | 每批浏览器数 | 3 |
-t, --timeout | 超时秒数 | 60 |
-n, --retries | 批次数或代理尝试数 | 3 |
-c, --check-proxy | 代理存活预检 | 关闭 |
-w, --wait | 页面等待 / 重连等待 | 5 |
--no-save | 不保存 Cookie | 关闭 |
| 参数 | 说明 | 默认 |
|---|
-p, --proxy | 代理 | 无 |
-t, --timeout | 总超时 | 60 |
--headless | 无头(不推荐) | 关闭 |
--no-save | 不保存 Cookie | 关闭 |
| 参数 | 说明 | 默认 |
|---|
-p, --proxy | 代理 | 无 |
-f, --fingerprint | 指纹配置 | chrome136 |
-t, --timeout | 请求超时 | 30 |
-n, --retries | 重试次数 | 3 |
--no-save | 不保存 Cookie | 关闭 |
| 代理 |
| 无 |
-t, --timeout | 总超时预算 | 60 |
--no-save | 不保存 Cookie | 关闭 |
| 字段 | 类型 | 含义 |
|---|
success | bool | 是否获得可用通过结果 |
cookies | dict | Cookie 字典 |
cf_clearance | str 或 None | 存在时的 Cloudflare clearance Cookie |
user_agent | str 或 None | 会话使用的浏览器 UA |
error | str 或 None | 失败原因 |
method | str | 方案标识 |
| 前缀 | 来源 |
|---|
cookies_*.json / cookies_*.txt | bypass.py, simple_bypass.py |
cookies_cdp_*.json | bypass_cdp.py |
cookies_nodriver_*.json / cookies_nodriver_*.txt | bypass_nodriver.py |
cookies_curl_*.json / cookies_curl_*.txt | bypass_curl_cffi.py |