Skip to content

What Is an Imphash? Calculation, Lookup and Pitfalls

What an imphash is, how pefile calculates it step by step, how to compute it and pivot on it in VirusTotal, MalwareBazaar and YARA, and when it misleads.

Published on 7 min read

TL;DR. An imphash is the MD5 of a PE file's import table: every imported function written as lower-case dll.function, in the order the file lists them, joined with commas. Rebuilding a program rarely changes what it imports, so variants of one tool often share an imphash while their SHA-256 values all differ. That makes it a cheap pivot for finding related samples. It is also easy to collide (packers, .NET, shared runtimes) and easy to forge, so treat a match as a lead, not as attribution.

Imphash in one paragraph

Mandiant introduced the import hash in 2014 (Tracking Malware with Import Hashing). The idea: a Windows executable declares which DLL functions it needs in its import directory, and the linker writes that list in a stable order tied to the source code. Hash the list and you get a fingerprint of what the program calls, not of its bytes. Changing a C2 address, a string or a key does not change it; adding one API call or switching the compiler usually does. Most tools, VirusTotal and MalwareBazaar included, compute it the way pefile's get_imphash() does, so the values are comparable across platforms.

How the imphash is calculated

pefile's get_imphash() walks the import directory in file order and applies four rules:

  1. DLL name: lower-cased, with a .dll, .ocx or .sys extension removed (KERNEL32.dll becomes kernel32; msvcrt.dll becomes msvcrt; any other extension is kept).
  2. Function name: lower-cased (GetProcAddress becomes getprocaddress).
  3. Imports by ordinal have no name in the file. pefile names them from built-in tables for ws2_32.dll, wsock32.dll and oleaut32.dll (ordinal 115 of ws2_32 becomes wsastartup) and writes ordN for every other DLL (ord12).
  4. Join every dll.function pair with commas, with no spaces, and take the MD5 of the resulting string.

Delay-load imports are not included; only the regular import directory counts.

Worked example

A small program imports six functions, two of them from WS2_32.dll by ordinal:

Import directory entryImported asBecomes
KERNEL32.dllGetProcAddresskernel32.getprocaddress
KERNEL32.dllLoadLibraryAkernel32.loadlibrarya
KERNEL32.dllVirtualAllockernel32.virtualalloc
WS2_32.dllordinal 115ws2_32.wsastartup
WS2_32.dllordinal 23ws2_32.socket
ADVAPI32.dllRegOpenKeyExAadvapi32.regopenkeyexa

The string that gets hashed:

kernel32.getprocaddress,kernel32.loadlibrarya,kernel32.virtualalloc,ws2_32.wsastartup,ws2_32.socket,advapi32.regopenkeyexa
$ printf '%s' 'kernel32.getprocaddress,kernel32.loadlibrarya,kernel32.virtualalloc,ws2_32.wsastartup,ws2_32.socket,advapi32.regopenkeyexa' | md5sum
b068af14f8db659807843214dad62b38  -

Order matters: the same six imports with the first two swapped hash to 716f742d1ef76aeeeebde8fd5e8a540d. That is why two programs importing the same APIs from different source code usually get different imphashes, and why a match is meaningful at all.

Compute it

pefile (Python). Install with pip install pefile, then:

import pefile

pe = pefile.PE("sample.exe", fast_load=True)
pe.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_IMPORT"]])
print(pe.get_imphash())

fast_load=True plus parsing only the import directory keeps it fast on large batches. pefile.PE("sample.exe").get_imphash() gives the same value with a full parse. A file without an import directory returns an empty string, not an error.

YARA. The pe module exposes pe.imphash() (YARA must be built with its hash/crypto support), so you can hunt for a known value:

import "pe"

rule imphash_b068af14
{
    condition:
        pe.imphash() == "b068af14f8db659807843214dad62b38"
}

In the browser. The PE Parser computes the imphash for every file you drop, with pefile's rules (ordinals of ws2_32, wsock32 and oleaut32 named, others as ordN, delay-load imports excluded), without uploading anything. The batch table shows it in its own column, and files that share one get the same family number: in the built-in sample, the two m64.exe builds have different SHA-256 values and the same imphash, and are labelled family 1. UPX-packed files are unpacked first and rebuilt with their original imports, so the imphash shown for the unpacked child matches the original build, not the packer stub. The inventory CSV export includes an Imphash column for every file.

Pivoting on an imphash

