-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first pass towards making the tool a launcher and client to the engine
- Loading branch information
Showing
142 changed files
with
521 additions
and
15,308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// 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" | ||
"flag" | ||
"io" | ||
"os" | ||
|
||
"github.com/caffix/stringset" | ||
"github.com/fatih/color" | ||
"github.com/owasp-amass/config/config" | ||
) | ||
|
||
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) | ||
} | ||
|
||
} |
Oops, something went wrong.