」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何繞過驗證碼

如何繞過驗證碼

發佈於2024-11-08
瀏覽:936

How to bypass recaptcha

No matter how many times people wrote that the captcha has outlived itself long time ago and no longer works as effectively as its developers would have liked initially, however, the owners of Internet resources continue to protect their projects with captchas. But what is the most popular captcha of our time?

Clarification – all the code that will be presented in this article has been prepared based on the API documentation of the captcha recognition service 2captcha

It is recaptcha. Recaptcha V2, V3, etc., that was created by Google back in 2007. It has been many years since the first recaptcha appeared, but it continues to keep the garland, periodically losing ground to competitors and then winning it back. But recaptcha has never taken the 2nd place in popularity, despite all its imperfections in front of neural networks.

There was a huge number of attempts to create a "recaptcha killer", some were less successful, some only looked like a threat to recaptcha, but in fact turned out to be nothing. Yet the fact remains that the desire of competitors to do something better and more reliable than recaptcha demonstrates its popularity.

How to bypass recaptcha using python (example of a code)

If you do not trust any third-party modules, I have prepared the most universal code that can be inserted into your Python script with minor modifications and solve the recaptcha automatically. Here is the code itself:

import requests
import time

API_KEY = 'Your_API_2Captcha_key'

def solve_recaptcha_v2(site_key, url):
    payload = {
        'key': API_KEY,
        'method': 'userrecaptcha',
        'googlekey': site_key,
        'pageurl': url,
        'json': 1
    }

    response = requests.post('https://2captcha.com/in.php', data=payload)
    result = response.json()

    if result['status'] != 1:
        raise Exception(f"Error when sending captcha: {result['request']}")

    captcha_id = result['request']

    while True:
        time.sleep(5)
        response = requests.get(f"https://2captcha.com/res.php?key={API_KEY}&action=get&id={captcha_id}&json=1")
        result = response.json()

        if result['status'] == 1:
            print("Captcha solved successfully.")
            return result['request']
        elif result['request'] == 'CAPCHA_NOT_READY':
            print("The captcha has not been solved yet, waiting...")
            continue
        else:
            raise Exception(f"Error while solving captcha: {result['request']}")

def solve_recaptcha_v3(site_key, url, action='verify', min_score=0.3):
    payload = {
        'key': API_KEY,
        'method': 'userrecaptcha',
        'googlekey': site_key,
        'pageurl': url,
        'version': 'v3',
        'action': action,
        'min_score': min_score,
        'json': 1
    }

    response = requests.post('https://2captcha.com/in.php', data=payload)
    result = response.json()

    if result['status'] != 1:
        raise Exception(f"Error when sending captcha: {result['request']}")

    captcha_id = result['request']

    while True:
        time.sleep(5)
        response = requests.get(f"https://2captcha.com/res.php?key={API_KEY}&action=get&id={captcha_id}&json=1")
        result = response.json()

        if result['status'] == 1:
            print("Captcha solved successfully.")
            return result['request']
        elif result['request'] == 'CAPCHA_NOT_READY':
            print("The captcha has not been solved yet, waiting...")
            continue
        else:
            raise Exception(f"Error while solving captcha: {result['request']}")

# Usage example for reCAPTCHA v2
site_key_v2 = 'your_site_key_v2'
url_v2 = 'https://example.com'
recaptcha_token_v2 = solve_recaptcha_v2(site_key_v2, url_v2)
print(f"Received token for reCAPTCHA v2: {recaptcha_token_v2}")

# Usage example for reCAPTCHA v3
site_key_v3 = 'your_site_key_v3'
url_v3 = 'https://example.com'
recaptcha_token_v3 = solve_recaptcha_v3(site_key_v3, url_v3)
print(f"Received token for reCAPTCHA v3: {recaptcha_token_v3}")

However, before using the provided script, carefully read the recommendations of the service for recognizing a particular type of recaptcha in order to have an idea how this code works.

