One packer to rule them all: Empirical identification, comparison and circumvention of current Antivirus detection techniques
Arne Swinnen (Security Consultant), Alaeddine Mesbahi (Security Consultant)
BruCON 0x06 · Day 1
Overview
In an ever-evolving cybersecurity landscape, the cat-and-mouse game between malware developers and antivirus (AV) vendors continues unabated. This talk, delivered by security consultants Arne Swinnen and Alaeddine Mesbahi at BruCON, delves into the sophisticated world of malware packing and its efficacy in circumventing modern antivirus detection mechanisms. The presenters introduce a custom-developed packer designed not only to obfuscate malware but also to empirically test and understand the underlying detection techniques employed by leading AV products.

Key moments
- 0:00 Introduction: Packers and AV detection techniques
- 4:00 Understanding PE file format and section constraints
- 11:30 Reflective DLL: The extensible, architecture-agnostic stub
- 24:00 Resource Packer: Complete static detection bypass
- 30:00 Code Emulation: The next AV defense layer
- 41:00 Anti-Emulation Checks: Categories and examples
- 47:00 Demo: Bypassing Microsoft Security Essentials' emulator
- 56:00 Summary: Evolution of detection and future trends
One packer to rule them all: Empirical identification, comparison and circumvention of current Antivirus detection techniques
Speakers: Arne Swinnen (Security Consultant); Alaeddine Mesbahi (Security Consultant)
Conference: BruCON
YouTube: https://www.youtube.com/watch?v=nPmbpBYmLpM
Overview
In an ever-evolving cybersecurity landscape, the cat-and-mouse game between malware developers and antivirus (AV) vendors continues unabated. This talk, delivered by security consultants Arne Swinnen and Alaeddine Mesbahi at BruCON, delves into the sophisticated world of malware packing and its efficacy in circumventing modern antivirus detection mechanisms. The presenters introduce a custom-developed packer designed not only to obfuscate malware but also to empirically test and understand the underlying detection techniques employed by leading AV products.
The core of their research focuses on identifying and analyzing three primary AV detection strategies: static analysis, code emulation, and dynamic/heuristic analysis. Through a series of increasingly stealthy packing techniques, Swinnen and Mesbahi demonstrate how attackers can bypass these layers, offering critical insights into the limitations of current AV solutions and providing a roadmap for both offensive and defensive security practitioners. Their work underscores the necessity for multi-layered defenses and continuous innovation in the face of persistent threats.
This article provides a detailed technical deep dive into the methodologies presented, the challenges overcome, and the significant implications for endpoint security. It highlights the intricate details of PE file manipulation, the nuances of anti-emulation, and the strategies for evading behavioral analysis, ultimately equipping readers with a comprehensive understanding of the current state of AV evasion.
Background
▶ Watch: Introduction: Packers and AV detection techniques (0:00)
The concept of packing involves transforming an executable file into another executable with identical or enhanced functionality but a significantly altered file system footprint. This transformation typically involves two main components: static changes to the executable's data and the injection of a stub — a small piece of code executed first at runtime to reverse these static modifications. Packers broadly fall into two categories: compressors, which aim to reduce file size (e.g., UPX), and obfuscators or protectors, designed to hinder reverse engineering. For malware, obfuscators are particularly useful as they can encrypt or modify signatures, thereby bypassing static antivirus detection which relies on identifying known patterns within a file.
To understand how a packer operates, a foundational knowledge of the Portable Executable (PE) file format is essential. A Windows executable consists of a header followed by a data blob. The header contains crucial fields, notably the Address of Entry Point (AEP), which dictates where execution begins, allowing a packer to hijack the control flow to its stub. The header also includes a section table, logically dividing the data blob into sections like .text (code), .rdata (imports), .data (static data), .rsrc (resources like icons), and .reloc (relocation information for ASLR).
Crucially, the PE format imposes several constraints on packers. Sections like the Imports table, Resource section, and Relocation table cannot be fully encrypted because the Windows operating system loader needs to read them in clear text to properly load and execute the program. Furthermore, the code section often contains absolute references to the Imports and Data sections. Modifying the size or position of these sections without careful handling can break these references, causing the executable to crash. These constraints highlight the complexity of developing a robust and stealthy packer that can successfully evade detection while maintaining the original program's functionality.
Key Findings
▶ Watch: Reflective DLL: The extensible, architecture-agnostic stub (11:30)
The research yielded several critical findings regarding the effectiveness of various packing techniques against different antivirus detection layers:
- Layered AV Detection: Antivirus products employ a multi-layered approach, typically starting with static analysis, then moving to code emulation, and finally dynamic/heuristic analysis. Each layer attempts to identify malicious characteristics at different stages of the file's lifecycle.
- Static Detection Bypass: The custom-developed Resource Packer technique achieved a 100% bypass rate against static detection for all tested antivirus products (McAfee, Microsoft Security Essentials, Kaspersky, AVG, Avast). This technique effectively conceals the original malware by encrypting it and embedding it as a legitimate-looking resource within a template executable, making it indistinguishable from a benign file at rest.
- Code Emulation Vulnerabilities: While powerful, code emulation implementations are complex and prone to discrepancies. The talk demonstrated that anti-emulation checks — such as exploiting time anomalies, specific file system interactions, network behaviors, obscure API functions, and dynamic binary instrumentation detection — can reliably bypass even robust emulators like Microsoft Security Essentials.
- Dynamic/Heuristic Analysis Challenges: Dynamic analysis, which monitors runtime behavior, represents the final line of defense. The speakers explored methods like API translation and API junk injection using inline hooking to modify the sequence or type of API calls, thereby evading behavioral signatures. While effective, these techniques introduce trade-offs in terms of generality and performance impact.
- Evolving AV Landscape: The research highlighted the continuous evolution of AV detection. Some AVs that initially failed to detect packed malware later updated their engines to identify the packing technique itself (e.g., Kiho detecting the inline packer). This indicates a responsive, albeit reactive, arms race.
- 64-bit vs. 32-bit: Consistently, 64-bit packed executables proved harder to detect than their 32-bit counterparts, especially against code emulation. This suggests that some AVs may have less mature or less robust emulation capabilities for 64-bit architectures.
Overall, the key finding is that while antivirus products offer layered defenses, dedicated and sophisticated packing and anti-detection techniques can still effectively circumvent initial analysis stages, allowing malware to execute and potentially trigger only later-stage, more generic behavioral alerts.
Technical Deep Dive
▶ Watch: Code Emulation: The next AV defense layer (30:00)
The technical core of the research revolved around two main challenges for building an effective packer: creating an extensible stub and ensuring stealthy injection.
Extensible Stub Development
The stub is the crucial piece of code that reverses the packing changes at runtime. It needs to be:
- Architecture-specific: Capable of running on 32-bit, 64-bit, or ARM systems.
- Position-independent code (PIC): Able to execute from any memory location without requiring fixed addresses.
- Self-dependency resolution: Unable to rely on the operating system for fetching Windows API addresses, it must resolve them itself.
Instead of writing complex assembly code like UPX, the researchers leveraged Stephen Fewer's Reflective DLL project. This open-source project provides a DLL structure with two key functions: DllMain (where the custom stub code is implemented in C/C++) and ReflectiveDllLoader.
The process works as follows:
- The custom stub logic (e.g., decryption algorithms) is written in C/C++ within the
DllMainfunction. - This DLL project is compiled for the target architecture (32-bit or 64-bit).
- The packer injects this entire compiled DLL into the target executable.
- The original Address of Entry Point (AEP) of the executable is hijacked to point to the
ReflectiveDllLoaderfunction within the injected DLL. - When the packed executable starts, the
ReflectiveDllLoaderfirst relocates the entire stub DLL to the heap. - It then parses the stub's own import table, fetches the necessary Windows API addresses, and hot-patches them.
- Finally, execution is handed over to the custom stub code in
DllMain, now running with full Windows API support. - The stub then decrypts and restores the original executable's memory layout and transfers execution to the original AEP. This approach provides a powerful, high-level C/C++ environment for stub development, significantly simplifying the process compared to raw assembly.
Stealthy Injection Techniques
The second, more difficult challenge was injecting the stub in a manner that evades detection by AVs looking for file modifications. Traditional packers like UPX create easily identifiable sections (e.g., UPX0, UPX1), which are trivial for AVs to flag. The researchers developed three progressively stealthier techniques:
- Inline Technique:
- The input executable's code and data sections are encrypted.
- The custom stub is appended as a new section at the end of the file.
- The AEP is hijacked to point to this new stub section.
- Detection Vector: AVs can easily detect a new, non-standard section and an AEP pointing outside the
.textsection. - Results: While 64-bit samples showed some evasion (2 AVs detected), 32-bit samples had higher detection rates. Notably, Kiho detected the packing technique itself, flagging all 110 packed samples regardless of the original malware. This indicated AVs were specifically looking for this type of structural change.
- New PE Technique:
- This technique uses both the malware and a legitimate template executable (e.g., Notepad++).
- A completely new PE header is constructed, combining elements from both the malware and template.
- The new
.text(code) section is created to contain all encrypted sections of the original malware, plus the stub. This dramatically increases its size. - Legitimate sections from the template executable are appended to make the final file appear normal.
- The stub's responsibilities increased: it had to decrypt multiple sections, and also parse and hot-patch the relocation and import tables (similar to the reflective loader's internal workings).
- Detection Vector: While the section table looks more legitimate, the dramatically increased size and high entropy of the
.textsection (due to encrypted data) are suspicious. Debuggers like OllyDbg would complain that the code section "is either compressed, encrypted or contains large amount of embedded data." - Results: This technique achieved 100% static bypass for 64-bit samples. For 32-bit, three AVs still detected minor parts, possibly due to the high entropy of the code section or discrepancies in the combined PE header (e.g., timestamp vs. architecture).
- Resource Packer Technique:
- This is the most advanced and stealthy static bypass technique.
- It uses a legitimate template executable (e.g.,
mstsc.exeornotepad++.exe). - The custom stub is hot-patched directly into existing, unused parts of the template's
.textsection, without increasing its size. - The complete malware (including its header) is encrypted and appended as a resource to the template file. Resource sections commonly contain large data blobs (icons, version info), so a large encrypted blob doesn't immediately appear suspicious.
- The AEP of the template is changed to point to the hot-patched stub within its own
.textsection, maintaining a legitimate entry point characteristic. - The stub's work now includes relocating itself, decrypting the malware from the resource section, writing it to an expected memory location, and then parsing and hot-patching its imports.
- Detection Vector: From a file structure perspective, the only visible change is a slight increase in the size of the resource section. The
.textsection's size and AEP remain legitimate. - Results: This technique achieved a complete bypass of all static detection for all tested antivirus products, both 32-bit and 64-bit.
Code Emulation and Anti-Emulation
After static analysis, many AVs employ code emulation. They run the potentially malicious file within a simulated Windows environment to observe its behavior, trigger unpacking, and then analyze the unpacked malware in memory.
Challenges for AV Emulators:
- Unpacking Detection: Identifying the exact moment unpacking finishes (e.g., when memory becomes both writable and executable, a strong indicator of unpacked code, or calls to "dangerous" API functions).
- Performance: Emulating a full OS is slow; AVs need to be fast.
- Anti-Emulation Bypass: Malware actively tries to detect and evade emulated environments.
- Complexity: Emulating x86/x64 architectures and Windows environments is immensely complex.
The researchers highlighted techniques AVs use:
- Writable/Executable Memory Heuristic: AVs track memory pages. If a page becomes both writable and executable, it's a strong indicator of unpacking.
- Omni Unpack: Combines the writable/executable heuristic with detection of calls to "dangerous" API functions, assuming these only come from unpacked malware.
- Caspersky Emulator: Noted for its sophisticated approach, separating system call emulation from standard instruction emulation. It uses caching of native code (executing known unpacking routines directly on hardware) and hardware acceleration (using real CPU for standard instructions) to boost performance and bypass anti-emulation checks.
Anti-Emulation Checks: These checks exploit discrepancies between a real and an emulated environment. The researchers categorized them:
- Time Anomalies:
- Simple
BigSleep(): Malware stalls execution to exceed AV timeout. GetTickCount+Sleep(): Measure ifSleep()actually pauses for the expected duration.- Multi-threaded Counter/Watcher: A counter thread increments a shared variable across multiple
Sleep()calls. A watcher thread performs aBigSleep()and then checks if the counter reached the expected value. In an emulator that shortensSleep(), the counter will be lower than expected, revealing emulation.
- Interaction with File System:
- Read/write to file system, EFS streams.
LoadLibrary()with system DLLs (e.g.,kernel32.dll) or fake DLLs. If system DLLs don't load or fake DLLs load unexpectedly, it indicates an incomplete or manipulated environment.
- Network Interaction:
- Attempting a
LocalHostconnection to a known port like SMB (445). If the connection fails, it suggests an incomplete network stack in the emulator.
- Obscure API Functions:
- Exploiting Windows API functions with specific, complex behaviors that are difficult for emulators to fully implement. If the function's behavior differs from a real system, emulation is detected. This is a robust check, as emulators cannot reimplement the entire Windows OS.
- Binary Instrumentation:
- Checks for tools that modify binary execution (e.g., debuggers, sandboxes). Example:
GetProcessImageFileName()to see if the process name isexplorer.exeorcmd.exeas expected, or something else indicating instrumentation.
Dynamic/Heuristic Analysis and Anti-Heuristic Methods
The final layer is dynamic or heuristic analysis, which monitors the program's behavior in a live or sandboxed environment. A common technique used by AVs for this is SSDT hooking (System Service Descriptor Table hooking) in the kernel, allowing them to log API calls from userland processes in an unbypassable manner. They look for suspicious sequences of API calls (e.g., CreateRemoteThread followed by WriteProcessMemory, indicating process injection).
To counter this, the researchers implemented two anti-heuristic methods using inline hooking:
- API Translation:
- Hooks "dangerous" API functions (e.g., registry manipulation functions).
- Instead of calling the original function, it translates the call into an alternative, less suspicious method. For instance, instead of directly calling
RegSetValueEx, it might executereg.exevia asystem()call. - Pros: The AV sees a call to a signed Microsoft executable (
reg.exe) from a different process, which has a lower risk profile. Low performance impact. - Cons: Less generic; requires specific translations for each suspicious signature.
- API Junk Injection:
- Hooks heuristic-dangerous functions.
- When a hooked function is called, the stub injects a series of non-functional, legitimate-looking API calls before or after the original call.
- Pros: Modifies the expected pattern of API calls, making it harder for heuristic engines to match known signatures. More generic.
- Cons: Significant performance impact due to numerous injected calls.
These methods demonstrate that even at the behavioral level, attackers can manipulate the perceived execution flow to evade detection, albeit with performance or generality trade-offs.
Demo / Proof of Concept
▶ Watch: Anti-Emulation Checks: Categories and examples (41:00)
The talk included several compelling demonstrations showcasing the effectiveness of the developed packing techniques and anti-detection methods.
- Packer Functionality and Static Bypass:
- The researchers used a console application packer to process
meterpreter_btcp.exe(a known Metasploit payload). - They packed it with all three techniques: Inline, New PE, and Resource Packer. For the latter two,
notepad++.exewas used as the legitimate template file. - Upon execution, all packed samples successfully opened port 4444, confirming the original malware's functionality was preserved.
- File sizes varied: Inline and New PE samples had distinct sizes, while the Resource Packer sample was only slightly larger than the
notepad++.exetemplate, as the malware was added as an encrypted resource. - A scan with McAfee antivirus (on-demand) revealed that none of the three packed files were detected statically. This proved McAfee was completely bypassed at the static analysis layer by all techniques.
- Code Emulation Detection by Microsoft Security Essentials (MSE):
- The same packed files were transferred to a system running Microsoft Security Essentials.
- Immediately upon being dropped into a shared folder, MSE detected some of the files without even being opened or an on-demand scan being initiated. This indicated that MSE was employing a more advanced form of static analysis or, more likely, code emulation on file access.
- Ultimately, all three packed samples (including the Resource Packer one) were detected by MSE, demonstrating that even with complete static bypass, code emulation could still identify the underlying malware. This was particularly significant for the Resource Packer, where "not a single byte of the original malware is in the final executable" in cleartext.
- Anti-Emulation Bypass Demo (Time4 Check):
- To counter MSE's emulation, a
meterpreter_btcp.exewas packed using the Resource Packer technique, with an added anti-emulation check called "Time4." - The "Time4" check specifically used repeated
LoadLibrarycalls tokernel32.dll(500 times) to simulate a prolonged sleep or execution delay. This is designed to trigger emulation timeouts. - When this anti-emulation-enabled sample was run in the MSE environment, MSE failed to detect it. The
ApiMonitortool showed the repeatedLoadLibrarycalls, confirming the anti-emulation check was active and successfully delaying the unpacking process beyond MSE's emulation timeout. This effectively bypassed MSE's robust emulator.
- Dynamic/Heuristic Analysis Detection:
- Even after bypassing static and emulation layers, dynamic analysis remains a challenge.
- A demo showed a Metasploit session successfully established on a machine running AVG antivirus (which had been bypassed initially).
- However, when attempting to migrate the Metasploit shell to
explorer.exe(a common technique for persistence and privilege escalation), AVG immediately flagged the activity as "something suspicious," without explicitly naming it "Metasploit" or a specific malware. This confirmed that behavioral heuristics were still active and capable of detecting post-execution malicious actions.
These demonstrations provided concrete evidence of the layered nature of AV detection and the distinct challenges and opportunities presented by each layer for both attackers and defenders.
Defensive Implications
▶ Watch: Summary: Evolution of detection and future trends (56:00)
The research presented by Arne Swinnen and Alaeddine Mesbahi offers crucial insights for cybersecurity defenders striving to protect their systems against advanced threats. The primary defensive implications are:
- Layered Defense is Imperative, But Not Invincible: Antivirus solutions rely on a multi-pronged approach (static, emulation, dynamic), and this is validated as necessary. However, the talk conclusively demonstrates that each layer has vulnerabilities that can be exploited by sophisticated packing and anti-detection techniques. Defenders must not solely rely on any single detection method.
- Static Detection is Increasingly Weak: The Resource Packer technique achieved 100% static bypass against multiple commercial AVs. This suggests that relying heavily on file signatures or entropy checks for initial detection is becoming less effective against modern packers. Defenders should shift focus towards post-execution analysis as the first line of defense is increasingly permeable.
- Code Emulation Requires Robustness and Vigilance: While powerful, code emulation is complex and susceptible to anti-emulation checks. AV vendors must continually refine their emulators to prevent detection of discrepancies (time, file system, network, obscure APIs). Defenders should be aware that initial file scans, even with emulation, might be bypassed, meaning malicious files could still execute.
- Behavioral Analysis as the Last Stand: Dynamic/heuristic analysis is often the last line of defense, detecting malicious activity after execution has begun. While the talk explored methods to bypass this (API translation, API junk injection), these often come with performance costs or are less generic. Defenders should invest in advanced Endpoint Detection and Response (EDR) solutions that excel at real-time behavioral monitoring, anomaly detection, and correlation of suspicious API calls, even if they've been manipulated.
- Focus on Post-Execution Indicators: Since initial file-based detection can be circumvented, defenders must prioritize detecting malicious activities that occur after a file has launched. This includes monitoring for:
- Unusual process creation or parent-child relationships.
- Suspicious network connections (e.g., to C2 servers).
- Unauthorized modifications to the registry, file system, or critical system processes.
- Abnormal use of legitimate system tools (Living Off The Land binaries).
- Network-Based Detection Remains Critical: Even if a packed executable bypasses endpoint AV, its attempts to communicate with C2 servers or exfiltrate data can be caught by network intrusion detection/prevention systems (NIDS/NIPS), firewalls, and network traffic analysis.
- User Education and Least Privilege: The ultimate bypass for any technical control is often the human element. Strong security awareness training to prevent users from executing unknown files, combined with a least privilege model, can significantly reduce the impact of successful bypasses.
- The Arms Race Continues: The research underscores that AV detection is a dynamic field. Defenders should anticipate that new packing and anti-detection techniques will emerge. Regular security updates, threat intelligence, and a proactive stance on threat hunting are essential to keep pace with evolving attack methodologies.
In essence, while AV products provide essential protection, the research highlights the need for a deeper, more comprehensive security strategy that extends beyond initial file scanning to robust behavioral monitoring, network defense, and continuous adaptation.
Key Takeaways
- Sophisticated Packers Bypass Static AV: Modern packing techniques, particularly the "Resource Packer," can completely circumvent static antivirus detection by embedding encrypted malware within legitimate file structures, making it indistinguishable from benign files at rest.
- Code Emulation is Powerful but Exploitable: Antivirus code emulators, while effective at triggering unpacking and analyzing in-memory malware, are complex and vulnerable to anti-emulation checks that exploit discrepancies in time, file system, network, or obscure API function behavior between real and emulated environments.
- Anti-Emulation Checks are Effective: Techniques that introduce time anomalies (e.g., multi-threaded sleep checks) or leverage specific environment differences can reliably bypass even robust emulators like Microsoft Security Essentials, allowing packed malware to execute undetected.
- Dynamic Analysis is the Last Defensive Layer: Heuristic and dynamic analysis, which monitor runtime behavior through kernel-level hooking, are the final defense. However, even these can be targeted by API manipulation techniques like "API Translation" or "API Junk Injection," albeit with trade-offs in generality and performance.
- 64-bit Malware Poses Greater Detection Challenges: Across multiple tests, 64-bit packed executables consistently showed lower detection rates by AVs, suggesting a potential gap in the maturity or robustness of 64-bit emulation and analysis capabilities.
- Layered Defenses are Essential, but Continuous Evolution is Key: While AVs employ multi-layered detection, attackers continuously innovate to bypass each layer. This necessitates that defenders adopt comprehensive EDR solutions, prioritize behavioral monitoring, and stay informed on evolving threat landscapes to maintain effective protection.
About the Speaker(s)
Arne Swinnen and Alaeddine Mesbahi are both Security Consultants. Their work primarily involves conducting penetration tests, which provides them with practical, real-world experience in identifying and exploiting vulnerabilities, as well as understanding the limitations of existing security controls like antivirus software. Their research into packer identification, comparison, and circumvention stems directly from this hands-on offensive security background.
Reviews
- Dr. Zero (Offensive Security Researcher) — MUST SEE ★★★★★