Skip to content
pwnsy
malwareintermediate#polymorphic-malware#malware#obfuscation#behavioural-detection#antivirus

What Is Polymorphic Malware? Why Signatures Fail

Polymorphic malware rewrites itself on every copy so no two samples share a signature. Polymorphic vs metamorphic, why hashes fail, and behavioural defence.

Antivirus, in its original form, worked like a lineup. Take a known bad file, record a fingerprint of its bytes, and match every new file against the list. It was fast and effective, right up until malware authors decided to change their own faces. Polymorphic malware is that response: code engineered so that every copy looks different on disk while doing exactly the same thing when it runs.

That single design choice breaks the fingerprint model. If no two samples share the same bytes, no single signature can catch them all, and the defender is left chasing an infinite supply of unique-looking files that are really one piece of malware wearing different masks.

How signatures work, and what breaks them

A traditional antivirus signature is a pattern: a hash of a whole file, or a sequence of bytes known to appear in a specific threat. Scanning is then a matching problem. Does this file contain that pattern? If yes, block it.

The model has one hard assumption baked in: that the malicious file stays roughly constant across infections. Polymorphism removes that assumption. If the attacker can make each copy structurally different, every hash is a miss and every byte pattern matches at most one sample. The signature database, which worked by generalising from one sample to many, no longer generalises to anything.

The polymorphic recipe

Polymorphic malware achieves its changing appearance with a simple, durable trick: separate the payload from the thing that unlocks it.

  • The payload, the part that does the actual damage, is encrypted. Encrypted data looks like random bytes, and random bytes carry no stable signature.
  • A small decryptor stub sits in front of it. When the file runs, the stub decrypts the payload in memory and hands control to it.
  • On each new infection, a mutation engine rewrites the stub and picks a fresh encryption key. Different key, different encrypted payload, differently arranged decryptor. New bytes on disk, every time.

The engine has a toolbox for making the stub look different without changing what it does: inserting junk instructions that have no effect, swapping registers, reordering independent operations, substituting one instruction sequence for an equivalent one. The decrypted payload underneath is always the same. That constancy is both the technique's strength and its weakness, and defenders exploit the weakness.

On MITRE ATT&CK, this is Obfuscated Files or Information (T1027), with the encrypt-and-unpack pattern captured under Software Packing (T1027.002).

Polymorphic versus metamorphic

The two terms get used loosely, so here is the clean distinction.

PropertyPolymorphicMetamorphic
What changesThe decryptor and encryption, not the payloadThe entire body, including the engine
Constant coreYes, the decrypted payload is identicalNo constant decrypted form
Main techniqueEncryption plus a mutating stubFull code rewriting on each generation
Detection weak pointThe decrypted payload in memoryVery few; behaviour is the main handle
Relative complexityModerateHigh

Polymorphic malware always decrypts to the same underlying code. That gives defenders a target: let the sample run in a controlled environment, wait for it to unpack itself, and inspect what appears in memory.

Metamorphic malware removes even that. It rewrites its whole body, engine included, so successive generations share almost no code and there is no constant encrypted core to wait for. It is much harder to write and much harder to catch, which is why it is rarer.

Different file, same behaviour

The insight that makes defence possible is this: obfuscation changes what a sample looks like, never what it does. A polymorphic banking trojan still hooks the browser, still contacts its command server, still steals the same data. The appearance is a variable. The behaviour is the constant, and behaviour is what modern detection watches.

Why this pushes defence toward behaviour

If the file is a moving target, you stop aiming at the file. Detection shifts to the things the malware cannot change without ceasing to be itself:

  • Heuristics flag structural tells: an encrypted blob paired with a self-modifying stub is itself a suspicious shape, even if the exact bytes are new.
  • Emulation and sandboxing run the sample in an isolated environment and watch it unpack. Once the polymorphic wrapper decrypts the payload, the constant core is exposed and can be identified.
  • Behavioural monitoring ignores appearance entirely and watches actions at runtime: process injection, credential access, suspicious network beacons. These stay the same across every mutated copy.

This is why serious antivirus stopped being purely signature-based years ago. The engines still use signatures as a cheap first pass, but the weight has moved to heuristics, emulation, and behaviour precisely because polymorphism made pure matching a losing game.

How to defend against polymorphic malware

  1. Rely on behaviour-based endpoint protection. Choose tooling that scores what a process does at runtime rather than what its file hash is. That is the layer polymorphism cannot rewrite around.
  2. Keep sandboxing and emulation in the loop. Detonating suspicious files in isolation forces the wrapper to unpack and reveals the constant payload underneath.
  3. Do not lean on hash blocklists alone. Hash-based blocking is useful against known, static threats and near-useless against a mutating one. Treat it as one thin layer.
  4. Restrict execution paths. Application control and blocking execution from user-writable locations cut off where these payloads typically land, regardless of how they are packed.
  5. Patch and reduce exposure. Polymorphism changes how malware looks, never how it gets in. Closing the delivery routes, phishing and vulnerable software, denies it the entry it needs.
  6. Feed behavioural telemetry to detection. Process, script, and network logs let you spot the invariant actions even when every file is unique.
Detonate, then identify

Against a packed or polymorphic sample, static inspection of the file on disk tells you little. Run it in an isolated sandbox and capture what it unpacks into memory. The decrypted payload is the stable identity the obfuscation was hiding, and it is where reliable detection and analysis begin.

Obfuscation like this is one entry in a broader kit that attackers use to slip payloads past scanners. To see how packing, encryption, and other evasion tricks fit together, and which formats carry them, our File-Format Abuse Atlas catalogues the delivery formats and the obfuscation they tend to wrap.

Polymorphic malware is a durable idea, not a specific threat. As long as detection rewards constancy, attackers will invest in change. The answer is to detect the one thing they cannot change: what the code does once it runs.

A worked example of a polymorphic lifecycle

Following one sample from creation to detection makes the mechanism concrete, and shows exactly where each defence bites.

An author writes a piece of malware with a fixed job: steal browser-stored credentials and send them to a command server. That logic is the payload, and it never changes, because changing it would change what the malware is for. To evade signature scanning, the author wraps the payload in a polymorphic engine before distribution. The engine encrypts the payload with a randomly chosen key and prepends a small decryptor stub that knows how to reverse it in memory.

The first victim receives a build where the payload is encrypted under one key and the stub is arranged one way. A signature written against that exact file would be a perfect hash of random-looking encrypted bytes plus a specific stub. The second victim receives a build generated moments later: a new key, so the encrypted payload is a completely different sequence of bytes, and a mutated stub with junk instructions inserted, registers swapped, and equivalent instruction sequences substituted. The two files share almost no bytes. A hash of the first matches nothing in the second, and a byte-pattern signature keyed to the first stub misses the second.

Now trace the detection. A pure hash blocklist fails immediately, because every build is unique. A heuristic engine does better, because the shape itself, a block of high-entropy encrypted data paired with a small self-modifying decryptor, is suspicious regardless of the exact bytes, and it can flag the sample as probably packed. The decisive step comes from emulation. The scanner runs the sample in an isolated environment and lets the stub execute. The stub does the one thing it must do: it decrypts the payload into memory so the payload can run. At that instant the constant core is exposed, and the scanner reads the same credential-stealing code that appears in every build. A signature written against the decrypted payload catches all of them at once.

That is the whole story of polymorphism in miniature. The wrapper is infinitely variable, the payload is constant, and detection wins by waiting for the wrapper to reveal the payload rather than trying to match the wrapper.

Detection signals

Because polymorphic samples are unique on disk, the useful signals are structural and behavioural rather than hash-based.

  • High-entropy regions in an executable. Encrypted payloads look like random data, which registers as unusually high entropy compared with normal code and resources. A small stub in front of a large high-entropy blob is a classic packed-or-encrypted shape.
  • A self-modifying or self-decrypting stub. Code that writes to a region of memory and then executes what it just wrote is the decryptor doing its job. This runtime behaviour is a strong tell that survives every mutation of the stub.
  • A mismatch between static and runtime appearance. A file that looks small and inert on disk but unpacks into substantially more code in memory is behaving like a packed sample.
  • Constant behaviour across many unique files. When a swarm of files that share no hashes all make the same sequence of system calls, contact the same infrastructure, or perform the same injection, the shared behaviour is the invariant identity the obfuscation is hiding.
  • Suspicious runtime actions regardless of the file. Process injection, credential access, tampering with security tooling, and beaconing to a command server stay the same across every mutated copy, which is why behavioural monitoring catches what signatures miss.
Entropy is the shape, behaviour is the identity

Two signals do most of the work against polymorphism. High entropy paired with a self-decrypting stub reveals that a file is probably packed, which is the shape. The sequence of actions the sample performs after it unpacks reveals which malware it actually is, which is the identity. Signatures fail because they key on neither of these, and behavioural detection succeeds because it keys on both.

Polymorphism is one member of a family of code-transformation techniques, and they get used together. Separating them clarifies what each defeats and where it stops.

TechniqueWhat changes across samplesConstant coreWhat it defeats
PackingPayload compressed or encrypted, unpacked at runtimeYes, the unpacked payloadStatic inspection of the file on disk
PolymorphismEncryption key and decryptor stubYes, the decrypted payloadHash and byte-pattern signatures
MetamorphismThe entire body, engine includedNo constant decrypted formSignatures and payload-in-memory matching
Obfuscation (general)Names, control flow, dead codeVariesStatic reading and analysis

Packing is the broad parent technique, where a payload is compressed or encrypted and unpacked at runtime, and it maps to MITRE ATT&CK Software Packing (T1027.002). Polymorphism adds the mutating engine on top, so each packed build looks different. Metamorphism removes the constant decrypted core entirely by rewriting the whole body, which is why it is the hardest to catch and the rarest to see, since it is difficult to build correctly. All of these sit under Obfuscated Files or Information (T1027) in ATT&CK.

Common misconceptions

"Polymorphic malware is a specific virus." It is a technique, not a single threat. Many different malware families use polymorphic engines, and the same underlying payload can be wrapped in polymorphism, delivered many ways. The label describes how a sample evades detection, not what it is or what it does.

"If every copy is unique, it is undetectable." Uniqueness defeats hash and byte-pattern signatures and nothing else. The behaviour is constant across every copy, and behavioural detection, emulation, and heuristics all catch what pure matching misses. Polymorphism raises the cost of detection, it does not remove the possibility.

"Polymorphic and metamorphic mean the same thing." They are distinct. Polymorphic malware keeps a constant decrypted payload and mutates only the encryption and decryptor. Metamorphic malware rewrites its entire body including the engine, so there is no constant decrypted core to key on. Metamorphism is the harder and rarer of the two.

"Antivirus is useless against it." Modern engines stopped relying on hashes alone years ago precisely because of polymorphism. They lead with heuristics, emulation, and behavioural monitoring, and keep signatures as a cheap first pass. Signature-only tools struggle, and layered engines do not.

"Changing the file changes the danger." The mutation is cosmetic. A polymorphic banking trojan performs the exact same theft as every other copy, because the payload is constant. The appearance is a variable and the behaviour is fixed, which is the whole reason behavioural defence works.

How the technique evolved

Polymorphism emerged as a direct answer to signature-based antivirus. Early antivirus recorded a fingerprint of each known malicious file and matched new files against the list, which was fast and effective while malware stayed constant across infections. Malware authors responded first with simple encryption, wrapping a payload so its bytes no longer matched a signature. Defenders countered by keying signatures on the small, constant decryptor stub that the encryption required, since the stub itself did not change.

Polymorphism was the next move: make the stub change too. A mutation engine rewrote the decryptor on every build, inserting junk instructions, swapping registers, and substituting equivalent instruction sequences, and picked a fresh encryption key each time so the encrypted payload also differed. Now neither the payload bytes nor the stub bytes were stable, and simple signatures had nothing constant to key on. Defenders answered again, this time with emulation: run the sample in a controlled environment and wait for it to decrypt itself, then match the exposed payload.

