Module: PWN::Plugins::HackerOne

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

Overview

This plugin is used for interacting w/ HackerOne's Hacker REST API using the 'rest' browser type of PWN::Plugins::TransparentBrowser.

Spec: https://api.hackerone.com/getting-started-hacker-api/#getting-started-hacker-api

Auth: HTTP Basic on every request (username + API token). Base: https://api.hackerone.com/v1/hackers/

Credentials are sourced from PWN::Env[:hackerone]:

plugins:
hackerone:
  username: your-h1-username
  api_key:  your-h1-api-token

Constant Summary collapse

BASE_H1_API_URI =
'https://api.hackerone.com/v1/hackers'
@@logger =
PWN::Plugins::PWNLogger.create

Class Method Summary collapse

Class Method Details

.api(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::HackerOne.api( path: 'required - path relative to /v1/hackers (e.g. "me/reports")', method: 'optional - :get|:post|:put|:patch|:delete (default :get)', params: 'optional - query params Hash', body: 'optional - request body Hash/Array/String', username: 'optional', api_key: 'optional', h1_obj: 'optional - session from #login (supplies username/api_key)', raw: 'optional - return raw response (default false)' )



160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/pwn/plugins/hacker_one.rb', line 160

public_class_method def self.api(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    http_method: opts[:method] || opts[:http_method] || :get,
    rest_call: opts[:path].to_s.delete_prefix('/'),
    params: opts[:params],
    http_body: opts[:body] || opts[:http_body],
    username: creds[:username],
    api_key: creds[:api_key],
    raw: opts[:raw]
  )
rescue StandardError => e
  raise e
end

.authorsObject

Author(s)

0day Inc. support@0dayinc.com



650
651
652
653
654
# File 'lib/pwn/plugins/hacker_one.rb', line 650

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <support@0dayinc.com>
  "
end

.create_report(opts = {}) ⇒ Object

Supported Method Parameters

report = PWN::Plugins::HackerOne.create_report( team_handle: 'required - program handle', title: 'required - report title', vulnerability_information: 'required - detailed description', impact: 'optional - impact text', severity_rating: 'optional - none|low|medium|high|critical', weakness_id: 'optional - weakness id integer', structured_scope_id: 'optional - structured scope id', body: 'optional - full JSON:API body Hash (overrides attribute kwargs)', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



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
# File 'lib/pwn/plugins/hacker_one.rb', line 238

public_class_method def self.create_report(opts = {})
  creds = creds_from(opts)
  http_body = opts[:body]
  if http_body.nil?
    attrs = {
      team_handle: opts[:team_handle],
      title: opts[:title],
      vulnerability_information: opts[:vulnerability_information]
    }
    attrs[:impact] = opts[:impact] if opts.key?(:impact)
    attrs[:severity_rating] = opts[:severity_rating] if opts.key?(:severity_rating)
    attrs[:weakness_id] = opts[:weakness_id] if opts.key?(:weakness_id)
    attrs[:structured_scope_id] = opts[:structured_scope_id] if opts.key?(:structured_scope_id)

    raise 'ERROR: team_handle required' if attrs[:team_handle].to_s.empty?
    raise 'ERROR: title required' if attrs[:title].to_s.empty?
    raise 'ERROR: vulnerability_information required' if attrs[:vulnerability_information].to_s.empty?

    http_body = {
      data: {
        type: 'report',
        attributes: attrs
      }
    }
  end

  h1_rest_call(
    http_method: :post,
    rest_call: 'reports',
    http_body: http_body,
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.create_report_intent(opts = {}) ⇒ Object

Supported Method Parameters

intent = PWN::Plugins::HackerOne.create_report_intent( body: 'required - full JSON:API body Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/pwn/plugins/hacker_one.rb', line 503

public_class_method def self.create_report_intent(opts = {})
  body = opts[:body]
  raise 'ERROR: body required for create_report_intent' if body.nil?

  creds = creds_from(opts)
  h1_rest_call(
    http_method: :post,
    rest_call: 'report_intents',
    http_body: body,
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.delete_report_intent(opts = {}) ⇒ Object

Supported Method Parameters

result = PWN::Plugins::HackerOne.delete_report_intent( id: 'required - report intent id', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/pwn/plugins/hacker_one.rb', line 550

public_class_method def self.delete_report_intent(opts = {})
  id = opts[:id]
  raise 'ERROR: report intent id required' if id.nil? || id.to_s.empty?

  creds = creds_from(opts)
  h1_rest_call(
    http_method: :delete,
    rest_call: "report_intents/#{id}",
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.delete_report_intent_attachment(opts = {}) ⇒ Object

Supported Method Parameters

result = PWN::Plugins::HackerOne.delete_report_intent_attachment( report_intent_id: 'required - report intent id', id: 'required - attachment id', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/pwn/plugins/hacker_one.rb', line 616

public_class_method def self.delete_report_intent_attachment(opts = {})
  rid = opts[:report_intent_id]
  id = opts[:id]
  raise 'ERROR: report_intent_id required' if rid.nil? || rid.to_s.empty?
  raise 'ERROR: attachment id required' if id.nil? || id.to_s.empty?

  creds = creds_from(opts)
  h1_rest_call(
    http_method: :delete,
    rest_call: "report_intents/#{rid}/attachments/#{id}",
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_balance(opts = {}) ⇒ Object

Supported Method Parameters

balance = PWN::Plugins::HackerOne.get_balance( username: 'optional', api_key: 'optional', h1_obj: 'optional' )



282
283
284
285
286
287
288
289
290
291
# File 'lib/pwn/plugins/hacker_one.rb', line 282

public_class_method def self.get_balance(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'payments/balance',
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_earnings(opts = {}) ⇒ Object

Supported Method Parameters

earnings = PWN::Plugins::HackerOne.get_earnings( params: 'optional - query params Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/pwn/plugins/hacker_one.rb', line 299

public_class_method def self.get_earnings(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'payments/earnings',
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_hacktivity(opts = {}) ⇒ Object

Supported Method Parameters

items = PWN::Plugins::HackerOne.get_hacktivity( params: 'optional - query params Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



444
445
446
447
448
449
450
451
452
453
454
# File 'lib/pwn/plugins/hacker_one.rb', line 444

public_class_method def self.get_hacktivity(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'hacktivity',
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_me_reports(opts = {}) ⇒ Object

Supported Method Parameters

reports = PWN::Plugins::HackerOne.get_me_reports( params: 'optional - query params Hash (e.g. page/filter)', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/pwn/plugins/hacker_one.rb', line 192

public_class_method def self.get_me_reports(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'me/reports',
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_payouts(opts = {}) ⇒ Object

Supported Method Parameters

payouts = PWN::Plugins::HackerOne.get_payouts( params: 'optional - query params Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



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

public_class_method def self.get_payouts(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'payments/payouts',
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_program(opts = {}) ⇒ Object

Supported Method Parameters

program = PWN::Plugins::HackerOne.get_program( handle: 'required - program handle', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/pwn/plugins/hacker_one.rb', line 355

public_class_method def self.get_program(opts = {})
  handle = opts[:handle].to_s.scrub
  raise 'ERROR: program handle required' if handle.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "programs/#{handle}",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_programs(opts = {}) ⇒ Object

Supported Method Parameters

programs = PWN::Plugins::HackerOne.get_programs( params: 'optional - query params Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



337
338
339
340
341
342
343
344
345
346
347
# File 'lib/pwn/plugins/hacker_one.rb', line 337

public_class_method def self.get_programs(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'programs',
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_report(opts = {}) ⇒ Object

Supported Method Parameters

report = PWN::Plugins::HackerOne.get_report( id: 'required - report id', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/pwn/plugins/hacker_one.rb', line 210

public_class_method def self.get_report(opts = {})
  id = opts[:id]
  raise 'ERROR: report id required' if id.nil? || id.to_s.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "reports/#{id}",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_report_intent(opts = {}) ⇒ Object

Supported Method Parameters

intent = PWN::Plugins::HackerOne.get_report_intent( id: 'required - report intent id', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/pwn/plugins/hacker_one.rb', line 482

public_class_method def self.get_report_intent(opts = {})
  id = opts[:id]
  raise 'ERROR: report intent id required' if id.nil? || id.to_s.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "report_intents/#{id}",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_report_intent_attachments(opts = {}) ⇒ Object

Supported Method Parameters

attachments = PWN::Plugins::HackerOne.get_report_intent_attachments( report_intent_id: 'required - report intent id', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/pwn/plugins/hacker_one.rb', line 594

public_class_method def self.get_report_intent_attachments(opts = {})
  rid = opts[:report_intent_id] || opts[:id]
  raise 'ERROR: report_intent_id required' if rid.nil? || rid.to_s.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "report_intents/#{rid}/attachments",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_report_intents(opts = {}) ⇒ Object

Supported Method Parameters

intents = PWN::Plugins::HackerOne.get_report_intents( params: 'optional', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



464
465
466
467
468
469
470
471
472
473
474
# File 'lib/pwn/plugins/hacker_one.rb', line 464

public_class_method def self.get_report_intents(opts = {})
  creds = creds_from(opts)
  h1_rest_call(
    rest_call: 'report_intents',
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_scope_exclusions(opts = {}) ⇒ Object

Supported Method Parameters

exclusions = PWN::Plugins::HackerOne.get_scope_exclusions( handle: 'required - program handle', params: 'optional', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/pwn/plugins/hacker_one.rb', line 399

public_class_method def self.get_scope_exclusions(opts = {})
  handle = opts[:handle].to_s.scrub
  raise 'ERROR: program handle required' if handle.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "programs/#{handle}/scope_exclusions",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_structured_scopes(opts = {}) ⇒ Object

Supported Method Parameters

scopes = PWN::Plugins::HackerOne.get_structured_scopes( handle: 'required - program handle', params: 'optional', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/pwn/plugins/hacker_one.rb', line 377

public_class_method def self.get_structured_scopes(opts = {})
  handle = opts[:handle].to_s.scrub
  raise 'ERROR: program handle required' if handle.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "programs/#{handle}/structured_scopes",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.get_weaknesses(opts = {}) ⇒ Object

Supported Method Parameters

weaknesses = PWN::Plugins::HackerOne.get_weaknesses( handle: 'required - program handle', params: 'optional', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/pwn/plugins/hacker_one.rb', line 421

public_class_method def self.get_weaknesses(opts = {})
  handle = opts[:handle].to_s.scrub
  raise 'ERROR: program handle required' if handle.empty?

  creds = creds_from(opts)
  h1_rest_call(
    rest_call: "programs/#{handle}/weaknesses",
    params: opts[:params],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.helpObject

Display Usage for this Module



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/pwn/plugins/hacker_one.rb', line 658

public_class_method def self.help
  puts "USAGE:
    h1_obj = #{self}.login(
      username: 'optional - default PWN::Env[:plugins][:hackerone][:username]',
      api_key: 'optional - default PWN::Env[:plugins][:hackerone][:api_key]'
    )

    reports = #{self}.get_me_reports(h1_obj: h1_obj)
    report  = #{self}.get_report(id: 12345)
    report  = #{self}.create_report(
      team_handle: 'security',
      title: 'Example',
      vulnerability_information: 'Details...'
    )

    balance  = #{self}.get_balance
    earnings = #{self}.get_earnings
    payouts  = #{self}.get_payouts

    programs = #{self}.get_programs
    program  = #{self}.get_program(handle: 'security')
    scopes   = #{self}.get_structured_scopes(handle: 'security')
    excl     = #{self}.get_scope_exclusions(handle: 'security')
    weak     = #{self}.get_weaknesses(handle: 'security')

    items = #{self}.get_hacktivity

    intents = #{self}.get_report_intents
    intent  = #{self}.get_report_intent(id: 1)
    intent  = #{self}.create_report_intent(body: { data: { type: 'report-intent', attributes: {} } })
    intent  = #{self}.update_report_intent(id: 1, body: { data: { type: 'report-intent', attributes: {} } })
    #{self}.submit_report_intent(id: 1)
    #{self}.delete_report_intent(id: 1)
    atts = #{self}.get_report_intent_attachments(report_intent_id: 1)
    #{self}.delete_report_intent_attachment(report_intent_id: 1, id: 2)

    json = #{self}.api(
      path: 'me/reports',
      method: :get,
      params: { page: { number: 1 } }
    )

    #{self}.logout(h1_obj: h1_obj)
    #{self}.authors
  "
end

.login(opts = {}) ⇒ Object

Supported Method Parameters

h1_obj = PWN::Plugins::HackerOne.login( username: 'optional - username (default PWN::Env[:hackerone][:username])', api_key: 'optional - api token (default PWN::Env; will prompt if still nil)', token: 'optional - alias for api_key' ) Backward-compatible session object. Auth is HTTP Basic on every subsequent call; login simply resolves + validates credentials against me/reports.



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
# File 'lib/pwn/plugins/hacker_one.rb', line 120

public_class_method def self.(opts = {})
  username = resolve_username(opts)
  api_key = resolve_api_key(opts)

  api_key = PWN::Plugins::AuthenticationHelper.mask_password if api_key.nil? || api_key.to_s.empty?

  username = username.to_s.scrub
  api_key = api_key.to_s.scrub
  raise 'ERROR: HackerOne username required' if username.empty?
  raise 'ERROR: HackerOne api_key required' if api_key.empty?

  @@logger.info("Validating HackerOne Hacker API credentials for #{username}")
  # Prefer a cheap authenticated endpoint (balance is small; me/reports is list)
  h1_rest_call(
    rest_call: 'payments/balance',
    username: username,
    api_key: api_key
  )

  {
    username: username,
    api_key: api_key,
    base_h1_api_uri: BASE_H1_API_URI
  }
rescue StandardError => e
  raise e
end

.logout(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::HackerOne.logout( h1_obj: 'required h1_obj returned from #login method' ) Clears the session hash in-place (no server-side session to destroy).



639
640
641
642
643
644
645
646
# File 'lib/pwn/plugins/hacker_one.rb', line 639

public_class_method def self.logout(opts = {})
  h1_obj = opts[:h1_obj]
  @@logger.info('Clearing HackerOne session object...')
  h1_obj.clear if h1_obj.respond_to?(:clear)
  nil
rescue StandardError => e
  raise e
end

.submit_report_intent(opts = {}) ⇒ Object

Supported Method Parameters

result = PWN::Plugins::HackerOne.submit_report_intent( id: 'required - report intent id', body: 'optional - JSON:API body Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/pwn/plugins/hacker_one.rb', line 572

public_class_method def self.submit_report_intent(opts = {})
  id = opts[:id]
  raise 'ERROR: report intent id required' if id.nil? || id.to_s.empty?

  creds = creds_from(opts)
  h1_rest_call(
    http_method: :post,
    rest_call: "report_intents/#{id}/submit",
    http_body: opts[:body],
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end

.update_report_intent(opts = {}) ⇒ Object

Supported Method Parameters

intent = PWN::Plugins::HackerOne.update_report_intent( id: 'required - report intent id', body: 'required - full JSON:API body Hash', username: 'optional', api_key: 'optional', h1_obj: 'optional' )



526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/pwn/plugins/hacker_one.rb', line 526

public_class_method def self.update_report_intent(opts = {})
  id = opts[:id]
  body = opts[:body]
  raise 'ERROR: report intent id required' if id.nil? || id.to_s.empty?
  raise 'ERROR: body required for update_report_intent' if body.nil?

  creds = creds_from(opts)
  h1_rest_call(
    http_method: :put,
    rest_call: "report_intents/#{id}",
    http_body: body,
    username: creds[:username],
    api_key: creds[:api_key]
  )
rescue StandardError => e
  raise e
end