Real
Real
Submitted by
MOWLEESWARAN V
SENTHAMIZHSELVAN M
of
BACHELOR OF ENGINEERING
IN
1
CHENNAI INSTITUTE OF TECHNOLOGY
(An Autonomous Institution, Affiliated to Anna University ,Chennai)
CHENNAI-600 069
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
Certified that the above students have attended viva voice during the exam held
on ………………........
2
ACKNOWLEDGEMENT
3
Abstract
The rapid growth of Internet of Things (IoT) devices has revolutionized various
industries, enhancing connectivity and automation. However, the increasing
number of IoT deployments also introduces significant cybersecurity challenges,
making them vulnerable to sophisticated cyber threats. Traditional Intrusion
Detection Systems (IDS) struggle to adapt to evolving attack patterns due to high
false positive rates and limited scalability. This project presents Deep-IDS, a
real-time intrusion detection system specifically designed for IoT environments
using deep learning techniques. By leveraging the NSL-KDD dataset, a deep
learning model is trained to effectively identify and mitigate cyber threats. The
proposed system employs advanced neural network architectures such as
Convolutional Neural Networks (CNNs) and Recurrent Neural Networks
(RNNs) to improve detection accuracy. The implementation is deployed as a
Flask web application, ensuring scalability, real-time monitoring, and user-
friendly interaction. Deep-IDS follows a structured approach, including data
collection, preprocessing, feature selection, deep learning model training, and
real-time classification of intrusions. The system demonstrates high accuracy
with reduced false positives, making it an effective security solution for IoT
networks. Furthermore, its real-time detection capability enables rapid responses
to potential threats, enhancing overall cybersecurity. The findings of this project
highlight the efficiency of deep learning-based IDS in IoT security. Future
improvements include integrating federated learning for distributed IDS and
leveraging blockchain for secure logging. Deep-IDS serves as a robust and
intelligent security framework, safeguarding IoT ecosystems against emerging
cyber threats.
4
TABLE OF CONTENTS
Pag
Chapters Section Title e
No.
Abstract 4
Chapter
Introduction 6
1
1.1 Background 6
Cyber
Threats in
1.2 IoT 7
Environment
s
Limitations
of Traditional
1.3 8
Security
Mechanisms
The Role of
Deep
1.4 9
Learning in
IoT Security
Problem
1.5 10
Statement
Objectives of
1.6 11
the Study
Significance
1.7 12
of the Study
Scope of the
1.8 13
Project
Organization
1.9 14
of the Report
Chapter Literature
15
2 Review
2.1 Introduction 15
5
Overview of
Intrusion
2.2 Detection 16
Systems
(IDS)
Traditional
2.3 IDS for IoT 17
Security
Machine
Learning-
2.4 Based 18
Intrusion
Detection
Deep
Learning for
2.5 19
Intrusion
Detection
Existing
Datasets for
2.6 20
Intrusion
Detection
Challenges
2.7 and Research 21
Gaps
2.8 Summary 22
Chapter
System Design 23
3
3.1 Introduction 23
System
3.2 24
Architecture
Block
3.3 25
Diagram
Module
3.4 26
Descriptions
6
Data
3.4.1 Collection 27
Module
Data
3.4.2 Preprocessin 28
g Module
Feature
3.4.3 Selection 29
Module
CNN-Based
Deep
3.4.4 30
Learning
Model
Detection
3.4.5 31
System
Web-Based
3.4.6 User 33
Interface
Workflow of
3.5 34
Deep-IDS
3.6 Summary 34
Chapter Implementatio
35
4 n
4.1 Dataset Used 36
Data
4.2 Preprocessin 37
g Techniques
Deep
Learning
4.3 38
Model
Development
System
4.4 39
Deployment
4.5 Summary 39
7
Chapter
Source Code 40
5
Code for
Model
5.1 41
Building and
Predictions
Code for
5.2 42
Deployment
Experimental
Chapter
Results and 43
6
Analysis
6.1 Introduction 43
Model
6.2 Evaluation 44
and Accuracy
Performance
6.3 45
Metrics
Comparison
with
6.4 46
Traditional
IDS
System
Performance
6.5 47
and Interface
Screenshots
6.6 Summary 48
Chapter Conclusion and
49
7 Future Work
7.1 Conclusion 49
7.2 Future Work 49
References 51
8
LIST OF FIGURES
TABLE NO. TITLE PAGE NO.
9
CHAPTER I: INTRODUCTION
1.1 Background
10
deployments. Its ability to process vast amounts of network traffic efficiently
enables organizations to maintain security without compromising system
performance. By utilizing deep learning models, Deep-IDS continuously
improves its detection capabilities, ensuring long-term resilience against
emerging cyber threats.
The increasing reliance on IoT has made these systems attractive targets for
cybercriminals, who exploit vulnerabilities to launch attacks such as:
11
Man-in-the-Middle (MITM) attacks – Cybercriminals intercept and
manipulate communications between IoT devices and servers,
compromising data integrity and confidentiality.
Traditional Intrusion Detection Systems (IDS) are classified into two primary
types:
1. Signature-Based IDS:
2. Anomaly-Based IDS:
12
Uses predefined behavioral baselines, but can generate high false
positive rates if benign activities are misclassified as threats.
Deep learning-based IDS offers several advantages in IoT security. CNNs are
effective in analyzing spatial features of network traffic, while RNNs and Long
Short-Term Memory (LSTM) networks help detect temporal anomalies in
sequential data. Hybrid models combining these techniques improve overall
detection accuracy and adaptability. Additionally, autoencoders and Generative
Adversarial Networks (GANs) are widely used for anomaly detection, enabling
the identification of zero-day attacks.
13
Learn complex patterns from vast amounts of network traffic data.
The existing security solutions for IoT networks suffer from several limitations:
14
1.3 Objectives of the Study
Training and evaluating the model using the NSL-KDD dataset to enhance
detection accuracy.
Ensuring low false positive rates while detecting various cyber threats.
15
Another significant advantage of Deep-IDS is its scalability. It can be deployed
across various IoT environments, ranging from small-scale smart homes to
complex industrial systems, without significant performance degradation. The
system efficiently handles large volumes of network data, ensuring real-time
threat analysis without introducing latency or excessive resource consumption.
16
1.5 Scope of the Project
Training deep learning models (CNNs and RNNs) for accurate attack
detection.
This report is structured into several chapters, each detailing different aspects of
the Deep-IDS: A Real-Time Intrusion Detector for IoT Nodes Using Deep
Learning project. The contents of each chapter are summarized below:
17
Chapter 4: Implementation – Explains the dataset used, preprocessing
techniques, deep learning model development, and system deployment.
2.1 Introduction
18
security configurations, making it difficult to implement standardized protection
measures.
19
2.2 Overview of Intrusion Detection Systems (IDS)
20
Hybrid deep learning models combining multiple architectures have shown
promising results in detecting both known and unknown intrusions. For example,
combining CNNs with LSTMs can leverage spatial and temporal features
simultaneously, leading to improved classification accuracy. Autoencoders and
Generative Adversarial Networks (GANs) have also been explored for
unsupervised anomaly detection, where the model learns to differentiate between
normal and suspicious activities without relying on labeled attack data. These
techniques enable IDS solutions to detect zero-day attacks, making them more
effective in real-world IoT environments.
21
Another critical challenge is model interpretability. Many deep learning models
operate as "black-box" systems, making it difficult for security analysts to
understand their decision-making process. Enhancing explainability through
techniques like SHAP (SHapley Additive exPlanations) and LIME (Local
Interpretable Model-agnostic Explanations) can help improve trust and adoption
of deep learning-based IDS. The integration of blockchain for secure threat
intelligence sharing and reinforcement learning for adaptive detection strategies
are also emerging solutions that could further enhance the effectiveness of IDS in
IoT networks. By continuously refining these approaches, researchers can
develop more robust, efficient, and scalable IDS solutions capable of addressing
the evolving cybersecurity challenges in IoT environments.
Machine learning has been widely adopted in intrusion detection systems (IDS)
to enhance their ability to recognize sophisticated attack patterns. Supervised
learning techniques, such as decision trees, support vector machines (SVM), and
random forests, classify network traffic into normal and malicious categories.
These models require labeled datasets for training and rely on handcrafted feature
selection to optimize performance. Despite their effectiveness, traditional
machine learning models often struggle to adapt to new attack types, limiting their
applicability in real-world IoT networks.
22
labeled and unlabeled data, have been introduced to improve detection
performance while reducing the dependency on extensive labeled datasets.
Deep learning has emerged as a powerful tool for intrusion detection due
to its ability to automatically extract meaningful features from large volumes of
network traffic data. Unlike traditional machine learning models that require
manual feature engineering, deep learning models can learn complex
representations from raw input data. Several neural network architectures,
including convolutional neural networks (CNNs), recurrent neural networks
(RNNs), and long short-term memory (LSTM) networks, have been successfully
applied to cybersecurity applications.
CNNs have been used for intrusion detection by analyzing network traffic as
image-like representations. These models can detect spatial patterns in network
data, improving classification accuracy. RNNs and LSTMs are particularly useful
for detecting attacks in time-series network traffic, as they can capture sequential
dependencies and identify anomalies over time. Autoencoders, a type of
unsupervised deep learning model, have been employed to detect novel intrusions
by reconstructing normal traffic patterns and flagging deviations as potential
threats.
23
The use of deep learning in intrusion detection has shown promising results, with
improved accuracy and reduced false positive rates compared to traditional
methods. However, the computational complexity of deep learning models poses
a challenge for deployment in resource-constrained IoT environments.
Researchers have proposed lightweight deep learning models and model
compression techniques to address these limitations, making deep IDS solutions
more feasible for IoT security applications.
The NSL-KDD dataset is one of the most commonly used datasets for intrusion
detection, containing various attack types categorized into four major groups:
denial-of-service (DoS) attacks, probing attacks, remote-to-local (R2L) attacks,
and user-to-root (U2R) attacks. Despite its popularity, NSL-KDD has limitations,
such as outdated attack patterns that may not reflect modern cyber threats.
Additionally, it lacks encrypted traffic samples and real-time network behaviors,
making it less suitable for evaluating IDS models in contemporary IoT
environments.
24
them more suitable for evaluating modern IDS solutions. CICIDS2017 contains
traffic data generated from realistic attack simulations, such as brute-force
attacks, botnets, and web-based intrusions, making it useful for deep learning-
based IDS training. Similarly, UNSW-NB15 includes a combination of synthetic
and real-world traffic, offering a balanced dataset with multiple attack vectors.
The TON_IoT dataset has been specifically designed for IoT security research,
containing traffic data from IoT networks with labeled attack categories. Unlike
traditional datasets, TON_IoT captures device-specific vulnerabilities, making it
valuable for training IDS models in resource-constrained environments. It
includes network telemetry from IoT, industrial IoT (IIoT), and edge devices,
reflecting the increasing adoption of connected technologies in various sectors.
The availability of diverse datasets enables researchers to train and test deep
learning-based IDS models in different network environments. By leveraging
multiple datasets, security researchers can enhance model generalization,
ensuring that IDS solutions remain effective against previously unseen threats.
Furthermore, ongoing efforts to create new benchmark datasets with up-to-date
attack patterns, encrypted traffic analysis, and adversarial examples will play a
crucial role in advancing IDS capabilities. The integration of real-world traffic
with synthetic attack scenarios will further strengthen the reliability of IDS
models, enabling them to detect and mitigate evolving cyber threats in IoT
ecosystems effectively. Additionally, dataset augmentation techniques, such as
data synthesis and transformation, can help improve the model's robustness
against sophisticated attack variations. Collaborative research initiatives focusing
on open-source dataset sharing will also accelerate innovation in IDS
development.
25
2.7 Challenges and Research Gaps
Another research gap is the integration of IDS with real-time security response
mechanisms. Most IDS solutions focus on threat detection without providing
automated mitigation strategies. The combination of intrusion detection with
proactive security measures, such as intrusion prevention systems (IPS) and
blockchain-based security frameworks, is an area that requires further
exploration. Additionally, the development of explainable IDS models is crucial
to enhance trust and transparency in cybersecurity decision-making. Many deep
learning models operate as black-box systems, making it difficult for security
analysts to interpret their predictions.
Future research should focus on optimizing deep learning models for edge
computing, reducing dependency on cloud-based processing, and incorporating
federated learning to enhance privacy and security. Strengthening adversarial
robustness in IDS models will help defend against sophisticated evasion
techniques used by attackers. Furthermore, integrating IDS with threat
intelligence platforms can enhance detection accuracy by leveraging real-time
global threat data, while improving energy-efficient IDS models will facilitate
seamless deployment in resource-constrained IoT environments.
26
2.8 Summary
27
CHAPTER III: SYSTEM DESIGN
3.1 Introduction
The selection of appropriate datasets is crucial for training effective IDS models.
However, many existing datasets contain outdated attack patterns, lack real-world
traffic diversity, or suffer from class imbalances. Since cyber threats continue to
evolve, using high-quality, diverse datasets that accurately represent modern
attack scenarios is essential for improving IDS performance. Enhancing dataset
relevance and incorporating encrypted traffic analysis can further strengthen
detection capabilities and ensure models are prepared for emerging cyber threats.
28
These improvements will help secure IoT environments against sophisticated
attacks, ensuring a safer and more resilient digital ecosystem.
The system consists of six key components, each performing a critical role in
intrusion detection:
The data collection module is responsible for gathering network traffic data from
various sources, ensuring that the system has a diverse dataset for training and
real-time monitoring.
29
2. Preprocessing Module
Before feeding the data into the deep learning model, preprocessing is crucial to
ensure data consistency, noise reduction, and proper formatting.
Not all network traffic features are relevant for intrusion detection. The feature
selection module extracts and selects the most significant features to improve
model efficiency and reduce computational overhead.
30
Feature Engineering: Identifies critical network attributes such as source
and destination ports, protocol types, connection state, and traffic
patterns that contribute to detecting intrusions.
Model Components:
31
Optimization & Training:
The model is trained using a split dataset (training, validation, and test
sets) to prevent overfitting and evaluate performance on unseen data.
Once the CNN model detects a potential threat, the detection and alert system
ensures that security administrators are promptly notified.
32
Web-Based User Interface
33
Figure 3.1 System Architecture of Deep-IDS
The block diagram of Deep-IDS visually represents the flow of data and
processing steps within the system. It illustrates the core components, including
data input, preprocessing, feature extraction, model training, and threat
classification.
34
The system follows a sequential process:
35
connection duration, and protocol usage, to distinguish between benign and
malicious activities. These extracted features are fed into the Deep Learning
Model, which leverages neural networks to analyze patterns and detect potential
threats. The model is trained on diverse datasets to improve accuracy and
adaptability to evolving cyber threats.
The data collection process involves acquiring network traffic data from two
primary sources. The first source is real-time network traffic generated by IoT
devices operating in a test environment. This data is captured using packet
sniffing tools such as Wireshark or tcpdump, which monitor and log all incoming
and outgoing packets on a network. By capturing real-time data, the system can
learn the natural behavior of IoT network communication, enabling it to
distinguish between legitimate and suspicious activities.
The second source of data includes publicly available intrusion detection datasets
that have been widely used in cybersecurity research. One of the most commonly
used datasets is NSL-KDD, which is an improved version of the original KDD99
dataset. This dataset contains labeled network traffic records classified into
different attack categories such as denial-of-service (DoS) attacks, remote-to-
36
local (R2L) attacks, user-to-root (U2R) attacks, and probing attacks. NSL-KDD
is specifically designed to address some of the limitations of its predecessor by
removing redundant records and balancing the distribution of attack and normal
traffic samples, making it a suitable choice for training deep learning models.
The collected network traffic data includes various features that help in
distinguishing between normal and malicious activities. Some of the key features
extracted from network packets include source and destination IP addresses,
protocol types, packet sizes, time intervals between packets, number of
connections within a given time frame, and flag status of TCP connections. These
features provide valuable insights into network behavior, enabling the model to
identify deviations from expected patterns that may indicate the presence of an
intrusion.
To ensure data integrity and consistency, the collected raw data undergoes initial
preprocessing, such as duplicate record removal and basic filtering to eliminate
noise. Any missing values in the dataset are handled appropriately to prevent
inconsistencies in the training process. Once the data collection phase is
37
complete, the processed dataset is stored in a structured format for further
preprocessing, feature selection, and model training.
The efficiency of the data collection module directly impacts the overall
performance of the intrusion detection system. A well-curated dataset that covers
a diverse range of attack scenarios and normal activities enhances the robustness
of the deep learning model, allowing it to adapt to new and emerging cyber
threats. By combining real-time IoT network traffic with standardized benchmark
datasets, Deep-IDS ensures that the intrusion detection system is capable of
identifying attacks with high accuracy while minimizing false alarms.
The preprocessing module systematically transforms raw network traffic data into
a structured format suitable for training. It consists of several important steps,
including data cleaning, normalization, feature encoding, and handling missing
values. Each of these steps plays a vital role in improving data quality and
ensuring efficient training of the deep learning model.
38
Data Cleaning
Raw network traffic logs collected from IoT devices or publicly available datasets
often contain duplicate entries, irrelevant records, and corrupted data points. Data
cleaning is performed to remove inconsistencies and refine the dataset for better
analysis. The cleaning process involves:
Filtering out irrelevant data: Some network traffic records may not
contribute to meaningful intrusion detection, such as unrelated background
traffic or incomplete packet captures. These records are discarded to focus
only on significant data points.
Standardizing time formats and field values: Since network logs are
generated with timestamps and varying field formats, standardization
ensures uniformity across all records, making it easier for the deep learning
model to process the data.
By performing data cleaning, the system ensures that only high-quality, relevant
data is used for intrusion detection, preventing misleading patterns and improving
model efficiency.
Normalization
39
byte counts. Since machine learning and deep learning models rely on numerical
inputs, inconsistent feature scales can negatively impact model performance.
Without normalization, features with large numerical values may dominate the
learning process, leading to biased predictions and slower convergence during
training. For example, if packet sizes range in thousands while connection
durations are measured in milliseconds, the model might prioritize packet size
over duration, skewing detection accuracy.
By normalizing network traffic data, IDS models achieve better feature balance,
faster training convergence, and improved detection accuracy. Proper
normalization ensures that deep learning models effectively differentiate between
normal and malicious activities, enhancing the overall performance of intrusion
detection systems.
40
This method ensures that all values lie within a specific range, making it easier
for the CNN model to process the data uniformly.
Feature Encoding
Many network traffic datasets contain categorical attributes such as protocol type
(TCP, UDP, ICMP), service type (HTTP, FTP, SSH, etc.), and flag status
(SYN, ACK, FIN, etc.). Since deep learning models require numerical inputs,
categorical data must be transformed into a suitable numerical format through
feature encoding.
o TCP → [1, 0, 0]
o UDP → [0, 1, 0]
41
o ICMP → [0, 0, 1]
o TCP → 1
o UDP → 2
o ICMP → 3
One-hot encoding is preferred when categorical values are nominal (i.e., have no
intrinsic ordering), while label encoding is used for ordinal categories. The choice
of encoding method impacts how the CNN model interprets categorical features
and extracts meaningful relationships.
Network traffic data may have missing or incomplete records due to network
disruptions, packet loss, or errors in data collection. If missing values are not
addressed, the deep learning model may struggle to learn meaningful patterns,
leading to incorrect predictions. The preprocessing module employs different
strategies for handling missing data:
42
Removing Highly Incomplete Records: If a record contains excessive
missing values that cannot be reasonably imputed, it is removed to
maintain dataset integrity.
Handling missing values ensures that the dataset remains complete and prevents
errors during model training, improving overall performance.
The preprocessing module plays a fundamental role in ensuring that the CNN-
based intrusion detection model receives high-quality, structured input data.
Without proper preprocessing, raw network traffic data may contain noise,
inconsistencies, and biases that could negatively affect model accuracy. The
impact of preprocessing on model performance includes:
Better Generalization: Properly scaled and encoded data allows the CNN
model to learn robust patterns, improving generalization to unseen network
traffic.
43
Data Consistency and Standardization – Ensuring uniform data formats
and handling missing values prevents inconsistencies that could mislead
the model.
Analysis (PCA) and feature selection help retain the most relevant attributes
while improving computational efficiency.
Feature selection plays a vital role in reducing the dimensionality of the dataset
while retaining relevant information. This module extracts key features from
network traffic, such as:
Protocol type
Packet size
44
Flow duration
TCP flags
The CNN model is trained using labeled datasets, where attack patterns are
identified and classified into different categories such as denial-of-service (DoS),
probing, and remote-to-local (R2L) attacks.
45
Figure 3.3 CNN Model Architecture for Intrusion Detection
Once a potential intrusion is detected, the system generates alerts that notify
network administrators of suspicious activity. These alerts contain detailed
information, including the attack type, severity level, source and destination IP
addresses, and timestamps. The system can also integrate with security
46
mechanisms such as firewalls and intrusion prevention systems (IPS) to block
malicious traffic automatically.
The detection module ensures minimal false positives and false negatives by
leveraging the high accuracy of the CNN model. It continuously updates itself by
learning from new traffic patterns, making it adaptive to emerging cyber threats.
Furthermore, the module maintains a log of all detected intrusions, which can be
analyzed to improve future threat detection. This real-time detection and response
mechanism enhances the overall security of IoT networks, preventing
unauthorized access and mitigating cyberattacks efficiently.
The user-friendly web interface ensures that system administrators can efficiently
manage and respond to security threats.
47
Figure 3.4 Web-Based Interface for Deep-IDS
48
3.5 Workflow of Deep-IDS
7. The web interface provides real-time visualization and logs for further
analysis.
3.6 Summary
This chapter described the system design of Deep-IDS, including its architecture,
block diagram, module descriptions, and overall workflow. The use of CNN-
based deep learning improves the system's accuracy and adaptability to evolving
cyber threats.
49
CHAPTER 4: IMPLEMENTATION
The implementation of Deep-IDS begins with the careful selection and utilization
of datasets that accurately represent the diverse network traffic encountered in
IoT environments. The primary dataset employed in this project is the NSL-KDD
dataset, a refined version of the original KDD99 dataset, which addresses issues
such as redundant records and class imbalance. The NSL-KDD dataset provides
a well-structured set of labelled network traffic records, categorizing various
forms of intrusions, including denial-of-service (DoS) attacks, probing, remote-
to-local (R2L) attacks, and user-to-root (U2R) attacks.To enhance model
robustness, additional datasets such as CICIDS2017 and UNSW-NB15 may be
integrated. CICIDS2017 captures realistic network traffic with a wide range of
modern cyber threats, while UNSW-NB15 offers a more recent and
comprehensive dataset with diverse attack types and realistic background traffic.
The inclusion of multiple datasets ensures that the deep learning model is exposed
to varied attack patterns and normal behaviours, improving its ability to
generalize and detect novel intrusions effectively.Beyond dataset selection,
preprocessing plays a vital role in preparing the data for deep learning. Key
preprocessing steps include data cleaning, feature selection, normalization, and
encoding categorical attributes. Normalization ensures that numerical features
like packet size and connection duration are scaled properly, preventing large
values from dominating the learning process. One-hot encoding or label encoding
is applied to categorical variables such as protocol types and service names to
make them compatible with neural networks.By leveraging multiple datasets and
implementing comprehensive preprocessing techniques, Deep-IDS enhances its
ability to detect sophisticated cyber threats in IoT environments. This approach
ensures that the model is well-equipped to handle real-world scenarios, providing
a reliable and scalable intrusion detection solution.
50
4.2 Data Preprocessing Techniques
First, data cleaning removes duplicate records, irrelevant entries, and corrupted
data points. Next, normalization scales numerical features, preventing larger
values from dominating the learning process and improving CNN model
performance. Categorical variables, such as protocol types and service names, are
converted into numerical values using one-hot encoding or label encoding,
making them compatible with the model.
Handling missing values is another essential step. Missing data is either imputed
using statistical methods (mean, median, or mode) or removed if excessive gaps
exist. These preprocessing techniques collectively enhance data reliability,
ensuring the model receives optimized and noise-free input for accurate intrusion
detection.
51
representation before the final classification is made through an output layer that
typically uses a sigmoid activation function for binary classification. The model
is trained using the labeled dataset, where a portion of the data is reserved for
validation to monitor the performance and avoid overfitting. Optimization
techniques such as Adam optimizer are employed alongside appropriate loss
functions like binary cross-entropy to ensure that the model converges to an
optimal solution. Hyperparameter tuning is conducted iteratively to refine the
model’s accuracy and reduce false positive rates.
After the successful training and evaluation of the CNN model, the next step
involves deploying Deep-IDS in a real-time environment. The system is
implemented as a Flask web application, which provides a user-friendly interface
for monitoring network traffic and intrusion alerts. The deployment architecture
is designed to integrate the trained model into a continuous monitoring system
that analyzes live network traffic from IoT devices. Real-time data is captured,
preprocessed, and fed into the CNN model, allowing for immediate classification
of network activity.
When an anomaly or potential intrusion is detected, the system triggers alerts and
logs the incident for further analysis. The deployment phase also involves
optimizing the model for resource-constrained environments, often by leveraging
techniques such as model quantization or converting the model into a lightweight
format suitable for edge devices. This approach ensures that Deep-IDS not only
maintains high accuracy but also operates efficiently in real-time, providing
robust security monitoring for IoT networks.
52
4.5 Summary
The use of diverse datasets ensures that the system is trained on a wide range of
attack scenarios, improving its ability to detect evolving cyber threats.
The final deployment strategy integrates the trained model into a real-time
monitoring system, providing administrators with an interactive web-based
interface for threat detection and response.
The next chapter will evaluate the system’s performance, analyzing its accuracy,
efficiency, and effectiveness in detecting network intrusions.
53
CHAPTER 5: SOURCE CODE
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv1D, MaxPooling1D, Flatten, Dense,
Dropout
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, StandardScaler
from sklearn.metrics import accuracy_score, classification_report,
confusion_matrix
from imblearn.over_sampling import SMOTE
from collections import Counter
# Load dataset
train = pd.read_csv('kdd_train.csv')
54
train['flag'] = train['flag'].map({
'SF': 1, 'S0': 2, 'REJ': 3, 'RSTR': 4, 'SH': 5,
'RSTO': 6, 'S1': 7, 'RSTOS0': 8, 'S3': 9, 'S2': 10, 'OTH': 11
})
train['flag'] = train['flag'].astype(int)
train['protocol_type'] = train['protocol_type'].astype(int)
55
# Apply SMOTE to balance the dataset
smote = SMOTE(k_neighbors=2)
X, y = smote.fit_resample(X, y)
print('Classes and number of values after SMOTE:', Counter(y))
# Normalize features
scaler = StandardScaler()
X = scaler.fit_transform(X)
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=9)
56
Dense(64, activation='relu'),
Dense(len(np.unique(y)), activation='softmax') # Output layer with softmax
for classification
])
# Compile model
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Evaluate Model
y_pred = np.argmax(model.predict(X_test), axis=1)
accuracy = accuracy_score(y_test, y_pred)
print("CNN Model Accuracy:", accuracy)
print("Classification Report:\n", classification_report(y_test, y_pred))
# Confusion Matrix
cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(6, 5))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',
xticklabels=label_encoder.classes_, yticklabels=label_encoder.classes_)
plt.xlabel("Predicted")
plt.ylabel("Actual")
plt.title("Confusion Matrix")
57
plt.show()
6.1 Introduction
This chapter presents the evaluation results of the Deep-IDS model, focusing on
its accuracy, performance metrics, and comparison with traditional intrusion
detection systems (IDS). The model's effectiveness is assessed using key
performance indicators, including accuracy, precision, recall, F1-score, and a
confusion matrix, which help determine its ability to correctly classify normal
and malicious network traffic.
58
security actions. The results and analysis presented here validate the effectiveness
of Deep-IDS in securing IoT environments against cyber threats.
Accuracy Calculation:
Where:
59
Based on the evaluation results from the test dataset, Deep-IDS achieved an
impressive accuracy of approximately 97%, demonstrating its exceptional
performance in detecting intrusions while keeping false positives at a minimum.
60
Figure 6.1: Web Application Home Page
The home page displays key metrics such as the total number of network requests,
the number of intrusions detected, and system health indicators. It serves as a
dashboard for the system administrator to quickly assess the state of the intrusion
detection system.
61
Recall measures the proportion of correctly predicted attacks (true
positives) out of all actual attacks (true positives and false negatives). High
recall indicates that the model correctly identifies most attacks.
Deep-IDS achieved a precision of 95% and recall of 98%, suggesting that the
system is highly effective in both minimizing false alarms and detecting most
attacks.
F1-Score:
The F1-score is the harmonic mean of precision and recall and provides a
balanced measure of the model’s ability to classify both classes correctly.
For Deep-IDS, the F1-score was 96.5%, reflecting the model’s strong
performance in balancing the need for accurate detection without overwhelming
the system with false positives. This high F1-score indicates that the model
effectively minimizes both false positives and false negatives, ensuring reliable
threat detection. The precision-recall trade-off is optimized, allowing the system
to detect even sophisticated attack patterns while maintaining a low false alarm
rate. Additionally, the model's ability to generalize across different network
62
environments makes it suitable for real-world deployment in IoT security
frameworks. Continuous refinements, such as adaptive learning techniques and
enhanced feature selection, can further improve its performance and resilience
against evolving cyber threats.
Confusion Matrix:
The confusion matrix is another critical tool used to evaluate the performance of
classification models. It provides a visual representation of the model’s
predictions compared to the actual labels, detailing the true positives, false
positives, true negatives, and false negatives.
The confusion matrix helps determine if the model is biased toward predicting
one class over the other. A high false positive rate means normal traffic is
63
incorrectly flagged as malicious, leading to unnecessary alerts. Similarly, a high
false negative rate indicates missed attacks, which can compromise security.
Analyzing this matrix allows for fine-tuning the model to improve accuracy and
balance detection.
Signature-Based IDS:
64
Anomaly-Based IDS:
65
6.5 System Performance and Interface Screenshots
This page provides real-time visualizations of the model’s training and validation
accuracy, allowing users to monitor how the model improves as it learns from the
dataset. The interactive graphs help in assessing the convergence and
performance trends over different training epochs.
66
Prediction Page:
This page allows the administrator to see the live predictions made by the CNN
model. Each network packet is classified, and the system provides real-time alerts
when an attack is detected. This page also shows the prediction confidence and
provides insights into the specific type of attack identified.
67
Performance Analysis Page:
This page gives a detailed breakdown of the model’s performance during testing.
It includes graphs, confusion matrices, and detailed numerical metrics, allowing
administrators to evaluate the system’s efficiency and accuracy.
Numerical Metrics: Precise values for accuracy, precision, recall, and F1-score,
allowing administrators to assess the model’s effectiveness in detecting various
types of cyber threats.
By analyzing this data, administrators can fine-tune the model, optimize detection
thresholds, and ensure that Deep-IDS maintains high reliability in real-world
cybersecurity applications
68
Performance Evaluation
This section presents the performance evaluation of the Deep- IDS developed in
this paper. It starts with the evaluation matrices. Then, the confusion matrix was
analyzed to evaluate classification performance. After that, the intrusion detection
rate and the IDS’s response time have been assessed.
Evaluation Metrics
The state-of-the-art machine learning evaluation metrics have been used in this
paper to evaluate the performance of the proposed Deep-IDS. These evaluation
metrics are calculated using True Positive (TP), True Negative (TN), False
Positive (FP), and False Negative (FN) values from the confusion matrix
illustrated in figure. The accuracy, precision, recall (sensitivity), and F1 Score are
defined by equations and respectively. Another evaluation metric is FAR, which
is the False Positive Rate (FPR).
Confusion Matrix
69
Scores, representing the harmonic mean of recall and precision, are 0.980 for
BRF, 0.985 for Benign and DDoS, 0.970 for DoS and RP, and 0.985 for MITM
attacks. In summary, the Deep-IDS exhibits high accuracy, recall, precision, and
F1 scores, indicating its strong performance in classifying different types of
intrusions. The overall performance for each class of the Deep-IDS is listed in
table
Performance Comparison
The Table presents the performance comparison between the proposed Deep-IDS
and other similar approaches. The proposed Deep-IDS demonstrates superior
performance in intrusion detection compared to several existing approaches, as
70
evidenced by a comprehensive performance compar- ison. Deep-IDS
outperforms other notable systems with an accuracy of 97.67%, precision of
97.67%, a recall of 98.17%, and an F1-Score of 97.91%. For instance, Ashiku
et al. reported an accuracy of 94.40% but did not provide figures for precision,
recall, or F1-Score, indicating a narrower focus on accuracy alone. Similarly,
Musleh et al. achieved a commendable balance with 92.40% accuracy, 89.10%
precision, and a 92% F1-Score, yet fell short of the comprehensive performance
metrics offered by Deep-IDS. Notably, Logeswari et al. , and Mebawondu et al.
presented systems with significantly lower overall performance metrics,
highlighting the advanced capabilities of Deep-IDS in handling various intrusion
types effectively. Elsayed et al. and Kumar et al. also proposed systems with high
accuracy rates of 96.56% and 97.45%, respectively, but neither matched the
balanced performance across all metrics achieved by Deep-IDS. This comparison
underscores the robustness and efficiency of Deep-IDS in accurately detecting
and classifying intrusions, setting a new benchmark in the field of cybersecurity
for IoT systems.
6.6 Summary
71
achieved a balanced performance with lower false alarms and better
generalization.
Additionally, the web application interface was reviewed, showcasing its real-
time monitoring capabilities, detailed performance analysis, and interactive user
controls. Screenshots were presented to illustrate how administrators can use the
system for live network analysis and security insights.
Overall, the results confirm that Deep-IDS is a robust, scalable, and future-proof
solution for securing IoT networks against both known and emerging cyber
threats. The next chapter will explore potential improvements, deployment
considerations, and future research directions to further enhance the system’s
effectiveness.
7.1 Conclusion
72
The implementation of Deep-IDS as a web-based application further enhances its
usability, allowing system administrators to monitor real-time traffic, review
performance metrics, and receive alerts when potential intrusions are detected.
The user-friendly interface provides administrators with quick insights into
network security and enables them to take timely action to mitigate risks.
Compared to traditional signature-based and anomaly-based IDS, Deep-IDS
offers superior adaptability, scalability, and accuracy, making it a valuable tool
for securing IoT environments. The system not only enhances the security of IoT
devices but also offers a promising approach for the future development of
intelligent, adaptive IDS solutions in rapidly evolving cyber threat landscapes.
Another area for future work is improving the system’s real-time performance on
resource-constrained IoT devices. Currently, deep learning models, particularly
CNNs, can be computationally intensive. Optimizing the model for deployment
73
on edge devices, perhaps through model pruning, quantization, or knowledge
distillation, would allow Deep-IDS to operate efficiently even with limited
hardware resources. Furthermore, the integration of blockchain technology could
offer an immutable and transparent logging mechanism for intrusion events,
enhancing system security and traceability. Future work could also explore the
integration of Deep-IDS with other security mechanisms, such as intrusion
prevention systems (IPS) and automated response frameworks, to create a more
comprehensive security solution. These advancements would not only improve
the overall performance of Deep-IDS but also broaden its applicability to a wider
range of IoT use cases.
74
Real-World Experiment
The proposed Deep-IDS has been experimented with in a testbed that resembles
a real-world scenario. As a result, the performance of the proposed system is
considered a realistic result. However, a testbed does not encompass a large
perimeter like a realistic environment. It is a significant limitation of the proposed
system.
REFERENCES
75
4. Kumar, S., et al. (2020). "Real-Time Intrusion Detection System for IoT
Using Deep Learning." IEEE Transactions on Network and Service
Management.
5. Sharma, R., et al. (2021). "Hybrid Intrusion Detection System for IoT
Using Deep Learning and Feature Selection." IEEE Transactions on
Information Forensics and Security.
6. Seth, A., et al. (2018). "A Deep Learning Approach for Intrusion Detection
System in IoT Networks." Proceedings of the International Conference on
Cyber Security and Cloud Computing.
7. Saha, B., et al. (2020). "A Comprehensive Review on Security and Privacy
in IoT." IEEE Internet of Things Journal.
8. Cheng, Y., et al. (2019). "Real-Time Intrusion Detection System for IoT
Networks Using Convolutional Neural Networks." IEEE Transactions on
Industrial Informatics.
9. Zhou, T., et al. (2020). "A CNN-Based Intrusion Detection System for IoT
Devices in Smart Homes." IEEE Access.
10. Nguyen, H., et al. (2019). "Anomaly-Based Intrusion Detection System
for IoT Networks." International Journal of Computer Applications.
11. Cai, X., et al. (2017). "IoT Security: Challenges and Solutions for the
Internet of Things." IEEE Communications Magazine.
12. Sivaprasad, S., et al. (2021). "A Novel Hybrid Deep Learning Model for
IoT Intrusion Detection." Journal of Cyber Security.
13. Singh, K., et al. (2019). "IoT-Based Intrusion Detection System Using
Machine Learning Techniques." International Journal of Network
Security.
14. Vasilenko, R., et al. (2020). "Cyber Threat Detection in IoT Networks
Using Machine Learning." Journal of Computer Security.
76
15. Bhattacharya, S., et al. (2021). "A Novel Intrusion Detection System for
IoT Using Convolutional Neural Networks." Computers, Materials &
Continua.
16. Kumar, A., et al. (2020). "IoT Security and Privacy: Challenges and
Solutions." Proceedings of the International Conference on Artificial
Intelligence and Security.
17. Sharma, A., et al. (2020). "Evaluation of Deep Learning Approaches for
Intrusion Detection in IoT Networks." International Journal of Computer
Science and Network Security.
18. Sengupta, S., et al. (2021). "A Hybrid Intrusion Detection Model for IoT
Networks Based on Deep Learning." IEEE Transactions on Neural
Networks and Learning Systems.
19. Zhang, Z., et al. (2019). "A Comparative Study of Machine Learning
Approaches for Intrusion Detection Systems." IEEE Access.
20. Li, H., et al. (2018). "A Survey of Deep Learning Techniques for Network
Intrusion Detection." IEEE Transactions on Information Forensics and
Security.
77