Sha256: 447dc382408a315baa33bf540b6d7aaca3d212a6fcf559e2981848b306ac8cb6

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

require_relative 'utils.rb'

# frozen_string_literal: true

module Shodanz
  module API
    # The Exploits API provides access to several exploit
    # and vulnerability data sources. At the moment, it
    # searches across the following:
    #  - Exploit DB
    #  - Metasploit
    #  - Common Vulnerabilities and Exposures (CVE)
    #
    # @author Kent 'picat' Gruber
    class Exploits
      include Shodanz::API::Utils

      # @return [String]
      attr_accessor :key

      # The path to the REST API endpoint.
      URL = 'https://exploits.shodan.io/'

      # @param key [String] SHODAN API key, defaulted to
      # the *SHODAN_API_KEY* enviroment variable.
      def initialize(key: ENV['SHODAN_API_KEY'])
        @url      = URL
        @client   = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
        self.key  = key

        warn 'No key has been found or provided!' unless key?
      end

      # Check if there's an API key.
      # @return [String]
      def key?
        return true if @key

        false
      end

      # Search across a variety of data sources for exploits and
      # use facets to get summary information.
      # == Example
      #   api.search("SQL", port: 443)
      #   api.search(port: 22)
      #   api.search(type: "dos")
      def search(query = '', facets: {}, page: 1, **params)
        params[:query] = query
        params = turn_into_query(**params)
        facets = turn_into_facets(**facets)
        params[:page] = page
        get('api/search', **params.merge(**facets))
      end

      # This method behaves identical to the "/search" method with
      # the difference that it doesn't return any results.
      # == Example
      #   api.count(type: "dos")
      def count(query = '', facets: {}, page: 1, **params)
        params[:query] = query
        params = turn_into_query(**params)
        facets = turn_into_facets(**facets)
        params[:page] = page
        get('api/count', **params.merge(**facets))
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shodanz-2.0.8 lib/shodanz/apis/exploits.rb
shodanz-2.0.7 lib/shodanz/apis/exploits.rb
shodanz-2.0.6 lib/shodanz/apis/exploits.rb
shodanz-2.0.5 lib/shodanz/apis/exploits.rb
shodanz-2.0.4 lib/shodanz/apis/exploits.rb
shodanz-2.0.3 lib/shodanz/apis/exploits.rb