0xMohammedHassan/morphkatz
MorphKatz is a static C++20 Windows x64 tool that rewrites PE binaries and raw shellcode into semantically identical but byte-different variants using a Zydis-powered CFG-aware disassembler/encoder, YAML rewrite rules, and EFLAGS liveness tracking. It targets two audiences: detection engineers who can measure what percentage of their YARA/Defender/Elastic/Sigma rules survive N polymorphic variants (--variants, --target, --bisect against a live Defender via MpCmdRun), and authorized red-teamers who need reproducible, seed-based, rule-cited evasion runs with JSON/HTML diff reports for engagement deliverables. It explicitly excludes ML-behavioral evasion and live pop-malware obfuscation, restricting mutations to author-audited, semantically-proven equivalence rules.
What it is
MorphKatz ships as a single static morphkatz.exe (no runtime dependencies) for Windows 10+/Server 2019+, x64. Beyond the summary's mechanism description, the page exposes the actual command surface an engineer would drive — the flags that turn "rewrite gadgets by hand" into repeatable measurement.
How it works
Zydis recursive-descent disassembly recovers the CFG (including jump tables; data-in-code is never decoded), rewrites flow through a typed ir::Instruction IR carrying full operand metadata, and per-basic-block EFLAGS liveness (AF/CF/OF/PF/SF/ZF) guarantees rewrites don't corrupt flag state. Rewrite rules live as hot-swappable YAML under rules/x64/, each with a cited Intel SDM equivalence proof. Output is verified by re-disassembly (default) or optional Unicorn basic-block emulation. NOP padding uses 1–9-byte multi-byte NOP rotation from the Intel Optimization Reference Manual.
What to do
Blue-team coverage measurement — generate variants and get per-rule trigger percentages:
morphkatz --variants 50 --target your-yara/*.yarFind which bytes drove a Defender detection:
morphkatz scan --bisectAuto-bisect Defender anchors via MpCmdRun and feed them into the rewrite priority queue:
morphkatz --target-defenderReproducible output for a write-up (byte-for-byte identical on any machine, xoshiro256** RNG):
morphkatz --seed NOther flags: --data-morph on (XOR-encodes signature-bearing bytes in .rdata/.data, decoded at runtime by a polymorphic stub with an anti-emulation gate), --verify unicorn. Reports emit as JSON/HTML with per-offset before/after diffs and rule IDs.
Build: no .sln/.vcxproj are committed — they're CMake-generated. Needs VS 2022 17.8+ with MSVC v143, CMake 3.27+, and vcpkg. Set VCPKG_ROOT after bootstrapping, then use .\Open-in-VS.cmd (presets vs2022-x64, vs2022-x64-asan; -Fresh clears cache, -NoOpen configures only for CI). Set morphkatz as startup project.
Caveats
The page states hard scope limits worth noting before you plan around it:
- ML/behavioral detections (anything ending
!ml) evaluate global behavior and will not budge — out of scope by design. - It refuses to ship "pop-malware-of-the-month" rule packs; only author-audited rules with cited equivalence proofs are included. It deliberately does not target the current-malware list (see
RESPONSIBLE_USE.md). - Red-team use is framed strictly around a documented rules-of-engagement paper trail, not live-malware obfuscation.
flowchart TD
A[PE / shellcode input] --> B{Detection class?}
B -->|byte-pattern: YARA/Defender/Sigma/Elastic| C[Morph → byte-different, semantically identical]
B -->|!ml behavioral| D[Out of scope — won't budge]
C --> E{Verify}
E -->|re-disasm default| F[Output + JSON/HTML diff]
E -->|--verify unicorn| FOrganisations named here
- HackTool:Win32/AmDisable!MTB
Technologies named here
- MorphKatz
- Windows 10+
- Zydis
- Windows Server 2019+
- PE binaries / raw shellcode
- LIEF
- Microsoft Defender
- libyara
- Unicorn Engine
- vcpkg
- MpCmdRun.exe / Microsoft Defender
- YARA
- Elastic detection rules
- Sigma
- Beatrice.py
- Windows
- Windows Defender
- Mimikatz
Techniques named here
- Polymorphic byte-level code rewriting
- Data-section morphing
- Signature triage / bisection
- YARA-aware / Defender-feedback targeted mutation
- Detection-engineering coverage testing
- Seeded/reproducible polymorphism
- Intel SDM multi-byte NOP padding
- EFLAGS liveness dataflow analysis
- Semantic verification via re-disassembly / emulation
- Binary similarity/diff comparison
- PE hygiene manipulation
Related in Blue Team & Detection
AI-Coded Malware | Analyzing Vibe-Coded AD Enumeration | Huntress
