Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- README.md +16 -11
- app.py +127 -0
- data/cybersecurity_intrusions.csv +0 -0
- requirements.txt +5 -0
README.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
| 1 |
-
|
| 2 |
-
title: Intrusion Dashboard
|
| 3 |
-
emoji: ๐ฆ
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: indigo
|
| 6 |
-
sdk: streamlit
|
| 7 |
-
sdk_version: 1.43.2
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Intrusion Detection Dashboard
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
## Overview
|
| 4 |
+
This web app is an interactive dashboard that allows users to explore network session data and predict whether a session is likely to be a cyberattack. The prediction is powered by a LightGBM machine learning model, trained on an intrusion detection dataset and deployed via a Flask AP on Hugging Face Spaces.
|
| 5 |
+
|
| 6 |
+
## Model Info
|
| 7 |
+
- Model: LightGBM
|
| 8 |
+
- Recall: 87.1%
|
| 9 |
+
- Precision: 62.5%
|
| 10 |
+
- F1 Score: 73.0%
|
| 11 |
+
- Threshold: 0.2
|
| 12 |
+
|
| 13 |
+
## Features
|
| 14 |
+
- Interactive Filtering: View attack distributions by protocol and encryption type.
|
| 15 |
+
- Visualization: Explore traffic patterns and protocol frequency.
|
| 16 |
+
- Real-time Prediction: Input session characteristics to predict if it's likely an intrusion.
|
| 17 |
+
- API Integration: Connects to a Flask API deployed on Hugging Face Spaces.
|
app.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import altair as alt
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
import requests
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
#######################
|
| 9 |
+
# Page Configuration
|
| 10 |
+
st.set_page_config(
|
| 11 |
+
page_title="Intrusion Detection Dashboard",
|
| 12 |
+
page_icon="๐ก๏ธ",
|
| 13 |
+
layout="wide",
|
| 14 |
+
initial_sidebar_state="expanded"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
alt.themes.enable("dark")
|
| 18 |
+
|
| 19 |
+
#######################
|
| 20 |
+
# Load Intrusion Detection Data
|
| 21 |
+
df_intrusions = pd.read_csv('data/cybersecurity_intrusions.csv')
|
| 22 |
+
|
| 23 |
+
#######################
|
| 24 |
+
# Sidebar Filters
|
| 25 |
+
with st.sidebar:
|
| 26 |
+
st.title('๐ก๏ธ Intrusion Detection Dashboard')
|
| 27 |
+
|
| 28 |
+
st.markdown("### This app predicts whether a network session is likely to be a cyberattack based on session characteristics such as packet size, login attemps, and IP reputation. Powered by a LightGBM model trained on labeled intrusion data.")
|
| 29 |
+
|
| 30 |
+
st.markdown("### Model Info")
|
| 31 |
+
st.markdown("""
|
| 32 |
+
- **Model:** LightGBM Classifier
|
| 33 |
+
- **Recall:** 87.1%
|
| 34 |
+
- **Precision:** 62.8%
|
| 35 |
+
- **F1 Score:** 73.0%
|
| 36 |
+
- **Threshold:** 0.2 (favor recall over precision)
|
| 37 |
+
""")
|
| 38 |
+
|
| 39 |
+
#######################
|
| 40 |
+
# Model Overview Section
|
| 41 |
+
|
| 42 |
+
st.markdown("### About This App")
|
| 43 |
+
st.markdown("""
|
| 44 |
+
This app predicts whether a network session is likely to be a cyberattack based on session-level characteristics
|
| 45 |
+
like packet size, login attempts, encryption type, and IP reputation score.
|
| 46 |
+
|
| 47 |
+
The underlying model was trained on a labeled intrusion detection dataset using LightGBM, a fast and accurate gradient boosting framework.
|
| 48 |
+
This project demonstrates real-time predictions via a deployed API, and provides insight into the features most correlated with attack behavior.
|
| 49 |
+
""")
|
| 50 |
+
|
| 51 |
+
#######################
|
| 52 |
+
# Intrusion Prediction Using API
|
| 53 |
+
st.markdown("### ๐ Intrusion Detection Prediction")
|
| 54 |
+
|
| 55 |
+
# Input fields for real-time attack detection
|
| 56 |
+
protocol_type = st.selectbox("Protocol Type", ["TCP", "UDP", "ICMP"])
|
| 57 |
+
encryption_used = st.selectbox("Encryption Used", ["AES", "DES", "None"])
|
| 58 |
+
packet_size = st.number_input("Network Packet Size", value=500)
|
| 59 |
+
login_attempts = st.number_input("Login Attempts", value=3)
|
| 60 |
+
session_duration = st.number_input("Session Duration", value=500.0)
|
| 61 |
+
ip_reputation = st.number_input("IP Reputation Score", value=0.5)
|
| 62 |
+
failed_logins = st.number_input("Failed Logins", value=1)
|
| 63 |
+
unusual_access = st.checkbox("Unusual Time Access")
|
| 64 |
+
|
| 65 |
+
# Manually apply one-hot encoding
|
| 66 |
+
protocol_tcp = 1 if protocol_type == "TCP" else 0
|
| 67 |
+
protocol_udp = 1 if protocol_type == "UDP" else 0
|
| 68 |
+
encryption_des = 1 if encryption_used == "DES" else 0
|
| 69 |
+
encryption_none = 1 if encryption_used == "None" else 0
|
| 70 |
+
|
| 71 |
+
# API URL
|
| 72 |
+
API_URL = "https://e-eeeema-intrusion-detection.hf.space/predict"
|
| 73 |
+
|
| 74 |
+
if st.button("Predict Attack"):
|
| 75 |
+
features = [
|
| 76 |
+
packet_size,
|
| 77 |
+
login_attempts,
|
| 78 |
+
session_duration,
|
| 79 |
+
ip_reputation,
|
| 80 |
+
failed_logins,
|
| 81 |
+
int(unusual_access),
|
| 82 |
+
protocol_tcp,
|
| 83 |
+
protocol_udp,
|
| 84 |
+
encryption_des,
|
| 85 |
+
encryption_none
|
| 86 |
+
]
|
| 87 |
+
|
| 88 |
+
response = requests.post(API_URL, json={"features": features})
|
| 89 |
+
|
| 90 |
+
if response.status_code == 200:
|
| 91 |
+
result = response.json()
|
| 92 |
+
prediction = response.json().get("attack_detected", 0)
|
| 93 |
+
probability = result.get("probability", 0.0)
|
| 94 |
+
|
| 95 |
+
st.markdown(f"**๐งฎ Prediction Confidence:** `{probability*100:.2f}%`")
|
| 96 |
+
|
| 97 |
+
if prediction == 1:
|
| 98 |
+
st.error("๐จ Attack Detected!")
|
| 99 |
+
st.markdown("""
|
| 100 |
+
> **Why?** The model flagged this session as an intrusion based on a combination of:
|
| 101 |
+
- Suspicious IP reputation
|
| 102 |
+
- Multiple failed login attempts
|
| 103 |
+
- Unusual access time or weak encryption
|
| 104 |
+
""")
|
| 105 |
+
else:
|
| 106 |
+
st.success("โ
No Attack Detected.")
|
| 107 |
+
st.markdown("> **Why?** The session appears typical and shows no strong indicators of intrusion.")
|
| 108 |
+
|
| 109 |
+
# Confidence interpretation
|
| 110 |
+
if probability >= 0.7:
|
| 111 |
+
st.info("๐ High model confidence in this prediction.")
|
| 112 |
+
elif probability >= 0.4:
|
| 113 |
+
st.warning("โ ๏ธ Medium confidence โ results should be interpreted with caution.")
|
| 114 |
+
else:
|
| 115 |
+
st.warning("โ Low confidence โ the model is uncertain about this prediction.")
|
| 116 |
+
else:
|
| 117 |
+
st.error("โ ๏ธ API request failed. Please check the API URL.")
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
#######################
|
| 121 |
+
# Resources
|
| 122 |
+
|
| 123 |
+
st.markdown("#### ๐ Resources")
|
| 124 |
+
st.markdown("""
|
| 125 |
+
- ๐ [View Model Training Code on GitHub](https://github.com/butlerem/intrusion-detection-model-lgbm/blob/main/intrusion_detector.ipynb)
|
| 126 |
+
- ๐ [View Kaggle Dataset](https://www.kaggle.com/code/nukimayasari/cybersecurity-intrusion)
|
| 127 |
+
""")
|
data/cybersecurity_intrusions.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
altair
|
| 4 |
+
plotly
|
| 5 |
+
requests
|