Class: CMSScanner::Scan

Inherits:
Object
  • Object
show all
Defined in:
lib/cms_scanner.rb

Overview

Scan

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Scan

Returns a new instance of Scan.

Yields:

  • (_self)

Yield Parameters:



87
88
89
90
91
92
93
# File 'lib/cms_scanner.rb', line 87

def initialize
  controllers << NS::Controller::Core.new

  exit_hook

  yield self if block_given?
end

Instance Attribute Details

#run_errorObject (readonly)

Returns the value of attribute run_error.



85
86
87
# File 'lib/cms_scanner.rb', line 85

def run_error
  @run_error
end

Instance Method Details

#controllersControllers

Returns:



96
97
98
# File 'lib/cms_scanner.rb', line 96

def controllers
  @controllers ||= NS::Controllers.new
end

#datastoreHash

Returns:

  • (Hash)


126
127
128
# File 'lib/cms_scanner.rb', line 126

def datastore
  controllers.first.datastore
end

#exit_hookObject

Hook to be able to have an exit code returned depending on the findings / errors



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cms_scanner.rb', line 132

def exit_hook
  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

#formatterObject

Used for convenience



121
122
123
# File 'lib/cms_scanner.rb', line 121

def formatter
  controllers.first.formatter
end

#runObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cms_scanner.rb', line 100

def run
  controllers.run
rescue OptParseValidator::NoRequiredOption => e
  @run_error = e

  formatter.output('@usage', msg: e.message)
rescue StandardError, SignalException => 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])
ensure
  Browser.instance.hydra.abort

  formatter.beautify
end

#run_error_exit_codeInteger

Returns The exit code related to the run_error.

Returns:

  • (Integer)

    The exit code related to the run_error



145
146
147
148
149
150
151
152
# File 'lib/cms_scanner.rb', line 145

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)

  NS::ExitCode::ERROR
end