Class: Arachni::OptionGroups::Input

Inherits:
Arachni::OptionGroup show all
Defined in:
lib/arachni/option_groups/input.rb

Overview

Holds options, and provides functionality, related to filling in inputs by name.

Author:

Constant Summary collapse

DEFAULT_VALUES =

System default input values.

{
    /name/i    => 'arachni_name',
    /user/i    => 'arachni_user',
    /usr/i     => 'arachni_user',
    /pass/i    => '5543!%arachni_secret',
    /txt/i     => 'arachni_text',
    /num/i     => '132',
    /amount/i  => '100',
    /mail/i    => '[email protected]',
    /account/i => '12',
    /id/i      => '1',
}
DEFAULT =
'1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Arachni::OptionGroup

#==, attr_accessor, #attributes, attributes, defaults, #defaults, #hash, inherited, #initialize, #merge, set_defaults, #to_hash, #to_rpc_data, #update, #validate

Constructor Details

This class inherits a constructor from Arachni::OptionGroup

Instance Attribute Details

#default_valuesHash<Regexp => String>

Returns Default values for #values.

Returns:

See Also:



42
43
44
# File 'lib/arachni/option_groups/input.rb', line 42

def default_values
  @default_values
end

#forceBool

Returns Force #fill all inputs, not just the empty ones.

Returns:

  • (Bool)

    Force #fill all inputs, not just the empty ones.



50
51
52
# File 'lib/arachni/option_groups/input.rb', line 50

def force
  @force
end

#valuesHash<Regexp => String, #call>

Returns Patterns used to match input names and value to use to fill it in. If the value is a callable object (like a ‘Proc`) its return value will be used instead – it will also be passed the name of the vector as an argument.

Returns:

  • (Hash<Regexp => String, #call>)

    Patterns used to match input names and value to use to fill it in. If the value is a callable object (like a ‘Proc`) its return value will be used instead – it will also be passed the name of the vector as an argument.



36
37
38
# File 'lib/arachni/option_groups/input.rb', line 36

def values
  @values
end

#without_defaultsBool

Returns ‘true` if #default_values should be used, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if #default_values should be used, `false` otherwise.



46
47
48
# File 'lib/arachni/option_groups/input.rb', line 46

def without_defaults
  @without_defaults
end

Instance Method Details

#effective_valuesHash<Regexp => String>

Returns #values, merged with #default_values if #without_defaults?.

Returns:



103
104
105
# File 'lib/arachni/option_groups/input.rb', line 103

def effective_values
    without_defaults? ? @values : default_values.merge( @values )
end

#fill(parameters) ⇒ Hash

Note:

If #force? it will fill-in even non-empty inputs.

Tries to fill a hash with values of appropriate type based on the key of the parameter.

Parameters:

  • parameters (Hash)

    Parameters hash.

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/arachni/option_groups/input.rb', line 68

def fill( parameters )
    parameters = parameters.dup

    parameters.each do |k, v|
        next if !force? && !v.to_s.empty?

        value = value_for_name( k, false )

        # Don't overwrite the default values of the parameters unless we've
        # fot a value, even if #force? is in effect.
        if parameters[k].to_s.empty?
            parameters[k] = value || DEFAULT
        elsif value
            parameters[k] = value
        end
    end

    parameters
end

#force?Bool

Returns Force #fill all inputs, not just the empty ones.

Returns:

  • (Bool)

    Force #fill all inputs, not just the empty ones.



121
122
123
# File 'lib/arachni/option_groups/input.rb', line 121

def force?
    !!@force
end

#format_values(values) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/arachni/option_groups/input.rb', line 136

def format_values( values )
    return if !values

    values.inject({}) do |h, (regexp, value)|
        regexp = regexp.is_a?( Regexp ) ? regexp : Regexp.new( regexp.to_s )
        h.merge!( regexp => value )
        h
    end
end

#to_hObject



146
147
148
149
150
151
152
153
# File 'lib/arachni/option_groups/input.rb', line 146

def to_h
    h = super
    [:values, :default_values].each do |k|
        # We can't have blocks in there...
        h[k] = h[k].select{ |_, v| v.is_a? String }.my_stringify
    end
    h
end

#update_values_from_file(location) ⇒ Object

Parameters:

  • location (String)

    Location of a YAML file used to fill in #values.



109
110
111
# File 'lib/arachni/option_groups/input.rb', line 109

def update_values_from_file( location )
    @values.merge!( format_values( YAML.load_file( location ) ) )
end

#value_for_name(name, use_default = true) ⇒ String?

Returns Value for the ‘name` or `nil` if none could be found.

Parameters:

Returns:

  • (String, nil)

    Value for the ‘name` or `nil` if none could be found.



93
94
95
96
97
98
99
# File 'lib/arachni/option_groups/input.rb', line 93

def value_for_name( name, use_default = true )
    effective_values.each do |k, v|
        return v.respond_to?( :call ) ? v.call( name ).to_s : v if name =~ k
    end

    use_default ? DEFAULT : nil
end

#without_defaults?Bool

Returns ‘true` if #default_values should be used, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if #default_values should be used, `false` otherwise.



115
116
117
# File 'lib/arachni/option_groups/input.rb', line 115

def without_defaults?
    !!@without_defaults
end