Enhancing the Insertion of NOP Instructions to Obfuscate Malware via Deep Reinforcement Learning

Daniel Gibert, Matt Fredrikson, Carles Mateu, Jordi Planes, Quan LeComput. Secur 2021 · DOI

Abstract

Deep learning models for malware detection are increasingly vulnerable to adversarial attacks. This paper presents a Deep Reinforcement Learning (DRL) framework designed to automatically identify optimal locations for inserting "dead code" (NOP instructions) into malware assembly code. By employing a Double Q-Network (DQN) to target a state-of-the-art CNN malware classifier, the proposed agent successfully reduced classification accuracy from 98.65% to 56.53%. Notably, the agent achieved a 100% evasion rate for several malware families while requiring 33% fewer modifications than random insertion strategies.

Introduction

Machine learning (ML) has significantly advanced malware detection by enabling the generalization of threats beyond static signatures. However, Deep Neural Networks (DNNs) possess a "glass heel": they are highly vulnerable to adversarial examples. In malware obfuscation, an adversarial attack involves modifying a malicious file to maintain its original functionality while causing an AI detector to misclassify it as benign or as a different family.

Traditional "dead code insertion"—adding non-functional instructions like NOP—has been used for decades. However, effectively applying this technique against complex neural networks remains a challenge. This research investigates whether an AI agent can autonomously discover the "blind spots" of an AI detector more efficiently than human experts or stochastic methods.

Methodology

The proposed framework utilizes Deep Reinforcement Learning, specifically a Double Q-Network (DQN) with experience replay, to navigate the obfuscation task.

The RL Environment

The environment consists of the assembly code of a malware sample, represented as a sequence of mnemonics (e.g., mov, push, add). The agent interacts with this environment by selecting insertion points for NOP instructions within the malware sample, which is then passed to a malware classifier to determine the reward.

Reinforcement Learning framework for malware obfuscation

Agent Architecture

The agent is a neural network that processes code sequences. It employs an embedding layer to transform mnemonics into dense vectors and a convolutional layer to extract local structural patterns. A critical component is the "time-distributed" fully-connected layer, which outputs a Q-value (predicted reward) for every potential insertion position within the code sequence.

Detailed architecture of the DRL agent's Q-Network

The agent receives a reward based on the increase in "loss" of the target classifier. If the insertion successfully increases the classifier's uncertainty regarding the malware's identity, the agent receives a positive signal.

Experimental Setup

The study utilizes the Microsoft Malware Classification Dataset, comprising nearly half a terabyte of data including hexadecimal and assembly code for nine distinct malware families (e.g., Ramnit, Kelihos, Vundo). The target of the attack is a state-of-the-art shallow Convolutional Neural Network (CNN) trained to classify these families based on assembly patterns.

Results and Discussion

The DRL-guided attack caused the target CNN's overall accuracy to drop from 98.65% to 56.53%. For specific families such as Kelihos_ver3, Simda, and Kelihos_ver1, the agent achieved a 100% evasion rate.

Strategic Pattern Breaking

The target CNN identifies malware by recognizing specific sequences of instructions (N-grams). The DRL agent learns to identify which N-grams serve as the strongest classification signals and strategically injects NOPs to disrupt these patterns or mimic those of other families.

Efficiency and File Size

The DRL agent demonstrated significant surgical precision, outperforming random insertion strategies across nearly all families. For the Simda family, the agent required an average of only 2 insertions to trigger misclassification, compared to 30 for a random agent. Overall, the agent achieved higher evasion rates while adding 33% fewer instructions, which is vital for maintaining small file sizes and avoiding "bloatware" detection heuristics.

Impact of File Size on Evasion

The attack was notably less effective against large-scale malware families like Ramnit and Lollipop, which average approximately 46,000 instructions. In these cases, the 50-instruction modification limit was insufficient to significantly alter the dominant statistical signature of the original code.

Conclusion and Future Work

This research demonstrates the potency of DRL in automating malware obfuscation. Future work will explore expanding the action space to include a wider variety of "dead code" (e.g., ADD EAX, 0) to further increase attack potency. Additionally, the authors suggest using these adversarial techniques for "adversarial training" to harden classifiers against such noise-based evasion tactics.

Summary updated

BibTeX
@inproceedings{gibert2021enhancing,
  author = {Daniel Gibert and Matt Fredrikson and Carles Mateu and Jordi Planes and Quan Le},
  title = {{Enhancing the Insertion of NOP Instructions to Obfuscate Malware via Deep Reinforcement Learning}},
  booktitle = {Comput. Secur},
  year = {2021},
  doi = {10.1016/j.cose.2021.102543},
}
Figure