Overview
The syscalls-cpp framework allows you to implement custom stub generation policies. This enables advanced techniques like encryption, obfuscation, polymorphism, and metamorphism at the syscall level. This guide walks through the completecustom-generator.cpp example, which implements an encrypted shellcode generator with junk code injection.
Custom Generator Requirements
To create a custom generator, you must implement a policy with:Complete Custom Generator Example
This example implements an encrypted syscall number generator with junk code injection:The EncryptedShellGenerator
Encryption Layer System
The generator applies multiple random transformations to the syscall number:Junk Code Injection
The generator injects random “junk” instructions that don’t affect execution:Buffer Writer Helper
A simple helper class for writing bytes to the stub buffer:Using the Custom Generator
How the Encryption Works
Example Flow
Let’s say the syscall number forNtAllocateVirtualMemory is 0x18:
-
Generate Random Layers:
[ADD 0x1234, XOR 0xABCD, ROL 5] -
Encrypt (Apply Reverse):
- Start:
0x18 - Apply ROL 5 reverse (ROR 5):
0x0C000000 - Apply XOR 0xABCD:
0x0C00ABCD - Apply ADD reverse (SUB):
0x0C009999 - Result: Encrypted value
0x0C009999
- Start:
-
Generated Stub:
Benefits of Custom Generators
Polymorphism
Polymorphism
Each stub is unique due to random encryption layers and junk code. The same syscall generates different bytecode on each run.
Signature Evasion
Signature Evasion
No static patterns to signature. Security products can’t create a single signature that matches all variants.
Analysis Resistance
Analysis Resistance
The encrypted syscall number and junk code make static and dynamic analysis significantly harder.
Extensibility
Extensibility
Easy to add new obfuscation techniques: more operations, different junk patterns, or metamorphic engines.
Use Cases
- Research: Studying polymorphic code generation
- Advanced Evasion: Maximum stealth with unique per-stub bytecode
- Testing: Validating security product effectiveness against polymorphic code
- Education: Learning x64 assembly and obfuscation techniques
Performance Considerations
- Generation Time: ~1-5μs per stub (during initialization)
- Execution Time: Slower than direct due to decryption layers
- Size: Larger stubs (up to 128 bytes) due to junk and decryption
Expected Output
Advanced Customization Ideas
Metamorphic Engine
Implement code reordering, equivalent instruction substitution, and register reallocation for maximum polymorphism.
Virtualization
Create a virtual machine interpreter that executes custom bytecode to perform syscalls.
Steganography
Hide syscall numbers in seemingly legitimate data structures or code patterns.
Control Flow Flattening
Use state machines and indirect jumps to obscure the execution flow.
Testing Your Custom Generator
When developing a custom generator:- Start Simple: Begin with a basic implementation without obfuscation
- Test Core Functionality: Verify syscalls work correctly
- Add Features Incrementally: Add encryption, then junk code, then advanced features
- Validate Output: Disassemble generated stubs to verify correctness
- Benchmark: Measure performance impact of your obfuscation
Debugging Tips
See Also
- Direct Syscalls - Understanding the baseline
- Architecture - Framework internals
- Generator Policies - Built-in generators reference
- Allocator Policies - Memory allocation strategies