Metamorphism pushed further still, rewriting the entire body including the engine so that even the decrypted form was not constant, which removed the target emulation relied on. It is powerful and correspondingly hard to write, which keeps it rare. The through-line across this whole history is a simple economy. Every time detection rewarded some constant feature, attackers invested in varying it, and defenders moved the point of detection one layer deeper, from file bytes to decrypted payload to runtime behaviour. Behaviour is where the contest has largely settled, because it is the one thing the malware cannot vary without ceasing to do its job.

The limits of polymorphism for an attacker

Polymorphism is powerful, and it carries costs and constraints that shape how attackers use it and where defenders get leverage.

The first constraint is complexity. A mutation engine that produces correct, working builds every time is difficult to write. Each generated stub has to decrypt the payload accurately and hand control to it, and a subtle bug in the engine produces broken samples that crash instead of running. This is part of why full metamorphism, which mutates the engine itself, stays rare: the difficulty of getting it right outweighs the marginal evasion benefit for most authors.

The second constraint is that the engine leaves its own fingerprints. A mutation engine has habits, such as the way it inserts junk instructions or the structure of the decryptor it emits, and those habits can be consistent enough across builds to become a detection target in their own right. Defenders sometimes catch a polymorphic family by recognising the engine rather than the payload, which is the technique being turned against itself.

The third constraint is the one the whole guide rests on. Polymorphism can vary everything about a sample's appearance and nothing about its purpose. The payload must decrypt to the same working code, and that code must perform the same actions to achieve the attacker's goal. Every layer of variation the attacker adds is effort spent on appearance, and none of it touches the behaviour that behavioural detection watches. The attacker can make detection more expensive, and cannot make the malware stop acting like itself.

For defenders, the practical takeaway is to stop treating a flood of unique files as a flood of distinct threats. A polymorphic campaign is usually one piece of malware wearing many masks. Detonating a sample to expose its payload, and correlating the shared behaviour across the unique files, collapses the swarm back into the single threat it actually is, which is where analysis and response should aim.

Frequently asked questions

What is the difference between polymorphic and metamorphic malware? Polymorphic malware encrypts a constant payload and mutates the encryption key and decryptor on each copy, so the file changes while the decrypted payload stays the same. Metamorphic malware rewrites its entire body, including the engine, so there is no constant decrypted core at all. Metamorphism is harder to build and rarer to see.

Why do signatures fail against polymorphic malware? A signature is a fingerprint of specific bytes, and it works by generalising from one sample to many that share those bytes. Polymorphism ensures no two copies share the same bytes, so each signature matches at most one sample and the database stops generalising. The technique attacks the core assumption signatures depend on.

Can antivirus detect polymorphic malware at all? Yes. Modern engines use heuristics to flag the packed shape, emulation to run the sample until it decrypts its constant payload, and behavioural monitoring to watch the actions the malware performs at runtime. These catch what hash matching misses, which is why serious antivirus stopped being purely signature-based.

Is polymorphic malware the same as a packer? They are related. Packing compresses or encrypts a payload and unpacks it at runtime, and polymorphism adds a mutating engine so each packed build looks different. All polymorphic malware is packed in a sense, and not all packed malware is polymorphic, since a plain packer can produce identical output each time.

How does sandboxing help against it? A sandbox runs the sample in isolation and lets the decryptor stub execute, which forces the polymorphic wrapper to reveal the constant payload in memory. Once the payload is exposed, it can be identified reliably, and the malware's runtime behaviour can be observed directly, both of which defeat the obfuscation.

Does polymorphism change how the malware infects a system? No. Polymorphism changes how the malware looks to a scanner, not how it gets in. Delivery still relies on the usual routes, such as phishing and vulnerable software, and the payload's behaviour after execution is unchanged. Closing the delivery routes denies polymorphic malware the same entry it denies any other malware.

Why is behavioural detection the recommended defence? Because behaviour is the one thing polymorphism cannot alter. A sample can change every byte on disk and still must perform the same actions to achieve its purpose, such as injecting into a process, accessing credentials, or beaconing to a server. Detection that scores those actions holds across every mutated copy.

Sources & further reading

Sharetwitterlinkedin

Related guides