Class: Arachni::Options
- Includes:
- Singleton
- Defined in:
- lib/arachni/options.rb
Overview
Provides access to all of Arachni‘s runtime options.
To make management of options for different subsystems easier, some options are grouped together.
Option groups are initialized and added as attribute readers to this class dynamically. Their attribute readers are named after the group’s filename and can be accessed, like so:
Arachni::Options.scope.page_limit = 10
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#authorized_by ⇒ String
E-mail address of the person that authorized the scan.
-
#checks ⇒ Array<String, Symbol>
Checks to load, by name.
-
#no_fingerprinting ⇒ Bool
Disable platform fingeprinting.
-
#platforms ⇒ Array<Symbol>
Platforms to use instead of (or in addition to, depending on the option) fingerprinting.
-
#plugins ⇒ Hash{<String, Symbol> => Hash{String => String}}
Plugins to load, by name, as keys and their options as values.
-
#spawns ⇒ Integer
Amount of child RPC::Server::Instances to spawn when performing multi-RPC::Server::Instance scans.
-
#url ⇒ String
The URL to audit.
Class Method Summary collapse
-
.group_classes ⇒ Hash<Symbol,OptionGroup>
Option group classes by name.
- .method_missing(sym, *args, &block) ⇒ Object
-
.register_group(group) ⇒ Object
Should be called by Arachni::OptionGroup.inherited.
- .respond_to?(*args) ⇒ Boolean
Instance Method Summary collapse
-
#do_not_fingerprint ⇒ Object
Disables platform fingerprinting.
-
#fingerprint ⇒ Object
Enables platform fingerprinting.
-
#fingerprint? ⇒ Bool
‘true` if platform fingerprinting is enabled, `false` otherwise.
-
#hash_to_rpc_data(hash) ⇒ Hash
‘hash` in #to_rpc_data format.
- #hash_to_save_data(hash) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
-
#load(filepath) ⇒ Arachni::Options
Loads a file created by #save.
-
#reset ⇒ Options
Restores everything to their default values.
-
#rpc_data_to_hash(hash) ⇒ Hash
‘hash` in #to_hash format.
- #save(file) ⇒ Object
-
#to_hash ⇒ Hash
(also: #to_h)
‘self` converted to a Hash.
-
#to_rpc_data ⇒ Hash
‘self` converted to a Hash suitable for RPC transmission.
- #to_save_data ⇒ Object
-
#update(options) ⇒ Options
(also: #set)
Configures options via a Hash object.
-
#validate ⇒ Hash
Hash of errors with the name of the invalid options/groups as the keys.
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
147 148 149 |
# File 'lib/arachni/options.rb', line 147 def initialize reset end |
Instance Attribute Details
#authorized_by ⇒ String
Returns E-mail address of the person that authorized the scan. It will be added to the HTTP ‘From` headers.
129 130 131 |
# File 'lib/arachni/options.rb', line 129 def @authorized_by end |
#checks ⇒ Array<String, Symbol>
Returns Checks to load, by name.
105 106 107 |
# File 'lib/arachni/options.rb', line 105 def checks @checks end |
#no_fingerprinting ⇒ Bool
Returns Disable platform fingeprinting.
138 139 140 |
# File 'lib/arachni/options.rb', line 138 def no_fingerprinting @no_fingerprinting end |
#platforms ⇒ Array<Symbol>
Returns Platforms to use instead of (or in addition to, depending on the option) fingerprinting.
114 115 116 |
# File 'lib/arachni/options.rb', line 114 def platforms @platforms end |
#plugins ⇒ Hash{<String, Symbol> => Hash{String => String}}
Returns Plugins to load, by name, as keys and their options as values.
122 123 124 |
# File 'lib/arachni/options.rb', line 122 def plugins @plugins end |
#spawns ⇒ Integer
Returns Amount of child RPC::Server::Instances to spawn when performing multi-RPC::Server::Instance scans.
145 146 147 |
# File 'lib/arachni/options.rb', line 145 def spawns @spawns end |
#url ⇒ String
Returns The URL to audit.
97 98 99 |
# File 'lib/arachni/options.rb', line 97 def url @url end |
Class Method Details
.group_classes ⇒ Hash<Symbol,OptionGroup>
Returns Option group classes by name.
73 74 75 |
# File 'lib/arachni/options.rb', line 73 def group_classes @group_classes ||= {} end |
.method_missing(sym, *args, &block) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/arachni/options.rb', line 55 def method_missing( sym, *args, &block ) if instance.respond_to?( sym ) instance.send( sym, *args, &block ) else super( sym, *args, &block ) end end |
.register_group(group) ⇒ Object
Should be called by Arachni::OptionGroup.inherited.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/arachni/options.rb', line 79 def register_group( group ) name = Utilities.caller_name # Prepare an attribute reader for this group... attr_reader name # ... and initialize it. instance_variable_set "@#{name}".to_sym, group.new group_classes[name.to_sym] = group end |
.respond_to?(*args) ⇒ Boolean
63 64 65 |
# File 'lib/arachni/options.rb', line 63 def respond_to?( *args ) super || instance.respond_to?( *args ) end |
Instance Method Details
#do_not_fingerprint ⇒ Object
Disables platform fingerprinting.
182 183 184 |
# File 'lib/arachni/options.rb', line 182 def do_not_fingerprint self.no_fingerprinting = true end |
#fingerprint ⇒ Object
Enables platform fingerprinting.
187 188 189 |
# File 'lib/arachni/options.rb', line 187 def fingerprint self.no_fingerprinting = false end |
#fingerprint? ⇒ Bool
Returns ‘true` if platform fingerprinting is enabled, `false` otherwise.
193 194 195 |
# File 'lib/arachni/options.rb', line 193 def fingerprint? !@no_fingerprinting end |
#hash_to_rpc_data(hash) ⇒ Hash
Returns ‘hash` in #to_rpc_data format.
372 373 374 |
# File 'lib/arachni/options.rb', line 372 def hash_to_rpc_data( hash ) self.class.allocate.reset.update( hash ).to_rpc_data end |
#hash_to_save_data(hash) ⇒ Object
376 377 378 |
# File 'lib/arachni/options.rb', line 376 def hash_to_save_data( hash ) self.class.allocate.reset.update( hash ).to_save_data end |
#load(filepath) ⇒ Arachni::Options
Loads a file created by #save.
314 315 316 |
# File 'lib/arachni/options.rb', line 314 def load( filepath ) update( YAML.load_file( filepath ) ) end |
#reset ⇒ Options
Restores everything to their default values.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/arachni/options.rb', line 154 def reset # nil everything out. instance_variables.each { |var| instance_variable_set( var.to_s, nil ) } # Set fresh option groups. group_classes.each do |name, klass| instance_variable_set "@#{name}".to_sym, klass.new end @checks = [] @platforms = [] @plugins = {} @spawns = 0 @no_fingerprinting = false @authorized_by = nil self end |
#rpc_data_to_hash(hash) ⇒ Hash
Returns ‘hash` in #to_hash format.
363 364 365 |
# File 'lib/arachni/options.rb', line 363 def rpc_data_to_hash( hash ) self.class.allocate.reset.update( hash ).to_hash end |
#save(file) ⇒ Object
297 298 299 300 301 302 |
# File 'lib/arachni/options.rb', line 297 def save( file ) File.open( file, 'w' ) do |f| f.write to_save_data f.path end end |
#to_hash ⇒ Hash Also known as: to_h
Returns ‘self` converted to a Hash.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/arachni/options.rb', line 342 def to_hash hash = {} instance_variables.each do |var| val = instance_variable_get( var ) next if (var = normalize_name( var )) == :instance hash[var] = (val.is_a? OptionGroup) ? val.to_h : val end hash.delete( :url ) if !hash[:url] hash.delete(:paths) hash.deep_clone end |
#to_rpc_data ⇒ Hash
Returns ‘self` converted to a Hash suitable for RPC transmission.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/arachni/options.rb', line 320 def to_rpc_data ignore = Set.new([:instance, :rpc, :dispatcher, :paths, :spawns, :snapshot, :output]) hash = {} instance_variables.each do |var| val = instance_variable_get( var ) var = normalize_name( var ) next if ignore.include?( var ) hash[var.to_s] = (val.is_a? OptionGroup) ? val.to_rpc_data : val end hash = hash.deep_clone hash.delete( 'url' ) if !hash['url'] hash end |
#to_save_data ⇒ Object
304 305 306 |
# File 'lib/arachni/options.rb', line 304 def to_save_data to_rpc_data.to_yaml end |
#update(options) ⇒ Options Also known as: set
Configures options via a Hash object.
270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/arachni/options.rb', line 270 def update( ) .each do |k, v| k = k.to_sym if group_classes.include? k send( k ).update v else send( "#{k.to_s}=", v ) end end self end |
#validate ⇒ Hash
Returns Hash of errors with the name of the invalid options/groups as the keys.
286 287 288 289 290 291 292 293 |
# File 'lib/arachni/options.rb', line 286 def validate errors = {} group_classes.keys.each do |name| next if (group_errors = send(name).validate).empty? errors[name] = group_errors end errors end |