-
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 rest of error cases for LocalGroupProcessorTest.cs
- Loading branch information
Showing
6 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...orCaseMocks/LocalGroupProcessorErrorCases/MockFailAliasAdministrators_PreviouslyCached.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,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(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...s/SAMMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailAlias_PreviouslyCached.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,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(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailDomainBuiltIn_PreviouslyCached.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_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(); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailSAMServer_LookupPrincipalBySid.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,69 @@ | ||
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_LookupPrincipalBySid : ISAMServer | ||
{ | ||
public bool IsNull { get; } | ||
public Result<IEnumerable<(string Name, int Rid)>> GetDomains() | ||
{ | ||
var domains = new List<(string, int)> | ||
{ | ||
("WIN10", 0), | ||
("BUILTIN", 1) | ||
}; | ||
return domains; | ||
} | ||
|
||
public Result<SecurityIdentifier> LookupDomain(string name) | ||
{ | ||
throw new 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) | ||
{ | ||
// switch (securityIdentifier.Value) | ||
// { | ||
// case "S-1-5-21-321011808-3761883066-353627080-500": | ||
// return ("Administrator", SharedEnums.SidNameUse.User); | ||
// case "S-1-5-21-321011808-3761883066-353627080-1000": | ||
// return ("DefaultUser", SharedEnums.SidNameUse.User); | ||
// case "S-1-5-21-321011808-3761883066-353627080-1003": | ||
// return ("TestGroup", SharedEnums.SidNameUse.Alias); | ||
// default: | ||
// throw new IndexOutOfRangeException(); | ||
// } | ||
return NtStatus.StatusAccessDenied; | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(string domainName, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
if (domainName.Equals("win10", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return new MockWorkstationDomainWIN10(); | ||
} | ||
return new MockWorkstationDomainBuiltIn(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(SecurityIdentifier securityIdentifier, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
return new MockWorkstationDomainBuiltIn(); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...MMocks/ErrorCaseMocks/LocalGroupProcessorErrorCases/MockFailSAMServer_PreviouslyCached.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,68 @@ | ||
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_PreviouslyCached : ISAMServer | ||
{ | ||
public bool IsNull { get; } | ||
public Result<IEnumerable<(string Name, int Rid)>> GetDomains() | ||
{ | ||
var domains = new List<(string, int)> | ||
{ | ||
("WIN10", 0), | ||
("BUILTIN", 1) | ||
}; | ||
return domains; | ||
} | ||
|
||
public Result<SecurityIdentifier> LookupDomain(string name) | ||
{ | ||
throw new 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) | ||
{ | ||
switch (securityIdentifier.Value) | ||
{ | ||
case "S-1-5-21-321011808-3761883066-353627080-500": | ||
return ("Administrator", SharedEnums.SidNameUse.User); | ||
case "S-1-5-21-321011808-3761883066-353627080-1000": | ||
return ("DefaultUser", SharedEnums.SidNameUse.User); | ||
case "S-1-5-21-321011808-3761883066-353627080-1003": | ||
return ("TestGroup", SharedEnums.SidNameUse.Alias); | ||
default: | ||
throw new IndexOutOfRangeException(); | ||
} | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(string domainName, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
if (domainName.Equals("win10", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return new MockWorkstationDomainWIN10(); | ||
} | ||
return new MockFailDomainBuiltIn_PreviouslyCached(); | ||
} | ||
|
||
public Result<ISAMDomain> OpenDomain(SecurityIdentifier securityIdentifier, | ||
SAMEnums.DomainAccessMask requestedDomainAccess = SAMEnums.DomainAccessMask.ListAccounts | SAMEnums.DomainAccessMask.Lookup) | ||
{ | ||
return new MockFailDomainBuiltIn_PreviouslyCached(); | ||
} | ||
} | ||
} |
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