DEV Community

Cover image for Cloudflare captcha & Cloudflare Turnstile - how to solve!
2captcha
2captcha

Posted on • Updated on

Cloudflare captcha & Cloudflare Turnstile - how to solve!

We have a guide - How to solve Cloudflare captcha & Cloudflare Turnstile using API of our service here - guide - how bypass cloudflare turnstile

If you want you can read it there or - we write short instuction here:

Open developer's console in your browser and find element with data-sitekey attribute.

<div class="cf-turnstile" data-sitekey="0x4AAAAAAAC3DHQFLr1GavRN"></div>
Enter fullscreen mode Exit fullscreen mode

Make a POST request to https://2captcha.com/in.php with the following parameters:

  {
    "key": "YOUR_API_KEY",
    "method": "turnstile",
    "sitekey": "0x4AAAAAAAC3DHQFLr1GavRN",
    "pageurl": "${window.location.href}",
    "json": 1
  }
Enter fullscreen mode Exit fullscreen mode

If everything is fine server will return the ID of your captcha:

  {
    "status": 1,
    "request": "2122988149"
  }
Enter fullscreen mode Exit fullscreen mode

After 15-20 seconds send GET request to get the result.

GET https://2captcha.com/res.php?key=YOUR_API_KEY&action=get&id=2122988149&json=1
Enter fullscreen mode Exit fullscreen mode

If captcha is already solved server will respond with the answer token.

  {
    "status": 1,
    "request": "0.WoGeDojxQzHCCk023JRjfxv23olYh37jFdvPrcqmNeQ7PbSYIEuiBTK2SR_GdjfMitYEC23Gm7Vt93U1CPcI6aIFEhG-ffe1i9e6tIfIlYCFtb7OMxTB4tKCyTdpiaA.SP5YT77nuMNdOhZlvoBWAQ.da6448d22df7dd92f56a9fcf6d7138e5ee712bcf7d00c281f419b3bc091cbe64"
  }
Enter fullscreen mode Exit fullscreen mode

If captcha is not solved yet server will return CAPCHA_NOT_READY code. Repeat your request in 5 seconds. If something went wrong server will return an error code.

Use the token returned in your interaction with the target website. Normally the token is sent through the input with name="cf-turnstile-response" or, if reCAPTCHA compatibility mode is enabled, also in input with name="g-recaptcha-response". Also the token can be processed by a callback function defined in turnstile.render call or inside data-callback attribute.

Code examples:

php

$result = $solver->turnstile([
  'sitekey' => '0x4AAAAAAAChNiVJM_WtShFf',
  'url'     => 'https://ace.fusionist.io',
]);
Enter fullscreen mode Exit fullscreen mode

Python

result = solver.turnstile(sitekey='0x1AAAAAAAAkg0s2VIOD34y5', url='http://mysite.com/')
Enter fullscreen mode Exit fullscreen mode

Ruby

require 'api_2captcha'

client =  Api2Captcha.new("YOUR_API_KEY")

result = client.turnstile({
  sitekey: '0x1AAAAAAAAkg0s2VIOD34y5',
  pageurl: 'http://mysite.com/'
})
Enter fullscreen mode Exit fullscreen mode

You can use this examples, but don't forgot change API Key and URL.

Top comments (0)