Created
August 7, 2020 08:45
-
-
Save moddingg33k/b9c89e53eec84b8dd170be0e7776aee5 to your computer and use it in GitHub Desktop.
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
Function Test-ServerSSLSupport | |
{ | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[ValidateNotNullOrEmpty()] | |
[String]$HostName, | |
[UInt16]$Port = 443 | |
) | |
Process | |
{ | |
$RetValue = New-Object -TypeName PSObject -Property ([ordered]@{ | |
DestinationHost = $HostName | |
DestinationAddress = $null | |
DestinationPort = $Port | |
SourceAddress = $null | |
SSLv2 = $null | |
SSLv3 = $null | |
TLSv1_0 = $null | |
TLSv1_1 = $null | |
TLSv1_2 = $null | |
TLSv1_3 = $null | |
KeyExhange = $null | |
HashAlgorithm = $null | |
}) | |
@('ssl2', 'ssl3', 'tls', 'tls11', 'tls12', 'tls13') | | |
Foreach-Object -Process { | |
$TcpClient = New-Object Net.Sockets.TcpClient | |
$TcpClient.Connect($HostName, $Port) | |
$SslStream = New-Object Net.Security.SslStream $TcpClient.GetStream() | |
$SslStream.ReadTimeout = 15000 | |
$SslStream.WriteTimeout = 15000 | |
Try { | |
$SslStream.AuthenticateAsClient($HostName,$null,$_,$false) | |
$RetValue.KeyExhange = $SslStream.KeyExchangeAlgorithm | |
$RetValue.HashAlgorithm = $SslStream.HashAlgorithm | |
$status = $true | |
} | |
Catch { | |
$status = $false | |
} | |
switch ($_) | |
{ | |
'ssl2' {$RetValue.SSLv2 = $status} | |
'ssl3' {$RetValue.SSLv3 = $status} | |
'tls' {$RetValue.TLSv1_0 = $status} | |
'tls11' {$RetValue.TLSv1_1 = $status} | |
'tls12' {$RetValue.TLSv1_2 = $status} | |
'tls12' {$RetValue.TLSv1_3 = $status} | |
} | |
$RetValue.SourceAddress = $TcpClient.Client.LocalEndPoint.Address.IPAddressToString | |
$RetValue.DestinationAddress = $TcpClient.Client.RemoteEndPoint.Address.IPAddressToString | |
# dispose objects to prevent memory leaks | |
$TcpClient.Dispose() | |
$SslStream.Dispose() | |
} | |
$RetValue | Add-Member -Type NoteProperty -Name SslStreamInfo -Value ( | |
$SslStream | Get-Member | | |
Where-Object -FilterScript { $_.MemberType -match 'Property' } | | |
Select-Object Name | | |
ForEach-Object -Process { @{Name = $_.Name; Value = $sslStream.($_.name)} } | |
) | |
$RetValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment