예제 #1
0
 public uint EditAce(object editAceslist,
                     object addedAceslist,
                     object deletedAceslist,
                     ref IntPtr pSecurityDescriptorOut)
 {
     return(SecurityDescriptorWrapper.ApiSetSecurityDescriptorDacl(
                editAceslist, addedAceslist, deletedAceslist, pSecurityDescriptor, out pSecurityDescriptorOut));
 }
예제 #2
0
        public string CovertStringSidToLookupName(string sSID)
        {
            string sUsername = string.Empty;
            string sDomain   = string.Empty;
            IntPtr pSid      = IntPtr.Zero;

            SecurityDescriptorApi.ConvertStringSidToSid(sSID, out pSid);
            if (pSid != IntPtr.Zero)
            {
                SecurityDescriptorWrapper.GetObjectLookUpName(pSid, out sUsername, out sDomain);
                sUsername = string.Concat(sUsername, "(", sUsername, "@", sDomain, ")");
            }

            return(sUsername);
        }
        public static uint ApiGetCurrentProcessHandle(uint DesiredAccess, out IntPtr pTokenHandle)
        {
            bool   bSuccess       = false;
            uint   errorReturn    = 0;
            IntPtr pProcessHandle = IntPtr.Zero;

            pTokenHandle = IntPtr.Zero;

            Logger.Log("SecurityDescriptorWrapper.ApiGetCurrentProcessHandle()", Logger.SecurityDescriptorLogLevel);

            try
            {
                uint iThreadId = SecurityDescriptorApi.GetCurrentThreadId();
                pProcessHandle = SecurityDescriptorApi.OpenThread(SecurityDescriptorApi.ThreadAccess.ALL_ACCESS, true, iThreadId);

                bSuccess    = SecurityDescriptorApi.OpenThreadToken(pProcessHandle, DesiredAccess, false, out pTokenHandle);
                errorReturn = (uint)Marshal.GetLastWin32Error();
                if (errorReturn == (uint)ErrorCodes.WIN32Enum.ERROR_NO_TOKEN ||
                    errorReturn != 0)
                {
                    pProcessHandle = Process.GetCurrentProcess().Handle;
                    bSuccess       = SecurityDescriptorApi.OpenProcessToken(pProcessHandle, DesiredAccess, out pTokenHandle);
                }
                if (pTokenHandle != null)
                {
                    SecurityDescriptorWrapper.ApiAdjustTokenPrivileges(ref pTokenHandle, "SeTakeOwnershipPrivilege");
                    SecurityDescriptorWrapper.ApiAdjustTokenPrivileges(ref pTokenHandle, "SeSecurityPrivilege");
                    SecurityDescriptorWrapper.ApiAdjustTokenPrivileges(ref pTokenHandle, "SeBackupPrivilege");
                    SecurityDescriptorWrapper.ApiAdjustTokenPrivileges(ref pTokenHandle, "SeRestorePrivilege");
                    //bSuccess = SecurityDescriptorApi.SetThreadToken(pProcessHandle, pTokenHandle);
                    //errorReturn = (uint)Marshal.GetLastWin32Error();
                    //Logger.Log("SecurityDescriptorApi.SetThreadToken()");
                }

                if (!bSuccess)
                {
                    errorReturn = (uint)Marshal.GetLastWin32Error();
                    Logger.Log("SecurityDescriptorWrapper.ApiGetCurrentProcessHandle() unsuccess with ReturnCode = " + errorReturn, Logger.SecurityDescriptorLogLevel);
                }
            }
            catch (Exception ex)
            {
                errorReturn = (uint)Marshal.GetLastWin32Error();
                Logger.LogException("SecurityDescriptorWrapper.ApiGetCurrentProcessHandle()", ex);
            }

            return(errorReturn);
        }
예제 #4
0
 public string ConvetByteSidToStringSid(byte[] bSid)
 {
     return(SecurityDescriptorWrapper.ConvetByteSidToStringSid(bSid));
 }