This lab is for a code injection technique that leverages Native APIs NtCreateSection, NtMapViewOfSection and RtlCreateUserThread.
Section is a memory block that is shared between processes and can be created with NtCreateSection API
Before a process can read/write to that block of memory, it has to map a view of the said section, which can be done with NtMapViewOfSection
Multiple processes can read from and write to the section through the mapped views
High level overwiew of the technique:
Create a new memory section with RWX protection
Map a view of the previously created section to the local malicious process with RW protection
Map a view of the previously created section to a remote target process with RX protection. Note that by mapping the views with RW (locally) and RX (in the target process) we do not need to allocate memory pages with RWX, which may be frowned upon by some EDRs.
Fill the view mapped in the local process with shellcode. By definition, the mapped view in the target process will get filled with the same shellcode
Create a remote thread in the target process and point it to the mapped view in the target process to trigger the shellcode
Execution
Let's create a new memory section in the local process, that will have RWX access rights set:
Let's create another view of the same section in a target process (notepad.exe PID 6572 in our case), but this time with RX protection. The memory address of the view will get stored in remoteSectionAddress variable:
We can now copy the shellcode into our localSectionAddress, which will get automatically mirrored/reflected in the remoteSectionAddress as it's a view of the same section shared between our local and target processes:
memcpy(localSectionAddress, buf,sizeof(buf));
Below shows how the localSectionAddress gets filled with the shellcode and at the same time the remoteSectionAddress at 0x000002614ed50000 inside notepad (on the right) gets filled with the same shellcode:
We can now create a remote thread inside the notepad.exe and make the remoteSectionAddress its start address in order to trigger the shellcode: