>_0x12Dark
←back to posts
malwarecybersecurityinfosechackingpentesting

Executing Stardust Shellcode in an Isolated vCPU

Welcome to this new Medium post, this one is the next part of this post:https://medium.com/@s12deff/executing-shellcode-in-an-isolated-vcpu-5ac0cc4baaacWant to go deeper into Windows offensive…

Executing Stardust Shellcode in an Isolated vCPU

Welcome to this new Medium post, this one is the next part of this post:

https://medium.com/@s12deff/executing-shellcode-in-an-isolated-vcpu-5ac0cc4baaac

Want to go deeper into Windows offensive development?

Video-based courses from beginner to advanced, and text-based modules (mini courses) with new releases constantly. Plus a technique database with 100+ real techniques updated weekly, and custom C2 agents and consulting for teams.

0x12 Dark Development

Introduction

In the previous one we spun up a Windows Hypervisor Platform vCPU and ran shellcode inside it. It worked, but the shellcode was blind. No PEB, no TEB, no access to ntdll or kernel32, no module list. Any real loader that walks gs:[0x60] and resolves exports by hash would fault immediately. This post solves that by mapping process structures and all required DLLs into the guest address space, and introducing a proxy that intercepts every DLL call and executes it on the host side. The result is running anyStardust, a full PIC reflective loader, inside the isolated vCPU.

Windows Hypervisor Platform (WHP) is a usermode API that lets a process create hypervisor partitions and virtual CPUs without writing a kernel driver. WHvCreatePartition, WHvMapGpaRange, WHvRunVirtualProcessor are all usermode calls.

The guest address space is Guest Physical Address (GPA) space; host memory is exposed to the guest by mapping host VAs with WHvMapGpaRange. When the vCPU exits for any reason, control returns to the host's run loop

Stardust is a PIC shellcode template written by Cracked5pider. It is position-independent, finds the PEB by reading gs:[0x60], walks InMemoryOrderModuleList to locate kernel32, resolves CreateProcessA by hash, and spawns a process. It needs a valid TEB with GS pointing at it, a readable PEB, a readable LDR with loader list entries, and the ability to call into kernel32. All of that requires work

https://github.com/Cracked5pider/Stardust

The core insight is that DLL code does not need to execute inside the guest. The shellcode only needs to read DLL exports to resolve function addresses. Once it has the address, it calls it. That call causes an execute fault. The host catches the fault, reads the registers, calls the function natively, injects the return value back into the guest, and resumes. The shellcode never executes a single byte of ntdll or kernel32 inside the vCPU. It only executes its own PIC code.

This requires three things:

  • Map DLL pages as readable but non executable
  • Intercept execute faults on DLL address ranges
  • Implement the proxy that handles the call

Methodology

Build the memory layout and 4-level paging:

  • Allocate a 2MB lowMem region as RWX
  • Place page tables, shellcode, stack, trampoline, and I/O buffer there

Map DLL modules as read-only, no-execute:

  • For each DLL (ntdll, kernel32, kernelbase, msvcrt, user32), walk its committed image regions and map every page into the guest using WHvMapGpaRange with read-only, no-execute permissions.

Record each module's VA range in g_dllRanges. The DLL data is readable so the shellcode can walk export tables. The DLL code is non-executable so any attempt to run it causes a memory access exit

Map process structures read-only:

  • Map TEB, PEB, PEB_LDR_DATA, all LDR_DATA_TABLE_ENTRY records from both InLoadOrderModuleList and InMemoryOrderModuleList, all DLL name string buffers, ProcessParameters (image path, command line, current directory, environment), heap, and ApiSetMap. Without these, Stardust's PEB walk crashes immediately

Set GS base to TEB:

The vCPU’s GS segment base is set to the current thread’s TEB address. This makes gs:[0x30] resolve to the TEB and gs:[0x60] resolve to the PEB, exactly as Stardust expects.

Set LSTAR to a trampoline:

The trampoline at GPA 0x6000 saves all syscall arguments to a struct at GPA 0x7000 (SCBUF), then HLTs. If shellcode executes a raw syscall instruction (not via DLL), the host handles the exit and reads the SSN. This is a fallback; Stardust goes through kernel32 and all calls get proxied.

Run the vCPU and handle exits:

On execute fault inside a DLL range: read RCX, RDX, R8, R9 and the stack from the guest. Translate any lowMem GPA pointers to host VAs. Call the target function natively on the host. Write RAX=result, adjust RIP and RSP to simulate a return

Full Code

The whole code is published under this GitHub repository:

GitHub - S12cybersecurity/HyperLoader: Hypervisor isolated shellcode execution environment. Maps host process memory into a guest vCPU, intercepts DLL execute faults, and proxies API calls to the host, Stardust PIC shellcode compatible

Proof of Concept

Requirements:

  • Windows 10/11
  • Hyper-V or Windows Hypervisor Platform feature enabled (OptionalFeatures -> Windows Hypervisor Platform)

Run as a standard user or admin (WHP does not require admin). On success:

--- Mapping DLLs (read-only, no execute) ---
[+] ntdll.dll 6 regions (2468 KB) at 0x7FFFA64C0000 [NO-EXEC]
[+] kernel32.dll 6 regions (816 KB) at 0x7FFFA4680000 [NO-EXEC]
[+] kernelbase.dll 9 regions (4104 KB) at 0x7FFFA36B0000 [NO-EXEC]

--- Mapping process structures ---
[+] TEB at 0xD5478E7000
[+] PEB at 0xD5478E6000
[+] Ldr at 0x7FFFA66938E0
[+] ProcessParameters at 0x291346579B0
[+] Heap at 0x291346500000 (224 KB)
[+] ApiSetMap at 0x291344000000
[+] Mapped 10 module list entries (InLoadOrder)
[+] Mapped 10 module list entries (InMemoryOrder)

[+] PT pool: 68 KB, Remapped GPA: 7796 KB, Pages: 1949, DLL ranges: 3

[+] RIP=0x4000 RSP=0x1FFF8 RCX=0x5000 (args)
[+] LSTAR=0x6000 EFER=0x101

--- Running Stardust in vCPU (DLL calls proxied to host) ---
[+] PROXY #1: DbgPrint @ 0x7FFFA64CA0E0
args: 0x291347743D5 0x29134774401 0x43 0x29134658008
ret = 0x0
[+] PROXY #2: LoadLibraryA @ 0x7FFFA46C2C80
args: 0x29134774407 0x29134774401 0x43 0x29134658008
ret = 0x7FFFA4680000
[+] PROXY #3: DbgPrint @ 0x7FFFA64CA0E0
args: 0x29134774414 0x29134774401 0x49 0x7FFFA46C4E70
ret = 0x0
[+] PROXY #4: CreateProcessA @ 0x7FFFA46C4E70
args: 0x29134774439 0x0 0x0 0x0
ret = 0x1
[+] PROXY #5: DbgPrint @ 0x7FFFA64CA0E0
args: 0x29134774459 0x29134774401 0x53 0x0
ret = 0x0
[+] HLT at RIP=0x3F01 -- Stardust finished

[+] DLL calls proxied: 5, Demand-paged: 0, Total mapped: 1949

Conclusions

The previous post showed that running shellcode in a WHP vCPU is simple. The hard part is making useful shellcode run there. Any loader that needs the PEB, the module list, or a single Win32 API call would immediately crash in a bare vCPU.

The fix is a combination of two things:

First, map everything the shellcode reads: TEB, PEB, LDR, loader list, all string buffers, process parameters, heap, ApiSetMap. Set GS base to TEB.

Second, make DLL pages non executable and proxy every DLL call to the host. The shellcode never executes inside ntdll or kernel32. It resolves addresses from the export table (readable), jumps to them (execute fault), and gets the return value back (proxy injected RAX)

📌 Follow me: 🐦 X | 💬 Discord Server | 📸 Instagram | YouTube

S12.

Executing Stardust Shellcode in an Isolated vCPU