2008-10-22 02:31:52 +00:00
|
|
|
##
|
2008-10-23 02:43:21 +00:00
|
|
|
# $Id$
|
2008-10-22 02:31:52 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/projects/Framework/
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'rex/proto/http'
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Auxiliary::WMAPScanDir
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'HTTP Directory Scanner',
|
|
|
|
'Description' => %q{
|
|
|
|
This module identifies the existence of interesting directories
|
|
|
|
in a given directory path.
|
|
|
|
},
|
|
|
|
'Author' => [ 'et [at] metasploit.com' ],
|
|
|
|
'License' => BSD_LICENSE,
|
2008-10-23 02:43:21 +00:00
|
|
|
'Version' => '$Revision$'))
|
2008-10-22 02:31:52 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('PATH', [ true, "The path to identify files", '/']),
|
2008-11-24 18:42:59 +00:00
|
|
|
OptInt.new('ERROR_CODE', [ true, "Error code for non existent directory", 404]),
|
2008-10-22 02:31:52 +00:00
|
|
|
OptPath.new('DICTIONARY', [ false, "Path of word dictionary to use",
|
|
|
|
File.join(Msf::Config.install_root, "data", "wmap", "wmap_dirs.txt")
|
|
|
|
]
|
2008-11-13 03:10:03 +00:00
|
|
|
),
|
|
|
|
OptPath.new('HTTP404S', [ false, "Path of 404 signatures to use",
|
|
|
|
File.join(Msf::Config.install_root, "data", "wmap", "wmap_404s.txt")
|
|
|
|
]
|
|
|
|
)
|
2008-10-22 02:31:52 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
conn = true
|
2008-11-13 03:10:03 +00:00
|
|
|
ecode = nil
|
|
|
|
emesg = nil
|
2008-10-22 02:31:52 +00:00
|
|
|
|
|
|
|
tpath = datastore['PATH']
|
|
|
|
if tpath[-1,1] != '/'
|
|
|
|
tpath += '/'
|
|
|
|
end
|
|
|
|
|
2008-11-13 03:51:21 +00:00
|
|
|
ecode = datastore['ERROR_CODE'].to_i
|
2008-11-13 03:10:03 +00:00
|
|
|
vhost = datastore['VHOST'] || target_host
|
|
|
|
prot = datastore['SSL'] ? 'https' : 'http'
|
|
|
|
|
|
|
|
|
2008-10-22 02:31:52 +00:00
|
|
|
#
|
|
|
|
# Detect error code
|
|
|
|
#
|
|
|
|
begin
|
|
|
|
randdir = Rex::Text.rand_text_alpha(5).chomp + '/'
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => tpath+randdir,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/html'
|
|
|
|
}, 20)
|
|
|
|
|
2008-11-13 03:10:03 +00:00
|
|
|
return if not res
|
|
|
|
|
|
|
|
tcode = res.code.to_i
|
|
|
|
|
2008-11-13 03:59:52 +00:00
|
|
|
|
2008-11-13 03:10:03 +00:00
|
|
|
# Look for a string we can signature on as well
|
|
|
|
if(tcode >= 200 and tcode <= 299)
|
2008-11-13 03:51:21 +00:00
|
|
|
|
2008-11-13 03:10:03 +00:00
|
|
|
File.open(datastore['HTTP404S']).each do |str|
|
|
|
|
if(res.body.index(str))
|
|
|
|
emesg = str
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if(not emesg)
|
|
|
|
print_status("Using first 256 bytes of the response as 404 string")
|
|
|
|
emesg = res.body[0,256]
|
|
|
|
else
|
|
|
|
print_status("Using custom 404 string of '#{emesg}'")
|
|
|
|
end
|
2008-11-13 03:59:52 +00:00
|
|
|
else
|
|
|
|
ecode = tcode
|
|
|
|
print_status("Using code '#{ecode}' as not found.")
|
2008-10-22 02:31:52 +00:00
|
|
|
end
|
2008-11-13 03:10:03 +00:00
|
|
|
|
|
|
|
|
2008-10-22 02:31:52 +00:00
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
|
|
|
conn = false
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
|
|
|
end
|
2008-11-13 03:10:03 +00:00
|
|
|
|
|
|
|
return if not conn
|
2008-10-22 02:31:52 +00:00
|
|
|
|
2008-11-13 03:10:03 +00:00
|
|
|
|
|
|
|
File.open(datastore['DICTIONARY']).each do |testf|
|
|
|
|
begin
|
|
|
|
testfdir = testf.chomp + '/'
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => tpath+testfdir,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/html'
|
|
|
|
}, 20)
|
2008-10-22 02:31:52 +00:00
|
|
|
|
2008-11-13 03:51:21 +00:00
|
|
|
|
2008-11-22 04:34:00 +00:00
|
|
|
if(not res or ((res.code.to_i == ecode) or (emesg and res.body.index(emesg))))
|
2008-11-13 03:10:03 +00:00
|
|
|
print_status("NOT Found #{prot}://#{vhost}:#{datastore['RPORT']}#{tpath}#{testfdir} #{res.code} (#{target_host})")
|
|
|
|
else
|
|
|
|
print_status("Found #{prot}://#{vhost}:#{datastore['RPORT']}#{tpath}#{testfdir} #{res.code} (#{target_host})")
|
|
|
|
rep_id = wmap_base_report_id(
|
|
|
|
wmap_target_host,
|
|
|
|
wmap_target_port,
|
|
|
|
wmap_target_ssl
|
|
|
|
)
|
|
|
|
vul_id = wmap_report(rep_id,'DIRECTORY','NAME',"#{tpath}#{testfdir}","Directory #{tpath}#{testfdir} found.")
|
|
|
|
wmap_report(vul_id,'DIRECTORY','RESP_CODE',"#{res.code}",nil)
|
2008-10-22 02:31:52 +00:00
|
|
|
end
|
2008-11-13 03:10:03 +00:00
|
|
|
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
|
|
|
end
|
2008-10-22 02:31:52 +00:00
|
|
|
end
|
2008-11-13 03:10:03 +00:00
|
|
|
|
2008-10-22 02:31:52 +00:00
|
|
|
end
|
|
|
|
end
|