“访问被拒绝”;LOGON32_LOGON_SERVICE

本文关键字:LOGON32 LOGON SERVICE 访问 拒绝 访问被拒绝 | 更新日期: 2023-09-27 17:50:39

我正在尝试使用advapi32模拟网络服务

LogonUser("NETWORK SERVICE", "NT AUTHORITY", null, LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, ref token)

但是一直得到Access is denied错误,在Windows 8机器上。什么好主意吗?(我谷歌了很多,但找不到答案)。

<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">        
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
      </applicationRequestMinimum>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application />      
  </compatibility>  
</asmv1:assembly>
编辑:

因此,经过几次尝试后,模拟似乎有效,但我无法以主机的网络服务身份验证。应用程序池如何在网络服务下运行?

使用

LOGON32_LOGON_SERVICE

结果:

Unhandled Exception: System.ComponentModel.Win32Exception: Access is denied
   at Tools.Network.Impersonator.Impersonate(String userName, String domainName,
 String password, LogonType logonType, LogonProvider logonProvider)
   at Tools.Network.Impersonator..ctor(String userName, String domainName, Strin
g password, LogonType logonType, LogonProvider logonProvider)
   at Impersonation.Program.Main(String[] args)
使用

LOGON32_LOGON_NEW_CREDENTIALS

结果:

System.IO.IOException: Logon failure: unknown user name or bad password.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Bo
olean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean ov
erwrite)
   at Impersonation.Program.Main(String[] args)

困惑。

“访问被拒绝”;LOGON32_LOGON_SERVICE

终于!我已经找到了答案:

I 'run as'& # 39;网络服务# 39;?

http://geek.hubkey.com/2008/02/impersonating-built-in-service-account.html

在Windows 8…微软已经改变了Windows 8/Windows Server 2012的默认行为。要允许交互服务,您需要找到注册表项HKEY_LOCAL_MACHINE'SYSTEM'CurrentControlSet'Control'Windows,并将NoInteractiveServices从1更改为0。"

这是一个非常好的链接,有代码和我认为这是你可能正在寻找的一切。让我知道这个链接是否有效

。NET (c#)具有网络凭据的模拟适用于LOGON32_LOGON_NEW_CREDENTIALS作为登录类型,这要求您选择LOGON32_PROVIDER_WINNT50作为登录提供程序类型。