UEFI Firmware Parser: Parse BIOS/Intel ME/UEFI firmware related structures

UEFI Firmware Parser

The UEFI firmware parser is a simple module and set of scripts for parsing, extracting, and recreating UEFI firmware volumes. This includes parsing modules for BIOS, OptionROM, Intel ME and other formats too. Please use the example scripts for parsing tutorials.

Features

  • UEFI Firmware Volumes, Capsules, FileSystems, Files, Sections parsing
  • Intel PCH Flash Descriptors
  • Intel ME modules parsing (ME, TXE, etc)
  • Dell PFS (HDR) updates parsing
  • Tiano/EFI, and native LZMA (7z) [de]compression
  • Complete UEFI Firmware volume object hierarchy display
  • Firmware descriptor [re]generation using the parsed input volumes
  • Firmware File Section injection

Supported Vendors

This module has been tested on BIOS/UEFI/firmware updates from the following vendors. Not every update for every product will parse, some may require a-priori decompression or extraction from the distribution update mechanism (typically a PE).

  • ASRock
  • Dell
  • Gigabyte
  • Intel
  • Lenovo
  • HP
  • MSI
  • VMware
  • Apple

Install

sudo pip install uefi_firmware

or

git clone https://github.com/theopolis/uefi-firmware-parser.git
sudo python ./setup.py install

Use

The simplest way to use the module to detect or parse firmware is through the AutoParser class.

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”import%20uefi_firmware%0Awith%20open(‘%2Fpath%2Fto%2Ffirmware.rom’%2C%20’r’)%20as%20fh%3A%0A%20%20file_content%20%3D%20fh.read()%0Aparser%20%3D%20uefi_firmware.AutoParser(file_content)%0Aif%20parser.type()%20!%3D%20’unknown’%3A%0A%20%20firmware%20%3D%20parser.parse()%0A%20%20firmware.showinfo()”/]

There are several classes within the uefipfsme, and flash packages that accept file contents in their constructor. In all cases there are abstract methods implemented:

  • process() performs parsing work and returns a True or False
  • showinfo() print a hierarchy of information about the structure
  • dump() walk the hierarchy and write each to a file

Scripts

A Python script is installed uefi-firmware-parser

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20uefi-firmware-parser%20-h%0Ausage%3A%20uefi-firmware-parser%20%5B-h%5D%20%5B-b%5D%20%5B–superbrute%5D%20%5B-q%5D%20%5B-o%20OUTPUT%5D%20%5B-O%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B-c%5D%20%5B-e%5D%20%5B-g%20GENERATE%5D%20%5B–test%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20file%20%5Bfile%20…%5D%0A%0AParse%2C%20and%20optionally%20output%2C%20details%20and%20data%20on%20UEFI-related%20firmware.%0A%0Apositional%20arguments%3A%0A%20%20file%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20file(s)%20to%20work%20on%0A%0Aoptional%20arguments%3A%0A%20%20-h%2C%20–help%20%20%20%20%20%20%20%20%20%20%20%20show%20this%20help%20message%20and%20exit%0A%20%20-b%2C%20–brute%20%20%20%20%20%20%20%20%20%20%20The%20input%20is%20a%20blob%20and%20may%20contain%20FV%20headers.%0A%20%20–superbrute%20%20%20%20%20%20%20%20%20%20The%20input%20is%20a%20blob%20and%20may%20contain%20any%20sort%20of%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20firmware%20object%0A%20%20-q%2C%20–quiet%20%20%20%20%20%20%20%20%20%20%20Do%20not%20show%20info.%0A%20%20-o%20OUTPUT%2C%20–output%20OUTPUT%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Dump%20firmware%20objects%20to%20this%20folder.%0A%20%20-O%2C%20–outputfolder%20%20%20%20Dump%20firmware%20objects%20to%20a%20folder%20based%20on%20filename%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%7BFILENAME%7D_output%2F%0A%20%20-c%2C%20–echo%20%20%20%20%20%20%20%20%20%20%20%20Echo%20the%20filename%20before%20parsing%20or%20extracting.%0A%20%20-e%2C%20–extract%20%20%20%20%20%20%20%20%20Extract%20all%20files%2Fsections%2Fvolumes.%0A%20%20-g%20GENERATE%2C%20–generate%20GENERATE%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Generate%20a%20FDF%2C%20implies%20extraction%20(volumes%20only)%0A%20%20–test%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Test%20file%20parsing%2C%20output%20name%2Fsuccess.”/]

To test a file or directory of files:

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20uefi-firmware-parser%20–test%20~%2Ffirmware%2F*%0A~%2Ffirmware%2F970E32_1.40%3A%20UEFIFirmwareVolume%0A~%2Ffirmware%2FCO5975P.BIO%3A%20EFICapsule%0A~%2Ffirmware%2Fme-03.obj%3A%20IntelME%0A~%2Ffirmware%2FO990-A03.exe%3A%20None%0A~%2Ffirmware%2FO990-A03.exe.hdr%3A%20DellPFS”/]

