IslandCreatureCTU/Pi-Defender

GitHub: IslandCreatureCTU/Pi-Defender

一个基于树莓派CPU侧信道的CNN模型指纹识别攻击与对抗性噪声防御研究项目。

Stars: 3 | Forks: 0

# PI-Defender 一个关于 Raspberry Pi CPU 侧信道指纹识别的研究项目,旨在实现 **CNN 模型识别(攻击)** 与 **对抗性噪声防御**。 完整数据流: ``` [Raspberry Pi] [Workstation / GPU] collect_cpu_trace.py ─┐ ├─► cpu_usage.csv ─────────────┐ run_inference_workload.py ─► model_prediction_timestamps.csv │ 01_preprocess_align_label.ipynb │ model_usage.csv │ ┌─────────────────────────────┼───────────────────────┐ ▼ ▼ ▼ 02_eda_plot_traces.ipynb 03_train_attack_classifier.ipynb (frozen attacker) │ ┌─────────────────────────┤ ▼ ▼ ▼ 04_defender_noise_v1 / _v2 / _v3 .ipynb ``` ## 目录结构 ``` pi-defender/ ├── collection/ # Run on Raspberry Pi (two scripts concurrently) │ ├── collect_cpu_trace.py # Victim side: record CPU usage │ └── run_inference_workload.py # Workload: run CNN inference and record timestamps ├── common/ # Shared code (removes duplicate model definitions) │ ├── models.py # Attacker classifiers: LSTM / Transformer / LSTM+Transformer │ ├── data_utils.py # Load / encode / window / augment / Dataset │ └── noise_models.py # Defender noise generators v1 / v2 / v3 + adversarial loss ├── notebooks/ # Run on workstation │ ├── 01_preprocess_align_label.ipynb │ ├── 02_eda_plot_traces.ipynb │ ├── 03_train_attack_classifier.ipynb │ ├── 04_defender_noise_v1.ipynb # Minimal LSTM │ ├── 04_defender_noise_v2.ipynb # BiLSTM + self-attention │ └── 04_defender_noise_v3.ipynb # BiLSTM + Transformer (progressive staged training) ├── requirements.txt # Workstation full environment └── requirements-pi.txt # Raspberry Pi minimal dependencies ``` ## 快速开始 **1. 在 Raspberry Pi 上采集数据**(在两个独立的终端中运行以下脚本) ``` pip install -r requirements-pi.txt python collection/collect_cpu_trace.py --interval 0.1 --duration 7200 -o cpu_usage.csv # 在另一个终端中: python collection/run_inference_workload.py --backend tensorflow --tier light \ --epochs 50 --images ./homemade -o model_prediction_timestamps.csv ``` `--tier` 对应 Raspberry Pi 5 上可行的模型层级:`light`(轻量且快速)、`mid`、`heavy`(推荐 8GB+ 内存)以及 `all`(全部 40 个模型)。 `--backend` 可以是 `tensorflow` / `torch` / `jax`;相同的代码和模型集使得跨框架比较 traces 是否易于区分变得十分方便。`--threads` 用于固定工作线程的数量,以确保不同 backend 之间的可比性。 **2. 在工作站上进行分析和训练** ``` pip install -r requirements.txt jupyter lab # Launch from repo root so notebooks can import common/ ``` 按顺序运行 notebooks:`notebooks/01 → 02 → 03 → 04_*`。 ## 数据格式 | 文件 | 列 | |---|---| | `cpu_usage.csv` | `Timestamp`(epoch 秒)、`CPU Usage (%)` | | `model_prediction_timestamps.csv` | `Model Name`、`Start Time`、`End Time`、`epoch` | | `model_usage.csv` | `model`、`epoch`、`Timestamp`(自重置以来的纳秒数)、`CPU Usage (%)` | ## v1.1 的主要更新 - 攻击模型(`PositionalEncoding` / `TransformerBlock` / `LSTMTransformerModel`)之前在四个 notebooks 中被重复定义了约六次;现在已统一整合到 `common/models.py` 中。 - 三个噪声生成器 notebooks 合并到了 `noise_models.py` 中(包含 v1 / v2 / v3 类),使 notebooks 精简到仅保留训练流程。 - 工作负载生成器现在包含感知模型族(family-aware)的预处理、原生输入尺寸、backend 切换以及层级选择。 - 预处理方式从 O(N) 的逐行 `pd.concat` 改为使用 `searchsorted` 和单次 `concat` 的向量化切片。
标签:AI安全, Apex, Chat Copilot, CNN, NoSQL, 侧信道分析, 凭据扫描, 对抗防御, 机器学习, 模型指纹提取, 逆向工具, 防御绕过