Sha256: 8bf05ef4aff2d3960d4364f9145bd877dfe45fe593bbaddbda3d64cbe62c1d77

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "urlscan"

module Mihari
  module Analyzers
    class Urlscan < Base
      attr_reader :title
      attr_reader :description
      attr_reader :query
      attr_reader :tags
      attr_reader :target_type

      def initialize(query, title: nil, description: nil, tags: [], target_type: "url")
        super()

        @query = query
        @title = title || "urlscan lookup"
        @description = description || "query = #{query}"
        @tags = tags
        @target_type = target_type

        raise TypeError, "type should be url, domain or ip." unless valid_target_type?
      end

      def artifacts
        result = search
        return [] unless result

        results = result.dig("results") || []
        results.map do |match|
          match.dig "page", target_type
        end.compact.uniq
      end

      private

      def api
        @api ||= ::UrlScan::API.new
      end

      def search
        api.search(query)
      rescue ::UrlScan::ResponseError => _e
        nil
      end

      def valid_target_type?
        %w(url domain ip).include? target_type
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-0.13.0 lib/mihari/analyzers/urlscan.rb
mihari-0.12.0 lib/mihari/analyzers/urlscan.rb