If you need to parse and extract a large number of firmware files check out the -O option to auto-generate an output folder per file. If parsing and searching for internals in a shell the –echo option will print the input filename before parsing.

The firmware-type checker will decide how to best parse the file. If the –test option fails to identify the type, or calls is unknown, try to use the -b or –superbrute option. The latter performs a byte-by-byte type checker.

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20uefi-firmware-parser%20–test%20~%2Ffirmware%2F970E32_1.40%0A~%2Ffirmware%2F970E32_1.40%3A%20unknown%0A%24%20uefi-firmware-parser%20–superbrute%20~%2Ffirmware%2F970E32_1.40%0A%5B…%5D”/]

GUID Injection

Injection or GUID replacement (no addition/subtraction yet) can be performed on sections within a UEFI firmware file, or on UEFI firmware files within a firmware filesystem.

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20python%20.%2Fscripts%2Ffv_injector.py%20-h%0Ausage%3A%20fv_injector.py%20%5B-h%5D%20%5B-c%5D%20%5B-p%5D%20%5B-f%5D%20%5B–guid%20GUID%5D%20–injection%20INJECTION%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B-o%20OUTPUT%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20file%0A%0ASearch%20a%20file%20for%20UEFI%20firmware%20volumes%2C%20parse%20and%20output.%0A%0Apositional%20arguments%3A%0A%20%20file%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20file%20to%20work%20on%0A%0Aoptional%20arguments%3A%0A%20%20-h%2C%20–help%20%20%20%20%20%20%20%20%20%20%20%20show%20this%20help%20message%20and%20exit%0A%20%20-c%2C%20–capsule%20%20%20%20%20%20%20%20%20The%20input%20file%20is%20a%20firmware%20capsule.%0A%20%20-p%2C%20–pfs%20%20%20%20%20%20%20%20%20%20%20%20%20The%20input%20file%20is%20a%20Dell%20PFS.%0A%20%20-f%2C%20–ff%20%20%20%20%20%20%20%20%20%20%20%20%20%20Inject%20payload%20into%20firmware%20file.%0A%20%20–guid%20GUID%20%20%20%20%20%20%20%20%20%20%20GUID%20to%20replace%20(inject).%0A%20%20–injection%20INJECTION%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Pre-generated%20EFI%20file%20to%20inject.%0A%20%20-o%20OUTPUT%2C%20–output%20OUTPUT%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Name%20of%20the%20output%20file.”/]

Note: when injecting into a firmware file the user will be prompted for which section to replace. At the moment this is not-yet-scriptable.

IDA Python support

There is an included script to generate additional GUID labels to import into IDA Python using Snare’s plugins. Using the -g LABEL the script will generate a Python dictionary-formatted output. This project will try to keep up-to-date with popular vendor GUIDs automatically.

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%24%20python%20.%2Fscripts%2Fuefi_guids.py%20-h%0Ausage%3A%20uefi_guids.py%20%5B-h%5D%20%5B-c%5D%20%5B-b%5D%20%5B-d%5D%20%5B-g%20GENERATE%5D%20%5B-u%5D%20file%0A%0AOutput%20GUIDs%20for%20files%2C%20optionally%20write%20GUID%20structure%20file.%0A%0Apositional%20arguments%3A%0A%20%20file%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20file%20to%20work%20on%0A%0Aoptional%20arguments%3A%0A%20%20-h%2C%20–help%20%20%20%20%20%20%20%20%20%20%20%20show%20this%20help%20message%20and%20exit%0A%20%20-c%2C%20–capsule%20%20%20%20%20%20%20%20%20The%20input%20file%20is%20a%20firmware%20capsule%2C%20do%20not%20search.%0A%20%20-b%2C%20–brute%20%20%20%20%20%20%20%20%20%20%20The%20input%20file%20is%20a%20blob%2C%20search%20for%20firmware%20volume%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20headers.%0A%20%20-d%2C%20–flash%20%20%20%20%20%20%20%20%20%20%20The%20input%20file%20is%20a%20flash%20descriptor.%0A%20%20-g%20GENERATE%2C%20–generate%20GENERATE%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Generate%20a%20behemoth-style%20GUID%20output.%0A%20%20-u%2C%20–unknowns%20%20%20%20%20%20%20%20When%20generating%20also%20print%20unknowns.”/]

Copyright (c) 2014 Teddy Reed <teddy@prosauce.org>
Copyright (c) 2013 Hector Martin <hector@marcansoft.com>

Source: https://github.com/theopolis/

Support Our Threat Intelligence

If you find our technology report and cybersecurity news helpful, consider supporting our work.

Crypto QR Code
USDT (TRC20):
TN8BdV8cp4T1Cd28gK9qTAnZknzzuwyUtm
USDT (ERC20):
0x3725e1a7d3bc5765499fa6aaafe307fabcd75bce