lib/cms_scanner.rb in cms_scanner-0.0.41.10 vs lib/cms_scanner.rb in cms_scanner-0.0.42.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Gems require 'typhoeus' require 'nokogiri' require 'yajl/json_gem' require 'public_suffix' @@ -13,20 +15,20 @@ require 'uri' require 'fileutils' require 'pathname' require 'timeout' require 'xmlrpc/client' -# Monkey Patches +# Monkey Patches/Fixes require 'cms_scanner/typhoeus/response' # Adds a Response#html using Nokogiri to parse the body require 'cms_scanner/typhoeus/hydra' # https://github.com/typhoeus/typhoeus/issues/439 require 'cms_scanner/public_suffix/domain' # Adds a Domain#match method and logic, used in scope stuff require 'cms_scanner/numeric' # Adds a Numeric#bytes_to_human # Custom Libs +require 'cms_scanner/scan' require 'cms_scanner/helper' require 'cms_scanner/exit_code' -require 'cms_scanner/errors/http' -require 'cms_scanner/errors/scan' +require 'cms_scanner/errors' require 'cms_scanner/cache/typhoeus' require 'cms_scanner/target' require 'cms_scanner/browser' require 'cms_scanner/version' require 'cms_scanner/controller' @@ -118,91 +120,9 @@ remove_const(:NS) const_set(:NS, base) base.extend(ClassMethods) super(base) - end - - # Scan - class Scan - attr_reader :run_error - - def initialize - controllers << NS::Controller::Core.new - - exit_hook - - yield self if block_given? - end - - # @return [ Controllers ] - def controllers - @controllers ||= NS::Controllers.new - end - - def run - controllers.run - rescue OptParseValidator::NoRequiredOption => e - @run_error = e - - formatter.output('@usage', msg: e.message) - rescue NoMemoryError, ScriptError, SecurityError, SignalException, StandardError, SystemStackError => e - @run_error = e - - formatter.output('@scan_aborted', - reason: e.is_a?(Interrupt) ? 'Canceled by User' : e.message, - trace: e.backtrace, - verbose: controllers.first.parsed_options[:verbose] || - run_error_exit_code == NS::ExitCode::EXCEPTION) - ensure - Browser.instance.hydra.abort - - formatter.beautify - end - - # Used for convenience - # @See Formatter - def formatter - controllers.first.formatter - end - - # @return [ Hash ] - def datastore - controllers.first.datastore - end - - # Hook to be able to have an exit code returned - # depending on the findings / errors - # :nocov: - def exit_hook - # Avoid hooking the exit when rspec is running, otherwise it will always return 0 - # and Travis won't detect failed builds. Couldn't find a better way, even though - # some people managed to https://github.com/rspec/rspec-core/pull/410 - return if defined?(RSpec) - - at_exit do - exit(run_error_exit_code) if run_error - - controller = controllers.first - - # The parsed_option[:url] must be checked to avoid raising erros when only -h/-v are given - exit(NS::ExitCode::VULNERABLE) if controller.parsed_options[:url] && controller.target.vulnerable? - exit(NS::ExitCode::OK) - end - end - # :nocov: - - # @return [ Integer ] The exit code related to the run_error - def run_error_exit_code - return NS::ExitCode::CLI_OPTION_ERROR if run_error.is_a?(OptParseValidator::Error) || - run_error.is_a?(OptionParser::ParseError) - - return NS::ExitCode::INTERRUPTED if run_error.is_a?(Interrupt) - - return NS::ExitCode::ERROR if run_error.is_a?(NS::Error) || run_error.is_a?(CMSScanner::Error) - - NS::ExitCode::EXCEPTION - end end end require "#{CMSScanner::APP_DIR}/app"