Evil Teacher: Code Injection in Moodle
A teacher could inject malicious code into a math formula used in Moodle's calculated quiz questions, bypassing a security check, to execute arbitrary commands on the server. This allowed remote code execution with teacher privileges.
blog.ripstech.com
Published on blog.ripstech.com
An attacker must be assigned the teacher role in a course of the latest Moodle (earlier than 3.5.0) running with default configurations. Escalating to this role via another vulnerability, such as XSS, would also be possible.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The formula validator failed to properly sanitise nested placeholders, allowing malicious PHP code to reach an eval() call.
What the attacker needed
Teacher role in a course; default Moodle configuration
The fix
The vulnerability was fixed in Moodle 3.5.0 after multiple patch attempts.
How it was found
- As a teacher, create a calculated question with a malicious formula that uses nested placeholders to hide code.
- The formula bypasses the validator and reaches eval(), executing the injected code.
- Access the question to trigger the code execution via a GET parameter.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Moodle lets teachers create quizzes with math formulas that are evaluated by the server. The server used a dangerous function to evaluate these formulas, and a security check could be bypassed by hiding malicious code inside placeholders. This let a teacher run commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.