Polymorphic and metamorphic malware: why hash-based detection is not enough
Polymorphic malware changes its encrypted wrapper each time; metamorphic code rewrites itself. Why file hashes and simple signatures fail, and how behavioral detection, YARA rules on stable features, and memory scanning keep up.
Diagram
Same behavior, different files
Step 1 of 4
Variant A
One build of a sample.
sha256 8a1f... size 412,288 section .text entropy 7.9
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Hash churn
- What fails
- Every sample has a new hash.
- Who is affected
- Defenders relying on hash blocklists.
- What you would notice
- IOC feeds full of single-use hashes.
- What you change
- Use hashes for known files only and add behavior detections.
Packers
- What fails
- Packing and encryption hide code on disk.
- Who is affected
- Static scanners.
- What you would notice
- High entropy and few imports.
- What you change
- Scan memory after unpacking, and flag packed binaries from unusual sources.
Behavior
- What fails
- What code does is harder to change than how it looks.
- Who is affected
- Attackers trying to evade.
- What you would notice
- Process trees and network behavior.
- What you change
- Write behavior-based rules.
A structure-based YARA example
This rule flags small-import, high-entropy PE files. It is a hunting rule, not a block rule, because legitimate packed software exists.
import "pe"
import "math"
rule Hunt_Packed_Small_Imports {
condition:
pe.is_pe and pe.number_of_imports < 5 and
for any s in pe.sections : ( math.entropy(s.raw_data_offset, s.raw_data_size) > 7.5 )
}Check yourself
Recognition and the fix. Nothing here is a procedure.
Why do hash blocklists fail against polymorphic malware?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.