Class: Arachni::Parser::Element::Form

Inherits:
Base show all
Includes:
Module::Utilities
Defined in:
lib/arachni/parser/elements.rb

Constant Summary collapse

FORM_VALUES_ORIGINAL =
'__original_values__'
FORM_VALUES_SAMPLE =
'__sample_values__'

Instance Attribute Summary

Attributes inherited from Base

#action, #auditable, #method, #orig, #raw, #url

Attributes inherited from Element::Auditable

#altered, #opts

Instance Method Summary collapse

Methods included from Module::Utilities

#exception_jail, #get_path, #hash_keys_to_str, #normalize_url, #read_file, #seed, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize

Methods inherited from Base

#dup

Methods inherited from Element::Auditable

#audit, #audit_id, #auditor, #debug?, #get_auditor, #get_status_str, #info, #injection_sets, #override_instance_scope!, #override_instance_scope?, #print_debug, #print_error, #print_status, reset, restrict_to_elements!, #skip?, #submit

Constructor Details

#initialize(url, raw = {}) ⇒ Form

Returns a new instance of Form.



163
164
165
166
167
168
169
170
171
172
# File 'lib/arachni/parser/elements.rb', line 163

def initialize( url, raw = {} )
    super( url, raw )

    @action = @raw['action'] || @raw[:action] || @raw['attrs']['action']
    @method = @raw['method'] || @raw[:method] || @raw['attrs']['method']

    @auditable = @raw[:inputs] || @raw['inputs'] || simple['auditable'] || {}
    @orig      = @auditable.deep_clone
    @orig.freeze
end

Instance Method Details

#http_request(url, opts) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/arachni/parser/elements.rb', line 174

def http_request( url, opts )
    params   = opts[:params]
    altered  = opts[:altered]

    curr_opts = opts.dup
    if( altered == FORM_VALUES_ORIGINAL )
        orig_id = audit_id( FORM_VALUES_ORIGINAL )

        return if !opts[:redundant] && audited?( orig_id )
        audited( orig_id )

        print_debug( 'Submitting form with original values;' +
            ' overriding trainer option.' )
        opts[:train] = true
        print_debug_trainer( opts )
    end

    if( altered == FORM_VALUES_SAMPLE )
        sample_id = audit_id( FORM_VALUES_SAMPLE )

        return if !opts[:redundant] && audited?( sample_id )
        audited( sample_id )

        print_debug( 'Submitting form with sample values;' +
            ' overriding trainer option.' )
        opts[:train] = true
        print_debug_trainer( opts )
    end


    if( @method.downcase != 'get' )
        return @auditor.http.post( url, opts )
    else
        return @auditor.http.get( url, opts )
    end
end

#idObject



211
212
213
214
215
216
217
218
219
220
221
# File 'lib/arachni/parser/elements.rb', line 211

def id
    id = simple['attrs'].to_s

    auditable.map {
        |name, value|
        next if name.substring?( seed )
        id +=  name
    }

    return id
end

#simpleObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/arachni/parser/elements.rb', line 223

def simple
    form = {}

    return form if !@raw || !@raw['auditable'] || @raw['auditable'].empty?

    form['attrs'] = @raw['attrs']
    form['auditable'] = {}
    @raw['auditable'].each {
        |item|
        if( !item['name'] ) then next end
        form['auditable'][item['name']] = item['value']
    }

    return form.dup
end

#typeObject



239
240
241
# File 'lib/arachni/parser/elements.rb', line 239

def type
    Arachni::Module::Auditor::Element::FORM
end