← Back to blog

Structural Polymorphism: Going Beyond Byte-Level Randomization

· Krait Team · 8 min read

In our polymorphic builds post, we described how Krait randomizes API hash seeds, XOR keys, encryption keys, and evasion patch variants on every build. These are byte-level changes — the binary’s overall structure stays the same, but the specific constant values are unique per build. This defeats signature-based detection that matches on byte patterns.

But byte-level polymorphism has a ceiling. Sophisticated analysis doesn’t always depend on specific byte values. Reverse engineers and automated analysis pipelines also rely on structural features of the binary: section layouts, entry point characteristics, section name patterns, file size, the ratio of code to data, and the entropy profile of different regions. If every binary your tool produces has the same sections in the same order with the same names and the same entropy distribution, that structural fingerprint becomes the signature — even when no two builds share a single constant value.

Krait’s thin packer adds a layer of structural polymorphism on top of the existing byte-level randomization. It changes what the binary looks like as a PE file, not just what values live inside it.

What Is a Thin Packer?

Traditional packers (UPX, Themida, VMProtect) transform an entire binary: they compress or encrypt the original code, wrap it in an unpacking stub, and produce an output that bears little structural resemblance to the input. They’re effective at defeating static analysis, but they’re also immediately recognizable. Every security analyst knows what a UPX-packed binary looks like. EDR products flag known packer signatures as suspicious by default, because legitimate software rarely ships packed.

A thin packer is different. It doesn’t compress the binary. It doesn’t wrap it in a virtual machine. It doesn’t fundamentally restructure the PE in a way that screams “packed.” Instead, it makes a small number of targeted structural changes that disrupt fingerprinting without creating the telltale artifacts that heavy packers leave behind.

The binary still looks like a normal Windows executable. It has standard PE headers, conventional section layouts, a valid import table, and resources if the build includes them. But the specific structural details — which sections are named what, how large the padding regions are, which code runs first — change per build.

Code Section Encryption

The primary structural change is encryption of the code section at build time. The packer encrypts the main code section using AES-256-CBC with a per-build random key and IV. A small decryption stub lives in a separate section. At runtime, the stub decrypts the code section in-place before jumping to the real entry point.

From a static analysis perspective, this means the code section of the PE on disk contains ciphertext, not executable code. Disassemblers that try to analyze the binary statically see encrypted bytes instead of x86 instructions. String extraction finds nothing in the code section. Entropy analysis shows the code section at near-maximum entropy (close to 8.0 bits per byte), which is characteristic of encrypted or compressed data — but importantly, only in the code section. The rest of the binary (imports, resources, the decryption stub) has normal entropy. This is unlike traditional packers where the entire binary is high-entropy, which is a strong packer signal.

The decryption stub itself is minimal. It resolves a single API function from the PEB’s loader data structures, changes the code section’s memory permissions, decrypts, restores execute permissions, and jumps to the original entry point. The stub contains no suspicious API calls, no shellcode patterns, and no network activity. It does exactly what a packed section of a legitimate application might do — application-level decryption of an embedded payload is a normal software pattern used in DRM, licensing, and asset management.

Stub Variation

The decryption stub selects from multiple functionally equivalent implementations at build time. Each variant performs the same operations — resolve VirtualProtect, decrypt, jump to entry — but uses different register allocation, different stack layouts, and different junk instructions.

This prevents fingerprinting the stub itself. If every Krait binary used the same byte sequence for the decryption stub, that sequence would become the new signature. By rotating the stub variant per build, the decryption section has a different instruction-level layout each time. An analyst can recognize the pattern (small section, resolves one API, decrypts another section), but can’t write a byte-level signature that matches all variants.

Section Name Randomization

PE section names are eight-byte ASCII strings visible in the file header. Conventionally, they follow predictable patterns: .text, .rdata, .data, .rsrc. Security tools and analysts use section names as a quick triage signal — unusual names like .crt, .upx0, or .vmp immediately flag the binary for closer inspection.

More subtly, consistent section names across builds create a fingerprint. If every Krait binary has sections named .text, .pack, .packd, and .pad, that specific combination of names becomes identifiable even though no individual name is unusual.

The thin packer randomizes section names at build time. The code section, data sections, and packer sections all receive random alphanumeric names. Only sections that the PE loader requires by convention (.reloc for base relocations, .rsrc for resources) keep their original names — renaming these would break the binary.

The randomization is purely cosmetic — section names don’t affect execution. But it eliminates a trivial fingerprinting vector that automated analysis tools commonly use for clustering. Two Krait binaries from the same source tree, built seconds apart, have completely different section name patterns.

Size Variation

Binary size is a surprisingly useful fingerprint. If every build of your tool produces a file that’s exactly 287,744 bytes, that file size becomes a weak but zero-cost filter. Threat intelligence platforms can flag all files matching the size, and clustering algorithms use size as a feature for grouping related samples.

The thin packer includes a padding section filled with random data at build time. The padding size varies randomly within a configured range, which means every build produces a binary with a slightly different total file size. Combined with the per-build encryption keys (which produce different ciphertext lengths due to AES block alignment and padding), no two builds share the same file hash or file size.

The random padding also disrupts section-level entropy analysis. Automated tools that profile the entropy of each section and use the entropy distribution as a fingerprint see different patterns: the padding section has high entropy (it’s random data), the code section has high entropy (it’s AES ciphertext), and the ratio between them changes per build.

What This Doesn’t Change

Structural polymorphism is not a substitute for behavioral evasion. Once the binary is running, the thin packer has done its job — the code section is decrypted and executing normally. The agent’s runtime behavior (API calls, network connections, sleep patterns, memory allocation) is exactly the same as an unpacked build. The packer only affects static analysis of the PE file on disk or in transit.

This is by design. The thin packer targets the analysis phase that happens before execution: automated sandbox pre-filtering, threat intelligence clustering, analyst triage based on file properties. If a binary doesn’t survive static triage — if it gets flagged before anyone runs it — no amount of runtime evasion helps.

In the layered evasion model, structural polymorphism sits at the outer ring. It defeats static fingerprinting and makes sample clustering harder. Inside that ring, byte-level polymorphism defeats signature matching on constants and keys. Inside that, runtime evasion techniques (sleep encryption, tampered syscalls, stack spoofing) defeat behavioral and memory analysis. Each layer addresses a different phase of the detection pipeline, and no single layer is sufficient on its own.

For Defenders

The honest defensive implication: if you’re relying on file hash, file size, section names, or static entropy profiles to detect a tool, structural polymorphism defeats you. These are useful features for clustering known malware families, but they’re brittle against any adversary that invests in build-time randomization.

The robust approach is behavioral detection. The thin packer doesn’t change what the binary does at runtime — it changes what the binary looks like on disk. A decryption stub that calls VirtualProtect to change code section permissions and then jumps to decrypted code is a detectable pattern regardless of what the stub’s bytes look like. EDR products that monitor the VirtualProtect → execute transition see the same behavior from every packed binary, whether the packer is UPX, Themida, or a custom thin packer.

Static analysis has its place for commodity malware and retroactive threat intelligence. But for detection in real-time against a motivated adversary, behavioral monitoring at the API and memory layer is what survives polymorphism.

The thin packer ships as the --pack flag in Krait builds. Combined with the existing polymorphic engine, it adds structural variation on top of byte-level randomization — defense in depth for the binary itself.