Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/instance/captcha.go
310 views
1
// Copyright (C) 2021 github.com/V4NSH4J
2
//
3
// This source code has been released under the GNU Affero General Public
4
// License v3.0. A copy of this license is available at
5
// https://www.gnu.org/licenses/agpl-3.0.en.html
6
7
package instance
8
9
import (
10
"bytes"
11
"encoding/json"
12
"fmt"
13
"io/ioutil"
14
"net/http"
15
"net/url"
16
"strconv"
17
"strings"
18
"time"
19
20
"github.com/V4NSH4J/discord-mass-dm-GO/utilities"
21
)
22
23
func (in *Instance) SolveCaptcha(sitekey string, cookie string, rqData string, rqToken string, url string) (string, error) {
24
var solution string
25
var err error
26
switch true {
27
case in.Config.CaptchaSettings.Self != "":
28
solution, err = in.self(sitekey, rqData)
29
case in.Config.CaptchaSettings.CaptchaAPI == "invisifox.com":
30
solution, err = in.invisifox(sitekey, cookie, rqData)
31
case in.Config.CaptchaSettings.CaptchaAPI == "captchaai.io":
32
solution, err = in.captchaAI(sitekey, rqData)
33
case utilities.Contains([]string{"capmonster.cloud", "anti-captcha.com"}, in.Config.CaptchaSettings.CaptchaAPI):
34
solution, err = in.Capmonster(sitekey, url, rqData, cookie)
35
case utilities.Contains([]string{"2captcha.com", "rucaptcha.com"}, in.Config.CaptchaSettings.CaptchaAPI):
36
solution, err = in.twoCaptcha(sitekey, rqData, url)
37
case in.Config.CaptchaSettings.CaptchaAPI == "capcat.xyz":
38
solution, err = in.CapCat(sitekey, rqData)
39
default:
40
return "", fmt.Errorf("unsupported captcha api: %s", in.Config.CaptchaSettings.CaptchaAPI)
41
}
42
if err != nil {
43
return "", err
44
}
45
utilities.CaptchaSolved(in.CensorToken(), solution)
46
return solution, nil
47
}
48
49
/*
50
2Captcha/RuCaptcha
51
*/
52
53
func (in *Instance) twoCaptcha(sitekey, rqdata, site string) (string, error) {
54
var solvedKey string
55
inEndpoint := "https://2captcha.com/in.php"
56
inURL, err := url.Parse(inEndpoint)
57
if err != nil {
58
return solvedKey, fmt.Errorf("error while parsing url %v", err)
59
}
60
q := inURL.Query()
61
if in.Config.CaptchaSettings.ClientKey == "" {
62
return solvedKey, fmt.Errorf("client key is empty")
63
}
64
q.Set("key", in.Config.CaptchaSettings.ClientKey)
65
q.Set("method", "hcaptcha")
66
q.Set("sitekey", sitekey)
67
// Page URL same as referer in headers
68
q.Set("pageurl", "https://discord.com")
69
q.Set("userAgent", in.UserAgent)
70
q.Set("json", "1")
71
q.Set("soft_id", "3359")
72
if rqdata != "" {
73
q.Set("data", rqdata)
74
q.Set("invisible", "0")
75
}
76
if in.Config.ProxySettings.ProxyForCaptcha {
77
q.Set("proxy", in.Proxy)
78
q.Set("proxytype", "http")
79
}
80
inURL.RawQuery = q.Encode()
81
if in.Config.CaptchaSettings.CaptchaAPI == "2captcha.com" {
82
inURL.Host = "2captcha.com"
83
} else if in.Config.CaptchaSettings.CaptchaAPI == "rucaptcha.com" {
84
inURL.Host = "rucaptcha.com"
85
}
86
inEndpoint = inURL.String()
87
req, err := http.NewRequest(http.MethodGet, inEndpoint, nil)
88
if err != nil {
89
return solvedKey, fmt.Errorf("error creating request [%v]", err)
90
}
91
resp, err := http.DefaultClient.Do(req)
92
if err != nil {
93
return solvedKey, fmt.Errorf("error sending request [%v]", err)
94
}
95
defer resp.Body.Close()
96
body, err := ioutil.ReadAll(resp.Body)
97
if err != nil {
98
return solvedKey, fmt.Errorf("error reading response [%v]", err)
99
}
100
var inResponse twoCaptchaSubmitResponse
101
err = json.Unmarshal(body, &inResponse)
102
if err != nil {
103
return solvedKey, fmt.Errorf("error unmarshalling response [%v]", err)
104
}
105
if inResponse.Status != 1 {
106
return solvedKey, fmt.Errorf("error %v", inResponse.Request)
107
}
108
outEndpoint := "https://2captcha.com/res.php"
109
outURL, err := url.Parse(outEndpoint)
110
if err != nil {
111
return solvedKey, fmt.Errorf("error while parsing url %v", err)
112
}
113
in.LastIDstr = inResponse.Request
114
q = outURL.Query()
115
q.Set("key", in.Config.CaptchaSettings.ClientKey)
116
q.Set("action", "get")
117
q.Set("id", inResponse.Request)
118
q.Set("json", "1")
119
if in.Config.CaptchaSettings.CaptchaAPI == "2captcha.com" {
120
outURL.Host = "2captcha.com"
121
} else if in.Config.CaptchaSettings.CaptchaAPI == "rucaptcha.com" {
122
outURL.Host = "rucaptcha.com"
123
}
124
outURL.RawQuery = q.Encode()
125
outEndpoint = outURL.String()
126
127
time.Sleep(10 * time.Second)
128
now := time.Now()
129
for {
130
if time.Since(now) > time.Duration(in.Config.CaptchaSettings.Timeout)*time.Second {
131
return solvedKey, fmt.Errorf("captcha response from 2captcha timedout")
132
}
133
req, err = http.NewRequest(http.MethodGet, outEndpoint, nil)
134
if err != nil {
135
return solvedKey, fmt.Errorf("error creating request [%v]", err)
136
}
137
resp, err := http.DefaultClient.Do(req)
138
if err != nil {
139
return solvedKey, fmt.Errorf("error sending request [%v]", err)
140
}
141
defer resp.Body.Close()
142
body, err := ioutil.ReadAll(resp.Body)
143
if err != nil {
144
return solvedKey, fmt.Errorf("error reading response [%v]", err)
145
}
146
var outResponse twoCaptchaSubmitResponse
147
err = json.Unmarshal(body, &outResponse)
148
if err != nil {
149
return solvedKey, fmt.Errorf("error unmarshalling response [%v]", err)
150
}
151
if outResponse.Request == "CAPCHA_NOT_READY" {
152
time.Sleep(5 * time.Second)
153
continue
154
} else if strings.Contains(string(body), "ERROR") {
155
return solvedKey, fmt.Errorf("error %v", outResponse.Request)
156
} else {
157
solvedKey = outResponse.Request
158
break
159
}
160
}
161
return solvedKey, nil
162
}
163
164
/*
165
Capmonster
166
*/
167
168
func (in *Instance) Capmonster(sitekey, website, rqdata, cookies string) (string, error) {
169
var solvedKey string
170
inEndpoint, outEndpoint := fmt.Sprintf("https://api.%s/createTask", in.Config.CaptchaSettings.CaptchaAPI), fmt.Sprintf("https://api.%s/getTaskResult", in.Config.CaptchaSettings.CaptchaAPI)
171
var submitCaptcha CapmonsterPayload
172
if in.Config.CaptchaSettings.ClientKey == "" {
173
return solvedKey, fmt.Errorf("no client key provided in config")
174
} else {
175
submitCaptcha.ClientKey = in.Config.CaptchaSettings.ClientKey
176
}
177
if in.Config.CaptchaSettings.CaptchaAPI == "anti-captcha.com" {
178
submitCaptcha.SoftID = 1021
179
}
180
if in.Config.ProxySettings.ProxyForCaptcha && in.Proxy != "" {
181
submitCaptcha.Task.CaptchaType = "HCaptchaTask"
182
if strings.Contains(in.Proxy, "@") {
183
// User:pass authenticated proxy
184
parts := strings.Split(in.Proxy, "@")
185
userPass, ipPort := parts[0], parts[1]
186
if !strings.Contains(ipPort, ":") || !strings.Contains(userPass, ":") {
187
return solvedKey, fmt.Errorf("invalid proxy format")
188
}
189
submitCaptcha.Task.ProxyType = "http"
190
submitCaptcha.Task.ProxyLogin, submitCaptcha.Task.ProxyPassword = strings.Split(userPass, ":")[0], strings.Split(userPass, ":")[1]
191
port := strings.Split(ipPort, ":")[1]
192
var err error
193
submitCaptcha.Task.ProxyPort, err = strconv.Atoi(port)
194
if err != nil {
195
return solvedKey, fmt.Errorf("invalid proxy format")
196
}
197
submitCaptcha.Task.ProxyAddress = strings.Split(ipPort, ":")[0]
198
} else {
199
if !strings.Contains(in.Proxy, ":") {
200
return solvedKey, fmt.Errorf("invalid proxy format")
201
}
202
submitCaptcha.Task.ProxyAddress = strings.Split(in.Proxy, ":")[0]
203
port := strings.Split(in.Proxy, ":")[1]
204
var err error
205
submitCaptcha.Task.ProxyPort, err = strconv.Atoi(port)
206
if err != nil {
207
return solvedKey, fmt.Errorf("invalid proxy format")
208
}
209
}
210
} else {
211
submitCaptcha.Task.CaptchaType = "HCaptchaTaskProxyless"
212
}
213
submitCaptcha.Task.WebsiteURL, submitCaptcha.Task.WebsiteKey, submitCaptcha.Task.UserAgent = "https://discord.com", sitekey, in.UserAgent
214
if rqdata != "" && in.Config.CaptchaSettings.CaptchaAPI == "capmonster.cloud" {
215
submitCaptcha.Task.Data = rqdata
216
// Try with true too
217
submitCaptcha.Task.IsInvisible = true
218
} else if rqdata != "" && in.Config.CaptchaSettings.CaptchaAPI == "anti-captcha.com" {
219
submitCaptcha.Task.IsInvisible = false
220
submitCaptcha.Task.Enterprise.RqData = rqdata
221
submitCaptcha.Task.Enterprise.Sentry = true
222
}
223
payload, err := json.Marshal(submitCaptcha)
224
if err != nil {
225
return solvedKey, fmt.Errorf("error while marshalling payload %v", err)
226
}
227
req, err := http.NewRequest(http.MethodPost, inEndpoint, strings.NewReader(string(payload)))
228
if err != nil {
229
return solvedKey, fmt.Errorf("error creating request [%v]", err)
230
}
231
req.Header.Set("Content-Type", "application/json")
232
resp, err := http.DefaultClient.Do(req)
233
if err != nil {
234
return solvedKey, fmt.Errorf("error sending request [%v]", err)
235
}
236
defer resp.Body.Close()
237
body, err := ioutil.ReadAll(resp.Body)
238
if err != nil {
239
return solvedKey, fmt.Errorf("error reading response [%v]", err)
240
}
241
var inResponse CapmonsterSubmitResponse
242
err = json.Unmarshal(body, &inResponse)
243
if err != nil {
244
return solvedKey, fmt.Errorf("error unmarshalling response [%v]", err)
245
}
246
if inResponse.ErrorID != 0 {
247
return solvedKey, fmt.Errorf("error %v %v", inResponse.ErrorID, string(body))
248
}
249
var retrieveCaptcha CapmonsterPayload
250
retrieveCaptcha.ClientKey = in.Config.CaptchaSettings.ClientKey
251
retrieveCaptcha.TaskId = inResponse.TaskID
252
in.LastID = inResponse.TaskID
253
payload, err = json.Marshal(retrieveCaptcha)
254
if err != nil {
255
return solvedKey, fmt.Errorf("error while marshalling payload %v", err)
256
}
257
req.Header.Set("Content-Type", "application/json")
258
time.Sleep(5 * time.Second)
259
t := time.Now()
260
for i := 0; i < 120; i++ {
261
if time.Since(t).Seconds() >= float64(in.Config.CaptchaSettings.Timeout) {
262
return solvedKey, fmt.Errorf("timedout - increase timeout in config to wait longer")
263
}
264
req, err = http.NewRequest(http.MethodPost, outEndpoint, bytes.NewBuffer(payload))
265
if err != nil {
266
return solvedKey, fmt.Errorf("error creating request [%v]", err)
267
}
268
resp, err = http.DefaultClient.Do(req)
269
if err != nil {
270
return solvedKey, fmt.Errorf("error sending request [%v]", err)
271
}
272
defer resp.Body.Close()
273
body, err = ioutil.ReadAll(resp.Body)
274
if err != nil {
275
return solvedKey, fmt.Errorf("error reading response [%v]", err)
276
}
277
var outResponse CapmonsterOutResponse
278
err = json.Unmarshal(body, &outResponse)
279
if err != nil {
280
return solvedKey, fmt.Errorf("error unmarshalling response [%v]", err)
281
}
282
if outResponse.ErrorID != 0 {
283
return solvedKey, fmt.Errorf("error %v %v", outResponse.ErrorID, string(body))
284
}
285
if outResponse.Status == "ready" {
286
solvedKey = outResponse.Solution.CaptchaResponse
287
break
288
} else if outResponse.Status == "processing" {
289
time.Sleep(5 * time.Second)
290
continue
291
} else {
292
return solvedKey, fmt.Errorf("error invalid status %v %v", outResponse.ErrorID, string(body))
293
}
294
295
}
296
return solvedKey, nil
297
}
298
299
func (in *Instance) ReportIncorrectRecaptcha() error {
300
site := "https://api.anti-captcha.com/reportIncorrectHcaptcha"
301
payload := CapmonsterPayload{
302
ClientKey: in.Config.CaptchaSettings.ClientKey,
303
TaskId: in.LastID,
304
}
305
payloadBytes, err := json.Marshal(payload)
306
if err != nil {
307
return fmt.Errorf("error while marshalling payload %v", err)
308
}
309
resp, err := http.Post(site, "application/json", bytes.NewBuffer(payloadBytes))
310
if err != nil {
311
return fmt.Errorf("error sending request [%v]", err)
312
}
313
defer resp.Body.Close()
314
body, err := ioutil.ReadAll(resp.Body)
315
if err != nil {
316
return fmt.Errorf("error reading response [%v]", err)
317
}
318
var outResponse CapmonsterOutResponse
319
err = json.Unmarshal(body, &outResponse)
320
if err != nil {
321
return fmt.Errorf("error unmarshalling response [%v]", err)
322
}
323
if outResponse.Status != "success" {
324
return fmt.Errorf("error %v ", outResponse.ErrorID)
325
}
326
327
return nil
328
}
329
330
func (in *Instance) CapCat(sitekey, rqdata string) (string, error) {
331
postURL := "http://capcat.xyz/api/tasks"
332
x := CapCat{
333
SiteKey: sitekey,
334
RqData: rqdata,
335
ApiKey: in.Config.CaptchaSettings.ClientKey,
336
}
337
ipAPI := "https://api.myip.com"
338
req, err := http.NewRequest("GET", ipAPI, nil)
339
if err != nil {
340
return "", fmt.Errorf("error creating request [%v]", err)
341
}
342
resp, err := http.DefaultClient.Do(req)
343
if err != nil {
344
return "", fmt.Errorf("error sending request [%v]", err)
345
}
346
defer resp.Body.Close()
347
body, err := ioutil.ReadAll(resp.Body)
348
if err != nil {
349
return "", fmt.Errorf("error reading response [%v]", err)
350
}
351
if !strings.Contains(string(body), "ip") {
352
return "", fmt.Errorf("error invalid response [%v]", string(body))
353
}
354
var ipResponse map[string]interface{}
355
err = json.Unmarshal(body, &ipResponse)
356
if err != nil {
357
return "", fmt.Errorf("error unmarshalling response [%v]", err)
358
}
359
x.IP = ipResponse["ip"].(string)
360
payload, err := json.Marshal(x)
361
if err != nil {
362
return "", fmt.Errorf("error while marshalling payload %v", err)
363
}
364
req, err = http.NewRequest(http.MethodPost, postURL, strings.NewReader(string(payload)))
365
if err != nil {
366
return "", fmt.Errorf("error creating request [%v]", err)
367
}
368
req.Header.Set("Content-Type", "application/json")
369
resp, err = http.DefaultClient.Do(req)
370
if err != nil {
371
return "", fmt.Errorf("error sending request [%v]", err)
372
}
373
defer resp.Body.Close()
374
body, err = ioutil.ReadAll(resp.Body)
375
if err != nil {
376
return "", fmt.Errorf("error reading response [%v]", err)
377
}
378
var outResponse CapCatResponse
379
err = json.Unmarshal(body, &outResponse)
380
if err != nil {
381
return "", fmt.Errorf("error unmarshalling response [%v]", err)
382
}
383
if outResponse.ID == 0 {
384
return "", fmt.Errorf("error %v %v", outResponse.Msg, string(body))
385
}
386
t := time.Now()
387
for {
388
time.Sleep(5 * time.Second)
389
if time.Since(t).Seconds() >= float64(in.Config.CaptchaSettings.Timeout) || time.Since(t).Seconds() >= 300 {
390
return "", fmt.Errorf("timedout - increase timeout in config to wait longer")
391
}
392
getURL := "http://capcat.xyz/api/result/"
393
y := CapCat{
394
ID: fmt.Sprintf("%v", outResponse.ID),
395
ApiKey: in.Config.CaptchaSettings.ClientKey,
396
}
397
payload, err = json.Marshal(y)
398
if err != nil {
399
return "", fmt.Errorf("error while marshalling payload %v", err)
400
}
401
req, err = http.NewRequest(http.MethodPost, getURL, strings.NewReader(string(payload)))
402
if err != nil {
403
return "", fmt.Errorf("error creating request [%v]", err)
404
}
405
req.Header.Set("Content-Type", "application/json")
406
resp, err = http.DefaultClient.Do(req)
407
if err != nil {
408
return "", fmt.Errorf("error sending request [%v]", err)
409
}
410
defer resp.Body.Close()
411
body, err = ioutil.ReadAll(resp.Body)
412
if err != nil {
413
return "", fmt.Errorf("error reading response [%v]", err)
414
}
415
var outResponse CapCatResponse
416
err = json.Unmarshal(body, &outResponse)
417
if err != nil {
418
return "", fmt.Errorf("error unmarshalling response [%v]", err)
419
}
420
if strings.Contains(string(body), "working") {
421
continue
422
} else if outResponse.Code == 1 && outResponse.Data != "" {
423
return outResponse.Data, nil
424
} else {
425
return "", fmt.Errorf("error %v", string(body))
426
}
427
}
428
}
429
430
func (in *Instance) self(sitekey, rqData string) (string, error) {
431
var solution string
432
var err error
433
link := in.Config.CaptchaSettings.Self
434
if link == "" {
435
return "", fmt.Errorf("self captcha not configured")
436
}
437
client := http.Client{
438
Timeout: 30 * time.Second,
439
}
440
selfPayload := SelfRequest{
441
Sitekey: sitekey,
442
RqData: rqData,
443
Host: "discord.com",
444
Proxy: in.Proxy,
445
Username: in.Config.CaptchaSettings.SelfUsername,
446
Password: in.Config.CaptchaSettings.SelfPassword,
447
ProxyType: "http",
448
}
449
payloadBytes, err := json.Marshal(selfPayload)
450
if err != nil {
451
return "", fmt.Errorf("error marshalling payload %v", err)
452
}
453
req, err := http.NewRequest(http.MethodPost, link, bytes.NewReader(payloadBytes))
454
if err != nil {
455
return "", fmt.Errorf("error creating request [%v]", err)
456
}
457
req.Header.Set("Content-Type", "application/json")
458
resp, err := client.Do(req)
459
if err != nil {
460
return "", fmt.Errorf("error sending request [%v]", err)
461
}
462
defer resp.Body.Close()
463
body, err := ioutil.ReadAll(resp.Body)
464
if err != nil {
465
return "", fmt.Errorf("error reading response [%v]", err)
466
}
467
var outResponse SelfResponse
468
err = json.Unmarshal(body, &outResponse)
469
if err != nil {
470
return "", fmt.Errorf("error unmarshalling response [%v]", err)
471
}
472
if outResponse.Answer != "" {
473
solution = outResponse.Answer
474
} else {
475
return "", fmt.Errorf("error %v", string(body))
476
}
477
return solution, err
478
}
479
480
type CapCat struct {
481
ApiKey string `json:"apikey"`
482
SiteKey string `json:"sitkey"`
483
RqData string `json:"rqdata"`
484
IP string `json:"ip"`
485
ID string `json:"id,omitempty"`
486
}
487
488
type CapCatResponse struct {
489
ID int `json:"id,omitempty"`
490
Msg string `json:"mess,omitempty"`
491
Code int `json:"code,omitempty"`
492
Data string `json:"data,omitempty"`
493
}
494
495
type SelfRequest struct {
496
Sitekey string `json:"sitekey"`
497
RqData string `json:"rqdata"`
498
Proxy string `json:"proxy"`
499
Host string `json:"host"`
500
Username string `json:"username"`
501
Password string `json:"password"`
502
ProxyType string `json:"proxytype"`
503
}
504
505
type SelfResponse struct {
506
Answer string `json:"generated_pass_UUID"`
507
}
508
509
/*
510
invisifox
511
*/
512
513
func (in *Instance) invisifox(sitekey, cookie, rqdata string) (string, error) {
514
site := "http://localhost:8888/solve"
515
inURL, err := url.Parse(site)
516
if err != nil {
517
return "", fmt.Errorf("error parsing url [%v]", err)
518
}
519
q := inURL.Query()
520
q.Set("sitekey", sitekey)
521
q.Set("host", "discord.com")
522
if rqdata != "" {
523
q.Set("rqdata", rqdata)
524
}
525
if in.Config.ProxySettings.ProxyForCaptcha {
526
if strings.Contains(in.Proxy, "http://") {
527
q.Set("proxy", strings.Split(in.Proxy, "http://")[1])
528
} else {
529
q.Set("proxy", in.Proxy)
530
}
531
}
532
inURL.RawQuery = q.Encode()
533
finalSite := inURL.String()
534
req, err := http.NewRequest(http.MethodPost, finalSite, nil)
535
if err != nil {
536
return "", fmt.Errorf("error creating request [%v]", err)
537
}
538
resp, err := http.DefaultClient.Do(req)
539
if err != nil {
540
return "", fmt.Errorf("error sending request [%v]", err)
541
}
542
defer resp.Body.Close()
543
body, err := ioutil.ReadAll(resp.Body)
544
if err != nil {
545
return "", fmt.Errorf("error reading response [%v]", err)
546
}
547
switch resp.StatusCode {
548
case 200:
549
return string(body), nil
550
case 500:
551
return "", fmt.Errorf("an unknown error has occured")
552
case 404:
553
return "", fmt.Errorf("trial attempts exceeded")
554
case 405:
555
return "", fmt.Errorf("got flagged images, your proxies or useragent might be overused")
556
case 401:
557
return "", fmt.Errorf("error while communicating with hcaptcha. it may be an issue with the proxy timing out or being rate limited")
558
case 408:
559
return "", fmt.Errorf("solver instance timedout. could not load/solve captcha in time")
560
default:
561
return "", fmt.Errorf("error %v %s", resp.StatusCode, string(body))
562
}
563
564
}
565
566
type invisifoxRequest struct {
567
Sitekey string `json:"sitekey"`
568
Proxy string `json:"proxy,omitempty"`
569
Host string `json:"host"`
570
Rqdata string `json:"rqdata,omitempty"`
571
}
572
573
/*
574
captchaai
575
*/
576
577
func (in *Instance) captchaAI(sitekey, rqdata string) (string, error) {
578
var captchaSolution string
579
var err error
580
submitURL := "https://api.captchaai.io/createTask"
581
var submitPayload captchaAIpayload
582
submitPayload.ClientKey = in.Config.CaptchaSettings.ClientKey
583
if in.Config.ProxySettings.ProxyForCaptcha {
584
submitPayload.Task.Type = "HCaptchaTask"
585
submitPayload.Task.ProxyType = "http"
586
var onlyProxy string
587
if strings.Contains(in.Proxy, "http://") {
588
onlyProxy = strings.Split(in.Proxy, "http://")[1]
589
} else {
590
onlyProxy = in.Proxy
591
}
592
if strings.Contains(onlyProxy, "@") {
593
auth, proxy := strings.Split(onlyProxy, "@")[0], strings.Split(onlyProxy, "@")[1]
594
if !strings.Contains(auth, ":") {
595
return captchaSolution, fmt.Errorf("proxy auth is not in format user:pass")
596
}
597
submitPayload.Task.ProxyLogin = strings.Split(auth, ":")[0]
598
submitPayload.Task.ProxyPassword = strings.Split(auth, ":")[1]
599
if !strings.Contains(proxy, ":") {
600
return captchaSolution, fmt.Errorf("proxy is not in format host:port")
601
}
602
submitPayload.Task.ProxyAddress = strings.Split(proxy, ":")[0]
603
p, err := strconv.Atoi(strings.Split(proxy, ":")[1])
604
if err != nil {
605
return captchaSolution, fmt.Errorf("proxy port is not a number")
606
}
607
submitPayload.Task.ProxyPort = p
608
} else {
609
if !strings.Contains(onlyProxy, ":") {
610
return captchaSolution, fmt.Errorf("proxy is not in format host:port")
611
}
612
submitPayload.Task.ProxyAddress = strings.Split(onlyProxy, ":")[0]
613
p, err := strconv.Atoi(strings.Split(onlyProxy, ":")[1])
614
if err != nil {
615
return captchaSolution, fmt.Errorf("proxy port is not a number")
616
}
617
submitPayload.Task.ProxyPort = p
618
}
619
} else {
620
submitPayload.Task.Type = "HCaptchaTaskProxyless"
621
}
622
if rqdata == "" {
623
submitPayload.Task.IsEnterprise = false
624
} else {
625
submitPayload.Task.IsEnterprise = true
626
submitPayload.Task.EnterprisePayload.RqData = rqdata
627
}
628
submitPayload.Task.WebsiteURL = "https://discord.com"
629
submitPayload.Task.WebsiteKey = sitekey
630
submitPayload.Task.UserAgent = in.UserAgent
631
submitPayload.Task.IsInvisible = false
632
bytes, err := json.Marshal(submitPayload)
633
if err != nil {
634
return captchaSolution, fmt.Errorf("error while marshalling payload [%v]", err)
635
}
636
req, err := http.NewRequest(http.MethodPost, submitURL, strings.NewReader(string(bytes)))
637
if err != nil {
638
return captchaSolution, fmt.Errorf("error creating request [%v]", err)
639
}
640
req.Header.Set("Content-Type", "application/json")
641
resp, err := http.DefaultClient.Do(req)
642
if err != nil {
643
return captchaSolution, fmt.Errorf("error sending request [%v]", err)
644
}
645
defer resp.Body.Close()
646
body, err := ioutil.ReadAll(resp.Body)
647
if err != nil {
648
return captchaSolution, fmt.Errorf("error reading response [%v]", err)
649
}
650
var submitResponse CaptchaAISubmitResponse
651
err = json.Unmarshal(body, &submitResponse)
652
if err != nil {
653
return captchaSolution, fmt.Errorf("error unmarshalling response [%v]", err)
654
}
655
if submitResponse.ErrorID != 0 {
656
return captchaSolution, fmt.Errorf("CaptchaAI error while submitting payload, errorID %d errroCode %s errorDescription %s", submitResponse.ErrorID, submitResponse.ErrorCode, submitResponse.ErrorDescription)
657
}
658
if submitResponse.TaskID == "" {
659
return captchaSolution, fmt.Errorf("CaptchaAI error while submitting payload, no taskID")
660
}
661
now := time.Now()
662
for {
663
if time.Since(now) > time.Duration(in.Config.CaptchaSettings.Timeout)*time.Second {
664
return captchaSolution, fmt.Errorf("captcha timeout")
665
}
666
time.Sleep(15 * time.Second)
667
result := "https://api.captchaai.io/getTaskResult"
668
var resultPayload captchaAIpayload
669
resultPayload.ClientKey = in.Config.CaptchaSettings.ClientKey
670
resultPayload.TaskID = submitResponse.TaskID
671
bytes, err := json.Marshal(resultPayload)
672
if err != nil {
673
return captchaSolution, fmt.Errorf("error while marshalling payload [%v]", err)
674
}
675
req, err := http.NewRequest(http.MethodPost, result, strings.NewReader(string(bytes)))
676
if err != nil {
677
return captchaSolution, fmt.Errorf("error creating request [%v]", err)
678
}
679
req.Header.Set("Content-Type", "application/json")
680
resp, err := http.DefaultClient.Do(req)
681
if err != nil {
682
return captchaSolution, fmt.Errorf("error sending request [%v]", err)
683
}
684
defer resp.Body.Close()
685
body, err := ioutil.ReadAll(resp.Body)
686
if err != nil {
687
return captchaSolution, fmt.Errorf("error reading response [%v]", err)
688
}
689
var resultResponse CaptchaAISubmitResponse
690
err = json.Unmarshal(body, &resultResponse)
691
if err != nil {
692
return captchaSolution, fmt.Errorf("error unmarshalling response [%v]", err)
693
}
694
if resultResponse.ErrorID != 0 {
695
return captchaSolution, fmt.Errorf("CaptchaAI error while submitting payload, errorID %d errroCode %s errorDescription %s", resultResponse.ErrorID, resultResponse.ErrorCode, resultResponse.ErrorDescription)
696
}
697
if resultResponse.Status == "processing" {
698
continue
699
}
700
return resultResponse.Solution.CaptchaResponse, nil
701
}
702
703
}
704
705
type captchaAIpayload struct {
706
ClientKey string `json:"clientKey"`
707
Task CaptchaAiTask `json:"task,omitempty"`
708
TaskID string `json:"taskId,omitempty"`
709
}
710
711
type CaptchaAiTask struct {
712
Type string `json:"type"`
713
WebsiteURL string `json:"websiteURL"`
714
WebsiteKey string `json:"websiteKey"`
715
ProxyType string `json:"proxyType,omitempty"`
716
ProxyAddress string `json:"proxyAddress,omitempty"`
717
ProxyPort int `json:"proxyPort,omitempty"`
718
ProxyLogin string `json:"proxyLogin,omitempty"`
719
ProxyPassword string `json:"proxyPassword,omitempty"`
720
UserAgent string `json:"userAgent"`
721
IsInvisible bool `json:"isInvisible"`
722
IsEnterprise bool `json:"isEnterprise"`
723
EnterprisePayload EnterprisePayload `json:"enterprisePayload,omitempty"`
724
}
725
726
type EnterprisePayload struct {
727
RqData string `json:"rqdata,omitempty"`
728
}
729
730
type CaptchaAISubmitResponse struct {
731
ErrorID int `json:"errorId"`
732
TaskID string `json:"taskId"`
733
Status string `json:"status"`
734
CreateTime int `json:"createTime"`
735
ErrorCode string `json:"errorCode"`
736
ErrorDescription string `json:"errorDescription"`
737
Solution Solution `json:"solution"`
738
}
739
740