Rusty Bootkit - UEFI Bootkit in Rust

Overview

A UEFI Bootkit in Rust

Note: This project is incomplete and work is in progress (W.I.P). A lot of things could be incorrect until this is complete.

While it's possible to use this for advanced adversary simulation or emulation (red teaming), it's unlikely to be used in most engagements. This tool can also be used for game hacking and is a side project for those interested in fun, learning, malware research, and spreading security awareness. It also demonstrates that Rust can handle both low-level and high-level tasks. One important capability of this tool is its ability to load a kernel driver before the operating system, or even execute shellcode in the kernel to bypass Windows security protections. It's important to recognize the potential of Rust and not underestimate its power.

Feel free to check out my Windows Kernel Rootkit and Blue Pill Hypervisor in pure Rust:

Features

  • Manually Map a Windows kernel driver and/or blue-pill (type-2) hypervisor driver (TODO)

Description

A bootkit can run code before the operating system and potentially inject malicious code into the kernel or load a malicious kernel driver by infecting the boot process and taking over the system's firmware or bootloader, effectively disabling or bypassing security protections.

The image below shows how Legacy and UEFI boot works.

Legacy-and-UEFI-Boot Figure 1. Comparison of the Legacy Boot flow (left) and UEFI boot flow (right) on Windows (Vista and newer) systems (Full Credits: WeLiveSecurity)

  1. AFAIK there are a few ways to achieve the same objective as shown below:

    • Hook/detour Archpx64TransferTo64BitApplicationAsm in bootmgfw.efi (Windows OS loader), which transfers execution to the OS loader (winload.efi) or

    • ImgArchStartBootApplication to catch the moment when the Windows OS loader (winload.efi) is loaded in the memory but still has not been executed or

    • Hook/Detour ExitBootServices, which is UEFI firmware service that signals the end of the boot process and transitions the system from the firmware environment to the operating system environment.

      1.1. The following is required if UEFI Secure Boot is enabled:

      • Patch BmFwVerifySelfIntegrity to bypass self integrity checks.
      • Execute bcdedit /set {bootmgr} nointegritychecks on to skip the integrity checks.
      • Inject bcdedit /set {bootmgr} nointegritychecks on option dynamically by modifying the LoadOptions.

      1.2. The following is required to allocate an additional memory buffer for the malicious kernel driver, because as a UEFI Application it will be unloaded from memory after returning from its entry point function.

      • BlImgAllocateImageBuffer or BlMmAllocateVirtualPages in the Windows OS loader (winload.efi).
  2. Hook/detour OslArchTransferToKernel in winload.efi (Windows OS loader), which transfers execution to the Windows Kernel (ntoskrnl.exe) to catch the moment when the OS kernel and some of the system drivers are already loaded in the memory, but still not been executed, which is a perfect moment to perform more in-memory patching.

    • Patch SepInitializeCodeIntegrity, a parameter to CiInitialize in ntoskrnl.exe to disable Driver Signature Enforcement (DSE).
    • Patch KeInitAmd64SpecificState in ntoskrnl.exe to disable PatchGuard.

Usage

A UEFI Bootkit works under one or more of the following conditions:

  • Secure Boot is disabled on the machine, so no vulnerabilities are required to exploit it. (Supported by this project).

  • Exploiting a known flaw in the UEFI firmware to disable Secure Boot in the case of an out-of-date firmware version or a product no longer supported, including the Bring Your Own Vulnerable Binary (BYOVB) technique to bring copies of vulnerable binaries to the machines to exploit a vulnerability or vulnerabilities and bypass Secure Boot on up-to-date UEFI systems (1-day/one-day).

  • Exploiting an unspecified flaw in the UEFI firmware to disable Secure Boot (0-day/zero-day vulnerability).

Usage 1: Infect Windows Boot Manager bootmgfw.efi on Disk (Unsupported)

