Knowledge-Informed Auto-Penetration Testing Based on Reinforcement Learning with Reward Machine

Yuanliang Li, Hanzheng Dai, Jun YanarXiv 2024

Abstract

Automated penetration testing (AutoPT) based on reinforcement learning (RL) has proven its ability to improve the efficiency of vulnerability identification in information systems. However, RL-based PT encounters several challenges, including poor sampling efficiency, intricate reward specification, and limited interpretability. To address these issues, we propose a knowledge-informed AutoPT framework called DRLRM-PT, which leverages reward machines (RMs) to encode domain knowledge as guidelines for training a PT policy. In our study, we specifically focus on lateral movement as a PT case study and formulate it as a partially observable Markov decision process (POMDP) guided by RMs. We design two RMs based on the MITRE ATT&CK knowledge base for lateral movement. To solve the POMDP and optimize the PT policy, we employ the deep Q-learning algorithm with RM (DQRM). The experimental results demonstrate that the DQRM agent exhibits higher training efficiency in PT compared to agents without knowledge embedding. Moreover, RMs encoding more detailed domain knowledge demonstrated better PT performance compared to RMs with simpler knowledge.

Introduction

Penetration Testing (PT) is a critical security practice involving authorized simulated attacks to identify vulnerabilities. Traditionally, this is a manual, labor-intensive process requiring high-level expertise. While Reinforcement Learning (RL) offers a path toward automation, standard RL agents struggle with the massive action spaces of network environments (sampling inefficiency) and the difficulty of defining meaningful rewards for intermediate steps (reward sparsity). Furthermore, the "black-box" nature of deep learning makes it difficult for human operators to interpret an agent's current attack phase. DRLRM-PT addresses these by embedding cybersecurity domain knowledge directly into the learning process.

The DRLRM-PT Framework

The core of the DRLRM-PT framework is the integration of a Reward Machine (RM) into the RL loop. The RM acts as a high-level logical scaffold that decomposes complex penetration goals into manageable subtasks based on established frameworks like MITRE ATT&CK.

The DRLRM-PT framework architecture, showing how domain knowledge from a Cybersecurity Knowledge Base is encoded into a Reward Machine to guide the PT Agent.

As shown in Figure 1, the framework consists of several key components:

  • Event Detector: A labeling function that maps observations from the target network to high-level events (e.g., "discovered new credentials").
  • Reward Machine: A finite state machine where transitions are triggered by these events. Each state in the RM corresponds to a specific subtask.
  • PT Agent: Utilizes the Deep Q-learning with Reward Machine (DQRM) algorithm to learn separate sub-policies for each state of the RM, significantly improving learning efficiency.

Key Insights: The Granularity Advantage

A critical finding of this research is that the granularity of encoded knowledge matters. The authors compared two RM designs: RM1 (a simpler 4-state model) and RM2 (a more detailed 5-state model). RM2 explicitly separated the subtasks of "discovering new nodes" and "discovering credentials," whereas RM1 combined them.

The detailed RM2 design, which decomposes the lateral movement process into five distinct states (u0 to u4) to provide finer-grained guidance to the RL agent.

Experimental results indicated that RM2 (Figure 3) outperformed RM1. By providing a more detailed "breadcrumb trail" of rewards, the RM helps the agent navigate the sparse reward landscape of network exploitation more effectively. This suggests that more comprehensive domain knowledge leads to superior PT performance.

Experimental Results

The framework was evaluated using Microsoft’s CyberBattleSim in two environments: a sequential "Chain" network and a complex "ToyCtf" mesh network.

  • Efficiency: In the Chain environment, DQRM agents reached peak performance in roughly half the steps required by standard DQN agents (approx. 104-186 steps vs. 218-374 steps).
  • Reliability: DQRM agents exhibited much lower variance in their success rates, indicating more consistent and reliable attack path identification.
  • Scalability: In the more difficult ToyCtf environment, which includes decoy nodes, the detailed RM2 agent showed the highest training efficiency, proving the framework's robustness against non-linear network topologies.

Conclusion and Future Work

DRLRM-PT demonstrates that embedding structured domain knowledge via Reward Machines can overcome the primary hurdles of RL-based automated penetration testing. While the current study focused on lateral movement, the modular nature of the framework allows for expansion. Future work will aim to incorporate the full Cyber Kill Chain to cover the entire attack lifecycle and explore methods for agents to dynamically adapt their Reward Machines to novel network defenses.

Summary updated

BibTeX
@misc{li2024knowledge,
  author = {Yuanliang Li and Hanzheng Dai and Jun Yan},
  title = {{Knowledge-Informed Auto-Penetration Testing Based on Reinforcement Learning with Reward Machine}},
  year = {2024},
  eprint = {2405.15908},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.15908},
}
Figure