Skip to content

Commit

Permalink
Merge branch 'main' into anemeth/cursor-jump-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
definitelynotagoblin authored Jan 22, 2024
2 parents 7be5719 + d30bc92 commit e371141
Show file tree
Hide file tree
Showing 247 changed files with 16,704 additions and 4,156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '^1.20.0'
go-version: '^1.21.0'

- name: Install Python
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion DEVREADME.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ More detailed information regarding [contributing](https://github.com/SpecterOps

- [Just](https://github.com/casey/just)
- [Python 3.10](https://www.python.org/downloads/)
- [Go 1.20](https://go.dev/dl/)
- [Go 1.21](https://go.dev/dl/)
- [Node 18](https://nodejs.dev/en/download/)
- [Yarn 3.6](https://yarnpkg.com/getting-started/install)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or Docker/Docker Compose compatible runtime)
Expand Down
461 changes: 252 additions & 209 deletions cmd/api/src/analysis/ad/ad_integration_test.go

Large diffs are not rendered by default.

91 changes: 49 additions & 42 deletions cmd/api/src/analysis/ad/adcs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package ad_test
import (
"context"
"github.com/specterops/bloodhound/analysis"
"github.com/specterops/bloodhound/graphschema"

ad2 "github.com/specterops/bloodhound/analysis/ad"

Expand All @@ -39,11 +40,12 @@ import (
)

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

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.ADCSESC1Harness.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - ESC1")

groupExpansions, err := ad2.ExpandAllRDPLocalGroups(context.Background(), db)
Expand Down Expand Up @@ -106,17 +108,16 @@ func TestADCSESC1(t *testing.T) {
}
return nil
})
return nil
})

}

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

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.ADCSGoldenCertHarness.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - Golden Cert")

domains, err := ad2.FetchNodesByKind(context.Background(), db, ad.Domain)
Expand Down Expand Up @@ -170,16 +171,17 @@ func TestGoldenCert(t *testing.T) {
}
return nil
})
return nil
})

}

func TestCanAbuseUPNCertMapping(t *testing.T) {
testContext := integration.NewGraphTestContext(t)
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.WeakCertBindingAndUPNCertMappingHarness.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - CanAbuseUPNCertMapping")

if enterpriseCertAuthorities, err := ad2.FetchNodesByKind(context.Background(), db, ad.EnterpriseCA); err != nil {
Expand All @@ -188,6 +190,7 @@ func TestCanAbuseUPNCertMapping(t *testing.T) {
t.Logf("failed post processing for %s: %v", ad.CanAbuseUPNCertMapping.String(), err)
}

// TODO: We're throwing away the collected errors from the operation and should assert on them
operation.Done()

db.ReadTransaction(context.Background(), func(tx graph.Transaction) error {
Expand All @@ -214,15 +217,15 @@ func TestCanAbuseUPNCertMapping(t *testing.T) {
}
return nil
})
return nil
})
}

func TestCanAbuseWeakCertBinding(t *testing.T) {
testContext := integration.NewGraphTestContext(t)
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.WeakCertBindingAndUPNCertMappingHarness.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - CanAbuseWeakCertBinding")

if enterpriseCertAuthorities, err := ad2.FetchNodesByKind(context.Background(), db, ad.EnterpriseCA); err != nil {
Expand All @@ -231,6 +234,7 @@ func TestCanAbuseWeakCertBinding(t *testing.T) {
t.Logf("failed post processing for %s: %v", ad.CanAbuseWeakCertBinding.String(), err)
}

// TODO: We're throwing away the collected errors from the operation and should assert on them
operation.Done()

db.ReadTransaction(context.Background(), func(tx graph.Transaction) error {
Expand All @@ -255,17 +259,18 @@ func TestCanAbuseWeakCertBinding(t *testing.T) {
assert.False(t, results.Contains(harness.WeakCertBindingAndUPNCertMappingHarness.Domain2))
assert.False(t, results.Contains(harness.WeakCertBindingAndUPNCertMappingHarness.Domain3))
}

return nil
})
return nil
})
}

