Machine Learning
Firewall Log Anomaly Detection Using Machine Learning
Hawa Doumbe Traore
Abstract
This project develops a machine learning system for detecting anomalies in firewall logs. Using the Isolation Forest algorithm, it analyzes 5,250 network records to identify suspicious behavior. The model detects 263 anomalies and 4,987 normal events.
- Python
- Pandas
- NumPy
- Scikit-learn
- Isolation Forest
- Google Colab
- Machine Learning
1. Problem
Firewall logs contain large amounts of information about network traffic. Manual analysis can make it difficult to quickly identify unusual behavior and potential threats. This project aims to develop a machine learning system that analyzes firewall logs and automatically detects suspicious activities to support network security monitoring.
2. Data
The project uses a dataset containing 5,250 network records, including 5,000 normal events and 250 anomalous events. The original dataset contains 11 fields with no missing values. After preprocessing and feature engineering, 12 features are used, including ports, connection duration, packet count, data volume, and connection rates.
The dataset includes 3,903 TCP records and 1,347 UDP records.
3. Method
The project uses the Isolation Forest algorithm, an unsupervised anomaly detection method.
The methodology includes:
- Cleaning and preprocessing network logs.
- Selecting and engineering relevant features.
- Scaling data using Scikit-learn.
- Training Isolation Forest with 200 trees and a contamination rate of 5%.
- Detecting anomalies and assigning risk levels.
- Saving the trained model, scaler, and detection results.
The implementation was developed in Python using Google Colab.
4. Results
The model analyzed all 5,250 records and identified 263 anomalies (5.01%) and 4,987 events classified as normal.
The resulting risk-level distribution is:
- Low: 4,987 events
- Medium: 13 events
- Critical: 250 events
- High: 0 events
The system was also tested using normal and anomalous traffic examples. The results demonstrate how Isolation Forest can help identify unusual behavior in firewall logs.
| Metric | Value |
|---|---|
| Firewall logs analyzed | 5,250 |
| Features used | 12 |
| Isolation Forest estimators | 200 |
| Anomalies detected | 263 |
| Anomaly detection rate | 5.01% |
| Normal logs | 4,987 |
5. Limitations and future work
The project has some limitations. The model relies on an experimental dataset and a contamination rate set to 5%. Results may vary depending on network traffic patterns and log characteristics. Furthermore, a detected anomaly does not necessarily represent a real cyberattack.
Future work could include:
- Using logs from real network environments.
- Comparing Isolation Forest with other anomaly detection algorithms.
- Improving risk-level classification.
- Implementing real-time monitoring and automated alerts.
- Evaluating performance with additional metrics on labeled datasets.
6. References
-
Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: A survey. ACM Computing Surveys, 41(3), Article 15. https://doi.org/10.1145/1541880.1541882
-
Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2008). Isolation Forest. In Proceedings of the Eighth IEEE International Conference on Data Mining (pp. 413–422). IEEE. https://doi.org/10.1109/ICDM.2008.17
-
Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M., & Duchesnay, É. (2011). Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12, 2825–2830. https://jmlr.org/papers/v12/pedregosa11a.html
-
National Institute of Standards and Technology. (2007). Guide to Intrusion Detection and Prevention Systems (IDPS) (Special Publication 800-94). U.S. Department of Commerce. https://doi.org/10.6028/NIST.SP.800-94
https://hawadtraore.alwaysdata.net/en/projects/detection-anomalies-logs-pare-feu