$ show EgeBalci/sgn
SGN is a Rust-based polymorphic binary encoder for x86/x64 shellcode, designed for offensive security purposes such as generating statically undetectable payloads. It encodes raw binary instructions using an additive feedback loop (ADFL) cipher, producing self-decoding shellcode that appears statistically random. The tool also supports optional schema cipher obfuscation of the decoder stub, garbage instruction insertion, register preservation, and brute-force avoidance of bad characters or ASCII-only output. The architecture is a monolithic CLI tool and library, with key entry points in `main.rs` (CLI) and `lib.rs` (Encoder struct). The codebase is well-structured, with clear separation of concerns across modules for cipher, decoder stub construction, garbage generation, and register management. It demonstrates high craftsmanship in areas such as loop-free decoder stub generation, value-preserving garbage instruction generation, and efficient bad-character detection. The project is actively maintained, with a recent port to Rust from Go, and includes comprehensive tests including real execution tests for both x64 and x86 architectures.
The LLM identified 3 files worth highlighting for reuse:
Implements two ciphers: the byte-wise ADFL (additive feedback loop) cipher and a DWORD-wise schema cipher with random operations (XOR, ADD, SUB, ROL, ROR, NOT). Both are self-contained, reversible, and designed to be inverted by loop-free x86/x64 instruction sequences. The ADFL cipher uses a last-to-first XOR with additive feedback, and the schema cipher applies per-block transforms in little-endian DWORD view. This module could be extracted as a standalone cipher library for any project requiring reversible obfuscation.
Provides strongly-typed register pool management for x86 and x64 architectures. Maps integer indices to iced-x86 register constants (8, 32, 64-bit), supports random selection with exclusion (e.g., avoiding the loop counter register), and handles the 32-bit limitation where only EAX/EBX/ECX/EDX have addressable low bytes. This module is self-contained and could be reused in any x86 code generation project that needs register allocation.
Generates random, value-preserving garbage instructions using iced-x86's assembler. Employs recursive templates that produce no-ops (shift/rotate by zero, xor with self, self-cancelling pairs, conditional jumps over nested garbage) to ensure registers are not clobbered. The module is self-contained (only depends on registers and iced-x86) and demonstrates non-obvious skill in generating semantically neutral instructions. It could be extracted as a standalone library for code obfuscation or fuzzing.