-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
auth.cpp
1972 lines (1625 loc) · 63.4 KB
/
auth.cpp
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define _CRT_SECURE_NO_WARNINGS
#include <auth.hpp>
#include <strsafe.h>
#include <windows.h>
#include <string>
#include <stdio.h>
#include <iostream>
#include <shellapi.h>
#include <sstream>
#include <iomanip>
#include <xorstr.hpp>
#include <fstream>
#include <http.h>
#include <stdlib.h>
#include <atlstr.h>
#include <ctime>
#include <filesystem>
#pragma comment(lib, "rpcrt4.lib")
#pragma comment(lib, "httpapi.lib")
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
#include <functional>
#include <vector>
#include <bitset>
#include <psapi.h>
#pragma comment( lib, "psapi.lib" )
#include <thread>
#include <cctype>
#include <algorithm>
#include "Security.hpp"
#include "killEmulator.hpp"
#include <lazy_importer.hpp>
#define SHA256_HASH_SIZE 32
static std::string hexDecode(const std::string& hex);
std::string get_str_between_two_str(const std::string& s, const std::string& start_delim, const std::string& stop_delim);
int VerifyPayload(std::string signature, std::string timestamp, std::string body);
void checkInit();
std::string checksum();
void debugInfo(std::string data, std::string url, std::string response, std::string headers);
void modify();
void runChecks();
void checkAtoms();
void checkFiles();
void checkRegistry();
void error(std::string message);
std::string generate_random_number();
std::string seed;
std::string signature;
std::string signatureTimestamp;
bool initialized;
std::string API_PUBLIC_KEY = "5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b";
void KeyAuth::api::init()
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)runChecks, 0, 0, 0);
std::string random_num = generate_random_number();
seed = random_num;
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)modify, 0, 0, 0);
if (ownerid.length() != 10)
{
MessageBoxA(0, XorStr("Application Not Setup Correctly. Please Watch Video Linked in main.cpp").c_str(), NULL, MB_ICONERROR);
LI_FN(exit)(0);
}
std::string hash = checksum();
CURL* curl = curl_easy_init();
auto data =
XorStr("type=init") +
XorStr("&ver=") + version +
XorStr("&hash=") + hash +
XorStr("&name=") + curl_easy_escape(curl, name.c_str(), 0) +
XorStr("&ownerid=") + ownerid;
// to ensure people removed secret from main.cpp (some people will forget to)
if (path.find("https") != std::string::npos) {
MessageBoxA(0, XorStr("You forgot to remove \"secret\" from main.cpp. Copy details from ").c_str(), NULL, MB_ICONERROR);
LI_FN(exit)(0);
}
if (path != "" || !path.empty()) {
if (!std::filesystem::exists(path)) {
MessageBoxA(0, XorStr("File not found. Please make sure the file exists.").c_str(), NULL, MB_ICONERROR);
LI_FN(exit)(0);
}
//get the contents of the file
std::ifstream file(path);
std::string token;
std::string thash;
std::getline(file, token);
auto exec = [&](const char* cmd) -> std::string
{
uint16_t line = -1;
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
if (!pipe) {
throw std::runtime_error(XorStr("popen() failed!"));
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result = buffer.data();
}
return result;
};
thash = exec(("certutil -hashfile \"" + path + XorStr("\" MD5 | find /i /v \"md5\" | find /i /v \"certutil\"")).c_str());
data += XorStr("&token=").c_str() + token;
data += XorStr("&thash=").c_str() + path;
}
curl_easy_cleanup(curl);
auto response = req(data, url);
if (response == XorStr("KeyAuth_Invalid").c_str()) {
MessageBoxA(0, XorStr("Application not found. Please copy strings directly from dashboard.").c_str(), NULL, MB_ICONERROR);
LI_FN(exit)(0);
}
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, response.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(response);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
load_response_data(json);
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
if (json[(XorStr("success"))])
{
if (json[(XorStr("newSession"))]) {
Sleep(100);
}
sessionid = json[(XorStr("sessionid"))];
initialized = true;
load_app_data(json[(XorStr("appinfo"))]);
}
else if (json[(XorStr("message"))] == XorStr("invalidver"))
{
std::string dl = json[(XorStr("download"))];
if (dl == "")
{
MessageBoxA(0, XorStr("Version in the loader does match the one on the dashboard, and the download link on dashboard is blank.\n\nTo fix this, either fix the loader so it matches the version on the dashboard. Or if you intended for it to have different versions, update the download link on dashboard so it will auto-update correctly.").c_str(), NULL, MB_ICONERROR);
}
else
{
ShellExecuteA(0, XorStr("open").c_str(), dl.c_str(), 0, 0, SW_SHOWNORMAL);
}
LI_FN(exit)(0);
}
}
else {
LI_FN(exit)(9);
}
}
else {
LI_FN(exit)(7);
}
}
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;
}
// Callback function to handle headers
size_t header_callback(char* buffer, size_t size, size_t nitems, void* userdata) {
size_t totalSize = size * nitems;
// Convert the header to a string for easier processing
std::string header(buffer, totalSize);
// Find the x-signature-ed25519 header
const std::string signatureHeaderName = "x-signature-ed25519: ";
if (header.find(signatureHeaderName) == 0) {
// Extract the header value
signature = header.substr(signatureHeaderName.length());
// Remove any trailing newline or carriage return characters
signature.erase(signature.find_last_not_of("\r\n") + 1);
}
// Find the x-signature-timestamp header
const std::string signatureTimeHeaderName = "x-signature-timestamp: ";
if (header.find(signatureTimeHeaderName) == 0) {
// Extract the header value
signatureTimestamp = header.substr(signatureTimeHeaderName.length());
// Remove any trailing newline or carriage return characters
signatureTimestamp.erase(signatureTimestamp.find_last_not_of("\r\n") + 1);
}
return totalSize;
}
void KeyAuth::api::login(std::string username, std::string password)
{
checkInit();
std::string hwid = utils::get_hwid();
auto data =
XorStr("type=login") +
XorStr("&username=") + username +
XorStr("&pass=") + password +
XorStr("&hwid=") + hwid +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, response.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(response);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
load_response_data(json);
if (json[(XorStr("success"))])
load_user_data(json[(XorStr("info"))]);
if (api::response.message != XorStr("Initialized").c_str()) {
LI_FN(GlobalAddAtomA)(seed.c_str());
std::string file_path = XorStr("C:\\ProgramData\\").c_str() + seed;
std::ofstream file(file_path);
if (file.is_open()) {
file << seed;
file.close();
}
std::string regPath = XorStr("Software\\").c_str() + seed;
HKEY hKey;
LONG result = RegCreateKeyExA(HKEY_CURRENT_USER, regPath.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
if (result == ERROR_SUCCESS) {
LI_FN(RegSetValueExA)(hKey, seed.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE*>(seed.c_str()), seed.size() + 1);
LI_FN(RegCloseKey)(hKey);
}
LI_FN(GlobalAddAtomA)(ownerid.c_str());
}
else {
LI_FN(exit)(12);
}
}
else {
LI_FN(exit)(9);
}
}
else {
LI_FN(exit)(7);
}
}
void KeyAuth::api::chatget(std::string channel)
{
checkInit();
auto data =
XorStr("type=chatget") +
XorStr("&channel=") + channel +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
auto json = response_decoder.parse(response);
load_channel_data(json);
}
bool KeyAuth::api::chatsend(std::string message, std::string channel)
{
checkInit();
auto data =
XorStr("type=chatsend") +
XorStr("&message=") + message +
XorStr("&channel=") + channel +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
auto json = response_decoder.parse(response);
load_response_data(json);
return json[("success")];
}
void KeyAuth::api::changeUsername(std::string newusername)
{
checkInit();
auto data =
XorStr("type=changeUsername") +
XorStr("&newUsername=") + newusername +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, response.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(response);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
load_response_data(json);
}
else {
LI_FN(exit)(9);
}
}
else {
LI_FN(exit)(7);
}
}
void KeyAuth::api::web_login()
{
checkInit();
// from https://perpetualprogrammers.wordpress.com/2016/05/22/the-http-server-api/
// Initialize the API.
ULONG result = 0;
HTTPAPI_VERSION version = HTTPAPI_VERSION_2;
result = HttpInitialize(version, HTTP_INITIALIZE_SERVER, 0);
if (result == ERROR_INVALID_PARAMETER) {
MessageBoxA(NULL, "The Flags parameter contains an unsupported value.", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result != NO_ERROR) {
MessageBoxA(NULL, "System error for Initialize", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
// Create server session.
HTTP_SERVER_SESSION_ID serverSessionId;
result = HttpCreateServerSession(version, &serverSessionId, 0);
if (result == ERROR_REVISION_MISMATCH) {
MessageBoxA(NULL, "Version for session invalid", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_INVALID_PARAMETER) {
MessageBoxA(NULL, "pServerSessionId parameter is null", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result != NO_ERROR) {
MessageBoxA(NULL, "System error for HttpCreateServerSession", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
// Create URL group.
HTTP_URL_GROUP_ID groupId;
result = HttpCreateUrlGroup(serverSessionId, &groupId, 0);
if (result == ERROR_INVALID_PARAMETER) {
MessageBoxA(NULL, "Url group create parameter error", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result != NO_ERROR) {
MessageBoxA(NULL, "System error for HttpCreateUrlGroup", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
// Create request queue.
HANDLE requestQueueHandle;
result = HttpCreateRequestQueue(version, NULL, NULL, 0, &requestQueueHandle);
if (result == ERROR_REVISION_MISMATCH) {
MessageBoxA(NULL, "Wrong version", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_INVALID_PARAMETER) {
MessageBoxA(NULL, "Byte length exceeded", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_ALREADY_EXISTS) {
MessageBoxA(NULL, "pName already used", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_ACCESS_DENIED) {
MessageBoxA(NULL, "queue access denied", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_DLL_INIT_FAILED) {
MessageBoxA(NULL, "Initialize not called", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result != NO_ERROR) {
MessageBoxA(NULL, "System error for HttpCreateRequestQueue", "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
// Attach request queue to URL group.
HTTP_BINDING_INFO info;
info.Flags.Present = 1;
info.RequestQueueHandle = requestQueueHandle;
result = HttpSetUrlGroupProperty(groupId, HttpServerBindingProperty, &info, sizeof(info));
if (result == ERROR_INVALID_PARAMETER) {
MessageBoxA(NULL, XorStr("Invalid parameter").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result != NO_ERROR) {
MessageBoxA(NULL, XorStr("System error for HttpSetUrlGroupProperty").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
// Add URLs to URL group.
PCWSTR url = L"http://localhost:1337/handshake";
result = HttpAddUrlToUrlGroup(groupId, url, 0, 0);
if (result == ERROR_ACCESS_DENIED) {
MessageBoxA(NULL, XorStr("No permissions to run web server").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_ALREADY_EXISTS) {
MessageBoxA(NULL, XorStr("You are running this program already").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_INVALID_PARAMETER) {
MessageBoxA(NULL, XorStr("ERROR_INVALID_PARAMETER for HttpAddUrlToUrlGroup").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result == ERROR_SHARING_VIOLATION) {
MessageBoxA(NULL, XorStr("Another program is using the webserver. Close Razer Chroma mouse software if you use that. Try to restart computer.").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
if (result != NO_ERROR) {
MessageBoxA(NULL, XorStr("System error for HttpAddUrlToUrlGroup").c_str(), "Error", MB_ICONEXCLAMATION);
LI_FN(exit)(0);
}
// Announce that it is running.
// wprintf(L"Listening. Please submit requests to: %s\n", url);
// req to: http://localhost:1337/handshake?user=mak&token=2f3e9eccc22ee583cf7bad86c751d865
bool going = true;
while (going == true)
{
// Wait for a request.
HTTP_REQUEST_ID requestId = 0;
HTTP_SET_NULL_ID(&requestId);
int bufferSize = 4096;
int requestSize = sizeof(HTTP_REQUEST) + bufferSize;
BYTE* buffer = new BYTE[requestSize];
PHTTP_REQUEST pRequest = (PHTTP_REQUEST)buffer;
RtlZeroMemory(buffer, requestSize);
ULONG bytesReturned;
result = HttpReceiveHttpRequest(
requestQueueHandle,
requestId,
HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
pRequest,
requestSize,
&bytesReturned,
NULL
);
// Display some information about the request.
// wprintf(L"Full URL: %ws\n", pRequest->CookedUrl.pFullUrl);
// wprintf(L" Path: %ws\n", pRequest->CookedUrl.pAbsPath);
// wprintf(L" Query: %ws\n", pRequest->CookedUrl.pQueryString);
std::wstring ws(pRequest->CookedUrl.pQueryString);
std::string myVarS = std::string(ws.begin(), ws.end());
std::string user = get_str_between_two_str(myVarS, "?user=", "&");
std::string token = get_str_between_two_str(myVarS, "&token=", "");
// std::cout << get_str_between_two_str(CW2A(pRequest->CookedUrl.pQueryString), "?", "&") << std::endl;
// break if preflight request from browser
if (pRequest->Verb == HttpVerbOPTIONS)
{
// Respond to the request.
HTTP_RESPONSE response;
RtlZeroMemory(&response, sizeof(response));
response.StatusCode = 200;
response.pReason = static_cast<PCSTR>(XorStr("OK").c_str());
response.ReasonLength = (USHORT)strlen(response.pReason);
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/6d468747-2221-4f4a-9156-f98f355a9c08/using-httph-to-set-up-an-https-server-that-is-queried-by-a-client-that-uses-cross-origin-requests?forum=vcgeneral
HTTP_UNKNOWN_HEADER accessControlHeader;
const char testCustomHeader[] = "Access-Control-Allow-Origin";
const char testCustomHeaderVal[] = "*";
accessControlHeader.pName = testCustomHeader;
accessControlHeader.NameLength = _countof(testCustomHeader) - 1;
accessControlHeader.pRawValue = testCustomHeaderVal;
accessControlHeader.RawValueLength = _countof(testCustomHeaderVal) - 1;
response.Headers.pUnknownHeaders = &accessControlHeader;
response.Headers.UnknownHeaderCount = 1;
// Add an entity chunk to the response.
// PSTR pEntityString = "Hello from C++";
HTTP_DATA_CHUNK dataChunk;
dataChunk.DataChunkType = HttpDataChunkFromMemory;
result = HttpSendHttpResponse(
requestQueueHandle,
pRequest->RequestId,
0,
&response,
NULL,
NULL, // &bytesSent (optional)
NULL,
0,
NULL,
NULL
);
delete[]buffer;
continue;
}
// keyauth request
std::string hwid = utils::get_hwid();
auto data =
XorStr("type=login") +
XorStr("&username=") + user +
XorStr("&token=") + token +
XorStr("&hwid=") + hwid +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto resp = req(data, api::url);
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, resp.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(resp);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
if (api::response.message != XorStr("Initialized").c_str()) {
LI_FN(GlobalAddAtomA)(seed.c_str());
std::string file_path = XorStr("C:\\ProgramData\\").c_str() + seed;
std::ofstream file(file_path);
if (file.is_open()) {
file << seed;
file.close();
}
std::string regPath = XorStr("Software\\").c_str() + seed;
HKEY hKey;
LONG result = RegCreateKeyExA(HKEY_CURRENT_USER, regPath.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
if (result == ERROR_SUCCESS) {
LI_FN(RegSetValueExA)(hKey, seed.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE*>(seed.c_str()), seed.size() + 1);
LI_FN(RegCloseKey)(hKey);
}
LI_FN(GlobalAddAtomA)(ownerid.c_str());
}
else {
LI_FN(exit)(12);
}
// Respond to the request.
HTTP_RESPONSE response;
RtlZeroMemory(&response, sizeof(response));
bool success = true;
if (json[(XorStr("success"))])
{
load_user_data(json[(XorStr("info"))]);
response.StatusCode = 420;
response.pReason = XorStr("SHEESH").c_str();
response.ReasonLength = (USHORT)strlen(response.pReason);
}
else
{
response.StatusCode = 200;
response.pReason = static_cast<std::string>(json[(XorStr("message"))]).c_str();
response.ReasonLength = (USHORT)strlen(response.pReason);
success = false;
}
// end keyauth request
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/6d468747-2221-4f4a-9156-f98f355a9c08/using-httph-to-set-up-an-https-server-that-is-queried-by-a-client-that-uses-cross-origin-requests?forum=vcgeneral
HTTP_UNKNOWN_HEADER accessControlHeader;
const char testCustomHeader[] = "Access-Control-Allow-Origin";
const char testCustomHeaderVal[] = "*";
accessControlHeader.pName = testCustomHeader;
accessControlHeader.NameLength = _countof(testCustomHeader) - 1;
accessControlHeader.pRawValue = testCustomHeaderVal;
accessControlHeader.RawValueLength = _countof(testCustomHeaderVal) - 1;
response.Headers.pUnknownHeaders = &accessControlHeader;
response.Headers.UnknownHeaderCount = 1;
// Add an entity chunk to the response.
// PSTR pEntityString = "Hello from C++";
HTTP_DATA_CHUNK dataChunk;
dataChunk.DataChunkType = HttpDataChunkFromMemory;
result = HttpSendHttpResponse(
requestQueueHandle,
pRequest->RequestId,
0,
&response,
NULL,
NULL, // &bytesSent (optional)
NULL,
0,
NULL,
NULL
);
if (result == NO_ERROR) {
going = false;
}
delete[]buffer;
if (!success)
LI_FN(exit)(0);
}
else {
LI_FN(exit)(9);
}
}
else {
LI_FN(exit)(7);
}
}
}
void KeyAuth::api::button(std::string button)
{
checkInit();
// from https://perpetualprogrammers.wordpress.com/2016/05/22/the-http-server-api/
// Initialize the API.
ULONG result = 0;
HTTPAPI_VERSION version = HTTPAPI_VERSION_2;
result = HttpInitialize(version, HTTP_INITIALIZE_SERVER, 0);
// Create server session.
HTTP_SERVER_SESSION_ID serverSessionId;
result = HttpCreateServerSession(version, &serverSessionId, 0);
// Create URL group.
HTTP_URL_GROUP_ID groupId;
result = HttpCreateUrlGroup(serverSessionId, &groupId, 0);
// Create request queue.
HANDLE requestQueueHandle;
result = HttpCreateRequestQueue(version, NULL, NULL, 0, &requestQueueHandle);
// Attach request queue to URL group.
HTTP_BINDING_INFO info;
info.Flags.Present = 1;
info.RequestQueueHandle = requestQueueHandle;
result = HttpSetUrlGroupProperty(groupId, HttpServerBindingProperty, &info, sizeof(info));
// Add URLs to URL group.
std::wstring output;
output = std::wstring(button.begin(), button.end());
output = std::wstring(L"http://localhost:1337/") + output;
PCWSTR url = output.c_str();
result = HttpAddUrlToUrlGroup(groupId, url, 0, 0);
// Announce that it is running.
// wprintf(L"Listening. Please submit requests to: %s\n", url);
// req to: http://localhost:1337/buttonvaluehere
bool going = true;
while (going == true)
{
// Wait for a request.
HTTP_REQUEST_ID requestId = 0;
HTTP_SET_NULL_ID(&requestId);
int bufferSize = 4096;
int requestSize = sizeof(HTTP_REQUEST) + bufferSize;
BYTE* buffer = new BYTE[requestSize];
PHTTP_REQUEST pRequest = (PHTTP_REQUEST)buffer;
RtlZeroMemory(buffer, requestSize);
ULONG bytesReturned;
result = HttpReceiveHttpRequest(
requestQueueHandle,
requestId,
HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
pRequest,
requestSize,
&bytesReturned,
NULL
);
going = false;
// Display some information about the request.
// wprintf(L"Full URL: %ws\n", pRequest->CookedUrl.pFullUrl);
// wprintf(L" Path: %ws\n", pRequest->CookedUrl.pAbsPath);
// wprintf(L" Query: %ws\n", pRequest->CookedUrl.pQueryString);
// std::cout << get_str_between_two_str(CW2A(pRequest->CookedUrl.pQueryString), "?", "&") << std::endl;
// Break from the loop if it's the poison pill (a DELETE request).
// if (pRequest->Verb == HttpVerbDELETE)
// {
// wprintf(L"Asked to stop.\n");
// break;
// }
// Respond to the request.
HTTP_RESPONSE response;
RtlZeroMemory(&response, sizeof(response));
response.StatusCode = 420;
response.pReason = XorStr("SHEESH").c_str();
response.ReasonLength = (USHORT)strlen(response.pReason);
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/6d468747-2221-4f4a-9156-f98f355a9c08/using-httph-to-set-up-an-https-server-that-is-queried-by-a-client-that-uses-cross-origin-requests?forum=vcgeneral
HTTP_UNKNOWN_HEADER accessControlHeader;
const char testCustomHeader[] = "Access-Control-Allow-Origin";
const char testCustomHeaderVal[] = "*";
accessControlHeader.pName = testCustomHeader;
accessControlHeader.NameLength = _countof(testCustomHeader) - 1;
accessControlHeader.pRawValue = testCustomHeaderVal;
accessControlHeader.RawValueLength = _countof(testCustomHeaderVal) - 1;
response.Headers.pUnknownHeaders = &accessControlHeader;
response.Headers.UnknownHeaderCount = 1;
// Add an entity chunk to the response.
// PSTR pEntityString = "Hello from C++";
HTTP_DATA_CHUNK dataChunk;
dataChunk.DataChunkType = HttpDataChunkFromMemory;
result = HttpSendHttpResponse(
requestQueueHandle,
pRequest->RequestId,
0,
&response,
NULL,
NULL, // &bytesSent (optional)
NULL,
0,
NULL,
NULL
);
delete[]buffer;
}
}
void KeyAuth::api::regstr(std::string username, std::string password, std::string key, std::string email) {
checkInit();
std::string hwid = utils::get_hwid();
auto data =
XorStr("type=register") +
XorStr("&username=") + username +
XorStr("&pass=") + password +
XorStr("&key=") + key +
XorStr("&email=") + email +
XorStr("&hwid=") + hwid +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, response.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(response);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
load_response_data(json);
if (json[(XorStr("success"))])
load_user_data(json[(XorStr("info"))]);
if (api::response.message != XorStr("Initialized").c_str()) {
LI_FN(GlobalAddAtomA)(seed.c_str());
std::string file_path = XorStr("C:\\ProgramData\\").c_str() + seed;
std::ofstream file(file_path);
if (file.is_open()) {
file << seed;
file.close();
}
std::string regPath = XorStr("Software\\").c_str() + seed;
HKEY hKey;
LONG result = RegCreateKeyExA(HKEY_CURRENT_USER, regPath.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
if (result == ERROR_SUCCESS) {
LI_FN(RegSetValueExA)(hKey, seed.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE*>(seed.c_str()), seed.size() + 1);
LI_FN(RegCloseKey)(hKey);
}
LI_FN(GlobalAddAtomA)(ownerid.c_str());
}
else {
LI_FN(exit)(12);
}
}
else {
LI_FN(exit)(9);
}
}
else
{
LI_FN(exit)(7);
}
}
void KeyAuth::api::upgrade(std::string username, std::string key) {
checkInit();
auto data =
XorStr("type=upgrade") +
XorStr("&username=") + username +
XorStr("&key=") + key +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, response.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(response);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
json[(XorStr("success"))] = false;
load_response_data(json);
}
else {
LI_FN(exit)(9);
}
}
else {
LI_FN(exit)(7);
}
}
std::string generate_random_number() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dist_length(5, 10); // Random length between 5 and 10 digits
std::uniform_int_distribution<> dist_digit(0, 9); // Random digit
int length = dist_length(gen);
std::string random_number;
for (int i = 0; i < length; ++i) {
random_number += std::to_string(dist_digit(gen));
}
return random_number;
}
void KeyAuth::api::license(std::string key) {
// Call threads to start in 15 seconds..
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)checkAtoms, 0, 0, 0);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)checkFiles, 0, 0, 0);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)checkRegistry, 0, 0, 0);
checkInit();
std::string hwid = utils::get_hwid();
auto data =
XorStr("type=license") +
XorStr("&key=") + key +
XorStr("&hwid=") + hwid +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
std::hash<int> hasher;
int expectedHash = hasher(42);
int result = VerifyPayload(signature, signatureTimestamp, response.data());
if ((hasher(result ^ 0xA5A5) & 0xFFFF) == (expectedHash & 0xFFFF))
{
auto json = response_decoder.parse(response);
if (json[(XorStr("ownerid"))] != ownerid) {
LI_FN(exit)(8);
}
std::string message = json[(XorStr("message"))];
std::hash<int> hasher;
size_t expectedHash = hasher(68);
size_t resultCode = hasher(json[(XorStr("code"))]);
if (!json[(XorStr("success"))] || (json[(XorStr("success"))] && (resultCode == expectedHash))) {
load_response_data(json);
if (json[(XorStr("success"))])
load_user_data(json[(XorStr("info"))]);
if (api::response.message != XorStr("Initialized").c_str()) {