-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKeyAuth.hpp
718 lines (593 loc) · 19.5 KB
/
KeyAuth.hpp
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#pragma once
#include <cryptopp/aes.h>
#include <cryptopp/osrng.h>
#include <cryptopp/cryptlib.h>
#include <cryptopp/base64.h>
#include <cryptopp/filters.h>
#include <cryptopp/modes.h>
#include <cryptopp/hex.h>
#include <cryptopp/ccm.h>
#include <atlsecurity.h>
#include <strsafe.h>
#include <windows.h>
#include <string>
#include <stdio.h>
#include <iostream>
#include <curl/curl.h>
#include <shellapi.h>
#include <sstream>
#include <iomanip>
#include "../xorstr.hpp"
#include <fstream>
#include <nlohmann/json.hpp>
#pragma comment(lib, "rpcrt4.lib")
namespace KeyAuth {
class encryption {
public:
std::string name;
static std::string encrypt_string(const std::string& plain_text, const std::string& key, const std::string& iv) {
std::string cipher_text;
try {
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption encryption;
encryption.SetKeyWithIV((CryptoPP::byte*)key.c_str(), key.size(), (CryptoPP::byte*)iv.c_str());
CryptoPP::StringSource encryptor(plain_text, true,
new CryptoPP::StreamTransformationFilter(encryption,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(cipher_text),
false
)
)
);
}
catch (CryptoPP::Exception& ex) {
system(XorStr("cls").c_str());
std::cout << ex.what();
exit(5000);
}
return cipher_text;
}
static std::string decrypt_string(const std::string& cipher_text, const std::string& key, const std::string& iv) {
std::string plain_text;
try {
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decryption;
decryption.SetKeyWithIV((CryptoPP::byte*)key.c_str(), key.size(), (CryptoPP::byte*)iv.c_str());
CryptoPP::StringSource decryptor(cipher_text, true,
new CryptoPP::HexDecoder(
new CryptoPP::StreamTransformationFilter(decryption,
new CryptoPP::StringSink(plain_text)
)
)
);
}
catch (CryptoPP::Exception& ex) {
system(XorStr("cls").c_str());
std::cout << ex.what();
exit(5000);
}
return plain_text;
}
static std::string sha256(const std::string& plain_text) {
std::string hashed_text;
CryptoPP::SHA256 hash;
try {
CryptoPP::StringSource hashing(plain_text, true,
new CryptoPP::HashFilter(hash,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(hashed_text),
false
)
)
);
}
catch (CryptoPP::Exception& ex) {
system(XorStr("cls").c_str());
std::cout << ex.what();
exit(5000);
}
return hashed_text;
}
static std::string encode(const std::string& plain_text) {
std::string encoded_text;
try {
CryptoPP::StringSource encoding(plain_text, true,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(encoded_text),
false
)
);
}
catch (CryptoPP::Exception& ex) {
system(XorStr("cls").c_str());
std::cout << ex.what();
exit(5000);
}
return encoded_text;
}
static std::string decode(const std::string& encoded_text) {
std::string out;
try {
CryptoPP::StringSource decoding(encoded_text, true,
new CryptoPP::HexDecoder(
new CryptoPP::StringSink(out)
)
);
}
catch (CryptoPP::Exception& ex) {
system(XorStr("cls").c_str());
std::cout << ex.what();
exit(5000);
}
return out;
}
static std::string iv_key() {
UUID uuid = { 0 };
std::string guid;
::UuidCreate(&uuid);
RPC_CSTR szUuid = NULL;
if (::UuidToStringA(&uuid, &szUuid) == RPC_S_OK)
{
guid = (char*)szUuid;
::RpcStringFreeA(&szUuid);
}
return guid.substr(0, 16);
}
static std::string encrypt(std::string message, std::string enc_key, std::string iv) {
enc_key = sha256(enc_key).substr(0, 32);
iv = sha256(iv).substr(0, 16);
return encrypt_string(message, enc_key, iv);
}
static std::string decrypt(std::string message, std::string enc_key, std::string iv) {
enc_key = sha256(enc_key).substr(0, 32);
iv = sha256(iv).substr(0, 16);
return decrypt_string(message, enc_key, iv);
}
};
class utils {
public:
static std::string get_hwid() {
ATL::CAccessToken accessToken;
ATL::CSid currentUserSid;
if (accessToken.GetProcessToken(TOKEN_READ | TOKEN_QUERY) &&
accessToken.GetUser(¤tUserSid))
return std::string(CT2A(currentUserSid.Sid()));
}
static std::time_t string_to_timet(std::string timestamp) {
auto cv = strtol(timestamp.c_str(), NULL, 10);
return (time_t)cv;
}
static std::tm timet_to_tm(time_t timestamp) {
std::tm context;
localtime_s(&context, ×tamp);
return context;
}
};
struct msg
{
std::string message;
std::string author;
std::string timestamp;
};
auto iv = encryption::sha256(encryption::iv_key());
class api {
public:
std::string name, ownerid, secret, version;
api(std::string name, std::string ownerid, std::string secret, std::string version)
: name(name), ownerid(ownerid), secret(secret), version(version) {}
void init()
{
enckey = encryption::sha256(encryption::iv_key());
if (ownerid.length() != 10 || secret.length() != 64)
{
error("Application Not Setup Correctly.Please Watch Video Linked in Main.cpp");
}
auto data =
XorStr("type=").c_str() + encryption::encode(XorStr("init").c_str()) +
XorStr("&ver=").c_str() + encryption::encrypt(version, secret, iv) +
XorStr("&enckey=").c_str() + encryption::encrypt(enckey, secret, iv) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, secret, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
sessionid = json[("sessionid")];
// optional success message
}
else if (json[("message")] == "invalidver")
{
std::string dl = json[("download")];
ShellExecuteA(0, "open", dl.c_str(), 0, 0, SW_SHOWNORMAL);
exit(0);
}
else
{
error(json[("message")]);
}
}
void login(std::string username, std::string password)
{
std::string hwid = utils::get_hwid();
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("login") +
XorStr("&username=").c_str() + encryption::encrypt(username, enckey, iv) +
XorStr("&pass=").c_str() + encryption::encrypt(password, enckey, iv) +
XorStr("&hwid=").c_str() + encryption::encrypt(hwid, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
// optional success message
load_user_data(json[("info")]);
}
else
{
error(json[("message")]);
}
}
void regstr(std::string username, std::string password, std::string key) {
std::string hwid = utils::get_hwid();
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("register") +
XorStr("&username=").c_str() + encryption::encrypt(username, enckey, iv) +
XorStr("&pass=").c_str() + encryption::encrypt(password, enckey, iv) +
XorStr("&key=").c_str() + encryption::encrypt(key, enckey, iv) +
XorStr("&hwid=").c_str() + encryption::encrypt(hwid, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
// optional success message
load_user_data(json[("info")]);
}
else
{
error(json[("message")]);
}
}
void upgrade(std::string username, std::string key) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("upgrade") +
XorStr("&username=").c_str() + encryption::encrypt(username, enckey, iv) +
XorStr("&key=").c_str() + encryption::encrypt(key, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
// optional success message
}
else
{
error(json[("message")]);
}
}
void license(std::string key) {
auto iv = encryption::sha256(encryption::iv_key());
std::string hwid = utils::get_hwid();
auto data =
XorStr("type=").c_str() + encryption::encode("license") +
XorStr("&key=").c_str() + encryption::encrypt(key, enckey, iv) +
XorStr("&hwid=").c_str() + encryption::encrypt(hwid, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
// optional success message
load_user_data(json[("info")]);
}
else
{
error(json[("message")]);
}
}
void setvar(std::string var, std::string vardata) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("setvar") +
XorStr("&var=").c_str() + encryption::encrypt(var, enckey, iv) +
XorStr("&data=").c_str() + encryption::encrypt(vardata, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
// optional success message
}
else
{
error(json[("message")]);
}
}
std::string getvar(std::string var) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("getvar") +
XorStr("&var=").c_str() + encryption::encrypt(var, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
return json[("response")];
}
else
{
error(json[("message")]);
}
}
void ban() {
auto iv = encryption::sha256(encryption::iv_key());
std::string hwid = utils::get_hwid();
auto data =
XorStr("type=").c_str() + encryption::encode("ban") +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
// optional success message
}
else
{
error(json[("message")]);
}
}
std::vector<msg> chatget(std::string channelname) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("chatget") +
XorStr("&channel=").c_str() + encryption::encrypt(channelname, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
std::vector<msg> buff;
for (const auto message : json[("messages")]) {
buff.push_back(msg{ message["message"],message["author"] ,message["timestamp"] });
}
return buff;
}
else
{
error(json[("message")]);
}
}
bool chatsend(std::string msg, std::string channelname) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("chatsend") +
XorStr("&message=").c_str() + encryption::encrypt(msg, enckey, iv) +
XorStr("&channel=").c_str() + encryption::encrypt(channelname, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
return true;
}
else
{
return false;
}
}
bool checkblack() {
std::string hwid = utils::get_hwid();
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("checkblacklist") +
XorStr("&hwid=").c_str() + encryption::encrypt(hwid, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
return true;
}
else
{
return false;
}
}
std::string var(std::string varid) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode("var") +
XorStr("&varid=").c_str() + encryption::encrypt(varid, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
return json[("message")];
}
else
{
error(json[("message")]);
}
}
void log(std::string message) {
auto iv = encryption::sha256(encryption::iv_key());
char acUserName[100];
DWORD nUserName = sizeof(acUserName);
GetUserNameA(acUserName, &nUserName);
std::string UsernamePC = acUserName;
auto data =
XorStr("type=").c_str() + encryption::encode(XorStr("log").c_str()) +
XorStr("&pcuser=").c_str() + encryption::encrypt(UsernamePC, enckey, iv) +
XorStr("&message=").c_str() + encryption::encrypt(message, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
req(data);
}
std::vector<unsigned char> download(std::string fileid) {
auto iv = encryption::sha256(encryption::iv_key());
auto to_uc_vector = [](std::string value) {
return std::vector<unsigned char>(value.data(), value.data() + value.length() + 1);
};
auto data =
XorStr("type=").c_str() + encryption::encode("file") +
XorStr("&fileid=").c_str() + encryption::encrypt(fileid, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (!json["success"])
{
error(json[("message")]);
}
auto file = encryption::decode(json["contents"]);
return to_uc_vector(file);
}
std::string webhook(std::string id, std::string params) {
auto iv = encryption::sha256(encryption::iv_key());
auto data =
XorStr("type=").c_str() + encryption::encode(XorStr("webhook").c_str()) +
XorStr("&webid=").c_str() + encryption::encrypt(id, enckey, iv) +
XorStr("¶ms=").c_str() + encryption::encrypt(params, enckey, iv) +
XorStr("&sessionid=").c_str() + encryption::encode(sessionid) +
XorStr("&name=").c_str() + encryption::encode(name) +
XorStr("&ownerid=").c_str() + encryption::encode(ownerid) +
XorStr("&init_iv=").c_str() + iv;
auto response = req(data);
response = encryption::decrypt(response, enckey, iv);
auto json = response_decoder.parse(response);
if (json[("success")])
{
return json[("response")];
}
else
{
error(json[("message")]);
}
}
class user_data_class {
public:
std::string username;
std::string ip;
std::string hwid;
std::tm createdate;
std::tm lastlogin;
std::tm expiry;
int timeleft;
};
user_data_class user_data;
private:
std::string sessionid, enckey;
static size_t write_callback(void* contents, size_t size, size_t nmemb, void* userp) {
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
static void error(std::string error)
{
system(("start cmd /C \"color b && title Error && echo " + error + " && timeout /t 5 >nul 2>&1").c_str());
exit(0);
}
static std::string req(std::string data) {
CURL* curl = curl_easy_init();
if (!curl)
return "null";
std::string to_return;
curl_easy_setopt(curl, CURLOPT_URL, XorStr("https://keyauth.win/api/1.0/").c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &to_return);
auto code = curl_easy_perform(curl);
if (code != CURLE_OK)
MessageBoxA(0, curl_easy_strerror(code), 0, MB_ICONERROR);
curl_easy_cleanup(curl);
long http_code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 429) // client was rate limited
{
error("You're connecting too fast to loader, slow down.");
}
return to_return;
}
class user_data_structure {
public:
std::string username;
std::string ip;
std::string hwid;
std::string createdate;
std::string lastlogin;
std::string expiry;
int timeleft;
};
void load_user_data(nlohmann::json data) {
user_data.username = data["username"];
user_data.ip = data["ip"];
user_data.hwid = data["hwid"];
user_data.createdate = utils::timet_to_tm(
utils::string_to_timet(data["createdate"])
);
user_data.lastlogin = utils::timet_to_tm(
utils::string_to_timet(data["lastlogin"])
);
user_data.expiry = utils::timet_to_tm(
utils::string_to_timet(data["subscriptions"][0]["expiry"])
);
user_data.timeleft = data["subscriptions"][0]["timeleft"];
}
nlohmann::json response_decoder;
};
}