2008-09-22 22:32:20 +00:00
|
|
|
##
|
2008-10-23 02:43:21 +00:00
|
|
|
# $Id$
|
2008-09-22 22:32:20 +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'
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2008-09-22 22:32:20 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Auxiliary::WMAPScanDir
|
|
|
|
include Msf::Auxiliary::Scanner
|
2008-09-22 22:32:20 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'HTTP Directory Brute Force Scanner',
|
|
|
|
'Description' => %q{
|
|
|
|
This module identifies the existence of interesting directories by brute forcing the name
|
|
|
|
in a given directory path.
|
|
|
|
|
|
|
|
},
|
|
|
|
'Author' => [ 'et [at] cyberspace.org' ],
|
|
|
|
'License' => BSD_LICENSE,
|
2008-10-23 02:43:21 +00:00
|
|
|
'Version' => '$Revision$'))
|
2008-09-22 22:32:20 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('PATH', [ true, "The path to identify directories", '/']),
|
2008-11-24 18:42:59 +00:00
|
|
|
OptInt.new('ERROR_CODE', [ true, "The expected http code for non existant directories", 404]),
|
2008-09-22 22:32:20 +00:00
|
|
|
OptString.new('FORMAT', [ true, "The expected directory format (a alpha, d digit, A upperalpha, N, n)", 'Aaa'])
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-11-10 04:38:05 +00:00
|
|
|
def wmap_enabled
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2008-09-22 22:32:20 +00:00
|
|
|
def run_host(ip)
|
|
|
|
|
|
|
|
numb = []
|
|
|
|
datastore['FORMAT'].scan(/./) { |c|
|
|
|
|
case c
|
|
|
|
when 'a'
|
|
|
|
numb << ('a'..'z')
|
|
|
|
when 'd'
|
|
|
|
numb << ('0'..'9')
|
|
|
|
when 'A'
|
|
|
|
numb << ('A'..'Z')
|
|
|
|
when 'N'
|
|
|
|
numb << ('A'..'Z')+('0'..'9')
|
|
|
|
when 'n'
|
|
|
|
numb << ('a'..'z')+('0'..'9')
|
|
|
|
else
|
|
|
|
print_status("Format string error")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
tpath = datastore['PATH']
|
|
|
|
if tpath[-1,1] != '/'
|
|
|
|
tpath += '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Running..")
|
|
|
|
|
|
|
|
Enumerable.cart(*numb).each {|testd|
|
|
|
|
begin
|
|
|
|
teststr = tpath+testd.to_s + '/'
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => teststr,
|
|
|
|
'method' => 'GET',
|
|
|
|
'ctype' => 'text/plain'
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
if res
|
|
|
|
if res.code.to_i != datastore['ERROR_CODE'].to_i
|
|
|
|
print_status("Found http://#{target_host}:#{target_port}#{teststr} #{res.code.to_i}")
|
2008-10-27 02:22:30 +00:00
|
|
|
|
|
|
|
rep_id = wmap_base_report_id(
|
2008-11-10 04:38:05 +00:00
|
|
|
wmap_target_host,
|
|
|
|
wmap_target_port,
|
|
|
|
wmap_target_ssl
|
2008-10-27 02:22:30 +00:00
|
|
|
)
|
|
|
|
wmap_report(rep_id,'DIRECTORY','NAME',"#{teststr}","Directory #{teststr} found.")
|
|
|
|
|
2008-09-22 22:32:20 +00:00
|
|
|
else
|
|
|
|
print_status("NOT Found http://#{target_host}:#{target_port}#{teststr} #{res.code.to_i}")
|
|
|
|
#blah
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
|
|
|
rescue ::Timeout::Error, ::Errno::EPIPE
|
|
|
|
end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-10-02 05:23:59 +00:00
|
|
|
|
|
|
|
|
2008-09-22 22:32:20 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Used module to do the basic brute forcing.
|
|
|
|
# This Module was developed by Thomas Hafner.
|
|
|
|
# No other references about the author.
|
|
|
|
#
|
|
|
|
|
|
|
|
# TITLE:
|
|
|
|
#
|
|
|
|
# Cartesian
|
|
|
|
#
|
|
|
|
# SUMMARY:
|
|
|
|
#
|
|
|
|
# Cartesian product and similar methods.
|
|
|
|
#
|
|
|
|
# AUTHORS:
|
|
|
|
#
|
|
|
|
# - Thomas Hafner
|
|
|
|
|
|
|
|
#
|
|
|
|
module Enumerable
|
|
|
|
|
|
|
|
class << self
|
|
|
|
# Provides the cross-product of two or more Enumerables.
|
|
|
|
# This is the class-level method. The instance method
|
|
|
|
# calls on this.
|
|
|
|
#
|
|
|
|
# Enumerable.cart([1,2], [4], ["apple", "banana"])
|
|
|
|
# #=> [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
|
|
|
|
#
|
|
|
|
# Enumerable.cart([1,2], [3,4])
|
|
|
|
# #=> [[1, 3], [1, 4], [2, 3], [2, 4]]
|
|
|
|
|
|
|
|
def cartesian_product(*enums, &block)
|
|
|
|
result = [[]]
|
|
|
|
while [] != enums
|
|
|
|
t, result = result, []
|
|
|
|
b, *enums = enums
|
|
|
|
t.each do |a|
|
|
|
|
b.each do |n|
|
|
|
|
result << a + [n]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if block_given?
|
|
|
|
result.each{ |e| block.call(e) }
|
|
|
|
else
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :cart, :cartesian_product
|
|
|
|
end
|
|
|
|
|
|
|
|
# The instance level version of <tt>Enumerable::cartesian_product</tt>.
|
|
|
|
#
|
|
|
|
# a = []
|
|
|
|
# [1,2].cart([4,5]){|elem| a << elem }
|
|
|
|
# a #=> [[1, 4],[1, 5],[2, 4],[2, 5]]
|
|
|
|
|
|
|
|
def cartesian_product(*enums, &block)
|
|
|
|
Enumerable.cartesian_product(self, *enums, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias :cart :cartesian_product
|
|
|
|
|
|
|
|
# Operator alias for cross-product.
|
|
|
|
#
|
|
|
|
# a = [1,2] ** [4,5]
|
|
|
|
# a #=> [[1, 4],[1, 5],[2, 4],[2, 5]]
|
|
|
|
#
|
|
|
|
def **(enum)
|
|
|
|
Enumerable.cartesian_product(self, enum)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Expected to be an enumeration of arrays. This method
|
|
|
|
# iterates through combinations of each in position.
|
|
|
|
#
|
|
|
|
# a = [ [0,1], [2,3] ]
|
|
|
|
# a.each_combo { |c| p c }
|
|
|
|
#
|
|
|
|
# produces
|
|
|
|
#
|
|
|
|
# [0, 2]
|
|
|
|
# [0, 3]
|
|
|
|
# [1, 2]
|
|
|
|
# [1, 3]
|
|
|
|
#
|
|
|
|
def each_combo
|
|
|
|
a = collect{ |x|
|
|
|
|
x.respond_to?(:to_a) ? x.to_a : 0..x
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.size == 1
|
|
|
|
r = a.shift
|
|
|
|
r.each{ |n|
|
|
|
|
yield n
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = a.shift
|
|
|
|
r.each{ |n|
|
|
|
|
a.each_combo{ |s|
|
|
|
|
yield [n, *s]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# As with each_combo but returns combos collected in an array.
|
|
|
|
#
|
|
|
|
def combos
|
|
|
|
a = []
|
|
|
|
each_combo{ |c| a << c }
|
|
|
|
a
|
|
|
|
end
|
|
|
|
|
2008-11-10 04:38:05 +00:00
|
|
|
end
|