用于UEFI固件的各种数据结构和分析工具。
uefi_firmware的Python项目详细描述
UEFI固件解析器是一个简单的模块和一组脚本,用于解析、提取, 以及重新创建UEFI固件卷。 这包括分析bios、optionrom、intel me和其他格式的模块。 请使用示例脚本解析教程。
安装
这个模块作为uefi_firmware包含在pypy中
$ sudo pip install uefi_firmware
要从github安装,请签出此repo并使用:
$ sudo python ./setup.py install
要求
- python开发头,通常位于python-dev包中。
- 压缩/解压功能将使用python头和gcc。
- pefile是可选的,可用于其他分析。
用法
使用模块检测或分析固件的最简单方法是通过AutoParser类。
import uefi_firmware with open('/path/to/firmware.rom', 'r') as fh: file_content = fh.read() parser = uefi_firmware.AutoParser(file_content) if parser.type() != 'unknown': firmware = parser.parse() firmware.showinfo()
在uefi、pfs、me和flash包中有几个类 接受其构造函数中的文件内容。在所有情况下都会实现抽象方法:
- process()执行分析工作并返回True或False
- showinfo()打印有关结构的信息层次结构
- dump()遍历层次结构并将每个层次结构写入文件
脚本
已安装python脚本uefi-firmware-parser
$ uefi-firmware-parser -h usage: uefi-firmware-parser [-h] [-b] [--superbrute] [-q] [-o OUTPUT] [-O] [-c] [-e] [-g GENERATE] [--test] file [file ...] Parse, and optionally output, details and data on UEFI-related firmware. positional arguments: file The file(s) to work on optional arguments: -h, --help show this help message and exit -b, --brute The input is a blob and may contain FV headers. --superbrute The input is a blob and may contain any sort of firmware object -q, --quiet Do not show info. -o OUTPUT, --output OUTPUT Dump firmware objects to this folder. -O, --outputfolder Dump firmware objects to a folder based on filename ${FILENAME}_output/ -c, --echo Echo the filename before parsing or extracting. -e, --extract Extract all files/sections/volumes. -g GENERATE, --generate GENERATE Generate a FDF, implies extraction (volumes only) --test Test file parsing, output name/success.
测试文件或文件目录:
$ uefi-firmware-parser --test ~/firmware/* ~/firmware/970E32_1.40: UEFIFirmwareVolume ~/firmware/CO5975P.BIO: EFICapsule ~/firmware/me-03.obj: IntelME ~/firmware/O990-A03.exe: None ~/firmware/O990-A03.exe.hdr: DellPFS
如果需要解析和提取大量固件文件,请检查-O选项,以自动生成每个文件的输出文件夹。如果解析和搜索shell中的内部内容,--echo选项将在解析之前打印输入文件名。
固件类型检查器将决定如何最好地分析文件。如果--test选项无法识别类型,或调用它unknown,请尝试使用-b或--superbrute选项。后者执行逐字节类型检查。
$ uefi-firmware-parser --type ~/firmware/970E32_1.40 ~/firmware/970E32_1.40: unknown $ uefi-firmware-parser --superbrute ~/firmware/970E32_1.40 [...]
功能
- UEFI固件卷、胶囊、文件系统、文件、解析部分
- 英特尔PCH闪存描述符
- 英特尔ME模块解析(ME、TXE等)
- Dell PFS(HDR)更新解析
- tiano/efi和本地lzma(7z)[de]压缩
- 完整的UEFI固件卷对象层次结构显示
- 使用解析的输入卷重新生成固件描述符
- 固件文件部分注入
guid注入
注入或guid替换(还没有加减操作)可以在uefi固件文件中的节上执行,也可以在固件文件系统中的uefi固件文件上执行。
$ python ./scripts/fv_injector.py -h usage: fv_injector.py [-h] [-c] [-p] [-f] [--guid GUID] --injection INJECTION [-o OUTPUT] file Search a file for UEFI firmware volumes, parse and output. positional arguments: file The file to work on optional arguments: -h, --help show this help message and exit -c, --capsule The input file is a firmware capsule. -p, --pfs The input file is a Dell PFS. -f, --ff Inject payload into firmware file. --guid GUID GUID to replace (inject). --injection INJECTION Pre-generated EFI file to inject. -o OUTPUT, --output OUTPUT Name of the output file.
注意:当注入固件文件时,系统会提示用户要替换哪个部分。目前,这还无法编写脚本。
ida python支持
有一个包含的脚本来生成额外的guid标签以导入ida python 使用陷阱的插件。使用-g LABEL,脚本将生成python字典格式的输出。此项目将尝试自动更新流行的供应商guid。
$ python ./scripts/uefi_guids.py -h usage: uefi_guids.py [-h] [-c] [-b] [-d] [-g GENERATE] [-u] file Output GUIDs for files, optionally write GUID structure file. positional arguments: file The file to work on optional arguments: -h, --help show this help message and exit -c, --capsule The input file is a firmware capsule, do not search. -b, --brute The input file is a blob, search for firmware volume headers. -d, --flash The input file is a flash descriptor. -g GENERATE, --generate GENERATE Generate a behemoth-style GUID output. -u, --unknowns When generating also print unknowns.
支持的供应商
此模块已在以下供应商的BIOS/UEFI/固件更新上测试。 不是每个产品的每个更新都会解析,有些可能需要先验解压 或者从分发更新机制中提取(通常是pe)。
- 阿斯洛克
- 戴尔
- 千兆字节
- 英特尔
- 联想
- 惠普
- 微星
- vmware
- 苹果