-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mocks to test error cases for LocalGroupProcessor
- Loading branch information
Showing
12 changed files
with
630 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailDomainBuiltIn_GetAliases.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailDomainBuiltIn_GetMembers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailDomainBuiltIn_OpenAlias.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailSAMAliasUsers_GetMembers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using SharpHoundRPC; | ||
using SharpHoundRPC.Wrappers; | ||
using System.Security.Principal; | ||
|
||
namespace CommonLibTest.Facades | ||
{ | ||
public class MockFailSAMAliasUsers_GetMembers : ISAMAlias | ||
{ | ||
public Result<IEnumerable<SecurityIdentifier>> GetMembers() | ||
{ | ||
return NtStatus.StatusAccessDenied; | ||
} | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
...des/SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailSAMServer_GetAliases.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Security.Principal; | ||
using SharpHoundRPC; | ||
using SharpHoundRPC.SAMRPCNative; | ||
using SharpHoundRPC.Shared; | ||
using SharpHoundRPC.Wrappers; | ||
|
||
namespace CommonLibTest.Facades | ||
{ | ||
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")] | ||
public class MockFailSAMServer_GetAliases : ISAMServer | ||
{ | ||
public bool IsNull { get; } | ||
public Result<IEnumerable<(string Name, int Rid)>> GetDomains() | ||
{ | ||
var domains = new List<(string, int)> | ||
{ | ||
("BUILTIN", 1) | ||
}; | ||
return domains; | ||
} | ||
|
||
public virtual Result<SecurityIdentifier> LookupDomain(string name) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Result<SecurityIdentifier> GetMachineSid(string testName = null) | ||
{ | ||
var securityIdentifier = new SecurityIdentifier(Consts.MockWorkstationMachineSid); | ||
return Result<SecurityIdentifier>.Ok(securityIdentifier); | ||
} | ||
|
||
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalBySid(SecurityIdentifier securityIdentifier) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(string domainName, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
if (domainName.Equals("builtin", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return new MockFailDomainBuiltIn_GetAliases(); | ||
} | ||
|
||
throw new NotImplementedException(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(SecurityIdentifier securityIdentifier, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...des/SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailSAMServer_GetDomains.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Security.Principal; | ||
using SharpHoundRPC; | ||
using SharpHoundRPC.SAMRPCNative; | ||
using SharpHoundRPC.Shared; | ||
using SharpHoundRPC.Wrappers; | ||
|
||
namespace CommonLibTest.Facades | ||
{ | ||
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")] | ||
public class MockFailSAMServer_GetDomains : ISAMServer | ||
{ | ||
public bool IsNull { get; } | ||
public Result<IEnumerable<(string Name, int Rid)>> GetDomains() | ||
{ | ||
// var domains = new List<(string, int)> | ||
// { | ||
// ("BUILTIN", 1) | ||
// }; | ||
// return domains; | ||
|
||
return Result<IEnumerable<(string Name, int Rid)>>.Fail(NtStatus.StatusAccessDenied); | ||
} | ||
|
||
public virtual Result<SecurityIdentifier> LookupDomain(string name) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Result<SecurityIdentifier> GetMachineSid(string testName = null) | ||
{ | ||
var securityIdentifier = new SecurityIdentifier(Consts.MockWorkstationMachineSid); | ||
return Result<SecurityIdentifier>.Ok(securityIdentifier); | ||
} | ||
|
||
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalBySid(SecurityIdentifier securityIdentifier) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(string domainName, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
if (domainName.Equals("builtin", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return new MockDCDomainBuiltIn(); | ||
} | ||
|
||
throw new NotImplementedException(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(SecurityIdentifier securityIdentifier, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailSAMServer_GetMachineSid.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Security.Principal; | ||
using SharpHoundRPC; | ||
using SharpHoundRPC.SAMRPCNative; | ||
using SharpHoundRPC.Shared; | ||
using SharpHoundRPC.Wrappers; | ||
|
||
namespace CommonLibTest.Facades | ||
{ | ||
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")] | ||
public class MockFailSAMServer_GetMachineSid : ISAMServer | ||
{ | ||
public bool IsNull { get; } | ||
public Result<IEnumerable<(string Name, int Rid)>> GetDomains() | ||
{ | ||
var domains = new List<(string, int)> | ||
{ | ||
("BUILTIN", 1) | ||
}; | ||
return domains; | ||
} | ||
|
||
public virtual Result<SecurityIdentifier> LookupDomain(string name) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Result<SecurityIdentifier> GetMachineSid(string testName = null) | ||
{ | ||
// var securityIdentifier = new SecurityIdentifier(Consts.MockWorkstationMachineSid); | ||
// return Result<SecurityIdentifier>.Ok(securityIdentifier); | ||
|
||
return Result<SecurityIdentifier>.Fail(NtStatus.StatusAccessDenied); | ||
} | ||
|
||
public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalBySid(SecurityIdentifier securityIdentifier) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(string domainName, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
if (domainName.Equals("builtin", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return new MockDCDomainBuiltIn(); | ||
} | ||
|
||
throw new NotImplementedException(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(SecurityIdentifier securityIdentifier, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.