Exploitation Summary
Moodle's badge criteria functionality allows a user with Teacher privileges to inject SQL into a badge criterion field, which is later executed unsanitised when the badge is enabled. An attacker could use this to run arbitrary SQL queries against the database.
Published on muffsec.com
Moodle is vulnerable to 2nd order sqli by users with Teacher or higher privileges. The reason these privileges are required is because the sqli is in the badge management functionality.
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
Likely the application builds SQL by directly interpolating a user-controlled badge criterion field into a query without parameterisation or escaping.
Impact
An attacker with Teacher privileges could execute arbitrary SQL queries, potentially reading or modifying database contents; the text also notes the bug can be used for stored XSS.
What the attacker needed
Teacher or higher role in a course
How it was found
- Log in as a user with Teacher or higher privileges for a course.
- Create a new badge for that course.
- Add a badge criterion of type profile and set the field value to the SQL payload.
- Enable the badge, which triggers the stored SQL to execute.
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.
A teacher-level user can create a badge and set a rule for earning it. The rule's value is saved and later placed directly into a database command without cleaning, so the teacher can make the database run extra commands. This is called second-order SQL injection because the harmful input is stored first and used later.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.