Skip to content

Commit

Permalink
Dynamic object types and support for having them defaulted on or off …
Browse files Browse the repository at this point in the history
…in UI
  • Loading branch information
lkarlslund committed Feb 7, 2022
1 parent ab904ae commit c1a2e5e
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 194 deletions.
36 changes: 18 additions & 18 deletions modules/analyze/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,37 +431,37 @@ $(function () {
`<input type="checkbox" ` +
(method.defaultenabled_f ? 'checked' : '') +
` id="` +
method.name +
method.lookup +
`_f" name="pwn_` +
method.name +
method.lookup +
`_f" autocomplete="off">`;
buttons +=
`<label for="` +
method.name +
method.lookup +
`_f" class ="btn btn-sm mb-0">F</label>`;
buttons +=
`<input type="checkbox" ` +
(method.defaultenabled_m ? 'checked' : '') +
` id="` +
method.name +
method.lookup +
`_m" name="pwn_` +
method.name +
method.lookup +
`_m" autocomplete="off">`;
buttons +=
`<label for="` +
method.name +
method.lookup +
`_m" class ="btn btn-sm mb-0">M</label>`;
buttons +=
`<input type="checkbox" ` +
(method.defaultenabled_l ? 'checked' : '') +
` id="` +
method.name +
method.lookup +
`_l" name="pwn_` +
method.name +
method.lookup +
`_l" autocomplete="off">`;
buttons +=
`<label for="` +
method.name +
method.lookup +
`_l" class ="btn btn-sm mb-0">L</label>`;
buttons += '</td>';

Expand All @@ -486,37 +486,37 @@ $(function () {
`<input type="checkbox" ` +
(objecttype.defaultenabled_f ? 'checked' : '') +
` id="` +
objecttype.name +
objecttype.lookup +
`_f" name="type_` +
objecttype.name +
objecttype.lookup +
`_f" autocomplete="off">`;
buttons +=
`<label for="` +
objecttype.name +
objecttype.lookup +
`_f" class ="btn btn-sm mb-0">F</label>`;
buttons +=
`<input type="checkbox" ` +
(objecttype.defaultenabled_m ? 'checked' : '') +
` id="` +
objecttype.name +
objecttype.lookup +
`_m" name="type_` +
objecttype.name +
objecttype.lookup +
`_m" autocomplete="off">`;
buttons +=
`<label for="` +
objecttype.name +
objecttype.lookup +
`_m" class ="btn btn-sm mb-0">M</label>`;
buttons +=
`<input type="checkbox" ` +
(objecttype.defaultenabled_l ? 'checked' : '') +
` id="` +
objecttype.name +
objecttype.lookup +
`_l" name="type_` +
objecttype.name +
objecttype.lookup +
`_l" autocomplete="off">`;
buttons +=
`<label for="` +
objecttype.name +
objecttype.lookup +
`_l" class ="btn btn-sm mb-0">L</label>`;

buttons += '</td>';
Expand Down
24 changes: 15 additions & 9 deletions modules/analyze/webservicefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func analysisfuncs(ws *webservice) {
ws.Router.HandleFunc("/filteroptions", func(w http.ResponseWriter, r *http.Request) {
type filterinfo struct {
Name string `json:"name"`
Lookup string `json:"lookup"`
DefaultEnabledF bool `json:"defaultenabled_f"`
DefaultEnabledM bool `json:"defaultenabled_m"`
DefaultEnabledL bool `json:"defaultenabled_l"`
Expand All @@ -41,18 +42,20 @@ func analysisfuncs(ws *webservice) {
for _, method := range engine.AllPwnMethodsSlice() {
results.Methods = append(results.Methods, filterinfo{
Name: method.String(),
Lookup: method.String(),
DefaultEnabledF: !strings.HasPrefix(method.String(), "Create") && !strings.HasPrefix(method.String(), "Delete") && !strings.HasPrefix(method.String(), "Inherits"),
DefaultEnabledM: !strings.HasPrefix(method.String(), "Create") && !strings.HasPrefix(method.String(), "Delete") && !strings.HasPrefix(method.String(), "Inherits"),
DefaultEnabledL: !strings.HasPrefix(method.String(), "Create") && !strings.HasPrefix(method.String(), "Delete") && !strings.HasPrefix(method.String(), "Inherits"),
})
}

for _, objecttype := range engine.ObjectTypeValues() {
for _, objecttype := range engine.ObjectTypes() {
results.ObjectTypes = append(results.ObjectTypes, filterinfo{
Name: objecttype.String(),
DefaultEnabledF: true,
DefaultEnabledM: true,
DefaultEnabledL: true,
Name: objecttype.Name,
Lookup: objecttype.Lookup,
DefaultEnabledF: objecttype.DefaultEnabledF,
DefaultEnabledM: objecttype.DefaultEnabledM,
DefaultEnabledL: objecttype.DefaultEnabledL,
})
}

Expand Down Expand Up @@ -289,8 +292,8 @@ func analysisfuncs(ws *webservice) {
} else if strings.HasPrefix(potentialfilter, "type_") {
prefix := potentialfilter[5 : len(potentialfilter)-2]
suffix := potentialfilter[len(potentialfilter)-2:]
ot, found := engine.ObjectTypeString(prefix)
if found != nil {
ot, found := engine.ObjectTypeLookup(prefix)
if !found {
continue
}

Expand Down Expand Up @@ -356,7 +359,7 @@ func analysisfuncs(ws *webservice) {

var targets int

var objecttypes [engine.OBJECTTYPEMAX]int
var objecttypes [256]int

for _, node := range pg.Nodes {
if node.Target {
Expand All @@ -367,7 +370,7 @@ func analysisfuncs(ws *webservice) {
}

resulttypes := make(map[string]int)
for i := engine.ObjectType(0); i < engine.OBJECTTYPEMAX; i++ {
for i := 0; i < 256; i++ {
if objecttypes[i] > 0 {
resulttypes[engine.ObjectType(i).String()] = objecttypes[i]
}
Expand Down Expand Up @@ -843,6 +846,9 @@ func analysisfuncs(ws *webservice) {
if objecttype == 0 {
continue // skip the dummy one
}
if count == 0 {
continue
}
result.Statistics[engine.ObjectType(objecttype).String()] += count
}

Expand Down
81 changes: 4 additions & 77 deletions modules/engine/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/rs/zerolog/log"
)

//go:generate enumer -type=ObjectType -trimprefix=ObjectType -json

var threadsafeobject int

const threadbuckets = 1024
Expand All @@ -38,37 +36,8 @@ func SetThreadsafe(enable bool) {
}
}

type ObjectType byte

var UnknownGUID = uuid.UUID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

const (
_ ObjectType = iota
ObjectTypeOther
ObjectTypeAttributeSchema
ObjectTypeClassSchema
ObjectTypeControlAccessRight
ObjectTypeGroup
ObjectTypeForeignSecurityPrincipal
ObjectTypeDomainDNS
ObjectTypeDNSNode
ObjectTypeDNSZone
ObjectTypeUser
ObjectTypeComputer
ObjectTypeManagedServiceAccount
ObjectTypeOrganizationalUnit
ObjectTypeBuiltinDomain
ObjectTypeContainer
ObjectTypeGroupPolicyContainer
ObjectTypeCertificateTemplate
ObjectTypeTrust
ObjectTypeService
ObjectTypeExecutable
ObjectTypeDirectory
ObjectTypeFile
OBJECTTYPEMAX = iota
)

type Object struct {
values AttributeValueMap
PwnableBy PwnConnections
Expand Down Expand Up @@ -314,53 +283,11 @@ func (o *Object) Type() ObjectType {
category = o.OneAttrString(ObjectCategorySimple)
}

switch category {
case "Domain-DNS":
o.objecttype = ObjectTypeDomainDNS
case "Dns-Node":
o.objecttype = ObjectTypeDNSNode
case "Dns-Zone":
o.objecttype = ObjectTypeDNSZone
case "Person":
o.objecttype = ObjectTypeUser
case "Group":
o.objecttype = ObjectTypeGroup
case "Foreign-Security-Principal":
o.objecttype = ObjectTypeForeignSecurityPrincipal
case "ms-DS-Group-Managed-Service-Account":
o.objecttype = ObjectTypeManagedServiceAccount
case "Organizational-Unit":
o.objecttype = ObjectTypeOrganizationalUnit
case "Builtin-Domain":
o.objecttype = ObjectTypeBuiltinDomain
case "Container":
o.objecttype = ObjectTypeContainer
case "Computer":
o.objecttype = ObjectTypeComputer
case "Group-Policy-Container":
o.objecttype = ObjectTypeGroupPolicyContainer
case "Trusted-Domain":
o.objecttype = ObjectTypeTrust
case "Attribute-Schema":
o.objecttype = ObjectTypeAttributeSchema
case "Class-Schema":
o.objecttype = ObjectTypeClassSchema
case "Control-Access-Right":
o.objecttype = ObjectTypeControlAccessRight
case "PKI-Certificate-Template":
o.objecttype = ObjectTypeCertificateTemplate
case "Service":
o.objecttype = ObjectTypeService
case "Executable":
o.objecttype = ObjectTypeExecutable
case "Directory":
o.objecttype = ObjectTypeDirectory
case "File":
o.objecttype = ObjectTypeFile
default:
o.objecttype = ObjectTypeOther
objecttype, found := ObjectTypeLookup(category)
if found {
o.objecttype = objecttype
}
return o.objecttype
return objecttype
}

func (o *Object) ObjectCategoryGUID(ao *Objects) uuid.UUID {
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var idcounter uint32 // Unique ID +1 to assign to Object added to this collection if it's zero

type typestatistics [OBJECTTYPEMAX]int
type typestatistics [256]int

type Objects struct {
threadsafemutex sync.RWMutex
Expand Down
Loading

0 comments on commit c1a2e5e

Please sign in to comment.