Skip to content

Commit efc8134

Browse files
committed
adding interface listing
1 parent 8414ae3 commit efc8134

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/runner/banners.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package runner
22

33
import (
4+
"net"
5+
"strings"
6+
47
"github.com/projectdiscovery/gologger"
58
"github.com/projectdiscovery/naabu/pkg/runas"
69
)
@@ -36,6 +39,26 @@ func showNetworkCapabilities() {
3639
gologger.Infof("Scan Type: %s\n", scanType)
3740
}
3841

42+
func showNetworkInterfaces() error {
43+
interfaces, err := net.Interfaces()
44+
if err != nil {
45+
return err
46+
}
47+
for _, itf := range interfaces {
48+
addresses, err := itf.Addrs()
49+
if err != nil {
50+
gologger.Warningf("Could not retrieve addresses for %s: %s\n", itf.Name, err)
51+
continue
52+
}
53+
var addrstr []string
54+
for _, address := range addresses {
55+
addrstr = append(addrstr, address.String())
56+
}
57+
gologger.Infof("Interface %s:\nMAC: %s\nAddresses: %s\nMTU: %d\nFlags: %s\n", itf.Name, itf.HardwareAddr, strings.Join(addrstr, " "), itf.MTU, itf.Flags.String())
58+
}
59+
return nil
60+
}
61+
3962
func handlePrivileges(options *Options) error {
4063
if options.Privileged {
4164
return runas.Root()

pkg/runner/options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Options struct {
4242
SourceIp string
4343
Interface string
4444
WarmUpTime int
45+
InterfacesList bool
4546
}
4647

4748
// ParseOptions parses the command line flags provided by a user
@@ -79,6 +80,7 @@ func ParseOptions() *Options {
7980
flag.BoolVar(&options.Unprivileged, "unprivileged", false, "Drop root privileges")
8081
flag.BoolVar(&options.ExcludeCDN, "exclude-cdn", false, "Avoid scanning CDN ips")
8182
flag.IntVar(&options.WarmUpTime, "warm-up-time", 2, "Time in Seconds between scan phases")
83+
flag.BoolVar(&options.InterfacesList, "interface-list", false, "list available interfaces and exit")
8284
flag.Parse()
8385

8486
// Check if stdin pipe was given
@@ -95,6 +97,12 @@ func ParseOptions() *Options {
9597
os.Exit(0)
9698
}
9799

100+
// Show network configuration and exit if the user requested it
101+
if options.InterfacesList {
102+
showNetworkInterfaces()
103+
os.Exit(0)
104+
}
105+
98106
// Validate the options passed by the user and if any
99107
// invalid options have been used, exit.
100108
err := options.validateOptions()
@@ -104,6 +112,7 @@ func ParseOptions() *Options {
104112

105113
showNetworkCapabilities()
106114

115+
// Handle privileges - most probably elevation will fail as the process would need to invoke fork()
107116
err = handlePrivileges(options)
108117
if err != nil {
109118
gologger.Warningf("Could not set privileges:%s\n", err)

0 commit comments

Comments
 (0)