diff --git a/README.md b/README.md index a4c31ded..fce02ecc 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,6 @@ OUTPUT: -json Write output in JSON lines Format CONFIGURATION: - -config string Config file -scan-all-ips Scan all the ips -scan-type, -s string Scan Type (s - SYN, c - CONNECT) (default "s") -source-ip string Source Ip diff --git a/v2/pkg/runner/banners.go b/v2/pkg/runner/banners.go index cc023bda..d7a6f346 100644 --- a/v2/pkg/runner/banners.go +++ b/v2/pkg/runner/banners.go @@ -1,11 +1,9 @@ package runner import ( - "io/ioutil" "net" "strings" - "github.com/projectdiscovery/fileutil" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/naabu/v2/pkg/scan" ) @@ -67,62 +65,3 @@ func showNetworkInterfaces() error { return nil } - -func (options *Options) writeDefaultConfig() { - dummyconfig := ` -# Number of retries -# retries: 1 -# Packets rate -# rate: 100 -# Timeout is the seconds to wait for ports to respond -# timeout: 5 -# Hosts are the host to find ports for -# host: -# - 10.10.10.10 -# Ports is the ports to use for enumeration -# ports: -# - 80 -# - 100 -# ExcludePorts is the list of ports to exclude from enumeration -# exclude-ports: -# - 20 -# - 30 -# Verify is used to check if the ports found were valid using CONNECT method -# verify: false -# NoProbe skips probes to discover alive hosts -# Ips or cidr to be excluded from the scan -# exclude-ips: -# - 1.1.1.1 -# - 2.2.2.2 -# Top ports list -# top-ports: 100 -# Attempts to run as root -# privileged: true -# Drop root privileges -# unprivileged: true -# Excludes ip of knows CDN ranges -# exclude-cdn: true -# SourceIP to use in TCP packets -# source-ip: 10.10.10.10 -# Interface to use for TCP packets -# interface: eth0 -# WarmUpTime between scan phases -# warm-up-time: 2 -# nmap command to invoke after scanning -# nmap: nmap -sV -` - configFile, err := getDefaultConfigFile() - if err != nil { - gologger.Warning().Msgf("Could not get default configuration file: %s\n", err) - } - if fileutil.FileExists(configFile) { - return - } - - err = ioutil.WriteFile(configFile, []byte(dummyconfig), 0755) - if err != nil { - gologger.Warning().Msgf("Could not write configuration file to %s: %s\n", configFile, err) - return - } - gologger.Info().Msgf("Configuration file saved to %s\n", configFile) -} diff --git a/v2/pkg/runner/config.go b/v2/pkg/runner/config.go deleted file mode 100644 index 126f742d..00000000 --- a/v2/pkg/runner/config.go +++ /dev/null @@ -1,108 +0,0 @@ -package runner - -import ( - "os" - "path" - - "gopkg.in/yaml.v3" -) - -const ConfigDefaultFilename = "naabu.conf" - -// ConfigFile contains the fields stored in the configuration file -type ConfigFile struct { - // Verify is used to check if the ports found were valid using CONNECT method - Verify bool `yaml:"verify,omitempty"` - // Ping uses ping probes to discover fastest active host and discover dead hosts - Ping bool `yaml:"ping,omitempty"` - // Excludes ip of knows CDN ranges - ExcludeCDN bool `yaml:"exclude-cdn,omitempty"` - // Retries is the number of retries for the port - Retries int `yaml:"retries,omitempty"` - // Rate is the rate of port scan requests - Rate int `yaml:"rate,omitempty"` - // Timeout is the seconds to wait for ports to respond - Timeout int `yaml:"timeout,omitempty"` - // WarmUpTime between scan phases - WarmUpTime int `yaml:"warm-up-time,omitempty"` - // Top ports list - TopPorts string `yaml:"top-ports,omitempty"` - // SourceIP to use in TCP packets - SourceIP string `yaml:"source-ip,omitempty"` - // Interface to use for TCP packets - Interface string `yaml:"interface,omitempty"` - // NMapCommand to invoke after scanning - NMapCommand string `yaml:"nmap,omitempty"` - // Hosts are the host to find ports for - Host []string `yaml:"host,omitempty"` - // Ports is the ports to use for enumeration - Ports []string `yaml:"ports,omitempty"` - // ExcludePorts is the list of ports to exclude from enumeration - ExcludePorts []string `yaml:"exclude-ports,omitempty"` - // Ips or cidr to be excluded from the scan - ExcludeIps []string `yaml:"exclude-ips,omitempty"` -} - -// GetConfigDirectory gets the subfinder config directory for a user -func GetConfigDirectory() (string, error) { - var config string - - directory, err := os.UserHomeDir() - if err != nil { - return config, err - } - config = directory + "/.config/naabu" - - // Create All directory for naabu even if they exist - err = os.MkdirAll(config, os.ModePerm) - if err != nil { - return config, err - } - - return config, nil -} - -// CheckConfigExists checks if the config file exists in the given path -func CheckConfigExists(configPath string) bool { - if _, err := os.Stat(configPath); err == nil { - return true - } else if os.IsNotExist(err) { - return false - } - return false -} - -// MarshalWrite writes the marshaled yaml config to disk -func (c *ConfigFile) MarshalWrite(file string) error { - f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE, 0755) - if err != nil { - return err - } - - // Indent the spaces too - enc := yaml.NewEncoder(f) - err = enc.Encode(&c) - f.Close() - return err -} - -// UnmarshalRead reads the unmarshalled config yaml file from disk -func UnmarshalRead(file string) (ConfigFile, error) { - config := ConfigFile{} - - f, err := os.Open(file) - if err != nil { - return config, err - } - err = yaml.NewDecoder(f).Decode(&config) - f.Close() - return config, err -} - -func getDefaultConfigFile() (string, error) { - directory, err := GetConfigDirectory() - if err != nil { - return "", err - } - return path.Join(directory, ConfigDefaultFilename), nil -} diff --git a/v2/pkg/runner/ips.go b/v2/pkg/runner/ips.go index 4ff1d928..68f71707 100644 --- a/v2/pkg/runner/ips.go +++ b/v2/pkg/runner/ips.go @@ -25,16 +25,6 @@ func parseExcludedIps(options *Options) ([]string, error) { } } - if options.config != nil { - for _, excludeIP := range options.config.ExcludeIps { - for _, ip := range strings.Split(excludeIP, ",") { - if isIpOrCidr(ip) { - excludedIps = append(excludedIps, ip) - } - } - } - } - return excludedIps, nil } diff --git a/v2/pkg/runner/nmap.go b/v2/pkg/runner/nmap.go index 63f581bc..fd5f2ce0 100644 --- a/v2/pkg/runner/nmap.go +++ b/v2/pkg/runner/nmap.go @@ -13,10 +13,6 @@ func (r *Runner) handleNmap() { // command from CLI command := r.options.NmapCLI hasCLI := r.options.NmapCLI != "" - // If empty load the one from config file - if command == "" && r.options.config != nil { - command = r.options.config.NMapCommand - } // If at least one is defined handle it if command != "" { args := strings.Split(command, " ") diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 33277751..c07c4a25 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -47,7 +47,6 @@ type Options struct { ScanType string // Scan Type Resolvers string // Resolvers (comma separated or file) baseResolvers []string - config *ConfigFile OnResult OnResultCallback // OnResult callback } @@ -62,18 +61,17 @@ func ParseOptions() *Options { createGroup(flagSet, "input", "Input", flagSet.StringVar(&options.Host, "host", "", "Host to scan ports for"), - flagSet.StringVarP(&options.HostsFile, "l", "list","", "File containing list of hosts to scan ports"), - flagSet.StringVarP(&options.ExcludeIps,"eh", "exclude-hosts", "", "Specifies a comma-separated list of targets to be excluded from the scan (ip, cidr)"), - flagSet.StringVarP(&options.ExcludeIpsFile,"ef", "exclude-file", "", "Specifies a newline-delimited file with targets to be excluded from the scan (ip, cidr)"), + flagSet.StringVarP(&options.HostsFile, "l", "list", "", "File containing list of hosts to scan ports"), + flagSet.StringVarP(&options.ExcludeIps, "eh", "exclude-hosts", "", "Specifies a comma-separated list of targets to be excluded from the scan (ip, cidr)"), + flagSet.StringVarP(&options.ExcludeIpsFile, "ef", "exclude-file", "", "Specifies a newline-delimited file with targets to be excluded from the scan (ip, cidr)"), ) createGroup(flagSet, "port", "Port", - flagSet.StringVarP(&options.Ports, "p", "port","", "Ports to scan (80, 80,443, 100-200"), - flagSet.StringVarP(&options.TopPorts,"tp", "top-ports", "", "Top Ports to scan (default top 100)"), - flagSet.StringVarP(&options.ExcludePorts,"ep", "exclude-ports", "", "Ports to exclude from scan"), - flagSet.StringVarP(&options.PortsFile,"pf", "ports-file", "", "File containing ports to scan for"), - flagSet.BoolVarP(&options.ExcludeCDN,"ec", "exclude-cdn", false, "Skip full port scans for CDNs (only checks for 80,443)"), - + flagSet.StringVarP(&options.Ports, "p", "port", "", "Ports to scan (80, 80,443, 100-200"), + flagSet.StringVarP(&options.TopPorts, "tp", "top-ports", "", "Top Ports to scan (default top 100)"), + flagSet.StringVarP(&options.ExcludePorts, "ep", "exclude-ports", "", "Ports to exclude from scan"), + flagSet.StringVarP(&options.PortsFile, "pf", "ports-file", "", "File containing ports to scan for"), + flagSet.BoolVarP(&options.ExcludeCDN, "ec", "exclude-cdn", false, "Skip full port scans for CDNs (only checks for 80,443)"), ) createGroup(flagSet, "rate-limit", "Rate-limit", @@ -82,17 +80,16 @@ func ParseOptions() *Options { ) createGroup(flagSet, "output", "Output", - flagSet.StringVarP(&options.Output,"output", "o", "", "File to write output to (optional)"), + flagSet.StringVarP(&options.Output, "output", "o", "", "File to write output to (optional)"), flagSet.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format"), ) createGroup(flagSet, "config", "Configuration", - flagSet.StringVar(&options.ConfigFile, "config", "", "Config file"), flagSet.BoolVar(&options.ScanAllIPS, "scan-all-ips", false, "Scan all the ips"), - flagSet.StringVarP(&options.ScanType,"s", "scan-type", SynScan, "Scan Type (s - SYN, c - CONNECT)"), + flagSet.StringVarP(&options.ScanType, "s", "scan-type", SynScan, "Scan Type (s - SYN, c - CONNECT)"), flagSet.StringVar(&options.SourceIP, "source-ip", "", "Source Ip"), - flagSet.BoolVarP(&options.InterfacesList,"il", "interface-list", false, "List available interfaces and public ip"), - flagSet.StringVarP(&options.Interface,"i", "interface", "", "Network Interface to use for port scan"), + flagSet.BoolVarP(&options.InterfacesList, "il", "interface-list", false, "List available interfaces and public ip"), + flagSet.StringVarP(&options.Interface, "i", "interface", "", "Network Interface to use for port scan"), flagSet.BoolVar(&options.Nmap, "nmap", false, "Invoke nmap scan on targets (nmap must be installed)"), flagSet.StringVar(&options.NmapCLI, "nmap-cli", "", "Nmap command line (invoked as COMMAND + TARGETS)"), flagSet.StringVar(&options.Resolvers, "r", "", "Custom resolvers to use to resolve DNS names (comma separated or from file)"), @@ -109,11 +106,10 @@ func ParseOptions() *Options { createGroup(flagSet, "debug", "Debug", flagSet.BoolVar(&options.Debug, "debug", false, "Enable debugging information"), flagSet.BoolVar(&options.Verbose, "v", false, "Show Verbose output"), - flagSet.BoolVarP(&options.NoColor, "nc","no-color", false, "Don't Use colors in output"), + flagSet.BoolVarP(&options.NoColor, "nc", "no-color", false, "Don't Use colors in output"), flagSet.BoolVar(&options.Silent, "silent", false, "Show found ports only in output"), flagSet.BoolVar(&options.Version, "version", false, "Show version of naabu"), flagSet.BoolVar(&options.EnableProgressBar, "stats", false, "Display stats of the running scan"), - ) _ = flagSet.Parse() @@ -127,9 +123,6 @@ func ParseOptions() *Options { // Show the user the banner showBanner() - // write default conf file template if it doesn't exist - options.writeDefaultConfig() - if options.Version { gologger.Info().Msgf("Current Version: %s\n", Version) os.Exit(0) @@ -144,17 +137,6 @@ func ParseOptions() *Options { os.Exit(0) } - // If a config file is provided, merge the options - if options.ConfigFile != "" { - options.MergeFromConfig(options.ConfigFile, false) - } else { - defaultConfigPath, err := getDefaultConfigFile() - if err != nil { - gologger.Error().Msgf("Program exiting: %s\n", err) - } - options.MergeFromConfig(defaultConfigPath, true) - } - // Validate the options passed by the user and if any // invalid options have been used, exit. err := options.validateOptions() @@ -179,44 +161,6 @@ func hasStdin() bool { return isPipedFromChrDev || isPipedFromFIFO } -func (options *Options) MergeFromConfig(configFileName string, ignoreError bool) { - configFile, err := UnmarshalRead(configFileName) - if err != nil { - if ignoreError { - gologger.Warning().Msgf("Could not read configuration file %s: %s\n", configFileName, err) - return - } - gologger.Fatal().Msgf("Could not read configuration file %s: %s\n", configFileName, err) - } - options.config = &configFile - - if configFile.Retries > 0 { - options.Retries = configFile.Retries - } - if configFile.Rate > 0 { - options.Rate = configFile.Rate - } - if configFile.Timeout > 0 { - options.Timeout = configFile.Timeout - } - options.Verify = configFile.Verify - options.Ping = configFile.Ping - if configFile.TopPorts != "" { - options.TopPorts = configFile.TopPorts - } - - options.ExcludeCDN = configFile.ExcludeCDN - if configFile.SourceIP != "" { - options.SourceIP = configFile.SourceIP - } - if configFile.Interface != "" { - options.Interface = configFile.Interface - } - if configFile.WarmUpTime > 0 { - options.WarmUpTime = configFile.WarmUpTime - } -} - func createGroup(flagSet *goflags.FlagSet, groupName, description string, flags ...*goflags.FlagData) { flagSet.SetGroup(groupName, description) for _, currentFlag := range flags { diff --git a/v2/pkg/runner/ports.go b/v2/pkg/runner/ports.go index 152f6897..d2dc7483 100644 --- a/v2/pkg/runner/ports.go +++ b/v2/pkg/runner/ports.go @@ -80,27 +80,6 @@ func ParsePorts(options *Options) ([]int, error) { } } - // ports from config file - if options.config != nil { - for _, p := range options.config.Ports { - // "-" equals to all ports - if p == "-" { - // Parse the custom ports list provided by the user - p = Full - } - ports, err := parsePortsList(p) - if err != nil { - return nil, fmt.Errorf("could not read ports: %s", err) - } - - pMap, err := excludePorts(options, ports) - if err != nil { - return nil, fmt.Errorf("could not read ports: %s", err) - } - portsConfigList = append(portsConfigList, pMap) - } - } - // If the user has specfied top option, use them too if options.Ports != "" { // "-" equals to all ports @@ -150,21 +129,7 @@ func excludePorts(options *Options, ports map[int]struct{}) (map[int]struct{}, e return nil, fmt.Errorf("could not read exclusion ports: %s", err) } - var excludedPortsConfigList []map[int]struct{} - if options.config != nil { - for _, excludePorts := range options.config.ExcludePorts { - p, err := parsePortsList(excludePorts) - if err != nil { - return nil, fmt.Errorf("could not read exclusion ports: %s", err) - } - excludedPortsConfigList = append(excludedPortsConfigList, p) - } - } - - excludedPortsConfig := merge(excludedPortsConfigList...) - excludedPorts := merge(excludedPortsCLI, excludedPortsConfig) - - for p := range excludedPorts { + for p := range excludedPortsCLI { delete(ports, p) } return ports, nil diff --git a/v2/pkg/runner/targets.go b/v2/pkg/runner/targets.go index 7c7c84f8..9238f1f8 100644 --- a/v2/pkg/runner/targets.go +++ b/v2/pkg/runner/targets.go @@ -71,13 +71,6 @@ func (r *Runner) mergeToFile() (string, error) { fmt.Fprintf(tempInput, "%s\n", target) } - // handles targets from config file if provided - if r.options.config != nil { - for _, target := range r.options.config.Host { - fmt.Fprintf(tempInput, "%s\n", target) - } - } - filename := tempInput.Name() return filename, nil } diff --git a/v2/pkg/runner/validate.go b/v2/pkg/runner/validate.go index 555d2bb3..d9ab5adf 100644 --- a/v2/pkg/runner/validate.go +++ b/v2/pkg/runner/validate.go @@ -17,7 +17,7 @@ import ( func (options *Options) validateOptions() error { // Check if Host, list of domains, or stdin info was provided. // If none was provided, then return. - if options.Host == "" && options.HostsFile == "" && !options.Stdin && len(flag.Args()) == 0 && (options.config != nil && len(options.config.Host) == 0) { + if options.Host == "" && options.HostsFile == "" && !options.Stdin && len(flag.Args()) == 0 { return errors.New("no input list provided") }