
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
TwoCaptcha is a Ruby API for 2Captcha - 2Captcha.com
Add this line to your application's Gemfile:
gem 'two_captcha'
And then execute:
$ bundle
Or install it yourself as:
$ gem install two_captcha
client = TwoCaptcha.new('my_key')
There are two types of methods available: decode
and decode!
:
decode
does not raise exceptions.decode!
may raise a TwoCaptcha::Error
if something goes wrong.If the solution is not available, an empty solution object will be returned.
captcha = client.decode_image!(url: 'http://bit.ly/1xXZcKo')
captcha.text # CAPTCHA solution
captcha.id # CAPTCHA numeric id
You can specify file
, path
, raw
, raw64
and url
when decoding an image.
client.decode_image!(file: File.open('path/to/my/captcha/file', 'rb'))
client.decode_image!(path: 'path/to/my/captcha/file')
client.decode_image!(raw: File.open('path/to/my/captcha/file', 'rb').read)
client.decode_image!(raw64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
client.decode_image!(url: 'http://bit.ly/1xXZcKo')
You may also specify any POST parameters specified at https://2captcha.com/setting.
captcha = client.decode_recaptcha_v2!(
googlekey: 'xyz',
pageurl: 'http://example.com/example=1',
)
# The response will be a text (token), which you can access with the `text` method.
captcha.text
"03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
Parameters:
googlekey
: the Google key for the reCAPTCHA.pageurl
: the URL of the page with the reCAPTCHA challenge.captcha = client.decode_recaptcha_v3!(
googlekey: 'xyz',
pageurl: 'http://example.com/example=1',
action: 'verify',
min_score: 0.3, # OPTIONAL
)
# The response will be a text (token), which you can access with the `text` method.
captcha.text
"03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
Parameters:
googlekey
: the Google key for the reCAPTCHA.pageurl
: the URL of the page with the reCAPTCHA challenge.action
: the action name used by the CAPTCHA.min_score
: optional parameter. The minimal score needed for the CAPTCHA resolution. Defaults to 0.3
.About the
action
parameter: in order to find out what this is, you need to inspect the JavaScript code of the website looking for a call to thegrecaptcha.execute
function.
// Example grecaptcha.execute('6Lc2fhwTAAAAAGatXTzFYfvlQMI2T7B6ji8UVV_f', { action: "examples/v3scores" })
About the
min_score
parameter: it's strongly recommended to use a minimum score of0.3
as higher scores are rare.
captcha = client.decode_hcaptcha!(
sitekey: 'xyz',
pageurl: 'http://example.com/example=1',
)
captcha.text
"P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiNnpWV..."
captcha = client.decode_amazon_waf!(
sitekey: 'xyz',
pageurl: 'http://example.com/example=1',
iv: 'A1A1A1A1A1A1A1A1',
context: 'ABcd...',
challenge_script: 'http://example.com/challenge.js',
)
puts captcha.text
{"captcha_voucher":"eyJ0...","existing_token":"f2ae6..."}
Parameters:
website_key
: the site key for the hCatpcha.website_url
: the URL of the page with the hCaptcha challenge.You are allowed to use custom options like proxy
, proxytype
or userAgent
whenever the
2Captcha API supports it. Example:
options = {
sitekey: 'xyz',
pageurl: 'http://example.com/example=1',
proxy: 'login:password@123.123.123.123:3128',
userAgent: 'user agent',
}
captcha = client.decode_hcaptcha!(options)
captcha = client.captcha('130920620') # with 130920620 being the CAPTCHA id
client.report!('130920620', 'reportbad') # with 130920620 being the CAPTCHA id
# returns `true` if successfully reported
client.report!('256892751', 'reportgood') # with 256892751 being the CAPTCHA id
# returns `true` if successfully reported
client.balance
# returns a Float balance in USD.
client.stats(Date.new(2022, 10, 7))
# returns an XML string with your usage statistics.
The API is thread-safe, which means it is perfectly fine to share a client instance between multiple threads.
TwoCaptcha don't require specific dependencies. That saves you memory and avoid conflicts with other gems.
Any format you use in the decode_image!
method (url
, file
, path
, raw
or raw64
)
will always be converted to a raw64
, which is a base64-encoded binary string.
So, if you already have this format on your end, there is no need for convertions
before calling the API.
Our recomendation is to never convert your image format, unless needed. Let the gem convert internally. It may save you resources (CPU, memory and IO).
TwoCaptcha gem uses Semantic Versioning.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)All contributors: https://github.com/infosimples/two_captcha/graphs/contributors
MIT License. Copyright (C) 2011-2022 Infosimples. https://infosimples.com/
FAQs
Unknown package
We found that two_captcha demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.