3
リモートマシンでRegLoadKey()を実行できる必要があります。私のマシンとリモートマシンが同じドメインにない可能性があります。もしそうであれば、以下のコードは正常に動作し、マシンの管理者権限を持つユーザーになりすますことができます。そうでなければ、私たちは...私が見つけたこの議論によると、ローカルユーザーに関するhttp://www.eggheadcafe.com/conversation.aspx?messageid=34224301&threadid=34224226advapi32.dllの使用:リモートマシンのローカルユーザーを偽装するLogonUserA()
を話している場合は...同じユーザ名とパスワードを使用して、私のマシン上のローカルユーザーが存在しなければなりません。ああ。その周りに道がありますか?
using System.Runtime.InteropServices;
using System.Security.Principal;
[DllImport("advapi32.dll")]
public static extern int LogonUserA(String lpszUserName, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken, int impersonationLevel, ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
public WindowsImpersonationContext WearDrag(string Username, string Password, string DomainOrMachine)
{
WindowsImpersonationContext impersonationContext;
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf())
{
if (LogonUserA(Username, DomainOrMachine, Password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return impersonationContext;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return null;
}
OK、これで奇妙なことが起こりました:それはどんなユーザー名ともパスワードを受け入れ、成功を返します! – JCCyC
あなたのアバターでレースをする - それはモナコで、ドライバーはEmerson Fittipaldiのように見えます。 –
私のファイアウォールはブラウニーをブロックしているので、あなたはupvotesを取得します。 ;) – JCCyC