func TestIssuedSignedBy(t *testing.T) {
testContext := integration.NewGraphTestContext(t)
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.IssuedSignedByHarness.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - IssuedSignedBy")

if rootCertAuthorities, err := ad2.FetchNodesByKind(context.Background(), db, ad.RootCA); err != nil {
Expand Down Expand Up @@ -322,20 +327,21 @@ func TestIssuedSignedBy(t *testing.T) {
assert.False(t, results2.Contains(harness.IssuedSignedByHarness.EnterpriseCA3))
assert.False(t, results3.Contains(harness.IssuedSignedByHarness.EnterpriseCA3))
}

return nil
})
return nil
})
}

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

testContext.DatabaseTestWithSetup(
func(harness *integration.HarnessDetails) {
func(harness *integration.HarnessDetails) error {
harness.TrustedForNTAuthHarness.Setup(testContext)
return nil
},
func(harness integration.HarnessDetails, db graph.Database) error {
func(harness integration.HarnessDetails, db graph.Database) {
// post `TrustedForNTAuth` edges
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - TrustedForNTAuth")

Expand Down Expand Up @@ -364,16 +370,15 @@ func TestTrustedForNTAuth(t *testing.T) {
}
return nil
})

return nil
})
}

func TestEnrollOnBehalfOf(t *testing.T) {
testContext := integration.NewGraphTestContext(t)
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.EnrollOnBehalfOfHarnessOne.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
certTemplates, err := ad2.FetchNodesByKind(context.Background(), db, ad.CertTemplate)
v1Templates := make([]*graph.Node, 0)
v2Templates := make([]*graph.Node, 0)
Expand All @@ -386,7 +391,9 @@ func TestEnrollOnBehalfOf(t *testing.T) {
v2Templates = append(v2Templates, template)
}
}

require.Nil(t, err)

db.ReadTransaction(context.Background(), func(tx graph.Transaction) error {
results, err := ad2.EnrollOnBehalfOfVersionOne(tx, v1Templates, certTemplates)
require.Nil(t, err)
Expand All @@ -413,16 +420,16 @@ func TestEnrollOnBehalfOf(t *testing.T) {

return nil
})

return nil
})

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.EnrollOnBehalfOfHarnessTwo.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
certTemplates, err := ad2.FetchNodesByKind(context.Background(), db, ad.CertTemplate)
v1Templates := make([]*graph.Node, 0)
v2Templates := make([]*graph.Node, 0)

for _, template := range certTemplates {
if version, err := template.Properties.Get(ad.SchemaVersion.String()).Float64(); err != nil {
continue
Expand All @@ -432,7 +439,9 @@ func TestEnrollOnBehalfOf(t *testing.T) {
v2Templates = append(v2Templates, template)
}
}

require.Nil(t, err)

db.ReadTransaction(context.Background(), func(tx graph.Transaction) error {
results, err := ad2.EnrollOnBehalfOfVersionTwo(tx, v2Templates, certTemplates)
require.Nil(t, err)
Expand All @@ -446,16 +455,15 @@ func TestEnrollOnBehalfOf(t *testing.T) {

return nil
})

return nil
})
}

func TestADCSESC3(t *testing.T) {
testContext := integration.NewGraphTestContext(t)
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext := integration.NewGraphTestContext(t, graphschema.DefaultGraphSchema())
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.ESC3Harness1.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - ESC3")

groupExpansions, err := ad2.ExpandAllRDPLocalGroups(context.Background(), db)
Expand Down Expand Up @@ -506,12 +514,12 @@ func TestADCSESC3(t *testing.T) {
}
return nil
})
return nil
})

testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) {
testContext.DatabaseTestWithSetup(func(harness *integration.HarnessDetails) error {
harness.ESC3Harness2.Setup(testContext)
}, func(harness integration.HarnessDetails, db graph.Database) error {
return nil
}, func(harness integration.HarnessDetails, db graph.Database) {
operation := analysis.NewPostRelationshipOperation(context.Background(), db, "ADCS Post Process Test - ESC3")

groupExpansions, err := ad2.ExpandAllRDPLocalGroups(context.Background(), db)
Expand Down Expand Up @@ -570,6 +578,5 @@ func TestADCSESC3(t *testing.T) {
}
return nil
})
return nil
})
}
94 changes: 0 additions & 94 deletions cmd/api/src/analysis/ad/tierzero.go

This file was deleted.

Loading

0 comments on commit e371141

Please sign in to comment.