Also, do not forget to insert your API key in the code and, of course, install the necessary modules.

How to bypass recaptcha in node js

As in the case of Python, for those who do not like ready-made solutions, below is a script for solving a captcha using the node js programming language. I remind you to not forget to install the necessary modules for the code to work, including:
axios

You can install it using this command –

npm install axios

Here is the code itself:

const axios = require('axios');
const sleep = require('util').promisify(setTimeout);

const API_KEY = 'YOUR_API_KEY_2CAPTCHA'; // Replace with your real API key

// Function for reCAPTCHA v2 solution
async function solveReCaptchaV2(siteKey, pageUrl) {
    try {
        // Sending a request for the captcha solution
        const sendCaptchaResponse = await axios.post(`http://2captcha.com/in.php`, null, {
            params: {
                key: API_KEY,
                method: 'userrecaptcha',
                googlekey: siteKey,
                pageurl: pageUrl,
                json: 1
            }
        });

        if (sendCaptchaResponse.data.status !== 1) {
            throw new Error(`Error when sending captcha: ${sendCaptchaResponse.data.request}`);
        }

        const requestId = sendCaptchaResponse.data.request;
        console.log(`Captcha sent, request ID: ${RequestId}`);

        // Waiting for the captcha solution
        while (true) {
            await sleep(5000); // Waiting 5 seconds before the next request

            const getResultResponse = await axios.get(`http://2captcha.com/res.php`, {
                params: {
                    key: API_KEY,
                    action: 'get',
                    id: requestId,
                    json: 1
                }
            });

            if (getResultResponse.data.status === 1) {
                console.log('Captcha solved successfully.');
                return getResultResponse.data.request;
            } else if (getResultResponse.data.request === 'CAPCHA_NOT_READY') {
                console.log('The captcha has not been solved yet, waiting...');
            } else {
                throw new Error(`Error while solving captcha: ${getResultResponse.data.request}`);
            }
        }
    } catch (error) {
        console.error(`An error occurred: ${error.message}`);
    }
}

// Function for reCAPTCHA v3 solution
async function solveReCaptchaV3(siteKey, pageUrl, action = 'verify', minScore = 0.3) {
    try {
        // Sending a request for the captcha solution
        const sendCaptchaResponse = await axios.post(`http://2captcha.com/in.php`, null, {
            params: {
                key: API_KEY,
                method: 'userrecaptcha',
                googlekey: siteKey,
                pageurl: pageUrl,
                version: 'v3',
                action: action,
                min_score: minScore,
                json: 1
            }
        });

        if (sendCaptchaResponse.data.status !== 1) {
            throw new Error(`Error when sending captcha: ${sendCaptchaResponse.data.request}`);
        }

        const requestId = sendCaptchaResponse.data.request;
        console.log(`Captcha sent, request ID: ${RequestId}`);

        // Waiting for the captcha solution
        while (true) {
            await sleep(5000); // Waiting 5 seconds before the next request

            const getResultResponse = await axios.get(`http://2captcha.com/res.php`, {
                params: {
                    key: API_KEY,
                    action: 'get',
                    id: requestId,
                    json: 1
                }
            });

            if (getResultResponse.data.status === 1) {
                console.log('Captcha solved successfully.');
                return getResultResponse.data.request;
            } else if (getResultResponse.data.request === 'CAPCHA_NOT_READY') {
                console.log('The captcha has not been solved yet, waiting...');
            } else {
                throw new Error(`Error while solving captcha: ${getResultResponse.data.request}`);
            }
        }
    } catch (error) {
        console.error(`An error occurred: ${error.message}`);
    }
}

// Usage example for reCAPTCHA v2
(async () => {
    const siteKeyV2 = 'YOUR_SITE_KEY_V2'; // Replace with the real site key
    const pageUrlV2 = 'https://example.com '; // Replace with the real URL of the page

    const tokenV2 = await solveReCaptchaV2(siteKeyV2, pageUrlV2);
    console.log(`Received token for reCAPTCHA v2: ${tokenV2}`);
})();

// Usage example for reCAPTCHA v3
(async () => {
    const siteKeyV3 = 'YOUR_SITE_KEY_V3'; // Replace with the real site key
    const pageUrlV3 = 'https://example.com '; // Replace with the real URL of the page
    const action = 'homepage'; // Replace with the corresponding action
    const MinScore = 0.5; // Set the minimum allowed score

    const tokenV3 = await solveReCaptchaV3(siteKeyV3, pageUrlV3, action, minScore);
    console.log(`Received token for reCAPTCHA v3: ${tokenV3}`);
})();

Also, do not forget to insert your API key into the code, instead of
"'YOUR_API_KEY_2CAPTCHA'"

How to recognize a recaptcha in PHP

Well, for those who are not used to using ready-made modules, here is the code for integration directly. The code uses standard PHP functions such as file_get_contents and json_decode, here is the code itself:

function solveRecaptchaV2($apiKey, $siteKey, $url) {
    $requestUrl = "http://2captcha.com/in.php?key={$apiKey}&method=userrecaptcha&googlekey={$siteKey}&pageurl={$url}&json=1";

    $response = file_get_contents($requestUrl);
    $result = json_decode($response, true);

    if ($result['status'] != 1) {
        throw new Exception("Error when sending captcha: " . $result['request']);
    }

    $captchaId = $result['request'];

    while (true) {
        sleep(5);
        $resultUrl = "http://2captcha.com/res.php?key={$apiKey}&action=get&id={$captchaId}&json=1";
        $response = file_get_contents($resultUrl);
        $result = json_decode($response, true);

        if ($result['status'] == 1) {
            return $result['request'];
        } elseif ($result['request'] == 'CAPCHA_NOT_READY') {
            continue;
        } else {
            throw new Exception("Error while solving captcha: " . $result['request']);
        }
    }
}

function solveRecaptchaV3($apiKey, $siteKey, $url, $action = 'verify', $minScore = 0.3) {
    $requestUrl = "http://2captcha.com/in.php?key={$apiKey}&method=userrecaptcha&googlekey={$siteKey}&pageurl={$url}&version=v3&action={$action}&min_score={$minScore}&json=1";

    $response = file_get_contents($requestUrl);
    $result = json_decode($response, true);

    if ($result['status'] != 1) {
        throw new Exception("Error when sending captcha: " . $result['request']);
    }

    $captchaId = $result['request'];

    while (true) {
        sleep(5);
        $resultUrl = "http://2captcha.com/res.php?key={$apiKey}&action=get&id={$captchaId}&json=1";
        $response = file_get_contents($resultUrl);
        $result = json_decode($response, true);

        if ($result['status'] == 1) {
            return $result['request'];
        } elseif ($result['request'] == 'CAPCHA_NOT_READY') {
            continue;
        } else {
            throw new Exception("Error while solving captcha: " . $result['request']);
        }
    }
}

// Usage example for reCAPTCHA v2
$apiKey = 'YOUR_API_KEY_2CAPTCHA';
$siteKeyV2 = 'YOUR_SITE_KEY_V2';
$urlV2 = 'https://example.com';

