How to bypass captcha verification

Solving captcha is the most irritating thing we do on the internet. Not only this, the most significant barrier while automating some tasks is the captcha. What if we can skip or bypass the process of solving captcha and only focus on what matters to us the most? It would be fun and productive at the same time, right? Let’s build a captcha solver for your next automation project then 🥳. At the end of this article, you will know how to bypass captcha using PHP or NodeJS.

Bypass Captcha

The purpose of captcha

Before we get started, let’s talk about the purpose of the captcha and how it works. The purpose of a captcha is to differentiate between bots and humans on the internet. They work in different ways. A few standard captchas are typing distorted letters, solving basic math, selecting the correct set of images, etc.

While there are a lot of captchas available, the most popular among them is reCaptcha. It’s hard for any automated bot to crack a ReCaptcha and pass. But there are many captcha solver programs available that offer you to solve this automatically. One of the best service providers in such a case is 2captcha. And today, we’re going to combine them both. I mean, let’s bypass reCaptcha using 2captcha 😀 before diving deeper into the topic, let’s know more about these two services.

What is reCaptcha?

reCaptcha is just another captcha service provided by Google. But it is considered the most advanced one out there. Recaptcha helps you protect your site from bot attacks to serve your real users a better experience.

reCAPTCHA works by presenting users with a challenge, such as a distorted text image, or image sets of different objects, that a computer would have difficulty recognizing. If the user correctly enters the challenge, they are deemed a human and are allowed to proceed.

What is 2Captcha?

2Captcha is a human-powered captcha solving service. As no bots can accurately solve captcha yet, we still need humans to solve the captchas in most cases. So, as long as you’re unwilling to solve a captcha, 2Captcha is here to hand over the job to someone else.

Captchas are designed in such ways that humans can solve them easily. So when a human solves a captcha on your behalf, you can expect the most accurate result. And that’s 2Captcha. It’s always there to get someone so you can bypass captcha on your end.

Why 2Captcha?

There are a good number of reasons why you should use 2captcha. Some of them are:

  • It’s human-powered
  • It can bypass any captcha out there
  • You get the most accurate result
  • Easy to use with any programming language
  • It’s super fast!

Get Site Key

The primary requirement to solve the reCaptcha is the site key. Every website that is using reCaptcha must have a site key. You will need this regardless of which programming language you’re using to bypass reCaptcha. And it’s super simple to get the site key of a website. You just need to visit the page containing the captcha and paste this simple query on the developer console. It will simply find the site key and will print in the console. For example, if we visit the contact page of TubeSort, which is using reCaptcha, and paste this query into the console, we will get the site key for TubeSort.

document.querySelector("[data-sitekey]").getAttribute("data-sitekey");

The result:

Getting site key using javascript

As you can see, the query has returned 6Ld32jwfAAAAAFlrj1p4pWBQY6RyUvStf0xiM3vW As the site key of TubeSort, you can use the browser inspect tool to find the site key manually. It will look something like this.

Now that you have the site key, you can pick your favorite programming language below to build your captcha-solving program. For our example captcha solver program, we will bypass the captcha for the TubeSort contact page and submit the contact form programmatically.

How to bypass captcha using PHP

If you’re on the web, there is over 70% possibility that you’re on a PHP-powered web. So if you’re planning to build your next automated tool based on the web, there’s a high chance that you will use PHP as your go-to programming language. Then why not start with PHP?

To make your first captcha solver program in PHP, you need to install the 2Captcha PHP SDK on your project. It’s pretty easy to do if you have installed composer on your system. Or you can install the composer from here. Then open the terminal and run the command below.

composer require 2captcha/2captcha

Start writing code

Once you have the site key and the 2Captcha PHP SDK, the next thing you can do is start writing your program. I will begin with requiring the SDK at the beginning of my file. Please make sure you use the correct path of your autoloader. I’m using an example path here.

require(__DIR__ . '/PATH_TO_YOUR_AUTO_LOADER/autoloader.php');

Next, I will create an instance of the 2captcha with my API key. Again, make sure you replace the YOUR_API_KEY with your actual API key.

$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');

Now, I will provide the site key and the URL of my targeted page. In my case, which is the contact page of TubeSort.

$response = $solver->recaptcha([
    'sitekey' => '6Ld32jwfAAAAAFlrj1p4pWBQY6RyUvStf0xiM3vW',
    'url'     => 'https://tubesort.com/contact',
]);

And for the sake of error handling, we can use the try-catch block.

try {
    $response = $solver->recaptcha([
            'sitekey' => '6Ld32jwfAAAAAFlrj1p4pWBQY6RyUvStf0xiM3vW',
            'url'     => 'https://tubesort.com/contact',
    ]);
} catch (\Exception $e) {
    die($e->getMessage());
}

If the script gets an error, it will simply stop working and print the error message. Otherwise, we have the solved response code for our current request as $response->code. we can combine this with all other parameters of the TubeSort contact page and submit the request.

$url = 'https://tubesort.com/contact';
$data = array('fullname' => 'Your Name', 'email' => 'your_email','subject' => 'Your message subject', 'message' => 'Your actuall message', 'g-recaptcha-response' => $response->code);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

Congrats! You have just built your first automated form submission tool that bypasses captcha automatically. Now it’s time to create the same program using other programming languages.

How to bypass captcha using Node Js

As you already know how the process exactly works. I will not repeat the same explanation again and again. Instead, I will start writing code.

First, we will install 2captcha NodeJS SDK with Axios using NPM. We will use Axios to make post requests like we did in the PHP. Make sure you have NodeJS and NPM installed on your system. After that, open your terminal and run the command below.

npm install 2captcha axios

Once you have installed both the packages, time to start writing codes. We will begin by requiring both the packages at the top of our javascript file.

const axios = require("axios");
const Captcha = require("2captcha");

Now, we can initiate the 2captcha with an API key.

const solver = new Captcha.Solver("API_KEY");

After that, we pass our site key and website URL similarly we did on the PHP case, then get the response using the then method and handle errors using the catch method. You can use the async-await method as well if you prefer that.

solver.recaptcha("6Ld32jwfAAAAAFlrj1p4pWBQY6RyUvStf0xiM3vW", "https://tubesort.com/contact")
.then((res) => {
    const data = res.data;
})
.catch(err=>console.log(err));

Once we have the solved response code of the captcha, we can send the post request to TubeSort’s contact page, including the captcha response and all other parameters of the contact form. Here’s how to do it:

Note: Please write this block of code inside the then method of our previous block of code.

axios.post("https://discord.com/api/v9/auth/register", {
    g-recaptcha-response: data,

    "fullname": "Your name",
    "email" : "Your email",
    "subject" : "Your message subject",
    "message" : "Your actual message"
})
.then(response=>console.log(response))
.catch(err=>console.log(err))

Now you can simply submit the contact form of TubeSort by running this script with NodeJS (e.g.: node script.js on terminal) without worrying about the ReCaptcha on the page.

Conclusion

That’s all for today, friends. I hope this article will help you build your next automated project without worrying about solving captcha. Because now you own a program for solving captcha of your own. If you have any questions, please feel free to post them in the comment section. Have a great day!

Blog Desire is Up for Sale!
Ready for a new chapter? Blog Desire could be yours!

Inquire Now Inquire Now!

Khokon M.

Full Stack Web Developer, Content Writer.

Leave a Reply

This Post Has 3 Comments