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

#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)


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

attribute :metadata, Types::Hash

#portInteger (readonly)

Returns:

  • (Integer)


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

attribute :port, Types::Int

Class Method Details

.from_dynamic!(d) ⇒ Match

Parameters:

  • d (Hash)

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mihari/structs/shodan.rb', line 89

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: hostnames,
    location: Location.from_dynamic!(d.fetch("location")),
    domains: d.fetch("domains"),
    ip_str: d.fetch("ip_str"),
    port: d.fetch("port"),
    metadata: d
  )
end

Instance Method Details

#_asnMihari::AutonomousSystem?

Returns:

  • (Mihari::AutonomousSystem, nil)


77
78
79
80
81
# File 'lib/mihari/structs/shodan.rb', line 77

def _asn
  return nil if asn.nil?

  Mihari::Models::AutonomousSystem.new(asn: normalize_asn(asn))
end