Skip to content
SQL injection Write-up Intermediate

The Story of my first critical bug

The search parameter on a subdomain was vulnerable to blind SQL injection, as confirmed by time-delay payloads that caused the server to respond after a controlled delay. An attacker could use this to extract or manipulate database contents.

Shellbr3ak Follow

Published on shellbr3ak.medium.com

3 months ago I got my first infosec job as a Threat Intelligence Analyst, and I can’t tell how happy I was to get this job. However my application wasn’t meant to be (I’m looking for a job as threat intel analyst) instead it was about web penetration testing.

Shellbr3ak, on shellbr3ak.medium.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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

This is the story of a first real-life critical bug, found during a web penetration test on a client's website. The author had recently started a job as a Threat Intelligence Analyst, but the actual assignment was web penetration testing. The client is referred to throughout as "redacted.com" for privacy, and the vulnerable host as subdomain.redacted.com.

The feature involved is a search bar on that subdomain. Whatever is submitted into it gets rendered in the response page. The backend technology in use is ASP.NET, and the server runs Windows, which led the author to expect MSSQL as the RDBMS.

From the original on shellbr3ak.medium.com

Setup

The author had prior experience only on CTF platforms such as HackTheBox, TryHackMe and Portswigger labs, and this was the second time the team leader asked them to conduct a pentest. The SQL injection techniques used here were learned from PortSwigger Academy.

Before the finding, almost every website owned by the company had been tested and a report prepared. That report contained nothing of interest beyond a few notes about security misconfigurations and brute force protection bypass issues. One website had been forgotten, and it was tested in a short window with a scanner plus some simple manual tests.

Burp was used to intercept the request and measure response time accurately, because the author's own internet connection was slow at the time.

Finding it

With little time left, the author picked three candidate vulnerabilities to test on the search bar:

  1. XSS
  2. SSTI
  3. SQLi

XSS testing produced nothing. SSTI fuzzing was abandoned once the backend was identified as ASP.NET, which has no template engines, so that test was meaningless. SQLi was almost skipped on the assumption that ASP.NET is a good platform for secure web apps and that such a critical bug could not be present. It was tested anyway, quickly.

Because the stack was ASP.NET on Windows, the author expected MSSQL and focused on it, while still submitting some payloads for other DBMSs.

Exploitation

Step 1: the classic comment payloads

The first payloads submitted were the well-known comment-based tests, placed in the search parameter:

HTTP
https://subdomain.redacted.com/?search= ' or 1=1 --
HTTP
https://subdomain.redacted.com/?search=" or 1=1 --

Neither produced any indication that the server might be vulnerable.

Step 2: varying the condition

Since ' or 1=1 -- is a very well known test, the author changed the numbers in case a firewall was blocking the 1=1 expression, and also tried an always-false condition instead of an always-true one, such as ' or 1=2 --. The server responded in a strange way, but not enough to conclude it was really vulnerable.

Step 3: time delay

After a two-minute break to recall SQLi techniques, the author remembered the time delay payload, described as the most effective one for detecting blind SQLi:

SQL
' WAITFOR DELAY '00:00:10'

The server took some time to respond, but the author's internet connection was slow, so the delay could not be attributed to the payload. The request was intercepted with Burp to measure the response time accurately: the response came back at 10 seconds and a few milliseconds.

Step 4: confirming with longer delays

The payload was changed to force a 20 second delay, which worked. Still not fully convinced, the author forced a delay of 1 minute, and that worked too, confirming the SQL injection.

The report was then edited to include the new SQLi notes and handed to the team leader.

Root cause

The report does not describe the server-side code. What it shows is that user input from the search bar reaches a SQL query without being safely handled, so an injected WAITFOR DELAY is executed by MSSQL and delays the response. The initial or 1=1 payloads produced no indication of vulnerability, and the author's own assumption that ASP.NET would be secure nearly ended the test before the delay payload was tried.

Impact

The report does not state what data or functionality an attacker could reach beyond confirming the injection. The author classifies it as a critical bug, confirmed through response timing. The practical consequence demonstrated is that input to the search feature can make the database execute injected SQL and control how long the response takes.

