Skip to main content
Be Bitwise

Trojanized Binaries

Supply Chain & Binary Attacks · Advanced Exploitation track

8 min read

In this module

The Trusted Executable That Betrays You

Every day you download and run software you didn't write. You trust that what you got is the genuine article — unmodified, no surprises. A trojanized binary is what happens when that trust is abused.

A trojanized binary is a legitimate program that's been modified to carry hidden malicious functionality. It still works normally — the text editor edits text, the compiler compiles code. Behind the scenes, though, it's also exfiltrating data, installing backdoors, or phoning home to an attacker.

It's one of the oldest attack techniques in computing, and it's still brutally effective because it exploits trust in the distribution process rather than any technical vulnerability.

How Binaries Get Trojanized

There are several points in the software lifecycle where a binary can be compromised:

Source code modification: The attacker gains access to the source code repository and inserts malicious code. If the change is subtle enough, it may pass code review and be compiled into the official release. The 2020 SolarWinds attack used this approach - malicious code was inserted into the Orion build system, and the resulting backdoored updates were distributed to thousands of organisations.

Build system compromise: The attacker compromises the build infrastructure (CI/CD pipelines, build servers) without modifying the source code. The build system injects malicious code during compilation or linking. The source code audit looks clean, but the resulting binary is trojanized.

Binary patching: The attacker modifies the compiled binary directly. This can be done by patching the executable file, by intercepting the download and replacing it with a modified version (a man-in-the-middle attack on the distribution channel), or by compromising the distribution server.

Installer wrapping: The attacker wraps a legitimate installer inside a new installer that first runs the attacker's payload, then runs the original installer. The user sees the expected installation process and does not suspect anything.

Trojanized Binary

A trojanized binary is a legitimate executable that has been secretly modified to include malicious functionality. It maintains its original behaviour to avoid suspicion while performing additional harmful actions. The modification can happen at the source code, build system, or binary level.

Binary Patching Techniques

To understand how a compiled binary can be modified, you need to understand executable file formats. On Linux, executables use the ELF (Executable and Linkable Format). On Windows, they use PE (Portable Executable). Both formats have headers that describe the sections of the binary, entry points, and metadata.

A simple approach to binary patching is to modify the entry point:

  1. Find unused space in the binary (padding between sections, or a new section)
  2. Write malicious shellcode into that space
  3. Modify the entry point in the ELF/PE header to point to the shellcode
  4. The shellcode does its work, then jumps to the original entry point
text
Original: Trojanized:
┌──────────┐ ┌──────────┐
│ ELF │ │ ELF │
│ Header │ │ Header │ ← entry point changed
│ entry: │ │ entry: │
│ 0x1000 │ │ 0x5000 │
├──────────┤ ├──────────┤
│ .text │ │ .text │
│ (code) │ │ (code) │
│ 0x1000 │ │ 0x1000 │ ← original entry point
├──────────┤ ├──────────┤
│ .data │ │ .data │
├──────────┤ ├──────────┤
│ padding │ │ malicious│ ← shellcode here
│ │ │ code │
└──────────┘ │ 0x5000 │
│ jmp 0x1000│ ← then jump to original
└──────────┘

There's a catch in step 1. Section padding usually sits in a segment that isn't mapped executable, so the patcher also has to flip that segment's permission flags (an ELF PT_LOAD gaining PF_X, or a PE section gaining IMAGE_SCN_MEM_EXECUTE), add a new executable section, or find a cave inside the existing code segment. That change is itself one of the best signals a defender can look for: an entry point outside .text, a writable-and-executable segment, or a section that wasn't there in the vendor's build.

More sophisticated patching hooks specific functions rather than the entry point. For example, replacing the implementation of a network function to also send a copy of the data to an attacker-controlled server. This is harder to detect because the program's startup behaviour is unchanged.

Code Signing and Its Limitations

Code signing is the primary defence against binary tampering. The developer signs the compiled binary with their private key. The operating system or the user can verify the signature before running the binary. If the binary has been modified in any way, the signature verification fails.

On macOS, all software distributed through the App Store must be signed, and Gatekeeper blocks unsigned or improperly signed applications by default. On Windows, signed drivers are required for 64-bit systems, and SmartScreen warns about unsigned downloads.

However, code signing has significant limitations:

  • Stolen signing keys: If the attacker steals the developer's private signing key, they can sign trojanized binaries that pass verification. This has happened to multiple software companies.
  • Compromised CAs: Certificate authorities that issue code signing certificates have been compromised, allowing attackers to obtain valid certificates.
  • Signing before review: If the build system is compromised and automatically signs the output, the trojanized binary gets a valid signature.
  • Users ignoring warnings: When users encounter "untrusted developer" warnings, many click through them rather than investigating.

The SolarWinds Attack: A Case Study

The SolarWinds supply chain attack, discovered in December 2020, is the most prominent example of binary trojanisation at scale. The attackers compromised the build system for SolarWinds' Orion network monitoring software. During the build process, a malicious component called SUNBURST was injected into the Orion update DLL.

The trojanized update was digitally signed with SolarWinds' legitimate code signing certificate and distributed through SolarWinds' official update mechanism. Approximately 18,000 organisations installed the malicious update, including US government agencies and major technology companies.

SUNBURST was sophisticated: it lay dormant for two weeks after installation, checked for the presence of security tools and sandboxes, and communicated with command-and-control servers using DNS queries that disguised themselves as normal Orion telemetry traffic. The backdoor blended into the application's normal behaviour so thoroughly that it evaded detection for months.

The attack showed exactly why build pipeline compromises are so prized over individual target compromises. A single successful intrusion reaches thousands of organisations simultaneously — delivered through their own trusted update mechanism.

The xz-utils backdoor (CVE-2024-3094) came at the same goal from the other end of the supply chain. Instead of breaking into a vendor's build servers, the attacker spent about two years becoming a trusted co-maintainer of an open-source compression library, helped along by sock-puppet accounts pressuring the overworked original maintainer. The malicious code never appeared in the git history. It lived in obfuscated "test files" and a modified build script that shipped only in the 5.6.0 and 5.6.1 release tarballs.

It was caught in Debian unstable, Fedora's pre-release builds and a few rolling distributions, before it reached the stable releases most servers run. Notice what reading the source repository would have shown you: nothing. The trojan existed only in the distributed artefact and the build step that consumed it.

The 3CX compromise of 2023 showed the chain can run twice. According to Mandiant's investigation, a 3CX employee installed a trojanised build of X_TRADER, a discontinued trading application whose installer was still signed with its vendor's certificate. That foothold led to 3CX's own build environment, and 3CX then shipped signed, trojanised versions of its desktop softphone to its customers. Mandiant described it as the first time it had seen one software supply chain attack lead to another.

Detecting Trojanized Binaries

Detection is difficult because the trojanized binary is functionally identical to the legitimate one for most observable behaviours. Approaches include:

  • Binary diffing: Comparing a suspected binary against a known-good copy byte-by-byte. Any difference warrants investigation.
  • Behavioural analysis: Running the binary in a sandbox and monitoring for unexpected network connections, file access, or process creation.
  • Reproducible builds: If the software supports reproducible builds, anyone can compile the source and verify that the result matches the distributed binary.
  • Hash verification: Comparing the binary's cryptographic hash against a hash published through an independent, trusted channel.
  • Static analysis: Disassembling the binary and analysing its code for suspicious patterns (encrypted strings, obfuscated logic, references to unexpected network addresses).

No single technique is reliable on its own. Sophisticated trojanized binaries are designed to evade each check individually. Layering multiple detection methods is the only approach that gives you a fighting chance.