{"uuid": "87a3d678-7aa5-453a-8ad0-1ff29e618f1c", "vulnerability_lookup_origin": "1a89b78e-f703-45f3-bb86-59eb712668bd", "author": "9f56dd64-161d-43a6-b9c3-555944290a09", "vulnerability": "CVE-2017-5754", "type": "seen", "source": "https://gist.github.com/SoulKIngx/9f1e8b1ffa1859b06c5b70915d9c28a0", "content": "&lt;# :\n@type \"%~f0\" | powershell -c - &amp; pause\n#&gt;\n\nfunction Get-SpeculationControlSettings {\n  &lt;#\n\n  .SYNOPSIS\n  This function queries the speculation control settings for the system.\n\n  .DESCRIPTION\n  This function queries the speculation control settings for the system.\n\n  .PARAMETER Quiet\n  This parameter suppresses host output that is displayed by default.\n  \n  #&gt;\n\n  [CmdletBinding()]\n  param (\n    [switch]$Quiet\n  )\n  \n  process {\n\n    $NtQSIDefinition = @'\n    [DllImport(\"ntdll.dll\")]\n    public static extern int NtQuerySystemInformation(uint systemInformationClass, IntPtr systemInformation, uint systemInformationLength, IntPtr returnLength);\n'@\n    \n    $ntdll = Add-Type -MemberDefinition $NtQSIDefinition -Name 'ntdll' -Namespace 'Win32' -PassThru\n\n\n    [System.IntPtr]$systemInformationPtr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(4)\n    [System.IntPtr]$returnLengthPtr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(4)\n\n    $object = New-Object -TypeName PSObject\n\n    try {\n    \n        #\n        # Query branch target injection information.\n        #\n\n        if ($Quiet -ne $true) {\n            Write-Host \"Speculation control settings for CVE-2017-5715 [branch target injection]\" -ForegroundColor Cyan\n            Write-Host \"For more information about the output below, please refer to https://support.microsoft.com/en-in/help/4074629\" -ForegroundColor Cyan\n            Write-Host\n        }\n\n        $btiHardwarePresent = $false\n        $btiWindowsSupportPresent = $false\n        $btiWindowsSupportEnabled = $false\n        $btiDisabledBySystemPolicy = $false\n        $btiDisabledByNoHardwareSupport = $false\n    \n        [System.UInt32]$systemInformationClass = 201\n        [System.UInt32]$systemInformationLength = 4\n\n        $retval = $ntdll::NtQuerySystemInformation($systemInformationClass, $systemInformationPtr, $systemInformationLength, $returnLengthPtr)\n\n        if ($retval -eq 0xc0000003 -or $retval -eq 0xc0000002) {\n            # fallthrough\n        }\n        elseif ($retval -ne 0) {\n            throw ((\"Querying branch target injection information failed with error {0:X8}\" -f $retval))\n        }\n        else {\n    \n            [System.UInt32]$scfBpbEnabled = 0x01\n            [System.UInt32]$scfBpbDisabledSystemPolicy = 0x02\n            [System.UInt32]$scfBpbDisabledNoHardwareSupport = 0x04\n            [System.UInt32]$scfHwReg1Enumerated = 0x08\n            [System.UInt32]$scfHwReg2Enumerated = 0x10\n            [System.UInt32]$scfHwMode1Present = 0x20\n            [System.UInt32]$scfHwMode2Present = 0x40\n            [System.UInt32]$scfSmepPresent = 0x80\n\n            [System.UInt32]$flags = [System.UInt32][System.Runtime.InteropServices.Marshal]::ReadInt32($systemInformationPtr)\n\n            $btiHardwarePresent = ((($flags -band $scfHwReg1Enumerated) -ne 0) -or (($flags -band $scfHwReg2Enumerated)))\n            $btiWindowsSupportPresent = $true\n            $btiWindowsSupportEnabled = (($flags -band $scfBpbEnabled) -ne 0)\n\n            if ($btiWindowsSupportEnabled -eq $false) {\n                $btiDisabledBySystemPolicy = (($flags -band $scfBpbDisabledSystemPolicy) -ne 0)\n                $btiDisabledByNoHardwareSupport = (($flags -band $scfBpbDisabledNoHardwareSupport) -ne 0)\n            }\n\n            if ($Quiet -ne $true -and $PSBoundParameters['Verbose']) {\n                Write-Host \"BpbEnabled                   :\" (($flags -band $scfBpbEnabled) -ne 0)\n                Write-Host \"BpbDisabledSystemPolicy      :\" (($flags -band $scfBpbDisabledSystemPolicy) -ne 0)\n                Write-Host \"BpbDisabledNoHardwareSupport :\" (($flags -band $scfBpbDisabledNoHardwareSupport) -ne 0)\n                Write-Host \"HwReg1Enumerated             :\" (($flags -band $scfHwReg1Enumerated) -ne 0)\n                Write-Host \"HwReg2Enumerated             :\" (($flags -band $scfHwReg2Enumerated) -ne 0)\n                Write-Host \"HwMode1Present               :\" (($flags -band $scfHwMode1Present) -ne 0)\n                Write-Host \"HwMode2Present               :\" (($flags -band $scfHwMode2Present) -ne 0)\n                Write-Host \"SmepPresent                  :\" (($flags -band $scfSmepPresent) -ne 0)\n            }\n        }\n\n        if ($Quiet -ne $true) {\n            Write-Host \"Hardware support for branch target injection mitigation is present:\"($btiHardwarePresent) -ForegroundColor $(If ($btiHardwarePresent) { [System.ConsoleColor]::Green } Else { [System.ConsoleColor]::Red })\n            Write-Host \"Windows OS support for branch target injection mitigation is present:\"($btiWindowsSupportPresent) -ForegroundColor $(If ($btiWindowsSupportPresent) { [System.ConsoleColor]::Green } Else { [System.ConsoleColor]::Red })\n            Write-Host \"Windows OS support for branch target injection mitigation is enabled:\"($btiWindowsSupportEnabled) -ForegroundColor $(If ($btiWindowsSupportEnabled) { [System.ConsoleColor]::Green } Else { [System.ConsoleColor]::Red })\n  \n            if ($btiWindowsSupportPresent -eq $true -and $btiWindowsSupportEnabled -eq $false) {\n                Write-Host -ForegroundColor Red \"Windows OS support for branch target injection mitigation is disabled by system policy:\"($btiDisabledBySystemPolicy)\n                Write-Host -ForegroundColor Red \"Windows OS support for branch target injection mitigation is disabled by absence of hardware support:\"($btiDisabledByNoHardwareSupport)\n            }\n        }\n        \n        $object | Add-Member -MemberType NoteProperty -Name BTIHardwarePresent -Value $btiHardwarePresent\n        $object | Add-Member -MemberType NoteProperty -Name BTIWindowsSupportPresent -Value $btiWindowsSupportPresent\n        $object | Add-Member -MemberType NoteProperty -Name BTIWindowsSupportEnabled -Value $btiWindowsSupportEnabled\n        $object | Add-Member -MemberType NoteProperty -Name BTIDisabledBySystemPolicy -Value $btiDisabledBySystemPolicy\n        $object | Add-Member -MemberType NoteProperty -Name BTIDisabledByNoHardwareSupport -Value $btiDisabledByNoHardwareSupport\n\n        #\n        # Query kernel VA shadow information.\n        #\n        \n        if ($Quiet -ne $true) {\n            Write-Host\n            Write-Host \"Speculation control settings for CVE-2017-5754 [rogue data cache load]\" -ForegroundColor Cyan\n            Write-Host    \n        }\n\n        $kvaShadowRequired = $true\n        $kvaShadowPresent = $false\n        $kvaShadowEnabled = $false\n        $kvaShadowPcidEnabled = $false\n\n        $cpu = Get-WmiObject Win32_Processor\n\n        if ($cpu -is [array]) {\n            $cpu = $cpu[0]\n        }\n\n        $manufacturer = $cpu.Manufacturer\n\n        if ($manufacturer -eq \"AuthenticAMD\") {\n            $kvaShadowRequired = $false\n        }\n        elseif ($manufacturer -eq \"GenuineIntel\") {\n            $regex = [regex]'Family (\\d+) Model (\\d+) Stepping (\\d+)'\n            $result = $regex.Match($cpu.Description)\n            \n            if ($result.Success) {\n                $family = [System.UInt32]$result.Groups[1].Value\n                $model = [System.UInt32]$result.Groups[2].Value\n                $stepping = [System.UInt32]$result.Groups[3].Value\n                \n                if (($family -eq 0x6) -and \n                    (($model -eq 0x1c) -or\n                     ($model -eq 0x26) -or\n                     ($model -eq 0x27) -or\n                     ($model -eq 0x36) -or\n                     ($model -eq 0x35))) {\n\n                    $kvaShadowRequired = $false\n                }\n            }\n        }\n        else {\n            throw (\"Unsupported processor manufacturer: {0}\" -f $manufacturer)\n        }\n\n        [System.UInt32]$systemInformationClass = 196\n        [System.UInt32]$systemInformationLength = 4\n\n        $retval = $ntdll::NtQuerySystemInformation($systemInformationClass, $systemInformationPtr, $systemInformationLength, $returnLengthPtr)\n\n        if ($retval -eq 0xc0000003 -or $retval -eq 0xc0000002) {\n        }\n        elseif ($retval -ne 0) {\n            throw ((\"Querying kernel VA shadow information failed with error {0:X8}\" -f $retval))\n        }\n        else {\n    \n            [System.UInt32]$kvaShadowEnabledFlag = 0x01\n            [System.UInt32]$kvaShadowUserGlobalFlag = 0x02\n            [System.UInt32]$kvaShadowPcidFlag = 0x04\n            [System.UInt32]$kvaShadowInvpcidFlag = 0x08\n\n            [System.UInt32]$flags = [System.UInt32][System.Runtime.InteropServices.Marshal]::ReadInt32($systemInformationPtr)\n\n            $kvaShadowPresent = $true\n            $kvaShadowEnabled = (($flags -band $kvaShadowEnabledFlag) -ne 0)\n            $kvaShadowPcidEnabled = ((($flags -band $kvaShadowPcidFlag) -ne 0) -and (($flags -band $kvaShadowInvpcidFlag) -ne 0))\n\n            if ($Quiet -ne $true -and $PSBoundParameters['Verbose']) {\n                Write-Host \"KvaShadowEnabled             :\" (($flags -band $kvaShadowEnabledFlag) -ne 0)\n                Write-Host \"KvaShadowUserGlobal          :\" (($flags -band $kvaShadowUserGlobalFlag) -ne 0)\n                Write-Host \"KvaShadowPcid                :\" (($flags -band $kvaShadowPcidFlag) -ne 0)\n                Write-Host \"KvaShadowInvpcid             :\" (($flags -band $kvaShadowInvpcidFlag) -ne 0)\n            }\n        }\n        \n        if ($Quiet -ne $true) {\n            Write-Host \"Hardware requires kernel VA shadowing:\"$kvaShadowRequired\n\n            if ($kvaShadowRequired) {\n\n                Write-Host \"Windows OS support for kernel VA shadow is present:\"$kvaShadowPresent -ForegroundColor $(If ($kvaShadowPresent) { [System.ConsoleColor]::Green } Else { [System.ConsoleColor]::Red })\n                Write-Host \"Windows OS support for kernel VA shadow is enabled:\"$kvaShadowEnabled -ForegroundColor $(If ($kvaShadowEnabled) { [System.ConsoleColor]::Green } Else { [System.ConsoleColor]::Red })\n\n                if ($kvaShadowEnabled) {\n                    Write-Host \"Windows OS support for PCID performance optimization is enabled: $kvaShadowPcidEnabled [not required for security]\" -ForegroundColor $(If ($kvaShadowPcidEnabled) { [System.ConsoleColor]::Green } Else { [System.ConsoleColor]::White })\n                }\n            }\n        }\n        \n        $object | Add-Member -MemberType NoteProperty -Name KVAShadowRequired -Value $kvaShadowRequired\n        $object | Add-Member -MemberType NoteProperty -Name KVAShadowWindowsSupportPresent -Value $kvaShadowPresent\n        $object | Add-Member -MemberType NoteProperty -Name KVAShadowWindowsSupportEnabled -Value $kvaShadowEnabled\n        $object | Add-Member -MemberType NoteProperty -Name KVAShadowPcidEnabled -Value $kvaShadowPcidEnabled\n\n        #\n        # Provide guidance as appropriate.\n        #\n\n        $actions = @()\n        \n        if ($btiHardwarePresent -eq $false) {\n            $actions += \"Install BIOS/firmware update provided by your device OEM that enables hardware support for the branch target injection mitigation.\"\n        }\n\n        if ($btiWindowsSupportPresent -eq $false -or $kvaShadowPresent -eq $false) {\n            $actions += \"Install the latest available updates for Windows with support for speculation control mitigations.\"\n        }\n\n        if (($btiHardwarePresent -eq $true -and $btiWindowsSupportEnabled -eq $false) -or ($kvaShadowRequired -eq $true -and $kvaShadowEnabled -eq $false)) {\n            $guidanceUri = \"\"\n            $guidanceType = \"\"\n\n            \n            $os = Get-WmiObject Win32_OperatingSystem\n\n            if ($os.ProductType -eq 1) {\n                # Workstation\n                $guidanceUri = \"https://support.microsoft.com/help/4073119\"\n                $guidanceType = \"Client\"\n            }\n            else {\n                # Server/DC\n                $guidanceUri = \"https://support.microsoft.com/help/4072698\"\n                $guidanceType = \"Server\"\n            }\n\n            $actions += \"Follow the guidance for enabling Windows $guidanceType support for speculation control mitigations described in $guidanceUri\"\n        }\n\n        if ($Quiet -ne $true -and $actions.Length -gt 0) {\n\n            Write-Host\n            Write-Host \"Suggested actions\" -ForegroundColor Cyan\n            Write-Host \n\n            foreach ($action in $actions) {\n                Write-Host \" *\" $action\n            }\n        }\n\n        return $object\n\n    }\n    finally\n    {\n        if ($systemInformationPtr -ne [System.IntPtr]::Zero) {\n            [System.Runtime.InteropServices.Marshal]::FreeHGlobal($systemInformationPtr)\n        }\n \n        if ($returnLengthPtr -ne [System.IntPtr]::Zero) {\n            [System.Runtime.InteropServices.Marshal]::FreeHGlobal($returnLengthPtr)\n        }\n    }    \n  }\n}\n\nGet-SpeculationControlSettings  \n#", "creation_timestamp": "2026-05-12T07:49:43.000000Z"}