Projects STRLCPY metabigor Commits b1188f07
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    cmd/scan.go
    skipped 24 lines
    25 25   
    26 26   scanCmd.Flags().StringP("ports", "p", "0-65535", "Port range for previous command")
    27 27   scanCmd.Flags().StringP("rate", "r", "5000", "rate limit for masscan command")
    28  - scanCmd.Flags().Bool("detail", false, "Do Nmap scan based on previous output")
     28 + scanCmd.Flags().BoolP("detail","D", false, "Do Nmap scan based on previous output")
    29 29   
    30 30   scanCmd.Flags().BoolP("flat", "f", false, "format output like this: 1.2.3.4:443")
    31 31   scanCmd.Flags().BoolP("skip-masscan", "s", false, "run nmap from input format like this: 1.2.3.4:443")
    32  - scanCmd.Flags().String("nmap-script", "", "nmap scripts")
     32 + scanCmd.Flags().StringP("script","S", "", "nmap scripts")
     33 + scanCmd.Flags().StringP("grep","g", "", "match string to confirm script success")
    33 34   // only parse scan
    34 35   scanCmd.Flags().StringP("result-folder", "R", "", "Result folder")
    35 36   
    skipped 2 lines
    38 39  }
    39 40   
    40 41  func runScan(cmd *cobra.Command, args []string) error {
    41  - options.Scan.NmapScripts, _ = cmd.Flags().GetString("nmap-script")
     42 + options.Scan.NmapScripts, _ = cmd.Flags().GetString("script")
     43 + options.Scan.GrepString, _ = cmd.Flags().GetString("grep")
    42 44   options.Scan.Ports, _ = cmd.Flags().GetString("ports")
    43 45   options.Scan.Rate, _ = cmd.Flags().GetString("rate")
    44 46   options.Scan.Detail, _ = cmd.Flags().GetBool("detail")
    skipped 119 lines
    164 166   core.DebugF("Reading: %v", filename)
    165 167   if strings.HasSuffix(file.Name(), "xml") && strings.HasPrefix(filename, "nmap") {
    166 168   data := core.GetFileContent(filename)
    167  - rawResult := modules.ParsingNmap(data)
     169 + rawResult := modules.ParsingNmap(data, options)
    168 170   for k, v := range rawResult {
    169 171   fmt.Printf("%v - %v\n", k, strings.Join(v, ","))
    170 172   }
    skipped 23 lines
  • ■ ■ ■ ■ ■ ■
    cmd/search.go
    skipped 95 lines
    96 96   case "fofa":
    97 97   data = append(data, modules.FoFaSearch(options)...)
    98 98   break
     99 + case "ip":
     100 + data = append(data, modules.IPSearch(options)...)
     101 + break
    99 102   }
     103 + 
    100 104   return data
    101 105  }
    102 106   
    skipped 20 lines
  • ■ ■ ■ ■ ■
    core/options.go
    skipped 13 lines
    14 14   Timeout int
    15 15   Verbose bool
    16 16   Debug bool
    17  - // Ports string
    18  - // Rate string
    19 17   Scan ScanOptions
    20 18   Net NetOptions
    21 19   Search SearchOptions
    skipped 8 lines
    30 28   SkipOverview bool
    31 29   TmpOutput string
    32 30   NmapScripts string
     31 + GrepString string
    33 32  }
    34 33   
    35 34  // NetOptions options for net command
    skipped 32 lines
  • ■ ■ ■ ■
    core/version.go
    skipped 1 lines
    2 2   
    3 3  const (
    4 4   // VERSION current Metabigor version
    5  - VERSION = "beta v1.1"
     5 + VERSION = "beta v1.2"
    6 6   // AUTHOR author of this
    7 7   AUTHOR = "@j3ssiejjj"
    8 8  )
    skipped 1 lines
  • ■ ■ ■ ■ ■ ■
    modules/ip.go
     1 +package modules
     2 + 
     3 +import (
     4 + "fmt"
     5 + "github.com/PuerkitoBio/goquery"
     6 + "github.com/j3ssie/metabigor/core"
     7 + "strings"
     8 +)
     9 + 
     10 +// Onyphe get IPInfo from https://www.onyphe.io
     11 +func Onyphe(query string, options core.Options) []string {
     12 + url := fmt.Sprintf(`https://www.onyphe.io/search/?query=%v`, query)
     13 + var result []string
     14 + core.InforF("Get data from: %v", url)
     15 + content := core.SendGET(url, options)
     16 + if content == "" {
     17 + return result
     18 + }
     19 + data := ParseOnyphe(content, options)
     20 + 
     21 + for _, item := range data {
     22 + result = append(result, fmt.Sprintf("%v:%v", query, item))
     23 + }
     24 + return result
     25 +}
     26 + 
     27 +// ParseOnyphe parsing data from Onyphe
     28 +func ParseOnyphe(content string, options core.Options) []string {
     29 + var result []string
     30 + doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
     31 + if err != nil {
     32 + return result
     33 + }
     34 + 
     35 + // searching for data
     36 + info := make(map[string]string)
     37 + doc.Find(".features-list").Each(func(i int, s *goquery.Selection) {
     38 + text := s.Text()
     39 + // basic info part
     40 + if strings.Contains(text, "geoloc") {
     41 + tds := s.Find("td").Children()
     42 + if strings.Contains(tds.Text(), "organization") {
     43 + for i := range tds.Nodes {
     44 + if i == 0 {
     45 + tag := tds.Eq(i)
     46 + data := tds.Eq(i + 1)
     47 + info[tag.Text()] = data.Text()
     48 + continue
     49 + }
     50 + if i%2 != 0 {
     51 + tag := tds.Eq(i)
     52 + data := tds.Eq(i + 1)
     53 + info[tag.Text()] = data.Text()
     54 + }
     55 + }
     56 + }
     57 + }
     58 + // open port
     59 + if strings.Contains(text, "synscan") {
     60 + var port string
     61 + s.Find("a").Each(func(i int, tag *goquery.Selection) {
     62 + href, _ := tag.Attr("href")
     63 + if strings.Contains(href, "port") {
     64 + port = tag.Text()
     65 + result = append(result, port)
     66 + }
     67 + })
     68 + }
     69 + })
     70 + 
     71 + // more info in verbose mode
     72 + if options.Verbose {
     73 + for k,v := range info {
     74 + data := fmt.Sprintf("%v|%v", k,v)
     75 + result = append(result, data)
     76 + }
     77 + }
     78 + return result
     79 +}
     80 + 
  • ■ ■ ■ ■ ■ ■
    modules/ip_test.go
     1 +package modules
     2 + 
     3 +import (
     4 + "fmt"
     5 + "github.com/j3ssie/metabigor/core"
     6 + "testing"
     7 +)
     8 + 
     9 +func TestParseOnyphe(t *testing.T) {
     10 + var options core.Options
     11 + raw := core.GetFileContent("/tmp/testttt/ony.html")
     12 + result := ParseOnyphe(raw, options)
     13 + fmt.Println(result)
     14 + if len(result) == 0 {
     15 + t.Errorf("Error parseOnyphe")
     16 + }
     17 + 
     18 +}
  • ■ ■ ■ ■ ■
    modules/netblock.go
    skipped 38 lines
    39 39   core.InforF(fmt.Sprintf("%s - %s", cidr, desc))
    40 40   result = append(result, fmt.Sprintf("%s", cidr))
    41 41   }
    42  - 
    43 42   })
    44 43   return result
    45 44  }
    skipped 150 lines
  • ■ ■ ■ ■ ■ ■
    modules/scan.go
    skipped 4 lines
    5 5   "io/ioutil"
    6 6   "os"
    7 7   "os/exec"
     8 + "regexp"
    8 9   "strings"
    9 10   
    10 11   "github.com/PuerkitoBio/goquery"
    skipped 83 lines
    94 95   }
    95 96   // result := ""
    96 97   data := core.GetFileContent(realNmapOutput)
    97  - rawResult := ParsingNmap(data)
     98 + rawResult := ParsingNmap(data, options)
    98 99   
    99 100   for k, v := range rawResult {
    100 101   if options.Scan.Flat {
    skipped 42 lines
    143 144  }
    144 145   
    145 146  // ParsingNmap parse result from nmap XML format
    146  -func ParsingNmap(raw string) map[string][]string {
     147 +func ParsingNmap(raw string, options core.Options) map[string][]string {
    147 148   result := make(map[string][]string)
    148 149   
    149 150   doc, err := goquery.NewDocumentFromReader(strings.NewReader(raw))
    skipped 2 lines
    152 153   }
    153 154   doc.Find("host").Each(func(i int, h *goquery.Selection) {
    154 155   ip, _ := h.Find("address").First().Attr("addr")
     156 + 
    155 157   h.Find("port").Each(func(j int, s *goquery.Selection) {
    156 158   service, _ := s.Find("service").First().Attr("name")
    157 159   product, ok := s.Find("service").First().Attr("product")
    skipped 2 lines
    160 162   }
    161 163   port, _ := s.Attr("portid")
    162 164   info := fmt.Sprintf("%v/%v/%v", port, service, product)
    163  - // fmt.Println(ip, port, service)
    164 165   result[ip] = append(result[ip], strings.TrimSpace(info))
    165 166   })
     167 + 
     168 + if options.Scan.NmapScripts != "" {
     169 + h.Find("script").Each(func(j int, s *goquery.Selection) {
     170 + id, _ := s.Attr("id")
     171 + scriptOutput, _ := s.Attr("output")
     172 + 
     173 + if scriptOutput != "" {
     174 + // grep script output with grepString
     175 + if options.Scan.GrepString != "" {
     176 + var vulnerable bool
     177 + if strings.Contains(scriptOutput, options.Scan.GrepString) {
     178 + vulnerable = true
     179 + } else {
     180 + r, err := regexp.Compile(options.Scan.GrepString)
     181 + if err == nil {
     182 + matches := r.FindStringSubmatch(scriptOutput)
     183 + if len(matches) > 0 {
     184 + vulnerable = true
     185 + }
     186 + }
     187 + }
     188 + if vulnerable {
     189 + vul := fmt.Sprintf("/vulnerable|%v", id)
     190 + result[ip] = append(result[ip], strings.TrimSpace(vul))
     191 + }
     192 + }
     193 + 
     194 + scriptOutput = strings.Replace(scriptOutput, "\n", "\\n", -1)
     195 + info := fmt.Sprintf("/script|%v;;out|%v", id, scriptOutput)
     196 + result[ip] = append(result[ip], strings.TrimSpace(info))
     197 + }
     198 + })
     199 + }
    166 200   })
    167 201   
    168 202   return result
    skipped 2 lines
  • ■ ■ ■ ■ ■ ■
    modules/scan_test.go
    skipped 15 lines
    16 16   }
    17 17  }
    18 18  func TestParsingNmap(t *testing.T) {
    19  - // var options core.Options
     19 + var options core.Options
     20 + options.Scan.NmapScripts = "vulners.nse"
    20 21   // options.Input = "103.102.128.0/24"
    21  - raw := core.GetFileContent("/tmp/tau/tl.xml")
    22  - result := ParsingNmap(raw)
     22 + raw := core.GetFileContent("/tmp/testttt/samm.xml")
     23 + result := ParsingNmap(raw, options)
    23 24   fmt.Println(result)
    24 25   if len(result) == 0 {
    25 26   t.Errorf("Error RunMasscan")
    skipped 12 lines
  • ■ ■ ■ ■ ■ ■
    modules/search.go
    skipped 10 lines
    11 11   "github.com/j3ssie/metabigor/core"
    12 12  )
    13 13   
     14 +// IPSearch doing searching on Onyphe
     15 +func IPSearch(options core.Options) []string {
     16 + var result []string
     17 + result = append(result, singleIPSearch(options.Search.Query, options)...)
     18 + if !options.Search.Optimize {
     19 + return result
     20 + }
     21 + return result
     22 +}
     23 + 
     24 +func singleIPSearch(query string, options core.Options) []string {
     25 + var result []string
     26 + result = append(result, Onyphe(query, options)...)
     27 + return result
     28 +}
     29 + 
    14 30  // FoFaSearch doing searching on FoFa
    15 31  func FoFaSearch(options core.Options) []string {
    16 32   var result []string
    skipped 102 lines
Please wait...
Page is in error, reload to recover