2009-12-30 22:24:22 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-12-30 22:24:22 +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 'rex/proto/http'
|
|
|
|
require 'msf/core'
|
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Auxiliary::WMAPScanFile
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-04-30 08:40:19 +00:00
|
|
|
super(update_info(info,
|
2009-12-30 22:24:22 +00:00
|
|
|
'Name' => 'HTTP File Extension Scanner',
|
|
|
|
'Description' => %q{
|
2010-04-30 08:40:19 +00:00
|
|
|
This module identifies the existence of additional files
|
2009-12-30 22:24:22 +00:00
|
|
|
by modifying the extension of an existing file.
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'et [at] cyberspace.org' ],
|
|
|
|
'License' => BSD_LICENSE,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Version' => '$Revision$'))
|
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('PATH', [ true, "The path/file to identify additional files", '/default.asp']),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptString.new('EXT', [ false, "File extension to replace (blank for automatic replacement of extension)", '']),
|
2009-12-30 22:24:22 +00:00
|
|
|
], self.class)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
OptInt.new('ErrorCode', [ true, "The expected http code for non existant files", 404]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptPath.new('HTTP404Sigs', [ false, "Path of 404 signatures to use",
|
2009-12-30 22:24:22 +00:00
|
|
|
File.join(Msf::Config.install_root, "data", "wmap", "wmap_404s.txt")
|
|
|
|
]
|
|
|
|
),
|
|
|
|
OptBool.new('NoDetailMessages', [ false, "Do not display detailed test messages", true ])
|
2010-04-30 08:40:19 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-09-20 08:06:27 +00:00
|
|
|
conn = false
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
dm = datastore['NoDetailMessages']
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
extensions= [
|
|
|
|
'bak',
|
2010-09-20 08:06:27 +00:00
|
|
|
'txt',
|
|
|
|
'tmp',
|
|
|
|
'old',
|
|
|
|
'temp',
|
|
|
|
'java',
|
|
|
|
'doc',
|
|
|
|
'log'
|
2009-12-30 22:24:22 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
tpathfile = Pathname.new(datastore['PATH'])
|
|
|
|
tpathnoext = tpathfile.to_s[0..datastore['PATH'].rindex(tpathfile.extname)]
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
|
|
|
|
extensions.each { |testext|
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
#
|
|
|
|
# Detect error code. This module is a special case as each extension
|
2010-04-30 08:40:19 +00:00
|
|
|
# usually is handled diferently by the server with different error codes
|
|
|
|
#
|
|
|
|
ecode = datastore['ErrorCode'].to_i
|
2009-12-30 22:24:22 +00:00
|
|
|
begin
|
|
|
|
randchars = Rex::Text.rand_text_alpha(3).chomp
|
|
|
|
tpath = tpathnoext+randchars+testext
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => tpath,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/html'
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
return if not res
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
tcode = res.code.to_i
|
2009-12-30 22:24:22 +00:00
|
|
|
|
|
|
|
emesg = ""
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
# Look for a string we can signature on as well
|
|
|
|
if(tcode >= 200 and tcode <= 299)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-07-01 23:33:07 +00:00
|
|
|
File.open(datastore['HTTP404Sigs'], 'rb').each do |str|
|
2009-12-30 22:24:22 +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.")
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2010-04-30 08:40:19 +00:00
|
|
|
conn = false
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
#if not conn return
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
begin
|
|
|
|
tpath = tpathnoext+testext
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => tpath,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/plain'
|
|
|
|
}, 20)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
if(not res or ((res.code.to_i == ecode) or (emesg and res.body.index(emesg))))
|
|
|
|
if dm == false
|
2010-04-30 08:40:19 +00:00
|
|
|
print_status("NOT Found #{wmap_base_url}#{tpath} #{res.code.to_i}")
|
2009-12-30 22:24:22 +00:00
|
|
|
#blah
|
|
|
|
end
|
|
|
|
else
|
2010-04-30 08:40:19 +00:00
|
|
|
if res.code.to_i == 400 and ecode != 400
|
|
|
|
print_error("Server returned an error code. #{wmap_base_url}#{tpath} #{res.code.to_i}")
|
2009-12-30 22:24:22 +00:00
|
|
|
else
|
|
|
|
print_status("Found #{wmap_base_url}#{tpath}")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
report_note(
|
|
|
|
:host => ip,
|
2011-02-04 01:54:32 +00:00
|
|
|
:proto => 'tcp',
|
|
|
|
:sname => 'HTTP',
|
2009-12-30 22:24:22 +00:00
|
|
|
:port => rport,
|
|
|
|
:type => 'FILE',
|
|
|
|
:data => "#{tpath} Code: #{res.code}"
|
|
|
|
)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2010-04-30 08:40:19 +00:00
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
|
|
|
end
|
2009-12-30 22:24:22 +00:00
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|