Class: Mihari::Structs::Shodan::Match
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Mihari::Structs::Shodan::Match
- Includes:
- Concerns::AutonomousSystemNormalizable
- Defined in:
- lib/mihari/structs/shodan.rb
Instance Attribute Summary collapse
- #asn ⇒ String? readonly
- #cpe ⇒ Array<String> readonly
- #domains ⇒ Array<String> readonly
- #hostname ⇒ Array<String> readonly
- #ip_str ⇒ String readonly
- #location ⇒ Location readonly
- #metadata ⇒ Hash readonly
- #port ⇒ Integer readonly
- #vulns ⇒ Hash readonly
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Concerns::AutonomousSystemNormalizable
Instance Attribute Details
#asn ⇒ String? (readonly)
48 |
# File 'lib/mihari/structs/shodan.rb', line 48 attribute :asn, Types::String.optional |
#cpe ⇒ Array<String> (readonly)
72 |
# File 'lib/mihari/structs/shodan.rb', line 72 attribute :cpe, Types::Array(Types::String) |
#domains ⇒ Array<String> (readonly)
60 |
# File 'lib/mihari/structs/shodan.rb', line 60 attribute :domains, Types.Array(Types::String) |
#hostname ⇒ Array<String> (readonly)
52 |
# File 'lib/mihari/structs/shodan.rb', line 52 attribute :hostnames, Types.Array(Types::String) |
#ip_str ⇒ String (readonly)
64 |
# File 'lib/mihari/structs/shodan.rb', line 64 attribute :ip_str, Types::String |
#location ⇒ Location (readonly)
56 |
# File 'lib/mihari/structs/shodan.rb', line 56 attribute :location, Location |
#metadata ⇒ Hash (readonly)
80 |
# File 'lib/mihari/structs/shodan.rb', line 80 attribute :metadata, Types::Hash |
Class Method Details
.from_dynamic!(d) ⇒ Match
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mihari/structs/shodan.rb', line 97 def from_dynamic!(d) d = Types::Hash[d] # hostnames should be an array of string but sometimes Shodan returns a string # e.g. "hostnames": "set(['149.28.146.131.vultr.com', 'rebs.ga'])", # https://github.com/ninoseki/mihari/issues/424 # so use an empty array if hostnames is a string hostnames = d.fetch("hostnames") hostnames = [] if hostnames.is_a?(String) new( asn: d["asn"], hostnames:, location: Location.from_dynamic!(d.fetch("location")), domains: d.fetch("domains"), ip_str: d.fetch("ip_str"), port: d.fetch("port"), cpe: d["cpe"] || [], vulns: d["vulns"] || {}, metadata: d ) end |
Instance Method Details
#autonomous_system ⇒ Mihari::Models::AutonomousSystem?
85 86 87 88 89 |
# File 'lib/mihari/structs/shodan.rb', line 85 def autonomous_system return nil if asn.nil? Models::AutonomousSystem.new(number: normalize_asn(asn)) end |