Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captcha validation issue #1

Open
SPYNARY opened this issue May 5, 2024 · 13 comments
Open

Captcha validation issue #1

SPYNARY opened this issue May 5, 2024 · 13 comments

Comments

@SPYNARY
Copy link

SPYNARY commented May 5, 2024

Hi, im facing an issue who block your code to submit the solution token, i have try multiple way to avoid this but the issue persist.

The thing is that the submit button of the website is enabled only when the MTCaptcha is completed by typing the right code, but when the code solve it using the solution token it doesn't enable this button , i have tried to remove the disabled attribute of the buton but i still get the error 'Please fill the captcha correctly'

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

Here the piece of code who archieve this :

				var mtcaptchaConfig = {
					"sitekey": "MTPublic-6dZ4hzZ6U",
					"theme":  "chrome" ,
					"lang": "fr",
					"loadAnimation": "false",
                    "verified-callback": function(state) {
						if (state.isVerified) {
							$('#captchaToken').val(state.verifiedToken);
							$('.btn-submit-vote').removeAttr('title').removeAttr('disabled');
                        }
                    }
				};
				(function(){var mt_service = document.createElement('script');mt_service.async = true;mt_service.src = 'https://service.mtcaptcha.com/mtcv1/client/mtcaptcha.min.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(mt_service);
					var mt_service2 = document.createElement('script');mt_service2.async = true;mt_service2.src = 'https://service2.mtcaptcha.com/mtcv1/client/mtcaptcha2.min.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(mt_service2);}) ();

@dzmitry-duboyski
Copy link
Owner

@SPYNARY Could you tell me the address of the page with the captcha, and the algorithm for how to get it?

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

Sure here it is :

https://top-serveurs.net/rdr/vote/last-red-line

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

I tried some manipulation and i think it may be possible to trick the page because the verification seem to be done on the client side

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

Here the piece of code who archieve this :

				var mtcaptchaConfig = {
					"sitekey": "MTPublic-6dZ4hzZ6U",
					"theme":  "chrome" ,
					"lang": "fr",
					"loadAnimation": "false",
                    "verified-callback": function(state) {
						if (state.isVerified) {
							$('#captchaToken').val(state.verifiedToken);
							$('.btn-submit-vote').removeAttr('title').removeAttr('disabled');
                        }
                    }
				};
				(function(){var mt_service = document.createElement('script');mt_service.async = true;mt_service.src = 'https://service.mtcaptcha.com/mtcv1/client/mtcaptcha.min.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(mt_service);
					var mt_service2 = document.createElement('script');mt_service2.async = true;mt_service2.src = 'https://service2.mtcaptcha.com/mtcv1/client/mtcaptcha2.min.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(mt_service2);}) ();

And if you want to fidn this you have to type sitekey in dev tool element

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

I also found in mtcaptcha documentation the mentionned part :

https://www.mtcaptcha.com/dev-guide-autoformvalidate

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

I also had an issue with your package idk why but it was returning an unsolvable error so i built my own using v2 api :

async function waitForTaskCompletion(clientKey, taskId) {
    while (true) {
        try {
            const res = await axios.post("https://api.2captcha.com/getTaskResult", {
                "clientKey": clientKey,
                "taskId": taskId
            });

            if (res.data.status === "ready") {
                console.log('Solution found');
                return res.data.solution;
            } else if (res.data.status === "processing") {
                console.log('In process, retry');
                await new Promise(resolve => setTimeout(resolve, 5000));
            } else {
                console.log('Solution search failed');
                throw new Error(`Error ${res.data.errorId}: ${res.data.errorDescription}`);
            }
        } catch (error) {
            throw error;
        }
    }
}

const res = await axios.post("https://api.2captcha.com/createTask", {
    "clientKey": "",
    "task": {
      "type": "MtCaptchaTaskProxyless",
      "websiteURL": "https://top-serveurs.net/rdr/vote/last-red-line",
      "websiteKey": mtCaptchaKey
    }
  });

 const solution = await waitForTaskCompletion('', res.data.taskId);
 
 const captchaAnswer = solution.token;

@dzmitry-duboyski
Copy link
Owner

dzmitry-duboyski commented May 5, 2024

@SPYNARY Hi.

I checked the MTcaptcha solution on this site using 2captcha-ts, the captcha is solved in the service, the 2captcha service returns the token, but the site not accepts the token using the code described in this repository.

Sites can add additional protection methods, such as callback functions, or something else. In order to correctly use the token, it is necessary to figure out how the token is used on this site.

@dzmitry-duboyski
Copy link
Owner

@SPYNARY The easiest way is to use a different method of solving the captcha. Try using the Normal captcha method. To do this, you just need to take a screenshot of the captcha task and send it to the service, then the service will return the text from the image to you. After that, you will only have to enter the text in the text field. And then click on the required button.

Since the text in the task is case-sensitive, it is advisable to send an additional parameter case: true:
image

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

Okay perfect thank's a lot, that blow my mind since 1 day XD

@dzmitry-duboyski
Copy link
Owner

@SPYNARY Hi again, I made a simple demo, it works for me, but apparently you also need to use a proxy, since the number of votes is tied to the ip.

Demo:

import puppeteer from "puppeteer";
import { Solver } from "2captcha-ts";
const solver = new Solver("you_2captcha_api_key");

const sleep = (ms) => new Promise((res) => setTimeout(res, ms));

(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    devtools: true
  });

  const [page] = await browser.pages();
  await page.setViewport({ width: 1080, height: 1024 });

  // Open target page that contains MTCaptcha.
  await page.goto("https://top-serveurs.net/rdr/vote/last-red-line");

  // show sometimes, depends on ip
  // await page.waitForSelector(".fc-consent-root");
  // await page.waitForSelector(".fc-cta-consent .fc-button-label");
  // await page.click('.fc-cta-consent .fc-button-label')

  await page.type('#playername', 'user3d3dd')
  await page.waitForSelector("#mtcaptcha-iframe-1");


  // Getting the frame
  const iframeElementHandle = await page.$("#mtcaptcha-iframe-1");
  const iframe = await iframeElementHandle.contentFrame();

  // Wait
  await sleep(2000);

  // Grab captcha image(`base64`)
  const captcha = await iframe.evaluate(() => {
    console.log(document.querySelector('.mtcap-image img'))
    const captcha = document.querySelector('.mtcap-image img').src
    console.log(captcha)
    return captcha
    });

  // Wait
  await sleep(3000)
  // console.log(captcha)

  // solve image captcha
  const res = await solver.imageCaptcha({
    body: captcha,
    regsense: 1
  });

  console.log("Answer:");
  console.log(res);

  const frameHandle = await page.$("#mtcaptcha-iframe-1");
  const frame = await frameHandle.contentFrame();
  await frame.click('#mtcap-inputtext-1')
  // type captcha answer
  await frame.type('#mtcap-inputtext-1', res.data)

  await sleep(3000)

  // click submit btn
  await page.click('button[type="submit"]')

})();

@dzmitry-duboyski
Copy link
Owner

@SPYNARY Please check or this method works for you.

@SPYNARY
Copy link
Author

SPYNARY commented May 5, 2024

It work, thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants