Abstract
Autonomous penetration testing requires agents that can both learn complex strategies in high-speed environments and execute them reliably on real-world systems. Current research is often bifurcated between abstract simulators that lack realism and high-fidelity emulators that are too slow for deep reinforcement learning (RL). This paper introduces NASimEmu, a unified framework that bridges this gap. By providing a shared OpenAI Gym interface for both a simulator and a VM-based emulator, NASimEmu enables agents to be trained at scale and subsequently deployed into realistic environments. Furthermore, we address the challenge of generalization by introducing size-invariant model architectures that allow agents to adapt to novel network topologies and scales.
1. Introduction
Training AI agents for offensive cyber operations presents a unique set of challenges. Deep RL typically requires millions of interactions to converge, a volume of data that is impossible to generate using traditional virtual machine (VM) clusters due to the significant overhead of booting systems and executing real exploits. Conversely, while simulators are fast, they often suffer from a "reality gap"—the agent learns to manipulate abstract Python objects rather than navigating the nuances of real network protocols and service vulnerabilities.
Moreover, many existing RL benchmarks for cybersecurity evaluate agents on the exact network configurations used during training. This often results in agents that memorize specific exploit paths rather than learning generalizable hacking heuristics. NASimEmu addresses these issues by providing a dual-mode framework designed for both high-speed training and high-fidelity validation.
2. The NASimEmu Framework
NASimEmu is built on the principle of environment parity. It utilizes an enhanced version of the Network Attack Simulator (NASim) for training and a robust emulation stack for testing.
2.1 Shared Interface
Both the simulator and emulator implement the OpenAI Gym interface. This abstraction allows researchers to swap the underlying environment without modifying the agent's code. An agent can learn the logic of lateral movement in the simulator and then be immediately tested against a real network of VMs.
2.2 The Emulation Stack
To ensure realism, the emulator utilizes industry-standard virtualization and security tools:
- Vagrant & VirtualBox: For automated VM lifecycle management.
- Mikrotik RouterOS: To provide realistic firewalling and routing between subnets.
- Metasploit Framework: Used as the primary engine for executing exploits, ensuring that the agent's actions correspond to real-world attack modules.
2.3 Dynamic Scenarios and Generalization
To prevent memorization, NASimEmu supports dynamic scenarios. While the high-level topology (e.g., a DMZ connected to an internal network) remains fixed, the specific number of hosts and their individual configurations are randomized for every episode. This forces the agent to develop strategies based on observed service signatures rather than hard-coded host addresses.
3. Model Architectures for Network Scaling
A key contribution of this work is the comparison between standard Multi-Layer Perceptrons (MLPs) and size-invariant architectures. Standard MLPs require a fixed-size input vector, meaning an agent trained on a network with 10 hosts cannot be deployed on a network with 20 hosts.
NASimEmu utilizes a size-invariant model that employs shared embeddings and aggregation layers (such as mean or max pooling). This allows the model to process an arbitrary number of host observations, making it fundamentally better suited for the variable nature of real-world networks.
4. Experimental Evaluation
4.1 Scenarios and Datasets
The framework includes several prototypical topologies, ranging from simple entry-point scenarios to complex enterprise networks containing dedicated subnets for users, services, and databases. These are categorized into "Small" (sm) and "Medium" (md) scales to facilitate transfer learning experiments (e.g., training on sm and testing on md).
4.2 Key Results
- Generalization: In transfer tasks (md2sm), the size-invariant model maintained high performance on novel network scales, whereas the MLP's performance collapsed. This confirms that architectural choices are a primary bottleneck for agent generalization in cybersecurity.
- Sim-to-Real Transfer: In qualitative evaluations, an agent trained exclusively in the simulator was deployed into the VM-based emulator. The agent successfully navigated a multi-stage attack: scanning the network, exploiting a WordPress vulnerability, pivoting to an internal subnet, and performing privilege escalation on a Linux kernel to retrieve sensitive data—all within 17 steps.
- Robustness: Despite the inherent "flakiness" of real networks (where actions may fail due to transient connectivity issues), the agents demonstrated robustness, successfully retrying failed actions to reach their objectives.
5. Discussion and Limitations
While NASimEmu represents a significant step forward, several areas remain for future development:
- Static Environments: The current framework lacks an active defender (e.g., an AI-driven Blue Team) or automated Intrusion Detection Systems (IDS) that react to the attacker's presence.
- Firewall Fidelity: Firewalls are currently modeled as all-or-nothing gates between subnets, lacking the port-specific filtering found in production environments.
- Credential Management: The complex logic of harvesting, storing, and reusing credentials (SSH keys, password hashes) for lateral movement is not yet fully implemented.
- The Stopping Problem: While the environment includes a
TerminalActionto mirror the real-world need for an attacker to decide when to exit, baseline agents still struggle to optimize the timing of their departure.
6. Conclusion
NASimEmu provides a critical bridge between simulation and reality for autonomous cyber operations. By combining high-speed training environments with high-fidelity emulation and size-invariant neural architectures, the framework enables the development of agents that are not only capable of hacking real systems but are also robust enough to generalize to networks they have never seen before.
Summary updated