Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Testing Coverage #178

Open
wants to merge 13 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
630 changes: 630 additions & 0 deletions test/unit/ACLProcessorTest.cs

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions test/unit/CertAbuseProcessorTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using System;
using System.DirectoryServices;
using System.Threading.Tasks;
using CommonLibTest.Facades;
using Moq;
using Newtonsoft.Json;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Processors;
using Xunit;
using Xunit.Abstractions;

namespace CommonLibTest {
Expand Down Expand Up @@ -77,26 +85,27 @@ public void Dispose() {
// Assert.Empty(results);
// }

// [Fact]
// public void CertAbuseProcessor_ProcessCAPermissions_NullSecurity_ReturnsNull()
// {
// var mockUtils = new Mock<MockLDAPUtils>();
// var processor = new CertAbuseProcessor(mockUtils.Object);
[Fact]
public async Task CertAbuseProcessor_ProcessCAPermissions_NullSecurity_ReturnsNull()
{
var processor = new CertAbuseProcessor(new MockLdapUtils());

// var results = processor.ProcessRegistryEnrollmentPermissions(null, null, "test");
var results = await processor.ProcessRegistryEnrollmentPermissions(null, "DUMPSTER.FIRE", null, "test");

// Assert.Empty(results);
// }
Assert.Equal("Value cannot be null. (Parameter 'machineName')", results.FailureReason);
Assert.False(results.Collected);
Assert.Empty(results.Data);
}

// [WindowsOnlyFact]
// public void CertAbuseProcessor_ProcessCAPermissions_ReturnsCorrectValues()
// {
// var mockUtils = new Mock<MockLDAPUtils>();
// var mockUtils = new Mock<MockLdapUtils>();
// var sd = new ActiveDirectorySecurityDescriptor(new ActiveDirectorySecurity());
// mockUtils.Setup(x => x.MakeSecurityDescriptor()).Returns(sd);
// var processor = new CertAbuseProcessor(mockUtils.Object);
// var bytes = Helpers.B64ToBytes(CASecurityFixture);

//
// var results = processor.ProcessCAPermissions(bytes, "TESTLAB.LOCAL", "test", false);
// _testOutputHelper.WriteLine(JsonConvert.SerializeObject(results, Formatting.Indented));
// Assert.Contains(results,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;
using SharpHoundRPC;
using SharpHoundRPC.Shared;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades.LSAMocks.WorkstationMocks
{
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
public class MockFailLSAPolicy_GetLocalDomainInformation : ILSAPolicy
{
public Result<(string Name, string Sid)> GetLocalDomainInformation()
{
return NtStatus.StatusAccessDenied;
}

public Result<IEnumerable<SecurityIdentifier>> GetPrincipalsWithPrivilege(string userRight)
{
throw new NotImplementedException();
}

public Result<IEnumerable<(SecurityIdentifier sid, string Name, SharedEnums.SidNameUse Use, string Domain)>>
GetResolvedPrincipalsWithPrivilege(string userRight)
{
return new List<(SecurityIdentifier sid, string Name, SharedEnums.SidNameUse Use, string Domain)>
{
(new SecurityIdentifier("S-1-5-32-555"), "Remote Desktop Users", SharedEnums.SidNameUse.Alias, "abc"),
(new SecurityIdentifier("S-1-5-32-544"), "Administrators", SharedEnums.SidNameUse.Alias, "abc"),
(new SecurityIdentifier($"{Consts.MockWorkstationMachineSid}-1000"), "John", SharedEnums.SidNameUse.User, "abc"),
(new SecurityIdentifier($"{Consts.MockWorkstationMachineSid}-1001"), "TestGroup", SharedEnums.SidNameUse.Alias, "abc"),
};
}

public Result<(string Name, SharedEnums.SidNameUse Use, string Domains)> LookupSid(SecurityIdentifier sid)
{
throw new NotImplementedException();
}

public Result<IEnumerable<(SecurityIdentifier Sid, string Name, SharedEnums.SidNameUse Use, string Domain)>>
LookupSids(SecurityIdentifier[] sids)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;
using SharpHoundRPC;
using SharpHoundRPC.Shared;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades.LSAMocks.WorkstationMocks
{
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
public class MockFailLSAPolicy_GetResolvedPrincipalsWithPrivilege : ILSAPolicy
{
public Result<(string Name, string Sid)> GetLocalDomainInformation()
{
return ("WIN10", Consts.MockWorkstationMachineSid);
}

public Result<IEnumerable<SecurityIdentifier>> GetPrincipalsWithPrivilege(string userRight)
{
throw new NotImplementedException();
}

public Result<IEnumerable<(SecurityIdentifier sid, string Name, SharedEnums.SidNameUse Use, string Domain)>>
GetResolvedPrincipalsWithPrivilege(string userRight)
{
return NtStatus.StatusAccessDenied;
}

public Result<(string Name, SharedEnums.SidNameUse Use, string Domains)> LookupSid(SecurityIdentifier sid)
{
throw new NotImplementedException();
}

public Result<IEnumerable<(SecurityIdentifier Sid, string Name, SharedEnums.SidNameUse Use, string Domain)>>
LookupSids(SecurityIdentifier[] sids)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;
using SharpHoundRPC;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades
{
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
public class MockFailAliasAdministrators_PreviouslyCached : ISAMAlias
{
public Result<IEnumerable<SecurityIdentifier>> GetMembers()
{
return new List<SecurityIdentifier>()
{
new("S-1-5-21-321011808-3761883066-353627080-1000"),
new("S-1-5-21-321011808-3761883066-353627080-1000"),
new("S-1-5-21-4243161961-3815211218-2888324771-512"),
};
}

public void Dispose()
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;
using SharpHoundRPC;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades
{
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
public class MockFailAlias_PreviouslyCached : ISAMAlias
{
public Result<IEnumerable<SecurityIdentifier>> GetMembers()
{
return new List<SecurityIdentifier>()
{
new("S-1-5-21-321011808-3761883066-353627080-1003"),
new("S-1-5-21-321011808-3761883066-353627080-1003"),
new("S-1-5-32-544"),
};
}

public void Dispose()
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using SharpHoundRPC;
using SharpHoundRPC.SAMRPCNative;
using SharpHoundRPC.Shared;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades
{
public class MockFailDomainBuiltIn_GetAliases : ISAMDomain
{
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalByRid(int rid)
{
throw new System.NotImplementedException();
}

public Result<IEnumerable<(string Name, int Rid)>> GetAliases()
{
// var results = new List<(string, int)>
// {
// ("Administrators", 544),
// ("Users", 545)
// };
// return results;
return NtStatus.StatusAccessDenied;
}

public Result<ISAMAlias> OpenAlias(int rid, SAMEnums.AliasOpenFlags desiredAccess = SAMEnums.AliasOpenFlags.ListMembers)
{
switch (rid)
{
case 544:
return new MockDCAliasAdministrators();
case 545:
return new MockDCAliasUsers();
default:
throw new IndexOutOfRangeException();
}
}

public Result<ISAMAlias> OpenAlias(string name)
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using SharpHoundRPC;
using SharpHoundRPC.SAMRPCNative;
using SharpHoundRPC.Shared;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades
{
public class MockFailDomainBuiltIn_GetMembers : ISAMDomain
{
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalByRid(int rid)
{
throw new System.NotImplementedException();
}

public Result<IEnumerable<(string Name, int Rid)>> GetAliases()
{
var results = new List<(string, int)>
{
("Users", 545)
};
return results;
}

public Result<ISAMAlias> OpenAlias(int rid, SAMEnums.AliasOpenFlags desiredAccess = SAMEnums.AliasOpenFlags.ListMembers)
{
switch (rid)
{
case 545:
return new MockFailSAMAliasUsers_GetMembers();
default:
throw new IndexOutOfRangeException();
}
}

public Result<ISAMAlias> OpenAlias(string name)
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using SharpHoundRPC;
using SharpHoundRPC.SAMRPCNative;
using SharpHoundRPC.Shared;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades
{
public class MockFailDomainBuiltIn_OpenAlias : ISAMDomain
{
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalByRid(int rid)
{
throw new System.NotImplementedException();
}

public Result<IEnumerable<(string Name, int Rid)>> GetAliases()
{
var results = new List<(string, int)>
{
("Administrators", 544)
};
return results;
}

public Result<ISAMAlias> OpenAlias(int rid, SAMEnums.AliasOpenFlags desiredAccess = SAMEnums.AliasOpenFlags.ListMembers)
{
// switch (rid)
// {
// case 544:
// return new MockDCAliasAdministrators();
// case 545:
// return new MockDCAliasUsers();
// default:
// throw new IndexOutOfRangeException();
// }
return NtStatus.StatusAccessDenied;
}

public Result<ISAMAlias> OpenAlias(string name)
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using SharpHoundRPC;
using SharpHoundRPC.SAMRPCNative;
using SharpHoundRPC.Shared;
using SharpHoundRPC.Wrappers;

namespace CommonLibTest.Facades
{
public class MockFailDomainBuiltIn_PreviouslyCached : ISAMDomain
{
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalByRid(int rid)
{
throw new System.NotImplementedException();
}

public Result<IEnumerable<(string Name, int Rid)>> GetAliases()
{
var result = new List<(string, int)>
{
("administrators", 544),
("remote desktop users", 555)
};
return result;
}

public Result<ISAMAlias> OpenAlias(int rid, SAMEnums.AliasOpenFlags desiredAccess = SAMEnums.AliasOpenFlags.ListMembers)
{
if (rid == 544)
{
return new MockFailAliasAdministrators_PreviouslyCached();
}
if (rid == 555)
{
return new MockFailAlias_PreviouslyCached();
}

throw new NotImplementedException();
}

public Result<ISAMAlias> OpenAlias(string name)
{
throw new System.NotImplementedException();
}
}
}
Loading
Loading