Typically UEFI Bootkits infect the Windows Boot Manager bootmgfw.efi located in EFI partition \EFI\Microsoft\Boot\bootmgfw.efi (C:\Windows\Boot\EFI\bootmgfw.efi. Modification of the bootloader includes adding a new section called .efi to the Windows Boot Manager bootmgfw.efi, and changing the executable's entry point address so program flow jumps to the beginning of the added section as shown below:

  • Convert bootkit to position-independent code (PIC) or shellcode
  • Find bootmgfw.efi (Windows Boot Manager) located in EFI partition \EFI\Microsoft\Boot\bootmgfw.efi
  • Add .efi section to bootmgfw.efi (Windows Boot Manager)
  • Inject or copy bootkit shellcode to the .efi section in bootmgfw.efi (Windows Boot Manager)
  • Change entry point of the bootmgfw.efi (Windows Boot Manager) to newly added .efi section bootkit shellcode
  • Reboot

Usage 2: Execute UEFI Bootkit via UEFI Shell (Supported)

  1. Compile the project
cargo build --target x86_64-unknown-uefi

Download EDK2 efi shell or UEFI-Shell and follow these steps:

  1. Extract downloaded efi shell and rename file Shell.efi (should be in folder UefiShell/X64) to bootx64.efi

  2. Format some USB drive to FAT32

  3. Create following folder structure:

USB:.
 │   bootkit.efi
 │
 └───EFI
      └───Boot
              bootx64.efi
  1. Boot from the USB drive

    4.1. The following is required for VMware Workstation:

    • VMware Workstation: VM -> Settings -> Hardware -> Add -> Hard Disk -> Next -> SCSI or NVMe (Recommended) -> Next -> Use a physical disk (for advanced users) -> Next -> Device: PhysicalDrive1 and Usage: Use entire disk -> Next -> Finish.

    • Start VM by clicking Power On to Firmware

    • Select Internal Shell (Unsupported option) or EFI Vmware Virtual SCSI Hard Drive (1.0)

  2. An UEFI shell should start, change directory to your USB (FS1 should be the USB since we are booting from it) and list files:

FS1:
ls
  1. You should see file bootkit.efi, if you do, load it:
bootkit.efi
  1. Now you should see output from the bootkit.efi application. If it is successful, Windows should boot automatically.

Credits / References / Thanks / Motivation

You might also like...
Rust-and-opengl-lessons - Collection of example code for learning OpenGL in Rust

rust-and-opengl-lessons Project requires Rust 1.31 Collection of example code for learning OpenGL in Rust 00 - Setup 01 - Window 02 - OpenGL Context 0

Simple retro game made using Rust bracket-lib by following "Herbert Wolverson's Hands on Rust" book.

Flappy Dragon Code from This program is a result of a tutorial i followed from Herbert Wolverson's Hands-on Rust Effective Learning through 2D Game De

A rust chess implementation using a neural network scoring function built on huggingface/candle + rust + wasm

Rusty Chess What is it? Rusty Chess aims to be a high quality embeddable chess engine that runs entirely locally in the browser (no backend required).

A Rust wrapper and bindings of Allegro 5 game programming library

RustAllegro A thin Rust wrapper of Allegro 5. Game loop example extern crate allegro; extern crate allegro_font; use allegro::*; use allegro_font::*;

High performance Rust ECS library
High performance Rust ECS library

Legion aims to be a feature rich high performance Entity component system (ECS) library for Rust game projects with minimal boilerplate. Getting Start

A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Rust library to create a Good Game Easily

ggez What is this? ggez is a Rust library to create a Good Game Easily. The current version is 0.6.0-rc0. This is a RELEASE CANDIDATE version, which m

RTS game/engine in Rust and WebGPU
RTS game/engine in Rust and WebGPU

What is this? A real time strategy game/engine written with Rust and WebGPU. Eventually it will be able to run in a web browser thanks to WebGPU. This

unrust - A pure rust based (webgl 2.0 / native) game engine

unrust A pure rust based (webgl 2.0 / native) game engine Current Version : 0.1.1 This project is under heavily development, all api are very unstable

Owner
Mostly interested in Rust, malware research, hypervisor development, Windows internals, and reverse engineering.
null
The Bloat-Free Browser Game in Rust but in C and in UEFI

rust-browser-game but in UEFI instead of browser quick start deps rust gnu-efi gcc make build process $ make running after building everything you wil

bit6tream 12 Nov 7, 2022
Quick example of displaying a BMP file with uefi-rs

uefi-bmp Quick example of drawing a bitmap using uefi-rs and tinybmp. Not necessarily the most efficient :) Build and run (may need some modification

Nicholas Bishop 1 Jan 16, 2022
Scuffed UEFI video(bad apple) player

Bad UEFI Another day, another Bad Apple project. Video and audio are loaded from \video.uefiv and \audio.uefia respectively. (when running in QEMU esp

Matic Babnik 4 Nov 8, 2022
UEFI command-line tool for read/write access of variables

UEFI Command Line Tool for Reading/Writing UEFI Variables This tool is a rewritten version of the modded grub with setup_var commands, enhanced with m

null 29 Jan 9, 2023
Zero-cost and safe interface to UEFI firmware

ZFI – Zero-cost and safe interface to UEFI firmware ZFI is a Rust crate for writing a UEFI application with the following goals: Provides base APIs th

Ultima Microsystems 22 Sep 14, 2023
Rusty NuGet client

ruget It's a NuGet client built in Rust. It's not really meant to replace existing nuget clients. It's more of a playground for experimenting with rel

Kat Marchán 18 Feb 2, 2022
Sombervale, a Rusty Jam 2021 game

Sombervale Made in 7 days for Rusty Jam 2021. About It is dark and spooky in Sombervale park. There are shadow creatures all around you. Run away with

Blipjoy 9 Oct 10, 2022
API tool,but egui style and rusty

WEAVER About Weaver is a simple,easy-to-use and cross-platform API tool.Inspired by hoppscotch . It uses the Rust egui GUI library. Features Get,Post

will 14 Dec 11, 2022
🦀 Rusty DLL Injector with GUI

DLL Crab Rusty DLL Injector with GUI Screenshot Why? Because I can't find a GUI DLL Injector that written in Rust. And i wrote it myself! Methods Crea

0x707 92 Nov 14, 2022
Rust-raytracer - 🔭 A simple ray tracer in Rust 🦀

rust-raytracer An implementation of a very simple raytracer based on Ray Tracing in One Weekend by Peter Shirley in Rust. I used this project to learn

David Singleton 159 Nov 28, 2022