Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell获取文件的证书链?_Powershell_Scripting_Certificate_Pki_Authenticode - Fatal编程技术网

使用PowerShell获取文件的证书链?

使用PowerShell获取文件的证书链?,powershell,scripting,certificate,pki,authenticode,Powershell,Scripting,Certificate,Pki,Authenticode,我正在寻找一种方法,仅使用PowerShell列出签名文件的证书链。特别是获取根证书 因为我需要获得某些可执行文件(在已安装的软件上)所依赖的非Microsoft根证书的列表。这是由于操作系统基线指南使用了Microsoft KB293781中的PKI过程。其中,只有特定的根证书才能放在特定的计算机上。例如,经常使用的“VeriSign Class 3 Primary CA-G5”仅在必要时使用 Get-Authenticode签名仅列出颁发者。例如:Get AuthenticodeSignat

我正在寻找一种方法,仅使用PowerShell列出签名文件的证书链。特别是获取根证书

因为我需要获得某些可执行文件(在已安装的软件上)所依赖的非Microsoft根证书的列表。这是由于操作系统基线指南使用了Microsoft KB293781中的PKI过程。其中,只有特定的根证书才能放在特定的计算机上。例如,经常使用的“VeriSign Class 3 Primary CA-G5”仅在必要时使用

Get-Authenticode签名仅列出颁发者。例如:
Get AuthenticodeSignature C:\windows\system32\MRT.exe

像“SysInternals SigCheck”这样的工具能够做到这一点
SigCheck.exe-ic:\windows\System32\mrt.exe
,并且可以进一步解析此信息。另外,Windows SDK中的
SignTool.exe
和Didier Stevens的
AnalyzePESig
等其他工具也可以获取此信息

但这可以只使用PowerShell完成吗?可能在Windows中使用WinVerifyTrust API。

干杯,
Tekk

这应该可以通过直接在PowerShell中访问.NET实现。下面是我使用您在问题中引用的示例文件编写的一个片段:

# Get a X590Certificate2 certificate object for a file
$cert = (Get-AuthenticodeSignature -FilePath C:\windows\system32\MRT.exe).SignerCertificate
# Create a new chain to store the certificate chain
$chain = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Chain
# Build the certificate chain from the file certificate
$chain.Build($cert)
# Return the list of certificates in the chain (the root will be the last one)
$chain.ChainElements | ForEach-Object {$_.Certificate}

这是否为您提供了所需内容?

只有Windows连接到internet,并且能够解析CTL/OCSP时,此方法才起作用,这在打开事件查看器中的CAPI2日志记录的环境中是不可能的,并获得以下内容(缩短):
Name:Microsoft-Windows-CAPI2 EventID:30 UserData-结果无法将证书链构建到受信任的根颁发机构。EventID:11-RevocationResult吊销功能无法检查吊销,因为吊销服务器处于脱机状态。-结果无法将证书链构建到受信任的根颁发机构