Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/matthew17-21/captcha-tools/captchatools-go

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/matthew17-21/captcha-tools/captchatools-go

  • v0.0.0-20241028180230-0facd0a099ec
  • Source
  • Go
  • Socket score

Version published
Created
Source

Captcha Tools (Go)

Go package to help solve captchas with Capmonster, 2Captcha and Anticaptcha API's!

2.0.0

What's new

  1. Get Balance Support
  2. Proxy Support
  3. User Agent Support
  4. Text image captcha support
  5. Refund support / Report answers support
  6. AntiCaptcha SoftID support

Breaking Changes

  • Changed the type of site from type int to type site
    • This affects the NewHarvester() param
  • Returns a CaptchaAnswer object rather than just the captcha token
  • Made captchas their own type

Upgrading to 2.0.0

  • When passing in the config, instead of manually declaring the CaptchaType field, use a preset type such as captchatools.ImageCaptcha
    • See captcha types
  • Instead of a captcha token being returned, a CaptchaAnswer is returned. To get the captcha answer, you must call the .Token field from the returned answer. See Examples.

Install

go get github.com/Matthew17-21/Captcha-Tools/captchatools-go

To update:

go get -u github.com/Matthew17-21/Captcha-Tools/captchatools-go

How to use

Basic usage

package main

import (
	"fmt"

	captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)

func main() {
	solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
		Api_key:     "ENTER YOUR API KEY HERE",
		Sitekey:     "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
		CaptchaURL:  "https://www.google.com/recaptcha/api2/demo",
		CaptchaType: captchatools.V2Captcha,
	})
	if err != nil {
		...
	}
	answer, err := solver.GetToken()
	if err != nil {
		switch err {
		case captchatools.ErrBanned:
			...
		case captchatools.ErrAddionalDataMissing:
			...
		}
	}

	fmt.Println("Captcha ID:", answer.Id())
	fmt.Println("Captcha token:", answer.Token)

	// ........Use captcha token......
	answer.Report(true) // report good
	// or
	answer.Report(false) // report bad / request refund
}

NewHarvester() Parameters:

ParameterRequiredTypeDescription
solving_sitetrueint (iota)The captcha solving site that will be used. Refer to the site IDs. Alternatively, you can use shortcuts such as captchatools.AnticaptchaSite
Configtruecaptchatools.ConfigConfigurations for the captchas you are solving.

Config struct fields:

FieldRequiredTypeDescription
Api_keytrueStringThe API Key for the captcha solving site
SitekeytrueStringSitekey from the site where captcha is loaded
CaptchaURLtrueStringURL where the captcha is located
CaptchaTypetruecaptchaTypeType of captcha you are solving. See captcha types
ActionfalseStringAction that is associated with the V3 captcha.
This param is only required when solving V3 captchas
IsInvisibleCaptchafalseboolIf the captcha is invisible or not.
This param is only required when solving invisible captchas
MinScorefalsefloat32Minimum score for v3 captchas.
This param is only required when solving V3 and it needs a higher / lower score
SoftIDfalseint2captcha Developer ID.
Developers get 10% of spendings of their software users.

AdditionalData struct fields:

FieldRequiredTypeDescription
B64ImgfalseStringBase64 encoded captcha image
This param is only required when solving image captchas
Proxyfalse*ProxyProxy to be used to solve captchas.
This will make the captcha be solved from the proxy ip
ProxyTypefalsestringType of the proxy being used. Options are:
HTTP, HTTPS, SOCKS4, SOCKS5
UserAgentfalsestringUserAgent that will be passed to the service and used to solve the captcha
RQDatafalsestringCustom data that is used in some implementations of hCaptcha. Most of the times, you want to set the IsInvisibleCaptcha param to true.

Examples

Example - V2 Captcha / Basic usage
package main

import (
	"fmt"

	captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)

func main() {
	solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
		Api_key:     "ENTER YOUR API KEY HERE",
		Sitekey:     "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
		CaptchaURL:  "https://www.google.com/recaptcha/api2/demo",
		CaptchaType: captchatools.V2Captcha,
	})
	if err != nil {
		...
	}
	answer, err := solver.GetToken()
	if err != nil {
		switch err {
		case captchatools.ErrBanned:
			...
		case captchatools.ErrAddionalDataMissing:
			...
		}
	}

	fmt.Println("Captcha ID:", answer.Id())
	fmt.Println("Captcha token:", answer.Token)

	// ........Use captcha token......
	answer.Report(true) // report good
	// or
	answer.Report(false) // report bad / request refund
}

