MKesenheimer/fault-injection-library

GitHub: MKesenheimer/fault-injection-library

一个支持低成本硬件的 Python 故障注入攻击库,旨在简化针对微控制器的电压毛刺攻击流程。

Stars: 151 | Forks: 21

# 使用示例 Findus(又名 fault-injection-library)是一个用于对微控制器和其他目标执行故障注入攻击的工具链。 该库为针对微控制器、SoC 和 MCU 执行故障注入攻击提供了一个简单的切入点。 借助提供且易于使用的函数和类,可以使用廉价且易得的硬件快速实现故障注入项目。 Findus 支持 [ChipWhisperer Pro](https://rtfm.newae.com/Capture/ChipWhisperer-Pro/)、[ChipWhisperer Husky](https://rtfm.newae.com/Capture/ChipWhisperer-Husky/) 和 [Pico Glitcher](https://mkesenheimer.github.io/blog/pico-glitcher-v3.html)。 有关 fault-injection-library 和 Pico Glitcher 的更多信息,请访问 [https://fault-injection-library.readthedocs.io/en/latest/](https://fault-injection-library.readthedocs.io/en/latest/)。 ## 目录 - [购买 Pico Glitcher](#purchasing-the-pico-glitcher) - [文档](#documentation) - [安装 findus](#installing-findus) - [更新 Pico Glitcher 固件](#updating-the-pico-glitcher-firmware) - [步骤 1:MicroPython 固件](#step-1-microPython-firmware) - [步骤 2:安装 findus 库](#step-2-install-the-findus-library) - [步骤 3:上传 Pico Glitcher MicroPython 脚本](#step-3-upload-the-pico-glitcher-micropython-script) - [从源码安装](#installing-from-source) - [测试 Pico Glitcher 的功能](#test-the-functionality-of-your-pico-glitcher) - [UART 触发器](#uart-trigger) - [更多示例](#more-examples) - [分析器](#analyzer) ## 购买 Pico Glitcher 只需一个 Raspberry Pi Pico 和少量其他组件即可使用本软件。 然而,为了获得最佳效果,我们开发了一款直接适配 fault-injection-library 的电路板。 该板包含一个 Raspberry Pi Pico、两个用于任意电压输入输出的电平转换器 (level shifter),以及可承受高达 66 安培电流的故障注入晶体管。 在修订版 2 中,增加了一个多路复用级,可在最多四种不同的电压等级之间快速切换。 提供多种电压源连接选项,从 1.8V、3.3V 到 5V。 Pico Glitcher 也可以通过 `VCC_EXTERN` 接入任何外部电压供电。 为了给目标板供电,需通过 `VTARGET` 连接为其提供电源。 该电压源的输出可以通过软件控制,即通过执行 `power_cycle_target()` 命令可以完全切断目标的电源。 这使得在发生无法通过复位消除的错误状态时,能够对目标进行冷启动。 ![组装好的 Pico Glitcher v1](https://github.com/MKesenheimer/fault-injection-library/blob/master/schematics/finished.JPG) Pico Glitcher 可以从 [faultyhardware](https://faultyhardware.de) 在线商店购买。如果您有任何问题或特殊需求,请随时联系我。 ## 文档 有关源代码的文档以及如何使用该库和硬件,可以在 [https://fault-injection-library.readthedocs.io/](https://fault-injection-library.readthedocs.io/) 找到。 ## 安装 findus 如果您只想快速入门,不想费心处理 findus 的源代码,可以通过 pip 安装 findus。findus 库可以在 [https://pypi.org/project/findus/](https://pypi.org/project/findus/) 找到,并可以使用以下命令在本地 Python 环境中安装: ``` mkdir my-fi-project && cd my-fi-project python -m venv .venv source .venv/bin/activate pip install findus ``` 如果您拥有 Riden 的 RK6006 或 RD6006 电源,请安装可选的 RD6006 python 绑定: ``` pip install rd6006 ``` 此外部电源可选择性用于为目标供电。可以通过 findus 库利用电源的 USB 接口控制 RD6006 电源。findus 库中实现了相应的功能函数。 如果您没有此电源也不必担心。Pico Glitcher 也可以为目标提供电压。 现在您可以使用 findus 了: ``` python >>> from findus import Database, PicoGlitcher ... ``` 下一步是复制现有的故障注入脚本并根据您的需求进行调整。 首先复制 [https://github.com/MKesenheimer/fault-injection-library/blob/master/example/pico-glitcher.py](https://github.com/MKesenheimer/fault-injection-library/blob/master/example/pico-glitcher.py)。更多示例项目位于 [https://github.com/MKesenheimer/fault-injection-library/tree/master/projects](https://github.com/MKesenheimer/fault-injection-library/tree/master/projects)。 有关如何使用 findus 和 Pico Glitcher 的更多信息,请参阅 [示例](examples.md)。 ## 更新 Pico Glitcher 固件 您的 Pico Glitcher 出厂时应该已经安装了最新固件。如果没有,请按照以下步骤更新 Pico Glitcher 上的软件。 ### 步骤 1:MicroPython 固件 从 [https://micropython.org/download/RPI_PICO/](https://micropython.org/download/RPI_PICO/) 下载 MicroPython 固件。将 Pico Glitcher 从计算机上拔下,按住 Raspberry Pi Pico 上的 'BOOTSEL' 按钮并重新连接到计算机。Raspberry Pi Pico 应显示为一个闪存存储设备。将 MicroPython 固件('RPI_PICO-xxxxxxxx-vx.xx.x.uf2')复制到此驱动器,直到 Raspberry Pi Pico 自动断开连接。 有关设置 Raspberry Pi Pico 的更多信息,请参阅[此处](https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico)。 ### 步骤 2:安装 findus 库 如果您之前已经安装了 findus,请跳过此步骤。 如果您想确保要安装的库不会与本地 Python 环境冲突,请使用虚拟环境。 通过生成一个新的虚拟环境并激活它来进行设置: ``` python -m venv .venv source .venv/bin/activate ``` 完成这些步骤后,我们需要安装 findus(即 fault-injection-library)。 确保已经[安装](https://docs.python.org/3/library/ensurepip.html) pip。 ``` pip install findus ``` ### 步骤 3:上传 Pico Glitcher MicroPython 脚本 如果一切顺利,您应该可以在命令行环境中执行 `upload` 脚本了。 将 Pico Glitcher 连接到计算机,并检查出现的串口设备: ``` ls /dev/tty* ``` 记下设备路径。接下来通过以下命令上传 Pico Glitcher 固件以及针对您的 Pico Glitcher 硬件版本的特定配置(`config_v1/config.json`、`config_v2.1-2/config.json`、`config_v2.3-4/config.json` 或 `config_v3.0/config.json`): ``` cd .venv/lib/python3.12/site-packages/findus/firmware upload --port /dev/tty. --files AD910X.py FastADC.py Globals.py \ PicoGlitcher.py PulseGenerator.py Spline.py Statemachines.py /config.json ``` 您的 Pico Glitcher 现在应该已准备好执行故障注入攻击了。 ## 从源码安装 如果您想参与开发或访问此仓库的所有资源,请克隆 findus 库: ``` git clone --depth 1 --recurse-submodules \ https://github.com/MKesenheimer/fault-injection-library.git ``` 安装 findus 和可选的 rd6006 库: ``` cd fault-injection-library pip install . cd rd6006 pip install . ``` 然后: ``` cd findus/firmware upload --port /dev/tty. --files AD910X.py FastADC.py Globals.py \ PicoGlitcher.py PulseGenerator.py Spline.py /config.json ``` 下一步是复制现有的故障注入脚本并根据您的需求进行调整。 首先复制 `fault-injection-library/example/pico-glitcher.py`。更多示例项目位于 `fault-injection-library/projects`。 ## 测试 Pico Glitcher 的功能 以下设置可用于测试 Pico Glitcher。 - 将 'TRIGGER' 输入连接到 'RESET'。 - 在 'GLITCH' 和 'VTARGET' 之间连接一个 10 Ohm 电阻(这是本例中的测试目标)。 - 可选地将示波器的通道 1 连接到 'RESET',通道 2 连接到 'GLITCH'。 ![示例设置](https://github.com/MKesenheimer/fault-injection-library/blob/master/docs/images/test-example.png) 接下来,运行位于 `fault-injection-library/example` 的测试脚本 `pico-glitcher.py`: ``` cd example python pico-glitcher.py --rpico /dev/ --delay 1000 1000 --length 100 100 ``` 您现在应该可以通过示波器在 10 Ohm 电阻上观察到故障信号。 使用示波器测量预期的延迟和故障长度。 ## UART 触发器 - 将 'TRIGGER' 输入连接到 USB 转 UART 适配器的 'RX' 和 'TX' - 在 'GLITCH' 和 'VTARGET' 之间连接一个 10 Ohm 电阻(这是本例中的测试目标)。 - 可选地将示波器的通道 1 连接到 'RESET',通道 2 连接到 'GLITCH'。 ![示例设置](https://github.com/MKesenheimer/fault-injection-library/blob/master/docs/images/test-example-uart.png) 接下来,运行位于 `fault-injection-library/example` 的测试脚本 `pico-glitcher-uart.py`: ``` cd example python pico-glitcher-uart.py --rpico /dev/ --target /dev/ --delay 1000 1000 --length 100 100 ``` 您现在应该可以通过示波器在 10 Ohm 电阻上观察到故障信号。 使用示波器测量预期的延迟和故障长度。 ## 更多示例 更多示例可以在 [https://fault-injection-library.readthedocs.io/en/latest/examples/#](https://fault-injection-library.readthedocs.io/en/latest/examples/#) 或 `fault-injection-library/projects` 下找到。 ## 分析器 在您的故障注入活动期间,在单独的终端窗口中运行 `analyzer` 脚本: ``` analyzer --directory databases ``` 这将在 [http://127.0.0.1:8080](http://127.0.0.1:8080) 上启动一个本地 Web 应用程序,可用于观察当前进度。 ![参数空间 Web 应用程序](https://github.com/MKesenheimer/fault-injection-library/blob/master/docs/images/parameterspace-pico-glitcher.png)
标签:ChipWhisperer, IoT安全, MCU安全, MicroPython, Pico Glitcher, Raspberry Pi Pico, SoC安全测试, 侧信道攻击, 固件提取, 密码学硬件, 嵌入式安全, 嵌入式开发, 微控制器攻击, 故障注入, 时钟毛刺, 物理攻击, 电压毛刺, 硬件安全, 逆向工具, 配置错误