Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -search and -addresses flags to the db subcommand options #666

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions cmd/amass/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net"
"os"
"strconv"
"strings"

"github.com/OWASP/Amass/v3/config"
"github.com/OWASP/Amass/v3/datasrcs"
Expand All @@ -31,18 +32,20 @@ const (
type dbArgs struct {
Domains stringset.Set
Enum int
Search string
Options struct {
DemoMode bool
IPs bool
IPv4 bool
IPv6 bool
ListEnumerations bool
ASNTableSummary bool
DiscoveredNames bool
NoColor bool
ShowAll bool
Silent bool
Sources bool
DemoMode bool
IPs bool
IPv4 bool
IPv6 bool
ListEnumerations bool
ASNTableSummary bool
DiscoveredNames bool
DiscoveredIPAddresses bool
NoColor bool
ShowAll bool
Silent bool
Sources bool
}
Filepaths struct {
ConfigFile string
Expand All @@ -66,6 +69,7 @@ func runDBCommand(clArgs []string) {
dbCommand.BoolVar(&help2, "help", false, "Show the program usage message")
dbCommand.Var(&args.Domains, "d", "Domain names separated by commas (can be used multiple times)")
dbCommand.IntVar(&args.Enum, "enum", 0, "Identify an enumeration via an index from the listing")
dbCommand.StringVar(&args.Search, "search", "", "Search results by keyword/name/IP")
dbCommand.BoolVar(&args.Options.DemoMode, "demo", false, "Censor output to make it suitable for demonstrations")
dbCommand.BoolVar(&args.Options.IPs, "ip", false, "Show the IP addresses for discovered names")
dbCommand.BoolVar(&args.Options.IPv4, "ipv4", false, "Show the IPv4 addresses for discovered names")
Expand All @@ -74,6 +78,7 @@ func runDBCommand(clArgs []string) {
dbCommand.BoolVar(&args.Options.Sources, "src", false, "Print data sources for the discovered names")
dbCommand.BoolVar(&args.Options.ASNTableSummary, "summary", false, "Print Just ASN Table Summary")
dbCommand.BoolVar(&args.Options.DiscoveredNames, "names", false, "Print Just Discovered Names")
dbCommand.BoolVar(&args.Options.DiscoveredIPAddresses, "addresses", false, "Print Just Discovered IP Addresses")
dbCommand.BoolVar(&args.Options.NoColor, "nocolor", false, "Disable colorized output")
dbCommand.BoolVar(&args.Options.ShowAll, "show", false, "Print the results for the enumeration index + domains provided")
dbCommand.BoolVar(&args.Options.Silent, "silent", false, "Disable all output during execution")
Expand Down Expand Up @@ -158,7 +163,7 @@ func runDBCommand(clArgs []string) {
args.Options.DiscoveredNames = true
args.Options.ASNTableSummary = true
}
if !args.Options.DiscoveredNames && !args.Options.ASNTableSummary {
if !args.Options.DiscoveredNames && !args.Options.DiscoveredIPAddresses && !args.Options.ASNTableSummary {
commandUsage(dbUsageMsg, dbCommand, dbBuf)
return
}
Expand Down Expand Up @@ -207,6 +212,7 @@ func listEvents(uuids []string, db *netmap.Graph) {
func showEventData(args *dbArgs, uuids []string, asninfo bool, db *netmap.Graph) {
var total int
var err error
var written bool
var outfile *os.File
var discovered []*requests.Output
domains := args.Domains.Slice()
Expand Down Expand Up @@ -236,26 +242,32 @@ func showEventData(args *dbArgs, uuids []string, asninfo bool, db *netmap.Graph)

tags := make(map[string]int)
asns := make(map[int]*format.ASNSummaryData)
addresses := stringset.New()
for _, out := range getEventOutput(uuids, asninfo, db, cache) {
if len(domains) > 0 && !domainNameInScope(out.Name, domains) {
continue
}

out.Addresses = format.DesiredAddrTypes(out.Addresses, args.Options.IPv4, args.Options.IPv6)
if l := len(out.Addresses); (args.Options.IPs || args.Options.IPv4 || args.Options.IPv6) && l == 0 {
if l := len(out.Addresses); (args.Options.DiscoveredIPAddresses || args.Options.IPs || args.Options.IPv4 || args.Options.IPv6) && l == 0 {
continue
} else if l > 0 {
total++
format.UpdateSummaryData(out, tags, asns)
}

source, name, ips := format.OutputLineParts(out, args.Options.Sources,
args.Options.IPs || args.Options.IPv4 || args.Options.IPv6, args.Options.DemoMode)
if ips != "" {
ips = " " + ips
args.Options.DiscoveredIPAddresses || args.Options.IPs || args.Options.IPv4 || args.Options.IPv6, args.Options.DemoMode)

if !strings.Contains(name, args.Search) && !strings.Contains(ips, args.Search) {
continue
}

if args.Options.DiscoveredNames {
if ips != "" {
ips = " " + ips
}

var written bool
if outfile != nil {
fmt.Fprintf(outfile, "%s%s%s\n", source, name, ips)
Expand All @@ -268,6 +280,17 @@ func showEventData(args *dbArgs, uuids []string, asninfo bool, db *netmap.Graph)
if !written {
fmt.Fprintf(color.Output, "%s%s%s\n", blue(source), green(name), yellow(ips))
}
} else if args.Options.DiscoveredIPAddresses {
addresses.InsertMany(strings.Split(ips, ",")...)
}
}
for _, address := range addresses.Slice() {
if outfile != nil {
fmt.Fprintf(outfile, "%s\n", address)
written = true
}
if !written {
fmt.Fprintf(color.Output, "%s\n", green(address))
}
}

Expand Down