Skip to content

Commit

Permalink
Improved GPO collection and merging into domains
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed May 17, 2022
1 parent b29519a commit 2db1c5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modules/integrations/activedirectory/analyze/gpoimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var usernamecpassword = regexp.MustCompile(`(?i)(runAs|userName)="(?P<username>[

func ImportGPOInfo(ginfo activedirectory.GPOdump, ao *engine.Objects) error {
if ginfo.DomainDN != "" {
ao.AddDefaultFlex(engine.UniqueSource, ginfo.DomainDN)
ao.AddDefaultFlex(engine.DomainPart, ginfo.DomainDN)
}

gpoobject, _ := ao.FindOrAdd(gPCFileSysPath, engine.AttributeValueString(ginfo.Path))
Expand Down
30 changes: 15 additions & 15 deletions modules/integrations/activedirectory/collect/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func Execute(cmd *cobra.Command, args []string) error {
datapath = idp.Value.String()
}

var domainContext, domainNetbios string
var gpostocollect []*activedirectory.RawObject

if *adexplorerfile != "" {
Expand All @@ -226,16 +225,6 @@ func Execute(cmd *cobra.Command, args []string) error {
return err
}

cp, _ := util.ParseBool(*collectgpos)
if *collectgpos == "auto" || cp {
for _, ro := range rao {
if _, found := ro.Attributes["gPCFileSysPath"]; found {
myro := ro
gpostocollect = append(gpostocollect, &myro)
}
}
}

var e *msgp.Writer

outfile, err := os.Create(filepath.Join(datapath, filepath.Base(*adexplorerfile)+".objects.msgp.lz4"))
Expand All @@ -262,6 +251,16 @@ func Execute(cmd *cobra.Command, args []string) error {
return fmt.Errorf("problem encoding LDAP object %v: %v", ro.DistinguishedName, err)
}
}

cp, _ := util.ParseBool(*collectgpos)
if *collectgpos == "auto" || cp {
for _, ro := range rao {
if _, found := ro.Attributes["gPCFileSysPath"]; found {
myro := ro
gpostocollect = append(gpostocollect, &myro)
}
}
}
} else {
// Active Directory dump directly from AD controller
ad := AD{
Expand Down Expand Up @@ -302,6 +301,8 @@ func Execute(cmd *cobra.Command, args []string) error {
return fmt.Errorf("expected 1 Active Directory RootDSE object, but got %v", len(rootdse))
}

var domainContext string

rd := rootdse[0]

namingcontexts := map[string]bool{}
Expand Down Expand Up @@ -332,8 +333,6 @@ func Execute(cmd *cobra.Command, args []string) error {
namingcontexts[schemaContext] = true
}

domainNetbios = util.ExtractNetbiosFromBase(domainContext)

var otherContexts []string
for context, used := range namingcontexts {
if !used {
Expand Down Expand Up @@ -441,6 +440,8 @@ func Execute(cmd *cobra.Command, args []string) error {
// Let's check if it this is a GPO and then add som fake attributes to represent it
if gpfsp, found := object.Attributes["gPCFileSysPath"]; found {

domainPart := util.ExtractDomainPart(object.DistinguishedName)

gpodisplayname := object.Attributes["displayName"]
gpoguid := object.Attributes["name"]
originalpath := gpfsp[0]
Expand Down Expand Up @@ -468,8 +469,7 @@ func Execute(cmd *cobra.Command, args []string) error {

gpoinfo.GPOinfo.GUID = gpuuid
gpoinfo.GPOinfo.Path = originalpath // The original path is kept, we don't care
gpoinfo.GPOinfo.DomainDN = domainContext
gpoinfo.GPOinfo.DomainNetbios = domainNetbios
gpoinfo.GPOinfo.DomainDN = domainPart

offset := len(gppath)
var filescollected int
Expand Down

0 comments on commit 2db1c5e

Please sign in to comment.