//////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public bool DuplicateToken(Winnt._SECURITY_IMPERSONATION_LEVEL impersonationLevel) { if (IntPtr.Zero == hExistingToken) { return(false); } Winbase._SECURITY_ATTRIBUTES securityAttributes = new Winbase._SECURITY_ATTRIBUTES(); if (!advapi32.DuplicateTokenEx( hWorkingToken, (uint)Winnt.ACCESS_MASK.MAXIMUM_ALLOWED, ref securityAttributes, impersonationLevel, Winnt._TOKEN_TYPE.TokenImpersonation, out phNewToken )) { Misc.GetWin32Error("DuplicateTokenEx: "); return(false); } Console.WriteLine(" [+] Duplicate Token Handle: 0x{0}", phNewToken.ToString("X4")); return(true); }
public static extern bool ImpersonateSelf(Winnt._SECURITY_IMPERSONATION_LEVEL ImpersonationLevel);
public static extern bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, ref Winbase._SECURITY_ATTRIBUTES lpTokenAttributes, Winnt._SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, Winnt._TOKEN_TYPE TokenType, out IntPtr phNewToken);
public static extern Boolean DuplicateTokenEx(IntPtr hExistingToken, UInt32 dwDesiredAccess, IntPtr lpTokenAttributes, Winnt._SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, Winnt._TOKEN_TYPE TokenType, out IntPtr phNewToken);