Overview
Stardust provides two primary methods for accessing Windows APIs:- PEB Resolution: Loading modules already loaded in the process
- Runtime Loading: Dynamically loading new libraries with
LoadLibraryA
Loading from PEB vs Runtime
Method 1: PEB Resolution
Best for: Core system libraries (ntdll.dll, kernel32.dll, kernelbase.dll)- No system calls required
- Already loaded in most processes
- Stealthy - no additional loading artifacts
- Faster than LoadLibrary
resolve::module() function walks the Process Environment Block (PEB):
src/resolve.cc
- Accesses
PEB->Ldr->InLoadOrderModuleList - Iterates through
LDR_DATA_TABLE_ENTRYstructures - Matches against FNV-1a hash of
BaseDllName - Returns module base address or 0 if not found
Method 2: Runtime Loading
Best for: Non-core libraries (user32.dll, advapi32.dll, wininet.dll, etc.)- Can load any library on the system
- Works even if the library wasn’t initially loaded
- Required for non-standard libraries
- Creates events that can be monitored (DLL load events)
- Slower than PEB resolution
- May trigger security solutions
Complete Example: Loading Multiple Libraries
Step 1: Define Module Structures
Ininclude/common.h, add your module definitions:
include/macros.h
Step 2: Initialize in Constructor
src/main.cc
Step 3: Load Additional Libraries at Runtime
src/main.cc
Advanced Pattern: Module Manager
For more complex shellcode, create a helper function:Best Practices
1. Minimize Runtime Loading
Good:2. Error Handling
Always validate:3. Load Order Matters
Correct order:4. Module Cleanup (Optional)
For long-running shellcode:Common Libraries and Use Cases
| Library | Load Method | Common APIs | Use Case |
|---|---|---|---|
| ntdll.dll | PEB | NtAllocateVirtualMemory, NtProtectVirtualMemory | Low-level system calls |
| kernel32.dll | PEB | LoadLibraryA, VirtualAlloc, CreateThread | Core Windows APIs |
| user32.dll | Runtime | MessageBoxA, CreateWindowEx, FindWindowA | GUI operations |
| advapi32.dll | Runtime | RegOpenKeyEx, CryptAcquireContext | Registry, crypto |
| wininet.dll | Runtime | InternetOpenA, HttpSendRequest | HTTP/HTTPS |
| ws2_32.dll | Runtime | WSAStartup, socket, connect | Network sockets |
| shell32.dll | Runtime | ShellExecuteA, SHGetFolderPath | Shell operations |
Troubleshooting
Module Not Found in PEB
API Resolution Fails
LoadLibrary Returns NULL
Next Steps
- Explore Advanced Techniques
- Review the API Resolution Reference
- Learn about Adding APIs
