Skip to content

Commit

Permalink
enumerations use the graph db as a data source
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Feb 24, 2019
1 parent 944d714 commit 46c8b49
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
30 changes: 30 additions & 0 deletions amass/amass.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func (e *Enumeration) Start() error {
}
}

// Use all previously discovered names that are in scope
go e.submitKnownNames()

var wg sync.WaitGroup
wg.Add(2)
go e.checkForOutput(&wg)
Expand Down Expand Up @@ -190,6 +193,33 @@ loop:
return nil
}

func (e *Enumeration) submitKnownNames() {
for _, enum := range e.Graph.EnumerationList() {
var found bool

for _, domain := range e.Graph.EnumerationDomains(enum) {
if e.Config.IsDomainInScope(domain) {
found = true
break
}
}
if !found {
continue
}

for _, o := range e.Graph.GetOutput(enum, true) {
if e.Config.IsDomainInScope(o.Name) {
e.Bus.Publish(core.NewNameTopic, &core.Request{
Name: o.Name,
Domain: o.Domain,
Tag: o.Tag,
Source: o.Source,
})
}
}
}
}

// DNSQueriesPerSec returns the number of DNS queries the enumeration has performed per second.
func (e *Enumeration) DNSQueriesPerSec() int {
e.metricsLock.RLock()
Expand Down
14 changes: 1 addition & 13 deletions amass/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import (
"github.com/miekg/dns"
)

const (
// ResolutionTimeout is the maximum time spent retrying a resolution request.
ResolutionTimeout time.Duration = 30 * time.Second
)

var (
// Public & free DNS servers
publicResolvers = []string{
Expand Down Expand Up @@ -261,7 +256,7 @@ func (r *resolver) processMessage(msg *dns.Msg) {
// Check that the query was successful
if msg.Rcode != dns.RcodeSuccess {
var again bool
if msg.Rcode == dns.RcodeRefused {
if msg.Rcode == dns.RcodeRefused || msg.Rcode == dns.RcodeServerFailure {
again = true
}
r.returnRequest(req, &resolveResult{
Expand Down Expand Up @@ -453,19 +448,12 @@ func Resolve(name, qtype string) ([]core.DNSAnswer, error) {
}

var again bool
var attempts int
started := time.Now()
var ans []core.DNSAnswer
for {
ans, again, err = nextResolver().resolve(name, qt)
if !again {
break
}

attempts++
if attempts > 10 && time.Now().After(started.Add(ResolutionTimeout)) {
break
}
}
return ans, err
}
Expand Down
33 changes: 21 additions & 12 deletions cmd/amass.tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ func main() {
g.Fprintf(color.Error, "Usage: %s [options] -d domain\n\n", path.Base(os.Args[0]))
flag.PrintDefaults()
g.Fprintln(color.Error, defaultBuf.String())
os.Exit(1)
}
flag.Var(&domains, "d", "Domain names separated by commas (can be used multiple times)")
flag.Parse()

// Some input validation
if *help || len(os.Args) == 1 {
flag.Usage()
return
}
if *vprint {
fmt.Fprintf(color.Error, "version %s\n", amass.Version)
return
os.Exit(1)
}
if len(domains) == 0 {
r.Fprintln(color.Error, "No root domain names were provided")
return
os.Exit(1)
}
if *startStr != "" && (*last != 2 || *all) {
r.Fprintln(color.Error, "The start flag cannot be used with the last or all flags")
return
os.Exit(1)
}

var err error
Expand All @@ -86,7 +86,7 @@ func main() {
start, err = time.Parse(timeFormat, *startStr)
if err != nil {
r.Fprintf(color.Error, "%s is not in the correct format: %s\n", *startStr, timeFormat)
return
os.Exit(1)
}
}

Expand All @@ -95,17 +95,17 @@ func main() {
if *dir == "" {
if finfo, err := os.Stat(handlers.DefaultGraphDBDirectory); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
return
os.Exit(1)
}
} else if finfo, err := os.Stat(*dir); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
return
os.Exit(1)
}

graph := handlers.NewGraph(*dir)
if graph == nil {
r.Fprintln(color.Error, "Failed to open the graph database")
return
os.Exit(1)
}

var enums []string
Expand Down Expand Up @@ -134,7 +134,7 @@ func main() {
} else { // Or the number of enumerations from the end of the timeline
if len(enums) < *last {
r.Fprintf(color.Error, "%d enumerations are not available\n", *last)
return
os.Exit(1)
}
if *all == false {
begin = len(enums) - *last
Expand All @@ -158,11 +158,20 @@ func main() {
prev = enum
continue
}

fmt.Fprintf(color.Output, "%s\t%s%s%s\n%s\t%s%s%s\n\n", blue("Between"),
if i != 1 {
fmt.Println()
}
for i := 0; i < 8; i++ {
b.Fprint(color.Output, "----------")
}
fmt.Println()
fmt.Fprintf(color.Output, "%s\t%s%s%s\n%s\t%s%s%s\n", blue("Between"),
yellow(earliest[i-1].Format(timeFormat)), blue(" -> "), yellow(latest[i-1].Format(timeFormat)),
blue("and"), yellow(earliest[i].Format(timeFormat)), blue(" -> "), yellow(latest[i].Format(timeFormat)))

for i := 0; i < 8; i++ {
b.Fprint(color.Output, "----------")
}
fmt.Println()
out1 := getEnumDataInScope(domains[0], prev, graph)
out2 := getEnumDataInScope(domains[0], enum, graph)
for _, d := range diffEnumOutput(domains[0], out1, out2) {
Expand Down

0 comments on commit 46c8b49

Please sign in to comment.