Module: PWN::WWW::HackerOne

Defined in:
lib/pwn/www/hacker_one.rb

Overview

This plugin supports hackerone.com actions.

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



345
346
347
348
349
# File 'lib/pwn/www/hacker_one.rb', line 345

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

.close(opts = {}) ⇒ Object

Supported Method Parameters

browser_obj = PWN::WWW::HackerOne.close(

browser_obj: 'required - browser_obj returned from #open method'

)



334
335
336
337
338
339
340
341
# File 'lib/pwn/www/hacker_one.rb', line 334

public_class_method def self.close(opts = {})
  browser_obj = opts[:browser_obj]
  PWN::Plugins::TransparentBrowser.close(
    browser_obj: browser_obj
  )
rescue StandardError => e
  raise e
end

.get_bounty_programs(opts = {}) ⇒ Object

Supported Method Parameters

programs_arr = PWN::WWW::HackerOne.get_bounty_programs(

browser_obj: 'required - browser_obj returned from #open method',
proxy: 'optional - scheme://proxy_host:port || tor',
min_payouts_enabled: 'optional - only display programs where payouts are > $0.00 (defaults to false)'

)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pwn/www/hacker_one.rb', line 35

public_class_method def self.get_bounty_programs(opts = {})
  browser_obj = opts[:browser_obj]
  browser = browser_obj[:browser]
  min_payouts_enabled = true if opts[:min_payouts_enabled]
  min_payouts_enabled ||= false

  browser.goto('https://hackerone.com/bug-bounty-programs')
  # Wait for JavaScript to load the DOM

  programs_arr = []
  browser.ul(class: 'program__meta-data').wait_until(&:present?)
  browser.uls(class: 'program__meta-data').each do |ul|
    min_payout = ul.text.split('$').last.split.first.to_f

    next if min_payouts_enabled && min_payout.zero?

    print '.'
    link = "https://#{ul.first.text}"
    min_payout_fmt = format('$%0.2f', min_payout)
    scheme = URI.parse(link).scheme
    host = URI.parse(link).host
    path = URI.parse(link).path
    burp_target_config = "#{scheme}://#{host}/teams#{path}/assets/download_burp_project_file.json"

    bounty_program_hash = {
      name: link.split('/').last,
      min_payout: min_payout_fmt,
      policy: "#{link}?view_policy=true",
      burp_target_config: burp_target_config,
      scope: "#{link}/policy_scopes",
      hacktivity: "#{link}/hacktivity",
      thanks: "#{link}/thanks",
      updates: "#{link}/updates",
      collaborators: "#{link}/collaborators"
    }
    programs_arr.push(bounty_program_hash)
  end

  programs_arr
rescue StandardError => e
  raise e
end

.get_scope_details(opts = {}) ⇒ Object

Supported Method Parameters

scope_details = PWN::WWW::HackerOne.get_scope_details(

program_name: 'required - program name from #get_bounty_programs method',
proxy: 'optional - scheme://proxy_host:port || tor'

)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/pwn/www/hacker_one.rb', line 84

