Back to Glossary
S

SQL Injection

What Is SQL Injection — In Simple Words

Imagine that you visit a website and try to log in. Enter “admin” in the “login” field, “1234” in the “password” field, press the button, and the system checks whether the data matches. Everything is logical.

Now imagine that in the “login” field someone enters this:

‘ OR 1=1 —

And suddenly — access is open. Without a password. Without a username. Just because the server was given a tricky request, and he believed it. This is SQL Injection.

SQL injection is when, instead of the usual data, a fragment of SQL code is inserted into the form field, the language in which the server “talks” to the database. And this code changes the behavior of the request. Not just looking for a user, but, say, showing everyone, deleting something, giving access without rights.

The essence of the attack is that the program does not check what is being injected into it. It “swallows” the entire string and sends it to the database. And the base does. Without suspicion.

That’s it, it’s a simple shape on the outside. There is vulnerability inside. Dangerous and ridiculously simple.

A Bit Of History: First There Was A Request

To understand how we came to SQL injections, we need to look back to the late 90s. Then the sites began to actively connect databases: registration, search, orders — everything worked through SQL queries. But the developers of that time didn’t really think much about input verification. Everything was new. The main thing is to make it work.

And in 1998, the first documented case of SQL Injection appeared. Phrack Magazine specialists publish an article describing how to extract data from the database through the input field. It was a real breakthrough: no one had thought before that plain text input could be a weapon.

Later, a series of attacks on the websites of banks, universities, and online stores. An example from 2002: an attacker using SQL injection gained access to thousands of credit card numbers from a website Guess.com . I just entered the required line and that’s it.

The irony is that in 25 years the essence of the attack has hardly changed. As it was trivial, it remained so. Protection methods are changing, but the main threat is alive. Precisely because the root of the problem lies in the carelessness of the developers themselves.

How It Works — On Your Fingers

Let’s try to decompose the mechanics of SQL injection at the level of everyday logic.

Let’s say you have a line of code on the server that is sent to the database:

SELECT * FROM users WHERE username = ‘$login’ AND password = ‘$pass’;

You enter the username “admin” and password “1234”. It’s all fair.
And the attacker enters:
login: ‘ OR ‘1’=’1
password: not important

And it turns out such a request:

SELECT * FROM THE users WHERE username = “OR “1”=”1″ AND password = “not important”;

What does the server see? It searches for a user whose name is an empty string or the condition ‘1’=’1′, which is always true. As a result, the server returns all users. And the logic of “accessing with the correct password” breaks down.

That’s why they say injection. Like an injection, just not into the body, but into the structure of the request. The attacker gets inside the logic of the database and manages it as he wants.

Another example: if you enter in the search form on the website
‘ UNION SELECT credit_card_number FROM clients —
then you can get the contents of a completely different table with card numbers.

Complicated words are not needed here. The main thing is to understand that injection is the introduction of extraneous code that is executed as if it were legitimate.

Where Does It Work — And Why

It would seem that in order for the vulnerability to be possible, some kind of special website is needed. In fact, everything is much simpler. SQL injection can work in the most common places:

  • Login form: classic. The login and password fields are ideal targets.
  • Search bar: you are looking for a product on the site, and the attacker is a vulnerability.
  • Feedback form: someone leaves a name, and someone else leaves an SQL query.
  • URL parameters: if the site inserts the value directly into the request without verification.
Where SQL Injection Works
Where SQL Injection Works

Why is this even possible? Because no one filters the input data on the server. Or filters it, but carelessly.

Important: it’s not just about large sites. Small online stores, blogs, even comment pages are all potential targets. If there is a field where you can enter something, and a database is hidden behind it, the vulnerability is nearby.

One of the most striking cases is a website MySQL.com . In 2011, he himself became a victim of SQL injection. Yes, the official website of the DBMS developers! It’s like a pharmacy being robbed with its own scalpel.

Classic Examples Of SQL Injection — Hacker Folklore

If you open any textbook on cybersecurity, be it a university course or a self—help guide for enthusiasts, you will almost certainly find the same “legendary” lines. They clearly show how simple and ingenious SQL injection is at the same time.

