From 8c6361c66dc506fa120cf5f0f0ee544c24724a86 Mon Sep 17 00:00:00 2001 From: caffix Date: Sun, 10 Sep 2023 16:31:43 -0400 Subject: [PATCH] removed the db subcommand now found in oam_subs --- cmd/amass/db.go | 270 ---------------------------------------------- cmd/amass/help.go | 2 - cmd/amass/main.go | 60 +---------- 3 files changed, 1 insertion(+), 331 deletions(-) delete mode 100644 cmd/amass/db.go diff --git a/cmd/amass/db.go b/cmd/amass/db.go deleted file mode 100644 index d1b7bf33c..000000000 --- a/cmd/amass/db.go +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright © by Jeff Foley 2017-2023. All rights reserved. -// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. -// SPDX-License-Identifier: Apache-2.0 - -package main - -import ( - "bytes" - "context" - "flag" - "fmt" - "io" - "net" - "os" - "time" - - "github.com/caffix/netmap" - "github.com/caffix/stringset" - "github.com/fatih/color" - "github.com/owasp-amass/amass/v4/format" - "github.com/owasp-amass/amass/v4/requests" - "github.com/owasp-amass/config/config" - oam "github.com/owasp-amass/open-asset-model" - "github.com/owasp-amass/open-asset-model/network" -) - -const ( - dbUsageMsg = "db [options]" -) - -type dbArgs struct { - Domains *stringset.Set - Enum int - Options struct { - DemoMode bool - IPs bool - IPv4 bool - IPv6 bool - ASNTableSummary bool - DiscoveredNames bool - NoColor bool - ShowAll bool - Silent bool - } - Filepaths struct { - ConfigFile string - Directory string - Domains string - TermOut string - } -} - -func runDBCommand(clArgs []string) { - var args dbArgs - var help1, help2 bool - dbCommand := flag.NewFlagSet("db", flag.ContinueOnError) - - dbBuf := new(bytes.Buffer) - dbCommand.SetOutput(dbBuf) - args.Domains = stringset.New() - defer args.Domains.Close() - - dbCommand.BoolVar(&help1, "h", false, "Show the program usage message") - 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.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") - dbCommand.BoolVar(&args.Options.IPv6, "ipv6", false, "Show the IPv6 addresses for 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.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") - dbCommand.StringVar(&args.Filepaths.ConfigFile, "config", "", "Path to the YAML configuration file. Additional details below") - dbCommand.StringVar(&args.Filepaths.Directory, "dir", "", "Path to the directory containing the graph database") - dbCommand.StringVar(&args.Filepaths.Domains, "df", "", "Path to a file providing root domain names") - dbCommand.StringVar(&args.Filepaths.TermOut, "o", "", "Path to the text file containing terminal stdout/stderr") - - if len(clArgs) < 1 { - commandUsage(dbUsageMsg, dbCommand, dbBuf) - return - } - if err := dbCommand.Parse(clArgs); err != nil { - r.Fprintf(color.Error, "%v\n", err) - os.Exit(1) - } - if help1 || help2 { - commandUsage(dbUsageMsg, dbCommand, dbBuf) - return - } - if args.Options.NoColor { - color.NoColor = true - } - if args.Options.Silent { - color.Output = io.Discard - color.Error = io.Discard - } - if args.Options.IPs { - args.Options.IPv4 = true - args.Options.IPv6 = true - } - if args.Filepaths.Domains != "" { - list, err := config.GetListFromFile(args.Filepaths.Domains) - if err != nil { - r.Fprintf(color.Error, "Failed to parse the domain names file: %v\n", err) - return - } - args.Domains.InsertMany(list...) - } - - cfg := config.NewConfig() - // Check if a configuration file was provided, and if so, load the settings - if err := config.AcquireConfig(args.Filepaths.Directory, args.Filepaths.ConfigFile, cfg); err == nil { - if args.Filepaths.Directory == "" { - args.Filepaths.Directory = cfg.Dir - } - if args.Domains.Len() == 0 { - args.Domains.InsertMany(cfg.Domains()...) - } - } else if args.Filepaths.ConfigFile != "" { - r.Fprintf(color.Error, "Failed to load the configuration file: %v\n", err) - os.Exit(1) - } - - db := openGraphDatabase(args.Filepaths.Directory, cfg) - if db == nil { - r.Fprintln(color.Error, "Failed to connect with the database") - os.Exit(1) - } - - if args.Options.ShowAll { - args.Options.DiscoveredNames = true - args.Options.ASNTableSummary = true - } - if !args.Options.DiscoveredNames && !args.Options.ASNTableSummary { - commandUsage(dbUsageMsg, dbCommand, dbBuf) - return - } - - var asninfo bool - if args.Options.ASNTableSummary { - asninfo = true - } - - showEventData(&args, asninfo, db) -} - -func showEventData(args *dbArgs, asninfo bool, db *netmap.Graph) { - var total int - var err error - var outfile *os.File - domains := args.Domains.Slice() - - if args.Filepaths.TermOut != "" { - outfile, err = os.OpenFile(args.Filepaths.TermOut, os.O_WRONLY|os.O_CREATE, 0644) - if err != nil { - r.Fprintf(color.Error, "Failed to open the text output file: %v\n", err) - os.Exit(1) - } - defer func() { - _ = outfile.Sync() - _ = outfile.Close() - }() - _ = outfile.Truncate(0) - _, _ = outfile.Seek(0, 0) - } - - var cache *requests.ASNCache - if asninfo { - cache = requests.NewASNCache() - if err := fillCache(cache, db); err != nil { - r.Printf("Failed to populate the ASN cache: %v\n", err) - return - } - } - - asns := make(map[int]*format.ASNSummaryData) - for _, out := range getEventOutput(context.Background(), domains, asninfo, db, cache) { - if len(domains) > 0 && !domainNameInScope(out.Name, domains) { - continue - } - - if args.Options.IPv4 || args.Options.IPv6 { - out.Addresses = format.DesiredAddrTypes(out.Addresses, args.Options.IPv4, args.Options.IPv6) - } - - if l := len(out.Addresses); (args.Options.IPv4 || args.Options.IPv6) && l == 0 { - continue - } else if l > 0 { - format.UpdateSummaryData(out, asns) - } - - total++ - name, ips := format.OutputLineParts(out, args.Options.IPv4 || args.Options.IPv6, args.Options.DemoMode) - if ips != "" { - ips = " " + ips - } - - if args.Options.DiscoveredNames { - var written bool - if outfile != nil { - fmt.Fprintf(outfile, "%s%s\n", name, ips) - written = true - } - if !written { - fmt.Fprintf(color.Output, "%s%s\n", green(name), yellow(ips)) - } - } - } - - if total == 0 { - r.Println("No names were discovered") - return - } - if args.Options.ASNTableSummary { - var out io.Writer - status := color.NoColor - - if outfile != nil { - out = outfile - color.NoColor = true - } else if args.Options.ShowAll { - out = color.Error - } else { - out = color.Output - } - - format.FprintEnumerationSummary(out, total, asns, args.Options.DemoMode) - color.NoColor = status - } -} - -func fillCache(cache *requests.ASNCache, db *netmap.Graph) error { - start := time.Now().Add(-730 * time.Hour) - assets, err := db.DB.FindByType(oam.ASN, start) - if err != nil { - return err - } - - for _, a := range assets { - as, ok := a.Asset.(network.AutonomousSystem) - if !ok { - continue - } - - desc := db.ReadASDescription(context.Background(), as.Number, start) - if desc == "" { - continue - } - - for _, prefix := range db.ReadASPrefixes(context.Background(), as.Number, start) { - first, cidr, err := net.ParseCIDR(prefix) - if err != nil { - continue - } - if ones, _ := cidr.Mask.Size(); ones == 0 { - continue - } - - cache.Update(&requests.ASNRequest{ - Address: first.String(), - ASN: as.Number, - Prefix: cidr.String(), - Description: desc, - }) - } - } - return nil -} diff --git a/cmd/amass/help.go b/cmd/amass/help.go index 1badd979f..924a0f020 100644 --- a/cmd/amass/help.go +++ b/cmd/amass/help.go @@ -19,8 +19,6 @@ func runHelpCommand(clArgs []string) { return } switch clArgs[0] { - case "db": - runDBCommand(help) case "enum": runEnumCommand(help) case "intel": diff --git a/cmd/amass/main.go b/cmd/amass/main.go index 832ccfedf..85bb0b9e2 100644 --- a/cmd/amass/main.go +++ b/cmd/amass/main.go @@ -24,30 +24,23 @@ package main import ( "bytes" - "context" "flag" "fmt" "net" "os" "path" - "path/filepath" - "strings" - "time" - "github.com/caffix/netmap" "github.com/caffix/service" - "github.com/caffix/stringset" "github.com/fatih/color" "github.com/owasp-amass/amass/v4/datasrcs" "github.com/owasp-amass/amass/v4/format" amassnet "github.com/owasp-amass/amass/v4/net" - "github.com/owasp-amass/amass/v4/requests" "github.com/owasp-amass/amass/v4/systems" "github.com/owasp-amass/config/config" ) const ( - mainUsageMsg = "intel|enum|db [options]" + mainUsageMsg = "intel|enum [options]" exampleConfigFileURL = "https://github.com/owasp-amass/amass/blob/master/examples/config.yaml" userGuideURL = "https://github.com/owasp-amass/amass/blob/master/doc/user_guide.md" tutorialURL = "https://github.com/owasp-amass/amass/blob/master/doc/tutorial.md" @@ -76,7 +69,6 @@ func commandUsage(msg string, cmdFlagSet *flag.FlagSet, errBuf *bytes.Buffer) { g.Fprintf(color.Error, "\nSubcommands: \n\n") g.Fprintf(color.Error, "\t%-11s - Discover targets for enumerations\n", "amass intel") g.Fprintf(color.Error, "\t%-11s - Perform enumerations and network mapping\n", "amass enum") - g.Fprintf(color.Error, "\t%-11s - Manipulate the Amass graph database\n", "amass db") } g.Fprintln(color.Error) @@ -114,8 +106,6 @@ func main() { } switch os.Args[1] { - case "db": - runDBCommand(os.Args[2:]) case "enum": runEnumCommand(os.Args[2:]) case "intel": @@ -190,54 +180,6 @@ func createOutputDirectory(cfg *config.Config) { } } -func openGraphDatabase(dir string, cfg *config.Config) *netmap.Graph { - // Add the local database settings to the configuration - cfg.GraphDBs = append(cfg.GraphDBs, cfg.LocalDatabaseSettings(cfg.GraphDBs)) - - for _, db := range cfg.GraphDBs { - if db.Primary { - var g *netmap.Graph - - if db.System == "local" { - g = netmap.NewGraph(db.System, filepath.Join(config.OutputDirectory(cfg.Dir), "amass.sqlite"), db.Options) - } else { - connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s", db.Host, db.Port, db.Username, db.Password, db.DBName) - g = netmap.NewGraph(db.System, connStr, db.Options) - } - - if g != nil { - return g - } - break - } - } - - return netmap.NewGraph("memory", "", "") -} - -func getEventOutput(ctx context.Context, domains []string, asninfo bool, db *netmap.Graph, cache *requests.ASNCache) []*requests.Output { - filter := stringset.New() - defer filter.Close() - - return EventOutput(ctx, db, domains, time.Time{}, filter, asninfo, cache) -} - -func domainNameInScope(name string, scope []string) bool { - var discovered bool - - n := strings.ToLower(strings.TrimSpace(name)) - for _, d := range scope { - d = strings.ToLower(d) - - if n == d || strings.HasSuffix(n, "."+d) { - discovered = true - break - } - } - - return discovered -} - func assignNetInterface(iface *net.Interface) error { addrs, err := iface.Addrs() if err != nil {