Skip to content

Commit 41494d4

Browse files
committed
Add flags for port collections on the scan command.
Closes #38
1 parent 92c642b commit 41494d4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

cmd/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ var (
6565
appendURI string
6666
appendURIFile string
6767

68+
// prepopulated ports for the scanner ports-sm,
69+
// ports-me, ports-lg flags
70+
scanPortsSmall = "80,443,8080,8443"
71+
scanPortsMedium = scanPortsSmall + ",81,90,591,3000,3128,8000,8008,8081,8082,8834,8888,7015,8800,8990,10000"
72+
scanPortsLarge = scanPortsMedium + ",300,2082,2087,2095,4243,4993,5000,7000,7171,7396,7474,8090,8280,8880,9443"
73+
6874
// report generate command
6975
reportFileName string
7076
reportChunks int

cmd/scan.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import (
1717
"github.com/spf13/cobra"
1818
)
1919

20+
var (
21+
portsS bool
22+
portsM bool
23+
portsL bool
24+
)
25+
2026
// scanCmd represents the scan command
2127
var scanCmd = &cobra.Command{
2228
Use: "scan",
@@ -56,10 +62,12 @@ $ gowitness scan --threads 20 --ports 80,443,8080 --cidr 192.168.0.1/32 --no-htt
5662
$ gowitness --log-level debug scan --threads 20 --ports 80,443,8080 --no-http --cidr 192.168.0.0/30
5763
$ gowitness scan --ports 80,443,8080 --cidr 192.168.0.0/30 --append-uri '/admin'
5864
$ gowitness scan --ports 80,443,8080 --cidr 192.168.0.0/30 --append-uri-file ~/wordlists/adminpanels.txt
65+
$ gowitness scan --ports 9999,9943 --ports-me --cidr 192.168.0.0/30 --append-uri-file ~/wordlists/adminpanels.txt
5966
`,
6067
Run: func(cmd *cobra.Command, args []string) {
6168

6269
validateScanCmdFlags()
70+
appendPorts()
6371

6472
ports, _ := utils.Ports(scanPorts)
6573
log.WithField("ports", ports).Debug("Using ports")
@@ -260,14 +268,41 @@ func validateScanCmdFlags() {
260268
}
261269
}
262270

271+
func appendPorts() {
272+
273+
if portsS {
274+
if !strings.HasSuffix(scanPorts, ",") {
275+
scanPorts = scanPorts + ","
276+
}
277+
scanPorts = scanPorts + scanPortsSmall
278+
}
279+
280+
if portsM {
281+
if !strings.HasSuffix(scanPorts, ",") {
282+
scanPorts = scanPorts + ","
283+
}
284+
scanPorts = scanPorts + scanPortsMedium
285+
}
286+
287+
if portsL {
288+
if !strings.HasSuffix(scanPorts, ",") {
289+
scanPorts = scanPorts + ","
290+
}
291+
scanPorts = scanPorts + scanPortsLarge
292+
}
293+
}
294+
263295
func init() {
264296
RootCmd.AddCommand(scanCmd)
265297

266298
scanCmd.Flags().StringSliceVarP(&scanCidr, "cidr", "c", []string{}, "The CIDR to scan (Can specify more than one --cidr)")
267299
scanCmd.Flags().StringVarP(&scanFileCidr, "file-cidr", "f", "", "A file containing newline separated CIDRs to scan")
268300
scanCmd.Flags().BoolVarP(&skipHTTP, "no-http", "s", false, "Skip trying to connect with HTTP")
269301
scanCmd.Flags().BoolVarP(&skipHTTPS, "no-https", "S", false, "Skip trying to connect with HTTPS")
270-
scanCmd.Flags().StringVarP(&scanPorts, "ports", "p", "80,443,8080,8443", "Ports to scan")
302+
scanCmd.Flags().StringVarP(&scanPorts, "ports", "p", "", "Ports to scan")
303+
scanCmd.Flags().BoolVar(&portsS, "ports-sm", true, "Use the small ports list (80,443,8080,8443)")
304+
scanCmd.Flags().BoolVar(&portsM, "ports-me", false, "Use the medium ports list (small + 81,90,591,3000,3128,8000,8008,8081,8082,8834,8888,7015,8800,8990,10000)")
305+
scanCmd.Flags().BoolVar(&portsL, "ports-lg", false, "Use the large ports list (medium + 300,2082,2087,2095,4243,4993,5000,7000,7171,7396,7474,8090,8280,8880,9443)")
271306
scanCmd.Flags().IntVarP(&maxThreads, "threads", "t", 4, "Maximum concurrent threads to run")
272307
scanCmd.Flags().BoolVarP(&randomPermutations, "random", "r", false, "Randomize generated permutations")
273308
scanCmd.Flags().StringVarP(&appendURI, "append-uri", "a", "", "Add permutations appending this URI")

0 commit comments

Comments
 (0)