8000 ADCS ESC11 coverage by JonasBK · Pull Request #1679 · SpecterOps/BloodHound · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ADCS ESC11 coverage #1679

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

Open
wants to merge 4 commits into
base: main
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
102 changes: 102 additions & 0 deletions cmd/api/src/analysis/ad/ntlm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,105 @@ func fetchNTLMPrereqs(db graph.Database) (expansions impact.PathAggregator, comp
return expansions, computers, domains, cache, nil
}
}

func TestPostNTLMRelayADCSRPC(t *testing.T) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.NTLMCoerceAndRelayNTLMToADCSRPC.Setup(testContext)
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "NTLM Post Process Test - CoerceAndRelayNTLMToADCSRPC")
expansions, _, _, _, err := fetchNTLMPrereqs(db)
require.NoError(t, err)
ntlmCache, err := ad2.NewNTLMCache(context.Background(), db, expansions)
require.NoError(t, err)

cache := ad2.NewADCSCache()
enterpriseCertAuthorities, err := ad2.FetchNodesByKind(context.Background(), db, ad.EnterpriseCA)
require.NoError(t, err)
certTemplates, err := ad2.FetchNodesByKind(context.Background(), db, ad.CertTemplate)
require.NoError(t, err)
err = cache.BuildCache(context.Background(), db, enterpriseCertAuthorities, certTemplates)
require.NoError(t, err)

err = ad2.PostCoerceAndRelayNTLMToADCS(cache, operation, ntlmCache)
require.NoError(t, err)

operation.Done()

db.ReadTransaction(context.Background(), func(tx graph.Transaction) error {
if results, err := ops.FetchRelationships(tx.Relationships().Filterf(func() graph.Criteria {
return query.Kind(query.Relationship(), ad.CoerceAndRelayNTLMToADCSRPC)
})); err != nil {
t.Fatalf("error fetching ntlm to adcs rpc edges in integration test; %v", err)
} else {

require.Len(t, results, 1)
rel := results[0]

start, end, err := ops.FetchRelationshipNodes(tx, rel)
require.NoError(t, err)

require.Equal(t, start.ID, harness.NTLMCoerceAndRelayNTLMToADCSRPC.AuthenticatedUsersGroup.ID)
require.Equal(t, end.ID, harness.NTLMCoerceAndRelayNTLMToADCSRPC.Computer.ID)
}
return nil
})
})
}

func TestNTLMRelayToADCSRPCComposition(t *testing.T) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.NTLMCoerceAndRelayNTLMToADCSRPC.Setup(testContext)
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "NTLM Composition Test - CoerceAndRelayNTLMToADCSRPC")
expansions, _, _, _, err := fetchNTLMPrereqs(db)
require.NoError(t, err)
ntlmCache, err := ad2.NewNTLMCache(context.Background(), db, expansions)
require.NoError(t, err)

cache := ad2.NewADCSCache()
enterpriseCertAuthorities, err := ad2.FetchNodesByKind(context.Background(), db, ad.EnterpriseCA)
require.NoError(t, err)
certTemplates, err := ad2.FetchNodesByKind(context.Background(), db, ad.CertTemplate)
require.NoError(t, err)
err = cache.BuildCache(context.Background(), db, enterpriseCertAuthorities, certTemplates)
require.NoError(t, err)

err = ad2.PostCoerceAndRelayNTLMToADCS(cache, operation, ntlmCache)
require.NoError(t, err)

operation.Done()

db.ReadTransaction(context.Background(), func(tx graph.Transaction) error {
if results, err := ops.FetchRelationships(tx.Relationships().Filterf(func() graph.Criteria {
return query.And(
query.Kind(query.Relationship(), ad.CoerceAndRelayNTLMToADCSRPC),
)
})); err != nil {
t.Fatalf("error fetching ntlm to adcs rpc edges in integration test; %v", err)
} else {
require.Len(t, results, 1)
edge := results[0]

composition, err := ad2.GetCoerceAndRelayNTLMtoADCSRPCEdgeComposition(context.Background(), db, edge)
require.NoError(t, err)

nodes := composition.AllNodes()
require.Len(t, nodes, 7)
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.Computer))
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.CertTemplate1))
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.EnterpriseCA1))
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.RootCA))
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.Domain))
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.NTAuthStore))
require.True(t, nodes.Contains(harness.NTLMCoerceAndRelayNTLMToADCSRPC.AuthenticatedUsersGroup))
}
return nil
})
})
}
56 changes: 56 additions & 0 deletions cmd/api/src/test/integration/harnesses.go
Original file line number Diff line number Diff line change
Expand Up @@ -8873,6 +8873,61 @@ func (s *CoerceAndRelayNTLMtoADCS) Setup(graphTestContext *GraphTestContext) {
graphTestContext.UpdateNode(s.AuthenticatedUsersGroup)
}

