Kopie von Keyven/CanDefender-Fuzzy
Browse files- Fuzzy-Tensor.png +0 -0
- README.md +83 -0
- candefender_fuzzy_final.pt +3 -0
Fuzzy-Tensor.png
ADDED
|
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-nd-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- de
|
| 6 |
+
tags:
|
| 7 |
+
- automotive
|
| 8 |
+
- IDS
|
| 9 |
+
- CAN
|
| 10 |
+
- CANIDS
|
| 11 |
+
- AutomotiveSecurity
|
| 12 |
+
- Cybersecurity
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# CANDefender – Fuzzy Attack Detection Model
|
| 16 |
+
|
| 17 |
+
**Model Summary**
|
| 18 |
+
This model detects **Fuzzy attacks** on the CAN bus. It was trained on **4.73 million** real CAN frames, including normal data and Fuzzy-labeled data. The model uses an LSTM architecture that processes the CAN ID and 8-byte payload to classify each frame as either “Fuzzy” or “Normal.”
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
## Performance
|
| 23 |
+
|
| 24 |
+
**Test Accuracy**: ~94.09%
|
| 25 |
+
**Confusion Matrix** (Fuzzy vs. Normal):
|
| 26 |
+
|
| 27 |
+
| True \ Pred | Fuzzy (pred) | Normal (pred) |
|
| 28 |
+
|:-----------:|:-------------:|:-------------:|
|
| 29 |
+
| **Fuzzy** | 3,737,645 | 13,379 |
|
| 30 |
+
| **Normal** | 266,808 | 722,063 |
|
| 31 |
+
|
| 32 |
+
- **Recall (Fuzzy)**: ~99.6% (very few Fuzzy frames missed)
|
| 33 |
+
- **Recall (Normal)**: ~73% (about 27% false positives on Normal)
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## Intended Use
|
| 38 |
+
|
| 39 |
+
- **Goal**: Real-time detection of **Fuzzy attacks** on the CAN bus.
|
| 40 |
+
- **Limitations**:
|
| 41 |
+
- Focused on Fuzzy vs. Normal classification only (other attacks handled in separate models).
|
| 42 |
+
- Tends to misclassify ~27% of normal frames as Fuzzy (relatively high false alarms).
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## How to Use
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
import torch
|
| 50 |
+
import numpy as np
|
| 51 |
+
from can_defender_fuzzy import CANLSTM # Adjust import name
|
| 52 |
+
|
| 53 |
+
# Example frame => [CAN_ID, b0..b7]
|
| 54 |
+
frame = [0x315, 0x12, 0x4F, 0xA2, 0x00, 0x00, 0x78, 0x1C, 0xAA]
|
| 55 |
+
|
| 56 |
+
x_np = np.array(frame, dtype=np.float32).reshape(1,1,9)
|
| 57 |
+
|
| 58 |
+
model = CANLSTM(input_dim=9, hidden_dim=64, num_classes=2)
|
| 59 |
+
model.load_state_dict(torch.load("can_lstm_model_final.pt"))
|
| 60 |
+
model.eval()
|
| 61 |
+
|
| 62 |
+
with torch.no_grad():
|
| 63 |
+
logits = model(torch.from_numpy(x_np))
|
| 64 |
+
pred = torch.argmax(logits, dim=1).item()
|
| 65 |
+
print("Prediction:", "Fuzzy" if pred == 0 else "Normal")
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Training Configuration
|
| 69 |
+
- Architecture: LSTM (64 hidden units), final linear layer → 2 classes (Fuzzy vs. Normal)
|
| 70 |
+
- Optimizer: Adam (lr=1e-3)
|
| 71 |
+
- Epochs: ~30 (stopped once performance stabilized)
|
| 72 |
+
- Dataset: 4.73 million CAN frames
|
| 73 |
+
## Limitations & Next Steps
|
| 74 |
+
- False Positives: ~27% of normal frames get labeled as Fuzzy. Acceptable for high-sensitivity scenarios, but can be improved (weighted loss, time-window approach, etc.).
|
| 75 |
+
- Scope: Only focuses on Fuzzy detection. Other attacks (DoS, Gear, RPM) are separate.
|
| 76 |
+
# Potential Enhancements:
|
| 77 |
+
- Weighted training or additional features (delta-time, frequency)
|
| 78 |
+
- Window-based LSTM or transformers for sequence data
|
| 79 |
+
|
| 80 |
+
## License & Contact
|
| 81 |
+
- License: cc-by-nc-nd-4.0
|
| 82 |
+
- Author: Keyvan Hardani
|
| 83 |
+
- Contact: https://www.linkedin.com/in/keyvanhardani/
|
candefender_fuzzy_final.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6f2cb50b86baae1ea7536c8db386b2b45c76ed7cccefb13953b66e5f6a83a961
|
| 3 |
+
size 79471
|