Skip to content

Added capability to audit ESP partition for revoked files#24

Open
sei-vsarvepalli wants to merge 15 commits intocjee21:mainfrom
sei-vsarvepalli:audit_efis
Open

Added capability to audit ESP partition for revoked files#24
sei-vsarvepalli wants to merge 15 commits intocjee21:mainfrom
sei-vsarvepalli:audit_efis

Conversation

@sei-vsarvepalli
Copy link

This setup now has an audit capability to check if any of the EFI files in the ESP folder - (default ESP mapped as FS0) has any files that are matching with the file in the DBX. Just right click "Scan EFI file against Microsoft DBX JSON".

  1. The script get the latest DBX JSON from Microsoft Secureboot objects folder https://github.com/microsoft/secureboot_objects/blob/main/PreSignedObjects/DBX/dbx_info_msft_latest.json
  2. Compares any binary file in the in the first ESP volume.
  3. Currently it does not care about the architecture.

The script can be used to audit current DBX status before applying the DBX update.

See screenshot example

Screenshot 2026-03-12 150404

@cjee21
Copy link
Owner

cjee21 commented Mar 13, 2026

Some questions/issues:

  • UEFI DBX uses Authenticode hash, not flat hash and some entries in Microsoft's json only has Authenticode hash. It seems you use flat hash only so does this mean the check is not reliable?
  • For certificates, thumbprint should be usable and Microsoft's json has thumbprint for certs. Can get cert thumbprint from inside DBX also.
  • In readme, "Just right click Scan ESP for revoked files.cmd." then what? Right click only will not do anything and some users will not know what next.
  • If the script has limitations and does not reliably detect every revoked binary, for example not checking certs or Authenticode hash, it should be stated in the readme so that users know the results may not have 100% coverage.

Suggestion:

  • another feature for checking any EFI file / bootable media specified by user may be added as some users may want to check whether their bootable USB is revoked and needs to be updated or not.

@sei-vsarvepalli
Copy link
Author

Some questions/issues:

  • UEFI DBX uses Authenticode hash, not flat hash and some entries in Microsoft's json only has Authenticode hash. It seems you use flat hash only so does this mean the check is not reliable?

I think my script was meant to use Authenticode hash only and ignore the flat hash.

  • For certificates, thumbprint should be usable and Microsoft's json has thumbprint for certs. Can get cert thumbprint from inside DBX also.

Sure will add it in a couple of days.

  • In readme, "Just right click Scan ESP for revoked files.cmd." then what? Right click only will not do anything and some users will not know what next.

Ok can update that.

  • If the script has limitations and does not reliably detect every revoked binary, for example not checking certs or Authenticode hash, it should be stated in the readme so that users know the results may not have 100% coverage.

Agreed.

Suggestion:

  • another feature for checking any EFI file / bootable media specified by user may be added as some users may want to check whether their bootable USB is revoked and needs to be updated or not.

👀 - looking..

@cjee21
Copy link
Owner

cjee21 commented Mar 18, 2026

I think my script was meant to use Authenticode hash only and ignore the flat hash.

But it doesn't and is the opposite...

function Get-FileSha256Hex {
    param([Parameter(Mandatory)][string] $FilePath)
    (Get-FileHash -Algorithm SHA256 -LiteralPath $FilePath).Hash.ToUpperInvariant()
}
# We put it in same set for now; the caller will label which “kind” matched.
# Without computing authenticode hashes locally, only flatHash matches are actionable.
[void]$sha256Set.Add($img.authenticodeHash.Trim().ToUpperInvariant())
# Hash match
if ($fileSha -and $set.Sha256Set.Contains($fileSha)) {
    $matches += [PSCustomObject]@{ Source=$set.Name; Type='Hash'; Detail='SHA256(flat) matches revocation list' }
}

@sei-vsarvepalli
Copy link
Author

okay looking at fixing that. I think my Get-AuthenticodeHash code is broken! so perhaps settled for the direct sha256 when available. It should definitely move away from that. If you have or aware of a readily available PowerShell for getting AuthenticodeHash lmk.

@cjee21
Copy link
Owner

cjee21 commented Mar 18, 2026

If you have or aware of a readily available PowerShell for getting AuthenticodeHash lmk.

--> 71dae46

and I see you are using Get-EfiSignatures.ps1 so you have to make changes because the object format has changed.

@sei-vsarvepalli
Copy link
Author

If you have or aware of a readily available PowerShell for getting AuthenticodeHash lmk.

--> 71dae46

and I see you are using Get-EfiSignatures.ps1 so you have to make changes because the object format has changed.

If you have or aware of a readily available PowerShell for getting AuthenticodeHash lmk.

--> 71dae46

and I see you are using Get-EfiSignatures.ps1 so you have to make changes because the object format has changed.

Thanks - that helps a lot. My code for Authenticode Signatures was very buggy. This seems to work fine. I have also added the example for scanning a CD rom like D:\

@cjee21
Copy link
Owner

cjee21 commented Mar 19, 2026

Good news is that it does detect revoked shim from Canonical now:

