Skip to content

Commit

Permalink
Deprecating custom config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Oct 12, 2021
1 parent 0c4933c commit 44cdbe9
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 297 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 0 additions & 61 deletions v2/pkg/runner/banners.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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)
}
108 changes: 0 additions & 108 deletions v2/pkg/runner/config.go

This file was deleted.

10 changes: 0 additions & 10 deletions v2/pkg/runner/ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 0 additions & 4 deletions v2/pkg/runner/nmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand Down
82 changes: 13 additions & 69 deletions v2/pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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",
Expand All @@ -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)"),
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 44cdbe9

Please sign in to comment.