如何正确使用 LogonUser 从工作组客户端模拟域用户
这个问题是我要问的,但答案没有提供有关如何派生 _token 的详细信息。它似乎只使用 WindowsIdentity.GetCurrent().Token
因此不会发生假冒行为。
我可以在.NET 中的不同 Active Directory 域?
下一个问题的答案相互矛盾,已接受的答案带有评论“我开始怀疑我的问题出在其他地方”。没有帮助。
下一个问题似乎暗示这是不可能的,但它涉及 2 个域,所以我不确定它是否相关。
我真正的问题是:
- 可能吗?如果可能的话,
- 怎么做?或我哪里出错了?
到目前为止我尝试过的是,使用 http://msdn. microsoft.com/en-us/library/chf6fbt4%28v=VS.80%29.aspx
bool returnValue = LogonUser(user, domain, password,
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
// after this point, returnValue = false
Win32 错误是
登录失败:用户名未知或密码错误
ASP.NET: Impersonate against a domain on VMWare
This question is what I am asking, but the answer does not provide details on how the _token is derived. It seems to only use WindowsIdentity.GetCurrent().Token
so there's no impersonation happening.
Can I impersonate a user on a different Active Directory domain in .NET?
This next question has conflicting answers, with the accepted one bearing a comment "I'm beginning to suspect that my problem lies elsewhere." Not helpful.
LogonUser works only for my domain
This next question seems to imply it is not possible, but it deals with 2 domains so I am not sure if it is relevant.
My real question is:
- Is it possible? And if so,
- How? or Where did I go wrong?
What I have tried so far is, using the code from http://msdn.microsoft.com/en-us/library/chf6fbt4%28v=VS.80%29.aspx
bool returnValue = LogonUser(user, domain, password,
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
// after this point, returnValue = false
The Win32 error is
Logon failure: unknown user name or bad password
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
很少有帖子建议使用
LOGON_TYPE_NEW_CREDENTIALS
而不是LOGON_TYPE_NETWORK
或LOGON_TYPE_INTERACTIVE
。我遇到了模拟问题,一台机器连接到域,另一台机器没有连接,这解决了这个问题。这篇文章中的最后一个代码片段表明,冒充整个森林确实有效,但事实并非如此特别说明有关建立信任的任何内容。因此,这可能值得尝试:
MSDN 说 < code>LOGON_TYPE_NEW_CREDENTIALS 仅在使用
LOGON32_PROVIDER_WINNT50
时有效。Very few posts suggest using
LOGON_TYPE_NEW_CREDENTIALS
instead ofLOGON_TYPE_NETWORK
orLOGON_TYPE_INTERACTIVE
. I had an impersonation issue with one machine connected to a domain and one not, and this fixed it.The last code snippet in this post suggests that impersonating across a forest does work, but it doesn't specifically say anything about trust being set up. So this may be worth trying:
MSDN says that
LOGON_TYPE_NEW_CREDENTIALS
only works when usingLOGON32_PROVIDER_WINNT50
.这对我有用,完整的工作示例(我希望更多的人这样做):
this works for me, full working example (I wish more people would do this):
我也遇到了同样的问题。不知道你是否已经解决了这个问题,但我真正想做的是使用 AD 凭据访问网络共享。在这种情况下,您需要使用
WNetAddConnection2()
。I was having the same problem. Don't know if you've solved this or not, but what I was really trying to do was access a network share with AD credentials.
WNetAddConnection2()
is what you need to use in that case.我已经成功地模拟了另一个域中的用户,但仅在两个域之间建立了信任。
I have been successfull at impersonating users in another domain, but only with a trust set up between the 2 domains.
最好使用 SecureString:
And:
函数定义:
It's better to use a SecureString:
And:
Function definition:
我遇到的问题是,当我的工作站位于一个域上,但我需要向不同域上的服务器进行身份验证时:
“异常模拟用户,错误代码:1326”
LOGON32_LOGON_NEW_CREDENTIALS
作为 Impersonate/LogonUser() 的后备Impersonation.cs
ExampleClient.cs
The problem I encountered was when my workstation was on one domain, but I needed to authenticate to a server on a different domain:
"Exception impersonating user, error code: 1326"
LOGON32_LOGON_NEW_CREDENTIALS
as a fallback to Impersonate/LogonUser()Impersonation.cs
ExampleClient.cs
无效的登录/密码也可能与您的 DNS 服务器中的问题有关 - 这就是发生在我身上的事情,并让我损失了 5 个小时的生命。看看是否可以在域名上指定 IP 地址。
Invalid login/password could be also related to issues in your DNS server - that's what happened to me and cost me good 5 hours of my life. See if you can specify ip address instead on domain name.