Can LLMs Obfuscate Code? A Systematic Analysis of Large Language Models into Assembly Code Obfuscation

Seyedreza Mohseni, Seyedali Mohammadi, Deepa Tilwani, Yash Saxena, Gerald Ketu Ndawula, Sriram Vema, Edward Raff, Manas Gaur

Introduction

Malware detection relies heavily on identifying code signatures. To evade these defenses, malware authors employ obfuscation—the intentional transformation of code to make it difficult to analyze while preserving its original functionality. Traditionally, this requires a metamorphic engine, a complex internal module that rewrites the malware's own binary. However, these engines increase file size and complexity, often serving as a "red flag" for security analysts.

This research explores a novel alternative: leveraging cloud-based Large Language Models (LLMs) as external metamorphic engines. By offloading obfuscation to an API, malware can remain lightweight and its network traffic can blend in with legitimate web activity. The study introduces the METAMORPHASM benchmark to evaluate whether LLMs can handle the rigorous demands of assembly-level code mutation.

The LLM-Based Obfuscation Paradigm

The researchers propose replacing the traditional "Code Analyzer" and "Obfuscator" components of a metamorphic engine with an LLM. This shift simplifies the malware's architecture by moving the complex logic of code mutation to a remote server.

Comparison of Traditional vs. LLM-based Obfuscation Engines

In the LLM-based model, the malware disassembles its own code and sends snippets to a remote LLM. The model returns an obfuscated version, which is then reassembled and executed. This approach not only reduces the local footprint but also leverages the vast knowledge encoded in state-of-the-art models, potentially allowing for more sophisticated mutations than a hardcoded engine could provide.

Methodology and Techniques

The study evaluates LLMs on three fundamental obfuscation techniques:

  1. Dead Code Insertion: Injecting "junk" instructions (e.g., NOP or redundant moves) that do not affect the program's logic but alter its binary signature.
  2. Register Substitution: Systematically swapping registers (e.g., replacing EAX with EBX) throughout a code block.
  3. Control Flow Change: Scrambling the order of code blocks using jump instructions (JMP) while maintaining the original execution path.

To guide the models, the researchers utilized a structured prompting approach, including zero-shot and few-shot examples to provide context for the assembly transformations.

Few-Shot Prompt Structure for Assembly Obfuscation

The METAMORPHASM Dataset (MAD)

To rigorously test these capabilities, the authors developed the METAMORPHASM DATASET (MAD). This dataset consists of 328,200 assembly code samples extracted from Windows 7 and 8.1 system files (DLLs and EXEs) and various open-source x64 assembly libraries. It contains 109,400 pairs for each of the three obfuscation techniques, providing the first major benchmark specifically designed to test an LLM's ability to perform assembly-level mutation.

Results and Analysis

The performance of various LLMs was measured using Delta Entropy (Δ) to quantify changes in code randomness and Cosine Similarity (CS) to ensure structural and functional integrity. The researchers found that effective obfuscation usually results in a Delta Entropy change of 10% to 20%; anything higher often indicates model "hallucination" that breaks the code.

  • Top Performers: GPT-4o-mini and DeepSeekCoder-v2 emerged as the clear winners. They consistently achieved the target entropy range while maintaining high Cosine Similarity (averaging 0.90+). DeepSeekCoder-v2 was particularly impressive, reaching similarity scores of 0.99 in some tests.
  • Specialization Matters: General-purpose models like LLaMA 3.1 struggled significantly with assembly code, often failing to generate valid instructions entirely. This suggests that models specifically pre-trained on code or highly optimized proprietary models are necessary for low-level tasks.
  • The Difficulty of Integrity: Register substitution proved to be the most challenging task. It requires a perfect "global" understanding of register usage; a single error in tracking which registers are free to use can lead to a program crash.

Conclusion and Future Work

The study demonstrates that LLMs can effectively serve as metamorphic engines, producing obfuscated assembly code that rivals human-written quality. While this presents a new threat vector for stealthy malware, the authors suggest that the METAMORPHASM dataset can also be used to train antivirus engines to recognize LLM-generated patterns. Future research will address the challenges of functional verification for larger code snippets and the potential for real-time, automated defense mechanisms.

Summary updated

BibTeX
@inproceedings{mohseni2025can,
  author = {Seyedreza Mohseni and Seyedali Mohammadi and Deepa Tilwani and Yash Saxena and Gerald Ketu Ndawula and Sriram Vema and Edward Raff and Manas Gaur},
  title = {{Can LLMs Obfuscate Code? A Systematic Analysis of Large Language Models into Assembly Code Obfuscation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i23.34672},
}
Figure