Overview
This guide covers all build options for Phantom Stealer, from basic development builds to fully obfuscated production binaries. Understanding build flags and optimization techniques is crucial for effective security research.Requirements
Minimum Requirements
Go Toolchain
Version: Go 1.21 or higherRequired for compilation. Install from go.dev
Operating System
Platform: Windows (x64)Uses Windows-specific APIs (DPAPI, GDI, Registry)
C Compiler
Compiler: GCC (MinGW-w64)Required for CGO/SQLite3 support
Git
Version Control: Git 2.0+For cloning and version management
Optional Tools
- Garble - Code obfuscation (recommended for production)
- UPX - Binary compression
- PowerShell 5.1+ - For build script automation
Environment Setup
CGO must be enabled for SQLite support, which is required for browser database decryption (passwords, cookies, history).
Build Methods
Standard Build
Basic development build with full debug symbols and console output.- Debug symbols included
- Console window visible
- Larger file size (~8-12 MB)
- Easy to debug
- Not suitable for production
- Local development
- Debugging
- Testing new features
- Learning the codebase
Production Build
Optimized build with stripped symbols and hidden console window.-ldflags- Pass flags to the linker-s- Strip symbol table (removes debugging symbols)-w- Strip DWARF debug info (removes debug metadata)-H windowsgui- Hide console window (GUI subsystem)
- File size reduced by ~30%
- No console window
- Harder to debug
- Still detectable by signature-based AV
Obfuscated Build
Maximum stealth using Garble for code obfuscation.-literals flag
-literals flag
Obfuscates string literals in the binary. This hides:
- File paths
- Registry keys
- Discord/Telegram API endpoints
- Wallet extension IDs
- Configuration strings
-tiny flag
-tiny flag
Reduces binary size by:
- Removing reflection data
- Stripping more metadata
- Optimizing string storage
-seed flag
-seed flag
Controls obfuscation determinism:
random- Different output each build (recommended)<value>- Reproducible builds with same seed
Trimpath Build
Remove absolute file paths from the binary to avoid leaking development environment information.- Full file paths (e.g.,
C:\Users\dev\phantom\main.go→phantom/main.go) - Module cache paths
- GOROOT paths
PowerShell Build Script
The includedbuild.ps1 script automates the build process with multiple options.
Basic Usage
Script Features
Script Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
-Output | String | phantom.exe | Output filename |
-Debug | Switch | false | Build with debug symbols |
-Garble | Switch | false | Enable Garble obfuscation |
-UPX | Switch | false | Compress with UPX |
Build Flags Reference
Go Build Flags
-o <filename>
-o <filename>
Specifies the output filename.
-ldflags <flags>
-ldflags <flags>
Pass flags to the Go linker.Common flags:
-s- Strip symbol table-w- Strip DWARF debug info-H windowsgui- Build GUI subsystem (no console)-X <var>=<value>- Set variable at link time
-gcflags <flags>
-gcflags <flags>
Pass flags to the Go compiler.Common flags:
-l- Disable inlining-N- Disable optimizations-m- Print optimization decisions
-trimpath
-trimpath
Remove absolute file paths from the compiled binary.
-tags <tags>
-tags <tags>
Garble Flags
-literals
-literals
Obfuscate string literals and constant expressions.Impact: Hides hardcoded strings from static analysis.
-tiny
-tiny
Optimize for smaller binary size.Impact: Removes reflection metadata, reduces size by 10-20%.
-seed
-seed
Control obfuscation reproducibility.Values:
random- Different output each build<number>- Reproducible with same seed
-debugdir
-debugdir
Generate debug information to a directory.Use case: Debug obfuscated builds.
Advanced Techniques
Variable Injection
Set configuration at build time using-ldflags -X:
- No need to edit config.go
- Different configs per build
- Scriptable deployment
Cross-Compilation
Build for different architectures:Static Linking
For maximum portability:Static linking increases binary size but eliminates dependency on system DLLs.
UPX Compression
Compress the final binary:--best- Maximum compression--lzma- Use LZMA algorithm--ultra-brute- Extreme compression (slow)
Build Optimization
Size Optimization
Minimize binary size:- Standard build: 12 MB
- Optimized build: 8 MB
- Garble + UPX: 3-4 MB
Stealth Optimization
Maximize evasion:Debug Optimization
Easier debugging:Verification
Build Verification Checklist
Common Issues
Build Errors
CGO_ENABLED error
CGO_ENABLED error
Error:
sqlite3: Binary was compiled with 'CGO_ENABLED=0'Solution:GCC not found
GCC not found
Error:
gcc: command not foundSolution:- Install MinGW-w64
- Add to PATH:
C:\mingw-w64\bin - Verify:
gcc --version
Garble build fails
Garble build fails
Error:
garble: cannot find main moduleSolution:Undefined reference to CreateDIBSection
Undefined reference to CreateDIBSection
Error: Linker error with Windows API functionsSolution:
Runtime Issues
Binary immediately exits
Binary immediately exits
Cause: Anti-analysis checks detecting VM/debuggerSolution: Build with debug config:
config/config.go
DLL load failed
DLL load failed
Cause: Missing runtime dependenciesSolution:
Browser passwords not decrypted
Browser passwords not decrypted
Cause: DPAPI decryption requires target user contextSolution: Run as the target user, not Administrator
Best Practices
Development
- Use
-Debugflag - Keep symbols for debugging
- Disable anti-analysis
- Use console output
Testing
- Standard optimized build
- Enable anti-analysis
- Test on clean VMs
- Verify data exfiltration
Production
- Use Garble obfuscation
- Random seed per build
- Remove all debug output
- Test on multiple systems
Security
- Never commit compiled binaries
- Rotate webhook URLs
- Change mutex names
- Unique BuildID per campaign
Build Recipes
Quick Development Build
Optimized Test Build
Production Stealth Build
Automated PowerShell Build
Next Steps
Quick Start
Run your first build and test data collection
Configuration
Customize modules, targets, and persistence options
Core Modules
Understand the module design and implementation
Security Research
Learn about detection and defense strategies