Skip to content

Commit 0f05947

Browse files
added turnstile captcha ; added custom domain for reCAPTCHA and hCaptcha
1 parent 02be846 commit 0f05947

File tree

5 files changed

+110
-2
lines changed

5 files changed

+110
-2
lines changed

Diff for: hcaptcha.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function test_api() {
1717
$params['sitekey'] = '1c7062c7-cae6-4e12-96fb-303fbec7fe4f';
1818
//$params['invisible'] = '1'; // if captcha is invisible - optional
1919

20+
// domain used in loading of hcaptcha interface, default: hcaptcha.com - optional
21+
// $params['domain'] = 'hcaptcha.com';
22+
2023
// extra parameters, useful for enterprise
2124
// submit userAgent from requests too, when this is used
2225
// $params['HcaptchaEnterprise'] = array(

Diff for: lib/imagetyperzapi.php

+40
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
define('HCAPTCHA_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadHCaptchaUser.ashx');
1616
define('TIKTOK_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadTikTokCaptchaUser.ashx');
1717
define('FUNCAPTCHA_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadFunCaptcha.ashx');
18+
define('TURNSTILE_ENDPOINT', 'http://captchatypers.com/captchaapi/Uploadturnstile.ashx');
1819
define('TASK_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadCaptchaTask.ashx');
1920
define('TASK_PUSH_ENDPOINT', 'http://captchatypers.com/CaptchaAPI/SaveCaptchaPush.ashx');
2021

@@ -178,6 +179,7 @@ function submit_recaptcha($d) {
178179
$data['enterprise_type'] = 'v3';
179180
}
180181
}
182+
if (isset($d['domain'])) $data["domain"] = $d['domain'];
181183
if (isset($d['v3_action'])) $data["captchaaction"] = $d['v3_action'];
182184
if (isset($d['v3_min_score'])) $data["score"] = (string)$d['v3_min_score'];
183185
if (isset($d['data-s'])) $data["data-s"] = (string)$d['data-s'];
@@ -343,6 +345,7 @@ function submit_hcaptcha($d) {
343345
}
344346
// check for user agent
345347
if (isset($d['user_agent'])) $data["useragent"] = $d['user_agent'];
348+
if (isset($d['domain'])) $data["apiEndpoint"] = $d['domain'];
346349
$response = Utils::post(HCAPTCHA_ENDPOINT, $data, USER_AGENT, $this->_timeout);
347350
if (strpos($response, 'ERROR:') !== false) {
348351
throw new Exception(trim(explode('ERROR:', $response)[1]));
@@ -429,6 +432,43 @@ function submit_funcaptcha($d) {
429432
return json_decode($response, true)[0]['CaptchaId'];
430433
}
431434

435+
function submit_turnstile($d) {
436+
$data = array(
437+
"action" => "UPLOADCAPTCHA",
438+
"pageurl" => $d['page_url'],
439+
"sitekey" => $d['sitekey'],
440+
);
441+
442+
if (!empty($this->_username)) {
443+
$data["username"] = $this->_username;
444+
$data["password"] = $this->_password;
445+
} else {
446+
$data['token'] = $this->_access_token;
447+
}
448+
449+
// affiliate
450+
if (!empty($this->_affiliate_id)) {
451+
$data['affiliateid'] = $this->_affiliate_id;
452+
}
453+
454+
// check for proxy
455+
if (isset($d['proxy'])) {
456+
// we have a good proxy here (at least both params supplied)
457+
// set it to the data/params
458+
$data["proxy"] = $d['proxy'];
459+
}
460+
// check for user agent
461+
if (isset($d['user_agent'])) $data["useragent"] = $d['user_agent'];
462+
if (isset($d['domain'])) $data["apiEndpoint"] = $d['domain'];
463+
if (isset($d['action'])) $data["taction"] = $d['action'];
464+
if (isset($d['cdata'])) $data["data"] = $d['cdata'];
465+
$response = Utils::post(TURNSTILE_ENDPOINT, $data, USER_AGENT, $this->_timeout);
466+
if (strpos($response, 'ERROR:') !== false) {
467+
throw new Exception(trim(explode('ERROR:', $response)[1]));
468+
}
469+
return json_decode($response, true)[0]['CaptchaId'];
470+
}
471+
432472
function submit_task($d) {
433473
$d['captchatype'] = '16';
434474
$d['action'] = 'UPLOADCAPTCHA';

Diff for: readme.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ For recaptcha submission there are two things that are required.
7171
- `3` - v3
7272
- `4` - enterprise v2
7373
- `5` - enterprise v3
74+
- domain - used in loading of reCAPTCHA interface, default: `www.google.com` (alternative: `recaptcha.net`) - `optional`
7475
- v3_min_score - minimum score to target for v3 recaptcha `- optional`
7576
- v3_action - action parameter to use for v3 recaptcha `- optional`
7677
- proxy - proxy to use when solving recaptcha, eg. `12.34.56.78:1234` or `12.34.56.78:1234:user:password` `- optional`
@@ -84,6 +85,7 @@ $params = array();
8485
$params['page_url'] = 'page_url_here';
8586
$params['sitekey'] = 'sitekey_here';
8687
// $params['type'] = 1; // optional
88+
// $params['domain'] = 'www.google.com'; // used in loading reCAPTCHA interface, default: www.google.com (alternative: recaptcha.net) - optional
8789
// $params['v3_min_score'] = 0.3; // min score to target when solving v3 - optional
8890
// $params['v3_action'] = 'homepage'; // action to use when solving v3 - optional
8991
// $params['proxy'] = '126.45.34.53:123'; // - optional
@@ -161,6 +163,9 @@ $params['page_url'] = 'https://your-site.com';
161163
$params['sitekey'] = '1c7062c7-cae6-4e12-96fb-303fbec7fe4f';
162164
//$params['invisible'] = '1'; // if captcha is invisible - optional
163165

166+
// domain used in loading of hcaptcha interface, default: hcaptcha.com - optional
167+
// $params['domain'] = 'hcaptcha.com';
168+
164169
// extra parameters, useful for enterprise
165170
// submit userAgent from requests too, when this is used
166171
// $params['HcaptchaEnterprise'] = array(
@@ -213,6 +218,22 @@ $params['data'] = '{"a":"b"}';
213218
$captcha_id = $i->submit_funcaptcha($params);
214219
```
215220

221+
### Turnstile (Cloudflare)
222+
223+
Requires page_url, sitekey
224+
225+
```php
226+
$params = array();
227+
$params['page_url'] = 'https://your-site.com';
228+
$params['sitekey'] = '0x4ABBBBAABrfvW5vKbx11FZ';
229+
//$params['domain'] = 'challenges.cloudflare.com'; // domain used in loading turnstile interface, default: challenges.cloudflare.com - optional
230+
//$params['action'] = 'homepage'; // used in loading turnstile interface, similar to reCAPTCHA - optional
231+
//$params['cdata'] = 'your cdata'; // used in loading turnstile interface - optional
232+
//$params['proxy'] = '126.45.34.53:123'; // - optional
233+
//$params['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'; // - optional
234+
$captcha_id = $i->submit_turnstile($params);
235+
```
236+
216237
### Task
217238

218239
Requires template_name, pageurl and usually variables
@@ -269,8 +290,7 @@ The response is a JSON object that looks like this:
269290
"CaptchaId": 176707908,
270291
"Response": "03AGdBq24PBCbwiDRaS_MJ7Z...mYXMPiDwWUyEOsYpo97CZ3tVmWzrB",
271292
"Cookie_OutPut": "",
272-
"Proxy_reason": "",
273-
"Recaptcha score": 0.0,
293+
"Proxy_reason": "",
274294
"Status": "Solved"
275295
}
276296
```

Diff for: recaptcha.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function test_api() {
2626
//
2727
//$params['type'] = 1; // optional
2828
//
29+
//$params['domain'] = 'www.google.com'; // used in loading reCAPTCHA interface, default: www.google.com (alternative: recaptcha.net) - optional
2930
//$params['v3_min_score'] = 0.3; // min score to target when solving v3 - optional
3031
//$params['v3_action'] = 'homepage'; // action to use when solving v3 - optional
3132
// proxy to use when solving recaptcha, works with auth as well 126.45.34.53:123:user:password

Diff for: turnstile.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/php
2+
3+
<?php
4+
require('lib/imagetyperzapi.php'); // load API library
5+
6+
function test_api() {
7+
# grab token from https://imagetyperz.com
8+
$access_token = 'your_access_token';
9+
$i = new ImagetyperzAPI($access_token); // init API lib obj
10+
11+
$balance = $i->account_balance(); // get balance
12+
echo "Balance: $balance\n";
13+
14+
echo "Solving captcha ...\n";
15+
$params = array();
16+
$params['page_url'] = 'https://your-site.com';
17+
$params['sitekey'] = '0x4ABBBBAABrfvW5vKbx11FZ';
18+
//$params['domain'] = 'challenges.cloudflare.com'; // domain used in loading turnstile interface, default: challenges.cloudflare.com - optional
19+
//$params['action'] = 'homepage'; // used in loading turnstile interface, similar to reCAPTCHA - optional
20+
//$params['cdata'] = 'your cdata'; // used in loading turnstile interface - optional
21+
//$params['proxy'] = '126.45.34.53:123'; // - optional
22+
//$params['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'; // - optional
23+
$captcha_id = $i->submit_turnstile($params);
24+
echo "Waiting for captcha to be solved...\n";
25+
$response = null;
26+
while($response === null) {
27+
sleep(10);
28+
$response = $i->retrieve_response($captcha_id);
29+
}
30+
echo "Response: ";
31+
var_dump($response);
32+
}
33+
34+
// Main method
35+
function main() {
36+
try {
37+
test_api(); // test API
38+
} catch (Exception $ex) {
39+
echo "Error occurred: " . $ex->getMessage(); // print error
40+
}
41+
}
42+
43+
main(); // run main function
44+
?>

0 commit comments

Comments
 (0)