我正在尝试使用 advapi32 模拟网络服务
LogonUser("NETWORK SERVICE", "NT AUTHORITY", null, LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, ref token)
但在 Windows 8 机器上不断出现 Access is denied 错误。有任何想法吗? (我用谷歌搜索了很多但找不到答案)。
<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)
不解。
请您参考如下方法:
终于!我找到了答案:
How do I 'run as' 'Network Service'?
和
http://geek.hubkey.com/2008/02/impersonating-built-in-service-account.html
在 Windows 8.. “Microsoft 已在 Windows 8/Windows Server 2012 中更改了此默认行为。要允许交互式服务,您需要找到注册表项 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows 并将 NoInteractiveServices 从 1 更改为 0。”