Loading Microsoft DBX JSON...
Loaded MsftJson: SHA256-like=659, X509=0
Scanning for EFI binaries...
Found 1 EFI file(s).

WARNING: EFI file matches revocation list(s)
  Path: C:\Users\***\Downloads\shimx64.efi
  SHA256 (flat): 2EA4CB6A1F1EB1D3DCE82D54FDE26DED243BA3E18DE7C6D211902A594FE56788  <-- This is actually Authenticode hash, not flat hash
  Match: [MsftJson] Hash - SHA256(flat) matches revocation list

Scan complete. Warnings: 1

@sei-vsarvepalli
Copy link
Author

I think my script was meant to use Authenticode hash only and ignore the flat hash.

But it doesn't and is the opposite...

function Get-FileSha256Hex {
    param([Parameter(Mandatory)][string] $FilePath)
    (Get-FileHash -Algorithm SHA256 -LiteralPath $FilePath).Hash.ToUpperInvariant()
}
# We put it in same set for now; the caller will label which “kind” matched.
# Without computing authenticode hashes locally, only flatHash matches are actionable.
[void]$sha256Set.Add($img.authenticodeHash.Trim().ToUpperInvariant())
# Hash match
if ($fileSha -and $set.Sha256Set.Contains($fileSha)) {
   $matches += [PSCustomObject]@{ Source=$set.Name; Type='Hash'; Detail='SHA256(flat) matches revocation list' }
}

I think my script was meant to use Authenticode hash only and ignore the flat hash.

But it doesn't and is the opposite...

function Get-FileSha256Hex {
    param([Parameter(Mandatory)][string] $FilePath)
    (Get-FileHash -Algorithm SHA256 -LiteralPath $FilePath).Hash.ToUpperInvariant()
}
# We put it in same set for now; the caller will label which “kind” matched.
# Without computing authenticode hashes locally, only flatHash matches are actionable.
[void]$sha256Set.Add($img.authenticodeHash.Trim().ToUpperInvariant())
# Hash match
if ($fileSha -and $set.Sha256Set.Contains($fileSha)) {
   $matches += [PSCustomObject]@{ Source=$set.Name; Type='Hash'; Detail='SHA256(flat) matches revocation list' }
}

Should be resolved.

@sei-vsarvepalli sei-vsarvepalli requested a review from cjee21 March 20, 2026 19:43
}

# MSFT JSON does not directly provide DER blobs for revoked cert entries (at least in the snippet provided),
# so in MsftJson mode we can only do hash-based checks unless you add a mapping of signer certs separately.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated comment.

$sigs = Get-EfiSignatures -FilePath $file
$fileSha = $sigs.Authentihash
foreach ($sig in $sigs.Signatures) {
foreach ($c in $sig.Certificates) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indents.

$matches += [PSCustomObject]@{ Source=$set.Name; Type='Hash'; Detail='SHA256(Authenticode) matches revocation list' }
}

# Cert match (only meaningful for CurrentDbx unless you add cert data to MsftJson mode)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated comment.

README.md Outdated

[!WARNING]
Detection is based on hash and certificate matching only.
Newer revocations using **SVN (version-based enforcement)** are **not currently checked**. However `Check EFI file info.cmd` will display SVN/SBAT data if present, but this tool does not compare it against UEFI NVRAM policy. Support for SVN comparison is welcome as a feature request. The `Check EFI file info.cmd` also provides SBAT information. The SBAT enforcement is handled by shim, this tool will likely catch revoked shim binaries.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SBAT enforcement is handled by shim, this tool will likely catch revoked shim binaries.

I do not think it will catch newer revoked shims as those are only revoked using SBAT. Same with Microsoft's Boot Managers that now use SVN to revoke.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of shim revoked with SBAT: https://launchpad.net/~canonical-signing/+archive/ubuntu/primary-2022v1/+build/26761603/+files/shim-signed_1.56+15.7-0ubuntu1_amd64.deb

sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
shim,3,UEFI shim,shim,1,https://github.com/rhboot/shim
shim.ubuntu,1,Ubuntu,shim,15.7-0ubuntu1,https://www.ubuntu.com/

SBAT is now shim,4

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do a push to say SBAT feature is also missing. The shim self test you mention is a specific rollback prevention revocation. Also the newer shims (specifically 15.7 and later, including 15.8+), SBATLevel NVRAM variable is actually now visible in the Operating System and there is also arguable SBATLevelRT visible in the UEFI NVRAM Runtime services in the in-between shim versions, too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are using SBAT to revoke Shim and Grub and SVN to revoke Windows Boot Manager now instead of using DBX hash. That's the reason they invented SBAT and SVN, to reduce NVRAM usage. SBATLevelRT is a volatile variable created by Shim at boot. It is only available when booting from Shim. Not available on Windows. Windows only writes the SBATLevel variable to revoke vulnerable Shim and Grub.

@cjee21
Copy link
Owner

cjee21 commented Mar 21, 2026

It works fine now. Just some minor touch-up needed.

Loading Microsoft DBX JSON...
Loaded MsftJson: SHA256-like=659, X509=1
Scanning for EFI binaries...                                                                                            
Found 10 EFI file(s).                                                                                                                                                                                                                           

