| skipped 15 lines |
16 | 16 | | if content == "" { |
17 | 17 | | return result |
18 | 18 | | } |
19 | | - | data := ParseOnyphe(content, options) |
| 19 | + | info := ParseOnyphe(content) |
| 20 | + | if options.Verbose { |
| 21 | + | result = append(result, fmt.Sprintf("[onyphe] %v ports|%v", query, info["ports"])) |
| 22 | + | return result |
| 23 | + | } |
| 24 | + | for key, value := range info { |
| 25 | + | if key != "port" { |
| 26 | + | result = append(result, fmt.Sprintf("[onyphe] %v %v|%v", query, key, value)) |
| 27 | + | } |
| 28 | + | } |
| 29 | + | return result |
| 30 | + | } |
20 | 31 | | |
21 | | - | for _, item := range data { |
22 | | - | result = append(result, fmt.Sprintf("%v:%v", query, item)) |
| 32 | + | // Shodan get IPInfo from https://www.shodan.io |
| 33 | + | func Shodan(query string, options core.Options) []string { |
| 34 | + | url := fmt.Sprintf(`https://www.shodan.io/host/%v`, query) |
| 35 | + | var result []string |
| 36 | + | core.InforF("Get data from: %v", url) |
| 37 | + | content := core.SendGET(url, options) |
| 38 | + | if content == "" { |
| 39 | + | core.DebugF("Error in sending to Shodan") |
| 40 | + | return result |
| 41 | + | } |
| 42 | + | info := ParseShodan(content) |
| 43 | + | if options.Verbose { |
| 44 | + | result = append(result, fmt.Sprintf("[shodan] %v ports|%v", query, info["ports"])) |
| 45 | + | return result |
| 46 | + | } |
| 47 | + | for key, value := range info { |
| 48 | + | if key != "port" { |
| 49 | + | result = append(result, fmt.Sprintf("[shodan] %v %v|%v", query, key, value)) |
| 50 | + | } |
23 | 51 | | } |
24 | 52 | | return result |
25 | 53 | | } |
26 | 54 | | |
27 | 55 | | // ParseOnyphe parsing data from Onyphe |
28 | | - | func ParseOnyphe(content string, options core.Options) []string { |
29 | | - | var result []string |
| 56 | + | func ParseOnyphe(content string) map[string]string { |
| 57 | + | info := make(map[string]string) |
| 58 | + | |
30 | 59 | | doc, err := goquery.NewDocumentFromReader(strings.NewReader(content)) |
31 | 60 | | if err != nil { |
32 | | - | return result |
| 61 | + | core.DebugF("Error parsing HTML") |
| 62 | + | return info |
33 | 63 | | } |
34 | 64 | | |
35 | 65 | | // searching for data |
36 | | - | info := make(map[string]string) |
37 | 66 | | doc.Find(".features-list").Each(func(i int, s *goquery.Selection) { |
38 | 67 | | text := s.Text() |
39 | 68 | | // basic info part |
40 | 69 | | 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 | | - | } |
| 70 | + | s.Find("tr").Each(func(i int, tr *goquery.Selection) { |
| 71 | + | text := tr.Text() |
| 72 | + | if strings.Contains(text, "organization") { |
| 73 | + | organization := strings.Replace(text, "organization", "", -1) |
| 74 | + | info["organization"] = organization |
| 75 | + | } |
| 76 | + | |
| 77 | + | if strings.Contains(text, "asn") { |
| 78 | + | asn := strings.Replace(text, "asn", "", -1) |
| 79 | + | info["asn"] = asn |
| 80 | + | } |
| 81 | + | |
| 82 | + | if strings.Contains(text, "subnet") { |
| 83 | + | subnet := strings.Replace(text, "subnet", "", -1) |
| 84 | + | info["subnet"] = subnet |
| 85 | + | } |
| 86 | + | |
| 87 | + | if strings.Contains(text, "city") { |
| 88 | + | city := strings.Replace(text, "city", "", -1) |
| 89 | + | info["city"] = city |
| 90 | + | } |
| 91 | + | |
| 92 | + | if strings.Contains(text, "country") { |
| 93 | + | country := strings.Replace(text, "country", "", -1) |
| 94 | + | info["country"] = country |
55 | 95 | | } |
56 | | - | } |
| 96 | + | }) |
57 | 97 | | } |
| 98 | + | |
58 | 99 | | // open port |
59 | 100 | | if strings.Contains(text, "synscan") { |
60 | | - | var port string |
| 101 | + | var ports []string |
61 | 102 | | s.Find("a").Each(func(i int, tag *goquery.Selection) { |
62 | 103 | | href, _ := tag.Attr("href") |
63 | 104 | | if strings.Contains(href, "port") { |
64 | | - | port = tag.Text() |
65 | | - | result = append(result, port) |
| 105 | + | port := tag.Text() |
| 106 | + | ports = append(ports, port) |
| 107 | + | } |
| 108 | + | }) |
| 109 | + | info["ports"] = strings.Join(ports, ",") |
| 110 | + | } |
| 111 | + | }) |
| 112 | + | return info |
| 113 | + | } |
| 114 | + | |
| 115 | + | // ParseShodan parsing data from Onyphe |
| 116 | + | func ParseShodan(content string) map[string]string { |
| 117 | + | info := make(map[string]string) |
| 118 | + | doc, err := goquery.NewDocumentFromReader(strings.NewReader(content)) |
| 119 | + | if err != nil { |
| 120 | + | core.DebugF("Error parsing HTML") |
| 121 | + | return info |
| 122 | + | } |
| 123 | + | |
| 124 | + | // searching for data |
| 125 | + | doc.Find(".table").Each(func(i int, s *goquery.Selection) { |
| 126 | + | text := s.Text() |
| 127 | + | // basic info part |
| 128 | + | if strings.Contains(text, "Country") { |
| 129 | + | s.Find("tr").Each(func(i int, tr *goquery.Selection) { |
| 130 | + | text := tr.Text() |
| 131 | + | if strings.Contains(text, "Organization") { |
| 132 | + | organization := strings.Replace(text, "Organization", "", -1) |
| 133 | + | info["organization"] = strings.TrimSpace(organization) |
| 134 | + | } |
| 135 | + | |
| 136 | + | if strings.Contains(text, "ASN") { |
| 137 | + | asn := strings.Replace(text, "ASN", "", -1) |
| 138 | + | info["asn"] = strings.TrimSpace(asn) |
| 139 | + | } |
| 140 | + | |
| 141 | + | if strings.Contains(text, "ISP") { |
| 142 | + | ISP := strings.Replace(text, "ISP", "", -1) |
| 143 | + | info["isp"] = strings.TrimSpace(ISP) |
| 144 | + | } |
| 145 | + | |
| 146 | + | if strings.Contains(text, "Hostnames") { |
| 147 | + | hostnames := strings.Replace(text, "Hostnames", "", -1) |
| 148 | + | info["hostnames"] = strings.TrimSpace(hostnames) |
| 149 | + | } |
| 150 | + | |
| 151 | + | if strings.Contains(text, "Country") { |
| 152 | + | country := strings.Replace(text, "Country", "", -1) |
| 153 | + | info["country"] = strings.TrimSpace(country) |
66 | 154 | | } |
67 | 155 | | }) |
68 | 156 | | } |
69 | 157 | | }) |
70 | 158 | | |
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) |
| 159 | + | // ports part |
| 160 | + | var ports []string |
| 161 | + | doc.Find(".services").Each(func(i int, s *goquery.Selection) { |
| 162 | + | port := strings.Replace(strings.TrimSpace(s.Find(".service-details").Text()), "\n", "/", -1) |
| 163 | + | port = strings.Replace(port, "///", "", -1) |
| 164 | + | if port != "" { |
| 165 | + | ports = append(ports, port) |
76 | 166 | | } |
77 | | - | } |
78 | | - | return result |
| 167 | + | }) |
| 168 | + | info["ports"] = strings.Join(ports, ",") |
| 169 | + | return info |
79 | 170 | | } |
80 | 171 | | |