Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How kernel mode injection works?
- 1) Get the address of KdVersionBlock from KPCR. (__readfsdword)
- 2) Get the address of MmLoadedUserImageList from KdVersionBlock.
- 3) Get the base address of ntdll from MmLoadedUserImageList.
- 4) Parse the export table of ntdll to locate LdrLoadDll.
- 5) Find a thread to hijack. (ZwQuerySystemInformation)
- 6) Open the target process. (PsLookupProcessByProcessId)
- 7) Open the target thread. (PsLookupThreadByThreadId)
- 8) Attach to target process's address space. (KeAttachProcess)
- 8) Allocate memory in target process's address space. (ZwAllocateVirtualMemory)
- 9) Copy the DLL name and APC routine into target process's address space. (memcpy,RtlInitUnicodeString)
- 10) Set ApcState.UserApcPending to TRUE to force the target thread to execute the APC routine.
- 11) Allocate an APC object from nonpaged pool. (ExAllocatePool)
- 12) Initialize the APC and insert it to the target thread. (KeInitializeApc,KeInsertQueueApc)
- 13) The target thread executes the APC routine in target process's address space. The APC routine calls LdrLoadDll to load the DLL.
- 14) Wait for the APC routine to complete.
- 15) Free the allocated memory. (ZwFreeVirtualMemory,ExFreePool)
- 16) Detach from target process's address space. (KeDetachProcess)
- 17) Dereference the target process and target thread. (ObDereferenceObject)
- Usage:
- To use the injector, run install.bat to install the driver, and then run kinject.exe from command prompt.
- kinject [PID] [DLL name]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement