如何识别 Cloudflare Turnstile
上方的方框是一个实时的 Cloudflare Turnstile 挑战。本页面展示三种简单方式来识别 Cloudflare Turnstile 并获取有效的 cf-turnstile-response token:使用 CapSkip 浏览器扩展自动识别、用 CapSkip SDK 在你自己的代码中识别,或将你的工具已经调用的验证码服务重新路由到 CapSkip。CapSkip 是一款快速、无限量的 Cloudflare Turnstile 识别工具,在你的设备上本地运行,因此没有按次付费,也没有任何数据离开你的机器。
方式一:使用浏览器扩展识别 Cloudflare Turnstile
绕过 Cloudflare Turnstile 最简单的方式是 CapSkip 验证码识别扩展 适用于 Chrome 和 Firefox。它会检测任意页面上的 Turnstile 小组件并在后台自动识别,无需编写代码,也无需复制 token。
安装扩展
从 Chrome 应用商店或 Firefox 附加组件添加 CapSkip。它同样适用于 Brave、Edge、Opera 和 Vivaldi。
运行 CapSkip 应用
安装并打开 CapSkip 桌面应用。它在你自己的设备上完成识别,并与扩展配对。
它会自动识别
重新加载本页面,CapSkip 就会为你通过 Turnstile。希望自己掌控?随时可切换到手动模式。
方式二:使用 CapSkip SDK 识别 Cloudflare Turnstile
在构建自动化、爬虫或机器人?使用 CapSkip 验证码识别 SDK 来识别 Cloudflare Turnstile,支持 Python, Node.js, PHP 或 C#。你传入本页面的 site key 和 URL,CapSkip 就会返回一个全新的 Turnstile token,你可以像真实 token 一样提交它。
0x4AAAAAADogn3t3_JKwKkgS
https://capskip.com/zh/captcha-demo/cloudflare-turnstile/
开始之前
CapSkip 在本地识别。下载并运行 CapSkip 桌面应用 并让它在后台保持打开。SDK 通过 127.0.0.1:8080与它通信,因此没有云端调用,也没有按次费用。
安装 SDK
将官方 CapSkip 客户端添加到你的项目中。
pip install capskipnpm install capskipcomposer require capskip/capskipdotnet add package CapSkip识别 Turnstile 并获取 token
传入本页的 sitekey 和 url 设置为 turnstile()。CapSkip 会返回一个新的 cf-turnstile-response token。
from capskip import CapSkip
# Connect to the CapSkip app running on your machine
solver = CapSkip(host="127.0.0.1", port=8080)
# Solve the Turnstile shown on this page
result = solver.turnstile(
sitekey="0x4AAAAAADogn3t3_JKwKkgS",
url="https://capskip.com/zh/captcha-demo/cloudflare-turnstile/",
)
token = result["code"] # the cf-turnstile-response token
print(token)const { CapSkip } = require('capskip');
// Connect to the CapSkip app running on your machine
const solver = new CapSkip({ host: '127.0.0.1', port: 8080 });
(async () => {
// Solve the Turnstile shown on this page
const result = await solver.turnstile(
'0x4AAAAAADogn3t3_JKwKkgS',
'https://capskip.com/zh/captcha-demo/cloudflare-turnstile/',
);
const token = result.code; // the cf-turnstile-response token
console.log(token);
})();<?php
require 'vendor/autoload.php';
use CapSkip\CapSkip;
// Connect to the CapSkip app running on your machine
$solver = new CapSkip(['host' => '127.0.0.1', 'port' => 8080]);
// Solve the Turnstile shown on this page
$result = $solver->turnstile(
'0x4AAAAAADogn3t3_JKwKkgS',
'https://capskip.com/zh/captcha-demo/cloudflare-turnstile/'
);
$token = $result['code']; // the cf-turnstile-response token
echo $token;using CapSkip;
// Connect to the CapSkip app running on your machine
var solver = new CapSkipClient(host: "127.0.0.1", port: 8080);
// Solve the Turnstile shown on this page
var result = await solver.TurnstileAsync(
"0x4AAAAAADogn3t3_JKwKkgS",
"https://capskip.com/zh/captcha-demo/cloudflare-turnstile/");
string token = result.Code; // the cf-turnstile-response token
Console.WriteLine(token);你会得到一个很长的 token,它以 1. 开头,对该 site key 有效,可直接提交。
使用 token
将 token 放入小组件隐藏的 cf-turnstile-response 字段中。有些页面也会从 g-recaptcha-response读取它。如果在 turnstile.render() 配置中定义了回调,则用该 token 运行它。然后提交表单,你的服务器会通过 Cloudflare siteverify 进行验证。请注意, 校验 本页面上的按钮会直接用 turnstile.getResponse()从小组件读取 token,因此它验证的是小组件自身的 token,而不是你放入字段中的 token。
// 1. Drop the solved token into the Turnstile response field
document.querySelector('[name="cf-turnstile-response"]').value = token;
// Some implementations also read it from g-recaptcha-response:
// document.querySelector('[name="g-recaptcha-response"]').value = token;
// 2. If a callback was defined in turnstile.render(), run it with the token
if (window.tsCallback) window.tsCallback(token);
// 3. ...then submit your form.Cloudflare Challenge 页面上的 Turnstile
有些站点完全置于 Cloudflare 之后,会在内容加载之前显示一个 Turnstile 挑战页面。这里你同样需要从 turnstile.render(): cData, chlPageData 和 action获取三个值。然后你用 CapSkip 返回的完全相同的 User-Agent 提交 token。
1. 拦截参数(在 Turnstile 加载之前注入这段代码)
// Override turnstile.render to capture the challenge parameters
const i = setInterval(() => {
if (window.turnstile) {
clearInterval(i);
window.turnstile.render = (container, params) => {
window.tsParams = {
sitekey: params.sitekey,
pageurl: window.location.href,
data: params.cData,
pagedata: params.chlPageData,
action: params.action,
};
window.tsCallback = params.callback; // call this with the solved token
console.log(JSON.stringify(window.tsParams));
return 'foo';
};
}
}, 50);2. 使用捕获的值进行识别,然后复用返回的 User-Agent
result = solver.turnstile(
sitekey="0x4AAAA...", # params.sitekey
url="https://the-protected-site.com/",
data="init_data...", # params.cData
pagedata="chl_page_data...", # params.chlPageData
)
token = result["code"]
user_agent = result["userAgent"] # submit the token with this exact User-Agentconst result = await solver.turnstile(
'0x4AAAA...', // params.sitekey
'https://the-protected-site.com/',
{ data: 'init_data...', pagedata: 'chl_page_data...' },
);
const token = result.code;
const userAgent = result.userAgent; // submit the token with this exact User-Agent$result = $solver->turnstile(
'0x4AAAA...', // params.sitekey
'https://the-protected-site.com/',
['data' => 'init_data...', 'pagedata' => 'chl_page_data...']
);
$token = $result['code'];
$userAgent = $result['userAgent']; // submit the token with this exact User-Agentvar result = await solver.TurnstileAsync(
"0x4AAAA...", // params.sitekey
"https://the-protected-site.com/",
new Dictionary<string, object?> { ["data"] = "init_data...", ["pagedata"] = "chl_page_data..." });
string token = result.Code;
string userAgent = result.UserAgent; // submit the token with this exact User-Agent原始 HTTP API 还接受一个可选的 action 值和一个 proxy,这在站点检查 token 是否从你自己的 IP 生成时很有用。
不使用 Python、Node.js、PHP 或 C#?这些 SDK 只是 CapSkip HTTP API 的封装(即标准的 由以下端点返回的验证码 ID: / res.php 端点),因此你可以从 任何语言、框架或工具识别 reCAPTCHA v2。参见 Turnstile API 参考.
选项 3:将你现有的识别服务代码发送到 CapSkip
已经在通过按次付费的验证码服务(例如 2Captcha, Anti-Captcha 或 CapMonster)识别基于回调的 reCAPTCHA v2?你无需重写一行代码。CapSkip 应用包含一个 服务模拟器 ,它在本地讲这些服务自己的 API:选择你使用的服务,点击 添加到 hosts 文件,你的机器人、爬虫或现成工具已经发送给它的每个请求,都会由 CapSkip 在你自己的机器上响应,采用统一价格而非按次账单。
选择你的服务
打开 CapSkip 应用,选择你的代码已经在对接的服务:2Captcha、RuCaptcha、Anti-Captcha、CapMonster Cloud、CapSolver、DeathByCaptcha、SolveCaptcha 或 Captchas.io。
添加到 hosts 文件
在应用中一键将该服务的域名指向 CapSkip,于是你的工具发出的调用会在你自己的机器上得到响应,而不是发往付费 API。
原样运行你的工具
相同的 API key、相同的请求、相同的轮询循环。CapSkip 以该服务自身的格式回复,你的代码会得到一个有效的 cf-turnstile-response token。
切换后,下面的内容不会有任何变化。这与你的代码今天发出的调用完全相同,只不过现在 Cloudflare Turnstile 在本地识别,并且一个有效的 cf-turnstile-response token 会从 CapSkip 返回:
POST https://2captcha.com/in.php
key=YOUR_EXISTING_API_KEY
method=turnstile
sitekey=0x4AAAAAADogn3t3_JKwKkgS
pageurl=https://capskip.com/zh/captcha-demo/cloudflare-turnstile/
GET https://2captcha.com/res.php?key=YOUR_EXISTING_API_KEY&action=get&id=2122988149
OK|0.sBQmB… the cf-turnstile-response token, solved by CapSkip客户端库同样如此:Anti-Captcha 风格的 createTask / getTaskResult 配对,或任何基于这些服务构建的封装,在模拟器开启后都能继续工作。完整的请求和响应参考见 CapSkip API 文档.
关于识别 Cloudflare Turnstile 的更多内容
针对人们通常与此演示搭配使用的工具和语言的指南。
关于本 Cloudflare Turnstile 演示
本页是一个实时的 Cloudflare Turnstile 演示 在这里你可以测试 Cloudflare Turnstile 的工作原理,并实时观看它被识别的过程。Turnstile 是 Cloudflare 推出的现代验证码,也是 reCAPTCHA 的替代方案,它通过浏览器和行为信号来验证访问者,通常无需点击任何谜题。用它来探索 Turnstile token 的生成、 cf-turnstile-response 值,以及网站用来保护表单、登录和注册免受垃圾信息、滥用和机器人侵害的验证流程。
开发者、测试人员和自动化工程师可以使用这个 Cloudflare Turnstile 测试页面来检查集成、验证配置,并对 CapSkip 识别 Turnstile 的速度进行基准测试。无论你需要识别一次 Cloudflare Turnstile 还是自动化数千次识别,CapSkip 都是一款 Cloudflare Turnstile 识别 ,它有三种工作方式:面向 Chrome 和 Firefox 的免代码 验证码识别扩展 ,面向 Python、Node.js、PHP 和 C# 的 验证码识别 SDK ,以及对你今天可能按次付费的验证码服务的即插即用模拟,全部以统一价格无限量识别。三者都由同一个桌面 AI 验证码识别工具驱动,安装一次即可在你自己的机器上运行,因此没有任何内容在远程服务器排队,也没有任何按次计费。
