Guest User

Untitled

a guest
Oct 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1.     IMAGE_NT_HEADERS inh;
  2.     IMAGE_DOS_HEADER idh;
  3.     PROCESS_BASIC_INFORMATION pbi;
  4.     PROCESS_INFORMATION pi;
  5.     STARTUPINFO si;
  6.     PEB peb;
  7.     PVOID imagebase;
  8.     LPBYTE addr;
  9.     DWORD entry;
  10.     char old[2];
  11.     CONTEXT ctx;
  12.     MAX_PATH;
  13.     memset(&si, 0, sizeof(si));
  14.     si.cb = sizeof(si);
  15.  
  16.     if (CreateProcess(file, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
  17.         NtQueryInformationProcess(pi.hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
  18.        
  19.         if (ReadProcessMemory(pi.hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL))
  20.             printf("PEB read from remote process\n");
  21.  
  22.         ReadProcessMemory(pi.hProcess, peb.ImageBaseAddress, &idh, sizeof(idh), NULL);
  23.        
  24.         addr = (LPBYTE)peb.ImageBaseAddress + idh.e_lfanew;
  25.  
  26.         if (ReadProcessMemory(pi.hProcess, addr, &inh, sizeof(inh), NULL))
  27.             printf("NT_HEADER read from remote process\n");
  28.        
  29.         printf("%u.%u\n", inh.OptionalHeader.MajorLinkerVersion, inh.OptionalHeader.MinorLinkerVersion);
  30.  
  31.         entry = inh.OptionalHeader.ImageBase + inh.OptionalHeader.AddressOfEntryPoint;
  32.  
  33.         printf("entry %d %d\n", peb.ImageBaseAddress, entry);
  34.        
  35.         ReadProcessMemory(pi.hProcess, (PVOID)entry, old, 2, NULL);
  36.  
  37.         WriteProcessMemory(pi.hProcess, (PVOID)entry, "\xEB\xFE", 2, NULL);
  38.  
  39.         ctx.ContextFlags = CONTEXT_CONTROL;
  40.  
  41.         GetThreadContext(pi.hThread, &ctx);
  42.  
  43.         ctx.Eip = entry;
  44.  
  45.         SetThreadContext(pi.hThread, &ctx);
  46.  
  47.         ResumeThread(pi.hThread);
  48.        
  49.         // i like dick in my ass
  50.  
  51.         MessageBox(NULL, L"imdabestmayne", NULL, 0);
  52.  
  53.         SuspendThread(pi.hThread);
  54.        
  55.         WriteProcessMemory(pi.hProcess, (PVOID)entry, old, 2, NULL); // restore OEP
  56.  
  57.         GetThreadContext(pi.hThread, &ctx);
  58.  
  59.         ctx.Eip = entry;
  60.  
  61.         SetThreadContext(pi.hThread, &ctx);
  62.  
  63.         ResumeThread(pi.hThread);
  64.  
  65.         CloseHandle(pi.hThread);
  66.         CloseHandle(pi.hProcess);
  67.     }
Add Comment
Please, Sign In to add comment