Glitteropia
Glitteropia

Reputation: 117

Ruby LoadError issue with 'require'

I have researched this for quite some time, and have yet to solve my issue. Here is the error that I am receiving:

C:/Ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- nexpose-runner/constants (LoadError)
  from C:/Ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require'
  from scan.rb:4:in `<main>'

Here is my code:

require 'nexpose'
require 'csv'
require 'json'
require 'nexpose-runner/constants'
require 'nexpose-runner/scan_run_description'

module NexposeRunner
module Scan
def Scan.start(options)

  run_details = ScanRunDescription.new(options)
  run_details.verify

  nsc = get_new_nexpose_connection(run_details)

  site = create_site(run_details, nsc)

  start_scan(nsc, site, run_details)

  reports = generate_reports(nsc, site, run_details)

  verify_run(reports[0])
end

def self.generate_reports(nsc, site, run_details)
  puts "Scan complete for #{run_details.site_name}, Generating Vulnerability Report"
  vulnerbilities = generate_report(CONSTANTS::VULNERABILITY_REPORT_QUERY, site.id, nsc)
  generate_csv(vulnerbilities, CONSTANTS::VULNERABILITY_REPORT_NAME)

  puts "Scan complete for #{run_details.site_name}, Generating Vulnerability Detail Report"
  vuln_details = generate_report(CONSTANTS:: VULNERABILITY_DETAIL_REPORT_QUERY, site.id, nsc)
  generate_csv(vuln_details, CONSTANTS::VULNERABILITY_DETAIL_REPORT_NAME)

  puts "Scan complete for #{run_details.site_name}, Generating Software Report"
  software = generate_report(CONSTANTS::SOFTWARE_REPORT_QUERY, site.id, nsc)
  generate_csv(software, CONSTANTS::SOFTWARE_REPORT_NAME)

  puts "Scan complete for #{run_details.site_name}, Generating Policy Report"
  policies = generate_report(CONSTANTS::POLICY_REPORT_QUERY, site.id, nsc)
  generate_csv(policies, CONSTANTS::POLICY_REPORT_NAME)

  puts "Scan complete for #{run_details.site_name}, Generating Audit Report"
  generate_template_report(nsc, site.id, CONSTANTS::AUDIT_REPORT_FILE_NAME, CONSTANTS::AUDIT_REPORT_NAME, CONSTANTS::AUDIT_REPORT_FORMAT)

  puts "Scan complete for #{run_details.site_name}, Generating Xml Report"
  generate_template_report(nsc, site.id, CONSTANTS::XML_REPORT_FILE_NAME, CONSTANTS::XML_REPORT_NAME, CONSTANTS::XML_REPORT_FORMAT)

  [vulnerbilities, software, policies]
end

def self.verify_run(vulnerabilities)

  raise StandardError, CONSTANTS::VULNERABILITY_FOUND_MESSAGE if vulnerabilities.count > 0

end

def self.start_scan(nsc, site, run_details)

  puts "Starting scan for #{run_details.site_name} using the #{run_details.scan_template} scan template"
  scan = site.scan nsc

  begin
    sleep(3)
    stats = nsc.scan_statistics(scan.id)
status = stats.status
    puts "Current #{run_details.site_name} scan status: #{status.to_s} -- PENDING: #{stats.tasks.pending.to_s} ACTIVE: #{stats.tasks.active.to_s} COMPLETED #{stats.tasks.completed.to_s}"
  end while status == Nexpose::Scan::Status::RUNNING
end

def self.create_site(run_details, nsc)
  puts "Creating a nexpose site named #{run_details.site_name}"
  site = Nexpose::Site.new run_details.site_name, run_details.scan_template
  run_details.ip_addresses.each { |address|
      site.add_ip address
  }
  if run_details.engine
    site.engine = run_details.engine
  end
  site.save nsc
  puts "Created site #{run_details.site_name} successfully with the following host(s) #{run_details.ip_addresses.join(', ')}"

  site
end

def self.get_new_nexpose_connection(run_details)
  nsc = Nexpose::Connection.new run_details.connection_url, run_details.username, run_details.password, run_details.port
  nsc.login
  puts 'Successfully logged into the Nexpose Server'
  nsc
end

def self.generate_report(sql, site, nsc)
  report = Nexpose::AdhocReportConfig.new(nil, 'sql')
  report.add_filter('version', '1.3.0')
  report.add_filter('query', sql)
  report.add_filter('site', site)
  report_output = report.generate(nsc)
  CSV.parse(report_output.chomp, {:headers => :first_row})
end

def self.generate_template_report(nsc, site, file_name, report_name, report_format)
  adhoc = Nexpose::AdhocReportConfig.new(report_name, report_format, site)
  data = adhoc.generate(nsc)
  File.open(file_name, 'w') { |file| file.write(data) }
end

def self.generate_csv(csv_output, name)
  CSV.open(name, 'w') do |csv_file|
    csv_file << csv_output.headers
    csv_output.each do |row|
      csv_file << row
      if name == CONSTANTS::VULNERABILITY_REPORT_NAME
        puts '--------------------------------------'
        puts "IP: #{row[0]}"
        puts "Vulnerability: #{row[1]}"
        puts "Date Vulnerability was Published: #{row[2]}"
        puts "Severity: #{row[3]}"
        puts "Summary: #{row[4]}"
        puts '--------------------------------------'
      end
     end
    end
  end
 end
end

In the command prompt, I am entering in the following code to run it (this file is called scan.rb):

ruby scan.rb "http://localhost:3780" "username" "password" "3780" "webpage" "ip-address" "full-audit-widget-corp"

So far, I've tried changing require to require_relative, as well as re-arranging the paths (like putting the whole path, for example). Neither has worked.

I also made sure to have the Ruby Development Kit installed.

Thanks!

Upvotes: 1

Views: 595

Answers (1)

W.Ranger
W.Ranger

Reputation: 46

please check the local gem list: gem list --local

Upvotes: 2

Related Questions