流程启动和模拟

我在ASP.NET 2.0中的模拟上下文中启动进程时遇到问题。

我在我的Web服务代码中启动了新的Process。 IIS 5.1,.NET 2.0

[WebMethod] public string HelloWorld() { string path = @"C:\KB\GetWindowUser.exe"; ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = Path.GetDirectoryName(path); startInfo.FileName = path; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.ErrorDialog = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; Process docCreateProcess = Process.Start(startInfo); string errors = docCreateProcess.StandardError.ReadToEnd(); string output = docCreateProcess.StandardOutput.ReadToEnd(); } 

“C:\ KB \ GetWindowUser.exe”是包含以下代码的控制台应用程序:

 static void Main(string[] args) { Console.WriteLine("Windows: " + WindowsIdentity.GetCurrent().Name); } 

当我在没有模仿的情况下调用Web服务时,一切正常。

当我打开模拟时,跟随错误写入Web服务代码中的“errors”变量:

未处理的exception:System.Security.SecurityException:访问被拒绝。\ r \ n \ r \ n在System.Security.Principal.WindowsIdentity的System.Security.Principal.WindowsIdentity.GetCurrentInternal(TokenAccessLevels desiredAccess,Boolean threadOnly)\ r \ n中.GetCurrent()\ r \ n在ObfuscatedMdc.Program.Main(String [] args)\ r \ n失败的程序集区域是:\ r \ nMyComputer

模拟用户是本地管理员,可以访问C:\ KB \ GetWindowUser.exe可执行文件。

当我在ProcesStartInfo属性Domain,User和Password中明确指定窗口用户时,我收到以下消息: http : //img201.imageshack.us/img201/5870/pstartah8.jpg

是否有可能从asp.net(IIS 5.1)开始使用不同于ASPNET的凭据?

您必须将特权代码放入GAC(或以完全信任方式运行)。

GAC中的代码必须声明XXXPermission,其中XXX是您要求的权限,模仿,访问硬盘或您有什么。

您应该在词语后立即恢复断言。

您应该确保放在GAC中的DLL上的API没有滥用的机会。 例如,如果您正在编写一个允许用户通过命令行应用程序备份服务器的网站,那么您的API应该显示“BackUp()”之类的方法,而不是“LaunchAribitraryProcess(string path)”

web.config文件也必须设置模拟,否则您将遇到NTFS权限问题以及CAS。

这是完整的解释 。

您也可以尝试将代码包装在内部

 using (Impersonator person = new Impersonator("domainName", "userName", "password") { // do something requiring special permissions } 

如http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic62740.aspx中所述

你究竟想做什么? 我无法确定您的代码在创建不同的可执行文件时的意义。 看起来很奇怪。 也许说出你想要首先解决的业务问题会更有帮助。

看起来您正在尝试让IIS服务模拟具有比服务本身更高权限的用户(在本例中为管理员)。 Windows将此视为安全漏洞,因为此时您基本上是在乞求某人接管您的系统。 可能有办法解决这个限制,但不要这样做 – 这是为了你自己的利益。

相反,让IIS模拟具有有限权限的用户,该用户具有您需要的权限。 例如,创建一个用户帐户,该帐户只拥有您希望Web服务写入的文件夹,或者其他任何权限组合。 如果冒充有限的用户,您将看不到此错误代码,但仍应能够调用此处的良性可执行文件。