how to lock down WinRM service?



Additional Group Policy Settings for Enabling WinRM over HTTPS

To ensure a secure and robust configuration for enabling Windows Remote Management (WinRM) over HTTPS, additional Group Policy settings can be configured. These settings will further enhance security, improve compatibility, and provide more control over the remote management environment.

Below are the additional GPO settings that can be applied:

Step 1: Configure GPO for WinRM Client
  1. Open Group Policy Management Console (GPMC):
  2. Press Win + R, type gpmc.msc, and press Enter.

  3. Edit the Existing GPO:

  4. Right-click the GPO created earlier ("Enable WinRM with HTTPS and Auto-Enrollment") and select Edit.

  5. Navigate to WinRM Client Settings:

  6. Go to Computer Configuration > Policies > Administrative Templates > Windows Components > Windows Remote Management (WinRM) > WinRM Client.

  7. Set Trusted Hosts:

  8. Double-click on "Trusted Hosts".
  9. Set it to Enabled.
  10. Add the names or IP addresses of the computers that are allowed to connect using WinRM. Use wildcards (e.g., *.domain.com) to specify multiple hosts.

  11. Specify Maximum Number of Concurrent Operations:

  12. Double-click "Allow maximum number of concurrent operations".
  13. Set it to Enabled and define the maximum number of concurrent operations that the WinRM client can establish. The default is 5.

  14. Configure CredSSP for Authentication:

  15. Go to Computer Configuration > Policies > Administrative Templates > System > Credentials Delegation.
  16. Double-click "Allow delegating fresh credentials with NTLM-only server authentication".
  17. Set it to Enabled and specify the list of servers for which the credentials can be delegated.
Step 2: Configure GPO for WinRM Service
  1. Navigate to WinRM Service Settings:
  2. Go to Computer Configuration > Policies > Administrative Templates > Windows Components > Windows Remote Management (WinRM) > WinRM Service.

  3. Allow Remote Shell Access:

  4. Double-click on "Allow remote server management through WinRM".
  5. Set it to Enabled.
  6. Ensure that the IPv4 and IPv6 Filter settings allow connections from the required IP ranges or addresses.

  7. Configure the Maximum Number of Concurrent Users:

  8. Double-click "Allow maximum number of connections".
  9. Set it to Enabled and specify the maximum number of users that can connect concurrently to the WinRM service. The default value is 25.

  10. Set Timeouts for Idle and Operation Timeout:

  11. Double-click "Allow WinRM service to receive requests from remote computers".
  12. Set it to Enabled and configure the Idle Timeout (e.g., 240000 milliseconds) and Operation Timeout as needed.

  13. Enable Compatibility HTTP Listener:

  14. Double-click "Allow compatibility HTTP listener".
  15. Set it to Enabled. This setting allows older systems to connect using HTTP for management purposes while you transition to HTTPS.
Step 3: Configure Additional Security Settings
  1. Enable Secure Connections with HTTPS:
  2. Ensure that WinRM is configured to use only HTTPS by restricting the allowed listeners:

    • Go to Computer Configuration > Policies > Administrative Templates > Windows Components > Windows Remote Management (WinRM) > WinRM Service > Allow unencrypted traffic.
    • Set it to Disabled to enforce encrypted communication only.
  3. Disable Basic Authentication:

  4. Go to Computer Configuration > Policies > Administrative Templates > Windows Components > Windows Remote Management (WinRM) > WinRM Service > Allow Basic authentication.
  5. Set it to Disabled to prevent the use of basic (plaintext) authentication.

  6. Enable Kerberos Authentication:

  7. Go to Computer Configuration > Policies > Administrative Templates > Windows Components > Windows Remote Management (WinRM) > WinRM Service > Allow Kerberos authentication.
  8. Set it to Enabled to ensure Kerberos authentication is always used.
Step 4: Apply the Policy and Test Configuration
  1. Close the GPO Editor:
  2. Save and close the Group Policy Management Editor.

  3. Force Group Policy Update:

  4. On the target servers, open a command prompt with administrative privileges and run:

powershell gpupdate /force

  1. Verify WinRM Configuration:
  2. Test the configuration using the following command:

powershell Test-WsMan -ComputerName <ServerName>

Summary of Additional GPO Settings

By applying these additional GPO settings, you enhance the security and control of your WinRM environment:

  • WinRM Client Configuration:
  • Set trusted hosts and maximum concurrent operations.
  • Configure CredSSP for secure authentication.
  • WinRM Service Configuration:
  • Allow remote shell access and set maximum connections.
  • Enable timeouts and compatibility listeners.
  • Security Settings:
  • Enforce HTTPS, disable basic authentication, and enable Kerberos.

Additional Considerations

  • Audit and Monitoring: Regularly audit WinRM logs and monitor connections for unauthorized access attempts.
  • Testing: Test all configurations in a controlled environment before applying them widely to ensure they meet your organization's security policies.

Pure PowerShell Implementation

Here's a script to apply these additional settings using PowerShell:

# Define variables
$gpoName = "Enable WinRM with HTTPS and Auto-Enrollment"
$trustedHosts = "*.domain.com" # Replace with your domain or specific hosts
$maxConcurrentOperations = 5
$maxConnections = 25
$idleTimeoutMs = 240000
$operationTimeoutMs = 60000

# Function to configure additional GPO settings for WinRM
function Configure-AdditionalGPOSettings {
    # Import GroupPolicy module
    Import-Module GroupPolicy

    # Set trusted hosts
    Write-Output "Configuring Trusted Hosts..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client" -ValueName "TrustedHosts" -Type String -Value $trustedHosts

    # Set maximum concurrent operations
    Write-Output "Configuring maximum concurrent operations..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client" -ValueName "MaxConcurrentOperations" -Type DWORD -Value $maxConcurrentOperations

    # Allow remote server management through WinRM
    Write-Output "Allowing remote server management through WinRM..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "AllowAutoConfig" -Type DWORD -Value 1

    # Set maximum connections
    Write-Output "Configuring maximum connections..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "MaxConnections" -Type DWORD -Value $maxConnections

    # Set timeouts
    Write-Output "Configuring timeouts..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "IdleTimeout" -Type DWORD -Value $idleTimeoutMs
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "OperationTimeout" -Type DWORD -Value $operationTimeoutMs

    # Disable basic authentication
    Write-Output "Disabling Basic Authentication..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "AllowBasic" -Type DWORD -Value 0

    # Enable Kerberos authentication
    Write-Output "Enabling Kerberos Authentication..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "AllowKerberos" -Type DWORD -Value 1

    # Enforce HTTPS-only connections
    Write-Output "Disabling unencrypted traffic..."
    Set-GPRegistryValue -Name $gpoName -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service" -ValueName "AllowUnencryptedTraffic" -Type DWORD -Value 0
}

# Execute additional GPO configuration
Write-Output "Applying additional GPO settings for WinRM..."
Configure-AdditionalGPOSettings
Write-Output "Additional GPO configuration completed successfully!"

How to Use the PowerShell Script

  1. Run PowerShell as Administrator: Open PowerShell with elevated privileges.
  2. Save the Script: Save the script as Configure-Additional-WinRM-GPO.ps1.
  3. Execute the Script:

powershell .\Configure-Additional-WinRM-GPO.ps1