LLMalMorph: On The Feasibility of Generating Variant Malware using Large-Language-Models

Md Ajwad Akil, Adrian Shuai Li, Imtiaz Karim, Arun Iyengar, Ashish Kundu, Vinny Parla, Elisa Bertino

TL;DR

LLMalMorph is a semi-automated framework that leverages off-the-shelf Large Language Models (LLMs) to mutate malware source code into functional, evasive variants without requiring resource-intensive fine-tuning. By combining function-level Abstract Syntax Tree (AST) extraction with constraint-driven prompt engineering, it successfully bypasses LLM safety filters and generates variants that significantly reduce detection rates across commercial antivirus engines and machine learning classifiers.

What Problem Does This Paper Address?

Automated malware variant generation is a constant cat-and-mouse game. Traditionally, defenders rely on signature-based or machine learning (ML) detectors to catch malicious binaries. Attackers counter this by mutating malware to alter its binary signature while preserving its original malicious behavior.

However, existing mutation techniques have notable gaps: most operate directly on compiled binaries (which is complex and limits structural diversity) or rely on heavy, iterative search algorithms. While LLMs excel at code generation, using them to mutate malware source code introduces unique challenges:

  1. Context Window Overload: Entire malware codebases are too large for an LLM to process at once, leading to incomplete or broken code edits.
  2. Safety Guardrails: Modern LLMs are aligned to refuse requests that look like malware generation.
  3. Compilation and Semantic Failures: LLMs are prone to "hallucinating" non-existent APIs or altering critical logic, rendering the mutated malware non-functional.

LLMalMorph addresses these challenges by demonstrating how a pre-trained LLM can safely and effectively mutate malware at the source-code level with minimal human intervention.

Methods

Fig. 1: Overall Architecture of LLMalMorph. The framework is organized into two main modules. Function Mutator extracts functions from the malware source code file and modifies them using an LLM. Variant Synthesizer updates the malware source code with the modified function and compiles the project to generate the variant.

LLMalMorph splits the mutation process into two main modules:

  1. Function Mutator: Instead of feeding the entire codebase to the LLM, LLMalMorph uses a Tree-sitter parser to extract individual function bodies, headers, and global declarations. It then wraps each function in a carefully engineered, constraint-driven prompt. To bypass safety filters, the prompts use neutral phrasing and abstract the malicious intent of the code.
  2. Variant Synthesizer: This module takes the mutated functions generated by the LLM, merges them back into the original codebase, and attempts to compile the project. It incorporates a minimal "human-in-the-loop" debugging process to quickly fix minor syntax errors or missing placeholders left by the LLM.

The framework guides the LLM (specifically Codestral-22B) using six distinct source-code transformation strategies:

  • Code Optimization: Removing redundancies and simplifying logic.
  • Code Quality and Reliability: Enhancing error and edge-case handling.
  • Code Reusability: Splitting monolithic functions into smaller modular blocks.
  • Code Security: Replacing standard cryptographic libraries (like OpenSSL) with alternative implementations.
  • Code Obfuscation: Renaming variables/functions to meaningless strings and inserting dead control flows.
  • Windows API Transformation: Replacing direct Windows API calls with indirect equivalents or wrappers.

Datasets

The authors evaluated LLMalMorph using 10 diverse, real-world Windows malware samples (primarily 32-bit C/C++) collected from public repositories. The dataset spans various malware categories:

  • Infectors/Viruses: Exeinfector
  • Generic Crimeware: Fungus
  • POS Trojans: Dexter
  • Botnets: HiddenVNC
  • Information Stealers: Predator, Prosto-Stealer
  • Ransomware: Conti (Cryptor), Babuk (Cryptor), RedPetya, RansomWar

Using the six transformation strategies, the framework generated a total of 618 unique malware variants.

