Symhash, CDHash and Team ID: Grouping Mac Samples
The Mach-O counterparts of imphash: how symhash, the cdhash and the Team ID are computed, what each one survives, and where block lists use them.
TL;DR. A Mach-O sample has more identities than its file hash:
- the cdhash: the hash of its code signature's CodeDirectory, one per slice;
- the Team ID of the developer account that signed it;
- its signing identifier;
- the symhash of its imported symbols;
- its UUID.
Each one survives different changes, which makes each one useful for a different job. File hashes identify a container. The cdhash identifies signed code and survives repackaging. The Team ID identifies a developer. Symhash and TLSH group variants. Mach-O Parser computes all of them for every slice, and exports them as indicators.
File hashes: the container
MD5, SHA-1 and SHA-256 cover the file byte for byte. They are what you share and look up first. They are also the most fragile identity of a Mac binary:
- A universal binary has one file hash, while each slice inside it would hash differently on its own.
lipo -thin arm64extracts a slice into a new file with a new hash, even though not one instruction changed.- Re-signing changes the hash, and so does stapling or editing anything in the file.
Threat reports that list only a universal binary's SHA-256 miss the same code distributed as a thin file, and the other way round.
cdhash: the signed code
The cdhash is the hash of a slice's CodeDirectory, the structure that lists a hash of every code page (see what you can verify offline). Changing one byte of code changes a page hash, which changes the CodeDirectory and therefore the cdhash. Any change to the entitlements, the identifier or the signing flags changes it too, and re-signing usually does.
What makes the cdhash valuable is what it ignores. Extracting a slice from a universal binary keeps the slice's bytes, signature included, so the cdhash stays the same. Zipping, copying or renaming the file changes nothing. The updater sample shows this: its arm64 slice has cdhash 0536c2c1… inside the universal file, and still 0536c2c1… after lipo -thin arm64, while the SHA-256 changes.
macOS itself keys on cdhashes:
- Notarization tickets are issued per cdhash, and Apple revokes them per cdhash.
- The trust caches of platform binaries are lists of cdhashes.
- Endpoint Security reports the cdhash of every process.
- Santa supports cdhash rules.
codesign -dvvv prints it as CDHash=, truncated to 20 bytes for SHA-256. Mach-O Parser shows the same value, and the full 32 bytes.
Team ID and signing identifier: the developer
A Team ID is the ten-character identifier of an Apple developer account, for example EQHXZ8M8AV for Google. It appears twice:
- in the CodeDirectory (since version
0x20200); - as the organisational unit of the Developer ID, App Store or development certificate.
Every program a developer account signs carries it, so it is the natural pivot from one sample to everything else that account shipped. When Apple revokes a certificate, the Team ID stays the same, which is why block lists prefer it to a certificate hash.
The signing identifier (com.google.Chrome) is chosen at signing time. It means something only next to a Team ID: Santa's signing-ID rules take the form EQHXZ8M8AV:com.google.Chrome. Next to an ad-hoc signature it is just text. The updater sample is ad-hoc signed and calls itself com.apple.softwareupdate.agent, and nothing on the system disputes the claim.
Ad-hoc and linker-signed files have no Team ID at all. For them the cdhash is the only signing identity.
Symhash: the imports
Symhash takes the names of a slice's undefined external symbols (its imports), sorts them, joins them with commas and takes the MD5. A rebuild with a small code change keeps the same imports and so the same symhash, even though every file hash, UUID and cdhash changes.
The samples show both sides:
- A useful match. The universal, ad-hoc-signed updater and the older, unsigned, Intel-only updater-old share the symhash
6277d8b3…. They import the same_dlopen,_dlsym,_ptraceand_puts, so the two builds group together. - A meaningless match. SyncTool and Installer share
d1ae1e50…because each imports only_putsanddyld_stub_binder. Thousands of trivial programs share that symhash.
The rules of thumb:
- Few imports, weak hash. Below a dozen or so imports, a matching symhash says little.
- The toolchain shapes the imports. A Go program imports the C functions the Go runtime needs, mostly the same for every Go program built with the same Go version. Its symhash says more about the compiler than about the author.
- The deployment target matters. Programs linked for macOS 12 or later use chained fixups and no longer import
dyld_stub_binder, so the same source built for two deployment targets can produce two symhashes. - Slices can differ. Compute and compare per slice.
The idea is the same as Windows' imphash, without the import order and the library names.
UUID and TLSH
The LC_UUID of a slice is derived from the linker's output, so two links of identical input give the same UUID. A different UUID means a different build. It ties a binary to its .dSYM and to its crash reports, and it is a cheap way to spot one build distributed under several file names.
TLSH is a similarity hash of the whole file: a small distance between two TLSH values means similar content. It catches variants whose imports changed (so symhash broke) but whose code and strings are mostly the same.
Which identity survives what
| Identity | Computed over | Survives | Changes on |
|---|---|---|---|
| SHA-256 | The whole file | Copying, renaming | Thinning, merging slices, re-signing, any byte |
| cdhash | One slice's CodeDirectory | Thinning, merging slices, zipping | Any code change, new entitlements or identifier, usually re-signing |
| Team ID | The signing certificate | Rebuilds, new versions, certificate renewal | A different developer account |
| Signing identifier | Signer's choice | Rebuilds | Whatever the signer wants |
| symhash | Sorted import names | Small code changes, re-signing, thinning | Imports added or removed, another toolchain |
| UUID | The linker's output | Re-signing, thinning | Any rebuild with different input |
| TLSH | The whole file | Small changes anywhere | Packing, large rewrites |
Putting them to work
- Blocking a known file: the cdhash of each slice, plus the SHA-256 for sharing.
- Blocking a developer: the Team ID. Check first that it isn't a legitimate company whose certificate was stolen: revoking trust in a real vendor breaks its real software.
- Hunting variants: symhash where there are enough imports, otherwise TLSH; then confirm by comparing two files side by side.
- Reporting: give the file SHA-256, then every slice's cdhash, and the Team ID if there is one. The next responder may only have the thin copy.
Mach-O Parser's Compare view puts two files side by side: signature, Team ID, identifier, architectures, imports, libraries and entitlements, with what is only in one of them. The IOC export carries Team IDs, cdhashes and symhashes along with the file hashes (see from a Mach-O file to IOCs).
Frequently asked questions
Is symhash the Mach-O version of imphash?
It plays the same role: a hash of the imported names that stays stable across rebuilds of the same tool. The recipes differ. Imphash hashes library.function pairs in import order. Symhash sorts the imported symbol names, leaves the library names out and takes the MD5 of the comma-joined list, so the order of imports does not matter.
Why does a universal binary have several cdhashes?
Each slice carries its own code signature, and a signature may hold more than one CodeDirectory (for example SHA-1 and SHA-256). Every CodeDirectory has its own hash, so an x86_64 + arm64 file has at least two cdhashes, one per slice.
Which identifier should go into a block list?
For one exact program, the cdhash of each slice, or the file's SHA-256. For everything one developer account has signed, the Team ID. For one product of that developer, the Team ID plus the signing identifier. Symhash and TLSH are for hunting related samples, not for blocking.