Skip to content

Commit

Permalink
updated the new enum output
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Jul 23, 2023
1 parent bd6da1e commit 06049fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
13 changes: 8 additions & 5 deletions cmd/amass/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ func processOutput(ctx context.Context, g *netmap.Graph, e *enum.Enumeration, ou
known := stringset.New()
defer known.Close()
// The function that obtains output from the enum and puts it on the channel
extract := func() {
for _, o := range NewOutput(ctx, g, e, known) {
extract := func(since time.Time) {
for _, o := range NewOutput(ctx, g, e, known, since) {
for _, ch := range outputs {
ch <- o
}
Expand All @@ -424,17 +424,20 @@ func processOutput(ctx context.Context, g *netmap.Graph, e *enum.Enumeration, ou

t := time.NewTimer(10 * time.Second)
defer t.Stop()
last := e.Config.CollectionStartTime
for {
select {
case <-ctx.Done():
extract()
extract(last)
return
case <-done:
extract()
extract(last)
return
case <-t.C:
extract()
next := time.Now()
extract(last)
t.Reset(10 * time.Second)
last = next
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions cmd/amass/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"golang.org/x/net/publicsuffix"
)

func NewOutput(ctx context.Context, g *netmap.Graph, e *enum.Enumeration, filter *stringset.Set) []string {
func NewOutput(ctx context.Context, g *netmap.Graph, e *enum.Enumeration, filter *stringset.Set, since time.Time) []string {
var output []string

// Make sure a filter has been created
Expand All @@ -32,26 +32,27 @@ func NewOutput(ctx context.Context, g *netmap.Graph, e *enum.Enumeration, filter
}

var assets []*types.Asset
qtime := e.Config.CollectionStartTime.UTC()
for _, atype := range []oam.AssetType{oam.FQDN, oam.IPAddress, oam.Netblock, oam.ASN, oam.RIROrg} {
if a, err := g.DB.FindByType(atype, qtime); err == nil {
if a, err := g.DB.FindByType(atype, since.UTC()); err == nil {
assets = append(assets, a...)
}
}

arrow := white("-->")
start := e.Config.CollectionStartTime.UTC()
for _, from := range assets {
fromstr := extractAssetName(from, qtime)
fromstr := extractAssetName(from)

if rels, err := g.DB.OutgoingRelations(from, qtime); err == nil {
if rels, err := g.DB.OutgoingRelations(from, start); err == nil {
for _, rel := range rels {
lineid := from.ID + rel.ID + rel.ToAsset.ID
if filter.Has(lineid) {
continue
}
if to, err := g.DB.FindById(rel.ToAsset.ID, qtime); err == nil {
tostr := extractAssetName(to, qtime)
if to, err := g.DB.FindById(rel.ToAsset.ID, start); err == nil {
tostr := extractAssetName(to)

output = append(output, fmt.Sprintf("%s %s %s %s %s", fromstr, "-->", magenta(rel.Type), "-->", tostr))
output = append(output, fmt.Sprintf("%s %s %s %s %s", fromstr, arrow, magenta(rel.Type), arrow, tostr))
filter.Insert(lineid)
}
}
Expand All @@ -61,7 +62,7 @@ func NewOutput(ctx context.Context, g *netmap.Graph, e *enum.Enumeration, filter
return output
}

func extractAssetName(a *types.Asset, since time.Time) string {
func extractAssetName(a *types.Asset) string {
var result string

switch a.Asset.AssetType() {
Expand Down
1 change: 1 addition & 0 deletions cmd/amass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var (
green = color.New(color.FgHiGreen).SprintFunc()
blue = color.New(color.FgHiBlue).SprintFunc()
magenta = color.New(color.FgHiMagenta).SprintFunc()
white = color.New(color.FgHiWhite).SprintFunc()
)

func commandUsage(msg string, cmdFlagSet *flag.FlagSet, errBuf *bytes.Buffer) {
Expand Down

0 comments on commit 06049fd

Please sign in to comment.