1 | 1 | | package cmd |
2 | 2 | | |
3 | 3 | | import ( |
4 | | - | "fmt" |
5 | | - | "github.com/thoas/go-funk" |
6 | | - | "io/ioutil" |
7 | | - | "os" |
8 | | - | "strings" |
9 | | - | "sync" |
| 4 | + | "fmt" |
| 5 | + | "github.com/thoas/go-funk" |
| 6 | + | "io/ioutil" |
| 7 | + | "os" |
| 8 | + | "strings" |
| 9 | + | "sync" |
10 | 10 | | |
11 | | - | "github.com/j3ssie/metabigor/core" |
12 | | - | "github.com/j3ssie/metabigor/modules" |
13 | | - | "github.com/spf13/cobra" |
| 11 | + | "github.com/j3ssie/metabigor/core" |
| 12 | + | "github.com/j3ssie/metabigor/modules" |
| 13 | + | "github.com/spf13/cobra" |
14 | 14 | | ) |
15 | 15 | | |
16 | 16 | | func init() { |
17 | | - | var scanCmd = &cobra.Command{ |
18 | | - | Use: "scan", |
19 | | - | Short: "Wrapper to run port scan from provided input", |
20 | | - | Long: core.DESC, |
21 | | - | RunE: runScan, |
22 | | - | } |
23 | | - | // scan options |
24 | | - | scanCmd.Flags().StringVarP(&options.Scan.Ports, "ports", "p", "0-65535", "Port range for previous command") |
25 | | - | scanCmd.Flags().StringVarP(&options.Scan.Rate, "rate", "r", "3000", "rate limit for masscan command") |
26 | | - | scanCmd.Flags().BoolVarP(&options.Scan.All, "join", "A", false, "Join all inputs to a file first then do a scan") |
27 | | - | // scan strategy option |
28 | | - | scanCmd.Flags().BoolVarP(&options.Scan.Flat, "flat", "f", true, "format output like this: 1.2.3.4:443") |
29 | | - | scanCmd.Flags().BoolVarP(&options.Scan.NmapOverview, "nmap", "n", false, "Use nmap instead of masscan for overview scan") |
30 | | - | scanCmd.Flags().BoolVarP(&options.Scan.ZmapOverview, "zmap", "z", false, "Only scan range with zmap") |
31 | | - | scanCmd.Flags().BoolVarP(&options.Scan.SkipOverview, "skip-masscan", "s", false, "run nmap from input format like this: 1.2.3.4:443") |
32 | | - | scanCmd.Flags().BoolVarP(&options.Scan.InputFromRustScan, "rstd", "R", false, "run nmap from rustscan input format like: 1.2.3.4 -> [80,443,8080,8443,8880]") |
33 | | - | // more nmap options |
34 | | - | scanCmd.Flags().StringVarP(&options.Scan.NmapScripts, "script", "S", "", "nmap scripts") |
35 | | - | scanCmd.Flags().StringVar(&options.Scan.NmapTemplate, "nmap-command", "nmap -sSV -sC -p {{.ports}} {{.input}} {{.script}} -T4 --open -oA {{.output}}", "Nmap template command to run") |
36 | | - | scanCmd.Flags().StringVar(&options.Scan.GrepString, "grep", "", "match string to confirm script success") |
37 | | - | scanCmd.Flags().String("result-folder", "", "Result folder") |
38 | | - | scanCmd.Flags().BoolVar(&options.Scan.IPv4, "4", true, "Filter input to only get ipv4") |
39 | | - | scanCmd.Flags().BoolVar(&options.Scan.Skip80And443, "8", false, "Skip ports 80 and 443. Useful when you want to look for service behind the list of pre-scanned data") |
40 | | - | //scanCmd.Flags().Bool("6", false, "Filter input to only get ipv4") |
41 | | - | scanCmd.Flags().BoolP("detail", "D", false, "Do Nmap scan based on previous output") |
42 | | - | scanCmd.Flags().Bool("uniq", true, "Unique input first") |
43 | | - | scanCmd.SetHelpFunc(ScanHelp) |
44 | | - | RootCmd.AddCommand(scanCmd) |
| 17 | + | var scanCmd = &cobra.Command{ |
| 18 | + | Use: "scan", |
| 19 | + | Short: "Wrapper to run port scan from provided input", |
| 20 | + | Long: core.DESC, |
| 21 | + | RunE: runScan, |
| 22 | + | } |
| 23 | + | // scan options |
| 24 | + | scanCmd.Flags().StringVarP(&options.Scan.Ports, "ports", "p", "0-65535", "Port range for previous command") |
| 25 | + | scanCmd.Flags().StringVarP(&options.Scan.Rate, "rate", "r", "3000", "rate limit for masscan command") |
| 26 | + | scanCmd.Flags().BoolVarP(&options.Scan.All, "join", "A", false, "Join all inputs to a file first then do a scan") |
| 27 | + | // scan strategy option |
| 28 | + | scanCmd.Flags().BoolVarP(&options.Scan.Flat, "flat", "f", true, "format output like this: 1.2.3.4:443") |
| 29 | + | scanCmd.Flags().BoolVarP(&options.Scan.NmapOverview, "nmap", "n", false, "Use nmap instead of masscan for overview scan") |
| 30 | + | scanCmd.Flags().BoolVarP(&options.Scan.ZmapOverview, "zmap", "z", false, "Only scan range with zmap") |
| 31 | + | scanCmd.Flags().BoolVarP(&options.Scan.SkipOverview, "skip-masscan", "s", false, "run nmap from input format like this: 1.2.3.4:443") |
| 32 | + | scanCmd.Flags().BoolVarP(&options.Scan.InputFromRustScan, "rstd", "R", false, "run nmap from rustscan input format like: 1.2.3.4 -> [80,443,8080,8443,8880]") |
| 33 | + | // more nmap options |
| 34 | + | scanCmd.Flags().StringVarP(&options.Scan.NmapScripts, "script", "S", "", "nmap scripts") |
| 35 | + | scanCmd.Flags().StringVar(&options.Scan.NmapTemplate, "nmap-command", "nmap -sSV -sC -p {{.ports}} {{.input}} {{.script}} -T4 --open -oA {{.output}}", "Nmap template command to run") |
| 36 | + | scanCmd.Flags().StringVar(&options.Scan.GrepString, "grep", "", "match string to confirm script success") |
| 37 | + | scanCmd.Flags().String("result-folder", "", "Result folder") |
| 38 | + | scanCmd.Flags().BoolVar(&options.Scan.IPv4, "4", true, "Filter input to only get ipv4") |
| 39 | + | scanCmd.Flags().BoolVar(&options.Scan.Skip80And443, "8", false, "Skip ports 80 and 443. Useful when you want to look for service behind the list of pre-scanned data") |
| 40 | + | //scanCmd.Flags().Bool("6", false, "Filter input to only get ipv4") |
| 41 | + | scanCmd.Flags().BoolP("detail", "D", false, "Do Nmap scan based on previous output") |
| 42 | + | scanCmd.Flags().Bool("uniq", true, "Unique input first") |
| 43 | + | scanCmd.SetHelpFunc(ScanHelp) |
| 44 | + | RootCmd.AddCommand(scanCmd) |
45 | 45 | | } |
46 | 46 | | |
47 | 47 | | func runScan(cmd *cobra.Command, _ []string) error { |
48 | | - | // only parse result |
49 | | - | resultFolder, _ := cmd.Flags().GetString("result-folder") |
50 | | - | uniq, _ := cmd.Flags().GetBool("uniq") |
51 | | - | if resultFolder != "" { |
52 | | - | parseResult(resultFolder, options) |
53 | | - | os.Exit(0) |
54 | | - | } |
| 48 | + | // only parse result |
| 49 | + | resultFolder, _ := cmd.Flags().GetString("result-folder") |
| 50 | + | uniq, _ := cmd.Flags().GetBool("uniq") |
| 51 | + | if resultFolder != "" { |
| 52 | + | parseResult(resultFolder, options) |
| 53 | + | os.Exit(0) |
| 54 | + | } |
55 | 55 | | |
56 | | - | if options.Scan.InputFromRustScan { |
57 | | - | options.Scan.SkipOverview = true |
58 | | - | } |
| 56 | + | if options.Scan.InputFromRustScan { |
| 57 | + | options.Scan.SkipOverview = true |
| 58 | + | } |
59 | 59 | | |
60 | | - | if options.Input == "-" || options.Input == "" { |
61 | | - | core.ErrorF("No input found") |
62 | | - | os.Exit(1) |
63 | | - | } |
64 | | - | |
65 | | - | var inputs []string |
66 | | - | if strings.Contains(options.Input, "\n") { |
67 | | - | inputs = strings.Split(options.Input, "\n") |
68 | | - | } else { |
69 | | - | inputs = append(inputs, options.Input) |
70 | | - | } |
71 | | - | |
72 | | - | // make sure input is valid |
73 | | - | if options.Scan.IPv4 { |
74 | | - | // only filter when run zmap |
75 | | - | if !options.Scan.SkipOverview { |
76 | | - | inputs = core.FilterIpv4(inputs) |
77 | | - | } |
78 | | - | } |
79 | | - | if uniq { |
80 | | - | inputs = funk.UniqString(inputs) |
81 | | - | } |
82 | | - | if len(inputs) == 0 { |
83 | | - | core.ErrorF("No input provided") |
84 | | - | os.Exit(1) |
85 | | - | } |
| 60 | + | // make sure input is valid |
| 61 | + | if options.Scan.IPv4 { |
| 62 | + | // only filter when run zmap |
| 63 | + | if !options.Scan.SkipOverview { |
| 64 | + | options.Inputs = core.FilterIpv4(options.Inputs) |
| 65 | + | } |
| 66 | + | } |
| 67 | + | if uniq { |
| 68 | + | options.Inputs = funk.UniqString(options.Inputs) |
| 69 | + | } |
| 70 | + | if len(options.Inputs) == 0 { |
| 71 | + | core.ErrorF("No input provided") |
| 72 | + | os.Exit(1) |
| 73 | + | } |
86 | 74 | | |
87 | | - | var result []string |
88 | | - | var wg sync.WaitGroup |
89 | | - | jobs := make(chan string) |
| 75 | + | var result []string |
| 76 | + | var wg sync.WaitGroup |
| 77 | + | jobs := make(chan string) |
90 | 78 | | |
91 | | - | if options.Scan.All || options.Scan.ZmapOverview { |
92 | | - | options.Scan.InputFile = StoreTmpInput(inputs, options) |
93 | | - | core.DebugF("Store temp input in: %v", options.Scan.InputFile) |
| 79 | + | if options.Scan.All || options.Scan.ZmapOverview { |
| 80 | + | options.Scan.InputFile = StoreTmpInput(options.Inputs, options) |
| 81 | + | core.DebugF("Store temp input in: %v", options.Scan.InputFile) |
94 | 82 | | |
95 | | - | if options.Scan.ZmapOverview { |
96 | | - | ports := core.GenPorts(options.Scan.Ports) |
97 | | - | core.DebugF("Run port scan with: %v", strings.Trim(strings.Join(ports, ","), ",")) |
98 | | - | if options.Scan.InputFile == "" || len(ports) == 0 { |
99 | | - | core.ErrorF("Error gen input or ports") |
100 | | - | return nil |
101 | | - | } |
102 | | - | for i := 0; i < options.Concurrency; i++ { |
103 | | - | wg.Add(1) |
104 | | - | go func() { |
105 | | - | defer wg.Done() |
106 | | - | for job := range jobs { |
107 | | - | // do real stuff here |
108 | | - | core.BannerF("Run zmap scan on port ", job) |
109 | | - | result = modules.RunZmap(options.Scan.InputFile, job, options) |
110 | | - | StoreData(result, options) |
111 | | - | } |
112 | | - | }() |
113 | | - | } |
114 | | - | for _, port := range ports { |
115 | | - | jobs <- port |
116 | | - | } |
117 | | - | close(jobs) |
118 | | - | wg.Wait() |
119 | | - | return nil |
120 | | - | } |
| 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() |
| 107 | + | return nil |
| 108 | + | } |
121 | 109 | | |
122 | | - | core.BannerF("Run overview scan on port ", options.Scan.InputFile) |
123 | | - | if options.Scan.NmapOverview { |
124 | | - | result = modules.RunNmap(options.Scan.InputFile, "", options) |
125 | | - | } else { |
126 | | - | result = modules.RunMasscan(options.Scan.InputFile, options) |
127 | | - | } |
128 | | - | StoreData(result, options) |
129 | | - | return nil |
130 | | - | } |
| 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) |
| 115 | + | } |
| 116 | + | StoreData(result, options) |
| 117 | + | return nil |
| 118 | + | } |
131 | 119 | | |
132 | | - | for i := 0; i < options.Concurrency; i++ { |
133 | | - | wg.Add(1) |
134 | | - | go func() { |
135 | | - | defer wg.Done() |
136 | | - | // do real stuff here |
137 | | - | for job := range jobs { |
138 | | - | if options.Scan.SkipOverview { |
139 | | - | result = directDetail(job, options) |
140 | | - | } else { |
141 | | - | result = runRoutine(job, options) |
142 | | - | } |
143 | | - | StoreData(result, options) |
144 | | - | } |
145 | | - | }() |
146 | | - | } |
| 120 | + | for i := 0; i < options.Concurrency; i++ { |
| 121 | + | wg.Add(1) |
| 122 | + | go func() { |
| 123 | + | defer wg.Done() |
| 124 | + | // do real stuff here |
| 125 | + | for job := range jobs { |
| 126 | + | if options.Scan.SkipOverview { |
| 127 | + | result = directDetail(job, options) |
| 128 | + | } else { |
| 129 | + | result = runRoutine(job, options) |
| 130 | + | } |
| 131 | + | StoreData(result, options) |
| 132 | + | } |
| 133 | + | }() |
| 134 | + | } |
147 | 135 | | |
148 | | - | for _, input := range inputs { |
149 | | - | jobs <- input |
150 | | - | } |
| 136 | + | for _, input := range options.Inputs { |
| 137 | + | jobs <- input |
| 138 | + | } |
151 | 139 | | |
152 | | - | close(jobs) |
153 | | - | wg.Wait() |
| 140 | + | close(jobs) |
| 141 | + | wg.Wait() |
154 | 142 | | |
155 | | - | return nil |
| 143 | + | return nil |
156 | 144 | | } |
157 | 145 | | |
158 | 146 | | func runRoutine(input string, options core.Options) []string { |
159 | | - | var data []string |
160 | | - | core.BannerF("Run overview scan on: ", input) |
161 | | - | if options.Scan.NmapOverview { |
162 | | - | data = append(data, modules.RunNmap(input, "", options)...) |
163 | | - | } else { |
164 | | - | data = append(data, modules.RunMasscan(input, options)...) |
165 | | - | } |
| 147 | + | var data []string |
| 148 | + | core.BannerF("Run overview scan on: ", input) |
| 149 | + | if options.Scan.NmapOverview { |
| 150 | + | data = append(data, modules.RunNmap(input, "", options)...) |
| 151 | + | } else { |
| 152 | + | data = append(data, modules.RunMasscan(input, options)...) |
| 153 | + | } |
166 | 154 | | |
167 | | - | if !options.Scan.Detail { |
168 | | - | return data |
169 | | - | } |
| 155 | + | if !options.Scan.Detail { |
| 156 | + | return data |
| 157 | + | } |
170 | 158 | | |
171 | | - | var wg sync.WaitGroup |
172 | | - | var realData []string |
173 | | - | for _, item := range data { |
174 | | - | wg.Add(1) |
175 | | - | go func(item string) { |
176 | | - | realData = append(realData, runDetail(item, options)...) |
177 | | - | wg.Done() |
178 | | - | }(item) |
179 | | - | } |
180 | | - | wg.Wait() |
181 | | - | return realData |
| 159 | + | var wg sync.WaitGroup |
| 160 | + | var realData []string |
| 161 | + | for _, item := range data { |
| 162 | + | wg.Add(1) |
| 163 | + | go func(item string) { |
| 164 | + | realData = append(realData, runDetail(item, options)...) |
| 165 | + | wg.Done() |
| 166 | + | }(item) |
| 167 | + | } |
| 168 | + | wg.Wait() |
| 169 | + | return realData |
182 | 170 | | } |
183 | 171 | | |
184 | 172 | | func runDetail(input string, options core.Options) []string { |
185 | | - | if options.Scan.Flat { |
186 | | - | return directDetail(input, options) |
187 | | - | } |
188 | | - | if input == "" { |
189 | | - | return []string{} |
190 | | - | } |
191 | | - | if len(strings.Split(input, " - ")) == 1 { |
192 | | - | return []string{} |
193 | | - | } |
| 173 | + | if options.Scan.Flat { |
| 174 | + | return directDetail(input, options) |
| 175 | + | } |
| 176 | + | if input == "" { |
| 177 | + | return []string{} |
| 178 | + | } |
| 179 | + | if len(strings.Split(input, " - ")) == 1 { |
| 180 | + | return []string{} |
| 181 | + | } |
194 | 182 | | |
195 | | - | host := strings.Split(input, " - ")[0] |
196 | | - | ports := strings.Split(input, " - ")[1] |
197 | | - | core.BannerF("Run detail scan on: ", fmt.Sprintf("%v:%v", host, ports)) |
198 | | - | return modules.RunNmap(host, ports, options) |
| 183 | + | host := strings.Split(input, " - ")[0] |
| 184 | + | ports := strings.Split(input, " - ")[1] |
| 185 | + | core.BannerF("Run detail scan on: ", fmt.Sprintf("%v:%v", host, ports)) |
| 186 | + | return modules.RunNmap(host, ports, options) |
199 | 187 | | } |
200 | 188 | | |
201 | 189 | | func directDetail(input string, options core.Options) []string { |
202 | | - | var out []string |
203 | | - | if options.Scan.Skip80And443 { |
204 | | - | if strings.HasSuffix(input, ":80") && strings.HasSuffix(input, ":443") { |
205 | | - | return out |
206 | | - | } |
207 | | - | } |
| 190 | + | var out []string |
| 191 | + | if options.Scan.Skip80And443 { |
| 192 | + | if strings.HasSuffix(input, ":80") && strings.HasSuffix(input, ":443") { |
| 193 | + | return out |
| 194 | + | } |
| 195 | + | } |
208 | 196 | | |
209 | | - | if input == "" { |
210 | | - | return out |
211 | | - | } |
212 | | - | var host, ports string |
| 197 | + | if input == "" { |
| 198 | + | return out |
| 199 | + | } |
| 200 | + | var host, ports string |
213 | 201 | | |
214 | | - | if options.Scan.InputFromRustScan { |
215 | | - | // 1.1.1.1 -> [80,443,2095,2096,8080,8443,8880] |
216 | | - | if !strings.Contains(input, "->") { |
217 | | - | return out |
218 | | - | } |
219 | | - | host = strings.Split(input, " -> ")[0] |
220 | | - | ports = strings.Split(input, " -> ")[1] |
221 | | - | ports = strings.TrimLeft(strings.TrimRight(ports, "]"), "[") |
222 | | - | } else { |
223 | | - | if len(strings.Split(input, ":")) == 1 { |
224 | | - | return out |
225 | | - | } |
226 | | - | host = strings.Split(input, ":")[0] |
227 | | - | ports = strings.Split(input, ":")[1] |
228 | | - | } |
| 202 | + | if options.Scan.InputFromRustScan { |
| 203 | + | // 1.1.1.1 -> [80,443,2095,2096,8080,8443,8880] |
| 204 | + | if !strings.Contains(input, "->") { |
| 205 | + | return out |
| 206 | + | } |
| 207 | + | host = strings.Split(input, " -> ")[0] |
| 208 | + | ports = strings.Split(input, " -> ")[1] |
| 209 | + | ports = strings.TrimLeft(strings.TrimRight(ports, "]"), "[") |
| 210 | + | } else { |
| 211 | + | if len(strings.Split(input, ":")) == 1 { |
| 212 | + | return out |
| 213 | + | } |
| 214 | + | host = strings.Split(input, ":")[0] |
| 215 | + | ports = strings.Split(input, ":")[1] |
| 216 | + | } |
229 | 217 | | |
230 | | - | core.BannerF("Run detail scan on: ", fmt.Sprintf("%v:%v", host, ports)) |
231 | | - | out = modules.RunNmap(host, ports, options) |
232 | | - | return out |
| 218 | + | core.BannerF("Run detail scan on: ", fmt.Sprintf("%v:%v", host, ports)) |
| 219 | + | out = modules.RunNmap(host, ports, options) |
| 220 | + | return out |
233 | 221 | | } |
234 | 222 | | |
235 | 223 | | // only parse result |
236 | 224 | | func parseResult(resultFolder string, options core.Options) { |
237 | | - | if !core.FolderExists(resultFolder) { |
238 | | - | core.ErrorF("Result Folder not found: ", resultFolder) |
239 | | - | return |
240 | | - | } |
241 | | - | core.BannerF("Reading result from: ", fmt.Sprintf("%v", resultFolder)) |
242 | | - | Files, err := ioutil.ReadDir(resultFolder) |
243 | | - | if err != nil { |
244 | | - | return |
245 | | - | } |
| 225 | + | if !core.FolderExists(resultFolder) { |
| 226 | + | core.ErrorF("Result Folder not found: ", resultFolder) |
| 227 | + | return |
| 228 | + | } |
| 229 | + | core.BannerF("Reading result from: ", fmt.Sprintf("%v", resultFolder)) |
| 230 | + | Files, err := ioutil.ReadDir(resultFolder) |
| 231 | + | if err != nil { |
| 232 | + | return |
| 233 | + | } |
246 | 234 | | |
247 | | - | if options.Scan.Detail { |
248 | | - | // nmap |
249 | | - | for _, file := range Files { |
250 | | - | filename := file.Name() |
251 | | - | core.DebugF("Reading: %v", filename) |
252 | | - | if strings.HasSuffix(file.Name(), "xml") && strings.HasPrefix(filename, "nmap") { |
253 | | - | data := core.GetFileContent(filename) |
254 | | - | result := modules.ParseNmap(data, options) |
255 | | - | if len(result) > 0 { |
256 | | - | fmt.Printf(strings.Join(result, "\n")) |
257 | | - | } |
258 | | - | } |
259 | | - | } |
260 | | - | return |
261 | | - | } |
| 235 | + | if options.Scan.Detail { |
| 236 | + | // nmap |
| 237 | + | for _, file := range Files { |
| 238 | + | filename := file.Name() |
| 239 | + | core.DebugF("Reading: %v", filename) |
| 240 | + | if strings.HasSuffix(file.Name(), "xml") && strings.HasPrefix(filename, "nmap") { |
| 241 | + | data := core.GetFileContent(filename) |
| 242 | + | result := modules.ParseNmap(data, options) |
| 243 | + | if len(result) > 0 { |
| 244 | + | fmt.Printf(strings.Join(result, "\n")) |
| 245 | + | } |
| 246 | + | } |
| 247 | + | } |
| 248 | + | return |
| 249 | + | } |
262 | 250 | | |
263 | | - | // masscan |
264 | | - | for _, file := range Files { |
265 | | - | filename := file.Name() |
266 | | - | core.DebugF("Reading: %v", filename) |
267 | | - | if strings.HasPrefix(filename, "masscan") { |
268 | | - | data := core.GetFileContent(filename) |
269 | | - | fmt.Println(data) |
270 | | - | rawResult := modules.ParsingMasscan(data) |
271 | | - | fmt.Println(rawResult) |
272 | | - | for k, v := range rawResult { |
273 | | - | for _, port := range v { |
274 | | - | fmt.Printf("%v:%v\n", k, port) |
275 | | - | } |
276 | | - | } |
277 | | - | } |
278 | | - | } |
| 251 | + | // masscan |
| 252 | + | for _, file := range Files { |
| 253 | + | filename := file.Name() |
| 254 | + | core.DebugF("Reading: %v", filename) |
| 255 | + | if strings.HasPrefix(filename, "masscan") { |
| 256 | + | data := core.GetFileContent(filename) |
| 257 | + | fmt.Println(data) |
| 258 | + | rawResult := modules.ParsingMasscan(data) |
| 259 | + | fmt.Println(rawResult) |
| 260 | + | for k, v := range rawResult { |
| 261 | + | for _, port := range v { |
| 262 | + | fmt.Printf("%v:%v\n", k, port) |
| 263 | + | } |
| 264 | + | } |
| 265 | + | } |
| 266 | + | } |
279 | 267 | | } |
280 | 268 | | |
281 | 269 | | // StoreTmpInput store list of string to tmp file |
282 | 270 | | func StoreTmpInput(raw []string, options core.Options) string { |
283 | | - | tmpDest := options.Scan.TmpOutput |
284 | | - | tmpFile, _ := ioutil.TempFile(options.Scan.TmpOutput, "joined-*.txt") |
285 | | - | if tmpDest != "" { |
286 | | - | tmpFile, _ = ioutil.TempFile(tmpDest, "joined-input-*.txt") |
287 | | - | } |
288 | | - | tmpDest = tmpFile.Name() |
289 | | - | core.WriteToFile(tmpDest, strings.Join(raw, "\n")) |
290 | | - | return tmpDest |
| 271 | + | tmpDest := options.Scan.TmpOutput |
| 272 | + | tmpFile, _ := ioutil.TempFile(options.Scan.TmpOutput, "joined-*.txt") |
| 273 | + | if tmpDest != "" { |
| 274 | + | tmpFile, _ = ioutil.TempFile(tmpDest, "joined-input-*.txt") |
| 275 | + | } |
| 276 | + | tmpDest = tmpFile.Name() |
| 277 | + | core.WriteToFile(tmpDest, strings.Join(raw, "\n")) |
| 278 | + | return tmpDest |
291 | 279 | | } |
292 | 280 | | |
293 | 281 | | // ScanHelp print help message |
294 | 282 | | func ScanHelp(cmd *cobra.Command, _ []string) { |
295 | | - | fmt.Println(cmd.UsageString()) |
296 | | - | h := "\nExample Commands:\n" |
297 | | - | h += " # Run Nmap with output from rustscan\n" |
298 | | - | h += " echo '1.2.3.4 -> [80,443,2222]' | metabigor scan -R\n" |
299 | | - | h += " # Only run masscan full ports\n" |
300 | | - | h += " echo '1.2.3.4/24' | metabigor scan -o result.txt\n\n" |
301 | | - | h += " # Only run nmap detail scan\n" |
302 | | - | h += " echo '1.2.3.4:21' | metabigor scan -s -c 10\n" |
303 | | - | h += " echo '1.2.3.4:21' | metabigor scan --tmp /tmp/raw-result/ -s -o result.txt\n\n" |
304 | | - | h += " # Only run scan with zmap \n" |
305 | | - | h += " cat ranges.txt | metabigor scan -p '443,80' -z\n" |
306 | | - | h += "\n" |
307 | | - | fmt.Printf(h) |
| 283 | + | fmt.Println(cmd.UsageString()) |
| 284 | + | h := "\nExample Commands:\n" |
| 285 | + | h += " # Run Nmap with output from rustscan\n" |
| 286 | + | h += " echo '1.2.3.4 -> [80,443,2222]' | metabigor scan -R\n" |
| 287 | + | h += " # Only run masscan full ports\n" |
| 288 | + | h += " echo '1.2.3.4/24' | metabigor scan -o result.txt\n\n" |
| 289 | + | h += " # Only run nmap detail scan\n" |
| 290 | + | h += " echo '1.2.3.4:21' | metabigor scan -s -c 10\n" |
| 291 | + | h += " echo '1.2.3.4:21' | metabigor scan --tmp /tmp/raw-result/ -s -o result.txt\n\n" |
| 292 | + | h += " # Only run scan with zmap \n" |
| 293 | + | h += " cat ranges.txt | metabigor scan -p '443,80' -z\n" |
| 294 | + | h += "\n" |
| 295 | + | fmt.Printf(h) |
308 | 296 | | } |
309 | 297 | | |