|
34 | 34 | )
|
35 | 35 | end
|
36 | 36 |
|
| 37 | + let(:bad_cred) do |
| 38 | + Metasploit::Framework::Credential.new( |
| 39 | + paired: true, |
| 40 | + public: 'bad', |
| 41 | + private: 'bad' |
| 42 | + ) |
| 43 | + end |
| 44 | + |
37 | 45 | let(:res_code) do
|
38 | 46 | 200
|
39 | 47 | end
|
|
87 | 95 | end
|
88 | 96 |
|
89 | 97 | 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 | + |
90 | 129 | 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) |
96 | 130 | http_scanner.try_glassfish_2(cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
|
97 | 131 | end
|
98 | 132 |
|
99 | 133 | 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) |
103 | 135 | end
|
104 | 136 | end
|
105 | 137 |
|
|
0 commit comments