Projects STRLCPY metabigor Commits e98bd8a1
🤬
  • ■ ■ ■ ■ ■ ■
    cmd/scan.go
    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
  • ■ ■ ■ ■
    core/common.go
    skipped 22 lines
    23 23   if !FolderExists(options.Scan.TmpOutput) {
    24 24   os.MkdirAll(options.Scan.TmpOutput, 0755)
    25 25   }
    26  - options.LogFile = path.Join(options.Scan.TmpOutput, "metabigor.log")
     26 + options.LogFile = path.Join(options.Scan.TmpOutput, fmt.Sprintf("metabigor-%s.log", GetTS()))
    27 27   f, err := os.OpenFile(options.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
    28 28   if err != nil {
    29 29   logger.Error("error opening file: %v", err)
    skipped 59 lines
  • ■ ■ ■ ■ ■ ■
    core/options.go
    skipped 29 lines
    30 30   ZmapOverview bool
    31 31   Detail bool
    32 32   Flat bool
     33 + All bool
    33 34   SkipOverview bool
    34 35   TmpOutput string
    35 36   NmapScripts string
    36 37   GrepString string
     38 + InputFile string
    37 39  }
    38 40   
    39 41  // NetOptions options for net command
    skipped 44 lines
  • ■ ■ ■ ■ ■ ■
    modules/scan.go
    skipped 29 lines
    30 30   massOutput = tmpFile.Name()
    31 31   
    32 32   masscanCmd := fmt.Sprintf("sudo masscan --rate %v -p %v -oG %v %v", rate, ports, massOutput, input)
     33 + if options.Scan.All {
     34 + masscanCmd = fmt.Sprintf("sudo masscan --rate %v -p %v -oG %v -iL %v", rate, ports, massOutput, input)
     35 + }
     36 + 
    33 37   core.DebugF("Execute: %v", masscanCmd)
    34 38   command := []string{
    35 39   "bash",
    skipped 191 lines
Please wait...
Page is in error, reload to recover