深度解析

数学和逻辑验证码类型解释

数学验证码提出算术问题,例如“7 + 3 是什么?”或“解决:15 – 8”作为挑战。逻辑验证码通过基于单词的问题(例如“天空是什么颜色?”)扩展了这一点。或“输入最大的数字:5、12、3。”这些挑战是最早的验证码类型之一,并且在 WordPress 网站、联系表单和旧应用程序中仍然很常见。如果您的自动化遇到一个文本字段要求您解一个简单的方程,那么您正在处理数学或逻辑验证码。


数学和逻辑验证码的类型

1. 基本算术验证码

提出一个简单的加法、减法或乘法问题。

示例:

  • “3+5是多少?”
  • “12 – 4 =?”
  • “6×7=?”

实现: 问题要么呈现为纯文本(易于解析),要么嵌入图像中(需要 OCR)。

2. 文本呈现的数学验证码

该方程被渲染为图像以防止简单的文本解析。

示例:

  • 显示“14 + 23 = ?”的图像字体变形
  • 带有彩色数字和噪声背景的验证码图像

实现:需要OCR从图像中读取方程,然后计算得出答案。

3. 基于单词的数学验证码

数字被写成单词而不是数字。

示例:

  • “七加三等于多少?”
  • “输入十二减五的结果”

实现:需要NLP解析将单词转换为数字,然后计算。

4.逻辑题

需要常识的非算术问题。

示例:

  • “草是什么颜色的?”
  • “狗有几条腿?”
  • “火是热的还是冷的?”

实现:需要知识库或语言模型。这些通常来自固定问题库。

5. 序列或模式验证码

给出一个数字序列并询问下一个值。

示例:

  • “接下来是什么:2、4、6、8?”
  • “完成图案:1、1、2、3、5、?”

实现:需要模式识别逻辑。


数学验证码在技术上如何工作

基于文本的数学验证码流程

Server generates random equation (e.g., "7 + 3")
    ↓
Stores answer (10) in server-side session
    ↓
Renders equation as HTML text or image
    ↓
User submits answer via form field
    ↓
Server compares submitted answer to stored answer
    ↓
Match → Form submitted     Mismatch → Error shown

基于图像的数学验证码流程

Server generates random equation
    ↓
Renders equation into a distorted image (noise, lines, color shifts)
    ↓
Image served to client via <img> tag
    ↓
User reads image, computes answer, types in form field
    ↓
Server validates submitted answer

检测自动化中的数学验证码

Python检测

import requests
from bs4 import BeautifulSoup
import re

def detect_math_captcha(url):
    """Detect common math CAPTCHA patterns on a page."""
    response = requests.get(url, timeout=10)
    soup = BeautifulSoup(response.text, "html.parser")
    html = response.text.lower()

    indicators = {
        "text_math": False,
        "image_math": False,
        "logic_question": False,
    }

    # Check for text-based math questions
    math_patterns = [
        r"what is \d+\s*[\+\-\×\*]\s*\d+",
        r"\d+\s*[\+\-\×\*]\s*\d+\s*=\s*\?",
        r"solve:\s*\d+",
        r"type the (result|answer|sum)",
    ]
    for pattern in math_patterns:
        if re.search(pattern, html):
            indicators["text_math"] = True
            break

    # Check for CAPTCHA images near math-related labels
    captcha_images = soup.find_all("img", attrs={
        "alt": re.compile(r"captcha|math|verify", re.I)
    })
    if captcha_images:
        indicators["image_math"] = True

    # Check for logic questions
    logic_patterns = [
        r"what color is",
        r"how many legs",
        r"what comes next",
        r"is .+ hot or cold",
    ]
    for pattern in logic_patterns:
        if re.search(pattern, html):
            indicators["logic_question"] = True
            break

    return indicators

result = detect_math_captcha("https://example.com/contact")
print(result)

Node.js 检测

const axios = require("axios");
const cheerio = require("cheerio");

async function detectMathCaptcha(url) {
    const { data: html } = await axios.get(url, { timeout: 10000 });
    const $ = cheerio.load(html);
    const lower = html.toLowerCase();

    const indicators = {
        textMath: false,
        imageMath: false,
        logicQuestion: false,
    };

    // Text-based math patterns
    const mathPatterns = [
        /what is \d+\s*[+\-×*]\s*\d+/,
        /\d+\s*[+\-×*]\s*\d+\s*=\s*\?/,
        /solve:\s*\d+/,
        /type the (result|answer|sum)/,
    ];

    for (const pattern of mathPatterns) {
        if (pattern.test(lower)) {
            indicators.textMath = true;
            break;
        }
    }

    // Check for CAPTCHA images
    $("img").each((_, el) => {
        const alt = ($(el).attr("alt") || "").toLowerCase();
        if (/captcha|math|verify/.test(alt)) {
            indicators.imageMath = true;
        }
    });

    return indicators;
}

