跳到正文
DEV Community· Ravi Kumar·· 4 天前AI 評分44

我用 Go 構建了更難被 AI 和爬蟲讀取的動態 CAPTCHA

I Built a Motion CAPTCHA in Go That Is Harder for AI and Crawlers to Read

AI 導讀

Gotcha 是一款開源、可自行託管的 Go 動態 CAPTCHA 程式庫,將數字挑戰隱藏在移動視覺雜訊中,播放動畫後答案才會變得清晰。它設有簽名及限時挑戰 token、重播防護和五次作答上限,但並非能抵禦所有 AI 攻擊的方案;正式環境仍須配合速率限制及其他安全措施。

正文

Traditional CAPTCHAs are becoming easier for automated systems to interpret. OCR, computer-vision tools, browser automation, and vision-language models can often process static visual challenges.

So I built Gotcha: an open-source, self-hosted motion CAPTCHA library for Go.

Repository: https://github.com/ravikumariitk/gotcha

How it works

Gotcha hides a numeric challenge inside moving visual noise.

A single frame looks like noise, while the answer becomes readable when the animation plays. This makes the challenge harder for basic OCR, single-frame analysis, and simple crawler automation to interpret.

Gotcha is designed to create friction for automated visual reading. It is not marketed as AI-proof, because determined attackers may still use vision models, optical-flow analysis, browser agents, or other techniques.

Features

  • Signed and expiring challenge tokens
  • Replay protection
  • Five-attempt challenge limit
  • MP4 rendering when ffmpeg is available
  • PNG-frame fallback when MP4 encoding is unavailable
  • Configurable colors and textures
  • Self-hosted deployment
  • No external CAPTCHA service required
  • Standard Go HTTP integration
  • MIT licensed

Installation

go get github.com/ravikumariitk/gotcha@v0.1.0

Basic usage

package main

import gotcha "github.com/ravikumariitk/gotcha"

func main() {
    gotcha.ConfigureSecret("your-long-random-secret")

    challenge := gotcha.NewChallenge(
        5,
        "standard",
        gotcha.ParseAppearance(
            []string{"#0ea5e9", "#f8fafc"},
            "noise",
        ),
    )

    valid, latency, err := gotcha.VerifyCode(
        challenge.Token,
        "12345",
    )

    _, _, _ = valid, latency, err
}

A real application normally exposes two endpoints:

GET  /challenge
POST /verify

The browser receives the signed token and motion media from /challenge, keeps the token in memory, and submits the token with the user’s answer to /verify.

Important security note

Gotcha is a CAPTCHA and abuse-friction layer, not a complete authentication system.

For production applications, combine it with:

  • Rate limiting
  • MFA or step-up verification
  • Account lockout or throttling
  • Session security
  • Monitoring and alerting
  • Server-side authorization

Challenge state is stored in process memory, so distributed deployments should use request affinity or shared state.

Why open source?

The goal is to make the CAPTCHA mechanism transparent and controllable. Developers can inspect the token format, rendering behavior, verification rules, and fallback behavior instead of depending entirely on a third-party CAPTCHA service.

The motion-noise concept is related to the work documented in DrMikeMaik/GOTCHA, which explores motion-based human-versus-algorithm challenges and attack techniques.

Feedback is welcome—especially from Go developers and security researchers interested in testing the rendering approach and its resistance to automated visual analysis.

Try it

GOTCHA_SECRET="$(openssl rand -hex 32)" go run ./examples/login

Then open:

http://localhost:8080

GitHub: https://github.com/ravikumariitk/gotcha

來源:DEV Community · dev.to