{'fraction_non_alphanumeric': 0.030213584505173786, 'fraction_numerical': 0.0072631997877421065, 'mean_word_length': 4.877777777777778, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
DeepMAL -- Deep Learning Models for Malware Traffic Detection and Classification

Robust network security systems are essential to prevent and mitigate the harming effects of the ever-growing occurrence of network attacks. In recent years, machine learning-based systems have gain popularity for network security applications, usually considering the application of shallow models, which rely on the careful engineering of expert, handcrafted input features. The main limitation of this approach is that handcrafted features can fail to perform well under different scenarios and types of attacks. Deep Learning (DL) models can solve this limitation using their ability to learn feature representations from raw, non-processed data. In this paper we explore the power of DL models on the specific problem of detection and classification of malware network traffic. As a major advantage with respect to the state of the art, we consider raw measurements coming directly from the stream of monitored bytes as input to the proposed models, and evaluate different raw-traffic feature representations, including packet and flow-level ones. We introduce DeepMAL, a DL model which is able to capture the underlying statistics of malicious traffic, without any sort of expert handcrafted features. Using publicly available traffic traces containing different families of malware traffic, we show that DeepMAL can detect and classify malware flows with high accuracy, outperforming traditional, shallow-like models.


I. INTRODUCTION
The popularity of Artificial Intelligence (AI) -and of Machine Learning (ML) as an approach to AI, has dramatically increased in the last few years due to its outstanding performance in various domains, notably in image, audio, and natural language processing, and more recently in gaming. A major breakthrough in AI/ML has been the successful application of Deep Learning (DL) models and techniques to traditional ML tasks. One of the most powerful characteristics of DL models is their ability to learn feature representations from input raw or basic, non-processed data. For example, a Convolutional Neural Network (CNN) trained for image classification can learn to recognize edges and more complex structures along the sequence of neural layers, using as input only the image pixel values [1]. The key behind DL is the so-called representation learning paradigm [2], which offers a set of methods allowing a ML algorithm to automatically discover the best data representations or features from raw data inputs. DL models are basically representation learning methods with multiple levels of abstraction, obtained by composing simple but non-linear consecutive transformation layers, each of them providing a more abstract representation of the data.
Despite the success of DL models, shallow ML models are usually applied when it comes to the analysis of network traffic measurements. Shallow ML models rely on the definition of highly specialized, expert-handcrafted features to achieve proper results, and this is actually critical for shallow ML. There are different problems when addressing network traffic measurements tasks using shallow ML approaches. First, the lack of a consensual labeled raw traffic, full-packet capture dataset to train ML models (e.g. due to privacy policies in the data); second, the lack of a consensual set of input features to tackle specific targets, such as network security, anomaly detection, traffic classification, etc.; third, the continuous changing in network measurements statistics that may cause static handcrafted features to fail. To improve these limitations, we explore the end-to-end application of DL models to complement traditional approaches for network measurement analysis, using different representations of the input data. We introduce DeepMAL, a DL model capable to detect and classify malware network traffic using raw, bytestream-based data as input. We describe and evaluate different DL architectures and different input representations, showing an outstanding detection performance through the analysis of raw bytestream packet data.
The rest of the paper is organized as follows: in Section II we present a brief state-of-the-art on DL models applied to the analysis of network traffic measurements; in Section III we present and provide details on the different DL approaches and architectures behind DeepMAL; in Section IV we discuss the detection performance achieved by different versions of DeepMAL, comparing them with traditional, shallow-like based models, using domain expert knowledge to craft the input features; in Section V we introduce a variation of the detection problem using a multi-class, malware classification approach, and present concluding remarks in Section VI.

II. STATE-OF-THE-ART
The application of shallow, ML models to general network measurement problems is largely extended in the literature. There are a couple of extensive surveys and papers on network measurement problems such as network anomaly detection [6] [5] -including ML-based approaches [4], ML for network traffic classification [8] and network security [7]. A recent survey on ML for networking is presented in [3], discussing different applications and associated challenges.
DL approaches have started to be used recently with promising performance results, mainly associated to traffic classification tasks. In 2015, Z. Wang et al. [20] presented a Deep Neural Network for feature learning using feed-forward networks and Stacked Auto-Encoders (SAE) to perform network protocol recognition over a dataset made up of TCP flows from an internal network. In 2017 there have been some works over the subject. W. Wang et al. presented two models based upon a 2D-CNN [19] and 1D-CNN [17], in which the authors transform network flows and sessions to imagesas done by [25], to work as an input for the CNN models, using either the information of all the layers, or only from the application layer. A similar image-based approach to traffic classification was recently introduced in [18]. Lotfollahi et al. [12] presented an approach for encrypted traffic classification using SAE and 1D-CNN at the packet level. M. Lopez-Martin et al. [11] presented different DL architectures based on CNN and LSTM networks to perform traffic classification using self-collected network traces. Additional papers based on DL architectures for traffic classification cover the classification of mobile networks encrypted traffic [21], [23] and the classification of general network traffic [25], [29].
When it comes to intrusion and anomaly detection, there are also many recent papers applying DL architectures. Radford et al. [15] presented an anomaly detection model using a LSTM network from network traffic logs for cybersecurity. Papers such as [24], [26] rely on the application of CNNs to capture the underlying spatial correlations of the analyzed data for intrusion detection, using already preprocessed input features -e.g., [24], [26] use the well-known KDD features and dataset. In [27], J. Cui et al. proposed a word embedding-based approach to pre-analyze the raw traffic data for network intrusion detection. H. Huang et al. apply a multi-task learning approach to detect intrusions and anomalies, using again CNNs. W. Wang et al. [22] propose a hierarchical learning approach to construct spatio-temporal features, combining spatial feature learning through CNNs and temporal feature learning through recursive networks. Finally, [13], [14] introduces RawPower, a DL architecture for network anomaly and intrusion detection, which combines spatio and temporal feature learning for detection. Most of these proposals use DL models after some sort of preprocessing of the data, or based on the definition of handcrafted features to generate DL model inputs.
The main contribution of our approach is that of using completely expert-knowledge-independent inputs for both the prediction and classification tasks -just the raw bytestream, opening the door to a broad set of potential applications of DL in networking problems. Additional contributions include: (i) the benchmarking of DeepMAL against shallow-like learning models commonly used in the literature; (ii) addressing not (a) Packet representation for the input data. The shape of the input data is (N, n): N is the number of packets and n the number of bytes.
n bytes m p a c k e t s  only the problem of binary malware detection, but also the classification of the specific class of malware detected; (iii) the evaluation of DeepMAL on multiple different network traffic datasets, publicly available from the well-known Stratosphere IPS Project of the CTU University of Prague in Czech Republic [10].

III. DL FOR MALWARE DETECTION
Our goal is to train a DL model with the stream of incoming bytes without requiring any preprocessing step or domain expert intervention, to make the approach generic and flexible. As we said before, we particularly focus on the problem of malware traffic detection and classification, using raw, bytestream-based data as input. The input representation of the data, as well as the network architecture, are both key elements to consider when building a DL model. Since we want to evaluate the feature representation power of the model from non-processed data, we consider two types of raw representations: packets and flows. In both cases we consider decimal normalized representation of every byte of every packet as a different feature. Since different packets can have different sizes, we set a fixed threshold n to trim each incoming packet to the first n bytes, after removing potentially biasing byte information such as MAC and IP addresses. All packets with size larger than n bytes are trimmed, and packets with smaller size are zero-padded. Next we describe basic concepts behind DeepMAL's architecture, and present the two raw representations based on packets and flows, along with the corresponding network architectures.

A. DL Architecture Basics
Finding the right DL architecture for a specific classification task is challenging. In general, one would like to capture different spatial and temporal correlations and phenomena hidden within the specific input data. To capture both types of correlations and learn spatio-temporal features, the proposed DL architectures consider both convolutional and recurrent neural networks as core layers. The convolutional layer(s) are included to build the feature representation of the spatial data inside packets and flows. The recurrent layers are used together with the convolutional ones to improve detection and classification performance, allowing the model to keep track of temporal information. We additionally consider fullyconnected neural layers to deal with the different combi-  Besides these core layers, we also include what we refer-to as helper layers, which goal is to reduce the generalization error and to improve the learning process, reducing over-fitting issues. As helper layers, we consider batch normalization and dropout layers. Batch normalization is used to normalize layer inputs for each mini-batch during training; as a result, higher learning rates can be used, the resulting model is less sensitive to initialization, and it additionally contributes to the regularization of the model. The dropout layers are also used to regularize the model, by doing the so-called model averaging; dropout consists of randomly dropping unitsalong with their connections, from the neural network during training. In a nutshell, dropout is a very efficient way to perform model averaging, as it is similar to train a huge number of different networks and average the results.

··· ···
Next, we use different combinations of these core and helper layers to build the proposed architectures. In all cases, we tried different combinations and network sizes, and keep those combinations that provided the best empirical results. A deeper and more structured analysis of the interplays among these different layers is part of our ongoing work.

B. Input Representations
In the packet approach, we consider each packet as a different instance, while in the flow approach we consider a group of packets -that make up the flow -as an input for the network. Both representations are depicted in Fig. 1.
For the Raw Packet representation, we have to choose the number of bytes from the packet to consider (n), while in the flow representation we also have to set the number of packets per flow to consider (m). This is because, naturally, different packets and flows can have different sizes.
Since both malware and normal captures are gathered under controlled conditions, there is some bias in the IP and transport protocol headers that are not representative of in the wild traffic. This is the case, for example, of fixed values for IP addresses and ports and even some of the transport protocol flags. For this reason, we take the payload of every packet as the key information to analyze and to build the dataset. Afterwards, we set a fixed threshold for the parameter n to trim each incoming packet to the first n bytes of payload. All packets with size larger than n bytes are trimmed, and packets with smaller size are zero-padded at the end. For the number of packets per flow, we fix a number m and take the first m packets of the flow, discarding the rest.

C. DeepMAL using Raw Packets
The architecture of DeepMAL for the Raw Packets input representation is shown in Fig. 2. It consists of two 1D-CNN convolutional layers of 32 and 64 filters of size 5, respectively; a max-pooling layer of size 8 to down-sample the input; a well-known LSTM as recursive layer, consisting of 200 units, returning the outputs of each cell ("return sequences" mode on); and finally, two fully-connected (FC) layers of 200 units each. A binary cross-entropy is used as the loss function. Spatial and normal batch normalization layers are added after each 1D-CNN and FC layers to ease the training process. Dropout layers are also used to add regularization to the model.

D. DeepMAL using Raw Flows
When deciding on the network architecture for the Raw Flows approach, we note that the number of instances to deal with when operating at the flow level is by far much smaller than in the case of packet-based inputs; as a consequence, the capacity of the model does not have to be as high as in the Raw Packets case. For this reason, we only include convolutional layers in this architecture. The final architecture  in this case consists of one single 1D-CNN layer of 32 filters of size 5 and two fully-connected layers of 50 and 100 units each. Also, binary cross-entropy is used as the loss function. The architecture is shown in Fig. 3.

IV. EXPERIMENTAL EVALUATIONS
We evaluate the different proposed DeepMAL architectures and input representations using real network measurements, publicly available though the Stratosphere IPS Project of the CTU University of Prague in Czech Republic [10]. In this section we focus exclusively on the problem of malware detection, posing it as a binary classification task: either normal instance or malware. To show the main advantages of DeepMAL, we pose ourselves three evaluation questions: (i) is it possible to achieve high detection accuracy with low false alarm rates using the raw-input, DL-based models?; (ii) are the proposed DL-based models better than the commonly used shallow models for malware detection, when feeding them all with raw inputs (e.g., byte-streams)?; and (iii) how good are the raw-input, DL-based models as compared to a traditional ML-based approach for malware detection, where shallow models take as input specific hand-crafted features based on domain expert knowledge?.

A. DeepMAL vs. Shallow Models with Raw Inputs
We begin with a simple evaluation scenario, detecting malware at the packet level. We take a first dataset previously used in the literature [19], referred to as the USTCTFC2016 dataset. This dataset consists of two groups of labeled pcap files from malware and benign applications. The malware files contain 10 types of malware traffic from public websites, collected from a real network environment by researchers of the Czech Technical University in Prague (CTU) [10]. The benign traffic contains 10 types of normal traffic which were collected using Ixia BreakingPoint (https://www.ixiacom.com), a network traffic simulation platform. We take every packet from each labeled pcap as part of the dataset, using decimal normalized representation of every byte as a different feature.
To set the number of bytes kept from each packets, we resort to a simple, data-driven analysis of the dataset. Fig. 4 depicts the distribution of the packets payload size for (a) all the normal or benign traffic samples, and (b) all the malware packets. As clearly observed, both distributions are rather similar for payload sizes below 750 bytes and above 1250 bytes, but markedly different between these two boundaries. We therefore decided to set n = 1024 bytes, which proved to be a reasonably good threshold to capture the difference between benign and malware activity. Each packet is finally labeled as either benign or malware, i.e., we consider a binary classification problem. The total dataset consists of one million samples (i.e., trimmed packets), half of them benign and half of them coming from the malware traces. We split the dataset on 80% of the samples for training, 10% for validation and 10% for testing purposes. We built the model using the Keras framework running on top of TensorFlow. Fig. 5 presents the initial results obtained by the Raw Packet DL model in the detection of malware packets, in the form of a ROC curve. The model is compared to a Random Forest (RF) model, using exactly the same input features and an internal architecture of 100 trees. We choose a RF model based on the generally outstanding detection performance shown by the model in previous work [9], using domain expert input features. DeepMAL can detect more than 70% of the malware packets with a false alarm rate below 3%, outperforming the RF model. Indeed, when applying the RF model with the same set of raw input features, the obtained results are very poor. These results point to the ability of the    DL-based model to better capture the underlying statistics of the malware, without requiring any specific handcrafted feature set. Still, the absolute detection performance is not good enough to rely on such a DL model with raw packet inputs for malware detection in the practice.

B. Packet vs. Flow Representation Performance
We take a step further an consider a similar comparison as before, but considering now both raw packet and raw flow representations as input. We take again publicly available datasets from CTU, but to test on different scenarios, we extend the mix of data by considering multiple pcap files. We   In Table I we show the parameters selection for each input representation. All of these parameters where selected again from a statistical analysis of the datasets. Different from the Raw Packet representation, we set n = 100 bytes for the Raw Flows scenario, and keep only the first 2 packets of each flow, i.e., m = 2. Note that such a small number of packets has been already proved to be efficient in discriminating among different types of applications when it comes to network traffic classification [16].
We built two different datasets to fit each one of the considered input representations. The dataset for the Raw Packet representation consists of roughly 250, 000 instances. For the Raw Flows representation, the dataset consists of about 68, 000 instances. Both datasets are split according to the same scheme as before: 80% of the samples for training, 10% for validation and 10% for testing.
The learning processes for both approaches is described in Fig. 6. In both cases we used mini-batches for the parameters update and we trained the models over several epochs (being an epoch a single pass-through over the complete training dataset). In the case of the Raw Packets representation, the training was held over 100 epochs, while in the case of Raw Flows we used 10 epochs. We used ADAM as the optimizer function, annealing the learning rate over time. The performance metric chosen in both cases was the accuracy, since the dataset is balanced. For the Raw Packets representation we achieved 77.6% of accuracy over the test set; while in the case of Raw Flows we achieved an accuracy of 98.6% also over the test set. Note that the learning process performs better when operating at the flow level, as there is some potential overfitting for this scenario using the packet-level representation. Fig. 7 compares the detection performance of both models against a RF model using exactly the same (raw) input features -in the Raw Flows case, we flatten the data to fit the input to the RF. In both cases, the internal architecture of the RF consisted of 100 trees using different pruning techniques to prevent over-fitting (e.g., maximum depth, maximum number of instances per leaf, etc.). Once again, we observe a clear out-performance of DeepMAL as compared  to the RF models, particularly when operating at the flow level. For Raw Packets representations, DeepMAL can detect about 65% of the malware traffic packets with a false alarm rate below 3%, with an overall out-performance of nearly 15% as compared to the RF. Note that in this evaluation, the differences in terms of performance are not as important as in Fig. 5. The main differences occur when operating with Raw Flows representations, where DeepMAL can detect all malware flows with a false alarm rate below 2.5%, and more than 90% of them with less than 0.5% of alarms. This suggests that, when operating at the flow level, such raw input representation and associated DL architecture can actually provide highly accurate results, applicable in the practice.
For additional benchmarking purposes, we compare the performance of the Raw Flows model against a broader set of shallow ML models, using in all cases the computed raw flows inputs for training and testing purposes. These additional models include decision-trees (CART), naïve bayes (NB) models, neural networks (MLP), k-nearest-neighbors (k-NN), and support vector machines (SVM). In all cases, we resort to grid-based search to calibrate model parameters. Results reveal a clear outperformance of DeepMAL as compared now to all the shallow models; indeed, shallow models using raw, non processed input features result in very poor performance.

C. Domain Knowledge vs. Raw Inputs
The last step of the evaluations tries to answer the third question regarding the goodness and advantages of the proposed approach w.r.t. the standard approach for machinelearning based malware detection. In particular, we study how good is the raw-flows, DL-based model as compared to a RFbased model, the latter using as input specific hand-crafted features based on domain expert knowledge.
The standard approach for detection of malware and network attacks in network traffic is to rely on flow-level fea-  tures, using traditional in-flow packet measurements such as traffic throughput, packet sizes, inter-arrival times, frequency of IP addresses and ports, transport protocols and shares of specific flags (e.g., SYN packets), etc. We therefore build a set of almost 200 of these features to feed a RF model. Note that besides using traditional features such as min/avg/max values of some of the input measurements, we also consider their empirical distribution, sampling the empirical distribution at many different percentiles. This provides as input much richer information, as the complete distribution is taken into account. We take the same dataset used in Sec. IV-B for training and testing purposes. Fig. 9 reports the results obtained in this scenario. Not surprisingly, the RF using expert domain features achieves highly accurate detection performance, detecting about 97% of all the malware flows with less than 1% of false alarms. However, also in this scenario, DeepMAL slightly outperforms this domain expert knowledge based detector. As such, we can conclude that the proposed DL architecture can perform as good as a more traditional shallow-model based detector for detection of malware flows, without requiring any sort of expert handcrafted inputs. This of course, shows the great contribution of DeepMAL.
Based on the three sets of evaluations, we can conclude that the proposed DL model, in particular when using raw flow representations as input, can: (i) provide highly accurate and applicable-in-the-practice malware detection results, (ii) capture the underlying malware and normal traffic models better than traditionally used, shallow-like models, and (iii) provide results as good as those obtained through a domain expert knowledge-based detector, without requiring any sort of hand-crafted features.

V. FROM MALWARE DETECTION TO CLASSIFICATION
To complement previous malware detection results, in this section we present a variation of the binary classification problem, considering now different sorts of malware traffic as different classes, together with a "normal" class representing benign traffic. In the CTU dataset, each capture represents a different scenario, in which different sorts of malware were executed using several protocols (e.g., IRC, HTTP, P2P, etc.) and porting different types of attacks (e.g., DDoS, port scan, click fraud, spam, etc.).
To build the dataset we considered three different malware traffic classes, corresponding to three different types  of botnets, named Neris, Rbot, and Virut. Thus, our multiclass classification problem has four different classes: three representing malware attacks and one that represents normal activity. The activity and protocols used in the scenarios selected to build our dataset are reported in Table II. The dataset consists of 160, 000 samples, built in a stratified way, i.e., the dataset is balanced with 40, 000 samples per class.
For this classification task, we rely on the Raw Packets representation. We do so to avoid reducing the dataset, as we need more samples to avoid over-fitting when dealing with multi-class problems. The DL model used for this task is therefore quite similar to the one used for the Raw Packets binary scenario. The difference is that now the activation function used in the last fully connected layer is a Softmax function -a generalization of the binary logistic regression classifier for multiple classes, instead of the sigmoid used for the binary classification. The corresponding loss function is also different for the multi-class classification problem. In this case we used a categorical cross-entropy, and the learning process was held over 50 epochs. The evolution of the learning process, including loss and accuracy after each epoch, is very similar to the previous raw packets-based model (cf. Fig. 6a), as both operate using a similar input representation.
We also compare the performance of DeepMAL against a RF, using the same input features. In Fig. 10 we show the normalized confusion matrices for both models -note that values are shown in percentages; the DL model clearly outperforms the RF for all classes. As a sanity check, note that the accuracy of the multi-class problem considering a binary approach (malware vs. normal) holds similar results as the Raw Packets approach presented in Sec. IV-B (77.6% vs. 76.5%). To complement, in Table III we show additional performance metrics for DeepMAL, including accuracy (AC), precision (PR), recall (RC) and F 1 score for each class. Values are computed in a one-vs-all schema, in which each class is evaluated against the rest. It is interesting to note that Rbot botnet is detected with an accuracy of 99.9%, while Neris and Virut achieve 63.5% and 54.7% each. It is likely that the fact that both Neris and Virut share spam as an activity attack, could actually be the root-cause behind the bad performance to distinguish one from each other -see Table II. Interesting is the fact that again, DeepMAL clearly outperforms the RF model, for all variations of malware. As a general conclusion of the multi-class problem, we observe that the raw packets  representation does not provide discriminative enough input for the proposed DL architecture to realize properly classification results, but it still outperforms the benchmark RF model. As part of our ongoing efforts, we are working on both testing the multi-class problem using Raw Flows representations, as well as on improving classification performance for the raw packets input.
VI. CONCLUSIONS In this paper we have presented two different approaches using DL for the detection of malware network traffic, considering raw representations of the input network data. Different from traditional, shallow-based approaches, our models operate with raw, byte stream inputs, without requiring any type of handcrafted, expert domain knowledgebased input features or feature engineering, providing an extremely powerful approach. We proposed two different DL architectures, relying on a combination of convolutional and recurrent neural network layers, capable to learn spatiotemporal features out of the raw inputs. Our results show that using Raw Flows as input for the DL models achieves much better results than using Raw Packets, achieving detection performance which is comparable -or even better, than the obtained by expert-domain knowledge. We also presented a variation of the binary classification model using a multiclass approach to discriminate between different types of malware. In all cases, DL models outperform a strong RF model used as benchmark, as well as other popular shallowlike ML models commonly used in the network security literature, using exactly the same raw input features. This demonstrates the power of the proposed DL architectures and data representations to better capture the underlying statistics of malicious traffic, as compared to more traditional, shallowlike models.