Module: Arachni::Element::Capabilities::Inputtable

Overview

Author:

  • Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

Defined Under Namespace

Classes: Error

Constant Summary collapse

INPUTTABLE_CACHE =
{
    inputtable_id: Support::Cache::LeastRecentlyPushed.new( 1_000 )
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_inputsHash (readonly)

Frozen version of #inputs, has all the original names and values.

Returns:



47
48
49
# File 'lib/arachni/element/capabilities/inputtable.rb', line 47

def default_inputs
  @default_inputs
end

#inputsHash

Note:

Can be modified via #update, #[]= or #inputs=.

Returns Frozen effective inputs.

Returns:

  • (Hash)

    Frozen effective inputs.



53
54
55
# File 'lib/arachni/element/capabilities/inputtable.rb', line 53

def inputs
  @inputs
end

#raw_inputsArray

Note:

Null-bytes will always be encoded.

Returns List of input names which should have their values submitted in raw form, without encoding.

Returns:

  • (Array)

    List of input names which should have their values submitted in raw form, without encoding.



60
61
62
# File 'lib/arachni/element/capabilities/inputtable.rb', line 60

def raw_inputs
  @raw_inputs
end

Class Method Details

.inputtable_id(inputs, raw_inputs) ⇒ Object



271
272
273
274
275
276
277
# File 'lib/arachni/element/capabilities/inputtable.rb', line 271

def self.inputtable_id( inputs, raw_inputs )
    INPUTTABLE_CACHE[:inputtable_id].fetch [inputs, raw_inputs] do
        id  = inputs ? inputs.sort_by { |k, _| k }.hash.to_s : ''
        id << ':'
        id << (raw_inputs ? raw_inputs.sort.hash.to_s : '')
    end
end

Instance Method Details

#[](name) ⇒ String

Shorthand #inputs reader.

Parameters:

  • name (#to_s)

    Name.

Returns:



155
156
157
# File 'lib/arachni/element/capabilities/inputtable.rb', line 155

def []( name )
    @inputs[name.to_s]
end

#[]=(name, value) ⇒ Object

Shorthand #inputs writer.

Parameters:

  • name (#to_s)

    Name.

  • value (#to_s)

    Value.

Raises:



168
169
170
171
# File 'lib/arachni/element/capabilities/inputtable.rb', line 168

def []=( name, value )
    update( name.to_s => value.to_s )
    self[name]
end

#changesHash

Returns changes make to the #inputs's inputs.

Returns:

  • (Hash)

    Returns changes make to the #inputs's inputs.



128
129
130
131
132
133
134
135
# File 'lib/arachni/element/capabilities/inputtable.rb', line 128

def changes
    (@default_inputs.keys | @inputs.keys).inject( {} ) do |h, k|
        if @default_inputs[k] != @inputs[k]
            h[k] = @inputs[k]
        end
        h
    end
end

#dupObject



261
262
263
# File 'lib/arachni/element/capabilities/inputtable.rb', line 261

def dup
    copy_inputtable( super )
end

#has_inputs?(*args) ⇒ Bool

Checks whether or not the given inputs match the inputs ones.

Parameters:

  • args (Hash, Array, String, Symbol)

    Names of inputs to check (also accepts var-args).

Returns:

  • (Bool)


116
117
118
119
120
121
122
123
124
# File 'lib/arachni/element/capabilities/inputtable.rb', line 116

def has_inputs?( *args )
    if (h = args.first).is_a?( Hash )
        h.each { |k, v| return false if self[k] != v }
        true
    else
        keys = args.flatten.compact.map { |a| [a].map(&:to_s) }.flatten
        (@inputs.keys & keys).size == keys.size
    end
end

#initialize(options) ⇒ Object



62
63
64
65
# File 'lib/arachni/element/capabilities/inputtable.rb', line 62

def initialize( options )
    super
    @raw_inputs = []
end

#inputtable_idString

Returns Uniquely identifies the #inputs.

Returns:



267
268
269
# File 'lib/arachni/element/capabilities/inputtable.rb', line 267

def inputtable_id
    Arachni::Element::Capabilities::Inputtable.inputtable_id( inputs, raw_inputs )
end

#raw_input?(name) ⇒ Boolean

Returns `true` if the input `name` is in #raw_inputs, `false` otherwise.

Parameters:

  • name (String)

    Name of the input to check.

Returns:

  • (Boolean)

    `true` if the input `name` is in #raw_inputs, `false` otherwise.



72
73
74
# File 'lib/arachni/element/capabilities/inputtable.rb', line 72

def raw_input?( name )
    @raw_inputs.include? name
end

#resetObject

Resets the inputs to their original format/values.



142
143
144
145
146
147
# File 'lib/arachni/element/capabilities/inputtable.rb', line 142

def reset
    super if defined?( super )
    self.inputs = @default_inputs.rpc_clone
    self.raw_inputs = []
    self
end

#to_hObject



279
280
281
282
283
284
285
# File 'lib/arachni/element/capabilities/inputtable.rb', line 279

def to_h
    (defined?( super ) ? super : {}).merge(
        inputs:         inputs,
        raw_inputs:     raw_inputs,
        default_inputs: default_inputs
    )
end

#try_input(&block) ⇒ Bool

Performs an input operation and silently handles Arachni::Element::Capabilities::Inputtable::Error::InvalidData.

Parameters:

  • block (Block)

    Input operation to try to perform.

Returns:

  • (Bool)

    `true` if the operation was successful, `false` otherwise.



250
251
252
253
254
255
256
257
258
259
# File 'lib/arachni/element/capabilities/inputtable.rb', line 250

def try_input( &block )
    block.call
    true
rescue Error::InvalidData => e
    return false if !respond_to?( :print_debug_level_1 )

    print_debug_level_1 e.to_s
    e.backtrace.each { |l| print_debug_level_1 l }
    false
end

#update(hash) ⇒ Auditable

Returns `self`.

Parameters:

  • hash (Hash)

    Inputs with which to update the #inputs inputs.

Returns:

Raises:



180
181
182
183
184
185
# File 'lib/arachni/element/capabilities/inputtable.rb', line 180

def update( hash )
    return self if hash.empty?

    self.inputs = @inputs.merge( hash )
    self
end

#updated?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/arachni/element/capabilities/inputtable.rb', line 137

def updated?
    @default_inputs != self.inputs
end

#valid_input_data?(data) ⇒ Bool

This method is abstract.

Returns `true` if the data can be carried by the element's inputs, `false` otherwise.

Parameters:

  • data (String)

    Data to check.

Returns:

  • (Bool)

    `true` if the data can be carried by the element's inputs, `false` otherwise.



239
240
241
# File 'lib/arachni/element/capabilities/inputtable.rb', line 239

def valid_input_data?( data )
    true
end

#valid_input_name?(name) ⇒ Bool

This method is abstract.

Returns `true` if the name can be carried by the element's inputs, `false` otherwise.

Parameters:

  • name (String)

    Name to check.

Returns:

  • (Bool)

    `true` if the name can be carried by the element's inputs, `false` otherwise.



195
196
197
# File 'lib/arachni/element/capabilities/inputtable.rb', line 195

def valid_input_name?( name )
    true
end

#valid_input_name_data?(name) ⇒ Bool

Returns `true` if `name` is both a #valid_input_name? and contains #valid_input_data?.

Parameters:

  • name (String)

    Name to check.

Returns:



205
206
207
# File 'lib/arachni/element/capabilities/inputtable.rb', line 205

def valid_input_name_data?( name )
    valid_input_name?( name ) && valid_input_data?( name )
end

#valid_input_value?(value) ⇒ Bool

This method is abstract.

Returns `true` if the value can be carried by the element's inputs, `false` otherwise.

Parameters:

  • value (String)

    Value to check.

Returns:

  • (Bool)

    `true` if the value can be carried by the element's inputs, `false` otherwise.



217
218
219
# File 'lib/arachni/element/capabilities/inputtable.rb', line 217

def valid_input_value?( value )
    true
end

#valid_input_value_data?(value) ⇒ Bool

Returns `true` if `value` is both a #valid_input_value? and contains #valid_input_data?.

Parameters:

  • value (String)

    Value to check.

Returns:



227
228
229
# File 'lib/arachni/element/capabilities/inputtable.rb', line 227

def valid_input_value_data?( value )
    valid_input_value?( value ) && valid_input_data?( value )
end