Exemple #1
0
        public void GetTokenUserSid_ForCurrentProcess()
        {
            SID sid;

            using (var token = Security.OpenProcessToken(AccessTokenRights.Read))
            {
                token.IsInvalid.Should().BeFalse();
                sid = token.GetTokenUserSid().Sid;
            }
            sid.IsValidSid().Should().BeTrue();

            AccountSidInformation info = sid.LookupAccountSid();

            info.Name.Should().Be(SystemInformation.GetUserName());
        }
        public void GetTokenPrimaryGroupSid_ForCurrentProcess()
        {
            SID sid;

            using (var token = AuthorizationMethods.OpenProcessToken(AccessTokenRights.Read))
            {
                token.IsInvalid.Should().BeFalse();
                sid = AuthorizationMethods.GetTokenPrimaryGroupSid(token);
            }
            AuthorizationMethods.IsValidSid(ref sid).Should().BeTrue();

            AccountSidInformation info = AuthorizationMethods.LookupAccountSidLocal(sid);

            info.Name.Should().Be(SystemInformationMethods.GetUserName());
        }
 public void GetSidForCreatedFile()
 {
     using (var cleaner = new TestFileCleaner())
     {
         using (var handle = FileMethods.CreateFile(cleaner.GetTestPath(), CreationDisposition.CreateNew))
         {
             handle.IsInvalid.Should().BeFalse();
             FileMethods.QueryOwner(handle, out SID sid);
             sid.IdentifierAuthority.Should().Be(SID_IDENTIFIER_AUTHORITY.NT);
             AccountSidInformation info = AuthorizationMethods.LookupAccountSidLocal(sid);
             info.Usage.Should().Be(SidNameUse.User);
             info.Name.Should().Be(SystemInformationMethods.GetUserName());
         }
     }
 }
 public void GetGroupSidForCreatedFile()
 {
     using (var cleaner = new TestFileCleaner())
     {
         using (var handle = Storage.CreateFile(cleaner.GetTestPath(), CreationDisposition.CreateNew))
         {
             handle.IsInvalid.Should().BeFalse();
             SID sid = Storage.GetPrimaryGroup(handle);
             sid.IdentifierAuthority.Should().Be(IdentifierAuthority.NT);
             string sidString           = sid.ConvertSidToString();
             AccountSidInformation info = sid.LookupAccountSid();
             info.Usage.Should().Be(SidNameUse.User);
             info.Name.Should().Be(WInterop.SystemInformation.SystemInformation.GetUserName());
         }
     }
 }
 // [Fact]
 private void DumpAllWellKnownSids()
 {
     foreach (WELL_KNOWN_SID_TYPE type in Enum.GetValues(typeof(WELL_KNOWN_SID_TYPE)))
     {
         Debug.WriteLine(@"/// <summary>");
         try
         {
             SID sid = AuthorizationMethods.CreateWellKnownSid(type);
             AccountSidInformation info = AuthorizationMethods.LookupAccountSidLocal(sid);
             Debug.WriteLine($"/// {info.Name} ({AuthorizationMethods.ConvertSidToString(ref sid)}) [{info.Usage}]");
         }
         catch
         {
             Debug.WriteLine($"/// Unable to retrieve");
         }
         Debug.WriteLine(@"/// </summary>");
         Debug.WriteLine($"{type} = {(int)type},");
         Debug.WriteLine("");
     }
 }
        public void CreateWellKnownSid_Everyone()
        {
            SID sid = AuthorizationMethods.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinWorldSid);

            AuthorizationMethods.IsValidSid(ref sid).Should().BeTrue();
            sid.Revision.Should().Be(1);
            sid.IdentifierAuthority.Should().Be(SID_IDENTIFIER_AUTHORITY.WORLD);

            AuthorizationMethods.GetSidSubAuthorityCount(ref sid).Should().Be(1);
            AuthorizationMethods.GetSidSubAuthority(ref sid, 0).Should().Be(0);

            AuthorizationMethods.IsWellKnownSid(ref sid, WELL_KNOWN_SID_TYPE.WinWorldSid).Should().BeTrue();
            AuthorizationMethods.ConvertSidToString(ref sid).Should().Be("S-1-1-0");

            AccountSidInformation info = AuthorizationMethods.LookupAccountSidLocal(sid);

            info.Name.Should().Be("Everyone");
            info.DomainName.Should().Be("");
            info.Usage.Should().Be(SidNameUse.WellKnownGroup);
        }
Exemple #7
0
 // [Fact]
 private void DumpAllWellKnownSids()
 {
     foreach (WellKnownSID type in Enum.GetValues(typeof(WellKnownSID)))
     {
         Debug.WriteLine(@"/// <summary>");
         try
         {
             SID sid = Security.CreateWellKnownSid(type);
             AccountSidInformation info = sid.LookupAccountSid();
             Debug.WriteLine($"///  {info.Name} ({sid.ConvertSidToString()}) [{info.Usage}]");
         }
         catch
         {
             Debug.WriteLine($"///  Unable to retrieve");
         }
         Debug.WriteLine(@"/// </summary>");
         Debug.WriteLine($"{type} = {(int)type},");
         Debug.WriteLine("");
     }
 }
Exemple #8
0
        public void CreateWellKnownSid_Everyone()
        {
            SID sid = Security.CreateWellKnownSid(WellKnownSID.World);

            sid.IsValidSid().Should().BeTrue();
            sid.Revision.Should().Be(1);
            sid.IdentifierAuthority.Should().Be(IdentifierAuthority.World);

            sid.GetSidSubAuthorityCount().Should().Be(1);
            sid.GetSidSubAuthority(0).Should().Be(0);

            sid.IsWellKnownSid(WellKnownSID.World).Should().BeTrue();
            sid.ConvertSidToString().Should().Be("S-1-1-0");

            AccountSidInformation info = sid.LookupAccountSid();

            info.Name.Should().Be("Everyone");
            info.DomainName.Should().Be("");
            info.Usage.Should().Be(SidNameUse.WellKnownGroup);
        }