Windows x64 handcrafted token stealing kernel-mode shellcode
github.com
github.com
"You have at least two race condition bugs in your code: manual traverse of ActiveProcessLinks without locking the list, and same issue with process objects you're working with. Correct approach: use appropriate kernel functions to reference needed _EPROCESS in error safe way."
And https://twitter.com/d_olex/status/1544013068388433920:
"Seriously, never ever touch nt!PsActiveProcessHead list with your own code, nt!ZwQuerySystemInformation() with SystemProcessInformation info class can do it for you without any risks to catch BSoD ... and if you want direct _EPROCESS pointer for your fuckery -- it's better to obtain it with nt!PsLookupProcessByProcessId() and free it with nt!ObDereferenceObject() call at the end."
Yes they do, they absolutely do - especially at this level. An easy way to get caught is to show up in a crashdump that automated software flags.
Shellcode can be hard to write since it might be a small amount of code you can execute, you might not be able to jump precisely to your code, it might have to use a limited range of values (such as correctly parsing as something else) or other challenges.
> Windows x64 kernel-mode handcrafted shellcode to replace primary access token of executing process with SYSTEM process token for Elevation of Privilege(EoP).
So yes, privilege escalation.
You can do things with IoAllocateMdl, MmProbeAndLockProcessPages, MmMapLockedPagesSpecifyCache, MmProtectMdlSystemAddress to achieve such tasks.
They don't even need to be public, you can just walk the exports of ntoskrnl.exe etc.
You can even do insane shit like changing the PML4 of a process to the PML4 of another and have them point to the same memory. Or change the Win32Thread of your KTHREAD structure to that of explorer.exe and draw on the screen from kernel with GDI commands.