Discovering Command and Control Channels Using Reinforcement Learning

Cheng Wang, Akshay Kakkar, Christopher Redino, Abdul Rahman, Ajinsyam S, Ryan Clark, Daniel Radke, Tyler Cody, Lanxiao Huang, Edward BowenarXiv 2024 · DOI

Abstract

Command and control (C2) paths for issuing commands to malware are sometimes the only indicators of its existence within networks. Identifying potential C2 channels is often a manually driven process that involves a deep understanding of cyber tradecraft. Efforts to improve discovery of these channels through using a reinforcement learning (RL) based approach that learns to automatically carry out C2 attack campaigns on large networks, where multiple defense layers are in place serves to drive efficiency for network operators. In this paper, we model C2 traffic flow as a three-stage process and formulate it as a Markov decision process (MDP) with the objective to maximize the number of valuable hosts whose data is exfiltrated. The approach also specifically models payload and defense mechanisms such as firewalls which is a novel contribution. The attack paths learned by the RL agent can in turn help the blue team identify high-priority vulnerabilities and develop improved defense strategies. The method is evaluated on a large network with more than a thousand hosts and the results demonstrate that the agent can effectively learn attack paths while avoiding firewalls.

Introduction

Command and Control (C2) channels are the communication lifelines between deployed malware and an attacker’s infrastructure. For sophisticated actors like Advanced Persistent Threats (APTs), these channels are carefully designed to be "signature-less" and blend into normal traffic, making them incredibly difficult to detect. Currently, identifying potential C2 pathways within a complex network is a manual, labor-intensive process that requires deep expertise in cyber tradecraft. As networks grow to include thousands of hosts and hundreds of subnets, manual analysis becomes a bottleneck. This paper presents a reinforcement learning (RL) framework designed to automatically discover these pathways, helping defenders proactively identify and harden high-priority vulnerabilities.

Methodology: Modeling the C2 Campaign

The researchers model the C2 attack campaign as a Markov Decision Process (MDP) and solve it using Proximal Policy Optimization (PPO), a popular actor-critic RL algorithm. The environment is modeled as a complex "cyber terrain" featuring multiple subnets and firewalls with dynamic defense mechanisms, such as periodic updates and emergency triggers that respond to aggressive network behavior.

Three-Stage Attack Model

The agent must progress through three distinct stages to successfully exfiltrate data:

  1. Infection Stage: Scanning and exploiting vulnerabilities (mapped to real-world CVEs).
  2. Connection Stage: Establishing a link between compromised hosts and the C2 server.
  3. Exfiltration Stage: Uploading the stolen data while avoiding detection.
The three-stage attack model used to formulate the MDP.

The agent's action space includes technical operations like subnet scans and CVE-based exploits, as well as a strategic "Sleep" action. This allows the agent to wait and let detection windows reset, mimicking the patient behavior of real-world attackers.

Results and Key Insights

The model was evaluated on a simulated network of 101 subnets and 1,444 hosts, populated with real-world service data from the Shodan API and vulnerabilities from the CVE-Search database.

Learning Stealth through RL

Perhaps the most significant insight is the agent's emergent ability to learn stealth. To avoid triggering firewall updates, the agent strategically used the "Sleep" action, learning the "cadence" of the defense system. It paused between uploads to stay below alert thresholds, as shown in the distribution of pause durations.

Distribution of pause durations between uploads, showing a median of 120 seconds as the agent learns to avoid detection.

Performance and Efficiency

  • Success Rate: In 100 test scenarios, the trained agent successfully completed the full three-stage attack on target hosts 78% of the time.
  • Efficiency: On average, the agent completed the entire campaign in 107 steps, taking approximately 47 minutes of simulated time.
  • Convergence: The RL policy successfully converged within 10,000 episodes, with total rewards approaching the theoretical maximum.

Conclusion

By playing the role of the aggressor, the RL agent identifies "high-priority" nodes—intermediate hosts frequently used in successful attack chains—which defenders can then prioritize for patching. Future research will focus on modeling specific protocols like HTTPS and DNS and exploring competitive "Purple Team" scenarios where both attackers and defenders are RL agents.

Summary updated

BibTeX
@misc{wang2024discovering,
  author = {Cheng Wang and Akshay Kakkar and Christopher Redino and Abdul Rahman and Ajinsyam S and Ryan Clark and Daniel Radke and Tyler Cody and Lanxiao Huang and Edward Bowen},
  title = {{Discovering Command and Control Channels Using Reinforcement Learning}},
  year = {2024},
  eprint = {2401.07154},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.07154},
}
Figure