Created
November 3, 2022 02:38
-
-
Save jborean93/adec1d69e35b05be23abed32eb6063f4 to your computer and use it in GitHub Desktop.
Basic replacement for Get-TlsCipherSuite for older OS versions.
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 Get-TlsCipherSuite { | |
<# | |
.DESCRIPTION | |
Get a list of enabled TLS cipher suites for the server. | |
This is like the Get-TlsCipherSuite cmdlet but works on older Windows | |
versions. | |
#> | |
[OutputType([string])] | |
param () | |
Add-Type -Namespace Bcrypt -Name Native -MemberDefinition @' | |
[StructLayout(LayoutKind.Sequential)] | |
public struct CRYPT_CONTEXT_FUNCTIONS | |
{ | |
public int cFunctions; | |
public IntPtr rpgszFunctions; | |
} | |
[DllImport("Bcrypt.dll", EntryPoint = "BCryptEnumContextFunctions", CharSet = CharSet.Unicode)] | |
private static extern int NativeBCryptEnumContextFunctions( | |
int dwTable, | |
string pszContext, | |
int dwInterface, | |
ref int pcbBuffer, | |
ref IntPtr ppBuffer); | |
public static IntPtr BCryptEnumContextFunctions(string context, int interfaceId) | |
{ | |
int length = 0; | |
IntPtr buffer = IntPtr.Zero; | |
int res = NativeBCryptEnumContextFunctions( | |
1, // CRYPT_LOCAL | |
context, | |
interfaceId, | |
ref length, | |
ref buffer); | |
if (res != 0) | |
{ | |
throw new System.ComponentModel.Win32Exception(res); | |
} | |
return buffer; | |
} | |
[DllImport("Bcrypt.dll")] | |
public static extern void BCryptFreeBuffer( | |
IntPtr pvBuffer); | |
'@ | |
$NCRYPT_SCHANNEL_INTERFACE = 0x00010002 | |
$buffer = [Bcrypt.Native]::BCryptEnumContextFunctions("SSL", $NCRYPT_SCHANNEL_INTERFACE) | |
try { | |
$context = [System.Runtime.InteropServices.Marshal]::PtrToStructure($buffer, [type][Bcrypt.Native+CRYPT_CONTEXT_FUNCTIONS]) | |
$cipherPtr = $context.rpgszFunctions | |
for ($i = 0; $i -lt $context.cFunctions; $i++) { | |
[System.Runtime.InteropServices.Marshal]::PtrToStringUni( | |
[System.Runtime.InteropServices.Marshal]::ReadIntPtr($cipherPtr)) | |
$cipherPtr = [IntPtr]::Add($cipherPtr, [IntPtr]::Size) | |
} | |
} | |
finally { | |
[Bcrypt.Native]::BCryptFreeBuffer($buffer) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment