ホームページ  >  記事  >  バックエンド開発  >  再キャプチャを回避する方法

再キャプチャを回避する方法

王林
王林オリジナル
2024-09-03 22:48:02412ブラウズ

How to bypass recaptcha

キャプチャはとうの昔に存続しなくなり、開発者が当初望んでいたほど効果的に機能しなくなったと人々が何度書いても、インターネット リソースの所有者は続けます。キャプチャでプロジェクトを保護します。しかし、現代で最も人気のあるキャプチャは何でしょうか?

説明 – この記事で紹介するすべてのコードは、キャプチャ認識サービス 2captcha の API ドキュメントに基づいて作成されています

再キャプチャです。 Recaptcha V2、V3 などは、2007 年に Google によって作成されました。最初の Recaptcha が登場してから何年も経ちましたが、競合他社に定期的に劣勢に立たされ、その後は取り戻されながらも、その地位を維持し続けています。しかし、recaptcha は、ニューラル ネットワークの前にあらゆる不完全性があるにもかかわらず、人気で 2 位になったことはありません。

「再捕獲キラー」を作成しようとする試みは膨大な数ありましたが、中にはあまり成功しなかったものもあれば、再捕獲に対する脅威にしか見えなかったが、実際には何の役にも立たなかったものもありました。それでも、recaptcha よりも優れた信頼性の高い何かをしたいという競合他社の願望がその人気を示しているという事実は変わりません。

Pythonを使用してrecaptchaを回避する方法(コード例)

サードパーティのモジュールを信頼しない場合は、少し変更を加えて Python スクリプトに挿入し、再キャプチャを自動的に解決できる最も汎用的なコードを用意しました。コード自体は次のとおりです:

インポートリクエスト
インポート時間

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}")

ただし、提供されたスクリプトを使用する前に、このコードがどのように機能するかを理解するために、特定のタイプの再キャプチャを認識するためのサービスの推奨事項をよく読んでください。

また、コードに API キーを挿入し、必要なモジュールをインストールすることを忘れないでください。

ノードjsでrecaptchaをバイパスする方法

Python の場合と同様、既製のソリューションが好きではない人のために、node js プログラミング言語を使用してキャプチャを解決するためのスクリプトを以下に示します。コードが機能するために必要なモジュールを忘れずにインストールしてください:
アクシオス

次のコマンドを使用してインストールできます –

npm install axios

コード自体は次のとおりです:

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}`);
})();

また、
の代わりに API キーをコードに挿入することを忘れないでください。 「'YOUR_API_KEY_2CAPTCHA'」

PHP で再キャプチャを認識する方法

既製のモジュールを使用することに慣れていない人のために、直接統合するためのコードを次に示します。このコードでは、file_get_contents や json_decode などの標準的な PHP 関数を使用します。コード自体は次のとおりです。

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';




したがって、ここで挙げた例を使用すると、再キャプチャの認識に関連する問題のほとんどを解決できます。質問が残っている場合は、コメント欄で質問してください!

以上が再キャプチャを回避する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。