Autonomous Penetration Testing using Reinforcement Learning.

Jonathon Schwartz, Hanna KurniawatiarXiv 2019

TL;DR

This paper explores using model-free Reinforcement Learning (RL) to automate penetration testing, removing the need for complex, pre-defined models of exploit success. By developing a high-speed network simulator, the author demonstrates that Q-learning agents can independently discover optimal attack paths in various network topologies, though scaling to massive, exploit-rich environments remains a significant hurdle.

What Problem Does This Paper Address?

Penetration testing (pentesting) is the "white hat" practice of authorized hacking to find security holes. It is critical for defense, but it’s also slow, expensive, and requires rare, high-level expertise.

While researchers have tried to automate this using AI, most previous attempts relied on "model-based" planning. These systems require a perfect map of the environment and, crucially, a precise mathematical model of every exploit’s success probability. In the real world, the cybersecurity landscape changes daily—new software versions and zero-day exploits make maintaining these models a nightmare.

The author asks: Can we use model-free Reinforcement Learning to let an agent learn how to hack a network simply through trial and error, without knowing the "rules" of the exploits beforehand?

Methods

The research was conducted in two main phases:

  1. The Network Attack Simulator (NAS): The author built a custom, lightweight simulator in Python. Unlike virtual machine (VM) setups, which are computationally heavy, NAS abstracts the network into a Markov Decision Process (MDP). It allows for rapid training—performing thousands of actions per second.
  2. RL Agent Implementation: The study tested three variations of Q-learning:
  3. Tabular $\epsilon$-greedy: A simple lookup table approach that explores randomly with a small probability ($\epsilon$).
  4. Tabular UCB (Upper Confidence Bound): A tabular approach that uses uncertainty to guide exploration more intelligently.
  5. Deep Q-Learning (DQL): Uses a neural network to approximate the "value" of actions, allowing it to handle larger state spaces and generalize to unseen scenarios.

The agents were tasked with navigating subnets, bypassing firewalls, and compromising "sensitive" machines while minimizing the "cost" (time, noise, or effort) of their actions.

Datasets

Because no standard benchmark exists for RL-based pentesting, the author created a procedural generation system within the NAS. The experiments used:

  • Custom Scenarios: Three fixed designs (Standard, Single-site, and Multi-site) to test basic pathfinding.
  • Procedurally Generated Networks: Networks ranging from 3 to 43 machines and 1 to 51 exploitable services to test how the algorithms scale.
  • Exploit Distributions: Success probabilities were sampled based on real-world 2017 Common Vulnerability Scoring System (CVSS) data to mimic realistic attack complexities.

Key Insights and Ideas

  • Model-Free is Viable: The most important "aha" moment was confirming that agents could find optimal attack paths without any prior knowledge of exploit success rates. The agent learns the "physics" of the network through interaction.
  • The Speed Advantage: The NAS simulator achieved up to 17,000 actions per second. For comparison, a VM-based setup typically manages only 0.2 to 0.3 actions per second. This speed is what makes RL training feasible for this domain.
  • The Generalization Paradox: Deep Q-Learning (DQL) was the most consistent at solving fixed scenarios because it could generalize its policy to states it hadn't seen exactly before. However, it struggled more than tabular methods when the number of actions (available exploits) increased, likely due to the increased complexity of the neural network's output layer.
  • Action Selection Matters: For tabular methods, the simple $\epsilon$-greedy strategy actually outperformed the more sophisticated UCB in this specific domain, learning faster and producing better policies.

Key Results

  • Optimality: In all three primary scenarios (Standard, Single-site, Multi-site), the RL agents converged to the theoretical maximum reward, meaning they found the shortest, most efficient path to the target.
  • Scaling Limits: Performance remained high for networks up to about 18 machines. Beyond 38 machines, the tabular $\epsilon$-greedy agent’s performance dropped sharply as the state space exploded.
  • DQL vs. Tabular: While DQL was slower to train in terms of raw time, it was more robust. In the largest tested networks (43 machines), DQL still outperformed a random agent, whereas the tabular methods failed completely.
  • Exploit Complexity: Tabular $\epsilon$-greedy was remarkably resilient to an increasing number of available exploits, maintaining near-optimal performance even with 50+ different exploit types available per machine.

Limitations and Future Work

The paper identifies two primary roadblocks:

  1. The Curse of Dimensionality: As networks grow to hundreds of machines, the state space becomes too vast for standard Q-learning. The author suggests Hierarchical RL—where one agent decides which machine to target and another decides which exploit to use—as a potential solution.
  2. Fidelity vs. Abstraction: The NAS is a high-level abstraction. An agent that learns to hack in this simulator might not yet be ready for a real-world network where timing, network traffic, and IDS (Intrusion Detection Systems) add layers of non-deterministic noise.

The next logical step is moving these agents into higher-fidelity environments, such as virtualized networks, to see if the learned strategies hold up against real-world operating systems.

Summary updated

BibTeX
@misc{schwartz2019autonomous,
  author = {Jonathon Schwartz and Hanna Kurniawati},
  title = {{Autonomous Penetration Testing using Reinforcement Learning.}},
  year = {2019},
  eprint = {1905.05965},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1905.05965},
}
Figure