Enhanced BiLSTM with multi-head attention for malicious network traffic detection scheme
Received date: 2025-09-27
Revised date: 2025-10-30
Online published: 2026-05-13
Copyright
In the realm of cybersecurity, accurately detecting malicious network traffic, particularly when it manifests in unknown forms, remains a significant challenge. To address this, we propose a novel detection framework that combines bidirectional long short-term memory (BiLSTM) networks with a multi-head attention mechanism, named as MA-BiLSTM. This integration leverages the inherent strengths of BiLSTM for capturing long-term dependencies in data sequences, while the multi-head attention mechanism enhances the model’s ability to focus on salient features crucial for the accurate identification and classification of unknown malicious traffic. Our approach is distinguished by its robustness in handling dynamic and complex attack vectors that traditional single deep learning models often fail to recognize. Comprehensive experiments conducted on various datasets reveal that our method not only achieves superior detection accuracy but also demonstrates enhanced efficiency in identifying unknown traffic types compared to existing deep learning solutions. Furthermore, we introduce a nuanced multi-dimensional feature analysis technique that employs the attention mechanism for fine-grained feature weight allocation, significantly augmenting the model's adaptability and performance in real-world network conditions. Validation in real-world network environments confirms the practicality and effectiveness of the MA-BiLSTM model, making it a promising tool for enhancing cybersecurity defenses against advanced network threats.
Wu Hongbin , Zhao Yufei , Zhao Qi , Wang Yuman , Chen Kai . Enhanced BiLSTM with multi-head attention for malicious network traffic detection scheme[J]. Journal of Cybersecurity, 2026 , 4(1) : 23 -33 . DOI: 10.20172/j.issn.2097-3136.251016
表 1 特征和说明Table 1 Features and descriptions |
| 特征 | 说明 |
| port_src | 源端口号 |
| port_dst | 目的端口号 |
| IAT | 包到达时间间隔,指两个连续数据包之间的到达时间差,即当前数据包与前一数据包到达时间差值, 对于网络流量中的第一个数据包,该值为0 |
| IAT_min | 前 8 个数据包的最小 IAT |
| IAT_max | 前 8 个数据包的最大 IAT |
| IAT_med | 前 8 个数据包的 IAT 中位数 |
| IAT_total | 前 8 个数据包的 IAT 的和 |
| ethernet_len | 以太网帧长度 |
| IP_len | IP 数据包长度 |
| IP_ttl | IP 数据包 TTL |
| tcph_len | TCP 首部长度 |
| tcp_data_len | TCP 载荷长度 |
| ack_pkts | ACK 数据包,指所有其他 TCP FLAG 字段均为 0。仅含 ACK 标志的空数据包,用于连接维护 |
| sack | TCP 首部是否包含 SACK(选择性确认)字段 |
| sack_len | TCP 首部 SACK 字段长度 |
| dsack | TCP 首部中包含的重复 SACK 字段长度 |
| psh | TCP FLAG 中的 PSH 位是否设为 1 |
| psh_rate | 网络流量中 PSH 标志设置为1的数据包比例 |
| urg | TCP FLAG 中的 URG 位是否设为 1 |
| urg_data_len | URG 字段长度 |
| win_size | 窗口大小 |
| adv_wind_scale | 所用窗口缩放因子的大小 |
表 2 MA-BiLSTM模型的检测结果Table 2 Detection results of MA-BiLSTM |
| 模型 | ACC | PRE | REC | F1值 | FNR | FPR |
| MA-BiLSTM | 97.72% | 96.96% | 98.45% | 97.70% | 1.55% | 2.99% |
表 3 MA-BiLSTM模型与其他深度学习模型性能对比结果Table 3 Performance results between MA-BiLSTM model and other deep learning models |
| 模型 | ACC | PRE | REC | F1值 | FNR | FPR |
| MA-BiLSTM | 97.72% | 96.96% | 98.45% | 97.70% | 1.55% | 2.99% |
| LSTM | 95.29% | 94.05% | 96.45% | 95.23% | 3.55% | 5.81% |
| BiLSTM | 96.16% | 95.39% | 96.89% | 96.13% | 3.11% | 4.54% |
| A-LSTM | 95.87% | 94.81% | 96.86% | 95.82% | 3.14% | 5.08% |
| A-BiLSTM | 97.48% | 97.70% | 97.27% | 97.49% | 2.73% | 2.31% |
| MA-LSTM | 95.74% | 95.88% | 95.61% | 95.74% | 4.39% | 4.14% |
表 4 真实网络环境模型性能检测结果Table 4 Model performance detection results in real-world network traffic |
| 模型 | 检出数 | TP | FP | PRE |
| MA-BiLSTM | 774 | 676 | 98 | 87.34% |
| LSTM | 412 | 271 | 141 | 65.78% |
| BiLSTM | 483 | 328 | 155 | 67.91% |
| A-LSTM | 519 | 376 | 143 | 72.45% |
| A-BiLSTM | 587 | 431 | 156 | 73.42% |
| MA-LSTM | 698 | 582 | 116 | 83.38% |
表 5 未知流量行为分类Table 5 Categorization of unknown traffic behaviors |
| 行为族 | 数量 | 典型标签(VT 检出名) | 主要恶意指标 |
| 木马远控 | 247 | AsyncRAT, Nanocore, Remcos | 持续外联、键盘记录 |
| 挖矿 | 198 | XMRig, CoinMiner | Stratum协议、100+ CPU占用 |
| 流氓下载器 | 102 | PrivateLoader, SmokeLoader | 多阶段PE投放 |
| WebShell 通信 | 78 | China Chopper, AntSword | POST载荷含eval关键字 |
| 蠕虫横向 | 36 | EternalBlue利用流 | SMB异常445扫描 |
| 其他/未命名 | 15 | —— | 低频次可疑DGA |
| 1 |
Dhote Y, Agrawal S, Deen A J. A survey on feature selection techniques for internet traffic classification[C]//2015 International Conference on Computational Intelligence and Communication Networks(CICN), Jabalpur, India, Piscataway, USA: IEEE, 2015: 1375-1380.
|
| 2 |
Ma Q, Sun P C, Wang R R, et al. A novel model for anomaly detection in network traffic based on kernel support vector machine[J]. Computers & Security, 2021, 104, 102215.
|
| 3 |
Hwang R H, Peng M C, Huang C W, et al. An unsupervised deep learning model for early network traffic anomaly detection[J]. IEEE Access, 2020, 8, 30387- 30399.
|
| 4 |
Lindemann B, Maschler B, Sahlab N, et al. A survey on anomaly detection for technical systems using LSTM networks[J]. Computers in Industry, 2021, 131, 103498.
|
| 5 |
Ahmad Z, Khan A S, Shafai M S, et al. Anomaly detection using deep neural network for IoT architecture[J]. Applied Sciences, 2021, 11 (15): 7050.
|
| 6 |
Torres P, Catania C, Garcia S, et al. An analysis of recurrent neural networks for botnet detection behavior[C]//2016 IEEE Biennial Congress of Argentina(ARGENCON), Buenos Aires, Argentina, Piscataway, USA: IEEE, 2016: 1-6.
|
| 7 |
Roy K C, Chen Q. DeepRan: Attention-based BiLSTM and CRF for ransomware early detection and classification[J]. Information Systems Frontiers, 2021, 23 (2): 299- 315.
|
| 8 |
Sinha J, Manollas M. Efficient deep CNN-BiLSTM model for network intrusion detection[C]//Proceedings of the 2020 3rd International Conference on Artificial Intelligence and Pattern Recognition (AIPR), New York, USA: ACM, 2020: 223-231.
|
| 9 |
Liu G, Guo J B. Bidirectional LSTM with attention mechanism and convolutional layer for text classification[J]. Neurocomputing, 2019, 337, 325- 338.
|
| 10 |
Zhai Y, Lu B, Li X. TPE-MHA: a malicious traffic detection model based on time position encoding and multi-head attention[C]//2021 IEEE 21st International Conference on Communication Technology (ICCT), Piscataway, USA: IEEE, 2021: 143-151.
|
| 11 |
Zhang J, Liu Y, Zhang H, et al. A network intrusion detection model based on BiLSTM with multi-head attention mechanism[J]. Electronics, 2023, 12 (19): 4035.
|
| 12 |
Internet Engineering Task Force (IETF). Hypertext transfer protocol (HTTP/1.1)[EB/OL]. [2025-09-25]. https://datatracker.ietf.org/doc/html/rfc7230.
|
| 13 |
Network Working Group. The transport layer security (TLS) protocol version 1.1[EB/OL]. [2025-09-25]. https://www.rfc-editor.org/rfc/rfc4346.
|
| 14 |
Network Working Group. Transport layer security (TLS) Extensions[EB/OL]. [2025-09-25]. https://www.ietf.org/rfc/rfc3546.txt.
|
| 15 |
Kasongo S M. A deep learning technique for intrusion detection system using a recurrent neural networks based framework[J]. Computer Communications, 2023, 199, 113- 125.
|
| 16 |
He K, Kim D D, Asghar M R. Adversarial machine learning for network intrusion detection systems: a comprehensive survey[J]. IEEE Communications Surveys & Tutorials, 2023, 25 (1): 538- 566.
|
| 17 |
Shafiq M, Yu X, Laghari A A, et al. Network traffic classification techniques and comparative analysis using machine learning algorithms[C]//2016 2nd IEEE International Conference on Computer and Communications (ICCC), Chengdu, China. Piscataway, USA: IEEE, 2016: 2451-2455.
|
| 18 |
Shafiq M, Tian Z, Bashir A K, et al. CorrAUC: A malicious Bot-IoT traffic detection method in IoT network using machine-learning techniques[J]. IEEE Internet of Things Journal, 2021, 8 (5): 3242- 3254.
|
| 19 |
Zhao J J, Liu J Y, Yang L, et al. Network traffic classification for data fusion: a survey[J]. Information Fusion, 2021, 72, 22- 47.
|
| 20 |
Zhao G, Xu K, Xu L, et al. Detecting APT malware infections based on malicious DNS and traffic analysis[J]. IEEE Access, 2015, 3, 1132- 1142.
|
| 21 |
Hochreiter S, Schmidhuber J. Long short-term memory[J]. Neural Computation, 1997, 9 (8): 1735- 1780.
|
| 22 |
Graves A, Schmidhuber J. Framewise phoneme classification with bidirectional LSTM and other neural network architectures[J]. Neural Networks, 2005, 18 (5): 602- 610.
|
| 23 |
Moustafa N, Slay J. UNSW-NB15: a comprehensive data set for network intrusion detection systems (UNSW-NB15 network data set)[C]//2015 Military Communications and Information Systems Conference (MilCIS), Canberra, Australia. Piscataway, USA: IEEE, 2015: 1-6.
|
| 24 |
Caida dataset[EB/OL]. [2025-09-25]. https://www.caida.org/.
|
| 25 |
CSE-CIC-IDS2018 on AWS[EB/OL]. [2025-09-25]. https://www.unb.ca/cic/datasets/ids-2018.html.
|
| 26 |
Parkour M. Contagio malware database[EB/OL]. [2025-09-25]. http://www.mediafire.com/?a49l965nlayad#a49l965nlayad.
|
| 27 |
Siddiqui S, Khan M S, Ferens K, et al. Detecting advanced persistent threats using fractal dimension based machine learning classification[C]//Proceedings of the 2016 ACM on International Workshop on Security and Privacy Analytics, New York, USA: ACM, 2016: 64-69.
|
/
| 〈 |
|
〉 |