Skip to content

Nithinsaim/MedShield-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ MedShield-AI: Intrusion-Aware Adaptive Encryption for IoMT

Python PyTorch IoMT CNN-BiLSTM


πŸ”΄ Problem Statement

The Internet of Medical Things (IoMT) connects medical devices, wearable sensors, and cloud systems to deliver real-time healthcare. This ecosystem transmits highly sensitive patient data β€” ECG signals, EHR records, diagnostic images β€” continuously over networks.

Current security solutions fail because:

  • Traditional encryption (AES, RSA) uses static keys that never adapt to changing threats
  • Intrusion Detection Systems (IDS) detect threats but don't respond β€” encryption continues unchanged even after an attack is flagged
  • IoMT devices are resource-constrained β€” heavy cryptographic methods are impractical
  • Attacks like DDoS, MITM, replay, and data injection are increasingly sophisticated

The result: A detected intrusion does not stop ongoing data exposure. There is no closed-loop between detection and encryption response.


πŸ’‘ Proposed Solution β€” MedShield-AI

A unified, closed-loop security framework that:

  1. Detects threats using a hybrid CNN-BiLSTM model
  2. Classifies threat level (Low / Medium / High) from a continuous probability score
  3. Adapts encryption β€” key size, update frequency β€” based on threat severity
  4. Self-heals β€” automatically re-keys, blocks, and isolates under attack

πŸ—οΈ System Architecture

IoMT Network Traffic
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         PREPROCESSING                β”‚
β”‚  Normalize β†’ One-hot encode β†’        β”‚
β”‚  Correlation-based feature selection β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     CNN (Spatial Feature Extractor)  β”‚
β”‚  Conv β†’ ReLU β†’ MaxPool               β”‚
β”‚  Learns: traffic bursts, patterns    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   BiLSTM (Temporal Sequence Model)   β”‚
β”‚  Forward LSTM + Backward LSTM        β”‚
β”‚  Concatenated: h_t = [β†’h_t ; ←h_t]  β”‚
β”‚  Learns: multi-stage attack patterns β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
   P_threat ∈ [0,1]  (sigmoid output)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ P < Ξ± β†’ LOW      β”‚ AES-128, slow rekeyβ”‚
β”‚ Ξ± ≀ P < Ξ² β†’ MED  β”‚ AES-256, rekey    β”‚
β”‚ P β‰₯ Ξ² β†’ HIGH     β”‚ AES-256, rekey +  β”‚
β”‚                  β”‚ block + isolate   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
ECDH Key Exchange β†’ KDF(K, context) β†’ AES Encryption
        β”‚
        β–Ό
Self-Healing: Isolate β†’ Re-key β†’ Restore channel

πŸ“ Repository Structure

MedShield-AI/
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ cnn_bilstm_ids.py        # Hybrid CNN-BiLSTM intrusion detection model
β”‚   β”œβ”€β”€ threat_classifier.py     # Threshold-based threat level classification
β”‚   β”œβ”€β”€ adaptive_encryption.py   # AES + ECDH + dynamic re-keying
β”‚   β”œβ”€β”€ key_derivation.py        # KDF with contextual binding
β”‚   β”œβ”€β”€ self_healing.py          # Automated response & recovery module
β”‚   β”œβ”€β”€ preprocessing.py         # Feature normalization & selection
β”‚   └── train.py                 # Training pipeline
β”œβ”€β”€ notebooks/
β”‚   └── MedShieldAI_Demo.ipynb
β”œβ”€β”€ results/
β”‚   └── metrics.json
β”œβ”€β”€ images/
β”‚   └── system_architecture.png
└── LICENSE

βš™οΈ Methods

1. CNN-BiLSTM Intrusion Detection

CNN β€” Spatial Feature Extraction:

F_k = ReLU(W_k * X' + b_k)     # Convolution
P_k = MaxPool(F_k)               # Dimensionality reduction

Captures discriminative patterns: abnormal traffic bursts, irregular packet structures.

BiLSTM β€” Temporal Modeling:

β†’h_t = LSTM(P_t, β†’h_{t-1})      # Forward pass
←h_t = LSTM(P_t, ←h_{t+1})      # Backward pass
h_t  = [β†’h_t ; ←h_t]            # Concatenated representation

Models past + future context simultaneously β€” effective against multi-stage attacks.

Threat Probability Output:

P_threat = sigmoid(W_o · h_t + b_o)    # ∈ [0, 1]

Loss Function:

L = -(1/N) Ξ£ [y_iΒ·log(P_i) + (1-y_i)Β·log(1-P_i)]   # Binary cross-entropy

Optimized with Adam optimizer.


2. Threat-Aware Encryption Policy

Threat Level Condition AES Key Size Re-key Interval Response
Low P_threat < Ξ± AES-128 Slow Monitor
Medium Ξ± ≀ P < Ξ² AES-256 Moderate Re-key
High P_threat β‰₯ Ξ² AES-256 Rapid Re-key + Block + Isolate

Key update interval adapts automatically:

t_update = 1 / (1 + P_threat)

Higher threat β†’ shorter interval β†’ more frequent key rotation.


3. Secure Key Exchange β€” ECDH

Q_A = d_A Β· G       # Device A public key
Q_B = d_B Β· G       # Device B public key
K   = d_A Β· Q_B     # Shared secret (never transmitted)
    = d_B Β· Q_A

Key Derivation with Contextual Binding:

K_enc = KDF(K, [timestamp, session_id, device_id, threat_level])

Every session uses a unique derived key β€” forward secrecy guaranteed.


4. Dynamic Re-Keying

K_new = KDF(K_old, P_threat, t)

Compromised keys are replaced automatically. Past sessions remain secure.


5. Self-Healing Mechanism

State Machine: Normal β†’ Suspicious β†’ Compromised
                                         β”‚
                              Filter malicious traffic:
                              X_safe = X \ X_malicious
                                         β”‚
                              Regenerate keys + re-establish channel:
                              C_new = AES(K_new, M)

πŸ“Š Evaluation

Intrusion Detection Metrics: Accuracy, Precision, Recall, F1-Score
System Metrics: Latency, Computational Overhead
Datasets: Benchmark network intrusion detection datasets (normal + malicious traffic)


πŸš€ Getting Started

pip install -r requirements.txt

Train the IDS Model

python src/train.py --epochs 50 --lr 1e-3

Run Adaptive Encryption Demo

python src/adaptive_encryption.py --threat_level high

Full Pipeline

python src/self_healing.py --mode demo

πŸ“¦ requirements.txt

See requirements.txt for full dependencies.


πŸ“ Amrita Vishwa Vidyapeetham, Coimbatore, Tamil Nadu

About

πŸ›‘οΈ Intrusion-Aware Adaptive Encryption for IoMT | CNN-BiLSTM IDS + ECDH + AES + Self-Healing

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages