Coder Social home page Coder Social logo

2captcha / 2captcha-go Goto Github PK

View Code? Open in Web Editor NEW
91.0 3.0 38.0 36 KB

Golang Module for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.

Home Page: https://2captcha.com

Go 100.00%
captcha-solving captcha-breaking anticaptcha 2captcha anti-captcha bypass-invisible-recaptcha bypass-on-captcha-recaptcha bypass-recaptcha-v2 bypasscaptcha captcha-bypass

2captcha-go's Introduction

Golang Module for 2Captcha API

The easiest way to quickly integrate 2Captcha into your code to automate solving of any type of captcha.

Installation

To install the api client, use this:

go get -u github.com/2captcha/2captcha-go

Configuration

Import the module like this:

import (
        "github.com/2captcha/2captcha-go"
)

Client instance can be created like this:

client := api2captcha.NewClient("YOUR_API_KEY")

There are few options that can be configured:

client.SoftId = 123
client.Callback = "https://your.site/result-receiver"
client.DefaultTimeout = 120
client.RecaptchaTimeout = 600
client.PollingInterval = 100

Client instance options

Option Default value Description
soft_id - your software ID obtained after publishing in 2captcha sofware catalog
callback - URL of your web-sever that receives the captcha recognition result. The URl should be first registered in pingback settings of your account
default_timeout 120 Timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from res.php API endpoint
recaptcha_timeout 600 Timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer from res.php API endpoint
polling_interval 10 Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended

IMPORTANT: once callback URL is defined for client instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. To get the answer manually use GetResult method

Solve captcha

When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.

Captcha options

Option Default Value Description
numeric 0 Defines if captcha contains numeric or other symbols see more info in the API docs
min_len 0 minimal answer lenght
max_len 0 maximum answer length
phrase 0 defines if the answer contains multiple words or not
case_sensitive 0 defines if the answer is case sensitive
calc 0 defines captcha requires calculation
lang - defines the captcha language, see the list of supported languages
hint_img - an image with hint shown to workers with the captcha
hint_text - hint or task text shown to workers with the captcha

Below you can find basic examples for every captcha type, check out the code below.

Basic example

Example below shows a basic solver call example with error handling.

cap := api2captcha.Normal{
   File: "/path/to/normal.jpg",
}

code, err := client.Solve(cap.ToRequest())
if err != nil {
	if err == api2captcha.ErrTimeout {
		log.Fatal("Timeout");
	} else if err == api2captcha.ErrApi {
		log.Fatal("API error");
	} else if err == api2captcha.ErrNetwork {
		log.Fatal("Network error");
	} else {
		log.Fatal(err);
	}
}
fmt.Println("code "+code)

Normal Captcha

To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.

cap := api2captcha.Normal{
   File: "/path/to/normal.jpg",
   Numeric: 4,
   MinLen: 4,
   MaxLen: 20,
   Phrase: true,
   CaseSensitive: true,
   Lang: "en",
   HintImgFile: "/path/to/hint.jpg",
   HintText: "Type red symbols",
}

Text Captcha

This method can be used to bypass a captcha that requires to answer a question provided in clear text.

cap := api2captcha.Text{
   Text: "If tomorrow is Saturday, what day is today?",
   Lang: "en",
}

ReCaptcha v2

Use this method to solve ReCaptcha V2 and obtain a token to bypass the protection.