One of the most basic examples is an attempt to log in without knowing your username and password. In the “username” field, the attacker enters:

‘ OR ‘1’=’1

And in the “password” field — anything or just leaves it empty. The server receives an SQL query, which instead of filtering by username and password now looks something like this:

SELECT * FROM users WHERE username = ” OR ‘1’=’1′ AND password = ”

And what does ‘1’=’1′ do? It always returns true. And if the server does not verify the correctness of the request, it honestly grants access… to all rows of the database. That’s why a person gets inside, as if he is the most authorized of all.

More complex examples include:

  • DROP TABLE users; — — the famous “Bobby Tables”. This row can delete the entire table with users if the site has no protection.
  • UNION SELECT — used to attach additional data to the query. This is how an attacker extracts e-mails, phone numbers, and even password hashes.
  • WAITFOR DELAY ’00:00:10′ is a method for “blind” attacks: it adds a pause to the server’s response, which helps analyze the site’s response even without direct display on the screen.

These fragments are like a set of lock picks that you can use to check dozens of doors. And, unfortunately, many are still opening.

What Can Be Stolen Through SQL Injection — Spoiler: Almost Everything

One of the main reasons why SQL injections are still among the top threats is their potential. They can pull out almost any information stored in the database. From harmless strings to critical system keys.

Here is an incomplete list of things that fall into the hands of an attacker:

  • Personal data of users: names, logins, mail, phone numbers, addresses.
  • Passwords: even in hashed form, you can still try to bruteforce them.
  • Bank card numbers: especially if the site has disregarded PCI-DSS rules.
  • Purchase history: allows you to create a portrait of a customer.
  • Admin access: if an attacker obtains administrator credentials, he can change the contents of the site, delete entries, or create a backdoor for himself.
  • Files and Documents: If the database contains links or paths to internal documents, you can access them as well.
  • The structure of the database itself: tables, fields, and data types. This gives the hacker a “map of the area”.

And in extreme cases, SQL injection can give direct access to the server’s operating system. This is already going beyond “just a base” — and a step towards the complete capture of the resource.

The Types Of SQL Injections Are Not Always Head—On

Not all SQL injections are equally straightforward. Some attackers work head—on, while others use workarounds. There are three main types in the professional environment::

  1. In-band (live channel), It’s a classic. The attacker enters a malicious query, and the result is immediately displayed on the page. For example, if he enters UNION SELECT in the search bar, and the site returns the result of the query, it means that the injection has worked. This is the easiest and fastest way to get the data.
  2. Blind (blind injection), the site does not show the result of the query, but it reacts differently if the input is correct or not. For example, you enter a query that should cause an error. If the page behaves differently, this is a sign. Or add AND 1=1 / AND 1=2, and you can tell by changing the behavior that the request has been processed. This approach requires patience and imagination.
  3. Out-of-band (via a third-party channel), the most non-trivial method. Instead of direct or blind injection, the attacker implements a command that causes the server to connect to an external resource, such as its own server. This makes it possible to track and analyze the reaction bypassing the main page.
Type of SQL InjectionResponse TypeHow It WorksTypical Use Case
In-bandImmediate feedbackAttacker sees results directly in the browserDumping database contents
Blind (Boolean-based)No visible feedbackAttacker observes changes in response behavior (true/false)Extracting data through guesswork
Blind (Time-based)Delayed feedbackAttacker sends queries that cause time delays if condition trueProbing deeper when no error messages
Out-of-bandExternal channelUses DNS or HTTP requests to exfiltrate data via third-party siteBypassing firewalls or filters

Each type is used depending on the site’s security level, platform features, and the attacker’s imagination. The main thing is to understand that even if you don’t see what’s going on, it doesn’t mean that nothing is happening.

Why Is It Still Working? Where Are All The Programmers?

It would seem that SQL injections are described, analyzed, included in all OWASP lists and covered by millions of guides. Then why are there still sites vulnerable to this attack in 2025?

