gocaptcha

package module
v0.0.0-...-04d17fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2022 License: MIT Imports: 10 Imported by: 0

README

gocaptcha

An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

Installation

Run the following command in your project folder: go get github.com/Alexvec00/gocaptcha

Support

Type 2Captcha AntiCaptcha CapMonster Cloud
RecaptchaV2
RecaptchaV3
Image Recaptcha
HCaptcha

Software like XEVil and CapMonster are also supported, but it gets a little trickier. Such software runs on a local ip:port so you must specify that with CustomServiceUrl (don't include the protocol as it defaults to http)

If you intend to use XEVil or CapMonster with this program you should check which API it supports (Either 2Captcha or AntiCaptcha). Don't forget to add firewall rules and host the captcha software on a public port when using XEVil or CapMonster between different machines.

Usage

RecaptchaV2
    payload := gocaptcha.RecaptchaV2Payload{
	EndpointUrl:   "https://www.google.com/recaptcha/api2/demo",
        EndpointKey:   "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
        ServiceApiKey: "key",
        ServiceName:   "2Captcha",
	}
	
    captcha, err := gocaptcha.SolveRecaptchaV2(&payload)
    
    // use captcha.ReportGoodRecaptcha() or captcha.ReportBadCaptcha() to help the provider improve their services.

These are all supported variables to use in RecaptchaV2Payload:

    	// This is the endpoint that has Recaptcha Protection
EndpointUrl string

// This is the Recaptcha Key
// Can be found on the Endpoint URL page
EndpointKey string

// The API key for your captcha service
ServiceApiKey string

// The name of the captcha service
// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
ServiceName string

// Enable if endpoint has invisible Recaptcha V2
IsInvisibleCaptcha bool

// Set this in case you're using a custom solver like CapMonster (not cloud)
CustomServiceUrl string

// The time to wait before starting to poll result
InitialWaitTime int

// The time to wait between polling results
PollInterval int

// Max amount of poll attempts
MaxRetries int
RecaptchaV3
    payload := gocaptcha.RecaptchaV3Payload{
EndpointUrl:   "https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php",
EndpointKey:   "6LdyC2cUAAAAACGuDKpXeDorzUDWXmdqeg-xy696",
ServiceApiKey: "key",
ServiceName:   "2Captcha",
Action:        "examples/v3scores",
}

captcha, err := gocaptcha.SolveRecaptchaV3(&payload)

// use captcha.ReportGoodRecaptcha() or captcha.ReportBadCaptcha() to help the provider improve their services.

These are all supported variables to use in RecaptchaV3Payload:

// This is the endpoint that has Recaptcha Protection
EndpointUrl string

// This is the Recaptcha Key
// Can be found on the Endpoint URL page
EndpointKey string

// The API key for your captcha service
ServiceApiKey string

// The name of the captcha service
// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
ServiceName string

// The action name of the recaptcha, you can find it in source code of site
Action string

// Set this in case you're using a custom solver like CapMonster (not cloud)
CustomServiceUrl string

// Set to true if it's V3 Enterprise
IsEnterprise bool

// Defaults to 0.3, accepted values are 0.3, 0.6, 0.9
MinScore float32

// The time to wait before starting to poll result
InitialWaitTime int

// The time to wait between polling results
PollInterval int

// Max amount of poll attempts
MaxRetries int
HCaptcha
    payload := gocaptcha.HCaptchaPayload{
        EndpointUrl:   "https://www.hcaptcha.com/",
        EndpointKey:   "00000000-0000-0000-0000-000000000000",
        ServiceApiKey: "key",
        ServiceName:   "2Captcha",
    }

    captcha, err := gocaptcha.SolveHCaptcha(&payload)

    // use captcha.ReportGoodRecaptcha() or captcha.ReportBadCaptcha() to help the provider improve their services.

These are all supported variables to use in HCaptchaPayload:

// This is the endpoint that has Recaptcha Protection
EndpointUrl string

// This is the HCaptcha Key
// Can be found on the Endpoint URL page
EndpointKey string

// The API key for your captcha service
ServiceApiKey string

// The name of the captcha service
// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
ServiceName string

// Set this in case you're using a custom solver like CapMonster (not cloud)
CustomServiceUrl string

// The time to wait before starting to poll result
InitialWaitTime int

// The time to wait between polling results
PollInterval int

// Max amount of poll attempts
MaxRetries int
Image Captcha
payload := gocaptcha.ImageCaptchaPayload{
    ServiceApiKey: "key", // your api key
    ServiceName:   "2Captcha", // the provider, can be 2Captcha, AntiCaptcha or Capmonster Cloud
    Base64String:  imageBase64, // the image converted to a base64 string
}

captcha, err := gocaptcha.SolveImageCaptcha(&payload)

// don't mind the naming, this also works for image captcha's.
// use captcha.ReportGoodRecaptcha() or captcha.ReportBadCaptcha() to help the provider improve their services.

These are all supported variables to use in ImageCaptchaPayload:

    // This is the base64 that represents the image captcha
	Base64String string

	// The API key for your captcha service
	ServiceApiKey string

	// The name of the captcha service
	// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
	ServiceName string

	// Set this in case you're using a custom solver like CapMonster (not cloud)
	CustomServiceUrl string

	// Set to true if captcha is case sensitive
	CaseSensitive bool

	// Set this if the human solver needs additional information
	// about how to solve the captcha
	InstructionsForSolver string

	// The time to wait before starting to poll result
	InitialWaitTime int

	// The time to wait between polling results
	PollInterval int

	// Max amount of poll attempts
	MaxRetries int

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptchaResponse

type CaptchaResponse struct {
	// The task ID of the solved captcha
	TaskId string

	// The answer of the solved captcha
	Solution string

	// The service used for solving the captcha
	// this is used when reporting a good/bad captcha
	Service string

	// The service endpoint, it's copied from CustomServiceUrl
	Endpoint string

	// The API key for the service that's used for solving
	ServiceApiKey string
}

func SolveHCaptcha

func SolveHCaptcha(payload *HCaptchaPayload) (*CaptchaResponse, error)

SolveHCaptcha solves hCaptcha

func SolveImageCaptcha

func SolveImageCaptcha(payload *ImageCaptchaPayload) (*CaptchaResponse, error)

SolveImageCaptcha solves an image captcha

func SolveRecaptchaV2

func SolveRecaptchaV2(payload *RecaptchaV2Payload) (*CaptchaResponse, error)

SolveRecaptchaV2 solves recaptcha V2

func SolveRecaptchaV3

func SolveRecaptchaV3(payload *RecaptchaV3Payload) (*CaptchaResponse, error)

SolveRecaptchaV3 solves recaptcha V3

func (*CaptchaResponse) ReportBadRecaptcha

func (response *CaptchaResponse) ReportBadRecaptcha()

func (*CaptchaResponse) ReportGoodRecaptcha

func (response *CaptchaResponse) ReportGoodRecaptcha()

type HCaptchaPayload

type HCaptchaPayload struct {
	// This is the endpoint that has Recaptcha Protection
	EndpointUrl string

	// This is the HCaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string

	// The API key for your captcha service
	ServiceApiKey string

	// The name of the captcha service
	// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
	ServiceName string

	// Set this in case you're using a custom solver like CapMonster (not cloud)
	CustomServiceUrl string

	// The time to wait before starting to poll result
	InitialWaitTime int

	// The time to wait between polling results
	PollInterval int

	// Max amount of poll attempts
	MaxRetries int
}

func (*HCaptchaPayload) CreateHCaptchaResponse

func (p *HCaptchaPayload) CreateHCaptchaResponse() *CaptchaResponse

func (*HCaptchaPayload) SetDefaultValues

func (p *HCaptchaPayload) SetDefaultValues()

type ImageCaptchaPayload

type ImageCaptchaPayload struct {
	// This is the base64 that represents the image captcha
	Base64String string

	// The API key for your captcha service
	ServiceApiKey string

	// The name of the captcha service
	// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
	ServiceName string

	// Set this in case you're using a custom solver like CapMonster (not cloud)
	CustomServiceUrl string

	// Set to true if captcha is case sensitive
	CaseSensitive bool

	// Set this if the human solver needs additional information
	// about how to solve the captcha
	InstructionsForSolver string

	// The time to wait before starting to poll result
	InitialWaitTime int

	// The time to wait between polling results
	PollInterval int

	// Max amount of poll attempts
	MaxRetries int
}

func (*ImageCaptchaPayload) CreateImageCaptchaResponse

func (p *ImageCaptchaPayload) CreateImageCaptchaResponse() *CaptchaResponse

func (*ImageCaptchaPayload) SetDefaultValues

func (p *ImageCaptchaPayload) SetDefaultValues()

type RecaptchaV2Payload

type RecaptchaV2Payload struct {
	// This is the endpoint that has Recaptcha Protection
	EndpointUrl string

	// This is the Recaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string

	// The API key for your captcha service
	ServiceApiKey string

	// The name of the captcha service
	// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
	ServiceName string

	// Enable if endpoint has invisible Recaptcha V2
	IsInvisibleCaptcha bool

	// Set this in case you're using a custom solver like CapMonster (not cloud)
	CustomServiceUrl string

	// The time to wait before starting to poll result
	InitialWaitTime int

	// The time to wait between polling results
	PollInterval int

	// Max amount of poll attempts
	MaxRetries int

	// Enable if endpoint has enterprise Recaptcha V2
	IsEnterpriseCaptcha bool
}

func (*RecaptchaV2Payload) CreateRecaptchaResponse

func (p *RecaptchaV2Payload) CreateRecaptchaResponse() *CaptchaResponse

func (*RecaptchaV2Payload) SetDefaultValues

func (p *RecaptchaV2Payload) SetDefaultValues()

type RecaptchaV3Payload

type RecaptchaV3Payload struct {
	// This is the endpoint that has Recaptcha Protection
	EndpointUrl string

	// This is the Recaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string

	// The API key for your captcha service
	ServiceApiKey string

	// The name of the captcha service
	// Can be AntiCaptcha, 2Captcha or CapMonster Cloud
	ServiceName string

	// The action name of the recaptcha, you can find it in source code of site
	Action string

	// Set this in case you're using a custom solver like CapMonster (not cloud)
	CustomServiceUrl string

	// Set to true if it's V3 Enterprise
	IsEnterprise bool

	// Defaults to 0.3, accepted values are 0.3, 0.6, 0.9
	MinScore float32

	// The time to wait before starting to poll result
	InitialWaitTime int

	// The time to wait between polling results
	PollInterval int

	// Max amount of poll attempts
	MaxRetries int
}

func (*RecaptchaV3Payload) CreateRecaptchaResponse

func (p *RecaptchaV3Payload) CreateRecaptchaResponse() *CaptchaResponse

func (*RecaptchaV3Payload) SetDefaultValues

func (p *RecaptchaV3Payload) SetDefaultValues()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL