让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,如需转载请自行联系原作者
目录
相关文章
|
18天前
|
编解码 异构计算
RT-DETR改进策略【Neck】| BiFPN:双向特征金字塔网络-跨尺度连接和加权特征融合
RT-DETR改进策略【Neck】| BiFPN:双向特征金字塔网络-跨尺度连接和加权特征融合
56 9
RT-DETR改进策略【Neck】| BiFPN:双向特征金字塔网络-跨尺度连接和加权特征融合
|
18天前
|
计算机视觉
RT-DETR改进策略【Neck】| GFPN 超越BiFPN 通过跳层连接和跨尺度连接改进RT-DETR颈部网络
RT-DETR改进策略【Neck】| GFPN 超越BiFPN 通过跳层连接和跨尺度连接改进RT-DETR颈部网络
45 12
RT-DETR改进策略【Neck】| GFPN 超越BiFPN 通过跳层连接和跨尺度连接改进RT-DETR颈部网络
|
20天前
|
计算机视觉
YOLOv11改进策略【Neck】| GFPN 超越BiFPN 通过跳层连接和跨尺度连接改进v11颈部网络
YOLOv11改进策略【Neck】| GFPN 超越BiFPN 通过跳层连接和跨尺度连接改进v11颈部网络
65 10
YOLOv11改进策略【Neck】| GFPN 超越BiFPN 通过跳层连接和跨尺度连接改进v11颈部网络
|
20天前
|
编解码 异构计算
YOLOv11改进策略【Neck】| BiFPN:双向特征金字塔网络-跨尺度连接和加权特征融合
YOLOv11改进策略【Neck】| BiFPN:双向特征金字塔网络-跨尺度连接和加权特征融合
81 7
YOLOv11改进策略【Neck】| BiFPN:双向特征金字塔网络-跨尺度连接和加权特征融合
|
1月前
|
安全 Linux 网络安全
利用Python脚本自动备份网络设备配置
通过本文的介绍,我们了解了如何利用Python脚本自动备份网络设备配置。该脚本使用 `paramiko`库通过SSH连接到设备,获取并保存配置文件。通过定时任务调度,可以实现定期自动备份,确保网络设备配置的安全和可用。希望这些内容能够帮助你在实际工作中实现网络设备的自动化备份。
61 14
|
2月前
|
负载均衡 网络协议 算法
不为人知的网络编程(十九):能Ping通,TCP就一定能连接和通信吗?
这网络层就像搭积木一样,上层协议都是基于下层协议搭出来的。不管是ping(用了ICMP协议)还是tcp本质上都是基于网络层IP协议的数据包,而到了物理层,都是二进制01串,都走网卡发出去了。 如果网络环境没发生变化,目的地又一样,那按道理说他们走的网络路径应该是一样的,什么情况下会不同呢? 我们就从路由这个话题聊起吧。
83 4
不为人知的网络编程(十九):能Ping通,TCP就一定能连接和通信吗?
|
3月前
|
物联网 5G 数据中心
|
4月前
|
Docker 容器
docker swarm启动服务并连接到网络
【10月更文挑战第16天】
84 5
|
3月前
|
存储 缓存 Dart
Flutter&鸿蒙next 封装 Dio 网络请求详解:登录身份验证与免登录缓存
本文详细介绍了如何在 Flutter 中使用 Dio 封装网络请求,实现用户登录身份验证及免登录缓存功能。首先在 `pubspec.yaml` 中添加 Dio 和 `shared_preferences` 依赖,然后创建 `NetworkService` 类封装 Dio 的功能,包括请求拦截、响应拦截、Token 存储和登录请求。最后,通过一个登录界面示例展示了如何在实际应用中使用 `NetworkService` 进行身份验证。希望本文能帮助你在 Flutter 中更好地处理网络请求和用户认证。
235 1
|
4月前
|
安全 网络架构
无线网络:连接未来的无形纽带
【10月更文挑战第13天】
113 4