cap := api2captcha.ReCaptcha{
   SiteKey: "6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-",
   Url: "https://mysite.com/page/with/recaptcha",
   Invisible: true,
   Action: "verify",
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

ReCaptcha v3

This method provides ReCaptcha V3 solver and returns a token.

cap := api2captcha.ReCaptcha{
   SiteKey: "6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-",
   Url: "https://mysite.com/page/with/recaptcha",
   Version: "v3",
   Action: "verify",
   Score: 0.3,
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

reCAPTCHA Enterprise

reCAPTCHA Enterprise can be used as reCAPTCHA V2 and reCAPTCHA V3. Below is a usage example for both versions.

// reCAPTCHA V2
cap :=  api2captcha.ReCaptcha({
   SiteKey: "6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-",
   Url: "https://mysite.com/page/with/recaptcha",
   Invisible: true,
   Action: "verify",
   Enterprise: true,
})

// reCAPTCHA V3
cap := api2captcha.ReCaptcha{
   SiteKey: "6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-",
   Url: "https://mysite.com/page/with/recaptcha",
   Version: "v3",
   Action: "verify",
   Score: 0.3,
   Enterprise: true,
}

req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

FunCaptcha

FunCaptcha (Arkoselabs) solving method. Returns a token.

cap := api2captcha.FunCaptcha{
   SiteKey: "69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC",
   Url: "https://mysite.com/page/with/funcaptcha",
   Surl: "https://client-api.arkoselabs.com",
   UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
   Data: map[string]string{"anyKey":"anyValue"},
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

GeeTest

Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.

cap := api2captcha.GeeTest{
   GT: "f2ae6cadcf7886856696502e1d55e00c",
   ApiServer: "api-na.geetest.com",
   Challenge: "12345678abc90123d45678ef90123a456b",
   Url: "https://mysite.com/captcha.html",
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

hCaptcha

Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.

cap := api2captcha.HCaptcha{
   SiteKey: "10000000-ffff-ffff-ffff-000000000001",
   Url: "https://mysite.com/captcha.html",
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

KeyCaptcha

Token-based method to solve KeyCaptcha.

cap := api2captcha.KeyCaptcha{
   UserId: 10,
   SessionId: "493e52c37c10c2bcdf4a00cbc9ccd1e8",
   WebServerSign: "9006dc725760858e4c0715b835472f22",
   WebServerSign2: "9006dc725760858e4c0715b835472f22",
   Url: "https://www.keycaptcha.ru/demo-magnetic/",
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

Capy

Token-based method to bypass Capy puzzle captcha.

cap := api2captcha.Capy{
   SiteKey: "PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v",
   Url: "https://www.mysite.com/captcha/",
}
req := cap.ToRequest()
req.SetProxy("HTTPS", "login:password@IP_address:PORT")
code, err := client.Solve(req)

Grid

Grid method is originally called Old ReCaptcha V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.

cap := api2captcha.Grid{
    File: "path/to/captcha.jpg",
    Rows: 3,
    Cols: 3,
    PreviousId: 0,
    CanSkip: false,
    Lang: "en",
    HintImageFile: "path/to/hint.jpg",
    HintText: "Select all images with an Orange",
}

Canvas

Canvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.

cap := api2captcha.Canvas{
    File: "path/to/captcha.jpg",
    PreviousId: 0,
    CanSkip: false,
    Lang: "en",
    HintImageFile: "path/to/hint.jpg",
    HintText: "Draw around apple",
}

ClickCaptcha

ClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.

cap := api2captcha.Coordinates{
    File: "path/to/captcha.jpg",
    Lang: "en",
    HintImageFile: "path/to/hint.jpg",
    HintText: "Connect the dots",
}

Rotate

This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.

cap := api2captcha.Rotate{
    File: "path/to/captcha.jpg",
    Angle: 40,
    Lang: "en",
    HintImageFile: "path/to/hint.jpg",
    HintText: "Put the images in the correct way",
}

GeeTestV4

Use this method to solve GeeTest v4. Returns the response in JSON.

cap := api2captcha.GeeTestV4{
    CaptchaId: "e392e1d7fd421dc63325744d5a2b9c73",
    Url: "https://www.site.com/page/",
}

Lemin Cropped Captcha

Use this method to solve Lemin Captcha challenge. Returns JSON with answer containing the following values: answer, challenge_id.

cap := Lemin{
   CaptchaId: "CROPPED_3dfdd5c_d1872b526b794d83ba3b365eb15a200b",
   Url:   "https://www.site.com/page/",
   DivId:     "lemin-cropped-captcha",
   ApiServer: "api.leminnow.com",
}

CloudflareTurnstile

Use this method to solve Cloudflare Turnstile. Returns JSON with the token.

cap := api2captcha.CloudflareTurnstile{
   SiteKey: "0x1AAAAAAAAkg0s2VIOD34y5",
   Url: "http://mysite.com/",
}

CyberSiARA

Use this method to solve CyberSiARA and obtain a token to bypass the protection.

cap := api2captcha.CyberSiARA{
   MasterUrlId: "12333-3123123",
   Url: "https://test.com",
   UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
}

DataDome

Use this method to solve DataDome and obtain a token to bypass the protection. To solve the DataDome captcha, you must use a proxy.

cap := api2captcha.DataDome{
  Url: "https://test.com",
  CaptchaUrl: "https://test.com/captcha/",
  Proxytype: "http",
  Proxy: "proxyuser:[email protected]:3128",
  UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
}

MTCaptcha

Use this method to solve MTCaptcha and obtain a token to bypass the protection.

cap := api2captcha.MTCaptcha{
  Url: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
  SiteKey: "MTPublic-DemoKey9M",
}

Yandex

Use this method to solve Yandex and obtain a token to bypass the protection.

cap := api2captcha.Yandex{
  Url: "https://rutube.ru",
  SiteKey: "Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV",
}

Friendly Captcha

Use this method to solve Friendly Captcha and obtain a token to bypass the protection.

cap := api2captcha.Friendly{
  Url: "https://example.com",
  SiteKey: "2FZFEVS1FZCGQ9",
}

CutCaptcha

Use this method to solve CutCaptcha and obtain a token to bypass the protection.

cap := api2captcha.CutCaptcha{
   MiseryKey: "a1488b66da00bf332a1488993a5443c79047e752",
   DataApiKey: "SAb83IIB",
   Url: "https://example.cc/foo/bar.html",
}

Amazon WAF

Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat mitigation for Amazon AWS. Returns JSON with the token.

cap := api2captcha.AmazonWAF {
    Iv: "CgAHbCe2GgAAAAAj",
    SiteKey: "0x1AAAAAAAAkg0s2VIOD34y5",
    Url: "https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest",
    Context: "9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb",
    ChallengeScript: "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js"
    CaptchaScript: "https://41bcdd4fb3cb.610cd090.us-east-1.captcha.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/captcha.js"
}

Other methods

Send / GetResult

These methods can be used for manual captcha submission and answer polling.

id, err := client.Send(cap.ToRequest())
if err != nil {
   log.Fatal(err);
}

time.Sleep(10 * time.Second)

code, err := client.GetResult(id)
if err != nil {
   log.Fatal(err);
}

if code == nil {
   log.Fatal("Not ready")
}

fmt.Println("code "+*code)

balance

Use this method to get your account's balance

balance, err := client.GetBalance()
if err != nil {
   log.Fatal(err);
}

report

Use this method to report good or bad captcha answer.

err := client.Report(id, true) // solved correctly
err := client.Report(id, false) // solved incorrectly

Proxies

You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha, keycaptcha, capy puzzle, lemin, turnstile, amazon waf, CyberSiARA, DataDome, MTCaptcha and etc. The proxy will be forwarded to the API to solve the captcha.

We have our own proxies that we can offer you. Buy residential proxies for avoid restrictions and blocks. Quick start.

2captcha-go's People

Contributors

brugeman avatar dzmitry-duboyski avatar kratzky avatar linuxsploit avatar pbadicean avatar ralphrimwell avatar uwynell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

2captcha-go's Issues

strconv.FormatInt base is 64? really?

panic info:

	panic: strconv: illegal AppendInt/FormatInt base

code

	if c.Rows != 0 {
		req.Params["recaptcharows"] = strconv.FormatInt(int64(c.Rows), 64)
	}
	if c.Cols != 0 {
		req.Params["recaptchacols"] = strconv.FormatInt(int64(c.Cols), 64)
	}
	if c.PreviousId != 0 {
		req.Params["previousID"] = strconv.FormatInt(int64(c.PreviousId), 64)
	}

base64 encoded images for normal captcha not working

base64 encoded image is not working, I keep getting a error stating no image was sent to the API. I made sure to leave the Image parameter blank and only leave the base64 parameter but I still get this error.

release is not actual

code have more actual version that release. For example method base64 for Normal captcha not found in release, but exist into last git commit !

Solve method doesn't return id of captcha task.

If you call client.Solve(req), you recieve token or error.
If you have desire to report captcha task - you have to use callback parameter to receive id of each task.
Simple solution would be to return id from this method too.

My implementation of this solution:

type SolveResult struct {
	ID    string
	Token string
}

func (c *Client) Solve(req Request) (SolveResult, error) {
	if c.Callback != "" {
		_, ok := req.Params["pingback"]
		if !ok {
			// set default pingback
			req.Params["pingback"] = c.Callback
		}
	}

	pingback, hasPingback := req.Params["pingback"]
	if pingback == "" {
		delete(req.Params, "pingback")
		hasPingback = false
	}

	_, ok := req.Params["soft_id"]
	if c.SoftId != 0 && !ok {
		req.Params["soft_id"] = strconv.FormatInt(int64(c.SoftId), 10)
	}

	id, err := c.Send(req)
	if err != nil {
		return SolveResult{}, err
	}

	// don't wait for result if Callback is used
	if hasPingback {
		return SolveResult{
			ID: id,
		}, nil
	}

	timeout := c.DefaultTimeout
	if req.Params["method"] == "userrecaptcha" {
		timeout = c.RecaptchaTimeout
	}

	result, resultErr := c.WaitForResult(id, timeout, c.PollingInterval)
	return SolveResult{ID: id, Token: result}, resultErr
}

Turnstile method appears to be broken.

Hello,
When attempting to use the cloudflare turnstile method to solve standalone turnstile captchas, it seems to always return an API error on the current version of the package.

for example, take the below code.

func handleTurnstileCaptcha() {
	cap := api2captcha.CloudflareTurnstile{SiteKey: "0x4AAAAAAADnPIDROrmt1Wwj", Url: "https://account.jagex.com"}
	solver := api2captcha.NewClient("CENSORED_API_KEY")
	solution, err := solver.Send(cap.ToRequest())
	if err != nil {
		zl.ErrorErr("Failed to solve captcha: ", err)
		log.Print(err)
		log.Print(cap.ToRequest())
		log.Print(solution)
	}
	if solution != "" {
		zl.Info("Got captcha solution: " + solution)
	}
}

This will always return api2captcha.ErrApi

2024/05/01 04:05:43 api2captcha: API error
2024/05/01 04:05:43 {map[method:turnstile pageurl:account.jagex.com sitekey:0x4AAAAAAADnPIDROrmt1Wwj] map[]}

When emulating the request this code sends in a http client we can see more details on the resulting error.

POST https://api.2captcha.com/createTask
Accept: application/json

{
    "clientKey":"CENSORED_API_KEY",
    "task": {
        "type":"TurnstileTaskProxyless",
        "websiteURL":"https://account.jagex.com",
        "websiteKey":"0x4AAAAAAADnPIDROrmt1Wwj"
    }
}
---
{
  "errorId": 110,
  "errorCode": "ERROR_BAD_PARAMETERS",
  "errorDescription": "The required captcha parameters in your reques are missing or have incorrect format. Please make sure your request payload has proper format for selected task type."
}

It seems the 2captcha api is expecting additional parameters, that the CloudflareTurnstile struct does not currently contain.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.