Example - V3 Captcha
func v3Example() {
	solver, err := captchatools.NewHarvester(captchatools.AnticaptchaSite, &captchatools.Config{
		Api_key:     "ENTER YOUR API KEY HERE",
		Sitekey:     "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
		CaptchaURL:  "..........",
		CaptchaType: captchatools.V3Captcha,
		Action:      "submit",
		MinScore:    0.9,
	})
	if err != nil {
		panic(err)
	}
	answer, err := solver.GetToken()
	if err != nil {
		switch err {
		case captchatools.ErrBanned:
		case captchatools.ErrAddionalDataMissing:
		}
	}

	fmt.Println("Captcha ID:", answer.Id())
	fmt.Println("Captcha token:", answer.Token)

	// ........Use captcha token......
	answer.Report(true) // report good
	// or
	answer.Report(false) // report bad / request refund

}

Example - Image captcha
package main

import (
	"fmt"

	captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)

func image_captcha() {
	solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
		Api_key:     "ENTER YOUR API KEY HERE",
		CaptchaType: captchatools.ImageCaptcha,
	})
	if err != nil {
		panic(err)
	}

	answer, err := solver.GetToken(&captchatools.AdditionalData{
		B64Img: "BASE64_ENCODED_IMAGE",
	})
	if err != nil {
		switch err {
		case captchatools.ErrBanned:
		case captchatools.ErrAddionalDataMissing:
		}
	}

	fmt.Println("Captcha ID:", answer.Id())
	fmt.Println("Captcha token:", answer.Token)

	// ........Use captcha token......
	answer.Report(true) // report good
	// or
	answer.Report(false) // report bad / request refund

}

Example - Additional captcha data
package main

import (
	"fmt"

	captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)

func addtional_data() {
	solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
		Api_key:     "ENTER YOUR API KEY HERE",
		Sitekey:     "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
		CaptchaURL:  "https://www.google.com/recaptcha/api2/demo",
		CaptchaType: captchatools.V2Captcha,
	})
	if err != nil {
		panic(err)
	}

	// The following data is OPTIONAL and is not required to solve captchas
	proxy, err := captchatools.NewProxy("IP:PORT:USER:PASS")
	answer, err := solver.GetToken(&captchatools.AdditionalData{
		B64Img:    "BASE64_ENCODED_IMAGE",
		Proxy:     proxy,
		ProxyType: "http",
		UserAgent: "SOME_USER_AGENT",
	})
	if err != nil {
		switch err {
		case captchatools.ErrBanned:
		case captchatools.ErrAddionalDataMissing:
		}
	}

	fmt.Println("Captcha ID:", answer.Id())
	fmt.Println("Captcha token:", answer.Token)

	// ........Use captcha token......
	answer.Report(true) // report good
	// or
	answer.Report(false) // report bad / request refund

}

Supported Sites

Site-Specific Support:

Captcha Type2CaptchaAnticaptchaCapmonsterCapsolverCaptchaAI
Recaptcha V2:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Recaptcha V3:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Hcaptcha:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
HcaptchaTurbo:x::x::x::white_check_mark::x:
Image Captcha:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Cloudflare Turnstile:white_check_mark::white_check_mark::white_check_mark::x::x:
Funcaptcha:x::x::x::x::x:
GeeTest:x::x::x::x::x:
Amazon WAF:x::x::x::x::x:

Recommendations

  1. For 2Captcha, don't run more than 60 tasks per API key.
  2. Handle errors appropriately.
    • If a ErrNoBalance is thrown, tasks should stop. Some sites will temporarily ban IP's if constant requests come in.

Errors

ErrorsReturned When
ErrNoBalanceBalance is below 0 for captcha solving site
ErrWrongAPIKeyIncorrect API Key for captcha solving site
ErrWrongSitekeyIncorrect sitekey
ErrIncorrectCapTypeIncorrectly chose a captcha type. When initializing a new harvester. Refer to the captcha types
ErrNoHarvesterWhen the user did not / incorrectly chose a captcha harvester. Refer to the "how to use" guide
Error Handling
package main

import (
	"fmt"

	captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)

func main() {
	solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
		Api_key:     "ENTER YOUR API KEY HERE",
		Sitekey:     "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
		CaptchaURL:  "https://www.google.com/recaptcha/api2/demo",
		CaptchaType: captchatools.V2Captcha,
	})
	if err != nil {
		...
	}
	answer, err := solver.GetToken()
	if err != nil {
		switch err {
		case captchatools.ErrBanned:
			...
		case captchatools.ErrAddionalDataMissing:
			...
		}
	}
}

TODOs

  • Add DeadByCaptcha
  • Nocaptchaai (maybe)
  • Context Support
  • FunCaptcha Support
  • Cookie Support

FAQs

Package last updated on 28 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc