Class: Arachni::UI::CLI::RestoredFramework::OptionParser

Inherits:
OptionParser show all
Defined in:
ui/cli/restored_framework/option_parser.rb

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OptionParser

#initialize, #on, #options, #parse, #parser, #separator

Methods included from Utilities

#list_checks, #list_platforms, #list_plugins, #list_reporters, #load_profile, #print_banner, #print_issues, #save_profile

Methods included from Support::Mixins::Terminal

#clear_screen, #empty_screen, #flush, #move_to_home, #reprint, #reputs, #restr

Methods included from Arachni::Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Methods included from Output

#caller_location, #debug?, #debug_level, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, #disable_only_positives, #error_buffer, #error_log_fd, #error_logfile, #has_error_log?, #included, #log_error, #mute, #muted?, #only_positives, #only_positives?, #print_bad, #print_debug, #print_debug_backtrace, #print_debug_exception, #print_debug_level_1, #print_debug_level_2, #print_debug_level_3, #print_debug_level_4, #print_error, #print_error_backtrace, #print_exception, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?, reset_output_options, #set_error_logfile, #unmute, #verbose?, #verbose_off, #verbose_on

Constructor Details

This class inherits a constructor from Arachni::UI::CLI::OptionParser

Instance Attribute Details

#snapshot_pathObject

Returns the value of attribute snapshot_path.



19
20
21
# File 'ui/cli/restored_framework/option_parser.rb', line 19

def snapshot_path
  @snapshot_path
end

Instance Method Details

#after_parseObject



85
86
87
# File 'ui/cli/restored_framework/option_parser.rb', line 85

def after_parse
    @snapshot_path = ARGV.shift
end


144
145
146
# File 'ui/cli/restored_framework/option_parser.rb', line 144

def banner
    "Usage: #{$0} SNAPSHOT"
end

#get_timeoutObject



45
46
47
# File 'ui/cli/restored_framework/option_parser.rb', line 45

def get_timeout
    @timeout
end

Returns:

  • (Boolean)


81
82
83
# File 'ui/cli/restored_framework/option_parser.rb', line 81

def print_metadata?
    !!@print_metadata
end

#reportObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'ui/cli/restored_framework/option_parser.rb', line 67

def report
    separator ''
    separator 'Report'

    on( '--report-save-path PATH', String,
        'Directory or file path where to store the scan report.',
        "You can use the generated file to create reports in several " +
            "formats with the 'arachni_report' executable."
    ) do |path|
        options.datastore.report_path = path
    end
end

#snapshotObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'ui/cli/restored_framework/option_parser.rb', line 49

def snapshot
    separator ''
    separator 'Snapshot'

    on( '--snapshot-print-metadata',
        'Show the metadata associated with the specified snapshot.' ) do
        @print_metadata = true
    end

    on( '--snapshot-save-path PATH', String,
        'Directory or file path where to store the scan snapshot.',
        'You can use the generated file to resume the scan at a later time ' +
            "with the 'arachni_restore' executable."
    ) do |path|
        options.snapshot.save_path = path
    end
end

#timeoutObject



21
22
23
24
25
26
27
28
29
30
# File 'ui/cli/restored_framework/option_parser.rb', line 21

def timeout
    separator ''
    separator 'Timeout'

    on( '--timeout HOURS:MINUTES:SECONDS',
        'Stop the scan after the given duration is exceeded.'
    ) do |time|
        @timeout = Arachni::Utilities.hms_to_seconds( time )
    end
end

#timeout_suspendObject



32
33
34
35
36
37
38
39
# File 'ui/cli/restored_framework/option_parser.rb', line 32

def timeout_suspend
    on( '--timeout-suspend',
        'Suspend after the timeout.',
        'You can use the generated file to resume the scan with the \'arachni_restore\' executable.'
    ) do
        @timeout_suspend = true
    end
end

#timeout_suspend?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'ui/cli/restored_framework/option_parser.rb', line 41

def timeout_suspend?
    !!@timeout_suspend
end

#valid_save_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
# File 'ui/cli/restored_framework/option_parser.rb', line 140

def valid_save_path?( path )
    !path || File.directory?( path ) || !path.end_with?( '/' )
end

#validateObject



89
90
91
92
93
94
# File 'ui/cli/restored_framework/option_parser.rb', line 89

def validate
    validate_timeout
    validate_report_path
    validate_snapshot_path
    validate_snapshot_save_path
end

#validate_report_pathObject



132
133
134
135
136
137
138
# File 'ui/cli/restored_framework/option_parser.rb', line 132

def validate_report_path
    report_path = options.datastore.report_path
    return if valid_save_path?( report_path )

    print_error "Report path does not exist: #{report_path}"
    exit 1
end

#validate_snapshot_pathObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ui/cli/restored_framework/option_parser.rb', line 103

def validate_snapshot_path
    if !@snapshot_path
        print_error 'No snapshot file provided.'
        exit 1
    end

    @snapshot_path = File.expand_path( @snapshot_path )

    if !File.exists?( @snapshot_path )
        print_error "Snapshot does not exist: #{@snapshot_path}"
        exit 1
    end

    begin
        Snapshot. @snapshot_path
    rescue Snapshot::Error::InvalidFile => e
        print_error e.to_s
        exit 1
    end
end

#validate_snapshot_save_pathObject



124
125
126
127
128
129
130
# File 'ui/cli/restored_framework/option_parser.rb', line 124

def validate_snapshot_save_path
    snapshot_path = options.snapshot.save_path
    return if valid_save_path?( snapshot_path )

    print_error "Snapshot path does not exist: #{snapshot_path}"
    exit 1
end

#validate_timeoutObject



96
97
98
99
100
101
# File 'ui/cli/restored_framework/option_parser.rb', line 96

def validate_timeout
    return if !@timeout || @timeout > 0

    print_bad 'Invalid timeout value.'
    exit 1
end