hex_analysis — Claude Code rule: hex signatures and compiler flags
hex_analysis — a rule file that explains YARA hex signatures for AdaptixC2: which instruction produced each one and which compiler flag moves those bytes.
MIT ★ 336 updated 2026-04-09
.claude/rules/hex_analysis.mdWhat hex_analysis does
The rule goes through hex patterns from two Elastic rules (Windows_Trojan_Adaptix_2779784c, Windows_Trojan_Adaptix_b2cda978) and from the CAPE AdaptixBeacon set. Each signature gets four notes: the kind of code it is, what the bytes decode to, the source construct behind it, and the flag that shifts it. A prologue that reserves 424 bytes of stack (sub rsp, 0x1A8) is traced to heavy locals or struct initialisation.
Half of the file is a Makefile diff. EVASION_FLAGS gains -fno-inline-functions-small, -fno-inline-functions-called-once, -fno-expensive-optimizations plus three switches that drop vectorisation: -fno-tree-loop-vectorize, -fno-tree-slp-vectorize, -fno-tree-vect-loop-version. -fno-exceptions stays in OPTIMIZATION_FLAGS. A table lines up every flag with the change it causes in the emitted code.
Flags do not cover everything. The $wininet_1–$wininet_2 patterns hunt for the stack string wininet.dll assembled one character at a time, and the beacon already builds it through HdChrA() in ConnectorHTTP.cpp:62-74. Optimisation can still produce matching bytes. For the XOR-like $a5, the analysis states that flags may not be enough and the source needs a rewrite.
What it helps with
- decode what a YARA byte sequence actually means
- trace a stack-allocation prologue back to the function behind it
- choose compiler flags that shift one specific signature
- rewrite
EVASION_FLAGSandOPTIMIZATION_FLAGSin the beacon Makefile - tell which patterns need a code change rather than a flag
Example prompts for the agent
- Walk me through pattern
$a2inWindows_Trojan_Adaptix_2779784c: where thesub rsp, 0x58prologue comes from and which flag changes it. - Add the flags that break the prologue patterns to
EVASION_FLAGSand show the Makefile diff. - Check
$wininet_1and$wininet_2: does another optimisation level help, or do I have to touchHdChrA()?
How to install hex_analysis
Manually: put the files in place
.claude/rules/hex_analysis.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/hex_analysis.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/hex_analysis.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/hex_analysis.mdManually: put the files in place
.clinerules/hex_analysis.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about hex_analysis
How do I install hex_analysis in Claude Code?
Copy the rule file into your project at .claude/rules/hex_analysis.md. That path is the whole install.
What does hex_analysis do?
It annotates AdaptixC2 YARA signatures with the code that produced them, then lists Makefile flag changes that alter the generated bytes.
Will compiler flags defeat every pattern?
No. The analysis says the XOR-like $a5 pattern may survive flag changes and call for a source rewrite.
Source text
hex_analysis.md · MIT
## Hex Pattern Analysis for AdaptixC2
### Elastic Security Rules (Windows_Trojan_Adaptix)
#### Rule: Windows_Trojan_Adaptix_2779784c
**Pattern $a1:**
```
48 81 EC A8 01 00 00 48 8B 84 24 C0 01 00 00 48 C7 00 00 00 00 00 ...
```
- **Type:** Function prologue with large stack allocation
- **Meaning:** `sub rsp, 0x1A8` (424 bytes) + memory operations
- **Source Cause:** Function with large local variables or struct initialization
- **Evasion Method:** Compiler flags change stack allocation and instruction ordering
**Pattern $a2:**
```
48 83 EC 58 48 8B 4C 24 70 E8 ?? ?? ?? ?? 89 44 24 38 ...
```
- **Type:** Function prologue with moderate stack allocation
- **Meaning:** `sub rsp, 0x58` (88 bytes) + function calls
- **Source Cause:** Medium-sized function with local variables
- **Evasion Method:** Compiler flags change optimization and stack layout
#### Rule: Windows_Trojan_Adaptix_b2cda978
**Pattern $a1:**
```
48 89 03 8B 45 EC 48 98 48 8D 14 C5 00 00 00 00 ...
```
- **Type:** Memory operations with conditional logic
- **Evasion Method:** Compiler flags
**Pattern $a2:**
```
48 89 45 D0 48 8B 4D 10 E8 4C 9F 00 00 ...
```
- **Type:** Stack variable storage with function calls
- **Evasion Method:** Compiler flags
**Pattern $a3:**
```
8B 53 54 48 89 C6 31 C0 48 39 C2 74 0B ...
```
- **Type:** Memory copy/set loop
- **Evasion Method:** Compiler flags
**Pattern $a4:**
```
48 89 45 E0 48 83 7D E0 00 75 17 ...
```
- **Type:** Error handling path
- **Evasion Method:** Compiler flags
**Pattern $a5:**
```
48 83 EC 10 89 4D 10 C7 ?? ?? ?? ?? ?? ?? ...
```
- **Type:** XOR-like operations (possibly encryption)
- **Evasion Method:** Compiler flags may help; source refactoring may be needed
### CAPE Rule (AdaptixBeacon)
#### Config Patterns ($conf_1 to $conf_5)
These patterns detect config initialization code. They are compiler-generated and can be evaded with compiler flag changes.
#### Wininet Patterns ($wininet_1, $wininet_2)
```
B9 77 00 00 00 (mov ecx, 0x77 = 'w')
B9 69 00 00 00 (mov ecx, 0x69 = 'i')
B9 6E 00 00 00 (mov ecx, 0x6E = 'n')
B9 65 00 00 00 (mov ecx, 0x65 = 'e')
```
**Analysis:**
- These patterns detect stack string construction for "wininet.dll"
- The beacon already uses obfuscation via `HdChrA()` function (ConnectorHTTP.cpp:62-74)
- The current code uses character-by-character construction with a macro
**Current Code (already obfuscated):**
```cpp
CHAR wininet_c[12];
wininet_c[0] = HdChrA('w');
wininet_c[1] = HdChrA('i');
wininet_c[2] = HdChrA('n');
// ... etc
```
**Status:** Already partially obfuscated. The YARA patterns may still match due to compiler optimization producing similar byte sequences.
---
## Makefile Changes Applied
### Beacon Makefile (Before):
```makefile
EVASION_FLAGS := -O2 \
-fomit-frame-pointer \
-fno-ident \
-ffunction-sections \
-fdata-sections \
-fmerge-all-constants
OPTIMIZATION_FLAGS := -fno-exceptions \
-fno-unwind-tables \
-fno-asynchronous-unwind-tables
```
### Beacon Makefile (After):
```makefile
EVASION_FLAGS := -O2 \
-fomit-frame-pointer \
-fno-ident \
-ffunction-sections \
-fdata-sections \
-fmerge-all-constants \
-fno-inline-functions-small \
-fno-inline-functions-called-once \
-fno-expensive-optimizations \
-fno-tree-loop-vectorize \
-fno-tree-slp-vectorize \
-fno-tree-vect-loop-version \
-fno-unwind-tables \
-fno-asynchronous-unwind-tables
OPTIMIZATION_FLAGS := -fno-exceptions
```
### Expected Hex Pattern Changes:
| Flag | Effect |
|------|--------|
| `-fno-inline-functions-small` | Prevents inlining of small functions, changes call patterns |
| `-fno-inline-functions-called-once` | Changes function call structure |
| `-fno-expensive-optimizations` | Uses simpler instruction sequences |
| `-fno-tree-loop-vectorize` | Changes loop code generation |
| `-fno-tree-slp-vectorize` | Changes memory operation patterns |
| `-fno-tree-vect-loop-version` | Alters loop prologue/epilogue |
© JDArmy · MIT · JDArmy/Evasion-SubAgents