Class: Arachni::Options

Inherits:
Object show all
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

See Also:

Author:

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.


150
151
152
# File 'lib/arachni/options.rb', line 150

def initialize
    reset
end

Instance Attribute Details

#authorized_byString

Returns E-mail address of the person that authorized the scan. It will be added to the HTTP From headers.

Returns:

  • (String)

    E-mail address of the person that authorized the scan. It will be added to the HTTP From headers.

See Also:


132
133
134
# File 'lib/arachni/options.rb', line 132

def authorized_by
  @authorized_by
end

#checksArray<String, Symbol>

Returns Checks to load, by name.

Returns:

See Also:


108
109
110
# File 'lib/arachni/options.rb', line 108

def checks
  @checks
end

#no_fingerprintingBool

Returns Disable platform fingeprinting.

Returns:

  • (Bool)

    Disable platform fingeprinting.

See Also:


141
142
143
# File 'lib/arachni/options.rb', line 141

def no_fingerprinting
  @no_fingerprinting
end

#parsed_urlArachni::URI (readonly)

Returns:


100
101
102
# File 'lib/arachni/options.rb', line 100

def parsed_url
  @parsed_url
end

#platformsArray<Symbol>

Returns Platforms to use instead of (or in addition to, depending on the option) fingerprinting.

Returns:

  • (Array<Symbol>)

    Platforms to use instead of (or in addition to, depending on the option) fingerprinting.

See Also:


117
118
119
# File 'lib/arachni/options.rb', line 117

def platforms
  @platforms
end

#pluginsHash{<String, Symbol> => Hash{String => String}}

Returns Plugins to load, by name, as keys and their options as values.

Returns:

See Also:


125
126
127
# File 'lib/arachni/options.rb', line 125

def plugins
  @plugins
end

#spawnsInteger

Returns Amount of child RPC::Server::Instances to spawn when performing multi-RPC::Server::Instance scans.

Returns:

See Also:

  • UI::CLI::RPC::Instance#scan

148
149
150
# File 'lib/arachni/options.rb', line 148

def spawns
  @spawns
end

#urlString

Returns The URL to audit.

Returns:

  • (String)

    The URL to audit.


97
98
99
# File 'lib/arachni/options.rb', line 97

def url
  @url
end

Class Method Details

.group_classesHash<Symbol,OptionGroup>

Returns Option group classes by name.

Returns:


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

.respond_to?(*args) ⇒ Boolean

Returns:

  • (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_fingerprintObject

Disables platform fingerprinting.


185
186
187
# File 'lib/arachni/options.rb', line 185

def do_not_fingerprint
    self.no_fingerprinting = true
end

#fingerprintObject

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.

Returns:

  • (Bool)

    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.

Parameters:

Returns:


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.

Parameters:

  • filepath (String)

    Path to the file created by #save.

Returns:


331
332
333
# File 'lib/arachni/options.rb', line 331

def load( filepath )
    update( YAML.load_file( filepath ) )
end

#resetOptions

Restores everything to their default values.

Returns:


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.

Parameters:

Returns:


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

Parameters:

  • file (String)

    Saves self to file using YAML.


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_hashHash Also known as: to_h

Returns self converted to a Hash.

Returns:

  • (Hash)

    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_dataHash

Returns self converted to a Hash suitable for RPC transmission.

Returns:

  • (Hash)

    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_dataObject


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.

Examples:

Configuring direct and Arachni::OptionGroups attributes.


{
    # Direct Options#url attribute.
    url:    'http://test.com/',
    # Options#audit attribute pointing to an OptionGroups::Audit instance.
    audit:  {
        # Works due to the OptionGroups::Audit#elements= helper method.
        elements: [ :links, :forms, :cookies ]
    },
    # Direct Options#checks attribute.
    checks: [ :xss, 'sql_injection*' ],
    # Options#scope attribute pointing to an OptionGroups::Scope instance.
    scope:  {
        # OptionGroups::Scope#page_limit
        page_limit:            10,
        # OptionGroups::Scope#directory_depth_limit
        directory_depth_limit: 3
    },
    # Options#http attribute pointing to an OptionGroups::HTTP instance.
    http:  {
        # OptionGroups::HTTP#request_concurrency
        request_concurrency: 25,
        # OptionGroups::HTTP#request_timeout
        request_timeout:     10_000
    }
}

Parameters:

Returns:

See Also:


287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/arachni/options.rb', line 287

def update( options )
    options.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

#validateHash

Returns Hash of errors with the name of the invalid options/groups as the keys.

Returns:

  • (Hash)

    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