Skip to content

Commit

Permalink
updated the reverse whois support
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Jun 9, 2019
1 parent 9340dc6 commit e37b827
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
4 changes: 3 additions & 1 deletion amass/core/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const (
NewASNTopic = "amass:asn"
IPRequestTopic = "amass:iprequest"
IPInfoTopic = "amass:ipinfo"
NewWhoisTopic = "amass:whois"
WhoisRequestTopic = "amass:whoisreq"
NewWhoisTopic = "amass:whoisinfo"
)

// DNSAnswer is the type used by Amass to represent a DNS record.
Expand Down Expand Up @@ -86,6 +87,7 @@ type WhoisRequest struct {
Domain string
Company string
Email string
NewDomains []string
Tag string
Source string
}
Expand Down
56 changes: 55 additions & 1 deletion amass/intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,63 @@ func LookupASNsByName(s string) ([]*core.ASNRequest, error) {
}

// ReverseWhois returns domain names that are related to the domain provided
func ReverseWhois(domain string) ([]string, error) {
func (ic *IntelCollection) ReverseWhois(domain string) ([]string, error) {
var domains []string

collect := func(req *core.WhoisRequest) {
for _, d := range req.NewDomains {
domains = utils.UniqueAppend(domains, d)
}
}

ic.Bus.Subscribe(core.NewWhoisTopic, collect)
defer ic.Bus.Unsubscribe(core.NewWhoisTopic, collect)

srcs := sources.GetAllSources(ic.Config, ic.Bus)
// Select the data sources desired by the user
if len(ic.Config.DisabledDataSources) > 0 {
srcs = ic.Config.ExcludeDisabledDataSources(srcs)
}
// Keep only the data sources that successfully start
var keep []core.Service
for _, src := range srcs {
if err := src.Start(); err != nil {
src.Stop()
continue
}
keep = append(keep, src)
}
srcs = keep

// Send the whois request to the data sources
for _, src := range srcs {
src.SendWhoisRequest(&core.WhoisRequest{Domain: domain})
}

t := time.NewTicker(2 * time.Second)
loop:
for {
select {
case <-ic.Done:
break loop
case <-t.C:
done := true
for _, src := range srcs {
if src.IsActive() {
done = false
break
}
}
if done {
break loop
}
}
}
t.Stop()
// Stop all the data sources and wait for cleanup to finish
for _, src := range srcs {
src.Stop()
}
sort.Strings(domains)
return domains, nil
}
12 changes: 9 additions & 3 deletions amass/sources/viewdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewViewDNS(config *core.Config, bus *core.EventBus) *ViewDNS {
func (v *ViewDNS) OnStart() error {
v.BaseService.OnStart()

v.Bus().Subscribe(core.WhoisRequestTopic, v.SendWhoisRequest)
go v.processRequests()
return nil
}
Expand Down Expand Up @@ -114,14 +115,19 @@ func (v *ViewDNS) executeWhoisQuery(domain string) {
// Get the list of domain names discovered through the reverse DNS service
re := regexp.MustCompile("<tr><td>([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,61}[a-zA-Z0-9]{1}[.]{1}[a-zA-Z0-9-]+)</td><td>")
subs := re.FindAllStringSubmatch(table, -1)

var matches []string
for _, match := range subs {
sub := match[1]
if sub == "" {
continue
if sub != "" {
matches = utils.UniqueAppend(matches, strings.TrimSpace(sub))
}
}

if len(matches) > 0 {
v.Bus().Publish(core.NewWhoisTopic, &core.WhoisRequest{
Domain: strings.TrimSpace(sub),
Domain: domain,
NewDomains: matches,
Tag: v.SourceType,
Source: v.String(),
})
Expand Down
10 changes: 8 additions & 2 deletions cmd/amass/intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,23 @@ func runIntelCommand(clArgs []string) {
}

if args.Options.ReverseWhois {
var all []string

for _, domain := range args.Domains {
domains, err := amass.ReverseWhois(domain)
domains, err := intel.ReverseWhois(domain)
if err != nil {
continue
}
for _, d := range domains {
if name := strings.TrimSpace(d); name != "" {
g.Println(name)
all = utils.UniqueAppend(all, name)
}
}
}

for _, d := range all {
g.Println(d)
}
return
}

Expand Down

0 comments on commit e37b827

Please sign in to comment.