Powershell : Bypass CredSPP to allow RDP

This is a very unique scenario where you need to disable this particular security feature, this particular situation came about because I needed to rebuild an older server that was not patched when it comes out of the box.

CredSPP - what’s that ?

You can get the full rundown here however this is the overview from Microsoft:

Credential Security Support Provider protocol (CredSSP) is an authentication provider that processes authentication requests for other applications.

A remote code execution vulnerability exists in unpatched versions of CredSSP. An attacker who successfully exploits this vulnerability could relay user credentials to execute code on the target system. Any application that depends on CredSSP for authentication may be vulnerable to this type of attack.

This security update addresses the vulnerability by correcting how CredSSP validates requests during the authentication process.

Security (CVE) vulnerability CredSSP

This is the security issue : CVE-2018-0866 - this was patched back in March 2018, which means if all your infrastructure is kept up with patches, you should not get the problem caused with unsupported operating systems not being attached.

When you attempt to RDP to a server check it will check the validity of this patch and if you have a new server with no patching and a client that is patched you will get this error:


This particular error is telling you that the client you’re trying to connect to has detected that the server is not patched, this means your client will decline the connection, if you are using an older version of RDP, and older, I mean server 2012 R2 and before the connection will simply fail, you will not get the error above.

CredSSP : Unable to patch due to denied connection

I have literally just built an old server that failed, the operating system of choice was Server 2016, however, out of the box that product is RTM (release to manufacturer) which means that server has never seen a Windows update in its life.

This is inherently bad because you now have a unpatched server in your network, at this stage, it is not part of our domain it is still in a workgroup.

However, this is still not a great position to be in and we need to get it patched, However, now we have the complication of not been able to remotely control it via RDP.

CredSSP bypass : temporarily

All the other devices inside your network should be fully patched so the only way you can manage this server to get it patched is to temporarily turn off this protection.

The script needs to be run on the client that’s trying to connect to this newly built server, Make sure you run this power shower with an elevator command prompt and this is the code:

Script : DisableCredSSP.ps1

# Define the registry key path and value name
$credsspRegistryPath = "HKLM:\SOFTWARE\Policies\Oracle\CredSSP"
$credsspValueName = "AllowCredentials"
$vulnerableValue = 1

# Create the registry key if it doesn't exist
if (-not (Test-Path $credsspRegistryPath)) {
    New-Item -Path $credsspRegistryPath -Force | Out-Null
}
# Set the registry value to enable vulnerable mode
Set-ItemProperty -Path $credsspRegistryPath -Name $credsspValueName -Value $vulnerableValue
Write-Host "CredSSP has been set to vulnerable mode (value set to 1)."

Operation Patching may commence

You have now turned off the CredSSP Protection, so now you need to RDP To the server and get the updates installed In an urgent manor - por favor - in my case, I’m running in server 2016 so cumulative update apply, Immediately at the time of writing this 2024-08 being downloaded ready to be installed.

The download will happen quite quickly, but the installation may take a considerable amount of time because there’s a lot of updates to get through, just remember that on the reboot, you may need a couple of reboot before you get back to usable login prompt.

Confirm hotfixes

Once the server is fully back online, I would hold off trying to RDP to the server, I’m from the client start a Powershell window as an administrator/elevated and run this command:

Get-Hotfix -Computer CredSSP.bear.local

That command should return all the hot fixes installed, which should show some from today, that will be a couple that should be installed today as you can see below:

Description      HotFixID      InstalledBy          InstalledOn
-----------      --------      -----------          -----------
Update           KB4049065     NT AUTHORITY\SYSTEM  03/02/2018 00:00:00
Security Update  KB5041576     NT AUTHORITY\SYSTEM  26/08/2024 00:00:00
Update           KB4103720     NT AUTHORITY\SYSTEM  26/08/2024 00:00:00

Remember to check for updates after reboot

Once you have installed the first batch of updates remeber to check for th new updates as you may find more updates are still applicble to keep your server secure, when I rechecked with this command : 

Get-Hotfix -Computer CredSSP.bear.local

I got 2 x additional updates as you can see in bold below:

Description      HotFixID      InstalledBy          InstalledOn
-----------      --------      -----------          -----------
Update           KB4049065     NT AUTHORITY\SYSTEM  03/02/2018 00:00:00
Update           KB4589210     NT AUTHORITY\SYSTEM  27/08/2024 00:00:00
Security Update  KB5012170     NT AUTHORITY\SYSTEM  26/08/2024 00:00:00
Security Update  KB5041576     NT AUTHORITY\SYSTEM  26/08/2024 00:00:00
Security Update  KB5041773     NT AUTHORITY\SYSTEM  27/08/2024 00:00:00

Check Windows Updates in Settings

Ensure all your updates are installed and you are fully patched by navigating in the settings application to Settings>Update and Security>Windows Update and ensure it look like this with "You device is up to date"

CredSSP Protect Mode : Enable protection

If you can see the latest hotfixes for today, then there is no reason to leave CredSSP in the bypass state, this means you’re ready to re-enable this protection - these command need to be run on the client not the server so you can use the same windows as before, but this time you need this code:

Script : EnableCredSSP.ps1

# Define the registry key path and value name
$credsspRegistryPath = "HKLM:\SOFTWARE\Policies\Oracle\CredSSP"
$credsspValueName = "AllowCredentials"
$secureValue = 0

# Create the registry key if it doesn't exist
if (-not (Test-Path $credsspRegistryPath)) {
    New-Item -Path $credsspRegistryPath -Force | Out-Null
}

# Set the registry value to secure mode
Set-ItemProperty -Path $credsspRegistryPath -Name $credsspValueName -Value $secureValue

Write-Host "CredSSP has been set to secure mode (value set to 0)."

Confirm RDP is available

You have just reenabled the protection on your client, Now the server has restarted you should now able to seamlessly connect with the setting in protect mode.
Previous Post Next Post

نموذج الاتصال