Fix

The report gives remediation as general principles rather than a code change:

  • Never trust user input
  • Always check user-supplied data

Variants to test

  • Always-false condition (' or 1=2 --): a change in the response compared with a true condition suggests the input reaches the query, even when 1=1 is filtered.
  • Altered true condition (' or 3=3 --): a positive result is the same behaviour as 1=1, and it can bypass a filter that blocks the literal 1=1.
  • Time delay (' WAITFOR DELAY '00:00:10'): a positive result is a response delayed by roughly the specified interval, measured through an intercepting proxy rather than by eye.
  • Escalating delays (20 seconds, then 1 minute): a positive result is a delay that scales with the value, which rules out network latency as the cause.

Bug bounty tips from the report: never underestimate time delay payloads, and do not rely on automated scanners.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

A security tester had just started a new job. The job title was Threat Intelligence Analyst, but the actual work turned out to be web penetration testing: probing a client's websites on purpose, with permission, to find weaknesses before criminals do. This was only the second time their team leader had asked them to do this kind of test.

They had practised before, but only on training platforms such as HackTheBox, TryHackMe and Portswigger labs. Those are websites that host deliberately broken applications so people can learn to attack them safely. Real client systems are different: nobody tells you where the bug is, and you have limited time.

They tested almost every website the client owned and wrote a report. The report had nothing serious in it, only a few notes about security misconfigurations (settings left in an unsafe state) and ways to get around brute force protection (the mechanism that slows down repeated login attempts). Then they found one website they had forgotten to test. With only a short window left, they decided to run an automated scanner and do a few simple manual checks rather than a full test.

On that website there was a search bar. Whatever you typed into it appeared back on the response page. The tester found a SQL injection: a flaw that lets a visitor slip database commands into the search box. It was their first real-life critical bug.

From the original on shellbr3ak.medium.com

The setup, and why it matters

Before the finding, the tester had already covered almost every site the client owned. The report from that work contained only minor items: some security misconfigurations and some brute force protection bypass issues. Nothing that would make headlines.

While waiting for the team leader to become available, they reviewed their own report and noticed one website they had not tested at all. They had very little time, so the plan was modest: run a scanner and do some quick manual tests. A scanner is a program that automatically throws thousands of known attack patterns at a site and reports anything that looks suspicious. It is fast but shallow, and it misses a lot. Manual testing is slower but lets a human follow a hunch.

One practical detail matters later: the tester's own internet connection was slow at that moment. That made it hard to judge whether a slow response came from the server or from their own network. To measure properly, they used Burp, a tool that sits between the browser and the website, lets you capture a request, change it, send it, and see exactly how long the reply took.

The target and the three ideas

The forgotten website lived at a subdomain, which the tester calls subdomain.redacted.com. A subdomain is a section of a larger domain: if redacted.com is the company's main address, subdomain.redacted.com is one of its named parts, often a separate application.

On that subdomain there was a search bar. Whatever was submitted into it got rendered in the response page. "Rendered" means the server took the text you typed and put it into the page it sent back, so you could see your own input echoed on screen.

With little time, the tester picked three candidate vulnerabilities to try on that search bar:

  1. XSS (Cross-Site Scripting): tricking a site into sending your own JavaScript code to other visitors' browsers, so the code runs as if the site itself wrote it.
  2. SSTI (Server-Side Template Injection): tricking the server's page-building engine into evaluating your input as part of its own template code.
  3. SQLi (SQL Injection): tricking the database into treating your input as part of a database command.

A quick everyday comparison: a database is like a filing clerk who only understands a strict shorthand (SQL). A search box is supposed to hand the clerk a single word to look up. SQL injection is what happens when the clerk cannot tell the difference between the word you gave them and an instruction you slipped in after it, so they go and fetch the wrong drawer, or in this case, wait ten seconds before answering.

XSS: nothing

XSS testing produced nothing. The tester tried the usual tricks and the site did not cooperate.

SSTI: abandoned for a good reason

SSTI fuzzing (throwing many candidate inputs at the field to see if any get evaluated) was abandoned once the backend was identified as ASP.NET. ASP.NET is Microsoft's framework for building web applications. It does not use template engines in the way the SSTI test assumes, so the test was meaningless on this stack. Knowing what software runs underneath saves you from wasting time on attacks that cannot apply.

SQLi: almost skipped

The tester nearly skipped SQL injection. The reasoning was: ASP.NET is a solid platform for building secure web apps, and SQL injection is one of the most critical bug classes, so surely this application would not have it. That assumption is exactly the kind of thing that makes testers miss bugs. They tested anyway, quickly.

Because the stack was ASP.NET on Windows, the tester expected the database to be MSSQL, Microsoft's database product. They focused on MSSQL payloads while still submitting some for other database systems (DBMS, database management systems) in case the guess was wrong.

Finding it, step by step

Step 1: the classic comment payloads

The first payloads submitted were the well-known comment-based tests, placed in the search parameter. A parameter is the part of a URL after the question mark that carries a value to the server; here, search is the name of the field and everything after = is its value.

HTTP
https://subdomain.redacted.com/?search= ' or 1=1 --

Line by line, in plain words:

  • https://subdomain.redacted.com/ is the address of the search page.
  • ?search= starts the parameter: everything after the equals sign is what the search box would send.
  • ' is a single quote. In SQL, text values are wrapped in quotes, so a stray quote can end the intended value early and let whatever follows be read as SQL code.
  • or 1=1 is a condition that is always true, because one always equals one. If the application builds a query like "find rows where name equals [your input]", injecting this can turn it into "find rows where name equals '' or 1=1", which matches every row.
  • -- starts a comment in SQL. Everything after it is ignored, which is useful for discarding the rest of the original query that would otherwise cause an error.
HTTP
https://subdomain.redacted.com/?search=" or 1=1 --

This is the same idea with a double quote instead of a single quote, in case the query wraps values in double quotes rather than single ones.

Neither produced any indication that the server might be vulnerable. No error, no change in results, nothing to latch onto.

Step 2: varying the condition

Since ' or 1=1 -- is a very well known test, the tester changed the numbers. The idea: some firewalls (security devices that inspect traffic) block the literal expression 1=1 because it is so commonly used in attacks. If you write 3=3 instead, the condition is still always true, but the filter may not recognise it.

They also tried an always-false condition instead of an always-true one, such as ' or 1=2 --. Here one does not equal two, so the condition is false. If the page behaves differently for a false condition than for a true one, that difference is a signal that your input is reaching the query.

The server responded in a strange way, but not enough to conclude it was really vulnerable. A strange response is a hint, not proof. Something else could explain it: caching, a random error, a slow moment.

Step 3: time delay

After a two-minute break to recall SQL injection techniques, the tester remembered the time delay payload. This is described as the most effective way to detect blind SQL injection. "Blind" means the application gives you no visible output from your injected command: no error message, no extra rows, no change on the page. You cannot see the answer, so you ask the database to do something you can observe from the outside, such as wait before replying.

SQL
' WAITFOR DELAY '00:00:10'

Line by line:

  • ' closes the text value the application was building, so what follows is read as SQL code.
  • WAITFOR DELAY is an MSSQL instruction that pauses execution for a given amount of time.
  • '00:00:10' is the duration in hours, minutes and seconds: zero hours, zero minutes, ten seconds.

If the input reaches the database as code, the server will sit there for ten seconds before answering. If it does not, the reply comes back immediately.

The server took some time to respond, but the tester's internet connection was slow, so the delay could not be attributed to the payload. This is the classic trap with timing attacks: your own network can add seconds of delay, and you cannot tell the difference by eye. The request was intercepted with Burp to measure the response time accurately: the response came back at 10 seconds and a few milliseconds. That precision is what turns a hunch into evidence.

Step 4: confirming with longer delays

The payload was changed to force a 20 second delay, which worked. Still not fully convinced, the tester forced a delay of 1 minute, and that worked too. Random latency does not politely double when you change a number.

The report was then edited to include the new SQL injection notes and handed to the team leader.

Why it worked

The report does not describe the server-side code. What it shows is that user input from the search bar reaches a SQL query without being safely handled, so an injected WAITFOR DELAY is executed by MSSQL and delays the response.

The initial or 1=1 payloads produced no indication of vulnerability. And the tester's own assumption that ASP.NET would be secure nearly ended the test before the delay payload was ever tried.

What an attacker could do

The report does not state what data or functionality an attacker could reach beyond confirming the injection. The tester classifies it as a critical bug, confirmed through response timing. The practical consequence demonstrated is that input to the search feature can make the database execute injected SQL and control how long the response takes.

The fix

The report gives remediation as general principles rather than a code change:

  • Never trust user input
  • Always check user-supplied data

Variants worth trying

  • Always-false condition (' or 1=2 --): a change in the response compared with a true condition suggests the input reaches the query, even when 1=1 is filtered.
  • Altered true condition (' or 3=3 --): a positive result is the same behaviour as 1=1, and it can bypass a filter that blocks the literal 1=1.
  • Time delay (' WAITFOR DELAY '00:00:10'): a positive result is a response delayed by roughly the specified interval, measured through an intercepting proxy rather than by eye.
  • Escalating delays (20 seconds, then 1 minute): a positive result is a delay that scales with the value, which rules out network latency as the cause.

Tips from the report

  • Never underestimate time delay payloads.
  • Do not rely on automated scanners.

Glossary

  • Threat Intelligence Analyst: a job focused on gathering and understanding information about attackers and threats; here, the actual assignment was web penetration testing instead.
  • Web penetration testing (pentest): testing a website with permission, by trying to break it, to find weaknesses before criminals do.
  • CTF platform: a training site (such as HackTheBox, TryHackMe or Portswigger labs) that hosts deliberately vulnerable applications for practice.
  • Security misconfiguration: a setting left in an unsafe state, such as a default password or an exposed admin page.
  • Brute force protection: the mechanism that slows down or blocks repeated login attempts; a bypass is a way around it.
  • Scanner: a program that automatically sends many known attack patterns to a site and reports anything suspicious.
  • Burp: a tool that sits between the browser and the website, letting you capture, change and resend requests and measure response times.
  • Subdomain: a named section of a larger domain, such as subdomain.redacted.com under redacted.com.
  • Rendered: put into the page the server sends back, so the user sees it on screen.
  • XSS (Cross-Site Scripting): tricking a site into sending your own JavaScript to other visitors' browsers.
  • SSTI (Server-Side Template Injection): tricking the server's page-building engine into evaluating your input as template code.
  • SQLi (SQL Injection): tricking a database into treating your input as part of a database command.
  • SQL: the language used to talk to relational databases.
  • Database: an organised store of data that applications query, like a filing cabinet with a strict clerk.
  • ASP.NET: Microsoft's framework for building web applications.
  • Template engine: software that builds pages from templates with placeholders; ASP.NET does not use one in the way the SSTI test assumes.
  • Fuzzing: throwing many candidate inputs at a field to see if any produce an interesting reaction.
  • DBMS: database management system, the software that runs a database.
  • MSSQL: Microsoft's database product.
  • Parameter: the part of a URL after the question mark that carries a value to the server, such as search here.
  • Payload: the specific input you send to try to trigger a vulnerability.
  • Comment (in SQL): text starting with -- that the database ignores, useful for discarding the rest of a query.
  • Always-true condition: a condition that is always true, such as 1=1, used to make a query match everything.
  • Always-false condition: a condition that is always false, such as 1=2, used to compare how the page behaves.
  • Firewall: a security device that inspects traffic and can block known attack patterns.
  • Blind SQL injection: injection where you get no visible output from your command, so you infer success from side effects such as timing.
  • Time delay payload: an injected instruction that makes the database pause, so you can detect it by measuring the response time.
  • WAITFOR DELAY: an MSSQL instruction that pauses execution for a given duration.
  • Intercepting proxy: a tool that sits between your browser and the server so you can capture and modify requests; Burp is one.
  • Response time: how long the server takes to reply, measured precisely rather than by eye.
  • Latency: delay in a network connection; random latency does not scale with a number you supply.
  • Unauthenticated visitor: someone using the site with no account or login.
  • Remediation: the fix or set of principles that removes the vulnerability.

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.