SOQL injection in SalesForce Apex earned me $$$$$
A SOQL injection in a Salesforce Apex method allowed an authenticated user to manipulate the LIKE clause and extract other users' data, including custom password fields. The attacker could dump PII and passwords character by character using regex matching.
medium.com
Published on medium.com
Some weeks ago, I was bored from sitting at my desk for almost 8 hours a day, so I decided to take my Mac and go outdoors to drink something,so I went to a cafe, got my laptop, and decided to read about something new. During those days, I was targeting a site that runs Salesforce CRM, which was using Salesforce…
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 Apex method concatenated user-supplied input directly into a SOQL query without parameterisation or sanitisation.
Impact
An authenticated attacker could read other users' personal data and passwords stored in a custom field, though the LIKE operator could not extract numeric fields like phone numbers.
What the attacker needed
Authenticated user account; access to the user dashboard
The fix
The application should use parameterised queries or proper input sanitisation to prevent SOQL injection.
How it was found
- Log in and open the user dashboard, which sends Aura requests to the /s/sfsites/aura endpoint.
- Decode the Aura message parameter to see the JSON containing FirstName, LastName, and Status fields.
- Inject a single quote into the FirstName value and observe an error, confirming injection in the LIKE operator.
- Craft a payload that breaks out of the LIKE clause and adds an AND condition using known fields to balance the query.
- Use the LIKE operator with regex patterns to brute-force data character by character.
- Brute-force custom field names and then dump the Account_Password__c field for the admin account.
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.
Salesforce stores data in objects rather than tables, and queries use a language called SOQL. The application built a query by pasting user input directly into a search condition, so a user could add extra conditions to the query. This let them read other people's records, including passwords stored in a custom field.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.