Obfuscation resilient binary code reuse through trace-oriented programming

Junyuan Zeng, Yangchun Fu, Kenneth A. Miller, Zhiqiang Lin, Xiangyu Zhang, Dongyan XuCCS 2013

TL;DR

This paper introduces Trace-Oriented Programming (TOP), a novel framework for reconstructing reusable software components from binary code by leveraging dynamic execution traces. TOP offers enhanced resilience against code obfuscation and avoids complex static analysis techniques, making it particularly useful for malware analysis and security function transplanting.

What Problem Does This Paper Address?

The ability to reuse binary code is highly desirable for various security applications, including malware analysis, software patching, and legacy system modernization. However, existing methods for extracting and reusing binary code often rely on static analysis, which struggles with obfuscated binaries. Obfuscation techniques, designed to hinder reverse engineering, can render static analysis tools ineffective. Furthermore, static analysis often requires complex and error-prone techniques like "points-to" and "alias" analysis to understand memory access patterns. This leaves a gap for a method that can reliably extract and reuse binary code, even from heavily protected or obfuscated programs, without the need for intricate static analysis.

Methods

The core of TOP is Trace-Oriented Programming (TOP), a framework that reconstructs software components by analyzing dynamic execution traces. Instead of statically dissecting the binary, TOP instruments the binary to record its execution path and then translates these traces into C code with templates and inlined assembly. This approach offers several advantages:

  • Dynamic Analysis: By observing actual execution, TOP bypasses many obfuscation techniques that rely on static code structure.
  • Resilience to Obfuscation: Since it follows the executed path, TOP can handle techniques like instruction aliasing, garbage code, and even encrypted code, as long as the program eventually executes.
  • Simplified Analysis: It avoids the need for complex static "points-to" and "alias" analysis by observing pointer dereferences directly during execution.
  • Safety Instrumentation: TOP incorporates mechanisms to ensure that the reconstructed code behaves consistently with the observed traces, adding safety checks to handle incomplete execution paths.
  • Instruction-to-C Translation: Executed instructions are translated into C code, using inlined assembly for performance and symbolic addresses for memory locations and function calls.

The framework comprises several key components: Control Structure Identification, Memory Address Symbolization, Safety Instrumentation, Instruction-to-C Translation, and Offline Combination (for merging multiple traces).

Datasets

The paper evaluates TOP using two main sets of benchmarks:

  • Legacy Linux Binaries: The coreutils-6.11 package, comprising 100 programs, was used to evaluate TOP's effectiveness on normal, un-obfuscated binaries.
  • Obfuscated Windows Binaries: 15 representative obfuscated samples from a known collection, along with two additional packed malware samples, were used to test TOP's resilience against various obfuscation techniques. The paper also mentions using tasklist.exe packed with 10 different publicly available packers as a testing "goat" program.

Key Insights and Ideas

  • Dynamic Traces as a Robust Abstraction: The paper demonstrates that dynamic execution traces, rather than static code structure, provide a more robust foundation for binary code reconstruction, especially in the face of sophisticated obfuscation.
  • "Reuse Safety" is Achievable: TOP's safety instrumentation ensures that reconstructed code either mimics the original behavior or safely flags deviations, addressing a critical concern for reliable binary reuse.
  • Symbolization Without Static Analysis: The ability to symbolize memory addresses and function pointers by observing their use during dynamic execution significantly simplifies the reconstruction process compared to static methods.
  • Practical Applications Demonstrated: The paper effectively showcases TOP's utility in real-world security scenarios like malware unpacking and identification, and security function transplanting, moving beyond theoretical concepts.

Key Results

  • Effectiveness on Legacy Binaries: All 100 coreutils programs were successfully reconstructed, recompiled, and executed with consistent semantics compared to their original counterparts.
  • Obfuscation Resilience: TOP successfully reconstructed source code from 15 obfuscated Windows binaries, with many achieving 100% code coverage and consistent semantics. It also handled multi-layer packing.
  • Performance: The online tracing phase of TOP incurs a performance overhead that is generally acceptable (typically under 1 second per program). The generated code exhibits negligible performance overhead due to the use of inlined assembly.
  • Code Size: The recovered source code size was generally comparable to or smaller than the original binary size, with specific examples showing recovered code sizes in the range of 1-15 KLOC.
  • Malware Unpacking: TOP successfully unpacked 12 samples packed with various packers, demonstrating its capability to reveal the original malicious code.

Limitations and Future Work

  • Incomplete Coverage: The primary limitation is that TOP's reconstruction is based on traced behavior, meaning behaviors not exercised during the trace are not captured. The authors suggest integrating advanced testing techniques like symbolic execution to improve coverage.
  • Platform and Environment Dependence: TOP currently requires the same kernel and library support for compilation and execution as the original binary, and relies on the presence of similar external resources.
  • Readability and Optimization: The generated C code is functional but not necessarily optimized for readability or performance. Future work aims to improve readability by introducing richer C structures and optimizing the code, for example, by removing unnecessary safety guards.
  • Advanced Obfuscation: While resilient to many techniques, TOP might struggle with highly advanced obfuscations like virtualization-based techniques or hypervisor-level malware. Future work will explore addressing these challenges.
  • Non-Deterministic Execution: The current offline trace merging simply combines control flow paths, which might not be sufficient for non-deterministic programs. Investigating more sophisticated merging strategies is planned.

Summary updated

BibTeX
@inproceedings{zeng2013obfuscation,
  author = {Junyuan Zeng and Yangchun Fu and Kenneth A. Miller and Zhiqiang Lin and Xiangyu Zhang and Dongyan Xu},
  title = {{Obfuscation resilient binary code reuse through trace-oriented programming}},
  booktitle = {CCS},
  year = {2013},
  doi = {10.1145/2508859.2516664},
}
Figure