Tag: 模仿

动态模拟远程用户 – c#和asp.net

我想动态模拟远程用户执行某些代码。 我在网上搜索了很多,并得到了一些代码来冒充。 模仿的代码如下所示 namespace Tools { #region Using directives. // ———————————————————————- using System; using System.Security.Principal; using System.Runtime.InteropServices; using System.ComponentModel; // ———————————————————————- #endregion ///////////////////////////////////////////////////////////////////////// /// /// Impersonation of a user. Allows to execute code under another /// user context. /// Please note that the account that instantiates the Impersonator class /// needs to have the ‘Act […]

Windows模拟和复制令牌

我有一个asp.net项目,请求将工作委托给后台(通过quartz.net)。 Web应用程序正在使用Windows身份validation和模拟。 我还想在后台线程上模拟当前用户。 我已经阅读了如何使用提供的域名,用户名和密码模拟用户并调用内核。 那种方法有效。 IntPtr token; var successfullLogon = LogonUser(userName, password, domain, logonType, logonProvider, out token); if(successfullLogon == false) { var errorCode = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(errorCode); } 这是有效的,但它要求我提供特定的用户名/密码,或让用户输入他们的密码。 两种情况都不理想。 我想要的是将令牌从用户的身份从请求传递到后台,然后从这个现有令牌模拟用户。 我读到我应该可以调用DuplicateHandle, var token = ((WindowsIdentity)Request.User.Identity).GetToken().ToInt64(); var token = new IntPrt(token from request); IntPtr duplicate; try { if(NaviteMethod.DuplicateToken(token, SecurityImpersonationLevel.Impersonate, out duplicate) == false) { var errorCode […]

未提供所需的模拟级别,或者提供的模拟级别无效

我在使用WCF服务和模拟时遇到了一些问题,我已将其提炼为下面的简单方法。 WCF服务目前在exe中自托管。 exception消息是“未提供所需的模拟级别,或者提供的模拟级别无效”。 检查错误何时抛出,Identity ImpersonationLevel设置为委托,如我的客户端上指定的,并通过Kerberos进行身份validation。 我有点困惑,因为在我看来ImpersonationLevel和Authenticaiton的要求已经得到满足。 我的想法是问题可能与域设置有关,我已经设置并认为设置正确。 所以我有两个问题: 下面的操作应该成功吗? (或者它有缺陷吗?) 需要在Win2k8域上配置哪些设置才能使其正常工作? 我正在使用两个属于同一个Win2k8域的成员(它是一个新域和非常香草,旨在测试模拟)。 代码如下: [OperationBehavior(Impersonation = ImpersonationOption.Required)] public string Test() { WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity; using (identity.Impersonate()) { ProcessStartInfo pi = new ProcessStartInfo(@”c:\temp\test.bat”); pi.UseShellExecute = false; pi.RedirectStandardOutput = true; Process p = Process.Start(pi); // exception thrown here! p.WaitForExit(); string o = p.StandardOutput.ReadToEnd(); return o; } } […]

Process.Start()在模拟后抛出“拒绝访问”

我在使用Process.Start()+ Impersonation从文件服务器执行文件时遇到问题。 请帮我解决我的问题。 还有另一种方法吗? 这是按钮点击事件。 private void btnOpen_Click(object sender, EventArgs e) { try { newUser = cls.ImpersonateUser(“username”, “domain”, “password”); string fileName = @”\\network_computer\Test\Test.doc”; System.Diagnostics.Process.Start(fileName); } catch (Exception ex) { throw ex; } finally { if (newUser != null) newUser.Undo(); } } 这是假冒课程。 public class clsImpersonate { #region ‘Impersonation’ // group type enum public enum SECURITY_IMPERSONATION_LEVEL […]

如何模拟WellKnownSidType?

我知道我可以使用以下方式冒充Windows帐户: http : //msdn.microsoft.com/en-us/library/chf6fbt4.aspx 但是,如何模拟WellKnownSidType帐户呢? SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null); NTAccount account = sid.Translate(typeof(NTAccount)) as NTAccount; if (account != null) { //Impersonate here??? }

通过网络模拟文件副本

我想从同一域中的远程计算机复制文件。 所以我正在冒充这样做。 我正在使用advapi32.dll的DLLImport,它正确模仿用户。 现在当执行下面的代码行时,我得到以下错误。 \\line File.Copy(@”\\sins00048178\D$\BNCustody\Swift\Received_from_SWIFT\Error_files\E03248681_error.out”, @”C:\E03248681_error.out”, true); \\Error “Logon failure: user not allowed to log on to this computer.” 完整的代码要求 [DllImport(“advapi32.dll”, SetLastError = true)] public static extern bool LogonUser( string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken ); IntPtr userHandle = IntPtr.Zero; bool loggedOn = LogonUser(userid, domain, pass, 9, […]

模拟和DirectoryEntry

我正在成功模拟用户帐户,但我无法使用模拟帐户绑定到AD并下拉DirectoryEntry 。 以下代码输出: 在模仿之前我是:DOMAIN \ user 冒充我之后:DOMAIN \ admin 错误:C:\ Users \ user \ ADSI_Impersonation \ bin \ Debug \ ADSI_Impersonation.exe samaccountname: 我的问题似乎与: 如何在ASP.NET中使用System.DirectoryServices命名空间 我正在获得一个主令牌。 我知道我需要使用委托在远程计算机上使用模拟令牌。 我确认该帐户没有选中“帐户敏感且无法委派”的标志。 我还确认本地组策略和域组策略不会阻止委派: 计算机配置\ Windows设置\安全设置\本地策略\用户权限分配\ 我错过了什么? 谢谢! using System; using System.DirectoryServices; using System.Security; using System.Security.Principal; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; using System.Runtime.ConstrainedExecution; namespace ADSI_Impersonation { class Program { [DllImport(“advapi32.dll”, SetLastError = […]

假冒和授权

我正在使用模拟用于访问UNC共享上的文件,如下所示。 var ctx = ((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate(); string level = WindowsIdentity.GetCurrent().ImpersonationLevel); 在使用IIS6的两台Windows 2003服务器上,我获得了不同的模拟级别:一台服务器上的委派和另一台服务器上的模拟 。 这会导致我无法以“模拟”级别访问服务器上的UNC共享的问题。 什么可能导致这种差异? 我搜索了应用程序池,站点和虚拟目录的machine.config和IIS设置 – 但无法找到此问题的原因。

访问共享网络驱动器时需要模拟

当我尝试从本地访问网络驱动器文件时工作正常,但是当我部署代码时,我得到了以下错误 在System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath) at System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions options,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy) 在System.IO.FileStream..ctor(字符串路径,FileMode模式,FileAccess访问,FileShare共享) 在System.Web.HttpResponse.WriteFile(String filename,Boolean readIntoMemory) 在System.Web.HttpResponse.WriteFile(String filename) at Configs.gvConfigs_RowCommand(Object sender,GridViewCommandEventArgs e)在C:\ Users \ bpucha1103c \ Desktop \ CellBackHaul_Publish \ Configs.aspx.cs:line 59 2013-02-05 13:31:21,412 [19] WARN System.Web.UI .Page [(null)] – 日志记录:System.IO.IOException:使用的帐户是计算机帐户。 使用您的全局用户帐户或本地用户帐户访问此服务器。 访问网络共享文件夹中的文件时如何进行模拟? 以下是我的代码 GridViewRow rw = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); […]

通过NTLM模拟用户

我有一个内部应用程序,它有两个安全级别。 FormsAuthentication用于面向客户端的应用程序和NTLM集成身份validation用于管理界面。 我可以通过使用FormsAuthentication类的方法创建正确的.ASPXAUTH cookie来轻松模拟客户端。 但是,到目前为止,为NTLM生成HTTP身份validation标头已超出我的范围。 当我发现这篇文章( http://msdn.microsoft.com/en-us/library/ms998358.aspx#paght000025_usingimpersonation )时,我有了希望,但后来我意识到它只创建一个上下文来运行代码一段时间请求。 我想切换整个会话,使服务器认为我正在使用另一个域登录。 我对我的帐户拥有管理权限,因此不是为了搞砸或窃取域密码。 它甚至可能吗? 谢谢。