Skip to content

Commit

Permalink
Linting fixes - struct reordering - code simplification - minor versi…
Browse files Browse the repository at this point in the history
…on package changes - objectclassguid regression fix (whoops!) - moved some attributes to more appropriate packages
  • Loading branch information
lkarlslund committed Nov 3, 2021
1 parent 8fbe94b commit bc91a53
Show file tree
Hide file tree
Showing 28 changed files with 347 additions and 296 deletions.
7 changes: 4 additions & 3 deletions modules/analyze/export-graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"

"github.com/lkarlslund/adalanche/modules/engine"
"github.com/lkarlslund/adalanche/modules/integrations/activedirectory"
"github.com/lkarlslund/adalanche/modules/version"
)

Expand All @@ -22,7 +23,7 @@ func ExportGraphViz(pg engine.PwnGraph, filename string) error {
case engine.ObjectTypeComputer:
formatting = ""
}
fmt.Fprintf(df, " \"%v\" [label=\"%v\";%v];\n", object.GUID(), object.OneAttr(engine.Name), formatting)
fmt.Fprintf(df, " \"%v\" [label=\"%v\";%v];\n", object.GUID(), object.OneAttr(activedirectory.Name), formatting)
}
fmt.Fprintln(df, "")
for _, connection := range pg.Connections {
Expand Down Expand Up @@ -61,7 +62,7 @@ type CytoFlatElement struct {
func GenerateCytoscapeJS(pg engine.PwnGraph, alldetails bool) (CytoGraph, error) {
g := CytoGraph{
FormatVersion: "1.0",
GeneratedBy: version.VersionStringShort(),
GeneratedBy: version.ProgramVersionShort(),
TargetCytoscapeJSVersion: "~3.0",
Data: CytoGraphData{
SharedName: "adalanche analysis data",
Expand Down Expand Up @@ -102,7 +103,7 @@ func GenerateCytoscapeJS(pg engine.PwnGraph, alldetails bool) (CytoGraph, error)
"type": object.Type().String(),
}}

if uac, ok := object.OneAttrRaw(engine.UserAccountControl).(uint64); ok && uac&engine.UAC_ACCOUNTDISABLE != 0 {
if uac, ok := object.OneAttrRaw(activedirectory.UserAccountControl).(uint64); ok && uac&engine.UAC_ACCOUNTDISABLE != 0 {
newnode.Data["_disabled"] = true
}

Expand Down
23 changes: 12 additions & 11 deletions modules/analyze/webservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/lkarlslund/adalanche/modules/engine"
"github.com/lkarlslund/adalanche/modules/integrations/activedirectory"
"github.com/lkarlslund/adalanche/modules/ldapquery"
"github.com/lkarlslund/adalanche/modules/util"
"github.com/lkarlslund/adalanche/modules/version"
Expand Down Expand Up @@ -125,23 +126,23 @@ func webservice(bind string, quit chan bool, objs *engine.Objects) (*http.Server
}
o, found = objs.FindByID(uint32(id))
case "dn", "distinguishedname":
o, found = objs.Find(engine.DistinguishedName, engine.AttributeValueString(vars["id"]))
o, found = objs.Find(activedirectory.DistinguishedName, engine.AttributeValueString(vars["id"]))
case "sid":
sid, err := windowssecurity.SIDFromString(vars["id"])
if err != nil {
w.WriteHeader(400) // bad request
w.Write([]byte(err.Error()))
return
}
o, found = objs.Find(engine.ObjectSid, engine.AttributeValueSID(sid))
o, found = objs.Find(activedirectory.ObjectSid, engine.AttributeValueSID(sid))
case "guid":
u, err := uuid.FromString(vars["id"])
if err != nil {
w.WriteHeader(400) // bad request
w.Write([]byte(err.Error()))
return
}
o, found = objs.Find(engine.ObjectGUID, engine.AttributeValueGUID(u))
o, found = objs.Find(activedirectory.ObjectGUID, engine.AttributeValueGUID(u))
}
if !found {
w.WriteHeader(404) // bad request
Expand Down Expand Up @@ -747,13 +748,13 @@ func webservice(bind string, quit chan bool, objs *engine.Objects) (*http.Server
object.OneAttrString(engine.MetaWorkstation) != "1" &&
object.OneAttrString(engine.MetaServer) != "1" &&
object.OneAttrString(engine.MetaAccountDisabled) != "1" {
lastlogin, _ := object.AttrTimestamp(engine.LastLogon)
lastlogints, _ := object.AttrTimestamp(engine.LastLogonTimestamp)
last, _ := object.AttrTimestamp(engine.PwdLastSet)
lastlogin, _ := object.AttrTimestamp(activedirectory.LastLogon)
lastlogints, _ := object.AttrTimestamp(activedirectory.LastLogonTimestamp)
last, _ := object.AttrTimestamp(activedirectory.PwdLastSet)

expires, _ := object.AttrTimestamp(engine.AccountExpires)
created, _ := object.AttrTimestamp(engine.WhenCreated)
changed, _ := object.AttrTimestamp(engine.WhenChanged)
expires, _ := object.AttrTimestamp(activedirectory.AccountExpires)
created, _ := object.AttrTimestamp(activedirectory.WhenCreated)
changed, _ := object.AttrTimestamp(activedirectory.WhenChanged)

// log.Debug().Msgf("%v last pwd %v / login %v / logints %v / expires %v / changed %v / created %v", object.DN(), last, lastlogin, lastlogints, expires, changed, created)

Expand Down Expand Up @@ -829,9 +830,9 @@ func webservice(bind string, quit chan bool, objs *engine.Objects) (*http.Server
}

type treeData struct {
ID uint32 `json:"id"`
Label string `json:"text"`
Type string `json:"type,omitempty"`
ID uint32 `json:"id"`
Children bool `json:"children,omitempty"`
}

Expand Down Expand Up @@ -859,7 +860,7 @@ func webservice(bind string, quit chan bool, objs *engine.Objects) (*http.Server
Statistics map[string]int `json:"statistics"`
}
result.Adalanche = make(map[string]string)
result.Adalanche["shortversion"] = version.VersionStringShort()[len(version.Program)+1:]
result.Adalanche["shortversion"] = version.VersionStringShort()
result.Adalanche["program"] = version.Program
result.Adalanche["version"] = version.Version
result.Adalanche["commit"] = version.Commit
Expand Down
2 changes: 1 addition & 1 deletion modules/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
Use: "version",
Short: "Show adalanche version information",
RunE: func(cmd *cobra.Command, args []string) error {
log.Info().Msg(version.VersionStringShort())
log.Info().Msg(version.ProgramVersionShort())
return nil
},
}
Expand Down
16 changes: 8 additions & 8 deletions modules/engine/analyzeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ func NewAnalyzeObjectsOptions() AnalyzeObjectsOptions {
type AnalyzeObjectsOptions struct {
IncludeObjects *Objects
ExcludeObjects *Objects
MethodsF PwnMethodBitmap
MethodsM PwnMethodBitmap
MethodsL PwnMethodBitmap
ObjectTypesF []ObjectType
ObjectTypesM []ObjectType
ObjectTypesL []ObjectType
Reverse bool
Backlinks bool
MethodsL PwnMethodBitmap
MethodsM PwnMethodBitmap
MethodsF PwnMethodBitmap
MaxDepth int
MaxOutgoingConnections int
Reverse bool
Backlinks bool
MinProbability Probability
PruneIslands bool
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) (pg PwnGraph) {

// This map contains all the nodes that point to someone else. If you're in this map you're not an outer node
pointsatsomeone := make(map[*Object]struct{})
for pair, _ := range connectionsmap {
for pair := range connectionsmap {
pointsatsomeone[pair.Source] = struct{}{}
}

Expand Down Expand Up @@ -280,11 +280,11 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) (pg PwnGraph) {
if opts.PruneIslands || weremovedsomething {
// Find island nodes
pointedto := make(map[*Object]struct{})
for pair, _ := range connectionsmap {
for pair := range connectionsmap {
pointedto[pair.Source] = struct{}{}
pointedto[pair.Target] = struct{}{}
}
for node, _ := range implicatedobjectsmap {
for node := range implicatedobjectsmap {
if _, found := pointedto[node]; !found {
if _, found := opts.IncludeObjects.FindByID(node.ID()); opts.PruneIslands || !found {
delete(implicatedobjectsmap, node)
Expand Down
26 changes: 13 additions & 13 deletions modules/engine/attributenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ type AttributeNode interface {
ChildrenSlice() []AttributeAndValues
}

type AttributeValueWithChildren struct {
AttributeValue
data AttributeValueMap
}
// type AttributeValueWithChildren struct {
// AttributeValue
// data AttributeValueMap
// }

func (avwc AttributeValueWithChildren) Children() AttributeValueMap {
return nil
}
// func (avwc AttributeValueWithChildren) Children() AttributeValueMap {
// return nil
// }

func (avwc AttributeValueWithChildren) ChildrenLen() int {
return 0
}
// func (avwc AttributeValueWithChildren) ChildrenLen() int {
// return 0
// }

func (avwc AttributeValueWithChildren) ChildrenSlice() []AttributeAndValues {
return nil
}
// func (avwc AttributeValueWithChildren) ChildrenSlice() []AttributeAndValues {
// return nil
// }
96 changes: 20 additions & 76 deletions modules/engine/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var attributenames = make(map[string]Attribute)

type attributeinfo struct {
name string
multi bool // expected to have multi value
unique bool // requires unique value to be inserted into objects
merge bool // is usable to merge objects
tags []string
multi bool
unique bool
merge bool
}

var attributenums []attributeinfo
Expand All @@ -24,78 +24,23 @@ var attributepopularity []int
var attributesizes []int

var (
NonExistingAttribute = NewAttribute("*NON EXISTING ATTRIBUTE*")
DistinguishedName = NewAttribute("distinguishedName").Tag("AD")
ObjectClass = NewAttribute("objectClass").Tag("AD")
ObjectCategory = NewAttribute("objectCategory").Tag("AD")
ObjectCategorySimple = NewAttribute("objectCategorySimple")
StructuralObjectClass = NewAttribute("structuralObjectClass").Tag("AD")
NTSecurityDescriptor = NewAttribute("nTSecurityDescriptor").Tag("AD")
SAMAccountType = NewAttribute("sAMAccountType").Tag("AD")
GroupType = NewAttribute("groupType").Tag("AD")
MemberOf = NewAttribute("memberOf").Tag("AD")
AccountExpires = NewAttribute("accountExpires").Tag("AD")
RepsTo = NewAttribute("repsTo").Tag("AD")
InstanceType = NewAttribute("instanceType").Tag("AD")
ModifiedCount = NewAttribute("modifiedCount").Tag("AD")
MinPwdAge = NewAttribute("minPwdAge").Tag("AD")
MinPwdLength = NewAttribute("minPwdLength").Tag("AD")
PwdProperties = NewAttribute("pwdProperties").Tag("AD")
LockOutDuration = NewAttribute("lockoutDuration")
PwdHistoryLength = NewAttribute("pwdHistoryLength")
IsCriticalSystemObject = NewAttribute("isCriticalSystemObject").Tag("AD")
FSMORoleOwner = NewAttribute("fSMORoleOwner")
NTMixedDomain = NewAttribute("nTMixedDomain")
SystemFlags = NewAttribute("systemFlags")
PrimaryGroupID = NewAttribute("primaryGroupID").Tag("AD")
LogonCount = NewAttribute("logonCount")
UserAccountControl = NewAttribute("userAccountControl").Tag("AD")
LocalPolicyFlags = NewAttribute("localPolicyFlags")
CodePage = NewAttribute("codePage")
CountryCode = NewAttribute("countryCode")
OperatingSystem = NewAttribute("operatingSystem")
OperatingSystemHotfix = NewAttribute("operatingSystemHotfix")
OperatingSystemVersion = NewAttribute("operatingSystemVersion")
OperatingSystemServicePack = NewAttribute("operatingSystemServicePack")
AdminCount = NewAttribute("adminCount").Tag("AD")
LogonHours = NewAttribute("logonHours")
BadPwdCount = NewAttribute("badPwdCount")
GPCFileSysPath = NewAttribute("gPCFileSysPath").Tag("AD")
SchemaIDGUID = NewAttribute("schemaIDGUID").Tag("AD")
PossSuperiors = NewAttribute("possSuperiors")
SystemMayContain = NewAttribute("systemMayContain")
SystemMustContain = NewAttribute("systemMustContain")
ServicePrincipalName = NewAttribute("servicePrincipalName").Tag("AD")
Name = NewAttribute("name").Tag("AD")
DisplayName = NewAttribute("displayName").Tag("AD")
LDAPDisplayName = NewAttribute("lDAPDisplayName").Tag("AD") // Attribute-Schema
Description = NewAttribute("description").Tag("AD")
SAMAccountName = NewAttribute("sAMAccountName").Tag("AD")
ObjectSid = NewAttribute("objectSid").Tag("AD").Merge()
ObjectGUID = NewAttribute("objectGUID").Tag("AD").Merge()
PwdLastSet = NewAttribute("pwdLastSet").Tag("AD")
WhenCreated = NewAttribute("whenCreated")
WhenChanged = NewAttribute("whenChanged")
SIDHistory = NewAttribute("sIDHistory").Tag("AD")
LastLogon = NewAttribute("lastLogon")
LastLogonTimestamp = NewAttribute("lastLogonTimestamp")
MSDSGroupMSAMembership = NewAttribute("msDS-GroupMSAMembership").Tag("AD")
MSDSHostServiceAccount = NewAttribute("msDS-HostServiceAccount").Tag("AD")
MSDSHostServiceAccountBL = NewAttribute("msDS-HostServiceAccountBL").Tag("AD")
MSmcsAdmPwdExpirationTime = NewAttribute("ms-mcs-AdmPwdExpirationTime").Tag("AD") // LAPS password timeout
SecurityIdentifier = NewAttribute("securityIdentifier")
TrustDirection = NewAttribute("trustDirection")
TrustAttributes = NewAttribute("trustAttributes")
TrustPartner = NewAttribute("trustPartner")
DsHeuristics = NewAttribute("dsHeuristics").Tag("AD")
AttributeSecurityGUID = NewAttribute("attributeSecurityGUID").Tag("AD")
MSDSConsistencyGUID = NewAttribute("mS-DS-ConsistencyGuid")
RightsGUID = NewAttribute("rightsGUID").Tag("AD")
GPLink = NewAttribute("gPLink").Tag("AD")
GPOptions = NewAttribute("gPOptions").Tag("AD")
ScriptPath = NewAttribute("scriptPath").Tag("AD")
MSPKICertificateNameFlag = NewAttribute("msPKI-Certificate-Name-Flag").Tag("AD")
PKIExtendedUsage = NewAttribute("pKIExtendedKeyUsage").Tag("AD")
NonExistingAttribute = NewAttribute("*NON EXISTING ATTRIBUTE*")

DistinguishedName = NewAttribute("distinguishedName")
ObjectClass = NewAttribute("objectClass")
ObjectCategory = NewAttribute("objectCategory")
ObjectCategorySimple = NewAttribute("objectCategorySimple")
Name = NewAttribute("name")
DisplayName = NewAttribute("displayName")
LDAPDisplayName = NewAttribute("lDAPDisplayName")
Description = NewAttribute("description")
SAMAccountName = NewAttribute("sAMAccountName")
ObjectSid = NewAttribute("objectSid")
ObjectGUID = NewAttribute("objectGUID")
NTSecurityDescriptor = NewAttribute("nTSecurityDescriptor")
SchemaIDGUID = NewAttribute("schemaIDGUID")
RightsGUID = NewAttribute("rightsGUID")
AttributeSecurityGUID = NewAttribute("attributeSecurityGUID")

dummyflag = NewAttribute("dummyflag")
MAX_IMPORTED = dummyflag
Expand All @@ -107,7 +52,6 @@ var (

IPAddress = NewAttribute("IPAddress")
Hostname = NewAttribute("Hostname").Merge()
MACAddress = NewAttribute("MACAddress").Multi()
DownLevelLogonName = NewAttribute("DownLevelLogonName").Merge()
NetbiosDomain = NewAttribute("netbiosDomain") // Used to merge users with - if we only have a DOMAIN\USER type of info

Expand Down
4 changes: 2 additions & 2 deletions modules/engine/attributevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func CompareAttributeValues(a, b AttributeValue) bool {
case []byte:
nb, btype := braw.([]byte)
if btype {
return bytes.Compare(na, nb) == 0
return bytes.Equal(na, nb)
}
case windowssecurity.SID:
nb, btype := braw.(windowssecurity.SID)
Expand All @@ -46,8 +46,8 @@ func CompareAttributeValues(a, b AttributeValue) bool {
}

type AttributeAndValues struct {
Attribute
AttributeValues
Attribute
}

// AttributeValues can contain one or more values
Expand Down
4 changes: 2 additions & 2 deletions modules/engine/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Loader interface {
}

var (
UninterestedError = errors.New("Plugin is not interested in this file, try harder")
ErrUninterested = errors.New("plugin is not interested in this file, try harder")

loaders []Loader
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func Load(path string, cb ProgressCallbackFunc) ([]*Objects, error) {
switch fileerr {
case nil:
break loaderloop
case UninterestedError:
case ErrUninterested:
// loop, and try next loader
default:
log.Error().Msgf("Error from loader %v: %v", loader.Name(), fileerr)
Expand Down
Loading

0 comments on commit bc91a53

Please sign in to comment.