# Shellcode detection evasion via encryption and API hashing

Encrypted or stego shellcode, non-default API hashes, AMSI patching, and PE entry-point overwrites that slip past scanners

_Area: Memory corruption and native code. Seen in 3 disclosed reports; latest 2026-11-17. Updated 2026-11-17._

## How it works
Scanners often match artifacts, not behavior: a known API-hash constant, a recognizable entry-point prologue, or the assumption that a scan function runs unmodified. The attacker keeps behavior identical and changes the artifact. Encrypting or hiding the payload in image pixels means the scanner never sees shellcode bytes at rest [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md). Recomputing API hashes with a different rotation constant means the hash table no longer matches signatures [E3](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md). Overwriting a benign host PE's entry point with position-independent shellcode pivots execution into the loader while the file still looks like a known binary [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md). The broken assumption is that the scanner's view of the payload equals what actually executes.

## Where it shows up
- .NET loaders referencing `System.Drawing.Bitmap` and `LockBits`, reading per-channel pixel bytes [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md)
- XOR/arithmetic transforms over pixel channels (e.g. `255 - red` XOR a constant) [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md)
- AES key/IV stored in a config class alongside the encrypted blob [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md)
- Shellcode resolving APIs by hash with a non-default rotation constant [E3](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md)
- PowerShell staging via `DownloadString`/`IEX` and a Base64 blob decoding to a .NET assembly [E4]
- Benign host PE (WinRAR, x64dbg, Firefox Launcher) with an obfuscated entry-point prologue, GetPC image-base computation, call/pop string tricks [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md)
- Embedded PNGs with a truncated IHDR width field (non-zero MSB), or a gradient key leaving plaintext strings [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md)

## How to review
For each stage ask: does the scanner see the same bytes that execute? The invariant is that any transform between stored payload and executed code (encryption, stego extraction, hash recomputation, entry-point redirection) must be reversed before judging safety. Check that detection does not rely solely on a fixed constant (hash value, prologue bytes) an attacker can regenerate. For a signed or known binary, verify the on-disk entry point still matches the original. Treat embedded PNGs whose IHDR width field is truncated (non-zero MSB) as a cheap static red flag, not as an evasion mechanism itself [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md).

## How finders spotted it
- Reverse-engineered samples: noticed an obfuscated entry-point prologue, GetPC image-base computation, call/pop string tricks, an invalid PNG with truncated IHDR, a sparse XOR key leaving plaintext strings, and opaque predicates in the decryption loop [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md)
- Manually followed the lure, confirmed the clipboard command, read the encrypted JS (`ENC`/`KEY_HEX`, rolling XOR), unpacked stages in dnSpy, recovered the AES key/IV from config, and reimplemented the stego algorithm to extract shellcode [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md)
- Noticed similar families shared identical hashing logic; googling default hashes (e.g. `0x726774c`) returned Metasploit/Cobalt Strike hits. A crude test substituting `0x11111111` saw 15 vendors fail detection, which is what suggested vendors key on these hashes; then refined by changing the rotation constant to keep code functional [E3](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md)
- Hunted persistence footholds, found an `LTSvc` scheduled task invoking PowerShell; beautified the one-liner by inserting newlines after semicolons/braces, exposing `DownloadString`/`IEX` staging and a Base64 blob starting `TVqQ` that decoded to a .NET assembly [E4]

## Variants seen
- Benign host PE entry point overwritten with PIC shellcode that allocates executable memory and copies two embedded PNGs; second fake PNG hides stage-2 shellcode and XOR-encrypted stage-3 keyed by the first [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md)
- Shellcode AES-encrypted and embedded in PNG R channel, extracted via `LockBits` and XOR [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md)
- API-hash rotation constant changed and hashes recomputed to evade signature matching [E3](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md)
- PowerShell `DownloadString`/`IEX` staging a Base64-encoded .NET assembly [E4]

## Impact and severity
High: these techniques let stealers (LummaC2, Rhadamanthys) and a staged .NET payload execute on endpoints while evading AV [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md)[E4]. Impact rose when the staging chain let all subsequent PowerShell stages run unscanned, culminating in persistent C2 access [E4]; hash evasion defeated 15 vendors at once [E3](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md). The stego loader reused the same URL structure and infrastructure across payload rotations, showing durable evasion [E2](https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md). Runtime polymorphism rewrote compiler padding with CPU timestamps so the in-memory payload hash changed every execution, defeating signature-based detection [E1](https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md).

## Seen in real software
Open-source packages and projects, and products, where this pattern was found. If the target runs one, compare the version it runs with the fix.
- **Cobalt Strike** (version not stated): Hackers No Hashing | Huntress. Report: https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Areversinglabs-com-blog-threat-researchers-notebook-bubbleloader.md
- E2: https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-clickfix-malware-buried-in-images.md
- E3: https://bugbountylibrary.com/r/blog%3Ahuntress-com-blog-hackers-no-hashing-randomizing-api-hashes-to-evade-cobalt-strike-shellcode-detection.md