The reasons lie in three commonplace things:

  1. Mistakes and haste, many websites are written on the knee. Freelancers, aspiring developers, and a quickie business all have the same goal: “to make it work.” No audit, no tests. And then, years later, the site with the vulnerability continues to live and serve customers.
  2. Legacy of old CMS and frameworks, WordPress, Joomla, old versions of PHP scripts — all this can drag unsupported modules for years. If they use unsafe SQL queries, no one will know about it until the moment of the attack.
  3. Non-updated platforms, large companies have dozens of microservices, legacy systems written many years ago. Sometimes it’s impossible to simply rewrite or update them. This means that the vulnerability remains.

And the icing on the cake: even with firewalls, proxies, and filters, if the database “listens” to unprepared input, there is always someone who will play with it.

High-Profile SQL Injection Attacks

Injections are not some boring theory for IT specialists with glasses. These are real hacks, with consequences that have been felt by millions. Let’s recall the most high-profile cases when a small line of SQL code brought down the giants.

  1. Sony Pictures (2011). Hackers from the LulzSec group penetrated Sony’s database and leaked almost a million user records, including e-mail, passwords, and dates of birth. How? The same classic SQL Injection. They just entered malicious code into a form on the website, and… the system opened like a refrigerator door.
  2. Heartland Payment Systems (2008). A card payment processing company has suffered one of the largest data thefts in history — more than 100 million cards. One vulnerable SQL query became the entry point for a Trojan that had been recording data for months. The injection opened the door, and while it was not noticed, the data was already walking on the darknet.
  3. HBGary Federal (2011). The Anonymous hacktivists not only penetrated the system, but also posted employee emails to the public. The reason is a vulnerability in SQL on the site, which gave full access to internal databases.

These stories show that SQL injection is not hooliganism, but a weapon. And if the site is not secure, hacking is a matter of time.

SQL Injection And The Modern Internet

It seems that in the 20+ years since the first attacks, it would be time to put an end to this story, right? After all, we have HTTPS, frameworks, libraries… But no. SQL injections are still with us — and they are not even thinking of leaving.

  1. Firstly, the human factor. Someone was in a hurry with the deadline. Someone copied the old code. Someone didn’t realize that SELECT * FROM users WHERE login=’${login}’ is not just a string, but an open door. The more code there is, the higher the chance that someone has made a breach somewhere.
  2. Secondly, the Internet is growing faster than they have time to teach how to defend themselves. New websites appear every day. Small businesses, school portals, self-made CRM systems. And not everyone has the resources for a security audit.Third, the legacy. The sites are still running on 2005 engines. If no one updates them, the vulnerability remains.

Of course, large companies are increasingly using ORMs, filters, and injection protection at the library level. But the injection manages to seep into new projects like water in an old basement.

Misconceptions About SQL Injection

SQL injections seem to be so “from the past” that they are often judged through the prism of myths. Here are some popular misconceptions that make it difficult to see the real threat.

  • “This is a problem of the noughties, they don’t do that now.” Alas, they do. And even how. SQL injection is not a bygone era, but a reality for thousands of sites. Even the big ones. Even “modern” ones.
  • “Everything is on WordPress, so it’s protected.” Mistake. WordPress itself is not bad, but plugins, themes, custom forms can all contain vulnerabilities. One careless developer, and hello, SQL injection.
  • “HTTPS saves you from everything.” No. HTTPS is about an encrypted connection. It protects against MITM attacks, but it has no effect on what happens inside the request. If malicious SQL is passed in the form, encryption simply makes this malicious code… encrypted.
  • “We don’t have a database, so we won’t be hacked.” Even if the site does not store sensitive data, it can be used as an entry point to more important systems.

Myths are relaxing. But injections don’t.

SQL Injection Conclusioт: Not A Single Code

When a developer forgets to escape variables, it’s not because they’re bad, but because they’re tired, in a hurry, or haven’t completed training. When the customer requires the MVP “yesterday”, and the security “later we will add”. When an audit is a formality. When the logic is “yes, we don’t have anything important, they won’t touch us.”

It is important to remember that SQL injection protection is not just about code. This is an approach to development, culture, and common sense. This is the ability to question a string that “works fine.” This is respect for the data and for those who entrusted it.

SQL injection is not just a mistake. This is a litmus test of the maturity of the project. And ignoring it means agreeing that safety is not a priority. And then be surprised when everything “suddenly” leaks away.