Class: Mihari::Structs::Shodan::Match

Inherits:
Dry::Struct
  • Object
show all
Includes:
Concerns::AutonomousSystemNormalizable
Defined in:
lib/mihari/structs/shodan.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::AutonomousSystemNormalizable

#normalize_asn

Instance Attribute Details

#asnString? (readonly)

Returns:

  • (String, nil)


48
# File 'lib/mihari/structs/shodan.rb', line 48

attribute :asn, Types::String.optional

#cpeArray<String> (readonly)

Returns:

  • (Array<String>)


72
# File 'lib/mihari/structs/shodan.rb', line 72

attribute :cpe, Types::Array(Types::String)

#domainsArray<String> (readonly)

Returns:

  • (Array<String>)


60
# File 'lib/mihari/structs/shodan.rb', line 60

attribute :domains, Types.Array(Types::String)

#hostnameArray<String> (readonly)

Returns:

  • (Array<String>)


52
# File 'lib/mihari/structs/shodan.rb', line 52

attribute :hostnames, Types.Array(Types::String)

#ip_strString (readonly)

Returns:

  • (String)


64
# File 'lib/mihari/structs/shodan.rb', line 64

attribute :ip_str, Types::String

#locationLocation (readonly)

Returns:



56
# File 'lib/mihari/structs/shodan.rb', line 56

attribute :location, Location

#metadataHash (readonly)

Returns:

  • (Hash)


80
# File 'lib/mihari/structs/shodan.rb', line 80

attribute :metadata, Types::Hash

#portInteger (readonly)

Returns:

  • (Integer)


68
# File 'lib/mihari/structs/shodan.rb', line 68

attribute :port, Types::Int

#vulnsHash (readonly)

Returns:

  • (Hash)


76
# File 'lib/mihari/structs/shodan.rb', line 76

attribute :vulns, Types::Hash

Class Method Details

.from_dynamic!(d) ⇒ Match

Parameters:

  • d (Hash)

Returns:



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_systemMihari::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