Skip to content
SQL injection Write-up Intermediate

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.

Chris Anastasio Follow

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.

mufinnnnnnn (@mufinnnnnnn), on muffsec.com

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

  1. Log in as a user with Teacher or higher privileges for a course.
  2. Create a new badge for that course.
  3. Add a badge criterion of type profile and set the field value to the SQL payload.
  4. 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.

More from Moodle

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.