Skip to content

Commit

Permalink
traversals moved to common cue (#1067)
Browse files Browse the repository at this point in the history
* traversals moved to common cue

* remove contains from azure.InboundOutboundRelationshipKinds
  • Loading branch information
brandonshearin authored Jan 14, 2025
1 parent 8d5bd4e commit 9b9f80c
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 28 deletions.
23 changes: 17 additions & 6 deletions packages/cue/bh/ad/ad.cue
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@

package ad

import "pkg.specterops.io/schemas/bh/types:types"
import (
"list"
"pkg.specterops.io/schemas/bh/types:types"
)

// Exported requirements
Properties: [...types.#StringEnum]
NodeKinds: [...types.#Kind]
RelationshipKinds: [...types.#Kind]
ACLRelationships: [...types.#Kind]
PathfindingRelationships: [...types.#Kind]
InboundRelationshipKinds: [...types.#Kind]
OutboundRelationshipKinds: [...types.#Kind]
EdgeCompositionRelationships: [...types.#Kind]

// Property name enumerations
Expand Down Expand Up @@ -1412,8 +1417,8 @@ ACLRelationships: [
WritePKINameFlag,
]

// Edges that are used in pathfinding
PathfindingRelationships: [
// these edges are common to inbound/outbound/pathfinding
SharedRelationshipKinds: [
Owns,
GenericAll,
GenericWrite,
Expand All @@ -1424,11 +1429,9 @@ PathfindingRelationships: [
AllExtendedRights,
AddMember,
HasSession,
Contains,
GPLink,
AllowedToDelegate,
CoerceToTGT,
TrustedBy,
AllowedToAct,
AdminTo,
CanPSRemote,
Expand Down Expand Up @@ -1458,11 +1461,19 @@ PathfindingRelationships: [
ADCSESC10a,
ADCSESC10b,
ADCSESC13,
DCFor,
SyncedToEntraUser,
CoerceAndRelayNTLMToSMB,
]

// Edges that are used during inbound traversal
InboundRelationshipKinds: list.Concat([SharedRelationshipKinds,[Contains]])

// Edges that are used during outbound traversal
OutboundRelationshipKinds: list.Concat([SharedRelationshipKinds,[Contains, DCFor]])

// Edges that are used in pathfinding
PathfindingRelationships: list.Concat([SharedRelationshipKinds,[Contains, DCFor, TrustedBy]])

EdgeCompositionRelationships: [
GoldenCert,
ADCSESC1,
Expand Down
12 changes: 9 additions & 3 deletions packages/cue/bh/azure/azure.cue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package azure

import "pkg.specterops.io/schemas/bh/types:types"
import (
"list"
"pkg.specterops.io/schemas/bh/types:types"
)

// Exported requirements
Properties: [...types.#StringEnum]
Expand All @@ -27,6 +30,7 @@ AbusableAppRoleRelationshipKinds: [... types.#Kind]
ControlRelationshipKinds: [...types.#Kind]
ExecutionPrivilegeKinds: [...types.#Kind]
PathfindingRelationships: [...types.#Kind]
InboundOutboundRelationshipKinds: [...types.#Kind]

// Property name enumerations
AppOwnerOrganizationID: types.#StringEnum & {
Expand Down Expand Up @@ -831,9 +835,9 @@ ExecutionPrivilegeKinds: [
ExecuteCommand,
]

PathfindingRelationships: [
// Edges that are used during inbound and outbound traversals
InboundOutboundRelationshipKinds: [
AvereContributor,
Contains,
Contributor,
GetCertificates,
GetKeys,
Expand Down Expand Up @@ -872,3 +876,5 @@ PathfindingRelationships: [
AZMGGrantRole,
SyncedToADUser,
]

PathfindingRelationships: list.Concat([InboundOutboundRelationshipKinds, [Contains]])
11 changes: 10 additions & 1 deletion packages/cue/bh/bh.cue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
Properties: [...types.#StringEnum]
NodeKinds: [...types.#Kind]
RelationshipKinds: [...types.#Kind]
InboundRelationshipKinds: [...types.#Kind]
OutboundRelationshipKinds: [...types.#Kind]
}

#Azure: {
Expand All @@ -39,6 +41,7 @@ import (
ControlRelationshipKinds: [...types.#Kind]
ExecutionPrivilegeKinds: [...types.#Kind]
PathfindingRelationships: [...types.#Kind]
InboundOutboundRelationshipKinds: [...types.#Kind]
}

#ActiveDirectory: {
Expand All @@ -47,6 +50,8 @@ import (
RelationshipKinds: [...types.#Kind]
ACLRelationships: [...types.#Kind]
PathfindingRelationships: [...types.#Kind]
InboundRelationshipKinds: [...types.#Kind]
OutboundRelationshipKinds: [...types.#Kind]
EdgeCompositionRelationships: [...types.#Kind]
}

Expand All @@ -55,6 +60,8 @@ Common: #Common & {
Properties: common.Properties
NodeKinds: common.NodeKinds
RelationshipKinds: common.RelationshipKinds
InboundRelationshipKinds: common.InboundRelationshipKinds
OutboundRelationshipKinds: common.OutboundRelationshipKinds
}

Azure: #Azure & {
Expand All @@ -66,6 +73,7 @@ Azure: #Azure & {
ControlRelationshipKinds: azure.ControlRelationshipKinds
ExecutionPrivilegeKinds: azure.ExecutionPrivilegeKinds
PathfindingRelationships: azure.PathfindingRelationships
InboundOutboundRelationshipKinds: azure.InboundOutboundRelationshipKinds
}

ActiveDirectory: #ActiveDirectory & {
Expand All @@ -74,6 +82,7 @@ ActiveDirectory: #ActiveDirectory & {
RelationshipKinds: ad.RelationshipKinds
ACLRelationships: ad.ACLRelationships
PathfindingRelationships: ad.PathfindingRelationships
InboundRelationshipKinds: ad.InboundRelationshipKinds
OutboundRelationshipKinds: ad.OutboundRelationshipKinds
EdgeCompositionRelationships: ad.EdgeCompositionRelationships

}
12 changes: 11 additions & 1 deletion packages/cue/bh/common/common.cue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@

package common

import "pkg.specterops.io/schemas/bh/types:types"
import (
"pkg.specterops.io/schemas/bh/types:types"
"pkg.specterops.io/schemas/bh/ad:ad"
"pkg.specterops.io/schemas/bh/azure:azure"
"list"
)

// Exported requirements
Properties: [...types.#StringEnum]
NodeKinds: [...types.#Kind]
RelationshipKinds: [...types.#Kind]
InboundRelationshipKinds: [...types.#Kind]
OutboundRelationshipKinds: [...types.#Kind]

// Property name enumerations
ObjectID: types.#StringEnum & {
Expand Down Expand Up @@ -168,3 +175,6 @@ NodeKinds: [

RelationshipKinds: [
]

InboundRelationshipKinds: list.Concat([ad.InboundRelationshipKinds, azure.InboundOutboundRelationshipKinds])
OutboundRelationshipKinds: list.Concat([ad.OutboundRelationshipKinds, azure.InboundOutboundRelationshipKinds])
10 changes: 8 additions & 2 deletions packages/go/graphschema/ad/ad.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/go/graphschema/azure/azure.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion packages/go/graphschema/common/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/go/graphschema/graph.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 53 additions & 3 deletions packages/go/schemagen/generator/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import (
)

const (
GraphPackageName = "github.com/specterops/bloodhound/dawgs/graph"
SchemaPackageName = "github.com/specterops/bloodhound/graphschema"
SchemaSourceName = "github.com/specterops/bloodhound/-/tree/main/packages/cue/schemas"
GraphPackageName = "github.com/specterops/bloodhound/dawgs/graph"
SchemaPackageName = "github.com/specterops/bloodhound/graphschema"
ADSchemaPackageName = "github.com/specterops/bloodhound/graphschema/ad"
AzureSchemaPackageName = "github.com/specterops/bloodhound/graphschema/azure"
SchemaSourceName = "github.com/specterops/bloodhound/-/tree/main/packages/cue/schemas"
)

func WriteGolangKindDefinitions(root *jen.File, values []model.StringEnum) {
Expand Down Expand Up @@ -308,6 +310,34 @@ func GenerateGolangGraphModel(pkgName, dir string, graphSchema model.Graph) (*je
),
)

root.Func().Id("InboundRelationshipKinds").Params().Index().Qual(GraphPackageName, "Kind").Block(
jen.Return(
jen.Index().Qual(GraphPackageName, "Kind").ValuesFunc(func(group *jen.Group) {
for _, relKind := range graphSchema.InboundRelationshipKinds {
if relKind.Schema == "active_directory" {
group.Qual(ADSchemaPackageName, "").Id(relKind.Symbol)
} else if relKind.Schema == "azure" {
group.Qual(AzureSchemaPackageName, "").Id(relKind.Symbol)
}
}
}),
),
)

root.Func().Id("OutboundRelationshipKinds").Params().Index().Qual(GraphPackageName, "Kind").Block(
jen.Return(
jen.Index().Qual(GraphPackageName, "Kind").ValuesFunc(func(group *jen.Group) {
for _, relKind := range graphSchema.OutboundRelationshipKinds {
if relKind.Schema == "active_directory" {
group.Qual(ADSchemaPackageName, "").Id(relKind.Symbol)
} else if relKind.Schema == "azure" {
group.Qual(AzureSchemaPackageName, "").Id(relKind.Symbol)
}
}
}),
),
)

return root, filepath.Join(dir, pkgName+".go")
}

Expand Down Expand Up @@ -362,6 +392,26 @@ func GenerateGolangActiveDirectory(pkgName, dir string, adSchema model.ActiveDir
),
)

root.Func().Id("InboundRelationshipKinds").Params().Index().Qual(GraphPackageName, "Kind").Block(
jen.Return(
jen.Index().Qual(GraphPackageName, "Kind").ValuesFunc(func(group *jen.Group) {
for _, pathRelationship := range adSchema.InboundRelationshipKinds {
group.Id(pathRelationship.Symbol)
}
}),
),
)

root.Func().Id("OutboundRelationshipKinds").Params().Index().Qual(GraphPackageName, "Kind").Block(
jen.Return(
jen.Index().Qual(GraphPackageName, "Kind").ValuesFunc(func(group *jen.Group) {
for _, pathRelationship := range adSchema.OutboundRelationshipKinds {
group.Id(pathRelationship.Symbol)
}
}),
),
)

root.Func().
Id("IsACLKind").
Params(jen.Id("s").Qual(GraphPackageName, "Kind")).
Expand Down
10 changes: 7 additions & 3 deletions packages/go/schemagen/model/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func (s StringEnum) GetName() string {
}

type Graph struct {
Properties []StringEnum
NodeKinds []StringEnum
RelationshipKinds []StringEnum
Properties []StringEnum
NodeKinds []StringEnum
RelationshipKinds []StringEnum
InboundRelationshipKinds []StringEnum
OutboundRelationshipKinds []StringEnum
}

type Azure struct {
Expand All @@ -62,5 +64,7 @@ type ActiveDirectory struct {
RelationshipKinds []StringEnum
ACLRelationships []StringEnum
PathfindingRelationships []StringEnum
InboundRelationshipKinds []StringEnum
OutboundRelationshipKinds []StringEnum
EdgeCompositionRelationships []StringEnum
}
Loading

0 comments on commit 9b9f80c

Please sign in to comment.