@@ -25,6 +25,7 @@ package main
2525import (
2626 "bytes"
2727 "flag"
28+ "fmt"
2829 "io"
2930 "os"
3031 "path"
@@ -38,6 +39,7 @@ import (
3839 assetdb "github.com/owasp-amass/asset-db"
3940 dbt "github.com/owasp-amass/asset-db/types"
4041 "github.com/owasp-amass/open-asset-model/domain"
42+ oamreg "github.com/owasp-amass/open-asset-model/registration"
4143)
4244
4345const (
@@ -61,7 +63,7 @@ type assocArgs struct {
6163
6264func main () {
6365 var args assocArgs
64- var help1 , help2 bool
66+ var help1 , help2 , verbose bool
6567 assocCommand := flag .NewFlagSet ("assoc" , flag .ContinueOnError )
6668
6769 args .Domains = stringset .New ()
@@ -72,6 +74,7 @@ func main() {
7274
7375 assocCommand .BoolVar (& help1 , "h" , false , "Show the program usage message" )
7476 assocCommand .BoolVar (& help2 , "help" , false , "Show the program usage message" )
77+ assocCommand .BoolVar (& verbose , "v" , false , "Show additional information about the associated assets" )
7578 assocCommand .Var (args .Domains , "d" , "Domain names separated by commas (can be used multiple times)" )
7679 assocCommand .StringVar (& args .Since , "since" , "" , "Exclude all assets discovered before (format: " + timeFormat + ")" )
7780 assocCommand .BoolVar (& args .Options .NoColor , "nocolor" , false , "Disable colorized output" )
@@ -150,19 +153,71 @@ func main() {
150153
151154 for _ , name := range args .Domains .Slice () {
152155 for _ , assoc := range getAssociations (name , start , db ) {
153- afmt .G .Fprintln (color .Output , assoc )
156+ var rel string
157+
158+ switch v := assoc .Asset .(type ) {
159+ case * oamreg.DomainRecord :
160+ rel = "registrant_contact"
161+ afmt .G .Fprintln (color .Output , v .Domain )
162+ if verbose {
163+ fmt .Fprintf (color .Output , "%s%s\n %s%s\n " , afmt .Blue ("Name: " ),
164+ afmt .Green (v .Name ), afmt .Blue ("Expiration: " ), afmt .Green (v .ExpirationDate ))
165+ }
166+ case * oamreg.AutnumRecord :
167+ rel = "registrant"
168+ afmt .G .Fprintln (color .Output , v .Handle )
169+ if verbose {
170+ fmt .Fprintf (color .Output , "%s%s\n %s%s\n %s%s\n " , afmt .Blue ("Name: " ), afmt .Green (v .Name ),
171+ afmt .Blue ("Status: " ), afmt .Green (v .Status [0 ]), afmt .Blue ("Updated: " ), afmt .Green (v .UpdatedDate ))
172+ }
173+ case * oamreg.IPNetRecord :
174+ rel = "registrant"
175+ afmt .G .Fprintln (color .Output , v .CIDR .String ())
176+ if verbose {
177+ fmt .Fprintf (color .Output , "%s%s\n %s%s\n %s%s\n " , afmt .Blue ("Name: " ), afmt .Green (v .Name ),
178+ afmt .Blue ("Status: " ), afmt .Green (v .Status [0 ]), afmt .Blue ("Updated: " ), afmt .Green (v .UpdatedDate ))
179+ }
180+ }
181+
182+ if verbose {
183+ printContactInfo (assoc , rel , start , db )
184+ }
185+ }
186+ }
187+ }
188+
189+ func printContactInfo (assoc * dbt.Asset , regrel string , since time.Time , db * assetdb.AssetDB ) {
190+ var contact * dbt.Asset
191+ if rels , err := db .OutgoingRelations (assoc , since , regrel ); err == nil && len (rels ) > 0 {
192+ if a , err := db .FindById (rels [0 ].ToAsset .ID , since ); err == nil && a != nil {
193+ contact = a
194+ }
195+ }
196+ if contact == nil {
197+ return
198+ }
199+
200+ for _ , out := range []string {"person" , "organization" , "location" , "phone" , "email" , "url" } {
201+ if rels , err := db .OutgoingRelations (contact , since , out ); err == nil && len (rels ) > 0 {
202+ for _ , rel := range rels {
203+ if a , err := db .FindById (rel .ToAsset .ID , since ); err == nil && a != nil {
204+ fmt .Fprintf (color .Output , "%s%s%s\n " ,
205+ afmt .Blue (string (a .Asset .AssetType ())), afmt .Blue (": " ), afmt .Green (a .Asset .Key ()))
206+ }
207+ }
154208 }
155209 }
156210}
157211
158- func getAssociations (name string , since time.Time , db * assetdb.AssetDB ) []string {
212+ func getAssociations (name string , since time.Time , db * assetdb.AssetDB ) []* dbt. Asset {
159213 if ! since .IsZero () {
160214 since = since .UTC ()
161215 }
162216
217+ var results []* dbt.Asset
163218 fqdns , err := db .FindByContent (& domain.FQDN {Name : name }, since )
164219 if err != nil || len (fqdns ) == 0 {
165- return [] string {}
220+ return results
166221 }
167222
168223 var assets []* dbt.Asset
@@ -183,7 +238,6 @@ func getAssociations(name string, since time.Time, db *assetdb.AssetDB) []string
183238 set .Insert (asset .ID )
184239 }
185240
186- var results []string
187241 for findings := assets ; len (findings ) > 0 ; {
188242 assets = findings
189243 findings = []* dbt.Asset {}
@@ -199,7 +253,7 @@ func getAssociations(name string, since time.Time, db *assetdb.AssetDB) []string
199253 if ! set .Has (asset .ID ) {
200254 set .Insert (asset .ID )
201255 findings = append (findings , asset )
202- results = append (results , asset . Asset . Key () )
256+ results = append (results , asset )
203257 }
204258 }
205259 }
0 commit comments