# An Adversarial DBN-LSTM Method for Detecting and Defending against DDoS Attacks in SDN Environments
## 3 Proposed System
### Adversarial DBN-LSTM Anomaly Detection  
In this module, we will judge whether the IP flow record is abnormal according to its features by sending it into the adversarial DBN-LSTM model. Firstly, we propose an effective method to produce many normal, DDoS, and adversarial DDoS samples by the GAN model. Then, the Classifier model will be trained by the above samples. DBN and LSTM construct the Classifier model. In the following, we briefly introduce the training process based on the GAN and Classifier models used in this work. The whole training process is shown in Figure 3.  
The GAN model mainly includes the generator (G) and discriminator (D) models. The G model needs to learn the original data distribution to generate untruth data to fake the D model. The discriminator needs to judge whether the received data are true or untrue. The generated samples come from the G model by random noise in this paper. Furthermore, some of the data in the original dataset receive disturbance to generate adversarial samples. The generated samples and adversarial samples will be sent to the D model. Moreover, the D model determines the probability that the samples belong to the adversarial samples. This competition is equivalent to a minima x two-player game. The generator and discriminator are constantly competing. Finally, the G model and D model will reach a dynamic equilibrium. The structure of the D model is the same as the G model. However, they have different objective functions and stochastic gradients. For the D model, its objective function and stochastic gradients are presented as follows:  
\[MaxE_{x\sim P_{data}}[logD(x)]+E_{y\sim P_{G}}[\log(1-D(y))]\]  
For the G model, its objective function and stochastic gradients are presented as follows:  
\[min\;MaxE_{x\sim P_{data}}[logD(x)]+E_{y\sim P_{G}}[\log(1-D(y))]\]  
\[\
abla_{\theta_{G}}\frac{1}{m+1}\sum_{i=1}^{m+1}\left[\log\Bigl{(}1-D\Bigl{(}y ^{i}\Bigr{)}\Bigr{)}\right]\]  
Figure 3: Adversarial DBN-LSTM training structure. \(x\sim P_{data}\) is the data from the original distribution, \(x^{i}\) is the No. \(i\) IP flow record, \(D(x)\) is the probability of the original adversarial data, \(y\sim P_{G}\) is the data from the generated distribution by G, and \(D(y)\) is the probability of generated data. In particular, we obtained the initial \(y\sim P_{G}\) based on the perturbation of \(x\sim P_{data}\), which is based on the FGSM algorithm, as follows:  
\[W^{T}.y_{1}^{i}=W^{T}.x^{i}+W^{T}.\epsilon(\Delta J_{X}(x,x^{\sim},\theta))\]  
The GAN model training steps are continuously implemented until the D model cannot identify the generated samples from the G model or reach t iterations training. The whole process is as Algorithm 1. ```
0: the G model; the D model; the Training dataset
1: Initialize \(\theta_{D}\) and \(\theta_{G}\)
2:while t iterations training or stop condition not met do
3:for\(d_{epoch}\)do
4: Sample \(\left\{x^{1},x^{2},\ldots,x^{m+1}\right\}\) from \(P_{data}\)
5: Sample \(\left\{y_{1}^{1},y_{1}^{2},\ldots,y_{1}^{m+1}\right\}\) from \(P_{G}\)
6: Generates \(z^{i}=G\left(y^{i}\right)\) by G
7: Calculate \(\theta_{D}=\theta_{D}-\eta\
abla_{\theta_{D}}\frac{1}{m+1}\sum_{i=1}^{m+1} \left[logD\left(x^{i}\right)+log\left(1-D\left(z^{i}\right)\right)\right]\)
8:endfor
9: Sample \(\left\{y_{2}^{1},y_{2}^{1},\ldots,y_{2}^{m+1}\right\}\) from \(P_{G}\)
10: Calculate \(\theta_{G}=\theta_{G}-\eta\
abla_{\theta_{G}}\frac{1}{m+1}\sum_{i=1}^{m+1} \left[logD\left(x^{i}\right)+log\left(1-D\left(y_{2}^{i}\right)\right)\right]\)
11:endwhile
12:
13:return G and D
```  
**Algorithm 1** The GAN model training steps  
After reaching a dynamic equilibrium, the G model generates many samples, which are used to fool the Classifier model, to construct an adversarial dataset. Then, the Classifier model randomly extracts \(n\) samples from the adversarial dataset and \(m\) samples from the training dataset. After aggregating into a complete set, these samples will be extracted features by the Classifier model.