Beispiel #1
0
        public void Impersonate(string domain, string userName, string password)
        {
            const int logon32ProviderDefault = 0;
            //This parameter causes LogonUser to create a primary token.
            const int logon32LogonInteractive = 2;

            // Call LogonUser to obtain a handle to an access token.
            SafeTokenHandle safeTokenHandle;
            bool            returnValue = LogonUser(userName, domain, password,
                                                    logon32LogonInteractive, logon32ProviderDefault,
                                                    out safeTokenHandle);

            if (!returnValue)
            {
                int ret = Marshal.GetLastWin32Error();

                throw new System.ComponentModel.Win32Exception(ret);
            }
            using (safeTokenHandle)
            {
                // Use the token handle returned by LogonUser.
                using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle()))
                {
                    using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
                    {
                        _leanPlatform.SetWindowsAuthentication();
                    }
                }
            }
        }
Beispiel #2
0
        public UAFConnector()
        {
            LeanFactory.Initialize("USER_APPLICATION");
            //_serviceEvent = new ServiceEventGateway();
            _leanPlatform = LeanFactory.Create();
            var principal = ClaimsPrincipal.Current;

            _leanPlatform.SetWindowsAuthentication();
            //Impersonate("Administrator", "SwqaMe$1");
        }