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.

Lesson 13 of 18 · 10 min read · practice only with authorization

Diagram

Same behavior, different files

Follow the path. One example at a time.

Step 1 of 4

Variant A

One build of a sample.

Illustration: Variant A
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.

  1. 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.
  2. 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.
  3. 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.

1 / 3

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.

  1. MapMalware fundamentals: families, delivery, persistence, and the responseWhat malware categories describe, how infections usually start, where persistence hides on Windows, Linux, and macOS, and why rebuilding usually beats cleaning.

Practice

  1. LabTerminal labRead the files on a scoped host and name the failure in a finding.