Exemplo n.º 1
0
        private TOKEN_GROUPS_AND_PRIILEGES GetTokenGroupsAndPrivileges(WindowsIdentity secp)
        {
            TOKEN_GROUPS_AND_PRIILEGES ret = default(TOKEN_GROUPS_AND_PRIILEGES);

            int tlength = 0;

            this.TokenHandle = IntPtr.Zero;

            this.Success = Advapi32.GetTokenInformation(secp.Token, TOKEN_INFORMATION_CLASS.TokenGroupsAndPrivileges, this.TokenHandle, tlength, out tlength);

            this.TokenHandle = Marshal.AllocHGlobal(tlength);

            this.Success = Advapi32.GetTokenInformation(secp.Token, TOKEN_INFORMATION_CLASS.TokenGroupsAndPrivileges, this.TokenHandle, tlength, out tlength);

            if (this.Success)
            {
                ret = (TOKEN_GROUPS_AND_PRIILEGES)Marshal.PtrToStructure(TokenHandle, typeof(TOKEN_GROUPS_AND_PRIILEGES));
            }

            else
            {
                GlobalEventHandler.RaiseDebugInfoOccured("Failed on GetTokenInformation");
            }

            return(ret);
        }
Exemplo n.º 2
0
        private void LoadInternal(string userName)
        {
            this.SidList = new List <string> {
            };

            this.Groups = new List <SidInfo> {
            };

            this.PrivilegesStringList = new List <string> {
            };

            this.Privileges = new List <PrivilegeInfo> {
            };

            this.CallingIdentity = GlobalUserStore.Name;

            this.CurrentIdentity = GlobalUserStore.Name;

            this.Sid = GlobalUserStore.SDDLSid;

            this.IsElevated = GlobalUserStore.IsElevated;

            if (!String.IsNullOrEmpty(userName))
            {
                this.Success = false;

                try
                {
                    using (WindowsIdentity secp = new WindowsIdentity(userName))
                    {
                        if (GlobalUserStore.UPN.ToLowerInvariant() != userName)
                        {
                            this.CurrentIdentity = secp.Name;

                            this.Sid = secp.User.Value;
                        }

                        this.TGP = GetTokenGroupsAndPrivileges(secp);
                    }

                    this.Success = true;
                }

                catch (Exception ex)
                { GlobalEventHandler.RaiseDebugInfoOccured("Failed to get target identity {0} {1} ({2})", userName, ex.Message, ex.GetType()); }
            }

            if (this.Success)
            {
                DecodeGroups();

                DecodePrivileges();
            }
        }