Files
metasploit-gs/modules/auxiliary/scanner/http/replace_ext.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

179 lines
4.6 KiB
Ruby
Raw Normal View History

2009-12-30 22:24:22 +00:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2009-12-30 22:24:22 +00:00
##
2021-01-28 10:35:25 +00:00
2009-12-30 22:24:22 +00:00
require 'pathname'
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
2009-12-30 22:24:22 +00:00
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::WmapScanFile
2009-12-30 22:24:22 +00:00
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
def initialize(info = {})
super(update_info(info,
2009-12-30 22:24:22 +00:00
'Name' => 'HTTP File Extension Scanner',
'Description' => %q{
This module identifies the existence of additional files
2009-12-30 22:24:22 +00:00
by modifying the extension of an existing file.
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
},
'Author' => [ 'et [at] cyberspace.org' ],
2013-01-03 01:05:45 +01:00
'License' => BSD_LICENSE))
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
register_options(
[
OptString.new('PATH', [ true, "The path/file to identify additional files", '/default.asp']),
])
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
register_advanced_options(
[
2024-01-07 15:02:53 -05:00
OptInt.new('ErrorCode', [ true, "The expected http code for non existent files", 404]),
OptPath.new('HTTP404Sigs', [ false, "Path of 404 signatures to use",
2013-09-26 20:34:48 +01: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 ])
])
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
end
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
def run_host(ip)
2013-08-30 16:28:54 -05:00
conn = false
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
dm = datastore['NoDetailMessages']
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
extensions= [
2011-02-04 05:57:26 +00:00
'.bak',
'.txt',
'.tmp',
'.old',
'.htm',
2012-02-20 16:28:19 -06:00
'.ini',
'.cfg',
2011-02-04 05:57:26 +00:00
'.html',
'.php',
'.temp',
'.tmp',
'.java',
'.doc',
2012-02-20 16:28:19 -06:00
'.log',
'.xml'
2009-12-30 22:24:22 +00:00
]
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
tpathfile = Pathname.new(datastore['PATH'])
2011-02-04 05:57:26 +00:00
oldext = tpathfile.extname
tpathnoext = tpathfile.to_s[0..(datastore['PATH'].rindex(oldext)-1)]
2013-08-30 16:28:54 -05:00
2011-02-04 05:57:26 +00:00
#print_status ("Old extension: #{oldext}")
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
extensions.each { |testext|
2013-08-30 16:28:54 -05:00
2011-02-04 05:57:26 +00:00
if oldext == testext
next
end
2013-08-30 16:28:54 -05:00
2011-02-04 05:57:26 +00:00
#print_status ("Test extension: #{testext}")
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
#
# Detect error code. This module is a special case as each extension
2024-01-07 15:02:53 -05:00
# usually is handled differently 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
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
res = send_request_cgi({
'uri' => tpath,
'method' => 'GET',
'ctype' => 'text/html'
}, 20)
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
return if not res
2013-08-30 16:28:54 -05:00
tcode = res.code.to_i
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
emesg = ""
2013-08-30 16:28:54 -05: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)
2013-08-30 16:28:54 -05: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
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
if(not emesg)
2011-02-04 05:57:26 +00:00
print_status("Using first 256 bytes of the response as 404 string for #{testext} files.")
2009-12-30 22:24:22 +00:00
emesg = res.body[0,256]
else
2011-02-04 05:57:26 +00:00
print_status("Using custom 404 string of '#{emesg}' for #{testext} files.")
2009-12-30 22:24:22 +00:00
end
else
ecode = tcode
2011-02-04 05:57:26 +00:00
print_status("Using code '#{ecode}' as not found for #{testext} files.")
2009-12-30 22:24:22 +00:00
end
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +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
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
#if not conn return
2013-08-30 16:28:54 -05: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)
2013-08-30 16:28:54 -05: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
print_status("NOT Found #{wmap_base_url}#{tpath} #{res.code.to_i}")
2009-12-30 22:24:22 +00:00
end
else
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_good("Found #{wmap_base_url}#{tpath}")
2013-08-30 16:28:54 -05:00
report_web_vuln(
2009-12-30 22:24:22 +00:00
:host => ip,
:port => rport,
:vhost => vhost,
:ssl => ssl,
:path => tpath,
:method => 'GET',
:pname => "",
:proof => "Res code: #{res.code.to_s}",
:risk => 0,
:confidence => 100,
:category => 'file',
:description => 'File found.',
:name => 'file'
2009-12-30 22:24:22 +00:00
)
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
end
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
rescue ::Timeout::Error, ::Errno::EPIPE
end
2009-12-30 22:24:22 +00:00
}
2013-08-30 16:28:54 -05:00
2009-12-30 22:24:22 +00:00
end
end