| skipped 20 lines |
21 | 21 | | } |
22 | 22 | | |
23 | 23 | | scanCmd.Flags().StringP("ports", "p", "0-65535", "Port range for previous command") |
24 | | - | scanCmd.Flags().StringP("rate", "r", "5000", "rate limit for masscan command") |
| 24 | + | scanCmd.Flags().StringP("rate", "r", "3000", "rate limit for masscan command") |
25 | 25 | | scanCmd.Flags().BoolP("detail", "D", false, "Do Nmap scan based on previous output") |
| 26 | + | scanCmd.Flags().BoolP("all", "A", false, "Join all inputs to a file first") |
26 | 27 | | |
27 | 28 | | scanCmd.Flags().BoolP("flat", "f", true, "format output like this: 1.2.3.4:443") |
28 | 29 | | scanCmd.Flags().BoolP("nmap", "n", false, "Use nmap instead of masscan for overview scan") |
| skipped 1 lines |
30 | 31 | | scanCmd.Flags().BoolP("skip-masscan", "s", false, "run nmap from input format like this: 1.2.3.4:443") |
31 | 32 | | |
32 | 33 | | scanCmd.Flags().StringP("script", "S", "", "nmap scripts") |
33 | | - | scanCmd.Flags().String("nmap-command", "sudo nmap -sSV -p {{.ports}} {{.input}} {{.script}} -T4 --open -oA {{.output}}", "Nmap template command to run") |
| 34 | + | scanCmd.Flags().String("nmap-command", "sudo nmap -sSV -p {{.ports}} {{.input}} {{.script}} -T4 --open -oA {{.output}}", "Nmap template command to run") |
34 | 35 | | scanCmd.Flags().StringP("grep", "g", "", "match string to confirm script success") |
35 | 36 | | // only parse scan |
36 | 37 | | scanCmd.Flags().StringP("result-folder", "R", "", "Result folder") |
| skipped 10 lines |
47 | 48 | | options.Scan.Rate, _ = cmd.Flags().GetString("rate") |
48 | 49 | | options.Scan.Detail, _ = cmd.Flags().GetBool("detail") |
49 | 50 | | options.Scan.Flat, _ = cmd.Flags().GetBool("flat") |
| 51 | + | options.Scan.All, _ = cmd.Flags().GetBool("all") |
50 | 52 | | options.Scan.NmapOverview, _ = cmd.Flags().GetBool("nmap") |
51 | 53 | | options.Scan.ZmapOverview, _ = cmd.Flags().GetBool("zmap") |
52 | 54 | | options.Scan.SkipOverview, _ = cmd.Flags().GetBool("skip-masscan") |
| skipped 21 lines |
74 | 76 | | var wg sync.WaitGroup |
75 | 77 | | jobs := make(chan string) |
76 | 78 | | |
77 | | - | if options.Scan.ZmapOverview { |
78 | | - | inputFile := StoreTmpInput(inputs, options) |
79 | | - | ports := core.GenPorts(options.Scan.Ports) |
80 | | - | core.DebugF("Store temp input in: %v", inputFile) |
81 | | - | core.DebugF("Run port scan with: %v", strings.Trim(strings.Join(ports, ","), ",")) |
82 | | - | if inputFile == "" || len(ports) == 0 { |
83 | | - | core.ErrorF("Error gen input or ports") |
| 79 | + | if options.Scan.All || options.Scan.ZmapOverview { |
| 80 | + | options.Scan.InputFile = StoreTmpInput(inputs, options) |
| 81 | + | core.DebugF("Store temp input in: %v", options.Scan.InputFile) |
| 82 | + | |
| 83 | + | if options.Scan.ZmapOverview { |
| 84 | + | ports := core.GenPorts(options.Scan.Ports) |
| 85 | + | core.DebugF("Run port scan with: %v", strings.Trim(strings.Join(ports, ","), ",")) |
| 86 | + | if options.Scan.InputFile == "" || len(ports) == 0 { |
| 87 | + | core.ErrorF("Error gen input or ports") |
| 88 | + | return nil |
| 89 | + | } |
| 90 | + | for i := 0; i < options.Concurrency; i++ { |
| 91 | + | wg.Add(1) |
| 92 | + | go func() { |
| 93 | + | defer wg.Done() |
| 94 | + | for job := range jobs { |
| 95 | + | // do real stuff here |
| 96 | + | core.BannerF("Run zmap scan on port ", job) |
| 97 | + | result = modules.RunZmap(options.Scan.InputFile, job, options) |
| 98 | + | StoreData(result, options) |
| 99 | + | } |
| 100 | + | }() |
| 101 | + | } |
| 102 | + | for _, port := range ports { |
| 103 | + | jobs <- port |
| 104 | + | } |
| 105 | + | close(jobs) |
| 106 | + | wg.Wait() |
84 | 107 | | return nil |
85 | 108 | | } |
86 | | - | for i := 0; i < options.Concurrency; i++ { |
87 | | - | wg.Add(1) |
88 | | - | go func() { |
89 | | - | defer wg.Done() |
90 | | - | for job := range jobs { |
91 | | - | // do real stuff here |
92 | | - | core.BannerF("Run zmap scan on port ", job) |
93 | | - | result = modules.RunZmap(inputFile, job, options) |
94 | | - | StoreData(result, options) |
95 | | - | } |
96 | | - | }() |
| 109 | + | |
| 110 | + | core.BannerF("Run overview scan on port ", options.Scan.InputFile) |
| 111 | + | if options.Scan.NmapOverview { |
| 112 | + | result = modules.RunNmap(options.Scan.InputFile, "", options) |
| 113 | + | } else { |
| 114 | + | result = modules.RunMasscan(options.Scan.InputFile, options) |
97 | 115 | | } |
98 | | - | for _, port := range ports { |
99 | | - | jobs <- port |
100 | | - | } |
101 | | - | close(jobs) |
102 | | - | wg.Wait() |
103 | 116 | | return nil |
| 117 | + | |
104 | 118 | | } |
105 | 119 | | |
106 | 120 | | for i := 0; i < options.Concurrency; i++ { |
| skipped 23 lines |
130 | 144 | | } |
131 | 145 | | |
132 | 146 | | func runRoutine(input string, options core.Options) []string { |
133 | | - | core.BannerF("Run overview scan on: ", input) |
134 | 147 | | var data []string |
135 | | - | |
| 148 | + | core.BannerF("Run overview scan on: ", input) |
136 | 149 | | if options.Scan.NmapOverview { |
137 | 150 | | data = append(data, modules.RunNmap(input, "", options)...) |
138 | 151 | | } else { |
| skipped 123 lines |