Created
September 5, 2024 10:17
-
-
Save oledid/4114469a1119ec17e4f8de4a4037e1e7 to your computer and use it in GitHub Desktop.
Get thumbprint of invalid SSL cert using old powershell
This file contains 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
$myUrl = "https://my-url-with-invalid-cert" | |
Function Get-SSLThumbprint { | |
param( | |
[Parameter( | |
Position=0, | |
Mandatory=$true, | |
ValueFromPipeline=$true, | |
ValueFromPipelineByPropertyName=$true) | |
] | |
[Alias('FullName')] | |
[String]$URL | |
) | |
add-type @" | |
using System.Net; | |
using System.Security.Cryptography.X509Certificates; | |
public class IDontCarePolicy : ICertificatePolicy { | |
public IDontCarePolicy() {} | |
public bool CheckValidationResult( | |
ServicePoint sPoint, X509Certificate cert, | |
WebRequest wRequest, int certProb) { | |
return true; | |
} | |
} | |
"@ | |
[System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
# Need to connect using simple GET operation for this to work | |
Invoke-RestMethod -Uri $URL -Method Get | Out-Null | |
$ENDPOINT_REQUEST = [System.Net.Webrequest]::Create("$URL") | |
$SSL_THUMBPRINT = $ENDPOINT_REQUEST.ServicePoint.Certificate.GetCertHashString() | |
return $SSL_THUMBPRINT -replace '(..(?!$))','$1:' | |
} | |
# Example output | |
Get-SSLThumbprint $myUrl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment