Using NTAPI Undocumented Functions

Overview

Process injection is a technique used to inject code into a running process on a target machine. This can be done to evade AV/EDRs as well as maintaining persistence on a target machine.

This technique leverages the below low-level native APIs.

NtOpenProcess - Get a handle on remote proces

NtCreateSection - This function creates a new section object in the virtual address space of a process.

NtMapViewOfSection - This function maps a section object into the virtual address space of a process. This can be used to load a DLL into a process.

NtUnmapViewOfSection - This function unmaps a previously mapped section object from the virtual address space of a process.

NtClose - This function closes a handle to an object.

Walkthrough

  1. Firstly, we will get a handle on both our local and the target remote thread.

  2. We then need to create a new RWX memory section.

  3. Map view of created section into the local process with (R-W) and map view of create section into the remote process with (R-E).

  4. Copy shellcode into the locally mapped view which will then be reflected on the remote process mapped view.

  5. Execute the shellcode in the remote process.

Example payload

Map view of created section into the remote process

We can verify the view has been create with RX protection.

Now we should be able to reflectively. copy our shellcode into the remote process.

We can verify this with Process Hacker 2:

Shellcode has been successfully copied into promote process memory.

Code example

Detection and AV

Detection on nt-PInject code without shellcode:

References

Last updated