As network scale and uncertainty complicate automated penetration testing, reinforcement learning (RL) environments must support controlled evaluation under defensive and non-stationary conditions. We present DYNAS (Dynamic Network Attack Simulator), which combines parameterized large-scale scenario generation with stateful intrusion detection responses, explicit scan false-positive and false-negative noise, temporary service unavailability, and duration-based action timeouts. We further introduce Pen-DHRL, a recurrent manager--worker policy that selects persistent subgoals using IDS-conditioned global context. We compare Pen-DHRL with GNN, Invariant, and Attention baselines across four scenario variants and multiple training regimes. Under IDS-disabled training followed by IDS-enabled evaluation, Pen-DHRL obtains approximately 64% and 24% higher reward per step on Bridge and Dynamic, respectively, and approximately 26% and 30% more captured hosts on VarA and VarB than the next-best baseline. With all defensive dynamics active from the beginning of training, Pen-DHRL achieves positive mean episode returns in all four scenarios, whereas the flat baselines produce negative mean returns in all 12 architecture--scenario combinations; staged curriculum training produces positive mean returns across all 16 evaluated combinations.
Figures & tables
Feature
NASim
IAPTF
WCE
DynPen
NASimEmu
PenGym
DYNAS
Simulation-Based Training
✓
✓
Conceptual
✓
✓
✓
✓
Structural Scenario Variation
Limited
–
Conceptual
✓
Limited
Limited
✓
Firewall-Aware Reachability
✓
Limited
Conceptual
–
✓
✓
✓
IDS Representation/Response
–
Limited
–
–
–
–
✓
Curriculum Scheduling
–
–
–
–
–
–
✓
Explicit Scan FP/FN Noise
–
–
–
–
–
–
✓
Table 1: Abstraction-level and environmental-feature comparison of RL-based pentesting frameworks
Figure 1: Overview of Dynamic Scenario Generation and HRL Agent Development. Part 1 (left, detailed in Part 1 below) is the scenario pipeline, from the cached template through the NASimEmu runtime. Part 2 (right, detailed in Part 2 below) is the Pen-DHRL agent, from graph encoding through the value and termination heads. Solid arrows carry data and decisions during an episode; dashed arrows carry gradients during the recurrent PPO update.
Figure 2: Pen-DHRL Architecture Implemented in DYNAS. Left: the forward path for one decision. Node features and positional encodings are embedded and passed through the recurrent manager GNN to obtain per-node features and a graph-level global context; the graph-wise mean of the per-host IDS fields is projected and added to that context. The manager either keeps its active goal or draws a new slot from the goal bank, refines it with the global context, and passes the result to a GAT worker that emits a (host, action) decision. Value and termination heads read the concatenated global context, refined goal, and normalized episode progress. Right: the state carried across steps, and the recurrent PPO update, which snapshots that state, replays the recorded decisions with done-masked resets, and applies the clipped policy, value, and entropy losses.
Scenario
(N,H,S)
Aheuristic
Captured hosts
Episode return
Corp-Dyn
(39,83,12)
314.5
36.13
49.41
VarA
(41,86,12)
327.5
36.68
48.43
Table 2: Scenario dimensions, heuristic interaction budget, and observed Pen-DHRL outcomes in the defense-disabled setting
Scenario
LinSvc
WinSvc
AnySvc
SensSvc
LinProc
WinProc
UserExp
RootExp
PrivEsc
Corp
3
2
1
1
0
0
4
1
1
Uni
3
2
1
1
0
0
4
1
1
Corp-Dyn
23
8
1
3
6
7
7
1
6
VarA
23
8
1
3
6
7
8
0
6
Table 3: Service and process distribution across network scenarios
Scenario
Subnets
Hosts
Exploits
SensHosts
Density
Corp
8
21
5
7
0.25
Uni
9
27
5
3
0.27
Corp-Dyn
12
83
8
39
0.19
VarA
12
86
8
41
0.19
Table 4: Structural and security characteristics of network scenarios
Metric
Architecture
Training
Testing
Reward/step
GNN
0.27
0.27
Invariant
0.34
0.33
Attention
0.26
0.26
Pen-DHRL
0.49
0.48
Episode return
GNN
29.90
30.02
Invariant
27.21
27.06
Table 5: Baseline performance on dynamically generated scenarios without IDS or curriculum
Reward/step
Episode return
Scenario
Model
No
Curr
Δ
No
Curr
Δ
Bridge
Pen-DHRL
−0.40
1.51
+1.11
−161
213
+53
GNN
−0.08
1.37
+1.45
−31
189
+220
Invariant
−1.30
1.22
+2.52
−511
206
+717
Attention
−1.23
1.24
+2.47
−490
205
+695
Dynamic
Pen-DHRL
−0.54
2.25
+1.71
−217
249
+32
Table 6: IDS-enabled evaluation of reward per step and episode return: no-curriculum vs. curriculum. Episode returns are rounded to integers; each Δ uses unrounded values
Episode length
Captured hosts
Scenario
Model
No
Curr
Δ
No
Curr
Δ
Bridge
Pen-DHRL
400
141
−259
24.95
25.72
+0.77
GNN
400
138
−262
0.99
23.68
+22.69
Invariant
392
170
−222
2.24
25.56
+23.32
Attention
400
165
−235
1.07
23.72
+22.65
Dynamic
Pen-DHRL
400
113
−287
29.59
30.37
+0.78
Table 7: IDS-enabled evaluation of episode length and captured hosts: no-curriculum vs. curriculum. Episode lengths are rounded to integers; each Δ uses unrounded values
Scenario
Architecture
Reward/step
Episode return
Ep Len
Capture
Bridge
Pen-DHRL
−1.15
−161.96
141.20
23.36
GNN
−0.18
−66.20
368.86
26.17
Invariant
−0.01
−5.20
367.77
25.69
Attention
−0.70
−120.04
170.39
17.58
Dynamic
Pen-DHRL
−1.49
−200.17
134.56
27.80
GNN
−0.26
−91.32
356.31
30.59
Table 8: Per-scenario model performance with IDS disabled during training but enabled during evaluation