Django Unauthenticated, 0 click, RCE, and SQL Injection using def
Django's FilteredRelation combined with select_related allowed attacker-controlled text to reach the SQL query, because the check comparing the two names could be bypassed by appending a character. An attacker able to control both arguments could inject SQL, leading to SQL injection on all databases and remote code execution on PostgreSQL.
In order for you to be vulnerable, you need to use the ‘FilteredRelation’ function as above, with ‘selectrelated’. An attacker with control over the ‘FilteredRelation’ and the ‘selectrelated’ as above will be able to exploit the vulnerability.
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 code compared the two supplied names for equality but the comparison could be defeated by a small string difference, so the unchecked select_related value was placed into the SQL query.
Impact
An attacker with control over both arguments could achieve SQL injection on all databases and remote code execution on PostgreSQL.
What the attacker needed
Control over FilteredRelation and select_related; PostgreSQL for the RCE path
How it was found
- Use FilteredRelation together with select_related so the vulnerable code path is reached.
- Supply a crafted select_related value that passes the name check but carries injected SQL.
- Execute the query so the injected SQL runs, using PostgreSQL COPY ... PROGRAM for a reverse shell.
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.
Django is a web framework that builds database queries for you. A feature meant to let developers name a related table was not properly checked, so a crafted name could slip extra database commands into the query. On PostgreSQL this could let an attacker run commands on the server, which is remote code execution.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.