2009-12-30 22:24:22 +00:00
|
|
|
##
|
2012-03-01 22:54:04 +00:00
|
|
|
# $Id$
|
2009-12-30 22:24:22 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2009-12-30 22:24:22 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'rex/proto/http'
|
|
|
|
require 'msf/core'
|
|
|
|
require 'thread'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2012-02-03 21:43:21 +00:00
|
|
|
include Msf::Auxiliary::WmapScanDir
|
2009-12-30 22:24:22 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
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,
|
2012-03-01 22:59:54 +00:00
|
|
|
'Version' => '$Revision$'))
|
2009-12-30 22:24:22 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('PATH', [ true, "The path to identify files", '/']),
|
|
|
|
OptPath.new('DICTIONARY', [ false, "Path of word dictionary to use",
|
|
|
|
File.join(Msf::Config.install_root, "data", "wmap", "wmap_dirs.txt")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
2010-12-07 00:59:28 +00:00
|
|
|
OptInt.new('ErrorCode', [ false, "Error code for non existent directory" ]),
|
2009-12-30 22:24:22 +00:00
|
|
|
OptPath.new('HTTP404Sigs', [ false, "Path of 404 signatures to use",
|
2010-12-07 00:59:28 +00:00
|
|
|
File.join(Msf::Config.data_directory, "wmap", "wmap_404s.txt")
|
2009-12-30 22:24:22 +00:00
|
|
|
]
|
|
|
|
),
|
|
|
|
OptBool.new('NoDetailMessages', [ false, "Do not display detailed test messages", true ]),
|
|
|
|
OptInt.new('TestThreads', [ true, "Number of test threads", 25])
|
|
|
|
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
conn = true
|
|
|
|
ecode = nil
|
|
|
|
emesg = nil
|
|
|
|
|
|
|
|
tpath = datastore['PATH']
|
|
|
|
if tpath[-1,1] != '/'
|
|
|
|
tpath += '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
ecode = datastore['ErrorCode'].to_i
|
|
|
|
vhost = datastore['VHOST'] || wmap_target_host
|
|
|
|
prot = datastore['SSL'] ? 'https' : 'http'
|
|
|
|
|
|
|
|
|
2010-12-07 00:59:28 +00:00
|
|
|
if (ecode == 0)
|
|
|
|
# Then the user didn't specify one, go request a (probably)
|
|
|
|
# nonexistent file to detect what to use.
|
|
|
|
begin
|
|
|
|
#
|
|
|
|
# Detect error code
|
|
|
|
#
|
|
|
|
print_status("Detecting error code")
|
|
|
|
randdir = Rex::Text.rand_text_alpha(5).chomp + '/'
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => tpath+randdir,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/html'
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
return if not res
|
|
|
|
|
|
|
|
tcode = res.code.to_i
|
|
|
|
|
|
|
|
# Look for a string we can signature on as well
|
|
|
|
if(tcode >= 200 and tcode <= 299)
|
|
|
|
|
|
|
|
File.open(datastore['HTTP404Sigs'], 'rb').each do |str|
|
|
|
|
if(res.body.index(str))
|
|
|
|
emesg = str
|
|
|
|
break
|
|
|
|
end
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
|
|
|
|
2010-12-07 00:59:28 +00:00
|
|
|
if(not emesg)
|
|
|
|
print_status("Using first 256 bytes of the response as 404 string for #{wmap_target_host}")
|
|
|
|
emesg = res.body[0,256]
|
|
|
|
else
|
|
|
|
print_status("Using custom 404 string of '#{emesg}' for #{wmap_target_host}")
|
|
|
|
end
|
2009-12-30 22:24:22 +00:00
|
|
|
else
|
2010-12-07 00:59:28 +00:00
|
|
|
ecode = tcode
|
|
|
|
print_status("Using code '#{ecode}' as not found for #{wmap_target_host}")
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
2010-12-07 00:59:28 +00:00
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
|
|
|
conn = false
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return if not conn
|
|
|
|
|
|
|
|
nt = datastore['TestThreads'].to_i
|
|
|
|
nt = 1 if nt == 0
|
|
|
|
|
|
|
|
dm = datastore['NoDetailMessages']
|
|
|
|
|
|
|
|
queue = []
|
2010-07-01 23:33:07 +00:00
|
|
|
File.open(datastore['DICTIONARY'], 'rb').each_line do |testd|
|
2009-12-30 22:24:22 +00:00
|
|
|
queue << testd.strip + '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
while(not queue.empty?)
|
|
|
|
t = []
|
|
|
|
1.upto(nt) do
|
2010-11-12 06:19:49 +00:00
|
|
|
t << framework.threads.spawn("Module(#{self.refname})-#{rhost}", false, queue.shift) do |testf|
|
2009-12-30 22:24:22 +00:00
|
|
|
Thread.current.kill if not testf
|
|
|
|
|
|
|
|
testfdir = testf
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => tpath+testfdir,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/html'
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
|
|
|
|
if(not res or ((res.code.to_i == ecode) or (emesg and res.body.index(emesg))))
|
|
|
|
if dm == false
|
|
|
|
print_status("NOT Found #{wmap_base_url}#{tpath}#{testfdir} #{res.code} (#{wmap_target_host})")
|
|
|
|
end
|
|
|
|
else
|
2012-06-06 05:22:36 +00:00
|
|
|
|
2012-02-21 20:13:12 +00:00
|
|
|
report_web_vuln(
|
2009-12-30 22:24:22 +00:00
|
|
|
:host => ip,
|
|
|
|
:port => rport,
|
2012-02-21 20:13:12 +00:00
|
|
|
:vhost => vhost,
|
|
|
|
:ssl => ssl,
|
|
|
|
:path => "#{tpath}#{testfdir}",
|
|
|
|
:method => 'GET',
|
|
|
|
:pname => "",
|
|
|
|
:proof => "Res code: #{res.code.to_s}",
|
|
|
|
:risk => 0,
|
|
|
|
:confidence => 100,
|
|
|
|
:category => 'directory',
|
|
|
|
:description => 'Directoy found.',
|
|
|
|
:name => 'directory'
|
2009-12-30 22:24:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
print_status("Found #{wmap_base_url}#{tpath}#{testfdir} #{res.code} (#{wmap_target_host})")
|
|
|
|
|
|
|
|
if res.code.to_i == 401
|
|
|
|
print_status("#{wmap_base_url}#{tpath}#{testfdir} requires authentication: #{res.headers['WWW-Authenticate']}")
|
|
|
|
|
|
|
|
report_note(
|
|
|
|
:host => ip,
|
|
|
|
:port => rport,
|
2011-02-04 01:54:32 +00:00
|
|
|
:proto => 'tcp',
|
2011-02-22 20:49:44 +00:00
|
|
|
:sname => (ssl ? 'https' : 'http'),
|
2009-12-30 22:24:22 +00:00
|
|
|
:type => 'WWW_AUTHENTICATE',
|
2010-09-19 22:25:56 +00:00
|
|
|
:data => "#{tpath}#{testfdir} Auth: #{res.headers['WWW-Authenticate']}",
|
|
|
|
:update => :unique_data
|
2009-12-30 22:24:22 +00:00
|
|
|
)
|
2012-03-18 05:07:27 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
t.map{|x| x.join }
|
|
|
|
end
|
|
|
|
end
|
2009-12-26 05:53:29 +00:00
|
|
|
end
|