Cloudflare Turnstile Bypass with 2Captcha

Solves Cloudflare Turnstile using 2Captcha

当前为 2025-04-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Cloudflare Turnstile Bypass with 2Captcha
  3. // @namespace http://yourdomain.com/
  4. // @version 1.0
  5. // @description Solves Cloudflare Turnstile using 2Captcha
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (async function () {
  11. 'use strict';
  12.  
  13. const API_KEY = '4429633d0beca8b7e7142514e2965e57'; // <-- আপনার 2Captcha API key
  14. const PAGE_URL = window.location.href;
  15.  
  16. function getSiteKey() {
  17. const iframe = document.querySelector('iframe[src*="turnstile"]');
  18. if (!iframe) return null;
  19.  
  20. const url = new URL(iframe.src);
  21. return url.searchParams.get('sitekey');
  22. }
  23.  
  24. const sitekey = getSiteKey();
  25. if (!sitekey) {
  26. console.log('No Turnstile found');
  27. return;
  28. }
  29.  
  30. console.log('Turnstile CAPTCHA found — requesting 2Captcha...');
  31.  
  32. // Step 1: Send CAPTCHA solve request
  33. const reqURL = `https://2captcha.com/in.php?key=${API_KEY}&method=turnstile&sitekey=${sitekey}&pageurl=${encodeURIComponent(PAGE_URL)}&json=1`;
  34. const req = await fetch(reqURL);
  35. const reqData = await req.json();
  36.  
  37. if (reqData.status !== 1) {
  38. console.error('2Captcha request failed:', reqData.request);
  39. return;
  40. }
  41.  
  42. const captchaId = reqData.request;
  43.  
  44. // Step 2: Poll result every 5 sec
  45. async function pollResult() {
  46. const res = await fetch(`https://2captcha.com/res.php?key=${API_KEY}&action=get&id=${captchaId}&json=1`);
  47. const resData = await res.json();
  48.  
  49. if (resData.status === 1) {
  50. return resData.request;
  51. } else if (resData.request === 'CAPCHA_NOT_READY') {
  52. console.log('Waiting for CAPTCHA solve...');
  53. await new Promise(r => setTimeout(r, 5000));
  54. return await pollResult();
  55. } else {
  56. console.error('2Captcha error:', resData.request);
  57. return null;
  58. }
  59. }
  60.  
  61. const token = await pollResult();
  62.  
  63. if (token) {
  64. console.log('CAPTCHA solved, token:', token);
  65. // Fill token to response field if found
  66. const input = document.querySelector('input[name="cf-turnstile-response"]');
  67. if (input) {
  68. input.value = token;
  69. const form = input.closest('form');
  70. if (form) {
  71. form.submit(); // Auto-submit if possible
  72. }
  73. } else {
  74. console.warn('No input field found for Turnstile response');
  75. }
  76. }
  77. })();
  78.  
  79.  
  80. const axios = require('axios');
  81.  
  82. // API Key from 2Captcha (আপনারটা এখানে বসান)
  83. const API_KEY = '4429633d0beca8b7e7142514e2965e57';
  84.  
  85. // CAPTCHA site key ও target URL (এগুলো আপনার পেজ অনুযায়ী বসাতে হবে)
  86. const SITE_KEY = 'YOUR_SITE_KEY_HERE';
  87. const PAGE_URL = 'https://example.com'; // যেই পেজে CAPTCHA আছে
  88.  
  89. // Step 1: CAPTCHA Solve Request পাঠানো
  90. async function requestCaptchaSolution() {
  91. try {
  92. const res = await axios.post('http://2captcha.com/in.php', null, {
  93. params: {
  94. key: API_KEY,
  95. method: 'turnstile', // যদি Turnstile হয়, নাহলে 'userrecaptcha'
  96. sitekey: SITE_KEY,
  97. pageurl: PAGE_URL,
  98. json: 1
  99. }
  100. });
  101.  
  102. if (res.data.status === 1) {
  103. console.log('Captcha ID:', res.data.request);
  104. return res.data.request;
  105. } else {
  106. throw new Error('CAPTCHA request failed: ' + res.data.request);
  107. }
  108. } catch (err) {
  109. console.error('Error requesting CAPTCHA:', err.message);
  110. }
  111. }
  112.  
  113. // Step 2: সলিউশন পাওয়ার জন্য Wait ও Poll করা
  114. async function getCaptchaResult(captchaId) {
  115. try {
  116. while (true) {
  117. const res = await axios.get('http://2captcha.com/res.php', {
  118. params: {
  119. key: API_KEY,
  120. action: 'get',
  121. id: captchaId,
  122. json: 1
  123. }
  124. });
  125.  
  126. if (res.data.status === 1) {
  127. console.log('CAPTCHA Solved:', res.data.request);
  128. return res.data.request;
  129. } else if (res.data.request === 'CAPCHA_NOT_READY') {
  130. console.log('Waiting for solution...');
  131. await new Promise(r => setTimeout(r, 5000));
  132. } else {
  133. throw new Error('Error getting CAPTCHA result: ' + res.data.request);
  134. }
  135. }
  136. } catch (err) {
  137. console.error('Error getting solution:', err.message);
  138. }
  139. }
  140.  
  141. // Full Flow
  142. (async () => {
  143. const captchaId = await requestCaptchaSolution();
  144. if (captchaId) {
  145. const solution = await getCaptchaResult(captchaId);
  146. console.log('\nUse this token in your request:', solution);
  147.  
  148. // এখানে আপনি এই টোকেন দিয়ে যেই রিকুয়েস্ট করবেন সেটি তৈরি করতে পারেন।
  149. }
  150. })();