Module: PWN::Plugins::BlackDuckBinaryAnalysis

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

Overview

This plugin is used for interacting w/ the Black Duck Binary Analysis REST API using the ‘rest’ browser type of PWN::Plugins::TransparentBrowser. This is based on the following Black Duck Binary Analysis API Specification: protecode-sc.com/help/api

Class Method Summary collapse

Class Method Details

.abort_product_scan(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.abort_product_scan(

token: 'required - Bearer token',
product_id: 'required - product id'

)



251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 251

public_class_method def self.abort_product_scan(opts = {})
  token = opts[:token]
  product_id = opts[:product_id]

  response = bd_bin_analysis_rest_call(
    http_method: :post,
    token: token,
    rest_call: "product/#{product_id}/abort"
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.authorsObject

Author(s)

0day Inc. <[email protected]>



649
650
651
652
653
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 649

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

.create_group(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.create_group(

token: 'required - Bearer token',
name: 'required - group name',
desc: 'optional - group description',
parent_id: 'optional - parent group id',
delete_binary: 'optional - delete binary after analysis C|Y|N (Default: C== company default)',
binary_cleanup_age: 'optional - after how long the binary will be deleted in seconds (Default: 2_592_000 / 30 days)',
product_cleanup_age: 'optional - after how long the product will be deleted in seconds (Default: 2_592_000 / 30 days)',
file_download_enabled: 'optional - allow download of uploaded binaries from group (Default: false),
low_risk_tolerance: 'optional - low risk tolerance nil|true|false (Default: nil == company default)',
include_historical_vulns: 'optional - include historical vulns nil|true|false (Default: nil == company default)',
cvss3_fallback: 'optional - cvss3 fallback nil|true|false (Default: nil == company default)',
assume_unknown_version_as_latest: 'optional - assume unknown version as latest nil|true|false (Default: nil == company default)',
custom_data: 'optional - custom data hash (Default: {}, see group metadata for details)',
scan_infoleak: 'optional - scan infoleak nil|true|false (Default: nil == company default)',
code_analysis: 'optional - code analysis nil|true|false (Default: nil == company default)',
scan_code_similarity: 'optional - scan code similarity nil|true|false (Default: nil == company default)'

)



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
395
396
397
398
399
400
401
402
403
404
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 357

public_class_method def self.create_group(opts = {})
  token = opts[:token]
  name = opts[:name]
  desc = opts[:desc]
  parent_id = opts[:parent_id]
  delete_binary = opts[:delete_binary] ||= 'C'
  binary_cleanup_age = opts[:binary_cleanup_age] ||= 2_592_000
  product_cleanup_age = opts[:product_cleanup_age] ||= 2_592_000
  file_download_enabled = opts[:file_download_enabled] ||= false
  low_risk_tolerance = opts[:low_risk_tolerance]
  include_historical_vulns = opts[:include_historical_vulns]
  cvss3_fallback = opts[:cvss3_fallback]
  assume_unknown_version_as_latest = opts[:assume_unknown_version_as_latest]
  custom_data = opts[:custom_data] ||= {}
  scan_infoleak = opts[:scan_infoleak]
  code_analysis = opts[:code_analysis]
  scan_code_similarity = opts[:scan_code_similarity]

  http_headers = {
    authorization: "Bearer #{token}",
    name: name,
    description: desc,
    parent: parent_id,
    delete_binary_after_scan: delete_binary,
    binary_cleanup_age: binary_cleanup_age,
    product_cleanup_age: product_cleanup_age,
    file_download_enabled: file_download_enabled,
    low_risk_tolerance: low_risk_tolerance,
    include_historical_vulnerabilities: include_historical_vulns,
    cvss3_fallback: cvss3_fallback,
    assume_unknown_version_as_latest: assume_unknown_version_as_latest,
    custom_data: custom_data,
    scan_infoleak: scan_infoleak,
    code_analysis: code_analysis,
    scan_code_similarity: scan_code_similarity
  }

  response = bd_bin_analysis_rest_call(
    http_method: :post,
    token: token,
    rest_call: 'groups',
    http_headers: http_headers
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.delete_group(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.delete_group(

token: 'required - Bearer token',
group_id: 'required - group id'

)



452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 452

public_class_method def self.delete_group(opts = {})
  token = opts[:token]
  group_id = opts[:group_id]

  response = bd_bin_analysis_rest_call(
    http_method: :delete,
    token: token,
    rest_call: "groups/#{group_id}"
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.generate_product_report(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.generate_product_report(

token: 'required - Bearer token',
product_id: 'required - product id',
output_path: 'required - path to output file',
type: 'optional - report type csv_libs||csv_vulns|pdf (Defaults to csv_vulns)'

)



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 274

public_class_method def self.generate_product_report(opts = {})
  token = opts[:token]
  product_id = opts[:product_id]
  output_path = opts[:output_path]
  type = opts[:type] ||= :csv_vulns

  case type.to_s.downcase.to_sym
  when :csv_libs
    rest_call = "product/#{product_id}/csv-libs"
  when :csv_vulns
    rest_call = "product/#{product_id}/csv-vulns"
  when :pdf
    rest_call = "product/#{product_id}/pdf-report"
  else
    raise "ERROR: Invalid report type #{type}"
  end

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: rest_call
  )

  File.write(output_path, response.body)
rescue StandardError => e
  raise e
end

.get_apps(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_apps(

token: 'required - Bearer token'

)



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 124

public_class_method def self.get_apps(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'apps'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_apps_by_group(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_apps_by_group(

token: 'required - Bearer token',
group_id: 'required - group id'

)



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

public_class_method def self.get_apps_by_group(opts = {})
  token = opts[:token]
  group_id = opts[:group_id]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: "apps/#{group_id}"
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_audit_trail(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_audit_trail(

token: 'required - Bearer token'

)



580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 580

public_class_method def self.get_audit_trail(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'audit-trail'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_component_licenses(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_component_licenses(

token: 'required - Bearer token'

)



490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 490

public_class_method def self.get_component_licenses(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'component-licenses'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_components(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_components(

token: 'required - Bearer token'

)



544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 544

public_class_method def self.get_components(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'components'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_group_details(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_group_details(

token: 'required - Bearer token',
group_id: 'required - group id'

)



412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 412

public_class_method def self.get_group_details(opts = {})
  token = opts[:token]
  group_id = opts[:group_id]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: "groups/#{group_id}"
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_group_statistics(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_group_statistics(

token: 'required - Bearer token',
group_id: 'required - group id'

)



432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 432

public_class_method def self.get_group_statistics(opts = {})
  token = opts[:token]
  group_id = opts[:group_id]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: "groups/#{group_id}/statistics"
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_groups(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_groups(

token: 'required - Bearer token'

)



324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 324

public_class_method def self.get_groups(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'groups'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_licenses(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_licenses(

token: 'required - Bearer token'

)



472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 472

public_class_method def self.get_licenses(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'licenses'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_product(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_product(

token: 'required - Bearer token',
product_id: 'required - product id'

)



231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 231

public_class_method def self.get_product(opts = {})
  token = opts[:token]
  product_id = opts[:product_id]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: "product/#{product_id}"
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_service_info(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_service_info(

token: 'required - Bearer token'

)



616
617
618
619
620
621
622
623
624
625
626
627
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 616

public_class_method def self.get_service_info(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'service/info'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_service_version(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_service_version(

token: 'required - Bearer token'

)



634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 634

public_class_method def self.get_service_version(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'service/version'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_status(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_status(

token: 'required - Bearer token'

)



598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 598

public_class_method def self.get_status(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'status'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_tags(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_tags(

token: 'required - Bearer token'

)



508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 508

public_class_method def self.get_tags(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'tags'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_tasks(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_tasks(

token: 'required - Bearer token'

)



306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 306

public_class_method def self.get_tasks(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'tasks'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_vendor_vulns(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_vendor_vulns(

token: 'required - Bearer token'

)



562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 562

public_class_method def self.get_vendor_vulns(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'teacher/api/vulns'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_vulnerabilities(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.get_vulnerabilities(

token: 'required - Bearer token'

)



526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 526

public_class_method def self.get_vulnerabilities(opts = {})
  token = opts[:token]

  response = bd_bin_analysis_rest_call(
    token: token,
    rest_call: 'vulnerabilities'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.helpObject

Display Usage for this Module



657
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 657

public_class_method def self.help
  puts "USAGE:
    response = #{self}.get_apps(
      token: 'required - Bearer token'
    )

    response = PWN::Plugins::BlackDuckBinaryAnalysis.upload_file(
      token: 'required - Bearer token',
      file: 'required - path of file to upload',
      group_id: 'optional - group id',
      delete_binary: 'optional - delete binary after upload (defaults to false)',
      force_scan: 'optional - force scan (defaults to false)',
      callback_url: 'optional - callback url',
      scan_infoleak: 'optional - scan infoleak (defaults to true)',
      code_analysis: 'optional - code analysis (defaults to true)',
      scan_code_familiarity: 'optional - scan code familiarity (defaults to true)',
      version: 'optional - version',
      product_id: 'optional - product id'
    )

    response = #{self}.get_product(
      token: 'required - Bearer token',
      product_id: 'required - product id'
    )

    response = #{self}.abort_product_scan(
      token: 'required - Bearer token',
      product_id: 'required - product id'
    )

    response = #{self}.generate_product_report(
      token: 'required - Bearer token',
      product_id: 'required - product id',
      output_path: 'required - path to output file',
      type: 'optional - report type csv_libs||csv_vulns|pdf (Defaults to csv_vulns)'
    )

    response = #{self}.get_tasks(
      token: 'required - Bearer token'
    )

    response = #{self}.get_apps_by_group(
      token: 'required - Bearer token',
      group_id: 'required - group id'
    )

    response = #{self}.get_groups(
      token: 'required - Bearer token'
    )

    response = #{self}.create_group(
      token: 'required - Bearer token',
      name: 'required - group name',
      desc: 'optional - group description',
      parent_id: 'optional - parent_id group id',
      delete_binary: 'optional - delete binary after analysis C|Y|N (Default: C== company default)',
      binary_cleanup_age: 'optional - after how long the binary will be deleted in seconds (Default: 2_592_000 / 30 days)',
      product_cleanup_age: 'optional - after how long the product will be deleted in seconds (Default: 2_592_000 / 30 days)',
      file_download_enabled: 'optional - allow download of uploaded binaries from group (Default: false),
      low_risk_tolerance: 'optional - low risk tolerance nil|true|false (Default: nil == company default)',
      include_historical_vulns: 'optional - include historical vulns nil|true|false (Default: nil == company default)',
      cvss3_fallback: 'optional - cvss3 fallback nil|true|false (Default: nil == company default)',
      assume_unknown_version_as_latest: 'optional - assume unknown version as latest nil|true|false (Default: nil == company default)',
      custom_data: 'optional - custom data hash (Default: {}, see group metadata for details)',
      scan_infoleak: 'optional - scan infoleak nil|true|false (Default: nil == company default)',
      code_analysis: 'optional - code analysis nil|true|false (Default: nil == company default)',
      scan_code_similarity: 'optional - scan code similarity nil|true|false (Default: nil == company default)'
    )

    response = #{self}.get_group_details(
      token: 'required - Bearer token',
      group_id: 'required - group id'
    )

    response = #{self}.get_group_statistics(
      token: 'required - Bearer token',
      group_id: 'required - group id'
    )

    response = #{self}.delete_group(
      token: 'required - Bearer token',
      group_id: 'required - group id'
    )

    response = #{self}.get_licenses(
      token: 'required - Bearer token'
    )

    response = #{self}.get_component_licenses(
      token: 'required - Bearer token'
    )

    response = #{self}.get_tags(
      token: 'required - Bearer token'
    )

    response = #{self}.get_vulnerabilities(
      token: 'required - Bearer token'
    )

    response = #{self}.get_components(
      token: 'required - Bearer token'
    )

    response = #{self}.get_vendor_vulns(
      token: 'required - Bearer token'
    )

    response = #{self}.get_audit_trail(
      token: 'required - Bearer token'
    )

    response = #{self}.get_status(
      token: 'required - Bearer token'
    )

    response = #{self}.get_service_info(
      token: 'required - Bearer token'
    )

    response = #{self}.get_service_version(
      token: 'required - Bearer token'
    )

    #{self}.authors
  "
end

.upload_file(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::BlackDuckBinaryAnalysis.upload_file(

token: 'required - Bearer token',
file: 'required - path of file to upload',
group_id: 'optional - group id',
delete_binary: 'optional - delete binary after upload (defaults to false)',
force_scan: 'optional - force scan (defaults to false)',
callback_url: 'optional - callback url',
scan_infoleak: 'optional - scan infoleak (defaults to true)',
code_analysis: 'optional - code analysis (defaults to true)',
scan_code_familiarity: 'optional - scan code familiarity (defaults to false)',
version: 'optional - version',
product_id: 'optional - product id'

)



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
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/pwn/plugins/black_duck_binary_analysis.rb', line 172

public_class_method def self.upload_file(opts = {})
  token = opts[:token]
  file = opts[:file]
  raise "ERROR: #{file} not found." unless File.exist?(file)

  file_name = File.basename(file)

  group_id = opts[:group_id]
  delete_binary = true if opts[:delete_binary] ||= false
  force_scan = true if opts[:force_scan] ||= false
  callback_url = opts[:callback_url]
  scan_infoleak = false if opts[:scan_infoleak] ||= true
  code_analysis = false if opts[:code_analysis] ||= true
  scan_code_familiarity = false if opts[:scan_code_familiarity] ||= false
  version = opts[:version]
  product_id = opts[:product_id]

  http_headers = {
    authorization: "Bearer #{token}",
    delete_binary: delete_binary,
    force_scan: force_scan,
    group: group_id,
    callback: callback_url,
    scan_infoleak: scan_infoleak,
    code_analysis: code_analysis,
    scan_code_familiarity: scan_code_familiarity,
    version: version,
    replace: product_id
  }

  # http_body = {
  #   multipart: true,
  #   file: File.new(file, 'rb')
  # }

  http_body = {
    raw: true,
    file: File.binread(file)
  }

  response = bd_bin_analysis_rest_call(
    http_method: :put,
    token: token,
    rest_call: "upload/#{CGI.escape_uri_component(file_name)}",
    http_headers: http_headers,
    http_body: http_body
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end