Evading control flow graph based GNN malware detectors via active opcode insertion method with maliciousness preserving

Hao Peng, Zehao Yu, Dandan Zhao, Zhiguo Ding, Jieshuai Yang, Bo Zhang, Jianming Han, Xuhong Zhang, Shouling Ji, Zhong MingScientific 2025

Abstract

With the continuous advancement of machine learning, numerous malware detection methods that leverage this technology have emerged, presenting new challenges to the generation of adversarial malware. Existing function-preserving adversarial attacks fall short of effectively modifying portable executable (PE) malware control flow graphs (CFGs), thereby failing to bypass the graph neural network (GNN) models that utilize CFGs for detection. To solve this issue, we introduce a novel base modification method called active opcode insertion, which modifies PE CFGs while preserving functionality by inserting a processed sequence of benign and jump opcodes to connect with the original base block. Using reinforcement learning, MalAOI identifies optimal insertion points and benign opcode sequences to autonomously generate adversarial malware that evades GNN model detection. We tested our approach on the BODMAS and SOREL-20M datasets, and the results demonstrate that MalAOI-generated adversarial malware achieves an average evasion rate of 93.73% against the GNN detection model, with only 12.87% increase in byte size.

Introduction

The shift from signature-based detection to deep learning has significantly improved malware identification. Graph Neural Networks (GNNs) have emerged as a particularly potent defense, as they analyze a program's Control Flow Graph (CFG). Unlike raw byte analysis, CFGs capture the structural logic of a program, making them inherently more robust against traditional obfuscation techniques. However, this robustness creates a new frontier for adversarial research: how can one modify a binary to alter its CFG without breaking its functionality?

The challenge is twofold. First, direct CFG modification is impossible; one must modify the underlying binary such that the resulting decompiled graph is different. Second, binary files are fragile; even minor insertions can lead to crashes. This paper introduces MalAOI, a framework designed to overcome these hurdles through active opcode insertion and reinforcement learning.

Methodology

The MalAOI Framework

MalAOI utilizes a reinforcement learning (RL) loop to autonomously generate adversarial malware. The framework consists of several key components: an extraction module for benign opcode sequences, an RL agent to determine optimal insertion strategies, and a modification engine that performs the binary edits.

The MalAOI overall framework, illustrating the reinforcement learning loop and the autonomous generation of adversarial malware.

Active Opcode Insertion

The core innovation is Active Opcode Insertion. Unlike "dead code" insertion, which adds non-executed bytes, MalAOI inserts code that is actually executed. This forces the GNN detector to incorporate new, benign-looking nodes and edges into its graph representation.

To ensure the malware remains functional, the framework implements meticulous state management. Before executing the inserted benign code, the CPU state is saved using pusha and pushf instructions. After the benign sequence runs, the state is restored with popa and popf. This "cleansing" process prevents the benign code from interfering with the malware's original logic.

Detailed view of the active opcode insertion process, showing how assembly code and the resulting Control Flow Graph are transformed to include benign detours.

Reinforcement Learning Agent

The RL agent acts as the attacker. It observes the malware's CFG and selects the best insertion points and benign sequences from a pre-extracted set. Its goal is to minimize the "maliciousness score" produced by a target GNN detector while maintaining the program's functionality.

Experimental Results

The researchers evaluated MalAOI using the SOREL-20M and BODMAS datasets, with benign sequences sourced from 12,500 legitimate Windows files.

Evasion Performance

MalAOI achieved an average Attack Success Rate (ASR) of 93.73% across various GNN architectures, including GCN, GAT, and DGCNN. In some specific configurations, the evasion rate reached as high as 99.20%. Furthermore, the adversarial samples demonstrated significant transferability, successfully evading models they weren't specifically trained against.

Stealth and Functionality

The modifications were remarkably efficient, resulting in only a 12.87% average increase in file size. More importantly, the Functionality Preservation Rate (FPR) averaged 78.43%, with certain malware families like Downloaders maintaining over 91% functionality. Tests against commercial engines on VirusTotal confirmed the real-world effectiveness, showing significant drops in detection by major vendors.

Conclusion

MalAOI demonstrates that GNN-based malware detectors, while robust, are vulnerable to structural modifications that preserve functionality. By using RL to automate the insertion of benign-looking "detours" in the control flow, attackers can effectively mask malicious intent. Future work will focus on extending this method to 64-bit architectures and Linux (ELF) files, as well as developing more resilient GNN training methods to counter such attacks.

Summary updated

BibTeX
@inproceedings{peng2025evading,
  author = {Hao Peng and Zehao Yu and Dandan Zhao and Zhiguo Ding and Jieshuai Yang and Bo Zhang and Jianming Han and Xuhong Zhang and Shouling Ji and Zhong Ming},
  title = {{Evading control flow graph based GNN malware detectors via active opcode insertion method with maliciousness preserving}},
  booktitle = {Scientific},
  year = {2025},
  doi = {10.1038/s41598-025-92023-7},
}
Figure