コード例 #1
0
        internal TokenPrivilege(MemoryMarshaler m)
        {
            LUID_AND_ATTRIBUTES la = (LUID_AND_ATTRIBUTES)m.ParseStruct(typeof(LUID_AND_ATTRIBUTES));

            _luid       = new Luid(la.Luid);
            _attributes = (PrivilegeAttributes)la.Attributes;
        }
コード例 #2
0
ファイル: Privileges.cs プロジェクト: FFFF0h/RunPSScript
 private static AdjustPrivilegeResult AdjustPrivilege(
     AccessTokenHandle accessTokenHandle,
     Privilege privilege,
     PrivilegeAttributes privilegeAttributes)
 {
     return(AdjustPrivilege(accessTokenHandle, GetLuid(privilege), privilegeAttributes));
 }
コード例 #3
0
        private static AdjustPrivilegeResult AdjustPrivilege(
            AccessTokenHandle accessTokenHandle,
            Luid luid,
            PrivilegeAttributes privilegeAttributes)
        {
            TokenPrivilege newState = new TokenPrivilege
            {
                PrivilegeCount = 1,
                Privilege = new LuidAndAttributes
                {
                    Attributes = privilegeAttributes,
                    Luid = luid
                }
            };
            TokenPrivilege previousState = new TokenPrivilege();
            int returnLength = 0;

            if (!NativeMethods.AdjustTokenPrivileges(
                accessTokenHandle,
                false,
                ref newState,
                Marshal.SizeOf(previousState),
                ref previousState,
                ref returnLength))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return (AdjustPrivilegeResult)previousState.PrivilegeCount;
        }
コード例 #4
0
ファイル: Privileges.cs プロジェクト: FFFF0h/RunPSScript
        private static AdjustPrivilegeResult AdjustPrivilege(
            AccessTokenHandle accessTokenHandle,
            Luid luid,
            PrivilegeAttributes privilegeAttributes)
        {
            TokenPrivilege newState = new TokenPrivilege
            {
                PrivilegeCount = 1,
                Privilege      = new LuidAndAttributes
                {
                    Attributes = privilegeAttributes,
                    Luid       = luid
                }
            };
            TokenPrivilege previousState = new TokenPrivilege();
            int            returnLength  = 0;

            if (!NativeMethods.AdjustTokenPrivileges(
                    accessTokenHandle,
                    false,
                    ref newState,
                    Marshal.SizeOf(previousState),
                    ref previousState,
                    ref returnLength))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return((AdjustPrivilegeResult)previousState.PrivilegeCount);
        }
コード例 #5
0
        public void AddPrivilege(Luid luid, PrivilegeAttributes attributes)
        {
            LuidAndAttributes priv = new LuidAndAttributes {
                Luid       = luid,
                Attributes = attributes
            };

            _privs.Add(priv);
        }
コード例 #6
0
        public TokenPrivilege(string systemName, string privilege, bool enabled)
        {
            BOOL rc = Win32.LookupPrivilegeValue(systemName, privilege, out LUID luid);

            Win32.CheckCall(rc);

            _luid       = new Luid(luid);
            _attributes = (enabled ? PrivilegeAttributes.Enabled : 0);
        }
コード例 #7
0
        public TokenPrivilege(string systemName, string privilege, bool enabled)
        {
            LUID luid;
            BOOL rc = Win32.LookupPrivilegeValue(systemName, privilege, out luid);
            Win32.CheckCall(rc);

            _luid = new Luid(luid);
            _attributes = (enabled ? PrivilegeAttributes.Enabled : 0);
        }
コード例 #8
0
 private void enablePrivilegeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listViewPrivs.SelectedItems.Count > 0)
     {
         IEnumerable <TokenPrivilege> privs = GetSelectedItemTags(listViewPrivs).OfType <TokenPrivilege>();
         bool all_enabled = AllPrivsEnabled(privs);
         PrivilegeAttributes attributes = all_enabled ? PrivilegeAttributes.Disabled : PrivilegeAttributes.Enabled;
         ModifyPrivileges(privs, attributes);
     }
 }
コード例 #9
0
        public PrivilegeSetting(string privilege, PrivilegeAttributes attributes)
        {
            Privileges p;

            if (!Enum.TryParse(privilege, out p))
            {
                p = Privileges.UnknownPrivilege;
            }
            Privilege  = p;
            Attributes = attributes;
        }
コード例 #10
0
        public static PrivilegeState GetPrivilegeState(PrivilegeAttributes privilegeAttributes)
        {
            if ((privilegeAttributes & PrivilegeAttributes.Enabled) == PrivilegeAttributes.Enabled)
            {
                return(PrivilegeState.Enabled);
            }

            if ((privilegeAttributes & PrivilegeAttributes.Removed) == PrivilegeAttributes.Removed)
            {
                return(PrivilegeState.Removed);
            }

            return(PrivilegeState.Disabled);
        }
コード例 #11
0
        public static PrivilegeState GetPrivilegeState(PrivilegeAttributes privilegeAttributes)
        {
            if ((privilegeAttributes & PrivilegeAttributes.Enabled) == PrivilegeAttributes.Enabled)
            {
                return PrivilegeState.Enabled;
            }

            if ((privilegeAttributes & PrivilegeAttributes.Removed) == PrivilegeAttributes.Removed)
            {
                return PrivilegeState.Removed;
            }

            return PrivilegeState.Disabled;
        }
コード例 #12
0
        protected override void ProcessRecord()
        {
            WriteVerbose("Getting current process handle");
            using SafeHandle processToken = PrivilegeHelper.GetCurrentProcess();

            WriteVerbose("Getting privilege info for all privileges on the current process");
            Dictionary <string, PrivilegeAttributes> privilegeInfo = PrivilegeHelper.GetAllPrivilegeInfo(processToken);

            if (Name.Length == 0)
            {
                Name = privilegeInfo.Keys.ToArray();
            }

            foreach (string privName in Name)
            {
                if (!PrivilegeHelper.CheckPrivilegeName(privName))
                {
                    ItemNotFoundException exp = new ItemNotFoundException($"Invalid privilege name '{privName}'");
                    WriteError(new ErrorRecord(exp, "PrivilegeNotFound", ErrorCategory.ObjectNotFound, privName));
                    continue;
                }

                string description       = PrivilegeHelper.GetPrivilegeDisplayName(privName);
                bool   enabled           = false;
                bool   enableByDefault   = false;
                PrivilegeAttributes attr = PrivilegeAttributes.Removed;
                bool isRemoved           = true;

                if (privilegeInfo.ContainsKey(privName))
                {
                    attr            = privilegeInfo[privName];
                    enabled         = (attr & PrivilegeAttributes.Enabled) != 0;
                    enableByDefault = (attr & PrivilegeAttributes.EnabledByDefault) != 0;
                    isRemoved       = false;
                }

                WriteObject(new Privilege()
                {
                    Name             = privName,
                    Description      = description,
                    Enabled          = enabled,
                    EnabledByDefault = enableByDefault,
                    Attributes       = attr,
                    IsRemoved        = isRemoved,
                });
            }
        }
コード例 #13
0
ファイル: NativeToken.cs プロジェクト: henke37/debugHelp
        public unsafe void AdjustPrivilege(UInt64 priv, PrivilegeAttributes newState, out PrivilegeAttributes oldState)
        {
            TokenPrivilege inBuff   = new TokenPrivilege(priv, newState);
            void *         inBuffP  = (void *)&inBuff;
            TokenPrivilege outBuff  = new TokenPrivilege();
            void *         outBuffP = (void *)&outBuff;

            uint size = (uint)sizeof(TokenPrivilege);

            bool success = AdjustTokenPrivileges(tokenHandle, false, inBuffP, size, outBuffP, out _);

            if (!success)
            {
                throw new Win32Exception();
            }

            oldState = outBuff.Privilege.Attributes;
        }
