Skip to content

Commit 468610b

Browse files
authored
Merge pull request #1482 from HackTricks-wiki/update_Crystal_Kit_20251013_063724
Crystal Kit
2 parents 99043b6 + 9132111 commit 468610b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/windows-hardening/av-bypass.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,66 @@ rmdir "C:\ProgramData\Microsoft\Windows Defender\Platform\5.18.25070.5-0"
975975
> [!TIP]
976976
> Note that This technique does not provide privilege escalation by itself; it requires admin rights.
977977
978+
## API/IAT Hooking + Call-Stack Spoofing with PIC (Crystal Kit-style)
979+
980+
Red teams can move runtime evasion out of the C2 implant and into the target module itself by hooking its Import Address Table (IAT) and routing selected APIs through attacker-controlled, position‑independent code (PIC). This generalises evasion beyond the small API surface many kits expose (e.g., CreateProcessA), and extends the same protections to BOFs and post‑exploitation DLLs.
981+
982+
High-level approach
983+
- Stage a PIC blob alongside the target module using a reflective loader (prepended or companion). The PIC must be self‑contained and position‑independent.
984+
- As the host DLL loads, walk its IMAGE_IMPORT_DESCRIPTOR and patch the IAT entries for targeted imports (e.g., CreateProcessA/W, CreateThread, LoadLibraryA/W, VirtualAlloc) to point at thin PIC wrappers.
985+
- Each PIC wrapper executes evasions before tail‑calling the real API address. Typical evasions include:
986+
- Memory mask/unmask around the call (e.g., encrypt beacon regions, RWX→RX, change page names/permissions) then restore post‑call.
987+
- Call‑stack spoofing: construct a benign stack and transition into the target API so call‑stack analysis resolves to expected frames.
988+
- For compatibility, export an interface so an Aggressor script (or equivalent) can register which APIs to hook for Beacon, BOFs and post‑ex DLLs.
989+
990+
Why IAT hooking here
991+
- Works for any code that uses the hooked import, without modifying tool code or relying on Beacon to proxy specific APIs.
992+
- Covers post‑ex DLLs: hooking LoadLibrary* lets you intercept module loads (e.g., System.Management.Automation.dll, clr.dll) and apply the same masking/stack evasion to their API calls.
993+
- Restores reliable use of process‑spawning post‑ex commands against call‑stack–based detections by wrapping CreateProcessA/W.
994+
995+
Minimal IAT hook sketch (x64 C/C++ pseudocode)
996+
```c
997+
// For each IMAGE_IMPORT_DESCRIPTOR
998+
// For each thunk in the IAT
999+
// if imported function == "CreateProcessA"
1000+
// WriteProcessMemory(local): IAT[idx] = (ULONG_PTR)Pic_CreateProcessA_Wrapper;
1001+
// Wrapper performs: mask(); stack_spoof_call(real_CreateProcessA, args...); unmask();
1002+
```
1003+
Notes
1004+
- Apply the patch after relocations/ASLR and before first use of the import. Reflective loaders like TitanLdr/AceLdr demonstrate hooking during DllMain of the loaded module.
1005+
- Keep wrappers tiny and PIC-safe; resolve the true API via the original IAT value you captured before patching or via LdrGetProcedureAddress.
1006+
- Use RW → RX transitions for PIC and avoid leaving writable+executable pages.
1007+
1008+
Call‑stack spoofing stub
1009+
- Draugr‑style PIC stubs build a fake call chain (return addresses into benign modules) and then pivot into the real API.
1010+
- This defeats detections that expect canonical stacks from Beacon/BOFs to sensitive APIs.
1011+
- Pair with stack cutting/stack stitching techniques to land inside expected frames before the API prologue.
1012+
1013+
Operational integration
1014+
- Prepend the reflective loader to post‑ex DLLs so the PIC and hooks initialise automatically when the DLL is loaded.
1015+
- Use an Aggressor script to register target APIs so Beacon and BOFs transparently benefit from the same evasion path without code changes.
1016+
1017+
Detection/DFIR considerations
1018+
- IAT integrity: entries that resolve to non‑image (heap/anon) addresses; periodic verification of import pointers.
1019+
- Stack anomalies: return addresses not belonging to loaded images; abrupt transitions to non‑image PIC; inconsistent RtlUserThreadStart ancestry.
1020+
- Loader telemetry: in‑process writes to IAT, early DllMain activity that modifies import thunks, unexpected RX regions created at load.
1021+
- Image‑load evasion: if hooking LoadLibrary*, monitor suspicious loads of automation/clr assemblies correlated with memory masking events.
1022+
1023+
Related building blocks and examples
1024+
- Reflective loaders that perform IAT patching during load (e.g., TitanLdr, AceLdr)
1025+
- Memory masking hooks (e.g., simplehook) and stack‑cutting PIC (stackcutting)
1026+
- PIC call‑stack spoofing stubs (e.g., Draugr)
1027+
9781028
## References
9791029

1030+
- [Crystal Kit – blog](https://rastamouse.me/crystal-kit/)
1031+
- [Crystal-Kit – GitHub](https://github.com/rasta-mouse/Crystal-Kit)
1032+
- [Elastic – Call stacks, no more free passes for malware](https://www.elastic.co/security-labs/call-stacks-no-more-free-passes-for-malware)
1033+
- [Crystal Palace – docs](https://tradecraftgarden.org/docs.html)
1034+
- [simplehook – sample](https://tradecraftgarden.org/simplehook.html)
1035+
- [stackcutting – sample](https://tradecraftgarden.org/stackcutting.html)
1036+
- [Draugr – call-stack spoofing PIC](https://github.com/NtDallas/Draugr)
1037+
9801038
- [Unit42 – New Infection Chain and ConfuserEx-Based Obfuscation for DarkCloud Stealer](https://unit42.paloaltonetworks.com/new-darkcloud-stealer-infection-chain/)
9811039
- [Synacktiv – Should you trust your zero trust? Bypassing Zscaler posture checks](https://www.synacktiv.com/en/publications/should-you-trust-your-zero-trust-bypassing-zscaler-posture-checks.html)
9821040
- [Check Point Research – Before ToolShell: Exploring Storm-2603’s Previous Ransomware Operations](https://research.checkpoint.com/2025/before-toolshell-exploring-storm-2603s-previous-ransomware-operations/)

0 commit comments

Comments
 (0)