Exemple #1
0
 private static NativeMethodProvider.GENERIC_MAPPING GenericMapping(string mapping)
 {
     NativeMethodProvider.GENERIC_MAPPING result = default(NativeMethodProvider.GENERIC_MAPPING);
     if (mapping.Length > 0)
     {
         string[] array = mapping.Split(new char[]
         {
             ','
         });
         if (array.Length != 4)
         {
             throw new ArgumentException();
         }
         result.GenericRead    = Convert.ToUInt32(array[0], 16);
         result.GenericWrite   = Convert.ToUInt32(array[1], 16);
         result.GenericExecute = Convert.ToUInt32(array[2], 16);
         result.GenericAll     = Convert.ToUInt32(array[3], 16);
     }
     else
     {
         result.GenericRead    = 2147483648U;
         result.GenericWrite   = 1073741824U;
         result.GenericExecute = 536870912U;
         result.GenericAll     = 268435456U;
     }
     return(result);
 }
Exemple #2
0
        public uint GetAccessCheck(byte[] ntsd, string listString)
        {
            uint desiredAccess = 33554432U;

            NativeMethodProvider.GENERIC_MAPPING    genericMapping = NativeMethodProvider.GenericMapping(string.Empty);
            NativeMethodProvider.OBJECT_TYPE_LIST[] list           = NativeMethodProvider.ObjectTypeList(string.Empty);
            return(this.AccessCheck(desiredAccess, ntsd, genericMapping, list));
        }
Exemple #3
0
        private uint AccessCheck(uint desiredAccess, byte[] ntsd, NativeMethodProvider.GENERIC_MAPPING genericMapping, NativeMethodProvider.OBJECT_TYPE_LIST[] list)
        {
            uint   result  = 0U;
            int    num     = 0;
            IntPtr intPtr  = IntPtr.Zero;
            IntPtr intPtr2 = IntPtr.Zero;
            IntPtr intPtr3 = IntPtr.Zero;
            bool   flag    = false;

            try
            {
                intPtr2 = Marshal.AllocHGlobal(1024);
                int num2 = 1024;
                NativeMethodProvider.MapGenericMask(ref desiredAccess, ref genericMapping);
                if (!NativeMethodProvider.ImpersonateSelf(2))
                {
                    int lastWin32Error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(lastWin32Error);
                }
                flag    = true;
                intPtr  = this.GetTokenHandle();
                intPtr3 = NativeMethodProvider.OBJECT_TYPE_LIST.NativeStruct(list);
                if (!NativeMethodProvider.AccessCheckByType(ntsd, IntPtr.Zero, intPtr, desiredAccess, intPtr3, list.Length, ref genericMapping, intPtr2, ref num2, ref result, ref num))
                {
                    int lastWin32Error = Marshal.GetLastWin32Error();
                    SetupLogger.LogError(new Win32Exception(lastWin32Error));
                }
            }
            finally
            {
                if (intPtr3 != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr3);
                }
                if (intPtr != IntPtr.Zero)
                {
                    NativeMethodProvider.CloseHandle(intPtr);
                }
                if (intPtr2 != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr2);
                }
                if (flag)
                {
                    NativeMethodProvider.RevertToSelf();
                }
            }
            return(result);
        }
Exemple #4
0
 private static extern bool AccessCheckByType([MarshalAs(UnmanagedType.LPArray)] byte[] pSecurityDescriptor, IntPtr principalSelfSid, IntPtr clientToken, uint DesiredAccess, IntPtr objectTypeList, int ObjectTypeListLength, ref NativeMethodProvider.GENERIC_MAPPING GenericMapping, IntPtr PrivilegeSet, ref int PrivilegeSetLength, ref uint GrantedAccess, ref int AccessStatus);
Exemple #5
0
 private static extern void MapGenericMask(ref uint accessMask, ref NativeMethodProvider.GENERIC_MAPPING genericMapping);