WARNING: EFI file matches revocation list(s)                                                                           
  Path: S:\EFI\Microsoft\Boot\bootmgr.efi                                                                              
  SHA256 (Authenticode): E19F7C6BDA7FBC1F14CD456CD33DE8D28CE82A0825D69FE8C3CF39CDC7488FF9                               
  Signer thumbprint(s): 3B77DB29AC72AA6B5880ECB2ED5EC1EC6601D847, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D              
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation                                                                                                                                                             

WARNING: EFI file matches revocation list(s)                                                                            
  Path: S:\EFI\Microsoft\Boot\memtest.efi                                                                               
  SHA256 (Authenticode): 8605130E03F1FA7CD4EA60C9258661ED2317D9BB4CDA1D0C7622764BADE1558C                               
  Signer thumbprint(s): 3B77DB29AC72AA6B5880ECB2ED5EC1EC6601D847, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D              
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation                                                                                                                                                             

WARNING: EFI file matches revocation list(s)                                                                            
  Path: S:\EFI\Microsoft\Boot\cbmr_driver.efi                                                                           
  SHA256 (Authenticode): 63BA7F74F98A0E7DD30E4A3AD8ADFDF7BA1D42E9DA20BDB9A70CA38AFF66046E                                
  Signer thumbprint(s): D2B3B8F124652EFC5415A10DBD7723B0C4531F0B, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D              
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation                                                                                                                                                             

WARNING: EFI file matches revocation list(s)                                                                            
  Path: S:\EFI\Microsoft\Boot\SecureBootRecovery.efi                                                                    
  SHA256 (Authenticode): F0E5F72E185A2AF31F4B52ACB17273F791FAA85A0D98F500380BF2C6CFD3C2C0                                
  Signer thumbprint(s): FACDE3D80E99AFCC15E08AC5A69BD22785287F79, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D              
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation                                                                                                                                                             

WARNING: EFI file matches revocation list(s)                                                                            
  Path: C:\WINDOWS\Boot\EFI\bootmgfw.efi                                                                                
  SHA256 (Authenticode): 2A5E50EB6A232538E895A32D3DC77BBF08059F952A6FA045BBBBC203CCBD2FA6                               
  Signer thumbprint(s): FACDE3D80E99AFCC15E08AC5A69BD22785287F79, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation

WARNING: EFI file matches revocation list(s)
  Path: C:\WINDOWS\Boot\EFI\bootmgr.efi
  SHA256 (Authenticode): E19F7C6BDA7FBC1F14CD456CD33DE8D28CE82A0825D69FE8C3CF39CDC7488FF9
  Signer thumbprint(s): 3B77DB29AC72AA6B5880ECB2ED5EC1EC6601D847, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation

WARNING: EFI file matches revocation list(s)
  Path: C:\WINDOWS\Boot\EFI\memtest.efi
  SHA256 (Authenticode): 8605130E03F1FA7CD4EA60C9258661ED2317D9BB4CDA1D0C7622764BADE1558C
  Signer thumbprint(s): 3B77DB29AC72AA6B5880ECB2ED5EC1EC6601D847, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation

WARNING: EFI file matches revocation list(s)
  Path: C:\WINDOWS\Boot\EFI\SecureBootRecovery.efi
  SHA256 (Authenticode): F0E5F72E185A2AF31F4B52ACB17273F791FAA85A0D98F500380BF2C6CFD3C2C0
  Signer thumbprint(s): FACDE3D80E99AFCC15E08AC5A69BD22785287F79, 580A6F4CC4E4B669B9EBDC1B2B3E087B80D0678D
  Match: [MsftJson] SignerCert - Signer certificate DER matches DBX X509 revocation

Scan complete. Warnings: 8
Loading Microsoft DBX JSON...
Loaded MsftJson: SHA256-like=659, X509=1
Scanning for EFI binaries...
Found 2 EFI file(s).

WARNING: EFI file matches revocation list(s)
  Path: D:\Revoked Ubuntu Shim sample\shimx64.efi
  SHA256 (Authenticode): 2EA4CB6A1F1EB1D3DCE82D54FDE26DED243BA3E18DE7C6D211902A594FE56788
  Signer thumbprint(s): C3313F1D98AB50971585F721EF90D55DBD1C74F7, 46DEF63B5CE61CF8BA0DE2E6639C1019D0ED14F3
  Match: [MsftJson] Hash - SHA256(Authenticode) matches revocation list

WARNING: EFI file matches revocation list(s)
  Path: D:\Revoked Ubuntu Shim sample\shimx64_dualsigned.efi
  SHA256 (Authenticode): 2EA4CB6A1F1EB1D3DCE82D54FDE26DED243BA3E18DE7C6D211902A594FE56788
  Signer thumbprint(s): FD52A3806ADF691FBECD6F941B3F1A207EAD4994, C3313F1D98AB50971585F721EF90D55DBD1C74F7, 46DEF63B5CE61CF8BA0DE2E6639C1019D0ED14F3
  Match: [MsftJson] Hash - SHA256(Authenticode) matches revocation list

Scan complete. Warnings: 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants