Last active
September 20, 2024 20:41
-
-
Save JeffMill/932052b7c0f5169b97b1d704e724328a to your computer and use it in GitHub Desktop.
Dump certs in a binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param([Parameter(Mandatory)][string]$Path) | |
# Caveats: | |
# | |
# Get-AuthenticodeSignature cmdlet has the following limitations: | |
# * Only first signature is fetched; | |
# * If the signature is timestamped, no signing time is provided; | |
# * No signature algorithm information is provided. | |
$chain = New-Object -TypeName Security.Cryptography.X509Certificates.X509Chain | |
$signature = Get-AuthenticodeSignature -LiteralPath $Path | |
$status = $signature.Status | |
if ($status -eq 'Valid') { | |
$cert = $signature.SignerCertificate | |
$chain.Build($cert) | Out-Null | |
# Show signers. | |
# | |
# Subject and Issuer are in "Distinguished Name" notation (RFC 1779), e.g. | |
# CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US | |
($chain.ChainElements).Certificate ` | |
| Format-List ` | |
@{ Name='Signer'; Expression={($_.Subject -split ',' | ConvertFrom-StringData).CN} }, | |
EnhancedKeyUsageList, | |
@{ Name='Cert Issuer'; Expression={($_.Issuer -split ',' | ConvertFrom-StringData).CN} }, | |
SerialNumber, | |
Thumbprint, | |
# Algorithm | |
NotBefore, | |
NotAfter | |
} | |
# Show version info. | |
$item = Get-Item $Path | |
$versionInfo = $item.VersionInfo | |
[PSCustomObject]@{ | |
'Verified' = $status | |
'FileDate' = $item.LastWriteTime | |
# Publisher | |
'Company' = $versionInfo.CompanyName | |
'Description' = $versionInfo.FileDescription | |
'Product' = $versionInfo.ProductName | |
'ProdVersion' = $versionInfo.ProductVersion | |
'FileVersion' = $versionInfo.FileVersion | |
# MachineType | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment