Class: Arachni::Options

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/options.rb,
lib/rpc/xml/server/options.rb

Overview

Overrides the Options class adding support for direct options parsing.

Not much to look at but it streamlines XML-RPC server option handling.

@author: Tasos “Zapotek” Laskos

<[email protected]>
<[email protected]>

@version: 0.1

Constant Summary collapse

PROFILE_EXT =

The extension of the profile files.

Returns:

'.afp'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/options.rb', line 332

def initialize( )

    # nil everything out
    self.instance_variables.each {
        |var|
        instance_variable_set( var.to_s, nil )
    }

    @exclude    = []
    @include    = []
    @redundant  = []

    @reports    = {}
    @lsrep      = []

    @lsmod      = []
    @dir        = Hash.new
    @exclude_cookies    = []
    @load_profile       = []

    @plugins = {}
    @lsplug  = []

    # set some defaults
    @redirect_limit = 20

    # relatively low but will give good performance without bottleneck
    # on low bandwidth conections
    @http_req_limit = 20

end

Instance Attribute Details

#arachni_verboseBool

Be verbose?

Returns:

  • (Bool)


70
71
72
# File 'lib/options.rb', line 70

def arachni_verbose
  @arachni_verbose
end

#audit_cookiesBool

Should Arachni audit cookies?

Returns:

  • (Bool)


157
158
159
# File 'lib/options.rb', line 157

def audit_cookies
  @audit_cookies
end

#audit_formsBool

Should Arachni audit forms?

Returns:

  • (Bool)


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

def audit_forms
  @audit_forms
end

#audit_headersBool

Should Arachni audit HTTP headers?

Returns:

  • (Bool)


164
165
166
# File 'lib/options.rb', line 164

def audit_headers
  @audit_headers
end

Should Arachni audit links?

Returns:

  • (Bool)


143
144
145
# File 'lib/options.rb', line 143

def audit_links
  @audit_links
end

#authed_byString

The person that authorized the scan<br/> It will be added to the HTTP “user-agent” and “from” headers.

Returns:



210
211
212
# File 'lib/options.rb', line 210

def authed_by
  @authed_by
end

Location of the cookiejar

Returns:



261
262
263
# File 'lib/options.rb', line 261

def cookie_jar
  @cookie_jar
end

#cookiesHash

To be populated by the framework

Parsed cookiejar cookies

Returns:

  • (Hash)

    name=>value pairs



254
255
256
# File 'lib/options.rb', line 254

def cookies
  @cookies
end

#debugBool

Output debugging messages?

Returns:

  • (Bool)


77
78
79
# File 'lib/options.rb', line 77

def debug
  @debug
end

#delta_timeObject

to be populated by the framework



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

def delta_time
  @delta_time
end

#depth_limitInteger

How deep to go in the site structure?<br/> If nil, depth_limit = inf

Returns:

  • (Integer)


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

def depth_limit
  @depth_limit
end

#dirHash

Holds absolute paths for the directory structure of the framework

Returns:

  • (Hash)


42
43
44
# File 'lib/options.rb', line 42

def dir
  @dir
end

#excludeArray

Exclude filters <br/> URL matching any of these patterns won’t be followed

Returns:

  • (Array)


276
277
278
# File 'lib/options.rb', line 276

def exclude
  @exclude
end

#exclude_cookiesArray

Cookies to exclude from audit<br/>

Returns:

  • (Array)


283
284
285
# File 'lib/options.rb', line 283

def exclude_cookies
  @exclude_cookies
end

#finish_datetimeObject

to be populated by the framework



311
312
313
# File 'lib/options.rb', line 311

def finish_datetime
  @finish_datetime
end

#follow_subdomainsBool

Should the crawler follow subdomains?

Returns:

  • (Bool)


298
299
300
# File 'lib/options.rb', line 298

def follow_subdomains
  @follow_subdomains
end

#helpBool

Show help?

Returns:

  • (Bool)


56
57
58
# File 'lib/options.rb', line 56

def help
  @help
end

#http_harvest_lastBool

Harvest the HTTP responses for the whole site at the end or for each page?

Returns:

  • (Bool)


306
307
308
# File 'lib/options.rb', line 306

def http_harvest_last
  @http_harvest_last
end

#http_req_limitInteger

How many concurrent HTTP requests?

Returns:

  • (Integer)


136
137
138
# File 'lib/options.rb', line 136

def http_req_limit
  @http_req_limit
end

#includeArray

Include filters <br/> Only URLs that match any of these patterns will be followed

Returns:

  • (Array)


291
292
293
# File 'lib/options.rb', line 291

def include
  @include
end

How many links to follow? If nil, link_count_limit = inf

Returns:

  • (Integer)


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

def link_count_limit
  @link_count_limit
end

#load_profileArray

Location of Arachni Framework Profile (.afp) files to load

Returns:

  • (Array)


199
200
201
# File 'lib/options.rb', line 199

def load_profile
  @load_profile
end

#lsmodArray<Regexp>

List modules, based on regexps, and exit?

Returns:

  • (Array<Regexp>)


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

def lsmod
  @lsmod
end

#lsplugObject

Returns the value of attribute lsplug.



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

def lsplug
  @lsplug
end

#lsrepBool

List reports and exit?

Returns:

  • (Bool)


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

def lsrep
  @lsrep
end

#modsArray

Array of modules to load

Returns:

  • (Array)


171
172
173
# File 'lib/options.rb', line 171

def mods
  @mods
end

#obey_robots_txtBool

Should the crawler obery robots.txt files?

Returns:

  • (Bool)


91
92
93
# File 'lib/options.rb', line 91

def obey_robots_txt
  @obey_robots_txt
end

#only_positivesBool

Output only positive results during the audit?

Returns:

  • (Bool)


63
64
65
# File 'lib/options.rb', line 63

def only_positives
  @only_positives
end

#pluginsObject

Returns the value of attribute plugins.



316
317
318
# File 'lib/options.rb', line 316

def plugins
  @plugins
end

#pool_sizeObject

Returns the value of attribute pool_size.



329
330
331
# File 'lib/options.rb', line 329

def pool_size
  @pool_size
end

#proxy_addrString

The address of the proxy server

Returns:



217
218
219
# File 'lib/options.rb', line 217

def proxy_addr
  @proxy_addr
end

#proxy_passString

The proxy password

Returns:



231
232
233
# File 'lib/options.rb', line 231

def proxy_pass
  @proxy_pass
end

#proxy_portString

The port to connect on the proxy server

Returns:



224
225
226
# File 'lib/options.rb', line 224

def proxy_port
  @proxy_port
end

#proxy_typeString

The proxy type

Returns:



245
246
247
# File 'lib/options.rb', line 245

def proxy_type
  @proxy_type
end

#proxy_userString

The proxy user

Returns:



238
239
240
# File 'lib/options.rb', line 238

def proxy_user
  @proxy_user
end

#redirect_limitInteger

How many redirects to follow? If nil, redirect_limit = inf

Returns:

  • (Integer)


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

def redirect_limit
  @redirect_limit
end

#redundantArray

Filters for redundant links

Returns:

  • (Array)


84
85
86
# File 'lib/options.rb', line 84

def redundant
  @redundant
end

#reploadString

Location of an Arachni Framework Report (.afr) file to load

Returns:



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

def repload
  @repload
end

#reportsArray

Array of reports to load

Returns:

  • (Array)


178
179
180
# File 'lib/options.rb', line 178

def reports
  @reports
end

#reroute_to_logfileObject

Returns the value of attribute reroute_to_logfile.



328
329
330
# File 'lib/options.rb', line 328

def reroute_to_logfile
  @reroute_to_logfile
end

#rpc_portObject

Returns the value of attribute rpc_port.



320
321
322
# File 'lib/options.rb', line 320

def rpc_port
  @rpc_port
end

#save_profileString

Where to save the Arachni Framework Profile (.afp) file

Returns:



192
193
194
# File 'lib/options.rb', line 192

def save_profile
  @save_profile
end

#serverObject

Returns the value of attribute server.



326
327
328
# File 'lib/options.rb', line 326

def server
  @server
end

#show_profileObject

Returns the value of attribute show_profile.



202
203
204
# File 'lib/options.rb', line 202

def show_profile
  @show_profile
end

#spider_firstObject

Returns the value of attribute spider_first.



318
319
320
# File 'lib/options.rb', line 318

def spider_first
  @spider_first
end

#sslObject

Returns the value of attribute ssl.



321
322
323
# File 'lib/options.rb', line 321

def ssl
  @ssl
end

#ssl_caObject

Returns the value of attribute ssl_ca.



324
325
326
# File 'lib/options.rb', line 324

def ssl_ca
  @ssl_ca
end

#ssl_certObject

Returns the value of attribute ssl_cert.



323
324
325
# File 'lib/options.rb', line 323

def ssl_cert
  @ssl_cert
end

#ssl_pkeyObject

Returns the value of attribute ssl_pkey.



322
323
324
# File 'lib/options.rb', line 322

def ssl_pkey
  @ssl_pkey
end

#start_datetimeObject

to be populated by the framework



309
310
311
# File 'lib/options.rb', line 309

def start_datetime
  @start_datetime
end

#urlString, URI

The URL to audit

Returns:



49
50
51
# File 'lib/options.rb', line 49

def url
  @url
end

#user_agentString

The HTTP user-agent to use

Returns:



268
269
270
# File 'lib/options.rb', line 268

def user_agent
  @user_agent
end

Instance Method Details

#merge!(options) ⇒ Object

Merges self with the object in ‘options’

Parameters:



433
434
435
436
437
438
439
440
# File 'lib/options.rb', line 433

def merge!( options )
    options.to_h.each_pair {
        |k, v|

        next if ( v.is_a?( Array ) || v.is_a?( Hash ) ) && v.empty?
        send( "#{k}=", v ) if v
    }
end

#resetObject

Resets all important options that can affect the scan during framework reuse.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rpc/xml/server/options.rb', line 42

def reset
    # nil everything out
    self.instance_variables.each {
        |var|

        # do *NOT* nil out @dir, we'll loose our paths!
        next if var.to_s == '@dir'

        begin
            instance_variable_set( var.to_s, nil )
        rescue Exception
        end
    }


    @exclude    = []
    @include    = []
    @redundant  = []
    @lsmod      = []
    @exclude_cookies    = []

    # set some defaults
    @redirect_limit = 20

    # relatively low but will give good performance without bottleneck
    # on low bandwidth conections
    @http_req_limit = 20
end

#save(file) ⇒ Object

Saves ‘self’ to file

Parameters:



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/options.rb', line 369

def save( file )

    dir           = @dir.clone
    load_profile  = @load_profile.clone if @load_profile
    save_profile  = @save_profile.clone if @save_profile
    authed_by     = @authed_by.clone if @authed_by

    @dir          = nil
    @load_profile = nil
    @save_profile = nil
    @authed_by    = nil

    begin
        f = File.open( file + PROFILE_EXT, 'w' )
        YAML.dump( self, f )
    rescue
        return
    ensure
        f.close

        @dir          = dir
        @load_profile = load_profile
        @save_profile = save_profile
        @authed_by    = authed_by
    end

    return f.path
end

#set(hash) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rpc/xml/server/options.rb', line 25

def set( hash )
    hash.each_pair {
        |k, v|
        begin
            send( "#{k.to_s}=", v )
        rescue Exception => e
            ap e
            ap e.backtrace
        end
    }
    true
end

#to_arg(key) ⇒ Object



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/options.rb', line 457

def to_arg( key )

    var = self.instance_variable_get( "@#{key}" )

    return if !var
    return if ( var.is_a?( Array ) || var.is_a?( Hash ) ) && var.empty?
    return if key == 'show_profile'
    return if key == 'url'
    return if key == 'dir'
    return if key == 'include' && var == [/.*/]
    return if key == 'reports' && var == ['stdout']

    key = 'exclude_cookie' if key == 'exclude_cookies'
    key = 'report'         if key == 'reports'

    key = key.gsub( '_', '-' )

    arg = ''

    case key

        when 'mods'
            var = var.join( ',' )

        when 'arachni-verbose'
            key = 'verbosity'

        when 'redundant'
            var.each {
                |rule|
                arg += " --#{key}=#{rule['regexp'].source}:#{rule['count']}"
            }
            return arg

        when 'plugins','report'
            arg = ''
            var.each {
                |opt, val|
                arg += " --#{key.chomp( 's' )}=#{opt}"
                arg += ':' if !val.empty?

                val.each {
                    |k, v|
                    arg += "#{k}=#{v},"
                }

                arg.chomp!( ',' )
            }
            return arg

        when 'proxy-port'
            return

        when 'proxy-addr'
            return "--proxy=#{self.proxy_addr}:#{self.proxy_port}"


    end

    if( var.is_a?( TrueClass ) )
        arg = "--#{key}"
    end

    if( var.is_a?( String ) || var.is_a?( Fixnum ) )
        arg = "--#{key}=#{var.to_s}"
    end

    if( var.is_a?( Array ) )

        var.each {
            |i|

            i = i.source if i.is_a?( Regexp )

            arg += " --#{key}=#{i}"
        }

    end

    return arg
end

#to_argsObject



442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/options.rb', line 442

def to_args

    cli_args = ''

    self.to_h.keys.each {
        |key|

        arg = self.to_arg( key )

        cli_args += " #{arg.to_s}" if arg
    }

    return cli_args += " #{self.url}"
end

#to_hHash

Converts the Options object to hash

Returns:

  • (Hash)


419
420
421
422
423
424
425
426
# File 'lib/options.rb', line 419

def to_h
    hash = Hash.new
    self.instance_variables.each {
        |var|
        hash[normalize_name( var )] = self.instance_variable_get( var )
    }
    hash
end