try {
    $tokenV2 = solveRecaptchaV2($apiKey, $siteKeyV2, $urlV2);
    echo "Received token for reCAPTCHA v2: {$tokenV2}\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

// Usage example for reCAPTCHA v3
$siteKeyV3 = 'YOUR_SITE_KEY_V3';
$urlV3 = 'https://example.com';
$action = 'homepage'; // Specify the appropriate action
$MinScore = 0.5; // Specify the minimum allowed score

try {
    $tokenV3 = solveRecaptchaV3($apiKey, $siteKeyV3, $urlV3, $action, $minScore);
    echo "Received token for reCAPTCHA v3: {$tokenV3}\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

?>

I also remind you of the need to replace some parameters in the code, in particular:
$apiKey = 'YOUR_API_KEY_2CAPTCHA';
 $siteKeyV2 = 'YOUR_SITE_KEY_V2';
$urlV2 = 'https://example.com';

Thus, using the examples given, you can solve most of the issues related to recaptcha recognition. You can ask questions in the comments if there are any left!

版本聲明 本文轉載於:https://dev.to/markus009/how-to-bypass-recaptcha-5f1i?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 如何同步迭代並從PHP中的兩個等級陣列打印值?
    如何同步迭代並從PHP中的兩個等級陣列打印值?
    同步的迭代和打印值來自相同大小的兩個數組使用兩個數組相等大小的selectbox時,一個包含country代碼的數組,另一個包含鄉村代碼,另一個包含其相應名稱的數組,可能會因不當提供了exply for for for the uncore for the forsion for for ytry...
    程式設計 發佈於2025-04-06
  • 在程序退出之前,我需要在C ++中明確刪除堆的堆分配嗎?
    在程序退出之前,我需要在C ++中明確刪除堆的堆分配嗎?
    在C中的顯式刪除 在C中的動態內存分配時,開發人員通常會想知道是否有必要在heap-procal extrable exit exit上進行手動調用“ delete”操作員,但開發人員通常會想知道是否需要手動調用“ delete”操作員。本文深入研究了這個主題。 在C主函數中,使用了動態分配變量(...
    程式設計 發佈於2025-04-06
  • 如何在無序集合中為元組實現通用哈希功能?
    如何在無序集合中為元組實現通用哈希功能?
    在未訂購的集合中的元素要糾正此問題,一種方法是手動為特定元組類型定義哈希函數,例如: template template template 。 struct std :: hash { size_t operator()(std :: tuple const&tuple)const {...
    程式設計 發佈於2025-04-06
  • 如何處理PHP文件系統功能中的UTF-8文件名?
    如何處理PHP文件系統功能中的UTF-8文件名?
    在PHP的Filesystem functions中處理UTF-8 FileNames 在使用PHP的MKDIR函數中含有UTF-8字符的文件很多flusf-8字符時,您可能會在Windows Explorer中遇到comploreer grounder grounder grounder gro...
    程式設計 發佈於2025-04-06
  • 如何從PHP中的Unicode字符串中有效地產生對URL友好的sl。
    如何從PHP中的Unicode字符串中有效地產生對URL友好的sl。
    為有效的slug生成首先,該函數用指定的分隔符替換所有非字母或數字字符。此步驟可確保slug遵守URL慣例。隨後,它採用ICONV函數將文本簡化為us-ascii兼容格式,從而允許更廣泛的字符集合兼容性。 接下來,該函數使用正則表達式刪除了不需要的字符,例如特殊字符和空格。此步驟可確保slug僅包...
    程式設計 發佈於2025-04-06
  • 為什麼不````''{margin:0; }`始終刪除CSS中的最高邊距?
    為什麼不````''{margin:0; }`始終刪除CSS中的最高邊距?
    在CSS 問題:不正確的代碼: 全球範圍將所有餘量重置為零,如提供的代碼所建議的,可能會導致意外的副作用。解決特定的保證金問題是更建議的。 例如,在提供的示例中,將以下代碼添加到CSS中,將解決餘量問題: body H1 { 保證金頂:-40px; } 此方法更精確,避免了由全局保證金重置...
    程式設計 發佈於2025-04-06
  • 為什麼我的CSS背景圖像出現?
    為什麼我的CSS背景圖像出現?
    故障排除:CSS背景圖像未出現 ,您的背景圖像儘管遵循教程說明,但您的背景圖像仍未加載。圖像和样式表位於相同的目錄中,但背景仍然是空白的白色帆布。 而不是不棄用的,您已經使用了CSS樣式: bockent {背景:封閉圖像文件名:背景圖:url(nickcage.jpg); 如果您的html,cs...
    程式設計 發佈於2025-04-06
  • 如何使用不同數量列的聯合數據庫表?
    如何使用不同數量列的聯合數據庫表?
    合併列數不同的表 當嘗試合併列數不同的數據庫表時,可能會遇到挑戰。一種直接的方法是在列數較少的表中,為缺失的列追加空值。 例如,考慮兩個表,表 A 和表 B,其中表 A 的列數多於表 B。為了合併這些表,同時處理表 B 中缺失的列,請按照以下步驟操作: 確定表 B 中缺失的列,並將它們添加到表的...
    程式設計 發佈於2025-04-06
  • 大批
    大批
    [2 數組是對象,因此它們在JS中也具有方法。 切片(開始):在新數組中提取部分數組,而無需突變原始數組。 令ARR = ['a','b','c','d','e']; // USECASE:提取直到索引作...
    程式設計 發佈於2025-04-06
  • 如何有效地轉換PHP中的時區?
    如何有效地轉換PHP中的時區?
    在PHP 利用dateTime對象和functions DateTime對象及其相應的功能別名為時區轉換提供方便的方法。例如: //定義用戶的時區 date_default_timezone_set('歐洲/倫敦'); //創建DateTime對象 $ dateTime = ne...
    程式設計 發佈於2025-04-06
  • 如何使用組在MySQL中旋轉數據?
    如何使用組在MySQL中旋轉數據?
    在關係數據庫中使用mySQL組使用mySQL組進行查詢結果,在關係數據庫中使用MySQL組,轉移數據的數據是指重新排列的行和列的重排以增強數據可視化。在這裡,我們面對一個共同的挑戰:使用組的組將數據從基於行的基於列的轉換為基於列。 Let's consider the following ...
    程式設計 發佈於2025-04-06
  • 可以在純CS中將多個粘性元素彼此堆疊在一起嗎?
    可以在純CS中將多個粘性元素彼此堆疊在一起嗎?
    [2这里: https://webthemez.com/demo/sticky-multi-header-scroll/index.html </main> <section> { display:grid; grid-template-...
    程式設計 發佈於2025-04-06
  • 如何使用Depimal.parse()中的指數表示法中的數字?
    如何使用Depimal.parse()中的指數表示法中的數字?
    在嘗試使用Decimal.parse(“ 1.2345e-02”中的指數符號表示法表示的字符串時,您可能會遇到錯誤。這是因為默認解析方法無法識別指數符號。 成功解析這樣的字符串,您需要明確指定它代表浮點數。您可以使用numbersTyles.Float樣式進行此操作,如下所示:[&& && && ...
    程式設計 發佈於2025-04-06
  • 如何限制動態大小的父元素中元素的滾動範圍?
    如何限制動態大小的父元素中元素的滾動範圍?
    在交互式接口中實現垂直滾動元素的CSS高度限制問題:考慮一個佈局,其中我們具有與用戶垂直滾動一起移動的可滾動地圖div,同時與固定的固定sidebar保持一致。但是,地圖的滾動無限期擴展,超過了視口的高度,阻止用戶訪問頁面頁腳。 映射{} 因此。我們不使用jQuery的“ .aimimate...
    程式設計 發佈於2025-04-06
  • 如何有效地選擇熊貓數據框中的列?
    如何有效地選擇熊貓數據框中的列?
    在處理數據操作任務時,在Pandas DataFrames 中選擇列時,選擇特定列的必要條件是必要的。在Pandas中,選擇列的各種選項。 選項1:使用列名 如果已知列索引,請使用ILOC函數選擇它們。請注意,python索引基於零。 df1 = df.iloc [:,0:2]#使用索引0和1 ...
    程式設計 發佈於2025-04-06

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3