Git Product home page Git Product logo

uefi_retool's Introduction

MIT License Python Versions Version

uefi_retool

A tool for UEFI firmware reverse engineering.

UEFI firmware analysis with uefi_retool script

Usage:

  • Copy ida_plugin/uefi_analyser.py script and ida_plugin/uefi_analyser directory to IDA plugins directory
  • Edit config.json file
    • PE_DIR is a directory that contains all executable images from the UEFI firmware
    • DUMP_DIR is a directory that contains all components from the firmware filesystem
    • LOGS_DIR is a directory for logs
    • IDA_PATH and IDA64_PATH are paths to IDA Pro executable files
  • Run pip install -r requirements.txt
  • Run python uefi_retool.py command to display the help message

Commands

python uefi_retool.py
Usage: uefi_retool.py [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  get-images  Get executable images from UEFI firmware.
  get-info    Analyze the entire UEFI firmware.
  get-pp      Get a list of proprietary protocols in the UEFI firmware.

get-images

python uefi_retool.py get-images --help
Usage: uefi_retool.py get-images [OPTIONS] FIRMWARE_PATH

  Get executable images from UEFI firmware. Images are stored in "modules"
  directory.

Options:
  --help  Show this message and exit.

Example:

python uefi_retool.py get-images test_fw/fw-tp-x1-carbon-5th.bin

get-info

python uefi_retool.py get-info --help
Usage: uefi_retool.py get-info [OPTIONS] FIRMWARE_PATH

  Analyze the entire UEFI firmware. The analysis result is saved to .json
  file.

Options:
  -w, --workers INTEGER  Number of workers (8 by default).
  --help                 Show this message and exit.

Example:

python uefi_retool.py get-info -w 6 test_fw/fw-tp-x1-carbon-5th.bin

get-pp

python uefi_retool.py get-pp --help
Usage: uefi_retool.py get-pp [OPTIONS] FIRMWARE_PATH

  Get a list of proprietary protocols in the UEFI firmware. The result is
  saved to .json file.

Options:
  -w, --workers INTEGER  Number of workers (8 by default).
  --help                 Show this message and exit.

Example:

python uefi_retool.py get-pp -w 6 test_fw/fw-tp-x1-carbon-5th.bin

Additional tools

  • tools/update_edk2_guids.py is a script that updates protocol GUIDs list from edk2 project

IDA plugin

IDA plugin for UEFI analysis

Similar works

uefi_retool's People

Contributors

assafcarlsbad avatar yeggor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uefi_retool's Issues

strange representation guids

why?
data:00000000000E2280 ; EFI_GUID *gEfiLoadedImageProtocolGuid_0xe2280
.data:00000000000E2280 gEfiLoadedImageProtocolGuid_0xe2280 dq 11D295625B1B31A1h
.data:00000000000E2280 ; DATA XREF: sub_1CD7E+1D5↑o
.data:00000000000E2280 ; sub_1D0C6+111↑o ...
.data:00000000000E2288 db 8Eh ; Ћ
.data:00000000000E2289 db 3Fh ; ?
.data:00000000000E228A db 0
.data:00000000000E228B db 0A0h ;  
.data:00000000000E228C db 0C9h ; Й
.data:00000000000E228D db 69h ; i
.data:00000000000E228E db 72h ; r
.data:00000000000E228F db 3Bh ; ;

but corectly

.data:00000000000E2280 ; EFI_GUID *gEfiLoadedImageProtocolGuid_0xe2280
.data:00000000000E2280 gEfiLoadedImageProtocolGuid_0xe2280 DGUID {5B1B31A1-9562-11D2-8E3F-00A0C969723B}
.data:00000000000E2280 ; DATA XREF: sub_1CD7E+1D5↑o
.data:00000000000E2280 ; sub_1D0C6+111↑o ...
.data:00000000000E2280 ; ->EFI_LOADED_IMAGE_PROTOCOL_GUID

IDA Pro: search protocols

A question:
in IDA Pro, why did you choose 25 (x86) and 16 (x64) when looking for protocols?
In get_protocols() (https://github.com/yeggor/UEFI_RETool/blob/master/ida_plugin/uefi_analyser/analyser.py#L130):

            for address in self.gBServices[service_name]:
                ea, found = address, False
                if self.arch == 'x86':
                    for _ in range(1, 25):
                        ea = idc.prev_head(ea)
                        if (idc.get_operand_value(ea, 0) > self.base
                                and idc.print_insn_mnem(ea) == 'push'):
                            found = True
                            break
                if self.arch == 'x64':
                    for _ in range(1, 16):
                        ea = idc.prev_head(ea)
                        if (idc.get_operand_value(ea, 1) > self.base
                                and idc.print_insn_mnem(ea) == 'lea'):
                            found = True
                            break

In radare2, instead, you use LEA_NUM (x64), a kind of instruction offset. This solution, unfortunately, is not always accurate.

What is the correct solution?

Erroneous attempt to delete old log file?

Inside the analyse_all function we can find the following snippet which tries to delete the previous log file:

log_path = os.path.join('log', 'ida_' + scr_name.replace('.py', '.log'))
if os.path.isfile(log_path):
	os.remove(log_path)

However, IMHO the output emitted by the analyzer script is a Markdown file with an .md extension, which means the above code will never execute. Am I missing something?

Support UEFI runtime services in addition to boot services

Currently the IDA plugin does a very good job in finding calls to several selected UEFI boot services, but so far the runtime services were neglected. Since runtime services are a key part of the UEFI specification, supporting them will greatly aid the reverse engineering of virtually any UEFI module.

Can not work with IDA v7.0

Failed while executing plugin_t.run():
Traceback (most recent call last):
File "C:/Program Files/IDA_Pro_v7.0/plugins/uefi_analyser.py", line 52, in run
self._analyse_all()
File "C:/Program Files/IDA_Pro_v7.0/plugins/uefi_analyser.py", line 93, in _analyse_all
prot_explorer.run()
File "C:/Program Files/IDA_Pro_v7.0/plugins\uefi_analyser\prot_explorer.py", line 181, in run
analyser.analyse_all()
File "C:/Program Files/IDA_Pro_v7.0/plugins\uefi_analyser\analyser.py", line 438, in analyse_all
self.make_comments()
File "C:/Program Files/IDA_Pro_v7.0/plugins\uefi_analyser\analyser.py", line 307, in make_comments
idc.op_stroff(address, 0, EFI_BOOT_SERVICES_ID, 0)
File "C:\Program Files\IDA_Pro_v7.0\python\idc.py", line 1267, in op_stroff
return ida_bytes.op_stroff(ea, n, path.cast(), 1, delta)
File "C:\Program Files\IDA_Pro_v7.0\python\ida_bytes.py", line 1007, in op_stroff
return _ida_bytes.op_stroff(*args)
TypeError: in method 'op_stroff', argument 1 of type 'insn_t const &'

How can I use this tool?

Overall, I don't see the significance of this tool, and it feels like it's useless compared to uefitools. Are there any other test cases or usage methods, thank you.

Support Cutter

IDA Pro is not the only reverse engineering platform in the world. Another popular one is Radare2, a highly-portable cross-platform reverse engineering framework and a toolkit without dependencies. It has support for analyzing binaries, disassembling code, debugging programs, attaching to remote GDB/LLDB, WinDbg servers, rich plugin system (see r2pm), and integration with various decompilers. For example, ghidra decompiler plugin - r2ghidra-dec. It is actively developed and can be easily integrated in various open source and commercial products. I believe, it will be highly beneficial to support these and provide a package for install from r2pm, see the package repository here: https://github.com/radareorg/radare2-pm

image

For documentation on writing plugins for radare2 see Scripting and Plugins Radare2 Book chapters.

Cutter is a crossplatform Qt/C++ GUI frontend to radare2:

image

For documentation on writing plugins for Cutter see the official tutorial and the curated list of various popular plugins.

incorrect result

ipxe-efi.zip

  1. see .text:000000000001D0D4 - error

  2. use for indirect call not only comment but IDA command: (example)

    op_stroff (0X1D130, 0, GetStrucIdByName("EFI_BOOT_SERVICES"), 0);

.text:0001D127 mov r8, [r13+10h]
.text:0001D12B xor edx, edx
.text:0001D12D mov rcx, r13
.text:0001D130 call qword ptr [rbp+140h] ; EFI_BOOT_SERVICES->LocateProtocol

changed to

.text:0001D127 mov r8, [r13+10h] ; Interface
.text:0001D12B xor edx, edx ; Registration
.text:0001D12D mov rcx, r13 ; Protocol
.text:0001D130 call [rbp+EFI_BOOT_SERVICES.LocateProtocol] ; EFI_BOOT_SERVICES->LocateProtocol

in this case Ida automatically comment parameters.
But previously you need load struct description from Tlib.

Handle reflexive cases in the dependencies graph.

There are cases in which a DXE driver uses a protocol it registered beforehand, for example:

[UEFI_RETool] EFI_ARP_PROTOCOL_GUID protocol information
{
    "module_name": "ArpDxe",
    "protocol_name": "EFI_ARP_PROTOCOL_GUID",
    "guid": "F4B427BB-BA21-4F16-BC4E43E416AB619C",
    "service": "InstallMultipleProtocolInterfaces",
    "used_by": [
        "ArpDxe",
        "Ip4Dxe",
        "UefiPxeBcDxe"
    ]
}

In these reflexive cases, the dependencies graph shows two distinct nodes instead of just one:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.