コード例 #14
0
        private void ModifyPrivileges(IEnumerable <TokenPrivilege> privs, PrivilegeAttributes attributes)
        {
            bool multi = privs.Count() > 1;

            foreach (TokenPrivilege priv in privs)
            {
                try
                {
                    _token.SetPrivilege(priv.Luid, attributes);
                }
                catch (Exception ex)
                {
                    if (!multi)
                    {
                        MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            UpdatePrivileges();
        }
コード例 #15
0
        public static ATPrivilege FromValues(string name, PrivilegeAttributes attributes)
        {
            uint attrib = 0;

            switch (attributes)
            {
            case PrivilegeAttributes.REMOVED:
                attrib = Constants.SE_PRIVILEGE_REMOVED;
                break;

            case PrivilegeAttributes.ENABLED:
                attrib = Constants.SE_PRIVILEGE_ENABLED;
                break;

            case PrivilegeAttributes.DISABLED:
                attrib = Constants.SE_PRIVILEGE_DISABLED;
                break;

            default:
                throw new Exception("Unkwnon privilege attribute");
            }
            return(ATPrivilege.FromValues(name, attrib));
        }
コード例 #16
0
 /// <summary>Initializes a new instance of the <see cref="PrivilegeAndAttributes"/> class.</summary>
 /// <param name="p">The privilege.</param>
 /// <param name="a">The attribute.</param>
 public PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a)
 {
     Privilege  = p;
     Attributes = a;
 }
コード例 #17
0
 public TOKEN_PRIVILEGES(LUID luid, PrivilegeAttributes attribute)
 {
     PrivilegeCount        = 1;
     Privileges.Luid       = luid;
     Privileges.Attributes = attribute;
 }
コード例 #18
0
 public LUID_AND_ATTRIBUTES(LUID luid, PrivilegeAttributes attr)
 {
     Luid       = luid;
     Attributes = attr;
 }
コード例 #19
0
 public LuidAndAttributes(LUID luid, PrivilegeAttributes attributes = default)
 {
     Luid       = luid;
     Attributes = attributes;
 }
コード例 #20
0
 internal TokenPrivilege(string system_name, Luid luid, PrivilegeAttributes attribute)
 {
     _system_name = system_name;
     Luid         = luid;
     Attributes   = attribute;
 }
コード例 #21
0
 internal TokenPrivilege(MemoryMarshaler m)
 {
     LUID_AND_ATTRIBUTES la = (LUID_AND_ATTRIBUTES)m.ParseStruct(typeof(LUID_AND_ATTRIBUTES));
     _luid = new Luid(la.Luid);
     _attributes = (PrivilegeAttributes)la.Attributes;
 }
コード例 #22
0
        public static SafeCoTaskMemHandle AdjustPrivilege(this SafeHTOKEN hObj, SystemPrivilege priv, PrivilegeAttributes attr)
        {
            var newState  = new PTOKEN_PRIVILEGES(priv.GetLUID(), attr);
            var prevState = PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance();

            if (!AdjustTokenPrivileges(hObj, false, newState, (uint)prevState.Size, prevState, out var retLen))
            {
                throw new Win32Exception();
            }
            prevState.Size = (int)retLen;
            return(prevState);
        }
コード例 #23
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="luid">The privilege LUID</param>
 /// <param name="attribute">The privilege attributes</param>
 public TokenPrivilege(Luid luid, PrivilegeAttributes attribute)
 {
     Luid       = luid;
     Attributes = attribute;
 }
コード例 #24
0
 internal PrivilegeInfo(NativeHelpers.LUID_AND_ATTRIBUTES la)
 {
     Name       = TokenUtil.GetPrivilegeName(la.Luid);
     Attributes = (PrivilegeAttributes)la.Attributes;
 }
コード例 #25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="luid">The privilege LUID</param>
 /// <param name="attribute">The privilege attributes</param>
 public TokenPrivilege(Luid luid, PrivilegeAttributes attribute)
     : this(null, luid, attribute)
 {
 }
コード例 #26
0
 public void Deconstruct(out UInt64 LUID, out PrivilegeAttributes Attributes)
 {
     LUID       = this.LUID;
     Attributes = this.Attributes;
 }
コード例 #27
0
 internal PrivilegeAndAttributes(Privilege privilege, PrivilegeAttributes privilegeAttributes)
 {
     this.privilege           = privilege;
     this.privilegeAttributes = privilegeAttributes;
 }
コード例 #28
0
 private static AdjustPrivilegeResult AdjustPrivilege(
     AccessTokenHandle accessTokenHandle,
     Privilege privilege,
     PrivilegeAttributes privilegeAttributes)
 {
     return AdjustPrivilege(accessTokenHandle, GetLuid(privilege), privilegeAttributes);
 }
コード例 #29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="value">The privilege value</param>
 /// <param name="attribute">The privilege attributes</param>
 public TokenPrivilege(TokenPrivilegeValue value, PrivilegeAttributes attribute)
     : this(new Luid((uint)value, 0), attribute)
 {
 }
コード例 #30
0
 public TokenPrivileges(PrivilegeAttributes attributes, LUID luid)
 {
     PrivilegeCount = 1;
     Attributes     = attributes;
     Luid           = luid;
 }
コード例 #31
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">The privilege name.</param>
 /// <param name="attribute">The privilege attributes</param>
 public TokenPrivilege(string name, PrivilegeAttributes attribute)
     : this(LookupPrivilegeLuid(name), attribute)
 {
 }
コード例 #32
0
 public PrivilegeSetting(Privilege privilege, PrivilegeAttributes attributes)
 {
     Privilege  = privilege;
     Attributes = attributes;
 }
コード例 #33
0
 internal PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a)
 {
     Privilege = p; Attributes = a;
 }
コード例 #34
0
        public void AddPrivilege(TokenPrivilegeValue name, PrivilegeAttributes attributes)
        {
            Luid luid = new Luid((uint)name, 0);

            AddPrivilege(luid, attributes);
        }
コード例 #35
0
 public TokenPrivilege(UInt64 LUID, PrivilegeAttributes attributes) : this()
 {
     Count     = 1;
     Privilege = new LuidAndAttributes(LUID, attributes);
 }