#!/usr/bin/env ruby # frozen_string_literal: true require 'pwn' require 'optparse' opts = {} OptionParser.new do |options| options.banner = "USAGE: #{File.basename($PROGRAM_NAME)} [opts] " options.on('-uURL', '--url=URL', '') do |u| opts[:url] = u end options.on('-VVERSION', '--api-version=VERSION', '') do |v| opts[:api_version] = v end options.on('-UUSER', '--username=USER', '') do |u| opts[:username] = u end options.on('-aKEY', '--api-key=KEY', '') do |a| opts[:api_key] = a end options.on('-nNAME', '--enagagement-name=NAME', '') do |n| opts[:name] = n end options.on('-dDESC', '--description=DESC', '') do |d| opts[:description] = d end options.on('-xTYPE', '--enagagement-type=TYPE', '') do |x| opts[:engagement_name] = x end options.on('-sSTATUS', '--status=STATUS', '') do |s| opts[:status] = s end options.on('-lUSER', '--lead-username=USER', '') do |l| opts[:lead_username] = l end options.on('-pNAME', '--product-name=NAME', '') do |p| opts[:product_name] = p end options.on('-tSTRATEGY', '--test-strategy=STRATEGY', '') do |t| opts[:test_strategy] = t end options.on('-bSERVER', '--build-server=SERVER', '') do |b| opts[:build_server] = b end options.on('-zSERVER', '--scm-server=SERVER', '') do |z| opts[:scm_server] = z end options.on('-oENGINE', '--orchestration-engine=ENGINE', '') do |o| opts[:orchestration_engine] = o end options.on('-A', '--[no-]api-test', '') do |a| opts[:api_test] = a end options.on('-P', '--[no-]pen-test', '') do |p| opts[:pen_test] = p end options.on('-T', '--[no-]threat-model', '') do |t| opts[:threat_model] = t end options.on('-C', '--[no-]check-list', '') do |c| opts[:check_list] = c end options.on('-cCONTACTED', '--first-contacted=CONTACTED', '') do |c| opts[:first_contacted] = c end options.on('-SSTART', '--target-start=START', '') do |s| opts[:target_start] = s end options.on('-EEND', '--target-end=END', '') do |e| opts[:target_end] = e end end.parse! if opts.empty? puts `#{File.basename($PROGRAM_NAME)} --help` exit 1 end # Construct AuthN Args url = opts[:url] api_version = opts[:api_version] opts[:username] ? (username = opts[:username]) : (username = PWN::Plugins::AuthenticationHelper.username) opts[:api_key] ? (api_key = opts[:api_key]) : (api_key = PWN::Plugins::AuthenticationHelper.mask_password(prompt: 'API Key')) # Create Engagement Args name = opts[:name] description = opts[:description] engagement_type = opts[:engagement_type] status = opts[:status] opts[:lead_username] ? (lead_username = opts[:lead_username]) : (lead_username = username) product_name = opts[:product_name] test_strategy = opts[:test_strategy] orchestration_engine = opts[:orchestration_engine] build_server = opts[:build_server] scm_server = opts[:scm_server] api_test = opts[:api_test] pen_test = opts[:pen_test] threat_model = opts[:threat_model] check_list = opts[:check_list] first_contacted = opts[:first_contacted] target_start = opts[:target_start] target_end = opts[:target_end] begin dd_obj = PWN::Plugins::DefectDojo.login( url: url, api_version: api_version, username: username, api_key: api_key ) engagement_create_resp = PWN::Plugins::DefectDojo.engagement_create( dd_obj: dd_obj, name: name, description: description, engagement_type: engagement_type, status: status, lead_username: lead_username, product_name: product_name, test_strategy: test_strategy, orchestration_engine: orchestration_engine, build_server: build_server, scm_server: scm_server, api_test: api_test, pen_test: pen_test, threat_model: threat_model, check_list: check_list, first_contacted: first_contacted, target_start: target_start, target_end: target_end ) rescue StandardError => e raise e end