detectMathCaptcha("https://example.com/contact").then(console.log);

使用 OCR 解决数学验证码问题

当数学验证码将方程式呈现为图像时,OCR 会提取文本,并由一个简单的解析器计算答案。

使用 CaptchaAI 进行基于图像的数学验证码

import requests
import time
import re

API_KEY = "YOUR_API_KEY"
CAPTCHA_IMAGE_URL = "https://example.com/captcha.png"

# Download the CAPTCHA image
image_data = requests.get(CAPTCHA_IMAGE_URL).content

# Submit to CaptchaAI OCR
import base64
b64_image = base64.b64encode(image_data).decode()

submit = requests.post("https://ocr.captchaai.com/in.php", data={
    "key": API_KEY,
    "method": "base64",
    "body": b64_image,
    "json": 1,
})

task_id = submit.json().get("request")

# Poll for result
for _ in range(30):
    time.sleep(3)
    result = requests.get("https://ocr.captchaai.com/res.php", params={
        "key": API_KEY,
        "action": "get",
        "id": task_id,
        "json": 1,
    })
    data = result.json()
    if data.get("status") == 1:
        ocr_text = data["request"]  # e.g., "7 + 3"
        print(f"OCR result: {ocr_text}")

        # Parse and compute the answer
        match = re.match(r"(\d+)\s*([+\-*/×])\s*(\d+)", ocr_text)
        if match:
            a, op, b = int(match.group(1)), match.group(2), int(match.group(3))
            ops = {"+": a + b, "-": a - b, "*": a * b, "×": a * b, "/": a // b}
            answer = ops.get(op)
            print(f"Answer: {answer}")
        break
    elif "CAPCHA_NOT_READY" in str(data):
        continue

数学验证码与其他验证码类型

特征 数学验证码 reCAPTCHA v2 验证码 滑块验证码
用户摩擦 低(快速心算) 中(图像选择) 中(图像选择) 低(单拖)
机器人抵抗 很低 高的 高的 中等的
辅助功能 好(基于文本的版本) 差(视力相关) 差(视力相关) 差(依赖于电机)
成本 免费(自托管) 提供免费套餐 提供免费套餐 各不相同
常用 WordPress、联系表格 登录、注册 登录、注册 电子商务,亚洲

为什么仍然使用数学验证码

  1. 简单 — 没有外部 API 依赖项,没有 JavaScript SDK
  2. WordPress 插件 — 像“Math CAPTCHA”和“Really Simple CAPTCHA”这样的插件被广泛安装
  3. 低摩擦 - 用户发现简单的数学比图像选择更快
  4. 辅助功能 — 基于文本的数学验证码可与屏幕阅读器配合使用(与图像验证码不同)
  5. 旧系统 - 早于现代验证码服务的旧应用程序

常见问题

数学验证码对机器人有效吗?

任何可以解析 HTML 的机器人都可以轻松绕过纯文本数学验证码。基于图像的数学验证码稍微困难一些,但可以通过 OCR 轻松解决。数学验证码仅对最基本的垃圾邮件机器人有效。对于严格的机器人保护,请使用行为验证码系统,例如 reCAPTCHA 或 Cloudflare Turnstile。

如何在自动化中解决基于图像的数学验证码?

使用 CaptchaAI 等 OCR 服务从图像中提取方程,然后以编程方式解析和计算答案。 CaptchaAI 支持 27,500 多种图像验证码类型,包括数学方程图像。

可以在没有 OCR 的情况下解决基于文本的数学验证码吗?

是的。如果方程呈现为 HTML 文本(而不是图像),您可以使用正则表达式或 DOM 解析直接从页面源解析它。基于文本的数学验证码不需要 OCR。

数学验证码的最佳替代品是什么?

如果您想要低摩擦和强大的机器人检测功能,Cloudflare Turnstile 是最好的替代品。它以不可见的方式运行,不需要用户交互。为了更高的安全性,基于分数评估的reCAPTCHA v3是有效的。


概括

数学和逻辑验证码是最简单的挑战类型,常见于 WordPress 联系表单和遗留系统中。基于文本的版本可以直接从 HTML 解析。基于图像的版本需要 OCR 来读取方程式,然后通过简单的算术来计算答案。对于基于图像的数学验证码,请使用CaptchaAI 图像 OCR API提取并求解方程。虽然数学验证码很容易被绕过,但由于其简单性和可访问性的优势,它仍然很受欢迎。

相关文章

该文章已禁用评论。