@@ -80,6 +80,18 @@ def initialize(info = {})
80
80
deregister_options ( 'RHOST' )
81
81
end
82
82
83
+
84
+ # Avoids writing to datastore['METHOD'] directly
85
+ def method
86
+ @method || datastore [ 'METHOD' ]
87
+ end
88
+
89
+ # Avoids writing to datastore['DATA'] directly
90
+ def data
91
+ @data || datastore [ 'DATA' ]
92
+ end
93
+
94
+
83
95
#
84
96
# The fuzz() function serves as the engine for the module. It can intelligently mutate
85
97
# a trigger, and find potential bugs with it.
@@ -101,7 +113,7 @@ def fuzz
101
113
102
114
# Each possible trigger, we try to traverse multiple levels down depending
103
115
# on datastore['DEPATH']
104
- depth = datastore [ 'DEPTH' ]
116
+ depth = datastore [ 'DEPTH' ]
105
117
triggers . each do |base |
106
118
1 . upto ( depth ) do |d |
107
119
file_to_read . each do |f |
@@ -124,19 +136,15 @@ def fuzz
124
136
def ini_request ( uri )
125
137
req = { }
126
138
127
- # If the user is using some rare-to-use method, we probably have not fully tested,
128
- # so we will not support it for now.
129
- method = datastore [ 'METHOD' ]
130
- data = datastore [ 'DATA' ]
131
139
case method
132
140
when 'GET'
133
141
# Example: Say we have the following datastore['PATH']
134
142
# '/test.php?page=1&id=3¬e=whatever'
135
143
# We expect it to regex the GET parameters:
136
144
# 'page=1&id=3¬e=whatever'
137
145
# And then let queryparse() to handle the rest
138
- data = uri . match ( /\? (\w +=.+&*)$/ )
139
- req [ 'vars_get' ] = queryparse ( data [ 1 ] ) if not data . nil?
146
+ query_params = uri . match ( /\? (\w +=.+&*)$/ )
147
+ req [ 'vars_get' ] = queryparse ( query_params [ 1 ] ) if query_params
140
148
when 'POST'
141
149
req [ 'vars_post' ] = queryparse ( data ) if not data . empty?
142
150
when 'PUT'
@@ -154,10 +162,10 @@ def ini_request(uri)
154
162
this_path = uri
155
163
end
156
164
157
- req [ 'method' ] = datastore [ 'METHOD' ]
165
+ req [ 'method' ] = method
158
166
req [ 'uri' ] = this_path
159
167
req [ 'headers' ] = { 'Cookie' => datastore [ 'COOKIE' ] } if not datastore [ 'COOKIE' ] . empty?
160
- req [ 'data' ] = datastore [ 'DATA' ] if not datastore [ 'DATA' ] . empty?
168
+ req [ 'data' ] = data if not data . empty?
161
169
req [ 'authorization' ] = basic_auth ( datastore [ 'USERNAME' ] , datastore [ 'PASSWORD' ] )
162
170
163
171
return req
@@ -217,7 +225,7 @@ def check(trigger)
217
225
:proof => trigger ,
218
226
:name => self . fullname ,
219
227
:category => "web" ,
220
- :method => datastore [ 'METHOD' ]
228
+ :method => method
221
229
} )
222
230
223
231
else
@@ -281,15 +289,15 @@ def php_download(files)
281
289
#
282
290
def is_writable ( trigger )
283
291
# Modify some registered options for the PUT method
284
- tmp_method = datastore [ 'METHOD' ]
285
- tmp_data = datastore [ 'DATA' ]
286
- datastore [ 'METHOD' ] = 'PUT'
292
+ tmp_method = method
293
+ tmp_data = data
294
+ @method = 'PUT'
287
295
288
- if datastore [ 'DATA' ] . empty?
296
+ if data . empty?
289
297
unique_str = Rex ::Text . rand_text_alpha ( 4 ) * 4
290
- datastore [ 'DATA' ] = unique_str
298
+ @data = unique_str
291
299
else
292
- unique_str = datastore [ 'DATA' ]
300
+ unique_str = data
293
301
end
294
302
295
303
# Form the PUT request
@@ -302,8 +310,8 @@ def is_writable(trigger)
302
310
send_request_cgi ( req , 25 )
303
311
304
312
# Prepare request to read our file
305
- datastore [ 'METHOD' ] = 'GET'
306
- datastore [ 'DATA' ] = tmp_data
313
+ @method = 'GET'
314
+ @data = tmp_data
307
315
req = ini_request ( uri )
308
316
vprint_status ( "Verifying upload..." )
309
317
res = send_request_cgi ( req , 25 )
@@ -316,24 +324,21 @@ def is_writable(trigger)
316
324
end
317
325
318
326
# Ah, don't forget to restore our method
319
- datastore [ 'METHOD' ] = tmp_method
327
+ @method = tmp_method
320
328
end
321
329
322
330
#
323
331
# Load the whole file list
324
332
# This is used in the lfi_download() function
325
333
#
326
334
def load_filelist
327
- f = File . open ( datastore [ 'FILELIST' ] , 'rb' )
328
- buf = f . read
329
- f . close
330
- return buf
335
+ File . open ( datastore [ 'FILELIST' ] , 'rb' ) { |f | f . read }
331
336
end
332
337
333
338
def run_host ( ip )
334
339
# Warn if it's not a well-formed UPPERCASE method
335
- if datastore [ 'METHOD' ] !~ /^[A-Z]+$/
336
- print_warning ( "HTTP method #{ datastore [ 'METHOD' ] } is not Apache-compliant. Try only UPPERCASE letters." )
340
+ if method !~ /^[A-Z]+$/
341
+ print_warning ( "HTTP method #{ method } is not Apache-compliant. Try only UPPERCASE letters." )
337
342
end
338
343
print_status ( "Running action: #{ action . name } ..." )
339
344
0 commit comments