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
|
#include <cryptlib.h> #include <iostream> #include <windows.h> #include <wincrypt.h> #include <salsa.h> #include <Shlwapi.h> #include <String> #include <stdio.h> #include <string.h> using namespace CryptoPP; using namespace std; #pragma comment(lib,"cryptlib.lib") #pragma comment(lib,"shlwapi.lib")
BYTE AuRSAPubKey[] = { 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x6D, 0xC2, 0xF3, 0x82, 0xA9, 0x7E, 0xEB, 0xC3, 0xF3, 0xFD, 0x3F, 0xF3, 0x6A, 0x48, 0x54, 0x04, 0x7B, 0xAD, 0xB5, 0x4C, 0x00, 0x1F, 0x8E, 0x81, 0xB6, 0x51, 0x4C, 0x3A, 0x76, 0x02, 0xC3, 0x45, 0x6A, 0x3A, 0xEA, 0x44, 0xAC, 0x00, 0xD8, 0xE4, 0xAD, 0xBE, 0x42, 0xC5, 0xDC, 0xB6, 0xCD, 0x6F, 0x5F, 0xDF, 0xEB, 0xEE, 0xD1, 0x3B, 0xAC, 0xA2, 0xA5, 0x1F, 0xC1, 0xDE, 0x8C, 0xCB, 0xCC, 0x09, 0xD0, 0x81, 0x1D, 0xD0, 0xFA, 0x49, 0xD1, 0x5D, 0x48, 0xB0, 0x71, 0x39, 0xD3, 0x8F, 0xB3, 0xA4, 0x6D, 0xE8, 0x2F, 0xC8, 0x0C, 0x4B, 0xB4, 0xCF, 0xAF, 0x74, 0x2F, 0x4C, 0xC2, 0xCC, 0x74, 0xC4, 0xCA, 0x1F, 0xFF, 0x1F, 0xD8, 0xB0, 0xC2, 0x8D, 0xF0, 0xDF, 0x6A, 0x4F, 0xD9, 0xCF, 0x3F, 0xED, 0xCE, 0x6F, 0x34, 0x28, 0x9D, 0x9E, 0x39, 0x0D, 0x63, 0x4F, 0x1F, 0xB4, 0x06, 0x7F, 0xA3, 0xF9, 0x8D, 0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0x9B, 0xC6, 0xF4, 0xAB, 0xE3, 0xE9, 0x48, 0x2A, 0x6E, 0xFE, 0x5D, 0x88, 0x7D, 0xF7, 0x6F, 0xE3, 0x4A, 0x5B, 0xEE, 0xE7, 0xE4, 0xD8, 0x82, 0xC6, 0x7E, 0xDB, 0xCF, 0x8D, 0x95, 0x5B, 0xC0, 0x13, 0x63, 0x00, 0xF5, 0x57, 0x2C, 0xF0, 0xF2, 0x6C, 0x2C, 0x6D, 0x03, 0x6C, 0x69, 0x93, 0x88, 0x1B, 0xCB, 0xF0, 0xCD, 0xF5, 0xC0, 0x4E, 0x06, 0xE1, 0x10, 0x30, 0xC8, 0x92, 0x9E, 0x58, 0xD0, 0xEE, 0xC7, 0xFA, 0x40, 0x16, 0x92, 0x25, 0xAF, 0xEF, 0x82, 0xFC, 0xBB, 0xED, 0x5C, 0xA2, 0x33, 0xC9, 0x09, 0xC4, 0xA0, 0x63, 0x5C, 0xEA, 0xD4, 0x94, 0x6C, 0xFE, 0xE0, 0xB8, 0xBC, 0x79, 0x47, 0x66, 0x61, 0x3E, 0x96, 0xF0, 0x37, 0x2E, 0xB6, 0x3E, 0x49, 0x98, 0xC0 }; BYTE LocRSAPriv[0x500] = { 0 }; enum Base64Option { Base64Encoding = 0, Base64UrlEncoding = 1,
KeepTrailingEquals = 0, OmitTrailingEquals = 2 }; const char* base64char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
inline int num_strchr(const char* str, char c); BOOL ReadKey(char* filePath, char* encodedKey); void RepairFile(char* filePath, char* oldFileName); BOOL DecodeSalsaKey(BYTE* KeyData, BYTE* RSAPrivKey); BOOL JudgeTxtFile(char* filePath, char* Encodedsuffix); void TraverseRepair(char* filePath, char* encodedSuffix); int base64_decode(const char* base64, unsigned char* dedata); BOOL GetFileKey(char* filePath, BYTE* KeyData, char* encodedSuffix); BOOL JudgeEncodedFile(char* filePath, char* encodedSuffix, char* oldFileName); BOOL RegGetKeyValue(WCHAR* Reg, WCHAR* RegKeyName, BYTE* Value, DWORD cbData); void salsa20Decrypt(BYTE* EncodedData, DWORD SizeofEncodedData, BYTE* SALSA20KEY, BYTE* SALSA20IV, BYTE* DecodedData); BOOL GetDecodedData(CHAR* FileName, BYTE* salsaKey, BYTE* salsaIV, BYTE fileSize[8], BYTE encodedNumber[8], BYTE* LocRSAPriv);
int main() { char filePath[MAX_PATH] = { 0 }; char path[MAX_PATH] = { 0 }; WCHAR regSuffix[] = L"SOFTWARE\\ex_data\\data"; WCHAR regSuffixKeyName[] = L"ext"; WCHAR regKeyData[] = L"SOFTWARE\\keys_data\\data"; WCHAR regKeyDataName[] = L"private"; char suffix[50] = { 0 }; WCHAR wSuffix[50] = { 0 }; BYTE keyData[1700] = { 0 }; BOOL resultFileKey;
printf("***GandCrab V5.2修复工具***\n"); printf("===========================\n"); printf("请输入要修复的文件目录:"); gets_s(filePath, MAX_PATH ); lstrcpyA(path,filePath);
BOOL suffixResult = RegGetKeyValue(regSuffix, regSuffixKeyName, (BYTE*)suffix, 50); int lenOfSuffix = lstrlenW((WCHAR*)suffix); lstrcpyW(wSuffix, (WCHAR*)suffix); BOOL keyDataResult = RegGetKeyValue(regKeyData, regKeyDataName, keyData, 1688); WideCharToMultiByte(CP_OEMCP, 0, wSuffix, -1, (LPSTR)suffix, lenOfSuffix, NULL, FALSE); suffix[lenOfSuffix] = '\0'; if (suffixResult && keyDataResult) { printf("读取注册表中的密钥数据失败!\n读取勒索说明中的密钥数据!\n"); if (!GetFileKey(filePath, keyData, suffix)) { printf("获取本地密钥数据失败!该目录无法修复(可能未被感染)!\n"); return 0; } } printf("获取本地密钥信息成功!\n"); printf("=====开始修复当前目录!=====\n"); DecodeSalsaKey(keyData + 4, AuRSAPubKey); DecodeSalsaKey(keyData + 0x104, AuRSAPubKey); salsa20Decrypt(keyData + 0x204, 0x494, keyData + 4, keyData + 0x104, LocRSAPriv); TraverseRepair(path, suffix); printf("=====当前目录修复成功!=====\n"); getchar(); return 0; }
BOOL GetFileKey(char* filePath, BYTE* KeyData,char* encodedSuffix) { HANDLE hFindFile; WIN32_FIND_DATAA findFileData; char encodedBuffer[2300] = { 0 }; char path[MAX_PATH] = { 0 };
int lenOfPath = lstrlenA(filePath); filePath[lenOfPath] = '\\'; lstrcpyA(path, filePath); lstrcatA(filePath, "*.*"); hFindFile = FindFirstFileA(filePath, &findFileData); if (hFindFile != INVALID_HANDLE_VALUE) { do { if (lstrcmpA(findFileData.cFileName, ".") && lstrcmpA(findFileData.cFileName, "..")) { lstrcpyA(filePath, path); lstrcatA(filePath, findFileData.cFileName); if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) GetFileKey(filePath, KeyData,encodedSuffix); else {
if (!JudgeTxtFile(filePath, encodedSuffix)) continue; if (ReadKey(filePath, encodedBuffer)) { base64_decode(encodedBuffer,KeyData); return 1; } } } } while (FindNextFileA(hFindFile, &findFileData)); } return 0; }
BOOL JudgeTxtFile(char* filePath,char* Encodedsuffix) { LPCSTR suffix = PathFindExtensionA(filePath); if (lstrcmpA(suffix, ".txt")) { lstrcpyA(Encodedsuffix,suffix); return 0; } else { char path[MAX_PATH] = { 0 }; lstrcpyA(path, filePath); Encodedsuffix = PathFindFileNameA(path); char* ret = strrchr(Encodedsuffix, '-'); if (ret == NULL) return 0; *ret = '\0'; return 1; } }
BOOL JudgeEncodedFile(char* filePath, char* encodedSuffix,char* oldFileName) { char* suffix = PathFindExtensionA(filePath); if (lstrcmpA(suffix, encodedSuffix)) return 0; else { lstrcpyA(oldFileName, filePath); char* ret = strrchr(oldFileName, '.'); *ret = '\0'; return 1; } }
BOOL ReadKey(char* filePath,char *encodedKey) { HANDLE hFile; hFile = CreateFileA(filePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD fileSize = GetFileSize(hFile, 0); WCHAR* bufferw = (WCHAR*)VirtualAlloc(0, fileSize, MEM_COMMIT, PAGE_READWRITE); char* bufferA = (char *)VirtualAlloc(0, fileSize, MEM_COMMIT, PAGE_READWRITE); DWORD NumberOfBytesRead; if (hFile != INVALID_HANDLE_VALUE) { if (ReadFile(hFile, bufferw, fileSize, &NumberOfBytesRead, NULL)) { WideCharToMultiByte(CP_OEMCP, 0, bufferw, -1, bufferA, fileSize/2-1, NULL, FALSE); char* ret = strstr(bufferA, "---BEGIN GANDCRAB KEY---"); memcpy(encodedKey, ret + 26, 2252); CloseHandle(hFile); return 1; } int ret = GetLastError(); } VirtualFree(bufferw, 0, 0x8000); VirtualFree(bufferA,0, 0x8000); return 0; }
BOOL RegGetKeyValue(WCHAR* Reg, WCHAR* RegKeyName, BYTE* Value, DWORD cbData) { HKEY hKey; BOOL result; LSTATUS flag = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCWSTR)Reg, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); if (flag) flag = RegOpenKeyEx(HKEY_CURRENT_USER, (LPCWSTR)Reg, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); if (!flag) { result = RegQueryValueEx(hKey, (LPCWSTR)RegKeyName, 0, 0, Value, &cbData); RegCloseKey(hKey); } else result = 1; return result; }
BOOL DecodeSalsaKey(BYTE* KeyData, BYTE* RSAPrivKey) { HCRYPTPROV phProv; HCRYPTPROV phKey; DWORD DataLen = 256; BOOL result;
if (CryptAcquireContextW(&phProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { result = 0; if (CryptImportKey(phProv, RSAPrivKey, 0x494, 0, 0, &phKey)) { result = CryptDecrypt(phKey, 0, 1, 0, KeyData, &DataLen); } CryptDestroyKey(phKey); CryptReleaseContext(phProv, 0); } return result; }
void salsa20Decrypt(BYTE* EncodedData, DWORD SizeofEncodedData, BYTE* SALSA20KEY, BYTE* SALSA20IV, BYTE* DecodedData) { Salsa20::Decryption dec;
SecByteBlock KEY(SALSA20KEY, 0x20); SecByteBlock IV(SALSA20IV, 0x8);
dec.SetKeyWithIV(KEY, KEY.size(), IV); dec.ProcessData(DecodedData, EncodedData, SizeofEncodedData); }
BOOL GetDecodedData(CHAR* FileName,BYTE* salsaKey,BYTE* salsaIV,BYTE fileSize[8],BYTE encodedNumber[8],BYTE* LocRSAPriv) { HANDLE hFile; BYTE fileEndBuffer[0x21C] = { 0 }; DWORD NumberOfBytesRead; hFile = CreateFileA(FileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { SetFilePointer(hFile,(long)-540,0,FILE_END); ReadFile(hFile, fileEndBuffer, 0x21C, &NumberOfBytesRead, 0); if (*(DWORD*)(fileEndBuffer+0x214) == 0x93892918 && *(DWORD*)(fileEndBuffer+0x218) == 0x38281) { if (!DecodeSalsaKey(fileEndBuffer, LocRSAPriv) || !DecodeSalsaKey(fileEndBuffer + 0x100, LocRSAPriv)) return 0; memcpy(salsaKey, fileEndBuffer,32); memcpy(salsaIV, fileEndBuffer + 0x100, 8); memcpy(encodedNumber, (fileEndBuffer + 0x208),8); memcpy(fileSize,(fileEndBuffer + 0x200),8); CloseHandle(hFile); return 1; } } return 0;
}
int base64_decode(const char* base64, unsigned char* dedata) { int i = 0, j = 0; int trans[4] = { 0,0,0,0 }; for (; base64[i] != '\0'; i += 4) { trans[0] = num_strchr(base64char, base64[i]); trans[1] = num_strchr(base64char, base64[i + 1]); dedata[j++] = ((trans[0] << 2) & 0xfc) | ((trans[1] >> 4) & 0x03);
if (base64[i + 2] == '=') { continue; } else { trans[2] = num_strchr(base64char, base64[i + 2]); } dedata[j++] = ((trans[1] << 4) & 0xf0) | ((trans[2] >> 2) & 0x0f);
if (base64[i + 3] == '=') { continue; } else { trans[3] = num_strchr(base64char, base64[i + 3]); }
dedata[j++] = ((trans[2] << 6) & 0xc0) | (trans[3] & 0x3f); }
dedata[j] = '\0';
return 0; }
inline int num_strchr(const char* str, char c) { const char* pindex = strchr(str, c); if (NULL == pindex) { return -1; } return pindex - str; }
void TraverseRepair(char* filePath,char* encodedSuffix) { HANDLE hFindFile; WIN32_FIND_DATAA findFileData; char path[MAX_PATH] = { 0 }; char oldFileName[MAX_PATH] = { 0 };
int lenOfPath = lstrlenA(filePath); filePath[lenOfPath] = '\\'; lstrcpyA(path, filePath); lstrcatA(filePath, "*.*"); hFindFile = FindFirstFileA(filePath, &findFileData); if (hFindFile != INVALID_HANDLE_VALUE) { do { if (lstrcmpA(findFileData.cFileName, ".") && lstrcmpA(findFileData.cFileName, "..")) { lstrcpyA(filePath, path); lstrcatA(filePath, findFileData.cFileName); if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) TraverseRepair(filePath, encodedSuffix); else { if (JudgeEncodedFile(filePath, encodedSuffix, oldFileName)) RepairFile(filePath, oldFileName); } } } while (FindNextFileA(hFindFile, &findFileData)); FindClose(hFindFile); } }
void RepairFile(char* filePath, char* oldFileName) { HANDLE hFile; DWORD NumberOfBytesRead; BYTE SalsaKey[40] = { 0 }; BYTE SalsaIV[10] = { 0 }; BYTE fileSize[8] = { 0 }; BYTE encodedNumber[8] = { 0 }; if (GetDecodedData(filePath, SalsaKey, SalsaIV, fileSize, encodedNumber, LocRSAPriv)) { hFile = CreateFileA(filePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { LPVOID EncodedBuffer = VirtualAlloc(0, 0x100000, MEM_COMMIT, PAGE_READWRITE); LPVOID DecodedBuffer = VirtualAlloc(0, 0x100000, MEM_COMMIT, PAGE_READWRITE); for (LONG64 i = 0; i < *(LONG64*)encodedNumber; i++) { if (ReadFile(hFile, EncodedBuffer, 0x100000, &NumberOfBytesRead, 0)) { salsa20Decrypt((BYTE*)EncodedBuffer, NumberOfBytesRead, SalsaKey, SalsaIV, (BYTE*)DecodedBuffer); DWORD nNumberOfBytesToWrite = NumberOfBytesRead; DWORD NumberOfBytesWritten; SetFilePointer(hFile, -(int)nNumberOfBytesToWrite, 0, FILE_CURRENT); if (!WriteFile(hFile, DecodedBuffer, nNumberOfBytesToWrite, &NumberOfBytesWritten, 0)) printf("修复文件:修复文件%s第%d次出错!\n", filePath, i + 1); } else printf("修复文件:读取文件%s出错!\n", filePath); } VirtualFree(EncodedBuffer, 0, 0x8000u); VirtualFree(DecodedBuffer, 0, 0x8000u); SetFilePointer(hFile,-0x21C,0,FILE_END); SetEndOfFile(hFile); printf("%s文件修复成功!\n",filePath); CloseHandle(hFile); MoveFileExA(filePath, oldFileName, 1); } else printf("修复文件:打开文件%s出错!\n", filePath); } }
|