Projects STRLCPY shodanidb Commits 8d9a781d
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    README.md
    skipped 26 lines
    27 27   -url Show only IP and Port
    28 28   -v Verbose mode
    29 29   -c Concurrency (default 5)
     30 + -nmap Run Nmap Service Detection
    30 31   
    31 32   
    32 33  # Simple Usage:
    skipped 14 lines
    47 48  # Show New Results by Comparing With The Old JSON File:
    48 49  cat ips.txt | shodanidb -compare output.json
    49 50   
     51 +```
     52 + 
     53 + 
     54 +### Compare
     55 + 
     56 +Before using this switch, you need save the output to a JSON file first:
     57 + 
     58 +```shell
     59 +echo 149.202.182.140 | shodanidb -json output.json
     60 +```
     61 + 
     62 +Then you can get the new resutls by comparing with the JSON file:
     63 + 
     64 +```shell
     65 +echo 149.202.182.140 | shodanidb -compare output.json
     66 +```
     67 + 
     68 +It can be used with the other switches:
     69 + 
     70 +```shell
     71 +echo 149.202.182.140 | shodanidb -nmap -compare output.json
     72 +echo 149.202.182.140 | shodanidb -url -compare output.json
     73 +echo 149.202.182.140 | shodanidb -url -nmap -compare output.json
     74 +```
     75 + 
     76 + 
     77 +### Nmap
     78 + 
     79 +To run this switch you need to have nmap installed.
     80 + 
     81 +It uses the nmap service detection with this command for every IP address:
     82 + 
     83 +```shell
     84 +nmap -sV -Pn IP -p Ports
     85 +```
     86 + 
     87 +It can be used with the other switches:
     88 + 
     89 +```shell
     90 +echo 149.202.182.140 | shodanidb -nmap
     91 +echo 149.202.182.140 | shodanidb -url -nmap
     92 +echo 149.202.182.140 | shodanidb -nmap -compare output.json
     93 +```
     94 + 
     95 + 
     96 +### url
     97 + 
     98 +This switch show the results as the `ip:port` format.
     99 + 
     100 +```shell
     101 +echo 149.202.182.140 | shodanidb -url
     102 +echo 149.202.182.140 | shodanidb -url -compare output.json
    50 103  ```
    51 104   
    52 105   
    skipped 5 lines
  • ■ ■ ■ ■ ■ ■
    go.mod
    skipped 6 lines
    7 7   github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e // indirect
    8 8   github.com/projectdiscovery/iputil v0.0.0-20210804143329-3a30fcde43f3 // indirect
    9 9   github.com/projectdiscovery/mapcidr v0.0.7 // indirect
     10 + github.com/Ullaakut/nmap/v2 v2.2.0 // indirect
     11 + github.com/pkg/errors v0.9.1 // indirect
     12 + golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
    10 13  )
    11 14   
  • ■ ■ ■ ■ ■ ■
    go.sum
     1 +github.com/Ullaakut/nmap/v2 v2.2.0 h1:68djp0dvUgAcsUx3gxmOI573GSAmPhHYkWvdgFdl4F8=
     2 +github.com/Ullaakut/nmap/v2 v2.2.0/go.mod h1:/6YyiW1Rgn7J6DAWCgL4CZZf6zJCFhB07PQzvjFfzLI=
    1 3  github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
    2 4  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
    3 5  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
    skipped 19 lines
    23 25  github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
    24 26  github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
    25 27  github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
     28 +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
     29 +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
    26 30  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
    27 31  github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e h1:7bwaFH1jvtOo5ndhTQgoA349ozhX+1dc4b6tbaPnBOA=
    28 32  github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs=
    skipped 15 lines
    44 48  github.com/yl2chen/cidranger v1.0.2/go.mod h1:9U1yz7WPYDwf0vpNWFaeRh0bjwz5RVgRy/9UEQfHl0g=
    45 49  golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
    46 50  golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
     51 +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
     52 +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
    47 53  golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
    48 54  golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
    49 55  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
    skipped 8 lines
  • ■ ■ ■ ■ ■ ■
    shodanidb.go
    skipped 15 lines
    16 16   "github.com/logrusorgru/aurora"
    17 17   "github.com/projectdiscovery/iputil"
    18 18   "github.com/projectdiscovery/mapcidr"
     19 + "github.com/Ullaakut/nmap/v2"
    19 20  )
    20 21   
    21 22  type Response struct {
    skipped 6 lines
    28 29  }
    29 30   
    30 31  var (
     32 + nmapScan bool
    31 33   urls bool
    32 34   noCPEs bool
    33 35   noTags bool
    skipped 18 lines
    52 54   flag.StringVar(&compareFile, "compare", "", "Compare new results with a JSON file")
    53 55   flag.BoolVar(&urls, "url", false, "Show only IP and Port")
    54 56   flag.IntVar(&concurrency, "c", 5, "Concurrency")
     57 + flag.BoolVar(&nmapScan, "nmap", false, "Run Nmap Service Detection")
    55 58   flag.Parse()
    56 59   
    57 60   var inputs, targets []string
    skipped 50 lines
    108 111   if jsonFile == "" && compareFile == "" {
    109 112   for i := 0; i < len(validData); i++ {
    110 113   printResult(validData[i])
     114 + }
     115 + if nmapScan {
     116 + fmt.Println()
     117 + for i := 0; i < len(validData); i++ {
     118 + runNmap(validData[i].IP, validData[i].Ports)
     119 + }
    111 120   }
    112 121   }
    113 122   
    114 123   if jsonFile != "" {
    115 124   saveJson(validData, jsonFile)
     125 + if nmapScan {
     126 + for i := 0; i < len(validData); i++ {
     127 + runNmap(validData[i].IP, validData[i].Ports)
     128 + }
     129 + }
    116 130   return
    117 131   }
    118 132   
    skipped 14 lines
    133 147   
    134 148   var jsonDatas []Response
    135 149   oldData := make(map[string]Response)
     150 + newIpPorts := make(map[string][]int32)
    136 151   
    137 152   theFile, err := os.Open(compareFile)
    138 153   if err != nil {
    skipped 11 lines
    150 165   for _, nData := range newData {
    151 166   oData, isInOld := oldData[nData.IP]
    152 167   if isInOld {
    153  - compareData(oData, nData)
     168 + newPorts := compareData(oData, nData)
     169 + if len(newPorts) != 0 {
     170 + newIpPorts[nData.IP] = newPorts
     171 + }
    154 172   } else {
    155 173   newPorts := nData.Ports
     174 + newIpPorts[nData.IP] = newPorts
    156 175   if urls {
    157 176   for _, port := range newPorts {
    158 177   fmt.Println(nData.IP + ":" + fmt.Sprint(port))
    skipped 5 lines
    164 183   }
    165 184   }
    166 185   }
     186 + if len(newIpPorts) != 0 {
     187 + fmt.Println()
     188 + }
     189 + if nmapScan {
     190 + for ip, ports := range newIpPorts {
     191 + runNmap(ip, ports)
     192 + }
     193 + }
    167 194   return
    168 195  }
    169 196   
    170 197   
    171  -func compareData(oldData Response, newData Response) {
     198 +func compareData(oldData Response, newData Response) []int32 {
     199 + var newPorts []int32
    172 200   if !reflect.DeepEqual(oldData.Ports, newData.Ports) {
    173 201   for _, nP := range newData.Ports {
    174 202   isNew := true
    skipped 9 lines
    184 212   fmt.Println(newData.IP)
    185 213   fmt.Println(fmt.Sprint(nP) + "\n")
    186 214   }
     215 + newPorts = append(newPorts, nP)
    187 216   }
    188 217   }
    189 218   }
    skipped 15 lines
    205 234   }
    206 235   }
    207 236   }
    208  - return
     237 + return newPorts
    209 238  }
    210 239   
    211 240   
    skipped 137 lines
    349 378   
    350 379   fmt.Println(builder.String())
    351 380  }
     381 + 
     382 +func runNmap(target string, intPorts []int32) {
     383 + 
     384 + ports := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(intPorts)), ", "), "[]")
     385 + 
     386 + scanner, err := nmap.NewScanner(
     387 + nmap.WithTargets(target),
     388 + nmap.WithPorts(ports),
     389 + nmap.WithServiceInfo(),
     390 + nmap.WithSkipHostDiscovery(),
     391 + )
     392 + if err != nil {
     393 + log.Fatalf("unable to create nmap scanner: %v", err)
     394 + }
     395 + 
     396 + result, warnings, err := scanner.Run()
     397 + if err != nil {
     398 + log.Fatalf("unable to run nmap scan: %v", err)
     399 + }
     400 + 
     401 + if warnings != nil {
     402 + if verbose {
     403 + log.Printf("Warnings: \n %v", warnings)
     404 + }
     405 + }
     406 + 
     407 + for _, host := range result.Hosts {
     408 + if len(host.Ports) == 0 || len(host.Addresses) == 0 {
     409 + continue
     410 + }
     411 + for _, port := range host.Ports {
     412 + fmt.Printf("%s:%d/%s %s %s %s %s %s\n", host.Addresses[0], port.ID, port.Protocol, port.State, port.Service.Name, port.Service.Product, port.Service.ExtraInfo, port.Service.Version)
     413 + }
     414 + }
     415 +}
Please wait...
Page is in error, reload to recover