Class: Mihari::Structs::Shodan::Response
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Mihari::Structs::Shodan::Response
- Includes:
- MemoWise
- Defined in:
- lib/mihari/structs/shodan.rb
Instance Attribute Summary collapse
- #matches ⇒ Array<Match> readonly
- #total ⇒ Integer readonly
Class Method Summary collapse
Instance Method Summary collapse
- #artifacts ⇒ Array<Mihari::Models::Artifact>
-
#collect_cpes_by_ip(ip) ⇒ Array<String>
Collect CPE from matches.
-
#collect_hostnames_by_ip(ip) ⇒ Array<String>
Collect hostnames from matches.
-
#collect_metadata_by_ip(ip) ⇒ Array<Hash>
Collect metadata from matches.
-
#collect_ports_by_ip(ip) ⇒ Array<String>
Collect ports from matches.
-
#collect_vulns_by_ip(ip) ⇒ Array<String>
Collect vulnerabilities from matches.
- #select_matches_by_ip(ip) ⇒ Array<Mihari::Structs::Shodan::Match>
Instance Attribute Details
#matches ⇒ Array<Match> (readonly)
127 |
# File 'lib/mihari/structs/shodan.rb', line 127 attribute :matches, Types.Array(Match) |
#total ⇒ Integer (readonly)
131 |
# File 'lib/mihari/structs/shodan.rb', line 131 attribute :total, Types::Int |
Class Method Details
.from_dynamic!(d) ⇒ Result
232 233 234 235 236 237 238 |
# File 'lib/mihari/structs/shodan.rb', line 232 def from_dynamic!(d) d = Types::Hash[d] new( matches: d.fetch("matches", []).map { |x| Match.from_dynamic!(x) }, total: d.fetch("total") ) end |
Instance Method Details
#artifacts ⇒ Array<Mihari::Models::Artifact>
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/mihari/structs/shodan.rb', line 202 def artifacts matches.map do |match| = (match.ip_str) ports = collect_ports_by_ip(match.ip_str).map { |port| Models::Port.new(number: port) } reverse_dns_names = collect_hostnames_by_ip(match.ip_str).map do |name| Models::ReverseDnsName.new(name:) end cpes = collect_cpes_by_ip(match.ip_str).map { |name| Models::CPE.new(name:) } vulnerabilities = collect_vulns_by_ip(match.ip_str).map { |name| Models::Vulnerability.new(name:) } Mihari::Models::Artifact.new( data: match.ip_str, metadata:, autonomous_system: match.autonomous_system, geolocation: match.location.geolocation, ports:, reverse_dns_names:, cpes:, vulnerabilities: ) end end |
#collect_cpes_by_ip(ip) ⇒ Array<String>
Collect CPE from matches
183 184 185 |
# File 'lib/mihari/structs/shodan.rb', line 183 def collect_cpes_by_ip(ip) select_matches_by_ip(ip).map(&:cpe).flatten.uniq end |
#collect_hostnames_by_ip(ip) ⇒ Array<String>
Collect hostnames from matches
172 173 174 |
# File 'lib/mihari/structs/shodan.rb', line 172 def collect_hostnames_by_ip(ip) select_matches_by_ip(ip).map(&:hostnames).flatten.uniq end |
#collect_metadata_by_ip(ip) ⇒ Array<Hash>
Collect metadata from matches
150 151 152 |
# File 'lib/mihari/structs/shodan.rb', line 150 def (ip) select_matches_by_ip(ip).map(&:metadata) end |
#collect_ports_by_ip(ip) ⇒ Array<String>
Collect ports from matches
161 162 163 |
# File 'lib/mihari/structs/shodan.rb', line 161 def collect_ports_by_ip(ip) select_matches_by_ip(ip).map(&:port) end |
#collect_vulns_by_ip(ip) ⇒ Array<String>
Collect vulnerabilities from matches
194 195 196 197 |
# File 'lib/mihari/structs/shodan.rb', line 194 def collect_vulns_by_ip(ip) # NOTE: vuln keys = CVE IDs select_matches_by_ip(ip).map { |match| match.vulns.keys }.flatten.uniq end |
#select_matches_by_ip(ip) ⇒ Array<Mihari::Structs::Shodan::Match>
138 139 140 |
# File 'lib/mihari/structs/shodan.rb', line 138 def select_matches_by_ip(ip) matches.select { |match| match.ip_str == ip } end |