从 ASP 访问 IIS WMI 提供程序时出现访问被拒绝错误

发布于 2024-08-21 02:37:34 字数 811 浏览 4 评论 0原文

我有一台运行 IIS 6 的 Windows 2003 服务器,并且有一些脚本可以自动设置和创建网站。他们没有在我调试的新服务器上工作(他们已经在其他 3 台 W2K3 服务器上正常工作)。该问题似乎归结为 IIS 提供程序上的 WMI 安全性。下面的 ASP 代码代表了该问题(尽管它不是导致该问题的原始代码 - 这是该问题的简化演示)。

Set wmiProvider = GetObject("winmgmts:\\.\root\MicrosoftIISv2")
If wmiProvider is Nothing Then
Response.Write "Failed to get WMI provider MicrosoftIISv2<br>"
End If

Response.Write "Querying for IISWebService...<br>"
Set colItems = wmiProvider.ExecQuery("Select * From IISWebServer",,0)
Response.Write "Error: " & Hex(Err.Number) & " (" & Err.Description & ")<br>"

如果我在浏览器中运行此命令,则会在 ExecQuery 调用后报告访问被拒绝错误。我已经从根分支一直向下设置了 IUSR_ 用户的 WMI 访问权限。事实上,我可以很高兴地使用 CIMV2 提供程序查询 IP 地址信息。如果我将 IUSR 用户放入计算机管理员组中,一切都会正常,但我真的不想这样做。

这肯定是 DCOM/WMI 安全问题,但我不知道还有什么问题。任何人都可以阐明吗?

I have a Windows 2003 server running IIS 6 and have some scripts that do automated setup and creation of websites. They are not working on a new server I cam commissioning (they already work happily on 3 other W2K3 servers). The problem appear to boil down to WMI security on the IIS provider. The ASP code below represents the problem (although it is not the original code that causes the problem - this is a simplified demonstration of the problem).

Set wmiProvider = GetObject("winmgmts:\\.\root\MicrosoftIISv2")
If wmiProvider is Nothing Then
Response.Write "Failed to get WMI provider MicrosoftIISv2<br>"
End If

Response.Write "Querying for IISWebService...<br>"
Set colItems = wmiProvider.ExecQuery("Select * From IISWebServer",,0)
Response.Write "Error: " & Hex(Err.Number) & " (" & Err.Description & ")<br>"

If I run this in my browser, I get an access denied error reported after the ExecQuery call. I have set WMI access for the IUSR_ user from the Root branch all the way down. In fact, I can query for IP address information using the CIMV2 provider quite happily. If I put the IUSR user in the machine admins group it all works, but I don't really want to do that.

This must be a DCOM/WMI security problem, but I can't work out what else there is. Can anyone shed any light?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏日落 2024-08-28 02:37:34

在阅读 G. Stoynev 询问 Windows 日志中是否记录了任何事件的评论后,我检查了我尝试通过 WMI 远程访问 IIS 的服务器上的事件日志,你瞧,我发现了一个包含以下文本的事件:

对 root\WebAdministration 命名空间的访问被拒绝,因为该命名空间标记有 RequiresEncryption,但脚本或应用程序尝试使用低于 Pkt_Privacy 的身份验证级别连接到此命名空间。将身份验证级别更改为 Pkt_Privacy 并再次运行脚本或应用程序。

请参阅相关 SO 问题的此答案中的代码c# - WMI 出现“访问被拒绝”异常

下面是我添加的一些示例 C# 代码,它似乎可以为我解决这个问题:

ConnectionOptions options = new ConnectionOptions();
options.Authentication = AuthenticationLevel.PacketPrivacy;
ManagementScope managementScope = new ManagementScope(@"\\remote-server\root\WebAdministration", options);
// ...

After reading G. Stoynev's comment asking if any events were logged in the Windows Logs, I checked the event logs on the server to which I'm attempting to access IIS remotely via WMI, and lo and behold I found an event with the following text:

Access to the root\WebAdministration namespace was denied because the namespace is marked with RequiresEncryption but the script or application attempted to connect to this namespace with an authentication level below Pkt_Privacy. Change the authentication level to Pkt_Privacy and run the script or application again.

See the code in this answer to the related SO question c# - "Access is denied" Exception with WMI.

Here's some example C# code that I added that seemed to resolve this issue for me:

ConnectionOptions options = new ConnectionOptions();
options.Authentication = AuthenticationLevel.PacketPrivacy;
ManagementScope managementScope = new ManagementScope(@"\\remote-server\root\WebAdministration", options);
// ...
坐在坟头思考人生 2024-08-28 02:37:34

如果您打算将其作为自己或管理员的工具运行(而不是未经洗礼的匿名群众),那么这是我过去使用过的一种方法(YMMV):

  1. 在您的网站中设置一个新目录(例如 /SiteCreate)并将您的 WMI 脚本放置在那里
  2. 配置具有适当权限的 Windows 用户(在本例中可能是管理员,但您应该使用与您的应用程序相关的任何内容)
  3. 关闭关闭对目录的匿名访问您在步骤 1 中创建,然后将安全性设置为仅允许访问您在步骤 2 中创建的用户(打开该目录的身份验证)

现在,当您在浏览器中导航到该目录时,您应该会收到登录提示。当您输入在步骤 2 中创建的用户名/密码时,您的脚本将具有执行 WMI 请求的适当权限。

If this is something that you intend to run as a tool for yourself or your admin (as opposed to the unwashed anonymous masses), here is a way I have used in the past (YMMV):

  1. Set up a new directory in your website (e.g. /SiteCreate) and place your WMI scripts there
  2. Configure a Windows user that has appropriate rights (probably admin in this case but you should use whatever is pertinent to your app)
  3. Turn off the anonymous access to the directory you created in step 1 and then set the security to allow access only to the user you created in step 2 (turn on the authentication for that directory)

Now, when you navigate to that directory in your browser, you should get a login prompt. When you enter the username/password you created in step 2 your script will have the appropriate rights to perform your WMI requests.

一生独一 2024-08-28 02:37:34

不是 DCOM 问题,更重要的是 WMI 安全和加密问题。尝试更改 GetObject 名字以包含模拟和 pktPrivacy,例如:

Set wmiProvider = GetObject("winmgmts:{impersonationLevel=impersonate;authenticationLevel=pktPrivacy}!\root\MicrosoftIISv2")

请参阅以下 MS 文章欲了解更多信息:
http://msdn.microsoft.com/en -us/library/aa393618(v=vs.85).aspx

Not a DCOM issue, more so a WMI security and encryption issue. Try changing the GetObject moniker to include impersonation and pktPrivacy, eg:

Set wmiProvider = GetObject("winmgmts:{impersonationLevel=impersonate;authenticationLevel=pktPrivacy}!\root\MicrosoftIISv2")

Refer to the follow MS article for more info:
http://msdn.microsoft.com/en-us/library/aa393618(v=vs.85).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文