{'fraction_non_alphanumeric': 0.03342039079125556, 'fraction_numerical': 0.007158057651383247, 'mean_word_length': 4.726114649681529, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
An Intrusion Response System utilizing Deep Q-Networks and System Partitions

Intrusion Response is a relatively new field of research. Recent approaches for the creation of Intrusion Response Systems (IRSs) use Reinforcement Learning (RL) as a primary technique for the optimal or near-optimal selection of the proper countermeasure to take in order to stop or mitigate an ongoing attack. However, most of them do not consider the fact that systems can change over time or, in other words, that systems exhibit a non-stationary behavior. Furthermore, stateful approaches, such as those based on RL, suffer the curse of dimensionality, due to a state space growing exponentially with the size of the protected system. In this paper, we introduce and develop an IRS software prototype, named irs-partition. It leverages the partitioning of the protected system and Deep Q-Networks to address the curse of dimensionality by supporting a multi-agent formulation. Furthermore, it exploits transfer learning to follow the evolution of non-stationary systems.


Motivation and significance
Intrusion Detection Systems (IDSs) are widely used to detect threats to computer systems. However, they are just one of the two parts of an automatic self-protecting system, as shown in Figure 1. Indeed, while IDSs are fundamental to identify ongoing threats, they generally offer trivial response capabilities, usually based on a static mapping between the attack that has been identified and a response (e.g., Snort [1]). Unfortunately, such an approach exhibits evident limitations, such as, scalability [2] and lack of generalizability [3]. For this reason, in the last decade, research on Intrusion Response Systems (IRSs) started to gain traction. The purpose of an IRS is to automatically identify the proper response to an ongoing attack, usually exploiting additional knowledge of the behavior of the attacker and of the protected system. We conducted an investigation of existing IRSs where software implementations or system design is publicly available to study how they operate on a modern com-puter system (e.g., [4,5,6,1,7,8,9,10]). We found that all of them assume that the behavior and the topology of the protected system does not change over time or, in other words, that the protected system is stationary. Indeed, most IRSs (e.g., [4,8,9,10]) use either a rule-based static configuration or a combination of static attacker and system models (e.g., [11,12]) to formulate a set of responses for the entire system. However, modern systems exhibit a non-stationary behavior, and therefore need the ability to automatically adapt to changes while dynamically predicting a near optimal response to an intrusion. Furthermore, when sophisticated techniques are employed, such as, those that make use of state information of the protected system or of the attacker, the IRS has to deal with the problem known as curse of dimensionality, given by the exponential relationship between the size of the system (or of the attacker) model and the resulting state space.
For this reason, in this work we describe as our main contribution an opensource licensed software prototype that implements an IRS, named irs-partition, which builds upon the methodology introduced in [3]. It uses Deep Q-Learning [13], Reinforcement Learning (RL) [14], and transfer learning [15] to cope with the nonstationary behavior of computer systems. To address the curse of dimensionality, its formulation supports the partitioning of the system model, therefore enabling the usage of different local modeling techniques and solvers, e.g., approaches based on Markov Decision Processes, such as, Deep Q-Learning [13] and Dynamic Programming [14], or other types of optimization, such as, Linear or Integer Programming. To the best of our knowledge, our IRS software implementation is the first to be released with an Apache 2.0 license.
The rest of the paper is organized as follows: we describe the system model and the design of its software implementation in Section 2. Then, we showcase the functionalities of the developed software with a use-case based on the open-source Google's Online Boutique application [16] in Section 3. Finally, we discuss the impact of the software followed by conclusions and future works in Section 4 and Section 5, respectively.

System model and IRS design
We developed and published under the Apache 2.0 license an IRS prototype, named irs-partition. Even though the software is flexible enough to support different optimization techniques for different system partitions, at the current stage of development we introduced the support for a single solver, based on Deep Q-Learning. The latter uses a training environment to train agents that are defined on a per-partition basis. Each agent works toward the overall system goal of keeping the system secure by predicting the near-optimal action for its partition using a customizable Deep Q-Learning neural network.
Software dependencies of the application include Eclipse Deeplearning4J (DL4J) [17], and Reinforcement Learning for Java (RL4J) [18]. Both are Java implementations of deep neural network algorithms and the RL framework.

System model
In this section we introduce the system model and its notation. The latter is summarized in Table 2.

Symbol Meaning i
A component type p i A partition corresponding to the i-th component type i j The j-th component of the i-th component type The j-th component of the i-th type of the i-th partition S The computer system model V The set of state variables of system S v i The set of state variables of component type i v i j T The state of the j-th component of type i at time T p i T The i-th partition state at time T S T The state of system S at time T Σ The state space A The set of actions available to system S A i The set of valid actions for the i-th component type The execution time for action a i C(a i ) The cost for taking action a i R(·) The reward function τ The termination function τ i The termination function for partition i Table 2: Main notation used in this paper.
A system contains components of different types. Each component type can be defined at a different granularity level, as deemed necessary. Examples of component types are hardware devices, virtual appliances, software modules, web servers, application servers, database servers, network switches, load balancers, and container images. We define a component as an instance of component type. Furthermore, we define the concept of partition as the set of all the components of a given type i, i.e., p i = ∪ m j=1 i j , where i j represents component j of type i, and m is the total number of components of type i. The system S is the set of all the partitions, that is, S = {p 1 , p 2 , . . . , p n }, where n is the total number of partitions. In addition, given any two partitions p a , p b ∈ S, they do not share any component, that is, ∀a.∀b.a = b → p a ∩ p b = ∅. In other words, partitions are disjoint. This restriction, which has been introduced to simplify the development of the prototype, has important implications: on one hand, it eases the design, development and run-time administration of the proposed prototype. On the other hand, it could not fully capture the dynamics of a complex system, if components belonging to different partitions have some interaction. As a consequence, given the current formulation, the near-optimality of the response is guaranteed only if components belonging to different partitions do not have any interaction. This limitation will be addressed in a future release of the software prototype.

System state
We define a set of boolean state variables defines a specific characteristic of component type i and q is the total number of variables used to model the state for such component type. For example, following the case study scenario we will describe in Section 3, the variable corrupted i is applied to all the components of type i, and its instances represent whether or not each component of type i has been compromised. The set of the variable values of all the components of a given partition i at a given discrete time T represents the partition state, that is, Similarly, the system state is represented by the set of the states of its component partitions, that is, where Σ represents the state space.

System actions
We define a set of actions which, when executed on a given component i j , change the state of its corresponding partition p i , and hence the system state. Each component type i of the system has its set of valid actions, i.e., A i = {a 1 , a 2 , . . . , a r }, where r is the total number of actions executable on component type i. Furthermore, by design, we have that ∀j.A i = A i j . Hence, the set of actions available to the entire system is the union of all of the actions defined for each component type, i.e., A = ∪ n i=1 A i . Furthermore, each action is associated with a pre-condition and a post-condition. The former, P re(S T , a i j ), where a i j ∈ A i j , determines if action a i j can be executed on component j of partition i when the system is in state S T . The latter modifies the partition state, taking it from p i T to p i T +1 , and thus from S T to S T +1 .

Reward and termination functions
For each action a i ∈ A i , we define its execution time, E(a i ), and cost, C(a i ), as two criteria of a reward function. The latter returns the immediate reward obtained by a reinforcement learning agent upon its execution, and it is defined as: where E max and C max are respectively the maximum execution time and the maximum cost; w E , w C ∈ [0, 1] are the corresponding optimization weights. R(p i T , a i , p i T +1 ) returns a high penalty score of −2 if an action, a i , cannot be run because the preconditions are not met. This specific formulation is a technical requirement of the Deep Q-Learning solver implementation of the DL4J library.
Finally, the termination function is used to identify the set of states in which the system is considered secure. We define a per-partition termination function as τ i : p i T → {true, f alse}, and a system-level termination function as τ = n i=1 τ i (p i T ).

Software design
We implement the system model S, system state variables V , actions A, partition state p i T , reward function R, termination function τ , and partition termination function τ i respectively, in the SystemEnvironment (SE), SystemState, SystemAction, SystemPartitionEnvironment (PSE), SystemRewardFunction, SystemTer-minateFunction, and PartitionSystemTerminateFunction (PSTF) classes. We decompose the system model S into multiple partitions, where each partition stores only its own state variables and actions in SystemPartitionEnvironment, which is a subclass of SystemEnvironment. All the partitions are then stored in the List<PartitionSystemEnvironment> list. We use PartitionCreatorUtility (PCU) to decompose the SystemEnvironment to multiple PartitionSystemEnvironment based on component type i, as shown in Fig. 2, which represents the class diagram of the main classes of the software. The references to the full system state variables The execution of our software starts with the main function of PartitionDQN-Main, where we create the system model (S) in SystemEnvironment from the .yml configuration files, store the system state (S T ) in MasterMDPHolder, decompose S into partitions, store each partition in SystemPartitionEnvironment, and create one DNN for each partition as shown in the sequence diagram of Fig. 3.
We train one agent on each partition p i . Each agent is responsible for providing the local near-optimal next action, according to the current partition state. Given the formulation of the system model as a set of disjoint partitions, the set of predicted optimal local actions leads to a global optimum. We use Deep Q-Learning with Monte Carlo simulation to train the agents. We utilize QLearningDiscret-eDense [18] for Deep Q-Learning with configurable parameters. The simulation begins with an initial system state configured in SystemState by the system administrator. Then, based on the initial state, a set of actions, ActionSet, (at most one for each partition) is executed on the environment, represented by Partition-SystemEnvironment, which returns a set of rewards (from SystemRewardFunction) and the next system state. Such actions are chosen by the agent by either exploiting the acquired knowledge, and therefore trying to maximize the expected discounted reward, or by exploring actions whose outcome, in terms of reward and transition, are still unknown. The latter case occurs with probability = 0.01 during the first epoch, and the parameter is gradually reduced to 0 after 1500 epochs. We store the state S T , the action a T +1 , and the reward R(S T , a, S T +1 ) in the memory called experience. We configured the maximum size of experience to 5000 in a parameter expRepMaxSize. Finally, the epoch continues until it either terminates when the environment reaches a secure state (as determined by the partition termination function, PartitionSystemTerminateFunction) or when it reaches its maximum length (as configured in maxStep.) After storing a batch (configured as 128 in batchSize parameter) of experiences, we train multiple DNNs, one (implemented in NNBuilder with parameters layers, hiddenSize, and learningRate) for each partition, p i , with episodes drawn from the memory using the experience replay technique. We run many batches of episodes to retrain the DNNs to increase accuracy in the prediction of the action.

Case study: Online Boutique
A proper validation and comparison of different IRS techniques is usually undermined by the lack of a standardized cyber-range [19]. For this reason, and in order to improve the reproducibility of our scenario and results, we illustrate the functionalities of our IRS software using a use-case scenario based on the open-source Online Boutique (OB) 2.0 system [16]. OB is a web application used by Google to showcase cloud-enabling technologies like Kubernetes/GKE, Istio, Stackdriver, gRPC, and OpenCensus [20]. It is a cloud-native application based on the microservice architectural style and is composed of 11 services, written in different languages that communicate over gRPC, plus a workload generator. It implements an online shop where users can browse items, add them to the cart, and purchase them. Fig. 4 shows the OB system architecture, along with a representation of a possible partitioning scheme, according to the definition of partition introduced in Section 2.1. There are 11 partitions, one for each service. For the sake of simplicity and without loss of generality, we report experimental results showing the time needed to converge to a near-optimal solution of a scenario in which a sub-system with 2 partitions is considered. We used a machine of type c220g2 from CloudLab [21] to run our experiments. We used the following JVM parameters: -Xms102400m -Xmx102400m -XX:MaxMetaspaceSize=40960m. For space reasons, we do not report experimental results on the reaction to system changes. However, the interested reader can find a detailed analysis in [3].
We now describe the system model of the case study and analyze the experiments.

Case study system model
The system administrator describes the system model containing the partition information in the topology-containers.yml configuration file. Listing 1 shows an example configuration of the frontend-service partition, where the number of components in the partition is represented by the parameter replication, and its state variables are listed in the state section. This specific configuration instance shows that the component type has the following 5 state variables: start, active, restarted, corrupted, shellCorrupted.
For space reasons, we only list the configuration of one component type. However, we list in Table 3 all the state variables (and their corresponding meaning) that we used to model the OB system.

State variable
Meaning start If true, the container has started active If true, the container is running corrupted If true, the container is under attacker control restarted If true, the container has been restarted after the agent requested to do so shellCorrupted If true, the attacker has overwritten the shell /bin/sh in the container cartCorrupted If true, the content of Redis data store has been altered by the attacker confVuln If true, the current configuration of Redis data store is vulnerable to potential attacks and is subject to loss of confidentiality intVuln If true, the current configuration of Redis data store is vulnerable to potential attacks and is subject to loss of integrity passwordRequired If true, it mandates a password before accepting a command on Redis data store dangerousCmdEnabled If true, dangerous commands, such as flushall, that can potentially compromise the Redis data store, are enabled. accessRestricted If true, it only permits access from permitted sources, such as cart-service, to the Redis data store. The administrator also defines a set of actions and provides the following parameters for each action: the reward parameters (execution time and cost), the pre-condition and the post-condition in the action-set-containers.yml configuration file. Listing 2 shows the configuration of the action start, consisting of: its reward parameters (execution-time and execution-cost); the component types (frontend-service and redis-service) whose components can choose start as one of the action under the components section; the pre-and post-conditions under their respective sections. Table 4 defines all the actions along with their precondition, post-conditions, execution time and cost, that we modeled for the protection of the OB system.
We use a total of 16 state variables and decompose the system state as shown in Fig. 5. Furthermore, we implement PartitionSystemTerminateFunction.-  Table 5. In addition, the input to each DQN is the set of the state variable values of the its corresponding partition, and the output is one action from the set of valid actions.

Case study experiments
We ran experiments to gather cumulative rewards in training the DQNs for the entire system and the front-end partition. As expected, the training time to converge to near-optimal cumulative reward of the front-end partition, 173 sec, is smaller than that of the system, 220 sec. We calculated the optimal cumulative reward using VIMain and PartitionVIMain, which invoke the Value Iteration implementation of RL4J. Fig. 6a and 6b respectively show the cumulative reward obtained according to the time spent on training for both, the single front-end partition and the system.

Impact
The irs-partition system described in this paper further advances the state of the art in IRS software. We take a significant step forward in creating self-protecting systems that support non-stationary behavior, allow complex system partitioning, and near-optimal mitigation of local threats using multiple model types, including DQNs with customizable hyper-parameters. Our IRS software implementation with these capabilities is also the first to be released with an Apache 2.0 license.
Our software uses a training environment with a simulated system to train the IRS agents. Thus, it makes it possible to pre-train agents in a training environment and deploy them in a live environment. We train each agent with a dedicated deep neural network, where each network can be customized to a different architecture with its own set of hyperparameters. In addition, each agent could configure different types of modeling approaches, including DQNs, which we have used in our prototype.

Conclusions
Cyber threats are still evolving, and the security industry needs systems that can both, detect and respond, automatically. This need requires further investigation on automatic self-protecting systems, which can help secure real-world systems exhibiting non-stationary behavior. In this paper, we demonstrated a software tool to train multiple agents in a training environment using customizable deep neural networks to build an IRS, named irs-partition. We focused on leveraging multiple deep neural networks that predict a set of optimal actions. Moreover, the pre-trained agents immediately enhance system security using the transfer learning technique from their experience gained in a simulated system. In the future, we plan to monitor the impact and quality of the predictions, and to provide a mechanism to self-tune the deep neural networks.

Conflict of Interest
We declare no conflict of interests.