@@ -71,7 +71,9 @@ bool initalized;
71
71
72
72
void KeyAuth::api::init ()
73
73
{
74
- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)modify, 0 , 0 , 0 );
74
+ #if defined(__x86_64__) || defined(_M_X64)
75
+ CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)modify, 0 , 0 , 0 );
76
+ #endif
75
77
76
78
if (ownerid.length () != 10 || secret.length () != 64 )
77
79
{
@@ -101,6 +103,35 @@ void KeyAuth::api::init()
101
103
XorStr (" &enckey=" ) + sentKey +
102
104
XorStr (" &name=" ) + curl_easy_escape (curl, name.c_str (), 0 ) +
103
105
XorStr (" &ownerid=" ) + ownerid;
106
+
107
+ if (path != " " ) {
108
+ // get the contents of the file
109
+ std::ifstream file (path);
110
+ std::string token;
111
+ std::string thash;
112
+ std::getline (file, token);
113
+
114
+ auto exec = [&](const char * cmd) -> std::string
115
+ {
116
+ uint16_t line = -1 ;
117
+ std::array<char , 128 > buffer;
118
+ std::string result;
119
+ std::unique_ptr<FILE, decltype (&_pclose)> pipe (_popen (cmd, " r" ), _pclose);
120
+ if (!pipe) {
121
+ throw std::runtime_error (XorStr (" popen() failed!" ));
122
+ }
123
+
124
+ while (fgets (buffer.data (), buffer.size (), pipe.get ()) != nullptr ) {
125
+ result = buffer.data ();
126
+ }
127
+ return result;
128
+ };
129
+
130
+ thash = exec ((" certutil -hashfile \" " + path + XorStr (" \" MD5 | find /i /v \" md5\" | find /i /v \" certutil\" " )).c_str ());
131
+
132
+ data += XorStr (" &token=" ).c_str () + token;
133
+ data += XorStr (" &thash=" ).c_str () + path;
134
+ }
104
135
curl_easy_cleanup (curl);
105
136
106
137
auto response = req (data, url);
@@ -1204,6 +1235,37 @@ void KeyAuth::api::forgot(std::string username, std::string email)
1204
1235
load_response_data (json);
1205
1236
}
1206
1237
1238
+ void KeyAuth::api::logout () {
1239
+ checkInit ();
1240
+
1241
+ auto data =
1242
+ XorStr (" type=logout" ) +
1243
+ XorStr (" &sessionid=" ) + sessionid +
1244
+ XorStr (" &name=" ) + name +
1245
+ XorStr (" &ownerid=" ) + ownerid;
1246
+ auto response = req (data, url);
1247
+ auto json = response_decoder.parse (response);
1248
+ if (json[(XorStr (" success" ))]) {
1249
+
1250
+ // clear all old user data from program
1251
+ user_data.createdate .clear ();
1252
+ user_data.ip .clear ();
1253
+ user_data.hwid .clear ();
1254
+ user_data.lastlogin .clear ();
1255
+ user_data.username .clear ();
1256
+ user_data.subscriptions .clear ();
1257
+
1258
+ // clear sessionid
1259
+ sessionid.clear ();
1260
+
1261
+ // clear enckey
1262
+ enckey.clear ();
1263
+
1264
+ }
1265
+
1266
+ load_response_data (json);
1267
+ }
1268
+
1207
1269
// credits https://stackoverflow.com/a/3790661
1208
1270
static std::string hexDecode (const std::string& hex)
1209
1271
{
@@ -1242,7 +1304,7 @@ std::string KeyAuth::api::req(std::string data, std::string url) {
1242
1304
1243
1305
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 1 );
1244
1306
1245
- curl_easy_setopt (curl, CURLOPT_NOPROXY, XorStr ( " keyauth.win" ) );
1307
+ curl_easy_setopt (curl, CURLOPT_NOPROXY, ( " keyauth.win" ) );
1246
1308
1247
1309
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1L );
1248
1310
curl_easy_setopt (curl, CURLOPT_CERTINFO, 1L );
@@ -1289,101 +1351,103 @@ void error(std::string message) {
1289
1351
__fastfail (0 );
1290
1352
}
1291
1353
// code submitted in pull request from https://github.com/Roblox932
1292
- auto check_section_integrity ( const char * section_name, bool fix = false ) -> bool
1354
+ auto check_section_integrity (const char * section_name, bool fix = false ) -> bool
1293
1355
{
1294
- const auto map_file = []( HMODULE hmodule ) -> std::tuple<std::uintptr_t , HANDLE>
1356
+ const auto map_file = [](HMODULE hmodule) -> std::tuple<std::uintptr_t , HANDLE>
1295
1357
{
1296
- wchar_t filename[ MAX_PATH ];
1358
+ wchar_t filename[MAX_PATH];
1297
1359
DWORD size = MAX_PATH;
1298
1360
QueryFullProcessImageName (GetCurrentProcess (), 0 , filename, &size);
1299
1361
1300
1362
1301
- const auto file_handle = CreateFile ( filename, GENERIC_READ, FILE_SHARE_READ, 0 , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
1302
- if ( !file_handle || file_handle == INVALID_HANDLE_VALUE )
1363
+ const auto file_handle = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, 0 , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
1364
+ if (!file_handle || file_handle == INVALID_HANDLE_VALUE)
1303
1365
{
1304
1366
return { 0ull , nullptr };
1305
1367
}
1306
1368
1307
- const auto file_mapping = CreateFileMapping ( file_handle, 0 , PAGE_READONLY, 0 , 0 , 0 );
1308
- if ( !file_mapping )
1369
+ const auto file_mapping = CreateFileMapping (file_handle, 0 , PAGE_READONLY, 0 , 0 , 0 );
1370
+ if (!file_mapping)
1309
1371
{
1310
- CloseHandle ( file_handle );
1372
+ CloseHandle (file_handle);
1311
1373
return { 0ull , nullptr };
1312
1374
}
1313
1375
1314
- return { reinterpret_cast < std::uintptr_t >( MapViewOfFile ( file_mapping, FILE_MAP_READ, 0 , 0 , 0 ) ), file_handle };
1376
+ return { reinterpret_cast <std::uintptr_t >( MapViewOfFile (file_mapping, FILE_MAP_READ, 0 , 0 , 0 ) ), file_handle };
1315
1377
};
1316
1378
1317
- const auto hmodule = GetModuleHandle ( 0 );
1318
- if ( !hmodule ) return true ;
1379
+ const auto hmodule = GetModuleHandle (0 );
1380
+ if (!hmodule) return true ;
1319
1381
1320
- const auto base_0 = reinterpret_cast < std::uintptr_t >( hmodule );
1321
- if ( !base_0 ) return true ;
1382
+ const auto base_0 = reinterpret_cast <std::uintptr_t >( hmodule);
1383
+ if (!base_0) return true ;
1322
1384
1323
- const auto dos_0 = reinterpret_cast < IMAGE_DOS_HEADER * >( base_0 );
1324
- if ( dos_0->e_magic != IMAGE_DOS_SIGNATURE ) return true ;
1385
+ const auto dos_0 = reinterpret_cast <IMAGE_DOS_HEADER*>( base_0);
1386
+ if (dos_0->e_magic != IMAGE_DOS_SIGNATURE) return true ;
1325
1387
1326
- const auto nt_0 = reinterpret_cast < IMAGE_NT_HEADERS * >( base_0 + dos_0->e_lfanew );
1327
- if ( nt_0->Signature != IMAGE_NT_SIGNATURE ) return true ;
1388
+ const auto nt_0 = reinterpret_cast <IMAGE_NT_HEADERS*>( base_0 + dos_0->e_lfanew );
1389
+ if (nt_0->Signature != IMAGE_NT_SIGNATURE) return true ;
1328
1390
1329
- auto section_0 = IMAGE_FIRST_SECTION ( nt_0 );
1391
+ auto section_0 = IMAGE_FIRST_SECTION (nt_0);
1330
1392
1331
- const auto [base_1, file_handle] = map_file ( hmodule );
1332
- if ( !base_1 || !file_handle || file_handle == INVALID_HANDLE_VALUE ) return true ;
1393
+ const auto [base_1, file_handle] = map_file (hmodule);
1394
+ if (!base_1 || !file_handle || file_handle == INVALID_HANDLE_VALUE) return true ;
1333
1395
1334
- const auto dos_1 = reinterpret_cast < IMAGE_DOS_HEADER * >( base_1 );
1335
- if ( dos_1->e_magic != IMAGE_DOS_SIGNATURE )
1396
+ const auto dos_1 = reinterpret_cast <IMAGE_DOS_HEADER*>( base_1);
1397
+ if (dos_1->e_magic != IMAGE_DOS_SIGNATURE)
1336
1398
{
1337
- UnmapViewOfFile ( reinterpret_cast < void * >( base_1 ) );
1338
- CloseHandle ( file_handle );
1399
+ UnmapViewOfFile (reinterpret_cast <void *>( base_1) );
1400
+ CloseHandle (file_handle);
1339
1401
return true ;
1340
1402
}
1341
1403
1342
- const auto nt_1 = reinterpret_cast < IMAGE_NT_HEADERS * >( base_1 + dos_1->e_lfanew );
1343
- if ( nt_1->Signature != IMAGE_NT_SIGNATURE ||
1404
+ const auto nt_1 = reinterpret_cast <IMAGE_NT_HEADERS*>( base_1 + dos_1->e_lfanew );
1405
+ if (nt_1->Signature != IMAGE_NT_SIGNATURE ||
1344
1406
nt_1->FileHeader .TimeDateStamp != nt_0->FileHeader .TimeDateStamp ||
1345
- nt_1->FileHeader .NumberOfSections != nt_0->FileHeader .NumberOfSections )
1407
+ nt_1->FileHeader .NumberOfSections != nt_0->FileHeader .NumberOfSections )
1346
1408
{
1347
- UnmapViewOfFile ( reinterpret_cast < void * >( base_1 ) );
1348
- CloseHandle ( file_handle );
1409
+ UnmapViewOfFile (reinterpret_cast <void *>( base_1) );
1410
+ CloseHandle (file_handle);
1349
1411
return true ;
1350
1412
}
1351
1413
1352
- auto section_1 = IMAGE_FIRST_SECTION ( nt_1 );
1414
+ auto section_1 = IMAGE_FIRST_SECTION (nt_1);
1353
1415
1354
1416
bool patched = false ;
1355
- for ( auto i = 0 ; i < nt_1->FileHeader .NumberOfSections ; ++i, ++section_0, ++section_1 )
1417
+ for (auto i = 0 ; i < nt_1->FileHeader .NumberOfSections ; ++i, ++section_0, ++section_1)
1356
1418
{
1357
- if ( strcmp ( reinterpret_cast < char * >( section_0->Name ), section_name ) ||
1358
- !( section_0->Characteristics & IMAGE_SCN_MEM_EXECUTE ) ) continue ;
1419
+ if (strcmp (reinterpret_cast <char *>( section_0->Name ), section_name) ||
1420
+ !(section_0->Characteristics & IMAGE_SCN_MEM_EXECUTE) ) continue ;
1359
1421
1360
- for ( auto i = 0u ; i < section_0->SizeOfRawData ; ++i )
1422
+ for (auto i = 0u ; i < section_0->SizeOfRawData ; ++i)
1361
1423
{
1362
- const auto old_value = *reinterpret_cast < BYTE * >( base_1 + section_1->PointerToRawData + i );
1424
+ const auto old_value = *reinterpret_cast <BYTE*>( base_1 + section_1->PointerToRawData + i);
1363
1425
1364
- if ( *reinterpret_cast < BYTE * >( base_0 + section_0->VirtualAddress + i ) == old_value )
1426
+ if (*reinterpret_cast <BYTE*>( base_0 + section_0->VirtualAddress + i) == old_value)
1365
1427
{
1366
1428
continue ;
1367
1429
}
1368
1430
1369
- if ( fix )
1431
+ if (fix)
1370
1432
{
1371
- DWORD new_protect { PAGE_EXECUTE_READWRITE }, old_protect;
1372
- VirtualProtect ( ( void * )( base_0 + section_0->VirtualAddress + i ), sizeof ( BYTE ), new_protect, &old_protect );
1373
- *reinterpret_cast < BYTE * >( base_0 + section_0->VirtualAddress + i ) = old_value;
1374
- VirtualProtect ( ( void * )( base_0 + section_0->VirtualAddress + i ), sizeof ( BYTE ), old_protect, &new_protect );
1433
+ DWORD old_protect = 0 ;
1434
+ DWORD* target_address = reinterpret_cast <DWORD*>(base_0 + section_0->VirtualAddress + i);
1435
+ DWORD new_protect = PAGE_EXECUTE_READWRITE;
1436
+
1437
+ if (target_address != nullptr ) {
1438
+ if (VirtualProtect (reinterpret_cast <void *>(target_address), sizeof (DWORD), new_protect, &old_protect)) {}
1439
+ else { break ; }
1440
+ }
1441
+ //
1442
+ *reinterpret_cast <BYTE*>(base_0 + section_0->VirtualAddress + i) = old_value;
1443
+ VirtualProtect ((void *)(base_0 + section_0->VirtualAddress + i), sizeof (BYTE), old_protect, &new_protect);
1375
1444
}
1376
1445
1377
1446
patched = true ;
1378
1447
}
1379
1448
1380
1449
break ;
1381
1450
}
1382
-
1383
- UnmapViewOfFile ( reinterpret_cast < void * >( base_1 ) );
1384
- CloseHandle ( file_handle );
1385
-
1386
- return patched;
1387
1451
}
1388
1452
1389
1453
std::string checksum ()
@@ -1432,8 +1496,61 @@ std::string getPath() {
1432
1496
}
1433
1497
}
1434
1498
1499
+ void RedactField (nlohmann::json& jsonObject, const std::string& fieldName)
1500
+ {
1501
+
1502
+ if (jsonObject.contains (fieldName)) {
1503
+ jsonObject[fieldName] = " REDACTED" ;
1504
+ }
1505
+ }
1506
+
1435
1507
void debugInfo (std::string data, std::string url, std::string response) {
1436
1508
1509
+ // turn response into json
1510
+ nlohmann::json responses = nlohmann::json::parse (response);
1511
+ RedactField (responses, " sessionid" );
1512
+ RedactField (responses, " ownerid" );
1513
+ RedactField (responses, " app" );
1514
+ RedactField (responses, " name" );
1515
+ RedactField (responses, " contents" );
1516
+ RedactField (responses, " key" );
1517
+ RedactField (responses, " username" );
1518
+ RedactField (responses, " password" );
1519
+ RedactField (responses, " secret" );
1520
+ RedactField (responses, " version" );
1521
+ RedactField (responses, " fileid" );
1522
+ RedactField (responses, " webhooks" );
1523
+ std::string redacted_response = responses.dump ();
1524
+
1525
+ // turn data into json
1526
+ std::replace (data.begin (), data.end (), ' &' , ' ' );
1527
+
1528
+ nlohmann::json datas;
1529
+
1530
+ std::istringstream iss (data);
1531
+ std::vector<std::string> results ((std::istream_iterator<std::string>(iss)),
1532
+ std::istream_iterator<std::string>());
1533
+
1534
+ for (auto const & value : results) {
1535
+ datas[value.substr (0 , value.find (' =' ))] = value.substr (value.find (' =' ) + 1 );
1536
+ }
1537
+
1538
+ RedactField (datas, " sessionid" );
1539
+ RedactField (datas, " ownerid" );
1540
+ RedactField (datas, " app" );
1541
+ RedactField (datas, " name" );
1542
+ RedactField (datas, " key" );
1543
+ RedactField (datas, " username" );
1544
+ RedactField (datas, " password" );
1545
+ RedactField (datas, " contents" );
1546
+ RedactField (datas, " secret" );
1547
+ RedactField (datas, " version" );
1548
+ RedactField (datas, " fileid" );
1549
+ RedactField (datas, " webhooks" );
1550
+
1551
+ std::string redacted_data = datas.dump ();
1552
+
1553
+
1437
1554
// gets the path
1438
1555
std::string path = getPath ();
1439
1556
@@ -1496,7 +1613,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
1496
1613
1497
1614
std::string currentTimeString = std::to_string (hours) + " :" + formattedMinutes + " " + period;
1498
1615
1499
- std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + data + " \n Response : " + response + " Sent to: " + url;
1616
+ std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + redacted_data + " \n Response : " + redacted_response + " Sent to: " + url;
1500
1617
1501
1618
logfile << contents;
1502
1619
0 commit comments