2010-05-03 17:13:09 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
##
|
2009-12-13 06:56:01 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-10-11 20:49:34 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
# Exploit mixins should be called first
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Auxiliary::WMAPScanServer
|
|
|
|
# Scanner mixin should be near last
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
2009-12-13 06:56:01 +00:00
|
|
|
'Name' => 'HTTP Subversion Scanner',
|
2010-05-03 17:13:09 +00:00
|
|
|
'Version' => '$Revision$',
|
2009-10-11 20:49:34 +00:00
|
|
|
'Description' => 'Detect subversion directories and files and analize its content. Only SVN Version > 7 supported',
|
|
|
|
'Author' => ['et'],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('PATH', [ true, "The test path to .svn directory", '/']),
|
|
|
|
OptBool.new('GET_SOURCE', [ false, "Attempt to obtain file source code", true ]),
|
|
|
|
OptBool.new('SHOW_SOURCE', [ false, "Show source code", true ])
|
2009-12-13 06:56:01 +00:00
|
|
|
|
|
|
|
], self.class)
|
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
OptInt.new('ErrorCode', [ true, "Error code for non existent directory", 404]),
|
2009-12-13 06:56:01 +00:00
|
|
|
OptPath.new('HTTP404Sigs', [ false, "Path of 404 signatures to use",
|
2009-10-18 07:10:32 +00:00
|
|
|
File.join(Msf::Config.install_root, "data", "wmap", "wmap_404s.txt")
|
|
|
|
]
|
|
|
|
),
|
|
|
|
OptBool.new('NoDetailMessages', [ false, "Do not display detailed test messages", true ])
|
2009-12-13 06:56:01 +00:00
|
|
|
|
|
|
|
], self.class)
|
2009-10-11 20:49:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(target_host)
|
2009-10-18 07:10:32 +00:00
|
|
|
conn = true
|
|
|
|
ecode = nil
|
|
|
|
emesg = nil
|
2009-12-13 06:56:01 +00:00
|
|
|
|
|
|
|
tpath = datastore['PATH']
|
2009-10-18 07:10:32 +00:00
|
|
|
if tpath[-1,1] != '/'
|
|
|
|
tpath += '/'
|
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
ecode = datastore['ErrorCode'].to_i
|
|
|
|
vhost = datastore['VHOST'] || wmap_target_host
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
#
|
|
|
|
# Detect error code
|
2009-12-13 06:56:01 +00:00
|
|
|
#
|
2009-10-11 20:49:34 +00:00
|
|
|
begin
|
2009-10-18 07:10:32 +00:00
|
|
|
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
|
|
|
|
|
2009-12-13 06:56:01 +00:00
|
|
|
tcode = res.code.to_i
|
|
|
|
|
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
# Look for a string we can signature on as well
|
|
|
|
if(tcode >= 200 and tcode <= 299)
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2010-07-01 23:33:07 +00:00
|
|
|
File.open(datastore['HTTP404Sigs'], 'rb').each do |str|
|
2009-10-18 07:10:32 +00:00
|
|
|
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
|
|
|
|
else
|
|
|
|
ecode = tcode
|
|
|
|
print_status("Using code '#{ecode}' as not found.")
|
2009-10-11 20:49:34 +00:00
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2009-12-13 06:56:01 +00:00
|
|
|
conn = false
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
2009-10-18 07:10:32 +00:00
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
return if not conn
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
dm = datastore['NoDetailMessages']
|
|
|
|
|
|
|
|
begin
|
2009-10-11 20:49:34 +00:00
|
|
|
turl = tpath+'.svn/entries'
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
res = send_request_cgi({
|
2009-12-13 06:56:01 +00:00
|
|
|
'uri' => turl,
|
2009-10-11 20:49:34 +00:00
|
|
|
'method' => 'GET',
|
|
|
|
'version' => '1.0',
|
|
|
|
}, 10)
|
|
|
|
|
2009-10-18 07:10:32 +00:00
|
|
|
if(not res or ((res.code.to_i == ecode) or (emesg and res.body.index(emesg))))
|
|
|
|
if dm == false
|
|
|
|
print_status("[#{target_host}] NOT Found. #{tpath} #{res.code}")
|
|
|
|
end
|
|
|
|
else
|
2009-10-11 22:40:57 +00:00
|
|
|
print_status("[#{target_host}] SVN Entries file found.")
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-11-25 06:08:28 +00:00
|
|
|
report_note(
|
|
|
|
:host => target_host,
|
|
|
|
:proto => 'HTTP',
|
|
|
|
:port => rport,
|
|
|
|
:type => 'SVN_ENTRIES',
|
|
|
|
:data => "#{turl}"
|
2009-10-11 20:49:34 +00:00
|
|
|
)
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
vers = res.body[0..1].chomp.to_i
|
|
|
|
if vers <= 6
|
2009-10-11 22:40:57 +00:00
|
|
|
print_error("[#{target_host}] Version #{vers} not supported")
|
2009-10-11 20:49:34 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
n = 0
|
|
|
|
res.body.split("\f\n").each do |record|
|
|
|
|
resarr = []
|
|
|
|
resarr = record.to_s.split("\n")
|
|
|
|
|
|
|
|
if n==0
|
|
|
|
#first record
|
|
|
|
version = resarr[0]
|
|
|
|
sname = "CURRENT"
|
|
|
|
skind = resarr[2]
|
|
|
|
srevision = resarr[3]
|
|
|
|
surl = resarr[4]
|
|
|
|
slastauthor = resarr[11]
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
else
|
|
|
|
sname = resarr[0]
|
|
|
|
skind = resarr[1]
|
|
|
|
srevision = resarr[2]
|
|
|
|
surl = resarr[3]
|
|
|
|
slastauthor = resarr[10]
|
2009-12-13 06:56:01 +00:00
|
|
|
end
|
2009-10-11 20:49:34 +00:00
|
|
|
|
2009-10-11 22:40:57 +00:00
|
|
|
print_status("[#{target_host}] #{skind} #{sname} [#{slastauthor}]")
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
if slastauthor and slastauthor.length > 0
|
2009-11-25 06:08:28 +00:00
|
|
|
report_note(
|
|
|
|
:host => target_host,
|
|
|
|
:proto => 'HTTP',
|
|
|
|
:port => rport,
|
|
|
|
:type => 'USERNAME',
|
|
|
|
:data => "#{slastauthor}"
|
|
|
|
)
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
if skind
|
2009-11-25 06:08:28 +00:00
|
|
|
if skind == 'dir'
|
|
|
|
report_note(
|
|
|
|
:host => target_host,
|
|
|
|
:proto => 'HTTP',
|
|
|
|
:port => rport,
|
|
|
|
:type => 'DIRECTORY',
|
|
|
|
:data => "#{sname}"
|
|
|
|
)
|
2009-10-11 20:49:34 +00:00
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
if skind == 'file'
|
2009-11-25 06:08:28 +00:00
|
|
|
report_note(
|
|
|
|
:host => target_host,
|
|
|
|
:proto => 'HTTP',
|
|
|
|
:port => rport,
|
|
|
|
:type => 'FILE',
|
|
|
|
:data => "#{sname}"
|
|
|
|
)
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
if datastore['GET_SOURCE']
|
2009-10-11 22:40:57 +00:00
|
|
|
print_status("- Trying to get file #{sname} source code.")
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
begin
|
|
|
|
turl = tpath+'.svn/text-base/'+sname+'.svn-base'
|
2009-10-11 22:40:57 +00:00
|
|
|
print_status("- Location: #{turl}")
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
srcres = send_request_cgi({
|
2009-12-13 06:56:01 +00:00
|
|
|
'uri' => turl,
|
2009-10-11 20:49:34 +00:00
|
|
|
'method' => 'GET',
|
|
|
|
'version' => '1.0',
|
|
|
|
}, 10)
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
if srcres and srcres.body.length > 0
|
|
|
|
if datastore['SHOW_SOURCE']
|
|
|
|
print_status("#{srcres.body}")
|
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
|
2009-11-25 06:08:28 +00:00
|
|
|
report_note(
|
|
|
|
:host => target_host,
|
|
|
|
:proto => 'HTTP',
|
|
|
|
:port => rport,
|
|
|
|
:type => 'SOURCE_CODE',
|
|
|
|
:data => "#{sname} Code: #{srcres.body}"
|
|
|
|
)
|
2009-10-11 20:49:34 +00:00
|
|
|
end
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
|
|
|
end
|
2009-12-13 06:56:01 +00:00
|
|
|
end
|
2009-10-11 20:49:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
n += 1
|
|
|
|
end
|
|
|
|
print_status("Done. #{n} records.")
|
2009-12-13 06:56:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-11 20:49:34 +00:00
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|