让Windows XP SP3远程桌面连接支持网络级身份验证的脚本

简介:

知识点:网络级别身份验证 (NLA) 是一项新的身份验证方法,即在您建立完整的远程桌面连接前就完成了用户身份验证并显示登录屏幕。它是一项更加安全的身份验证方法,可以防止远程计算机受到 黑客或恶意软件的攻击。NLA 的优点是: 最初只需要少量的远程计算机资源。对用户进行身份验证之前,远程计算机仅使用有限的资源,而不是像在先前版本中启动整个远程桌面连接。  可以通过降低拒绝服务攻击(尝试限制或阻止访问 Internet)的风险提供更高的安全保障。  使用远程计算机身份验证可以防止我们连接到因恶意目的而安装的远程计算机。


 

如果在Windows 7或Windows 2008远程桌面里启用了“带网络级别的身份验证”默认在XPSP3里是没有办法用“远程桌面连接”连接到2008的,需要手工的修改二项注册表。
1
 
默认XPSP3是“不支持网络级别的身份验证”如下图:
  2
如何使它支持网络级别的身份验证呢?需要手工的改两个注册表键值,具体操作如下:
  1. 单击 开始 ,单击 运行 ,键入 regedit ,然后按 ENTER 键。
  2. 在导航窗格找到,并单击下面的注册表子项:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
  3. 在详细信息窗格中右键单击 安全包 ,然后单击 修改 
  4. 在 数值数据 框中,键入 tspkg 。 将只用于其他 SSP 的任何数据,然后单击 确定 
  3
5、在导航窗格找到,并单击下面的注册表子项:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders
6、在详细信息窗格中右键单击 SecurityProviders,然后单击  修改 
7、在  数值数据 框中,键入 credssp.dll 。 将只用于其他 SSP 的任何数据,然后单击  确定 
 
  4 
8、退出注册表编辑器。
9、重新启动计算机。
  5
 
 

======================================================================

Following on from my previous blog entry, while the manual method is simple enough, and we could just import a .REG file to force “Security Packages” and “SecurityProviders” to fixed values, it would be more elegant to have a smarter solution that will make the amendments if necessary.

So here is a VBScript to check if “tspkg” is in “Security Packages” and “credssp.dll” is in “SecurityProviders”, and add them if not. 
It also reports on the status of the GPO settings affecting DisableRootAutoUpdate and CredentialsDelegation (default and saved), but does not attempt to adjust these as they should be done via GPO rather than registry edits.

Use this script at your own risk – I’ve tested it very briefly but there is no error checking or backing up of the keys/values performed, and it does not attempt to verify the OS version is applicable.

