Furry / 2captcha

A wrapper around the 2captcha api
71 stars 23 forks source link

Cloudflare Turnstile broken #46

Closed mayrsascha closed 3 months ago

mayrsascha commented 11 months ago

Trying to solve a CloudFlare turnstile captcha at https://dexscreener.com/new-pairs/24h

const solver = new Captcha.Solver("myapikey")
solver.turnstile("0x4AAAAAAADnPIDROrmt1Wwj", "https://dexscreener.com/new-pairs/24h")

gives

APIError: Some parameters are missing in this request. If you're using a pre-provided function, please open up an issue on the GitHub (https://github.com/furry/2captcha)

This API call is broken, it's the same if I fetch it manually via browser. I logged the exact API call that is being done inside the turnstile function: https://2captcha.com/in.php?key=myapikey&json=1&header_acao=1&soft_id=3316&method=turnstile&sitekey=0x4AAAAAAADnPIDROrmt1Wwj&pageurl=https%3A%2F%2Fdexscreener.com%2Fnew-pairs%2F24h

I'm not super familiar with Cloudflare Turnstile solving through 2captcha, but the API docs seem to know that some params are missing: https://2captcha.com/2captcha-api#turnstile . I'll keep trying to solve this on my own by using the third extra parameter and giving those params to the turnstile function, but some more guidance on this would be appreciated.

ivangrosse commented 9 months ago

Any update on this issue? I'm facing the same error when trying to solve a CloudFlare Turnstile captcha.

Site key: 0x4AAAAAAADnPIDROrmt1Wwj Page URL: https://gladiknow.com/remove-confirm

Furry commented 9 months ago

Any update on this issue? I'm facing the same error when trying to solve a CloudFlare Turnstile captcha.

Site key: 0x4AAAAAAADnPIDROrmt1Wwj Page URL: https://gladiknow.com/remove-confirm

I'll look into it now, thank you!

Furry commented 9 months ago

@ivangrosse @mayrsascha

I was able to recreate it with and without error. It seems there's two separate types of turnstile solves, though I've never used turnstile myself so I'm not too terribly sure how it works.

Utilizing 2captcha's standalone turnstile captcha, this code works properly:

const Captcha = require("../dist/index.js");
const Solver = new Captcha.Solver(process.argv[2]);

Solver.turnstile("0x4AAAAAAAC3DHQFLr1GavRN", "https://2captcha.com/demo/cloudflare-turnstile")
.then((res) => {
    console.log(res);
})
.catch((err) => {
    console.log(err);
})

However both of your sites error when doing it that way, but the request seems to pass through properly when using the parameters given by the Cloudflare Turnstile Challenge


const Captcha = require("../dist/index.js");
const Solver = new Captcha.Solver(process.argv[2]);

Solver.turnstile("0x4AAAAAAADnPIDROrmt1Wwj", "https://gladiknow.com/remove-confirm", {
    type: "TurnstileTask",
    userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)",
    action: "managed",
    data: "1324652345234623463425534",
    pagedata: "452353262347623453",
})
.then((res) => {
    console.log(res);
})
.catch((err) => {
    console.log(err);
})```

This code properly sends the request, by passing in the 'action, data, & pagedata' manually through the 'extras' field of the <Solver>.turnstile method. How you'd go about retrieving that data from the website isn't something that I know but 2captcha's official site seems to have a good deal of documentation on it.
mayrsascha commented 9 months ago

Thanks for the update @Furry ! Getting those action, data and pageData params seems to be my issue now, so I guess you can close this issue as its not directly related to the library.

Been trying to make it work but I just can't for the life of me figure out how to get those params, something seems to be broken. For reference my Puppeteer code that will try and grab all the arguments from the window.turnstile.render straight after page navigation, copy/pasted most of it from 2captcha's docs directly:

const page = await browser.newPage()
  await page.evaluateOnNewDocument(() => {
    const i = setInterval(()=>{
      if (window.turnstile) {
          clearInterval(i)
          window.turnstile.render = (a,b) => {
          let p = {
              method: "turnstile",
              key: "YOUR_API_KEY",
              sitekey: b.sitekey,
              pageurl: window.location.href,
              data: b.cData,
              pagedata: b.chlPageData,
              action: b.action,
              userAgent: navigator.userAgent,
              json: 1
          }
          console.log(JSON.stringify(p))
          window.tsCallback = b.callback
          return 'foo'
          }
      }
      },50)
  });
  await page.goto('https://dexscreener.com/new-pairs/24h')

Just nothing get's console.logged, it's like the window.turnstile.render function never gets called or somehow manages to be elusive in other ways, so I can't confirm its working for me. I also tried to inject this code manually upon page render multiple times to make sure its not a Puppetteer problem but same result. @ivangrosse Please share if you managed to get further than me here. I've opened a ticket with 2captcha last month but not reply so far.

ivangrosse commented 9 months ago

Thanks for the quick response @Furry 🙌 Currently I'm facing the same issue as you @mayrsascha , I'm not able to get action, data, and pageData.

My only suggestion for this repo would be to create a new interface to use when you define the type of the extra parameter for turnstile because now we're using UserHCaptchaExtra which doesn't support these properties we're talking about.

Furry commented 9 months ago

I'll make a push with this change tonight, completely slipped my mind since I was testing in JS. Thank you!

paveltyavin commented 8 months ago

Any news?

joeyvmason commented 7 months ago

+1 Facing the same issue

pavan-jaju commented 6 months ago

+1, need to know how to skip the Turnstile Captcha proxy pages. Not standalone. Also need know where to put the values and what to call next, once api responses back with success

pavan-jaju commented 6 months ago

I'll make a push with this change tonight, completely slipped my mind since I was testing in JS. Thank you!

@Furry Have you pushed any changes for this. I can not see anything pushed recently. Help will be much appreciated, as I am stuck on this for last 3+ months

Furry commented 3 months ago

I'll make a push with this change tonight, completely slipped my mind since I was testing in JS. Thank you!

@Furry Have you pushed any changes for this. I can not see anything pushed recently. Help will be much appreciated, as I am stuck on this for last 3+ months

I apologize for my lack of maintenance for this period, life was pretty chaotic.

https://www.npmjs.com/package/2captcha/v/4.0.0-1 https://github.com/Furry/2captcha/commit/825fe927fcdf590cd6f689890499d8f96fc726fe

The next branch uses 2captcha's v2 api, supporting all captcha types provided, including a second method for Turnstile on Cloudflare- It's a bit buggy now, but will eventually phase out the current older version.