Skip to content

Commit 07238ef

Browse files
committed
Redo try_glassfish_2 specs
1 parent 9a42e76 commit 07238ef

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

lib/metasploit/framework/login_scanner/glassfish.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def try_login(credential)
8686
# * :proof [String] the HTTP response body
8787
def try_glassfish_2(credential)
8888
res = try_login(credential)
89-
if res and res.code == 302
89+
if res && res.code == 302
9090
opts = {
9191
'uri' => '/applications/upload.jsf',
9292
'method' => 'GET',

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
)
3535
end
3636

37+
let(:bad_cred) do
38+
Metasploit::Framework::Credential.new(
39+
paired: true,
40+
public: 'bad',
41+
private: 'bad'
42+
)
43+
end
44+
3745
let(:res_code) do
3846
200
3947
end
@@ -87,19 +95,43 @@
8795
end
8896

8997
context '#try_glassfish_2' do
98+
99+
let(:login_ok_message) do
100+
'<title>Deploy Enterprise Applications/Modules</title>'
101+
end
102+
103+
before :each do
104+
allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv) do |req|
105+
p "#{req.opts['uri']}"
106+
if req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
107+
req.opts['data'] &&
108+
req.opts['data'].include?("j_username=#{username}") &&
109+
req. opts['data'].include?("j_password=#{password}")
110+
res = Rex::Proto::Http::Response.new(302)
111+
res.headers['Location'] = '/applications/upload.jsf'
112+
res.headers['Set-Cookie'] = 'JSESSIONID=GOODSESSIONID'
113+
res
114+
elsif req.opts['uri'] && req.opts['uri'].include?('j_security_check')
115+
res = Rex::Proto::Http::Response.new(200)
116+
res.body = 'bad login'
117+
elsif req.opts['uri'] &&
118+
req.opts['uri'].include?('/applications/upload.jsf')
119+
res = Rex::Proto::Http::Response.new(200)
120+
res.body = '<title>Deploy Enterprise Applications/Modules</title>'
121+
else
122+
res = Rex::Proto::Http::Response.new(404)
123+
end
124+
125+
res
126+
end
127+
end
128+
90129
it 'returns status Metasploit::Model::Login::Status::SUCCESSFUL for a valid credential' do
91-
good_auth_res = Rex::Proto::Http::Response.new(302)
92-
good_res = Rex::Proto::Http::Response.new(200)
93-
good_res.stub(:body).and_return('<title>Deploy Enterprise Applications/Modules</title>')
94-
http_scanner.should_receive(:try_login).with(cred).and_return(good_auth_res)
95-
http_scanner.should_receive(:send_request).with(kind_of(Hash)).and_return(good_res)
96130
http_scanner.try_glassfish_2(cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
97131
end
98132

99133
it 'returns Metasploit::Model::Login::Status::INCORRECT for an invalid credential' do
100-
bad_auth_res = Rex::Proto::Http::Response.new(200)
101-
http_scanner.should_receive(:try_login).with(cred).and_return(bad_auth_res)
102-
http_scanner.try_glassfish_2(cred)[:status].should eq(Metasploit::Model::Login::Status::INCORRECT)
134+
http_scanner.try_glassfish_2(bad_cred)[:status].should eq(Metasploit::Model::Login::Status::INCORRECT)
103135
end
104136
end
105137

0 commit comments

Comments
 (0)