Module: PWN::Plugins::Hunter

Defined in:
lib/pwn/plugins/hunter.rb

Overview

This plugin is used for interacting w/ Hunter’s REST API using the ‘rest’ browser type of PWN::Plugins::TransparentBrowser.

This is based on the following Hunter API Specification:

hunter.how/search-api

Constant Summary collapse

@@logger =
PWN::Plugins::PWNLogger.create

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



135
136
137
138
139
# File 'lib/pwn/plugins/hunter.rb', line 135

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.helpObject

Display Usage for this Module



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/pwn/plugins/hunter.rb', line 143

public_class_method def self.help
  puts "USAGE:
    search_results = #{self}.query(
      api_key: 'required hunter api key',
      query: 'required - hunter search query',
      start_time: 'required - start date for the search (format is yyyy-mm-dd)',
      end_time: 'required - end date for the search (format is yyyy-mm-dd)',
      start_page: 'optional - starting page number for pagination (default is 1)',
      page_size: 'optional - number of results per page (default is 10)',
      fields: 'optional - comma-separated list of fields 'product,transport_protocol,protocol,banner,country,province,city,asn,org,web,updated_at' (default is nil)'
    )

    #{self}.authors
  "
end

.search(opts = {}) ⇒ Object

Supported Method Parameters

search_results = PWN::Plugins::Hunter.search(

api_key: 'required hunter api key',
query: 'required - hunter search query',
start_time: 'required - start date for the search (format is yyyy-mm-dd)',
end_time: 'required - end date for the search (format is yyyy-mm-dd)',
start_page: 'optional - starting page number for pagination (default is 1)',
page_size: 'optional - number of results per page (default is 10)',
fields: 'optional - comma-separated list of fields 'product,transport_protocol,protocol,banner,country,province,city,asn,org,web,updated_at' (default is nil)'

)



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/pwn/plugins/hunter.rb', line 98

public_class_method def self.search(opts = {})
  api_key = opts[:api_key].to_s.scrub
  raise "ERROR: #{self} requires a valid Hunter API Key" if api_key.empty?

  query = opts[:query].to_s.scrub
  raise "ERROR: #{self} requires a valid query" if query.empty?

  start_time = opts[:start_time]
  raise "ERROR: #{self} requires a valid start time" if start_time.nil?

  end_time = opts[:end_time]
  raise "ERROR: #{self} requires a valid end time" if end_time.nil?

  start_page = opts[:start_page] ||= 1
  page_size = opts[:page_size] ||= 10
  fields = opts[:fields]

  params = {}
  params[:'api-key'] = api_key
  base64_query = Base64.urlsafe_encode64(query)
  params[:query] = base64_query
  params[:page] = start_page
  params[:page_size] = page_size
  params[:start_time] = start_time
  params[:end_time] = end_time
  params[:fields] = fields

  hunter_rest_call(
    rest_call: 'search',
    params: params
  )
rescue StandardError => e
  raise e
end