Key Insights and Ideas

  • Function-Level Isolation is Crucial: Processing code at the function level keeps the context window small and manageable, which drastically improves the LLM's code generation quality and prevents project-wide dependency breaks.
  • Semantic Neutrality Bypasses Alignment: LLM safety filters trigger on explicit malware patterns. By presenting the code under the guise of benign refactoring or optimization tasks, the framework consistently circumvents refusal triggers.
  • Optimization is an Unexpected Evasion Tool: Surprisingly, the Code Optimization strategy was one of the most effective at evading antivirus detection. By restructuring data flows and introducing language-specific features, it alters the compiled binary's structural "blueprint" enough to blind signature-based detectors.
  • High Payoff for Low Manual Effort: The human-in-the-loop debugging phase required less than two minutes per variant on average, yet over 85% of that minimal effort resulted in successfully compiled, evasive variants.

Key Results

Fig. 2: Comparison of detection rates for different strategies across VirusTotal and Hybrid Analysis for ten malware samples.

The generated variants were tested against commercial antivirus aggregators (VirusTotal and Hybrid Analysis) and graph-based ML malware classifiers (Malgraph):

  • AV Evasion: Out of 618 variants, 72.6% showed a reduced detection rate. For complex samples, LLMalMorph typically reduced VirusTotal detection rates by 10–15%. For simpler samples (like Exeinfector), detection dropped by up to 31%.
  • ML Classifier Evasion: Without explicitly optimizing against machine learning models, LLMalMorph variants achieved an Attack Success Rate (ASR) of up to 89% (via Optimization) and 91% (via Security/Crypto replacement) against the Malgraph classifier.
  • Functionality Preservation: Using a normalized Longest Common Subsequence (LCS) metric on API call sequences, the authors verified that over 66% of the evasive variants fully preserved their original malicious functionality across four representative samples (with RedPetya exceeding 85%).

Limitations and Future Work

While LLMalMorph proves the feasibility of LLM-driven source mutation, it has a few limitations:

  • Language and Architecture Constraints: The current implementation is strictly focused on 32-bit Windows malware written in C/C++.
  • Sequential Function Selection: The framework mutates functions sequentially rather than intelligently targeting the specific functions responsible for malicious logic.
  • Human-in-the-Loop Dependency: It still relies on a human developer to resolve minor compilation errors caused by LLM hallucinations.

Future Directions: The authors plan to extend the framework to support other programming languages, automate the function selection process by isolating malware-relevant patterns, and integrate binary-level transformations to completely eliminate the need for manual debugging.

Summary updated

Abstract

Large Language Models (LLMs) have transformed software development and automated code generation. Motivated by these advancements, this paper explores the feasibility of LLMs in modifying malware source code to generate variants. We introduce LLMalMorph, a semi-automated framework that leverages semantical and syntactical code comprehension by LLMs to generate new malware variants. LLMalMorph extracts function-level information from the malware source code and employs custom-engineered prompts coupled with strategically defined code transformations to guide the LLM in generating variants without resource-intensive fine-tuning. To evaluate LLMalMorph, we collected 10 diverse Windows malware samples of varying types, complexity and functionality and generated 618 variants. Our experiments demonstrate that LLMalMorph variants can effectively evade antivirus engines, achieving typical detection rate reductions of 10-15% across multiple complex samples. Furthermore, without explicitly targeting learning-based detectors, LLMalMorph attained attack success rates of up to 91% against a Machine Learning (ML) based malware detector. We also discuss the limitations of current LLM capabilities in generating malware variants from source code and assess where this emerging technology stands in the broader context of malware variant generation.
BibTeX
@misc{akil2025llmalmorph,
  author = {Md Ajwad Akil and Adrian Shuai Li and Imtiaz Karim and Arun Iyengar and Ashish Kundu and Vinny Parla and Elisa Bertino},
  title = {{LLMalMorph: On The Feasibility of Generating Variant Malware using Large-Language-Models}},
  year = {2025},
  eprint = {2507.09411},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.09411},
}
Figure