type CoerceAndRelayNTLMtoADCSRPC struct {
AuthenticatedUsersGroup *graph.Node
CertTemplate1 *graph.Node
Computer *graph.Node
CAHost *graph.Node
Domain *graph.Node
EnterpriseCA1 *graph.Node
NTAuthStore *graph.Node
RootCA *graph.Node
}

func (s *CoerceAndRelayNTLMtoADCSRPC) Setup(graphTestContext *GraphTestContext) {
domainSid := RandomDomainSID()
s.AuthenticatedUsersGroup = graphTestContext.NewActiveDirectoryGroup("Authenticated Users Group", domainSid)
s.CertTemplate1 = graphTestContext.NewActiveDirectoryCertTemplate("CertTemplate1", domainSid, CertTemplateData{
ApplicationPolicies: []string{},
AuthenticationEnabled: true,
AuthorizedSignatures: 0,
EffectiveEKUs: []string{},
EnrolleeSuppliesSubject: false,
NoSecurityExtension: false,
RequiresManagerApproval: false,
SchannelAuthenticationEnabled: false,
SchemaVersion: 1,
SubjectAltRequireEmail: false,
SubjectAltRequireSPN: false,
SubjectAltRequireUPN: false,
})
s.CAHost = graphTestContext.NewActiveDirectoryComputer("CAHost", domainSid)
s.Computer = graphTestContext.NewActiveDirectoryComputer("Computer", domainSid)
s.Domain = graphTestContext.NewActiveDirectoryDomain("Domain", domainSid, false, true)
s.EnterpriseCA1 = graphTestContext.NewActiveDirectoryEnterpriseCA("EnterpriseCA1", domainSid)
s.NTAuthStore = graphTestContext.NewActiveDirectoryNTAuthStore("NTAuthStore", domainSid)
s.RootCA = graphTestContext.NewActiveDirectoryRootCA("RootCA", domainSid)
graphTestContext.NewRelationship(s.Computer, s.CertTemplate1, ad.Enroll)
graphTestContext.NewRelationship(s.Computer, s.EnterpriseCA1, ad.Enroll)
graphTestContext.NewRelationship(s.AuthenticatedUsersGroup, s.EnterpriseCA1, ad.Enroll)
graphTestContext.NewRelationship(s.CAHost, s.EnterpriseCA1, ad.HostsCAService)
graphTestContext.NewRelationship(s.CertTemplate1, s.EnterpriseCA1, ad.PublishedTo)
graphTestContext.NewRelationship(s.EnterpriseCA1, s.RootCA, ad.IssuedSignedBy)
graphTestContext.NewRelationship(s.EnterpriseCA1, s.NTAuthStore, ad.TrustedForNTAuth)
graphTestContext.NewRelationship(s.NTAuthStore, s.Domain, ad.NTAuthStoreFor)
graphTestContext.NewRelationship(s.RootCA, s.Domain, ad.RootCAFor)

s.EnterpriseCA1.Properties.Set(ad.RPCEncryptionCollected.String(), true)
s.EnterpriseCA1.Properties.Set(ad.RPCEncryptionEnforced.String(), false)
graphTestContext.UpdateNode(s.EnterpriseCA1)
s.Computer.Properties.Set(ad.RestrictOutboundNTLM.String(), false)
graphTestContext.UpdateNode(s.Computer)
s.CAHost.Properties.Set(common.Enabled.String(), true)
graphTestContext.UpdateNode(s.CAHost)
s.Authe 7B08 nticatedUsersGroup.Properties.Set(common.ObjectID.String(), fmt.Sprintf("authenticated-users%s", adAnalysis.AuthenticatedUsersSuffix))
graphTestContext.UpdateNode(s.AuthenticatedUsersGroup)
}

type CoerceAndRelayNTLMToSMB struct {
Computer1 *graph.Node
Computer10 *graph.Node
Expand Down Expand Up @@ -10175,6 +10230,7 @@ type HarnessDetails struct {
NTLMCoerceAndRelayNTLMToLDAP CoerceAndRelayNTLMToLDAP
NTLMCoerceAndRelayNTLMToLDAPS CoerceAndRelayNTLMToLDAPS
NTLMCoerceAndRelayNTLMToADCS CoerceAndRelayNTLMtoADCS
NTLMCoerceAndRelayNTLMToADCSRPC CoerceAndRelayNTLMtoADCSRPC
NTLMCoerceAndRelayToLDAPSelfRelay CoerceAndRelayNTLMToLDAPSelfRelay
NTLMCoerceAndRelayToLDAPSSelfRelay CoerceAndRelayNTLMToLDAPSSelfRelay
NTLMCoerceAndRelayNTLMToSMBSelfRelay CoerceAndRelayNTLMToSMBSelfRelay
Expand Down
Loading
0