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.



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

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:



129
130
131
# File 'lib/arachni/options.rb', line 129

def authorized_by
  @authorized_by
end

#checksArray<String, Symbol>

Returns Checks to load, by name.

Returns:

See Also:



105
106
107
# File 'lib/arachni/options.rb', line 105

def checks
  @checks
end

#no_fingerprintingBool

Returns Disable platform fingeprinting.

Returns:

  • (Bool)

    Disable platform fingeprinting.

See Also:



138
139
140
# File 'lib/arachni/options.rb', line 138

def no_fingerprinting
  @no_fingerprinting
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:



114
115
116
# File 'lib/arachni/options.rb', line 114

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:



122
123
124
# File 'lib/arachni/options.rb', line 122

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


145
146
147
# File 'lib/arachni/options.rb', line 145

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

.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

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.



182
183
184
# File 'lib/arachni/options.rb', line 182

def do_not_fingerprint
    self.no_fingerprinting = true
end

#fingerprintObject

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.

Returns:

  • (Bool)

    ‘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.

Parameters:

Returns:



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.

Parameters:

  • filepath (String)

    Path to the file created by #save.

Returns:



314
315
316
# File 'lib/arachni/options.rb', line 314

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

#resetOptions

Restores everything to their default values.

Returns:



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.

Parameters:

Returns:



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

Parameters:

  • file (String)

    Saves ‘self` to `file` using YAML.



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

Returns ‘self` converted to a Hash.

Returns:

  • (Hash)

    ‘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_dataHash

Returns ‘self` converted to a Hash suitable for RPC transmission.

Returns:

  • (Hash)

    ‘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_dataObject



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.

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:



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/arachni/options.rb', line 270

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.



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