public_class_method def self.get_scope_details(opts = {})
  program_name = opts[:program_name]
  proxy = opts[:proxy]

  browser_obj = PWN::Plugins::TransparentBrowser.open(
    browser_type: :rest,
    proxy: proxy
  )
  rest_client = browser_obj[:browser]
  rest_request = rest_client::Request

  graphql_endpoint = 'https://hackerone.com/graphql'
  headers = { content_type: 'application/json' }
  # NOTE: If you copy this payload to the pwn REPL
  # the triple dots ... attempt to execute commands
  # <cough>Pry CE</cough>
  payload = {
    operationName: 'PolicySearchStructuredScopesQuery',
    variables: {
      handle: program_name,
      searchString: '',
      eligibleForSubmission: nil,
      eligibleForBounty: nil,
      asmTagIds: [],
      from: 0,
      size: 100,
      sort: {
        field: 'cvss_score',
        direction: 'DESC'
      },
      product_area: 'h1_assets',
      product_feature: 'policy_scopes'
    },
    query: 'query PolicySearchStructuredScopesQuery(
      $handle: String!,
      $searchString: String,
      $eligibleForSubmission: Boolean,
      $eligibleForBounty: Boolean,
      $minSeverityScore: SeverityRatingEnum,
      $asmTagIds: [Int],
      $from: Int, $size: Int, $sort: SortInput) {
        team(handle: $handle) {
          id
          structured_scopes_search(
            search_string: $searchString
            eligible_for_submission: $eligibleForSubmission
            eligible_for_bounty: $eligibleForBounty
            min_severity_score: $minSeverityScore
            asm_tag_ids: $asmTagIds
            from: $from
            size: $size
            sort: $sort
          ) {
            nodes {
              ... on StructuredScopeDocument {
                id
                ...PolicyScopeStructuredScopeDocument
                __typename
              }
              __typename
            }
            pageInfo {
              startCursor
              hasPreviousPage
              endCursor
              hasNextPage
              __typename
            }
            total_count
            __typename
          }
          __typename
        }
      }

      fragment PolicyScopeStructuredScopeDocument on StructuredScopeDocument {
        id
        identifier
        display_name
        instruction
        cvss_score
        eligible_for_bounty
        eligible_for_submission
        asm_system_tags
        created_at
        updated_at
        attachments {
          id
          file_name
          file_size
          content_type
          expiring_url
          __typename
        }
        __typename
      }
    '
  }

  rest_response = rest_request.execute(
    method: :post,
    url: graphql_endpoint,
    headers: headers,
    payload: payload.to_json.delete("\n"),
    verify_ssl: false
  )

  json_resp_hash = JSON.parse(rest_response.body, symbolize_names: true)

  json_resp = {
    name: program_name,
    scope_details: json_resp_hash[:data][:team][:structured_scopes_search]
  }
rescue RestClient::ExceptionWithResponse => e
  if e.response
    puts "HTTP RESPONSE CODE: #{e.response.code}"
    puts "HTTP RESPONSE HEADERS:\n#{e.response.headers}"
    puts "HTTP RESPONSE BODY:\n#{e.response.body}\n\n\n"
  end

  raise e
rescue StandardError => e
  raise e
ensure
  browser_obj = PWN::Plugins::TransparentBrowser.close(browser_obj: browser_obj) if browser_obj
  rest_client = nil if rest_client
  rest_request = nil if rest_request
end

.helpObject

Display Usage for this Module



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/pwn/www/hacker_one.rb', line 353

public_class_method def self.help
  puts "USAGE:
    browser_obj = #{self}.open(
      browser_type: 'optional - :firefox|:chrome|:ie|:headless (Defaults to :firefox)',
      proxy: 'optional - scheme://proxy_host:port || tor'
    )

    programs_arr = #{self}.get_bounty_programs(
      browser_obj: 'required - browser_obj returned from #open method',
      proxy: 'optional - scheme://proxy_host:port || tor',
      min_payouts_enabled: 'optional - only display programs where payouts are > $0.00 (defaults to false)'
    )

    scope_details = PWN::WWW::HackerOne.get_scope_details(
      program_name: 'required - program name from #get_bounty_programs method',
      proxy: 'optional - scheme://proxy_host:port || tor'
    )

    #{self}.save_burp_target_config_file(
      programs_arr: 'required - array of hashes returned from #get_bounty_programs method',
      browser_opts: 'optional - opts supported by PWN::Plugins::TransparentBrowser.open method',
      name: 'optional - name of burp target config file (defaults to ALL)',
      root_dir: 'optional - directory to save burp target config files (defaults to \"./\"))'
    )

    browser_obj = #{self}.login(
      browser_obj: 'required - browser_obj returned from #open method',
      username: 'required - username',
      password: 'optional - passwd (will prompt if blank),
    )

    browser_obj = #{self}.logout(
      browser_obj: 'required - browser_obj returned from #open method'
    )

    #{self}.close(
      browser_obj: 'required - browser_obj returned from #open method'
    )

    #{self}.authors
  "
end

.login(opts = {}) ⇒ Object

Supported Method Parameters

browser_obj = PWN::WWW::HackerOne.login(

browser_obj: 'required - browser_obj returned from #open method',
username: 'required - username',
password: 'optional - passwd (will prompt if blank)'

)



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/pwn/www/hacker_one.rb', line 288

public_class_method def self.(opts = {})
  browser_obj = opts[:browser_obj]
  username = opts[:username].to_s.scrub.strip.chomp
  password = opts[:password]

  browser = browser_obj[:browser]

  if password.nil?
    password = PWN::Plugins::AuthenticationHelper.mask_password
  else
    password = opts[:password].to_s.scrub.strip.chomp
  end

  browser.goto('https://hackerone.com/users/sign_in')

  browser.text_field(name: 'user[email]').wait_until(&:present?).set(username)
  browser.text_field(name: 'user[password]').wait_until(&:present?).set(password)
  browser.button(name: 'commit').click!

  browser_obj
rescue StandardError => e
  raise e
end

.logout(opts = {}) ⇒ Object

Supported Method Parameters

browser_obj = PWN::WWW::HackerOne.logout(

browser_obj: 'required - browser_obj returned from #open method'

)



317
318
319
320
321
322
323
324
325
326
327
# File 'lib/pwn/www/hacker_one.rb', line 317

public_class_method def self.logout(opts = {})
  browser_obj = opts[:browser_obj]

  browser = browser_obj[:browser]
  browser.i(class: 'icon-arrow-closure').click!
  browser.link(index: 16).click!

  browser_obj
rescue StandardError => e
  raise e
end

.open(opts = {}) ⇒ Object

Supported Method Parameters

browser_obj = PWN::WWW::HackerOne.open(

browser_type: 'optional - :firefox|:chrome|:ie|:headless (Defaults to :firefox)',
proxy: 'optional - scheme://proxy_host:port || tor'

)



17
18
19
20
21
22
23
24
25
26
# File 'lib/pwn/www/hacker_one.rb', line 17

public_class_method def self.open(opts = {})
  browser_obj = PWN::Plugins::TransparentBrowser.open(opts)

  browser = browser_obj[:browser]
  browser.goto('https://www.hackerone.com')

  browser_obj
rescue StandardError => e
  raise e
end

.save_burp_target_config_file(opts = {}) ⇒ Object

Supported Method Parameters

PWN::WWW::HackerOne.save_burp_target_config_file(

programs_arr: 'required - array of hashes returned from #get_bounty_programs method',
browser_opts: 'optional - opts supported by PWN::Plugins::TransparentBrowser.open method',
name: 'optional - name of burp target config file (defaults to ALL)',
root_dir: 'optional - directory to save burp target config files (defaults to "./"))'

)



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/pwn/www/hacker_one.rb', line 220

public_class_method def self.save_burp_target_config_file(opts = {})
  programs_arr = opts[:programs_arr]
  raise 'ERROR: programs_arr should be data returned from #get_bounty_programs' unless programs_arr.any?

  browser_opts = opts[:browser_opts]
  raise 'ERROR: browser_opts should be a hash' unless browser_opts.nil? ||
                                                      browser_opts.is_a?(Hash)

  browser_opts ||= {}
  browser_opts[:browser_type] = :rest

  name = opts[:name]
  root_dir = opts[:root_dir]

  rest_obj = PWN::Plugins::TransparentBrowser.open(browser_opts)
  rest_client = rest_obj[:browser]::Request
  user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_5_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'

  if name
    path = "./burp_target_config_file-#{name}.json" if opts[:root_dir].nil?
    path = "#{root_dir}/burp_target_config_file-#{name}.json" unless opts[:root_dir].nil?
    burp_download_link = programs_arr.select do |program|
      program[:name] == name
    end.first[:burp_target_config]

    resp = rest_client.execute(
      method: :get,
      headers: { user_agent: user_agent },
      url: burp_download_link
    )
    json_resp = JSON.parse(resp.body)

    puts "Saving to: #{path}"
    File.write(path, JSON.pretty_generate(json_resp))
  else
    programs_arr.each do |program|
      name = program[:name]
      burp_download_link = program[:burp_target_config]
      path = "./burp_target_config_file-#{name}.json" if opts[:root_dir].nil?
      path = "#{root_dir}/burp_target_config_file-#{name}.json" unless opts[:root_dir].nil?

      resp = rest_client.execute(
        method: :get,
        headers: { user_agent: user_agent },
        url: burp_download_link
      )
      json_resp = JSON.parse(resp.body)

      puts "Saving to: #{path}"
      File.write(path, JSON.pretty_generate(json_resp))
    rescue JSON::ParserError,
           RestClient::NotFound
      puts '-'
      next
    end
  end
  puts 'complete.'
rescue StandardError => e
  raise e
end