Overview
This guide covers advanced techniques for developing sophisticated, stealthy, and optimized position-independent shellcode using Stardust.Custom Memory Allocation Patterns
Using High-Level APIs
Stardust’s kernel32 integration provides standard memory allocation:Using Low-Level Syscalls
For more stealth, bypass user-mode hooks by calling ntdll directly:Memory Utility Functions
Stardust includes position-independent memory utilities:include/memory.h
Direct Syscall Execution
Why Use Syscalls?
- Bypass user-mode hooks: EDR/AV solutions hook ntdll and kernel32
- Stealth: Direct kernel interaction
- Stability: Avoid hooked function trampolines
Syscall Stub Generation
For x64 Windows, syscalls follow this pattern:- Parsing ntdll to extract syscall numbers dynamically
- Using a version-specific lookup table
- Implementing syscall number resolution at runtime
Anti-Debugging Techniques
PEB Checks
Timing Checks
Anti-Analysis Integration
Optimizing Shellcode Size
1. Use Compiler Optimizations
ModifyMakefile:
2. Minimize String Usage
Before (larger):3. Reduce Debug Output
Debug builds are significantly larger:4. Inline Small Functions
5. Use Conditional Compilation
Thread Safety Considerations
Problem: Multiple Threads
If shellcode spawns threads or is injected into multi-threaded processes:Thread-Safe Module Resolution
The PEB walk is generally safe, but consider:Code Obfuscation
String Encryption
Control Flow Obfuscation
Performance Profiling
Measure Shellcode Execution Time
Memory Footprint
Complete Advanced Example
Security Considerations
- OPSEC: Every Windows API call creates artifacts
- Memory Protection: Avoid RWX memory when possible
- String Artifacts: All strings are embedded in shellcode
- Call Patterns: API call sequences can be signatured
- Persistence: Clean up resources to avoid detection
Next Steps
- Review Basic MessageBox Example
- Learn about Loading Libraries
- Explore the API Reference
