0

0

如何绕过验证码

王林

王林

发布时间:2024-09-04 21:46:21

|

792人浏览过

|

来源于dev.to

转载

如何绕过验证码

无论人们多少次写道验证码早已过时,不再像开发者最初希望的那样有效,但是,互联网资源的所有者仍然继续使用验证码来保护他们的项目。但我们这个时代最流行的验证码是什么?

澄清 - 本文中介绍的所有代码都是基于验证码识别服务 2captcha 的 api 文档编写的

这是验证码。 recaptcha v2、v3 等,由 google 于 2007 年创建。自第一个 recaptcha 出现以来已经很多年了,但它仍然保持着花环,周期性地输给竞争对手,然后又赢回来。但尽管 recapcha 在神经网络面前存在诸多缺陷,但它的受欢迎程度从未达到第二位。

人们曾进行过大量创建“验证码杀手”的尝试,有些不太成功,有些看起来只是对验证码的威胁,但事实上却毫无作用。但事实仍然是,竞争对手希望做比 recapcha 更好、更可靠的事情,这表明了它的受欢迎程度。

如何使用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 密钥,当然,还要安装必要的模块。

Sora
Sora

Sora是OpenAI发布的一种文生视频AI大模型,可以根据文本指令创建现实和富有想象力的场景。

下载

如何绕过node js中的recaptcha

与 python 的情况一样,对于那些不喜欢现成解决方案的人,下面是使用 node js 编程语言解决验证码的脚本。我提醒您不要忘记安装代码运行所需的模块,包括:
axios

您可以使用此命令安装它 –

npm 安装 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 中识别 recapcha

好了,对于那些不习惯使用现成模块的人来说,这里是直接集成的代码。该代码使用标准 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';

因此,使用给出的示例,您可以解决与验证码识别相关的大部分问题。有问题可以在评论里提问!

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

WorkBuddy
WorkBuddy

腾讯云推出的AI原生桌面智能体工作台

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
js正则表达式
js正则表达式

php中文网为大家提供各种js正则表达式语法大全以及各种js正则表达式使用的方法,还有更多js正则表达式的相关文章、相关下载、相关课程,供大家免费下载体验。

530

2023.06.20

js获取当前时间
js获取当前时间

JS全称JavaScript,是一种具有函数优先的轻量级,解释型或即时编译型的编程语言;它是一种属于网络的高级脚本语言,主要用于Web,常用来为网页添加各式各样的动态功能。js怎么获取当前时间呢?php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

576

2023.07.28

js 字符串转数组
js 字符串转数组

js字符串转数组的方法:1、使用“split()”方法;2、使用“Array.from()”方法;3、使用for循环遍历;4、使用“Array.split()”方法。本专题为大家提供js字符串转数组的相关的文章、下载、课程内容,供大家免费下载体验。

760

2023.08.03

js是什么意思
js是什么意思

JS是JavaScript的缩写,它是一种广泛应用于网页开发的脚本语言。JavaScript是一种解释性的、基于对象和事件驱动的编程语言,通常用于为网页增加交互性和动态性。它可以在网页上实现复杂的功能和效果,如表单验证、页面元素操作、动画效果、数据交互等。

6208

2023.08.17

js删除节点的方法
js删除节点的方法

js删除节点的方法有:1、removeChild()方法,用于从父节点中移除指定的子节点,它需要两个参数,第一个参数是要删除的子节点,第二个参数是父节点;2、parentNode.removeChild()方法,可以直接通过父节点调用来删除子节点;3、remove()方法,可以直接删除节点,而无需指定父节点;4、innerHTML属性,用于删除节点的内容。

492

2023.09.01

js截取字符串的方法
js截取字符串的方法

js截取字符串的方法有substring()方法、substr()方法、slice()方法、split()方法和slice()方法。本专题为大家提供字符串相关的文章、下载、课程内容,供大家免费下载体验。

221

2023.09.04

Js中concat和push的区别
Js中concat和push的区别

Js中concat和push的区别:1、concat用于将两个或多个数组合并成一个新数组,并返回这个新数组,而push用于向数组的末尾添加一个或多个元素,并返回修改后的数组的新长度;2、concat不会修改原始数组,是创建新的数组,而push会修改原数组,将新元素添加到原数组的末尾等等。本专题为大家提供concat和push相关的文章、下载、课程内容,供大家免费下载体验。

240

2023.09.14

js截取字符串的方法介绍
js截取字符串的方法介绍

JavaScript字符串截取方法,包括substring、slice、substr、charAt和split方法。这些方法可以根据具体需求,灵活地截取字符串的不同部分。在实际开发中,根据具体情况选择合适的方法进行字符串截取,能够提高代码的效率和可读性 。

303

2023.09.21

C# ASP.NET Core微服务架构与API网关实践
C# ASP.NET Core微服务架构与API网关实践

本专题围绕 C# 在现代后端架构中的微服务实践展开,系统讲解基于 ASP.NET Core 构建可扩展服务体系的核心方法。内容涵盖服务拆分策略、RESTful API 设计、服务间通信、API 网关统一入口管理以及服务治理机制。通过真实项目案例,帮助开发者掌握构建高可用微服务系统的关键技术,提高系统的可扩展性与维护效率。

76

2026.03.11

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
最新Python教程 从入门到精通
最新Python教程 从入门到精通

共4课时 | 22.5万人学习

Django 教程
Django 教程

共28课时 | 4.9万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.9万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号