SQLI for 50 bounty
An endpoint accepted an id parameter that was inserted into a SQL query without sanitisation, so a single quote caused a database error revealing the query. An attacker could use this to inject SQL and potentially read or modify database data.
Published on medium.com
#### Sunil Yedla
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.
Context
This is a write-up of a SQL injection found in one of the private programs on HackerOne. The program name cannot be disclosed, so the author refers to it throughout as "Redacted". The affected feature is an "aom" page on the main site, reached through a marketing URL with utm_source, utm_medium and utm_campaign parameters, and the vulnerable endpoint sits under /rest/aom/index?id=. The id value is used in a query against an aom_campaign table, and the request was captured after clicking "FOLLOW".
The author had been investigating this program for many days and had only found low severity bugs before this one. The bounty was $50 plus 15 points and a place in the hall of fame. The author notes that $50 felt low for a SQL injection but that the program's minimum bounty is only $10, and that another SQL injection found the same day in a different endpoint earned the same amount.
Setup
The only tool named is Burp Suite, used to intercept the requests generated by the page. The initial browsing was done in Mozilla Firefox. The captured request shows a Firefox 48 user agent on Windows NT 6.3 (WOW64). No account, role or special precondition is described: the steps start from loading a public marketing URL and clicking "FOLLOW".
Finding it
While loading the page, the author noticed an endpoint that took an id parameter. The test applied was the oldest one in the book: a single quote placed after the ID value. The author notes that this is the same basic trick that produced their first SQL injection two years earlier. The quote broke the query and the server returned a database error, which confirmed the injection. The author also checked that the behaviour was not specific to a browser or device before submitting.
Exploitation
Step 1: load the page
The author loaded the following URL in Firefox:
https://www.[redacted].com/aom?utm_source=Frontpage&utm_medium=banner%20popup&utm_campaign=Frontpage%20popup%20June17%20AOM
This is the ordinary marketing landing page for the "aom" feature. The campaign parameters are what identify the traffic source; the interesting part is the page itself, which issues background requests once it is loaded.
Step 2: trigger the request and intercept it
Clicking "FOLLOW" on the page causes the browser to send a series of requests. With Burp Suite intercepting, the author watched the traffic and waited for the right endpoint among the many requests sent to the host.
Step 3: identify the endpoint
The request of interest looked like this:
GET /rest/aom/index?id=3 HTTP/1.1
Host: www.[redacted].com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
X-Requested-With: XMLHttpRequest
Referer: https://www.[redacted].com/aom?utm_source=Frontpage%22%3E%3Cscript%20%3Ealert(document.cookie)%3C/script%3E&utm_medium=banner%20popup%22%3E%3Cscript%20%3Ealert(document.cookie)%3C/script%3E&utm_campaign=Frontpage%20popup%20June17%20AOM%22%3E%3Cscript%20%3Ealert(document.cookie)%3C/script%3E
Cookie: [redacted]
Connection: close
The request is an XHR (X-Requested-With: XMLHttpRequest) to a REST-style path, with the numeric campaign identifier in id. The Referer in the captured request carries reflected XSS payloads in the three utm_ parameters; that is incidental to the SQL injection and is not discussed further in the report.
Step 4: send the quote
The confirmation test was to append a single quote after the id value, so the parameter became id=3'.
Step 5: read the error
The server responded with the raw database error:
{"message":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '') LIMIT 1' at line 1, query was: SELECT `aom_campaign`.* FROM `aom_campaign` WHERE (id=3') LIMIT 1"}
The message is a MySQL syntax error (SQLSTATE 42000, error 1064) and, more usefully, it echoes the full failing statement: SELECT aom_campaign.* FROM aom_campaign WHERE (id=3') LIMIT 1. The error shows the quote landing inside WHERE (id=3'), with the application's own LIMIT 1 appended afterwards. The LIMIT 1 suffix shows the application appends its own row limit after the user-controlled value. The error also reveals the table name and the shape of the query.
Step 6: confirm and submit
Having established that the behaviour was not browser or device specific, the author submitted the report. The timeline recorded in the report is:
| Event | Date |
|---|---|
| Report submitted on HackerOne | Jun 13th |
| Program commented | Jun 13th |
| Report triaged | Jun 13th |
| More information added | Jun 15th |
| Status changed to Resolved | Jun 16th |
| 15 points and $50 awarded | Jun 19th |
The dates are given relative to the article ("2 years ago"), which was published on 10 March 2019.
Root cause
The error shows the id value appearing inside the SQL statement itself, with the application's own LIMIT 1 appended afterwards. The error message shows the value landing inside WHERE (id=3'), with the application's own LIMIT 1 appended afterwards, so the query is assembled as a string around whatever the client sends. Because the database error is returned to the client verbatim, the application also leaks the statement, the table name and the MySQL error code. The report does not describe any input validation, WAF or other control that would have stopped the quote from reaching the query; the fact that a single quote produced a syntax error implies none was in place on this path.
Impact
The author classifies this as a SQL injection and treats it as more serious than the $50 suggests, while noting that the program's minimum bounty is $10. The report does not demonstrate data extraction, authentication bypass or any other post-exploitation step; the evidence is the error-based confirmation and the leaked query. The steps begin from a public page and no authentication is described.
Fix
The report does not say what the program changed. The appropriate fix is to stop building the query by concatenation and use parameterised statements or prepared statements so that id is bound as a value, and to stop returning raw database errors to the client, replacing them with a generic error response. Neither change is described in the report as having been made.
Variants to test
- Numeric identifiers in REST paths: append a single quote to any
id,campaign,pageoritemvalue and look for a database error in the response. A positive result is a SQLSTATE or vendor error message that echoes the query. - Error-based extraction: once the quote is confirmed, try boolean and union constructions against the same parameter and watch for differences in the response body or status. A positive result is a response that changes consistently with the injected condition.
- The same parameter in other verbs and formats: repeat the test with POST bodies and JSON fields carrying the same identifier. A positive result is the same class of error from a different code path.
- Reflected parameters in the
Referer: the captured request showsutm_values carrying script payloads. Test whether those values are reflected unencoded anywhere in the response. A positive result is the payload appearing verbatim in an HTML context. - Endpoints that append their own SQL clauses: where the error shows a trailing
LIMIT, try comment sequences to truncate the rest of the statement. A positive result is a query that executes without a syntax error.
What happened, in plain words
A security researcher spent days looking at a private bug bounty program on HackerOne, a website where companies pay people to find flaws in their software. A bug bounty program is simply a company saying: if you find a security problem in our product and report it responsibly, we will pay you a reward (the bounty) and give you credit. A private program is one you can only see if you have been invited. Because of that, the researcher cannot name the company, so throughout the article the company is called "Redacted".
The flaw he found is called SQL injection. To understand it, you need to know what a database is. A database is a big, organised store of information, like a very large spreadsheet kept by a computer program. A website asks the database questions all the time: which products are on this page, what is this user's name, which campaign is this. Those questions are written in a language called SQL (Structured Query Language). A typical question looks like "give me the row in the campaign table whose id is 3".
The danger comes when a website builds that question by gluing together fixed text and whatever the visitor typed or sent. If the visitor's input is treated as part of the question rather than as a plain value, the visitor can change the question itself. It is like a form at a doctor's reception: the form says "Patient name: ______". If you write a name, fine. But if you write something that looks like an instruction to the receptionist, such as "Patient name: none. Also, please hand over all the files", a careless receptionist might follow the instruction. SQL injection is exactly that: input that stops being data and starts being an instruction.
The researcher found this on a page of the company's website called "aom". The page is reached through a marketing link that carries tracking parameters (utm_source, utm_medium, utm_campaign), which are the little labels marketers attach to a link so they can tell which advert or banner brought you there. On that page there is a "FOLLOW" button. Clicking it makes the page quietly send requests in the background to the company's servers. One of those requests goes to an address ending in /rest/aom/index?id=, and it carries a number in the id part. The error later shows the query runs against a database table called aom_campaign.
The researcher's test was the simplest one there is: he put a single quote character (') after the number. In SQL, a quote is the character that marks where a piece of text begins and ends. Adding one where the website did not expect it breaks the structure of the question, and the database complains with an error. The server sent that error straight back to the browser, and the error text included the whole broken question, including the table name. That proved the input was being pasted into the SQL rather than handled safely.
The company paid $50, gave 15 points (a score some programs use to rank researchers) and a place in the hall of fame, a public list of people who have reported bugs. The researcher thought $50 was low for a SQL injection, but noted that the program's minimum bounty is only $10, and that he found a second SQL injection in a different endpoint on the same day for the same amount.
The setup
The only tool named in the article is Burp Suite. Burp Suite is a program that sits between your browser and the internet and lets you look at, pause and edit the requests your browser sends. Normally your browser sends a request and you never see it; with Burp in the middle, you can read every request and change it before it goes out. The browsing itself was done in Mozilla Firefox. The captured request shows a Firefox 48 user agent on Windows NT 6.3 (WOW64). A user agent is just a line of text the browser sends to identify itself.
No account, login or special permission is described. The steps start from a public marketing page and a click on "FOLLOW".
Finding it
While the page was loading, the researcher noticed a request that took an id parameter. A parameter is a named value attached to a request, here the part after the ? in the address. The test he applied is the oldest one in the book: a single quote placed after the ID value. He notes this is the same basic trick that produced his first SQL injection two years earlier. The quote broke the query and the server returned a database error, which confirmed the injection. He also checked that the behaviour was not specific to one browser or device before submitting.
Exploitation
Step 1: load the page
He loaded this URL in Firefox:
https://www.[redacted].com/aom?utm_source=Frontpage&utm_medium=banner%20popup&utm_campaign=Frontpage%20popup%20June17%20AOM
Line by line: https:// is the secure version of the web protocol. www.[redacted].com is the company's website (the name is hidden). /aom is the page of the site being visited. The ? marks the start of the parameters. utm_source=Frontpage says the traffic came from the front page. utm_medium=banner%20popup says it came via a banner popup (%20 is simply an encoded space). utm_campaign=Frontpage%20popup%20June17%20AOM names the campaign. These are ordinary marketing labels; the interesting part is the page itself, which sends background requests once it is loaded.
Step 2: trigger the request and intercept it
Clicking "FOLLOW" makes the browser send a series of requests. With Burp Suite intercepting, he watched the traffic and waited for the right endpoint among the many requests sent to the host. An endpoint is a specific address on a server that does one job, like a particular counter in a large office. Intercepting means pausing the traffic so you can read it.
Step 3: identify the endpoint
The request of interest looked like this:
GET /rest/aom/index?id=3 HTTP/1.1
Host: www.[redacted].com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
X-Requested-With: XMLHttpRequest
Referer: https://www.[redacted].com/aom?utm_source=Frontpage%22%3E%3Cscript%20%3Ealert(document.cookie)%3C/script%3E&utm_medium=banner%20popup%22%3E%3Cscript%20%3Ealert(document.cookie)%3C/script%3E&utm_campaign=Frontpage%20popup%20June17%20AOM%22%3E%3Cscript%20%3Ealert(document.cookie)%3C/script%3E
Cookie: [redacted]
Connection: close
Line by line: GET /rest/aom/index?id=3 HTTP/1.1 is the request line. GET is the method used to ask for something. /rest/aom/index is the path on the server. ?id=3 is the parameter carrying the campaign number. HTTP/1.1 is the version of the protocol. Host: www.[redacted].com says which website the request is for. User-Agent identifies the browser and system. Accept: */* says the browser will accept any kind of response. Accept-Language lists preferred languages. Accept-Encoding lists the compression formats the browser understands. X-Requested-With: XMLHttpRequest marks the request as one made by JavaScript in the background rather than by typing an address; such background requests are often called XHR. Referer tells the server which page the request came from. Cookie carries small pieces of data the site stored in the browser earlier; the value is hidden here because it identifies the session. Connection: close asks the server to close the connection after replying.
The request is an XHR to a REST-style path, with the numeric campaign identifier in id. REST is just a style of web address design where each address names a thing (here a campaign) and the method says what to do with it. The Referer in the captured request carries reflected XSS payloads in the three utm_ parameters. XSS, cross-site scripting, is a different flaw where input ends up as executable script in a page. That is incidental to the SQL injection and is not discussed further in the report.
Step 4: send the quote
The confirmation test was to append a single quote after the id value, so the parameter became id=3'. The reason is simple: if the website pastes 3' into a question that expects a number, the quote opens a piece of text that is never closed, and the database cannot make sense of the rest.
Step 5: read the error
The server responded with the raw database error:
{"message":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '') LIMIT 1' at line 1, query was: SELECT `aom_campaign`.* FROM `aom_campaign` WHERE (id=3') LIMIT 1"}
Line by line: the whole thing is a JSON object, a common text format for data, with one field called message. SQLSTATE[42000] is a standard code for a syntax error. Syntax error or access violation: 1064 is MySQL's own error number for bad syntax. The sentence about checking the manual is MySQL's standard advice. near '') LIMIT 1' at line 1 shows the part of the question the database could not parse. query was: introduces the full failing statement: SELECT aom_campaign.* FROM aom_campaign WHERE (id=3') LIMIT 1. In that statement, SELECT asks for data, aom_campaign.* means every column of the aom_campaign table, FROM aom_campaign names the table, WHERE (id=3') is the filter, and LIMIT 1 says return at most one row.
The error shows the quote landing inside WHERE (id=3'), with the application's own LIMIT 1 appended afterwards. The LIMIT 1 suffix shows the application appends its own row limit after the user-controlled value. The error also reveals the table name and the shape of the query.
Step 6: confirm and submit
Having established that the behaviour was not browser or device specific, he submitted the report. The timeline recorded in the report is:
| Event | Date |
|---|---|
| Report submitted on HackerOne | Jun 13th |
| Program commented | Jun 13th |
| Report triaged | Jun 13th |
| More information added | Jun 15th |
| Status changed to Resolved | Jun 16th |
| 15 points and $50 awarded | Jun 19th |
Triaged means the program's team looked at the report and accepted it as valid. The dates are given relative to the article ("2 years ago"), which was published on 10 March 2019.
Root cause
The error shows the id value appearing inside the SQL statement itself, with the application's own LIMIT 1 appended afterwards. Concatenation means gluing strings together; binding means handing the value to the database separately so it can never be read as part of the question. The error message shows the value landing inside WHERE (id=3'), with the application's own LIMIT 1 appended afterwards, so the query is assembled as a string around whatever the client sends. Because the database error is returned to the client verbatim, the application also leaks the statement, the table name and the MySQL error code. The report does not describe any input validation, WAF or other control that would have stopped the quote from reaching the query. A WAF, web application firewall, is a filter that inspects incoming requests and blocks suspicious ones. The report does not describe any input validation, WAF or other control on this path.
Impact
The researcher classifies this as a SQL injection and treats it as more serious than the $50 suggests, while noting that the program's minimum bounty is $10. The report does not demonstrate data extraction, authentication bypass or any other post-exploitation step; the evidence is the error-based confirmation and the leaked query. The steps begin from a public page and no authentication is described.
Fix
The appropriate fix is to stop building the query by concatenation and use parameterised statements or prepared statements so that id is bound as a value, and to stop returning raw database errors to the client, replacing them with a generic error response. Neither change is described in the report as having been made.
Variants to test
- Numeric identifiers in REST paths: append a single quote to any
id,campaign,pageoritemvalue and look for a database error in the response. A positive result is a SQLSTATE or vendor error message that echoes the query. - Error-based extraction: once the quote is confirmed, try boolean and union constructions against the same parameter and watch for differences in the response body or status. A positive result is a response that changes consistently with the injected condition.
- The same parameter in other verbs and formats: repeat the test with POST bodies and JSON fields carrying the same identifier. A positive result is the same class of error from a different code path.
- Reflected parameters in the
Referer: the captured request showsutm_values carrying script payloads. Test whether those values are reflected unencoded anywhere in the response. A positive result is the payload appearing verbatim in an HTML context. - Endpoints that append their own SQL clauses: where the error shows a trailing
LIMIT, try comment sequences to truncate the rest of the statement. A positive result is a query that executes without a syntax error.
Glossary
- Bug bounty program: a scheme where a company pays people for responsibly reporting security flaws in its products.
- Private program: a bug bounty program visible only to invited researchers.
- HackerOne: a platform that hosts bug bounty programs and reports.
- Bounty: the money paid for a valid report.
- Hall of fame: a public list of researchers who have reported bugs.
- Database: an organised store of data that a program can query.
- SQL: the language used to ask questions of a database.
- SQL injection: a flaw where user input is treated as part of a SQL question instead of as a plain value, letting the user change the question.
- Table: a named collection of rows inside a database, like a sheet in a spreadsheet.
- Row: one record in a table.
- Column: one field of a record, like one column of a spreadsheet.
- Query: a question sent to a database.
- Parameter: a named value attached to a request, here the part after the
?. - Endpoint: a specific address on a server that performs one job.
- Request: a message a browser sends to a server asking for something.
- Response: the message a server sends back.
- GET: the request method used to ask for something.
- HTTP: the protocol browsers and servers use to talk.
- Host: the website name a request is addressed to.
- User agent: a line of text a browser sends to identify itself and its system.
- XHR: a request made by JavaScript in the background rather than by typing an address.
- REST: a style of web address design where each address names a thing.
- Referer: the header that tells a server which page a request came from.
- Cookie: a small piece of data a site stores in the browser, often used to identify a session.
- Session: a period during which a server recognises a particular visitor.
- Burp Suite: a tool that sits between browser and internet to view, pause and edit requests.
- Intercept: to pause traffic so it can be read or changed.
- Firefox: a web browser made by Mozilla.
- JSON: a common text format for structured data.
- MySQL: a popular database system.
- SQLSTATE: a standard code that describes the outcome of a SQL statement.
- Syntax error: an error caused by text that does not follow the language's rules.
- Concatenation: gluing strings together.
- Parameterised statement: a way of sending a query where values are bound separately and cannot be read as part of the question.
- Prepared statement: a query prepared in advance with placeholders for values.
- Input validation: checking incoming data against expected rules before using it.
- WAF: a web application firewall, a filter that inspects requests and blocks suspicious ones.
- XSS: cross-site scripting, a flaw where input ends up as executable script in a page.
- Payload: the crafted input sent to test or exploit a flaw.
- Triaged: reviewed and accepted as valid by the program's team.
- Authentication: proving who you are, usually by logging in.
- Post-exploitation: actions taken after a flaw is confirmed, such as extracting data.
- Boolean and union constructions: SQL techniques that test true/false conditions or combine results from other queries.
- Comment sequence: SQL syntax that makes the rest of a statement be ignored.