ModX: Binary Level Partially Imported Third-Party Library Detection via Program Modularization and Semantic Matching

Can Yang, Zhengzi Xu, Hongxu Chen, Yang Liu, Xiaorui Gong, Baoxu Liu

TL;DR

This paper introduces ModX, a novel framework for detecting third-party libraries (TPLs) in binary code, even when only parts of a library are used. ModX achieves this by first decomposing programs and libraries into semantically coherent modules and then matching these modules using a combination of syntactic and semantic features, outperforming existing methods in accuracy and robustness.

What Problem Does This Paper Address?

In modern software development, the reuse of third-party libraries (TPLs) is ubiquitous, offering significant benefits in terms of development speed and quality. However, this widespread adoption introduces challenges: managing a vast number of libraries, understanding their components, and identifying potential security risks like license violations, malware infections, or vulnerabilities. Existing TPL detection methods often struggle with two main issues: they typically rely on syntactic features (like strings) that can be easily obfuscated, and they treat entire libraries as monolithic units. This makes them ineffective when a program only imports a subset of a library's functionality, a common scenario due to compiler optimizations and modular design. The paper aims to address these limitations by enabling accurate TPL detection at a more granular, semantic level, even for partially imported libraries.

Methods

ModX employs a two-phase approach:

  1. Binary Modularization: This phase decomposes a binary program or library into fine-grained, functionality-based modules. It uses a novel algorithm inspired by community detection in networks. Key aspects include:
  2. Module Quality Metric: A metric is designed to assess the coherence of function clusters, incorporating both connectivity (based on call graphs) and function volume (number of statements). This metric is adjusted to favor modules with strong internal connections and a balance of core functionality and utility functions.
  3. Heuristic Biases: To guide the modularization process and make it more intuitive, ModX introduces two biases:
  4. Locality Bias: Encourages grouping functions that are physically close in the binary, assuming they are more likely to share functionality.
  5. Entry Limit Bias: Promotes modules with fewer entry points, aiming for better encapsulation and single responsibility.
  6. Algorithm: The Fast Unfolding Louvain algorithm is adapted to efficiently group functions into modules while maximizing the module quality score.
  7. TPL Detection: Once programs and libraries are modularized, ModX performs TPL detection by matching modules.
  8. Module Similarity Measurement: This involves extracting and comparing various features:
  9. Syntactic Features: Includes string literals and constant numbers, with TF-IDF used to weigh constants by their uniqueness.
  10. Graph Similarity Features: Leverages graph kernels and edge embedding techniques to compare the call graph structures of modules.
  11. Function Similarity Features: Uses a pre-trained binary function matching tool (Gemini) to assess function similarity within modules. A "drill-down" approach using anchor points (data access patterns, dispatch tables) is employed to efficiently select function pairs for comparison.
  12. Matching and Ranking: Modules are matched against a database of TPL modules. Module Importance (MI) and Library Importance (LI) scores are calculated to refine the matching confidence (MC), helping to prioritize more significant modules and libraries and reduce false positives.

Datasets

The paper evaluates ModX on two main types of datasets:

  • Nix-based Binaries: 106 binaries collected using the nix package manager, representing a broad range of applications with their ground truth dependencies.
  • Manually Crafted Ubuntu Binaries: 7 commonly used programs built with static and dynamic linking of TPLs to ensure a more precise ground truth.
  • TPL Database: A database of 795 frequently used libraries from Ubuntu 20.04, pruned for uniqueness and static linking compatibility.
  • Malware Variants: A collection of 15 variants of the Mirai botnet family, used to test partial code reuse detection in a security context.
  • CVE Datasets: Vulnerability data (CVEs) for 5 real-world projects (BinUtils, LibXML2, OpenSSL, FreeType, Tcpdump) to evaluate attack surface detection.

Key Insights and Ideas

  • Modularization as a Foundation: The core insight is that decomposing programs into semantically coherent modules is a more robust foundation for TPL detection than treating entire libraries or individual functions in isolation.
  • Semantic Matching for Obfuscation Resilience: By focusing on semantic features derived from module structure and function behavior, ModX becomes more resilient to syntactic obfuscation techniques commonly used to hide library usage.
  • Partial Import Handling: The modular approach naturally handles partially imported libraries, as it can identify and match individual functional modules rather than requiring a full library match.
  • Module Quality Metrics Matter: The development of specialized module quality metrics, incorporating both graph structure and function volume, is crucial for generating meaningful modules that accurately reflect program functionality.
  • Beyond TPL Detection: The paper highlights that the modularization technique itself has broader applications in reverse engineering and security analysis (e.g., attack surface detection), demonstrating its versatility.

Key Results

  • Modularization Quality: ModX achieved significantly higher module quality scores compared to BCD and AR modularization, with an average improvement of 353% in module quality scores across several metrics. It also produced fewer isolated clusters and entries.
  • TPL Detection Accuracy:
    • On real-world programs, ModX achieved 83.0% precision and 73.8% recall for package detection, and 85.6% precision and 49.6% recall for TPL detection.
  • On manually crafted binaries, ModX achieved an average precision of 85.0% and recall of 65.4%, outperforming state-of-the-art tools like BAT and OssPolice.
  • Malware Variant Detection: ModX successfully detected 12 out of 15 malware variants, demonstrating its effectiveness in identifying partial code reuse across different architectures and mutations.
  • Performance: While ModX's modularization is faster than BCD, its TPL detection phase is slower than syntactic-based methods due to the complexity of semantic feature extraction and matching.

Limitations and Future Work

  • Performance Overhead: The semantic feature extraction and matching process in ModX incurs higher computational overhead compared to purely syntactic methods. The authors suggest combining ModX with lightweight syntactic approaches to pre-filter candidates.
  • Ground Truth for Modularization: Establishing a definitive "ground truth" for binary program modularization remains a challenge, making it difficult to empirically validate the absolute correctness of the proposed metrics. Future work could involve more extensive empirical studies on metric impact.
  • Obfuscation and Semantic Drift: Heavy binary obfuscation or significant semantic changes in libraries could still pose challenges.
  • Broader Applications: The authors plan to extend the modularization technique to facilitate other program analysis tasks beyond TPL detection, such as more advanced reverse engineering and security analysis.

Summary updated

BibTeX
@inproceedings{yang2022modx,
  author = {Can Yang and Zhengzi Xu and Hongxu Chen and Yang Liu and Xiaorui Gong and Baoxu Liu},
  title = {{ModX: Binary Level Partially Imported Third-Party Library Detection via Program Modularization and Semantic Matching}},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510627},
}
Figure