Documentation Index
Fetch the complete documentation index at: https://mintlify.com/HavocFramework/Havoc/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Theshellcode command provides capabilities for injecting raw shellcode into processes using either process injection (into existing processes) or fork & run (spawning new processes). Multiple injection techniques are supported with varying OPSEC profiles.
Syntax
Injection Methods
inject
Inject shellcode into an existing process.Architecture of the shellcode:
x86- 32-bit shellcodex64- 64-bit shellcode
Process ID of the target process to inject into
Local path to the raw shellcode file (will be uploaded to agent)
Optional arguments to pass to the shellcode (base64 encoded)
spawn
Spawn a new process and inject shellcode (fork & run).Architecture:
x86- Spawns 32-bit processx64- Spawns 64-bit process
Local path to the raw shellcode file
Optional arguments to pass to the shellcode
execute
Execute shellcode directly in the current process.Injection Techniques
The injection technique can be configured using theconfig command:
- Default (0)
- CreateRemoteThread (1)
- NtCreateThreadEx (2)
- NtQueueApcThread (3)
Uses the default injection method configured in the profile.Process Flow:
- Open target process
- Allocate memory (respects
config memory.alloc) - Write shellcode
- Protect memory (respects
config memory.execute) - Create thread (respects
config inject.technique)
Memory Allocation Techniques
Configure memory allocation method:0-VirtualAllocEx(Win32 API)1-NtAllocateVirtualMemory(Indirect syscall)
Memory Protection Techniques
Configure memory protection method:0-VirtualProtectEx(Win32 API)1-NtProtectVirtualMemory(Indirect syscall)
Return Values
Injection result:
INJECT_ERROR_SUCCESS(0) - Injection succeededINJECT_ERROR_FAILED(1) - General failureINJECT_ERROR_INVALID_PARAM(2) - Invalid parametersINJECT_ERROR_PROCESS_ARCH_MISMATCH(3) - Architecture mismatch
Thread ID of the created thread (if successful)
Examples
Basic Process Injection
Fork & Run with Configured Spawn Process
Advanced Injection with Custom Technique
Shellcode with Arguments
32-bit Injection
OPSEC Considerations
Process Selection
Good Injection Targets:- Long-running system processes
- Processes with legitimate network activity
- Processes matching your shellcode architecture
- Protected processes (PPL)
- Antivirus/EDR processes
- System critical processes (csrss.exe, lsass.exe)
Spawn Process Selection
Configure legitimate-looking spawn processes:API Call Flow
Depending on configuration, the following API sequence is used:INJECTION_TECHNIQUE_SYSCALL with all syscall options:
CreateProcessA(spawning only)NtAllocateVirtualMemory*(indirect syscall)NtWriteVirtualMemory*(indirect syscall)NtProtectVirtualMemory*(indirect syscall)NtCreateThreadEx*orNtQueueApcThread*(indirect syscall)NtResumeThread*(indirect syscall)
* indicates indirect syscall usage
Memory Permissions
- Avoid RWX memory if possible (highly suspicious)
- Use RW allocation, write shellcode, then change to RX
- Configure with
memory.allocandmemory.execute
Detection Vectors
- Process Open: Opening handles to inject into processes
- Memory Allocation: Allocating executable memory in remote processes
- Thread Creation: Creating threads in remote processes
- Memory Permissions: RWX memory regions
- Shellcode Signatures: Known beacon/payload signatures
Use Cases
Cobalt Strike Beacon Injection
Metasploit Payload Injection
Custom Shellcode Runner
Architecture Mismatch
Injecting shellcode into a process with mismatched architecture will fail:- Cannot inject x64 shellcode into x86 process
- Cannot inject x86 shellcode into x64 process (WoW64 exception may apply)
Configuration Summary
Notes
- Shellcode files are automatically chunked for upload (max 30MB per chunk)
- Injection respects the configured injection technique
- Failed injections return error codes for troubleshooting
- Always test shellcode in a lab environment first
- Some shellcode (like Cobalt Strike beacons) may require specific arguments
- Suspended processes created with
proc create suspendedare good injection targets
