Class: Arachni::Plugins::VectorFeed

Inherits:
Arachni::Plugin::Base show all
Defined in:
components/plugins/vector_feed.rb

Overview

Vector feed plug-in.

Can be used to perform extremely specialized/narrow audits on a per vector/element basis.

Useful for unit-testing or a gazillion other things. :)

Author:

Constant Summary

Constants included from Arachni

BANNER, Cookie, Form, Header, JSON, Link, LinkTemplate, NestedCookie, Severity, UIForm, UIInput, VERSION, WEBSITE, WIKI, XML

Instance Attribute Summary

Attributes inherited from Arachni::Plugin::Base

#framework, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Arachni::Plugin::Base

#browser_cluster, #clean_up, distributable, distributable?, #framework_abort, #framework_pause, #framework_resume, gems, #http, #info, #initialize, is_distributable, merge, #register_results, #restore, #run, #session, #suspend, #wait_while_framework_running, #with_browser

Methods inherited from Component::Base

author, description, fullname, #shortname, shortname, shortname=, version

Methods included from Component::Output

#depersonalize_output, #depersonalize_output?, #intercept_print_message

Methods included from UI::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

Methods included from Component::Utilities

#read_file

Methods included from 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 Arachni

URI, collect_young_objects, #get_long_win32_filename, jruby?, null_device, profile?, windows?

Constructor Details

This class inherits a constructor from Arachni::Plugin::Base

Class Method Details

.infoObject



168
169
170
171
172
173
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'components/plugins/vector_feed.rb', line 168

def self.info
    {
        name:        'Vector feed',
        description: %q{
Reads in vector data from which it creates elements to be audited.
Can be used to perform extremely specialized/narrow audits on a per vector/element basis.

**Notes**:

* To only audit the vectors in the feed you must set the scope page-limit to `0` to prevent crawling.
* Can handle multiple YAML documents.

Example YAML file:

-
  # you can pass pages to be audited by grep checks (and JS in the future)
  type: page
  url: http://localhost/
  # response code
  code: 200
  # response headers
  headers:
    Content-Type: "text/html; charset=utf-8"
  body: "HTML code goes here"

-
  # default type is link which has method get
  #type: link
  action: http://localhost/link
  inputs:
    my_param: "my val"

-
  # if a method is post it'll default to a form type
  type: form
  method: post
  action: http://localhost/form
  inputs:
    post_this: "HUA!"
    csrf: "my_csrf_token"
  # do not fuzz/mutate/audit the following inputs (by name obviously)
  skip:
    - csrf

# GET only
-
  type: cookie
  action: http://localhost/cookie
  inputs:
    session_id: "43434234343sddsdsds"

# GET only
-
  type: header
  action: http://localhost/header
  # only 1 input allowed, each header field=>value must be defined separately
  inputs:
    User-Agent: "Blah/2"

},
        author:      'Tasos "Zapotek" Laskos <[email protected]>',
        version:     '0.2.1',
        options:     [
            Options::Object.new( :vectors,
                description: ' Vector array (for configuration over RPC).'
            ),
            Options::String.new( :yaml_string,
                description: 'A string of YAML serialized vectors (for configuration over RPC).'
            ),
            Options::Path.new( :yaml_file,
                description: 'A file containing the YAML serialized vectors.'
            )
        ]
    }
end

Instance Method Details

#hash_to_element(vector) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'components/plugins/vector_feed.rb', line 102

def hash_to_element( vector )
    owner  = framework.options.url.to_s
    action = vector[:action]
    inputs = vector[:inputs]
    source = vector[:source].to_s
    method = vector[:method] || 'get'
    type   = (vector[:type]  || 'link').to_s

    return if (!inputs || inputs.empty?) &&
        (!(type == 'xml' || type == 'json') && !source.empty?)

    e = case type
        when Element::Link.type.to_s
            Element::Link.new(
                url:    owner,
                action: action,
                inputs: inputs,
                source: source
            )

        when Element::Form.type.to_s
            Element::Form.new(
                url:    owner,
                method: method,
                action: action,
                inputs: inputs,
                source: source
            )

        when Element::Cookie.type.to_s
            Element::Cookie.new(
                url:    action,
                inputs: inputs,
                source: source
            )

        when Element::Header.type.to_s
            Header.new( url: action, inputs: inputs )

        when Element::JSON.type.to_s
            Element::JSON.new(
                url:    action,
                inputs: inputs,
                source: source
            )

        when Element::XML.type.to_s
            Element::XML.new(
                url:    action,
                inputs: inputs,
                source: source
            )

        else
            Element::Link.new(
                url:    owner,
                action: action,
                inputs: inputs
            )
        end

    (vector[:skip] || []).each { |i| e.immutables << i }

    e
end

#page?(vector) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'components/plugins/vector_feed.rb', line 87

def page?( vector )
    vector[:type] == 'page'
end

#page_from_vector(vector) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'components/plugins/vector_feed.rb', line 91

def page_from_vector( vector )
    Page.from_data(
        url:      vector[:url] || framework.options.url.to_s,
        response: {
            code:    Integer( vector[:code] || 200 ),
            body:    vector[:body]     || '',
            headers: vector[:headers]  || {}
        }
    )
end

#prepareObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'components/plugins/vector_feed.rb', line 19

def prepare
    # if the 'vectors' option is an array at this point then someone fed
    # them to us programmatically
    if !options[:vectors].is_a? Array
        feed = if options[:yaml_file]
            IO.read( options[:yaml_file] )
        elsif options[:yaml_string]
            options[:yaml_string]
        else
            ''
        end

        if !feed || feed.empty?
            print_bad 'The feed is empty, bailing out.'
            return
        end

        feed = YAML.load_stream( StringIO.new( feed ) ).flatten

        yaml_err = 'Invalid YAML syntax, bailing out..'
        begin
            if !feed.is_a? Array
                print_bad yaml_err
                return
            end
        rescue
            print_bad yaml_err
            return
        end
    else
        feed = options[:vectors]
    end

    pages = {}
    page_buffer = []
    print_status "Imported #{feed.size} vectors."
    feed.each do |obj|
        vector = (obj.respond_to?( :value ) ? obj.value : obj).my_symbolize_keys( false )

        exception_jail false do
            if page?( vector )
                page_buffer << page_from_vector( vector )
                next
            end

            next if !(element = hash_to_element( vector ))

            pages[element.url] ||= Page.from_data( url: element.url )
            pages[element.url].send(
                "#{element.type}s=",
                pages[element.url].send( "#{element.type}s" ) | [element]
            )
        end
    end

    pages  = pages.values
    pages << page_buffer
    pages.flatten!

    if !pages.empty?
        print_status 'Pushing the vectors to the audit queue...'
        pages.each { |page| framework.push_to_page_queue( page, true ) }
        print_status 'Done!'
    else
        print_bad 'Could not find any usable vectors.'
    end
end