lib/mihari/analyzers/shodan.rb in mihari-1.4.1 vs lib/mihari/analyzers/shodan.rb in mihari-1.5.0

- old
+ new

@@ -3,14 +3,11 @@ require "shodan" module Mihari module Analyzers class Shodan < Base - attr_reader :title - attr_reader :description - attr_reader :query - attr_reader :tags + attr_reader :title, :description, :query, :tags def initialize(query, title: nil, description: nil, tags: []) super() @query = query @@ -22,23 +19,23 @@ def artifacts results = search return [] unless results || results.empty? results.map do |result| - matches = result.dig("matches") || [] + matches = result["matches"] || [] matches.map do |match| - match.dig "ip_str" + match["ip_str"] end.compact end.flatten.compact.uniq end private PAGE_SIZE = 100 def config_keys - %w(shodan_api_key) + %w[shodan_api_key] end def api @api ||= ::Shodan::API.new(key: Mihari.config.shodan_api_key) end @@ -56,10 +53,10 @@ (1..Float::INFINITY).each do |page| res = search_with_page(query, page: page) break unless res responses << res - break if res.dig("total").to_i <= page * PAGE_SIZE + break if res["total"].to_i <= page * PAGE_SIZE end responses end end end