If double-clicked then wscript.exe is used by default and the result is displayed in a pop-up window – if it needs to be run in a computer startup script then make sure to explicitly use cscript.exe (and optionally pipe the output to a log file if needed).

 

 
 
  1. ' ============================================ 
  2. ' CheckCredSSP.vbs 
  3. ' 
  4. ' Verifies that the settings necessary for CredSSP are enabled on XP clients 
  5. ' As per http://support.microsoft.com/kb/951608 
  6. ' 
  7. ' Checks if DisableRootAutoUpdate policy setting is enabled to avoid a 30-second 
  8. ' delay when clients have no access to Windows Update and NLA is used 
  9. ' 
  10. ' Displays a summary of any credential delegation policy settings found 
  11. ' ============================================ 
  12. const HKEY_LOCAL_MACHINE = &H80000002 
  13. const REG_SZ = 1 
  14. strComputer = "." 
  15.  
  16. ' Variables to hold results of key enumeration and the value types 
  17. arrNames = Array() 
  18. arrTypes = Array() 
  19.  
  20. ' Variables to hold values for REG_MULTI_SZ, REG_SZ and REG_DWORD data 
  21. arrValues = Array() 
  22. strValue = "" 
  23. dwValue = 0 
  24.  
  25. ' Object to allow us access to the registry 
  26. Set objReg=GetObject( _ 
  27.     "winmgmts:{impersonationLevel=impersonate}!\\" & _ 
  28.    strComputer & "\root\default:StdRegProv"
  29.  
  30.  
  31. ' ============================================ 
  32. ' Check for (and add if necessary) tspkg in REG_MULTI_SZ value 
  33. ' ============================================ 
  34. strKeyPath = "SYSTEM\CurrentControlSet\Control\Lsa" 
  35. strValueName = "Security Packages" 
  36. bPresent_tspkg = FALSE 
  37.  
  38. If ( objReg.GetMultiStringValue( HKEY_LOCAL_MACHINE, strKeyPath, strValueName, arrValues ) <> 0 ) Then 
  39.   ' Failed to read the value, exit early 
  40.   WScript.Echo "ERROR - Failed to open value: " & strValueName 
  41.   WScript.Quit 
  42. End If 
  43.  
  44. For Each strElement in arrValues 
  45.   If strElement = "tspkg" Then bPresent_tspkg = TRUE 
  46. Next 
  47.  
  48. If Not bPresent_tspkg Then 
  49.   ReDim Preserve arrValues( UBound( arrValues ) + 1 ) 
  50.   arrValues( UBound( arrValues ) ) = "tspkg" 
  51.   iError = objReg.SetMultiStringValue( HKEY_LOCAL_MACHINE, strKeyPath, strValueName, arrValues ) 
  52.   If ( iError <> 0 ) Then 
  53.     ' Failed to write the value, exit early 
  54.     WScript.Echo "ERROR - Failed to write value: " & strValueName & vbCrLf & "Error code: " & iError 
  55.     WScript.Quit 
  56.   End If 
  57. End If 
  58.  
  59.  
  60. ' ============================================ 
  61. ' Check for (and add if necessary) credssp.dll in REG_SZ value 
  62. ' ============================================ 
  63. strKeyPath = "SYSTEM\CurrentControlSet\Control\SecurityProviders" 
  64. strValueName = "SecurityProviders" 
  65. bPresent_credssp = FALSE 
  66.  
  67. If ( objReg.GetStringValue( HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue ) <> 0 ) Then 
  68.   ' Failed to read the value, exit early 
  69.   WScript.Echo "ERROR - Failed to open value: " & strValueName 
  70.   WScript.Quit 
  71. End If 
  72.  
  73. ' Convert the comma-separated string into an array of strings to check each element 
  74. arrValues = ConvertStrToArr( strValue ) 
  75. For Each strElement in arrValues 
  76.   ' We use LTrim() to ignore leading spaces (i.e. spaces after commas) 
  77.   If LTrim( strElement ) = "credssp.dll" Then bPresent_credssp = TRUE 
  78. Next 
  79.  
  80. If Not bPresent_credssp Then 
  81.   If ( strValue <> "" ) Then strValue = strValue & ", " 
  82.   strValue = strValue & "credssp.dll" 
  83.   iError = objReg.SetStringValue( HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue ) 
  84.   If ( iError <> 0 ) Then 
  85.     ' Failed to write the value, exit early 
  86.     WScript.Echo "ERROR - Failed to write value: " & strValueName & vbCrLf & "Error code: " & iError 
  87.     WScript.Quit 
  88.   End If 
  89. End If 
  90.  
  91.  
  92. ' ============================================ 
  93. ' Check for DisableRootAutoUpdate = 1 
  94. ' ============================================ 
  95. strKeyPath = "SOFTWARE\Policies\Microsoft\SystemCertificates\AuthRoot" 
  96. strValueName = "DisableRootAutoUpdate" 
  97.  
  98. strPolicyOutput = vbCrLf & vbCrLf &_ 
  99.                   "DisableRootAutoUpdate policy setting " 
  100.  
  101. ' Does the value exist and is non-zero? 
  102. If ( objReg.GetDWORDValue( HKEY_LOCAL_MACHINE, strKeyPath, strValueName, dwValue ) = 0 ) Then 
  103.   If ( dwValue <> 0 ) Then 
  104.     strPolicyOutput = strPolicyOutput & "found : ENABLED" & vbCrLf & vbCrLf 
  105.   Else 
  106.     strPolicyOutput = strPolicyOutput & "found : DISABLED" & vbCrLf & vbCrLf 
  107.   End If 
  108. Else 
  109.   strPolicyOutput = strPolicyOutput & "NOT found" & vbCrLf &_ 
  110.                     "Consider enabling the following policy setting if hitting a ~30 second delay:" & vbCrLf &_ 
  111.                     "Administrative Templates > System > Internet Communication Management > Internet Communication Settings" & vbCrLf &_ 
  112.                     "Turn off Automatic Root Certificates Update" & vbCrLf & vbCrLf 
  113. End If 
  114.  
  115.  
  116. ' ============================================ 
  117. ' Check for any policy settings relating to credential delegation 
  118. ' ============================================ 
  119. strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation" 
  120.  
  121. If ( objReg.EnumValues( HKEY_LOCAL_MACHINE, strKeyPath, arrNames, arrTypes ) <> 0 ) Then 
  122.   strPolicyOutput = strPolicyOutput & "Found no credential delegation policy settings (e.g. SSO, saved credentials)" & vbCrLf &_ 
  123.                     "Recommend reading KB951608 if SSO is required." & vbCrLf &_ 
  124.                     "Or check under:" & vbCrLf &_ 
  125.                     "Administrative Templates > System > Credentials Delegation" & vbCrLf 
  126. Else 
  127.   strPolicyOutput = strPolicyOutput & "Found credential delegation policy settings..." & vbCrLf 
  128.  
  129.   strPolicyCheck = CheckPolicy( "DenyDefaultCredentials" ) 
  130.   If ( strPolicyCheck = "" ) Then 
  131.     strPolicyCheck = CheckPolicy( "AllowDefaultCredentials" ) 
  132.     strPolicyCheck = strPolicyCheck & CheckPolicy( "AllowDefCredentialsWhenNTLMOnly" ) 
  133.   Else 
  134.     strPolicyOutput = strPolicyOutput & vbCrLf & "DEFAULT credential delegation (SSO) explicitly DENIED by policy" & vbCrLf 
  135.   End If 
  136.   strPolicyOutput = strPolicyOutput & strPolicyCheck 
  137.  
  138.   strPolicyCheck = CheckPolicy( "DenySavedCredentials" ) 
  139.   If ( strPolicyCheck = "" ) Then 
  140.     strPolicyCheck = CheckPolicy( "AllowSavedCredentials" ) 
  141.     strPolicyCheck = strPolicyCheck & CheckPolicy( "AllowSavedCredentialsWhenNTLMOnly" ) 
  142.   Else 
  143.     strPolicyOutput = strPolicyOutput & vbCrLf & "SAVED credential delegation explicitly DENIED by policy" & vbCrLf 
  144.   End If 
  145.   strPolicyOutput = strPolicyOutput & strPolicyCheck 
  146. End If 
  147.  
  148.  
  149. ' ============================================ 
  150. ' Display summary of actions 
  151. ' ============================================ 
  152. strOutput = "Security Packages - tspkg : " 
  153.  
  154. If Not bPresent_tspkg Then 
  155.   strOutput = strOutput & "PRESENT (added)" 
  156. Else 
  157.   strOutput = strOutput & "PRESENT" 
  158. End If 
  159.  
  160. strOutput = strOutput & vbCrLf & vbCrLf &_ 
  161.             "SecurityProviders - credssp.dll : " 
  162.  
  163. If Not bPresent_credssp Then 
  164.   strOutput = strOutput & "PRESENT (added)" 
  165. Else 
  166.   strOutput = strOutput & "PRESENT" 
  167. End If 
  168.  
  169. WScript.Echo strOutput & strPolicyOutput 
  170.  
  171.  
  172. ' ============================================ 
  173. ' Function to convert a comma-separated string into an array of strings 
  174. ' ============================================ 
  175. Function ConvertStrToArr ( strInput ) 
  176.   Set objRegExp = CreateObject( "VBScript.RegExp" ) 
  177.   objRegExp.IgnoreCase = TRUE 
  178.   objRegExp.Global = TRUE 
  179.   objRegExp.Pattern = ",(?=([^']*'[^']*')*(?![^']*'))" 
  180.   ConvertStrToArr = Split( objRegExp.Replace(strInput, "\b"), "\b" ) 
  181. End Function 
  182.  
  183.  
  184. ' ============================================ 
  185. ' Function to check for a credential delegation policy setting 
  186. ' ============================================ 
  187. Function CheckPolicy ( strPolicy ) 
  188.   dwValue = 0 
  189.   If ( objReg.GetDWORDValue( HKEY_LOCAL_MACHINE, strKeyPath, strPolicy, dwValue ) = 0 ) Then 
  190.     CheckPolicy = strPolicy & " = " & dwValue 
  191.     If ( dwValue <> 0 ) Then 
  192.       CheckPolicy = CheckPolicy & " (ENABLED)" & vbCrLf 
  193.       If ( objReg.EnumValues( HKEY_LOCAL_MACHINE, strKeyPath & "\" & strPolicy, arrNames, arrTypes ) = 0 ) Then 
  194.         If IsArray( arrNames ) Then 
  195.           For i = 0 To UBound( arrNames ) 
  196.             If ( arrTypes( i ) = REG_SZ ) Then 
  197.               If ( objReg.GetStringValue( HKEY_LOCAL_MACHINE, strKeyPath & "\" & strPolicy, arrNames( i ), strValue ) <> 0 ) Then 
  198.                 ' Failed to read the value, exit early 
  199.                  WScript.Echo "ERROR - Failed to open value: " & arrNames( i ) 
  200.                  WScript.Quit 
  201.               End If 
  202.               CheckPolicy = CheckPolicy & " > " & strValue & vbCrLf 
  203.             End If 
  204.           Next 
  205.         Else 
  206.           CheckPolicy = CheckPolicy & " > [no SPNs specified]" & vbCrLf 
  207.         End If 
  208.       Else 
  209.         CheckPolicy = CheckPolicy & " > [no SPNs specified]" & vbCrLf 
  210.       End If 
  211.     Else 
  212.       CheckPolicy = CheckPolicy & " (DISABLED)" & vbCrLf 
  213.     End If 
  214.   End If 
  215. End Function 









本文转自 h2appy  51CTO博客,原文链接:http://blog.51cto.com/h2appy/812554,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
Ubuntu
虚拟机Ubuntu连接不了网络的解决方法
虚拟机Ubuntu连接不了网络的解决方法
|
2月前
|
Shell Linux C语言
【Shell 命令集合 网络通讯 】Linux 关闭PPP(Point-to-Point Protocol)连接 ppp-off命令 使用指南
【Shell 命令集合 网络通讯 】Linux 关闭PPP(Point-to-Point Protocol)连接 ppp-off命令 使用指南
45 1
|
2月前
|
监控 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 显示网络 连接、路由表和网络接口信息 netstat命令 使用指南
【Shell 命令集合 网络通讯 】Linux 显示网络 连接、路由表和网络接口信息 netstat命令 使用指南
70 1
|
11天前
|
安全 网络协议 物联网
城域以太网:连接城市的高速网络
【4月更文挑战第22天】
20 0
|
11天前
|
数据可视化 网络协议
|
11天前
|
设计模式 数据中心 网络架构
|
19天前
|
Apache 数据安全/隐私保护 Windows
如何在Windows部署TortoiseSVN客户端并实现公网连接内网VisualSVN服务端
如何在Windows部署TortoiseSVN客户端并实现公网连接内网VisualSVN服务端
|
20天前
|
安全 网络安全 数据安全/隐私保护
HTTP代理SSL连接:保障网络安全的重要协议
HTTP代理SSL连接:保障网络安全的重要协议
|
21天前
|
运维 安全 Cloud Native
安全访问服务边缘(SASE):网络新时代的安全与连接解决方案
SASE(安全访问服务边缘)是一种云基安全模型,结合了网络功能和安全策略,由Gartner在2019年提出。它强调身份驱动的私有网络、云原生架构和全面边缘支持,旨在解决传统WAN和安全方案的局限性,如高延迟和分散管理。SASE通过降低IT成本、提升安全响应和网络性能,应对数据分散、风险控制和访问速度等问题,适用于移动办公、多分支办公等场景。随着网络安全挑战的增加,SASE将在企业的数字化转型中扮演关键角色。
|
26天前
|
Windows
【Windows】 手写脚本更快编辑hosts文件
【Windows】 手写脚本更快编辑hosts文件
22 0