Skip to content

Commit 768b509

Browse files
committed
Redo try_glassfish_3 specs
1 parent 07238ef commit 768b509

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

lib/metasploit/framework/login_scanner/glassfish.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def try_glassfish_2(credential)
111111
# @return (see #try_glassfish_2)
112112
def try_glassfish_3(credential)
113113
res = try_login(credential)
114-
if res and res.code == 302
114+
if res && res.code == 302
115115
opts = {
116116
'uri' => '/common/applications/uploadFrame.jsf',
117117
'method' => 'GET',

spec/lib/metasploit/framework/login_scanner/glassfish_spec.rb

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
'admin'
2323
end
2424

25+
let(:username_disabled) do
26+
'admin_disabled'
27+
end
28+
2529
let(:password) do
2630
'password'
2731
end
2832

33+
let(:password_disabled) do
34+
'password_disabled'
35+
end
36+
2937
let(:cred) do
3038
Metasploit::Framework::Credential.new(
3139
paired: true,
@@ -42,6 +50,14 @@
4250
)
4351
end
4452

53+
let(:disabled_cred) do
54+
Metasploit::Framework::Credential.new(
55+
paired: true,
56+
public: username_disabled,
57+
private: password_disabled
58+
)
59+
end
60+
4561
let(:res_code) do
4662
200
4763
end
@@ -102,7 +118,6 @@
102118

103119
before :each do
104120
allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv) do |req|
105-
p "#{req.opts['uri']}"
106121
if req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
107122
req.opts['data'] &&
108123
req.opts['data'].include?("j_username=#{username}") &&
@@ -136,26 +151,52 @@
136151
end
137152

138153
context '#try_glassfish_3' do
154+
155+
let(:login_ok_message) do
156+
'<title>Deploy Enterprise Applications/Modules</title>'
157+
end
158+
159+
before :each do
160+
allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv) do |req|
161+
if req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
162+
req.opts['data'] &&
163+
req.opts['data'].include?("j_username=#{username}") &&
164+
req. opts['data'].include?("j_password=#{password}")
165+
res = Rex::Proto::Http::Response.new(302)
166+
res.headers['Location'] = '/common/applications/uploadFrame.jsf'
167+
res.headers['Set-Cookie'] = 'JSESSIONID=GOODSESSIONID'
168+
res
169+
elsif req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
170+
req.opts['data'] &&
171+
req.opts['data'].include?("j_username=#{username_disabled}") &&
172+
req. opts['data'].include?("j_password=#{password_disabled}")
173+
res = Rex::Proto::Http::Response.new(200)
174+
res.body = 'Secure Admin must be enabled'
175+
elsif req.opts['uri'] && req.opts['uri'].include?('j_security_check')
176+
res = Rex::Proto::Http::Response.new(200)
177+
res.body = 'bad login'
178+
elsif req.opts['uri'] &&
179+
req.opts['uri'].include?('/common/applications/uploadFrame.jsf')
180+
res = Rex::Proto::Http::Response.new(200)
181+
res.body = '<title>Deploy Applications or Modules'
182+
else
183+
res = Rex::Proto::Http::Response.new(404)
184+
end
185+
186+
res
187+
end
188+
end
189+
139190
it 'returns status Metasploit::Model::Login::Status::SUCCESSFUL for a valid credential' do
140-
good_auth_res = Rex::Proto::Http::Response.new(302)
141-
good_res = Rex::Proto::Http::Response.new(200)
142-
good_res.stub(:body).and_return('<title>Deploy Applications or Modules</title>')
143-
http_scanner.should_receive(:try_login).with(cred).and_return(good_auth_res)
144-
http_scanner.should_receive(:send_request).with(kind_of(Hash)).and_return(good_res)
145191
http_scanner.try_glassfish_3(cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
146192
end
147193

148194
it 'returns status Metasploit::Model::Login::Status::SUCCESSFUL based on a disabled remote admin message' do
149-
good_auth_res = Rex::Proto::Http::Response.new(200)
150-
good_auth_res.stub(:body).and_return('Secure Admin must be enabled')
151-
http_scanner.should_receive(:try_login).with(cred).and_return(good_auth_res)
152-
http_scanner.try_glassfish_3(cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
195+
http_scanner.try_glassfish_3(disabled_cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
153196
end
154197

155198
it 'returns status Metasploit::Model::Login::Status::INCORRECT for an invalid credential' do
156-
bad_auth_res = Rex::Proto::Http::Response.new(200)
157-
http_scanner.should_receive(:try_login).with(cred).and_return(bad_auth_res)
158-
http_scanner.try_glassfish_3(cred)[:status].should eq(Metasploit::Model::Login::Status::INCORRECT)
199+
http_scanner.try_glassfish_3(bad_cred)[:status].should eq(Metasploit::Model::Login::Status::INCORRECT)
159200
end
160201
end
161202

0 commit comments

Comments
 (0)