Skip to content
SQL injection Write-up Advanced

Drupal 7 SQL Injection Vulnerability

Drupal's prepared-statement helper mishandled array placeholders whose keys were not integers, letting an unauthenticated attacker inject arbitrary SQL. Because Drupal uses PDO with multi-queries enabled, an attacker could read, modify or drop data and, by inserting rows, execute PHP code.

sektioneins.de

Published on sektioneins.de

Advisory: Drupal - pre Auth SQL Injection Vulnerability Release Date: 2014/10/15 Last Modified: 2014/10/15 Author: Stefan Horst [stefan.horst[at]sektioneins.de]

SektionEins GmbH, on sektioneins.de

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 expandArguments helper built placeholder names from array keys without forcing them to be integers, so a crafted key could break out of the placeholder and become SQL syntax.

Impact

An unauthenticated remote attacker could read, insert, modify or drop database contents and, through inserted data, execute PHP code, giving total control of the site.

What the attacker needed

No authentication required; Drupal 7.0 to 7.31

The fix

The helper was changed to iterate over array_values so placeholder names are always built from integer positions; Drupal 7.32 contains the fix.

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.

Drupal builds database queries using placeholders, small named slots that are filled with values later so user input is not treated as SQL. A helper that expands a list of values into several placeholders assumed the list was a plain numbered list; when it was not, part of a value could end up as SQL syntax. That let anyone on the internet run their own database commands without logging in.

What is SQL injection?

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

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.