Once you have a value, look for siblings:

  • VirusTotal: the imphash: search modifier, for example imphash:b068af14f8db659807843214dad62b38, lists files with the same value. It is part of VirusTotal Intelligence (the premium search), and the imphash is also shown on each file's Details tab.
  • MalwareBazaar: search imphash:<md5> in the web interface, or use the API query get_imphash. Results come with family tags and first-seen dates, which helps decide whether a cluster is one tool or noise.
  • Your own collection: group your sample store or EDR file inventory by imphash, then sort each group by compile time. A cluster with steady compile times and small TLSH distances is a strong candidate for one tool and its rebuilds.
  • Hunting rules: a pe.imphash() condition catches new builds that keep the same imports even when strings and bytes change. Combine it with another condition (a string, a section name, a size range) so it does not fire on every file built from the same template.

Before trusting a pivot, check how common the value is. An imphash shared by thousands of files across many family tags is describing a packer, a runtime or a framework, not your actor.

When imphash lies

The imphash describes the import table and nothing else. It misleads in predictable ways:

  • .NET assemblies. A classic .NET executable imports a single function, mscoree.dll!_CorExeMain (DLLs: _CorDllMain). Every such file hashes to the same value: f34d5f2d4577ed6d9ceec516c1f5a744 for EXEs and dae02f32a21e03ce65412f6e56942daa for DLLs. Some newer .NET assemblies have no import table at all, so the imphash is empty. For .NET, pivot on assembly metadata (module version ID, type and method names) instead.
  • Packers and protectors. The import table of a packed file is the stub's: a handful of loader functions such as LoadLibraryA, GetProcAddress and VirtualAlloc. Unrelated samples packed with the same tool often collide, and two builds of one tool packed differently do not match. Unpack first (see detecting packed executables), then hash the result.
  • Dynamic API resolution. Malware that resolves its APIs at runtime (by name or by hash) keeps a tiny, generic import table. The imphash then says almost nothing about the code.
  • Shared runtimes and templates. Programs built with the same runtime or framework start from the same import list. Go binaries are a known case: their import table comes from the Go runtime, so unrelated Go programs built with the same toolchain version often share an imphash. Small C programs that only call a few common kernel32 functions collide for the same reason.
  • Ordinal-only imports. Imports by ordinal from DLLs outside pefile's tables (MFC is the common one) become ordN. The hash still works, but you cannot read the capabilities back from the import list.
  • Forgery. The import table is under the author's control. Adding unused imports, reordering them or copying another family's table changes or fakes the value at no cost.
  • Implementation differences. A tool that keeps extensions, sorts imports or includes delay-load imports produces different values for the same file. Stick to pefile-compatible values when comparing across sources.

Imphash vs Rich header hash vs TLSH vs ssdeep

FingerprintWhat it hashesGood atBreaks on
ImphashImport table, in orderGrouping rebuilds of one toolPackers, .NET, shared runtimes, forged imports
Rich header hashMicrosoft toolchain components (comp.ids)Same project and build environmentNon-Microsoft toolchains (no Rich header), copied headers
TLSHByte distributionMeasuring how close two files arePacking and compression, large shared resources
ssdeepContext-triggered piecewise hashesNear-identical files and documentsPacking, reordered content

They fail in different ways, so use them together: group by imphash and Rich header hash, then check TLSH distances and timestamps inside each group. The imphash, Rich header and TLSH article covers the other three in depth, including why the PE Parser offers TLSH and not ssdeep.

FAQ

What is an imphash?

An imphash (import hash) is the MD5 of a Windows executable's import table, written as lower-case dll.function pairs in file order and joined with commas. Two builds of the same program often share it even when their SHA-256 values differ.

Who created the imphash?

Mandiant introduced it in 2014 in the post Tracking Malware with Import Hashing. The pefile Python library's get_imphash() is the reference implementation that other tools follow.

Does the same imphash mean the same malware family?

No. It means the same import list in the same order. Packed files, .NET assemblies and programs built with the same runtime can share an imphash without being related. Confirm with other evidence such as the Rich header, TLSH distance, strings and timestamps.

Why is the imphash empty for my file?

The file has no import directory. pefile returns an empty string in that case. Some modern .NET assemblies and some packed or hand-crafted files have no import table at all.

Related articles

Step-by-step static triage of Windows executables with the free PE Parser: load files or a ZIP, read indicators, compare builds and export results.
Where a Windows executable stores its times, which ones can be trusted, how reproducible builds and timestomping show up, and how to use them.
How Authenticode signs a PE file, which checks can be done from the file alone, and why a valid signature is not the same as a trusted one.