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.
- #parsed_url ⇒ Arachni::URI readonly
-
#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.
150 151 152 |
# File 'lib/arachni/options.rb', line 150 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.
132 133 134 |
# File 'lib/arachni/options.rb', line 132 def @authorized_by end |
#checks ⇒ Array<String, Symbol>
Returns Checks to load, by name.
108 109 110 |
# File 'lib/arachni/options.rb', line 108 def checks @checks end |
#no_fingerprinting ⇒ Bool
Returns Disable platform fingeprinting.
141 142 143 |
# File 'lib/arachni/options.rb', line 141 def no_fingerprinting @no_fingerprinting end |
#parsed_url ⇒ Arachni::URI (readonly)
100 101 102 |
# File 'lib/arachni/options.rb', line 100 def parsed_url @parsed_url end |
#platforms ⇒ Array<Symbol>
Returns Platforms to use instead of (or in addition to, depending on the option) fingerprinting.
117 118 119 |
# File 'lib/arachni/options.rb', line 117 def platforms @platforms end |
#plugins ⇒ Hash{<String, Symbol> => Hash{String => String}}
Returns Plugins to load, by name, as keys and their options as values.
125 126 127 |
# File 'lib/arachni/options.rb', line 125 def plugins @plugins end |
#spawns ⇒ Integer
Returns Amount of child RPC::Server::Instances to spawn when performing multi-RPC::Server::Instance scans.
148 149 150 |
# File 'lib/arachni/options.rb', line 148 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.
185 186 187 |
# File 'lib/arachni/options.rb', line 185 def do_not_fingerprint self.no_fingerprinting = true end |
#fingerprint ⇒ Object
Enables platform fingerprinting.
190 191 192 |
# File 'lib/arachni/options.rb', line 190 def fingerprint self.no_fingerprinting = false end |
#fingerprint? ⇒ Bool
Returns `true` if platform fingerprinting is enabled, `false` otherwise.
196 197 198 |
# File 'lib/arachni/options.rb', line 196 def fingerprint? !@no_fingerprinting end |
#hash_to_rpc_data(hash) ⇒ Hash
Returns `hash` in #to_rpc_data format.
391 392 393 |
# File 'lib/arachni/options.rb', line 391 def hash_to_rpc_data( hash ) self.class.allocate.reset.update( hash ).to_rpc_data end |
#hash_to_save_data(hash) ⇒ Object
395 396 397 |
# File 'lib/arachni/options.rb', line 395 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.
331 332 333 |
# File 'lib/arachni/options.rb', line 331 def load( filepath ) update( YAML.load_file( filepath ) ) end |
#reset ⇒ Options
Restores everything to their default values.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/arachni/options.rb', line 157 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.
382 383 384 |
# File 'lib/arachni/options.rb', line 382 def rpc_data_to_hash( hash ) self.class.allocate.reset.update( hash ).to_hash end |
#save(file) ⇒ Object
314 315 316 317 318 319 |
# File 'lib/arachni/options.rb', line 314 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.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/arachni/options.rb', line 360 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( :parsed_url ) hash.delete(:paths) hash.deep_clone end |
#to_rpc_data ⇒ Hash
Returns `self` converted to a Hash suitable for RPC transmission.
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/arachni/options.rb', line 337 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.delete( 'parsed_url' ) hash end |
#to_save_data ⇒ Object
321 322 323 |
# File 'lib/arachni/options.rb', line 321 def to_save_data to_rpc_data.to_yaml end |
#update(options) ⇒ Options Also known as: set
Configures options via a Hash object.
287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/arachni/options.rb', line 287 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.
303 304 305 306 307 308 309 310 |
# File 'lib/arachni/options.rb', line 303 def validate errors = {} group_classes.keys.each do |name| next if (group_errors = send(name).validate).empty? errors[name] = group_errors end errors end |