A lecture on SQL injection attacks: how attackers exploit unfiltered input fields to read, modify, or delete database data, and the classic 'OR 1=1' and comment-based techniques. Covers defenses too.
Key Takeaways
- SQL injection arises when user input is concatenated directly into database queries without validation.
- Successful attacks can expose, modify, or delete sensitive data and disrupt services.
- Parameterized queries and strict input filtering are essential defenses.
- Error messages and detailed responses can aid attackers, so they should be controlled.
What the video covers
- Introduces injection attacks as among the strongest and most famous attacks against web applications.
- Explains that SQL injection exploits weak input validation, letting malicious input alter database commands.
- Describes consequences: unauthorized data access, data theft, modification or deletion, and denial of service.
- Cites statistics on the prevalence of such attacks in 2013, 2016 and 2021 as evidence of their severity.
- Explains why dynamic websites that build queries from user input are vulnerable.
- Walks through the attack flow: finding a vulnerable input, crafting a payload, and having the database execute it.
- Demonstrates basic payloads such as 'OR 1=1' to make a WHERE condition always true and retrieve all rows.
- Covers comment-based techniques using double dashes to truncate the original query.
- Discusses reconnaissance: using error messages to learn database type, table names and column names.
- Presents defenses: input filtering, parameterized queries, scanning tools, and runtime query checks as a last line of defense.
Chapters
- 00:00Introduction to Injection Attacks
- 01:50Consequences and Real-World Impact
- 03:52Why Dynamic Websites Are Vulnerable
- 07:03Attack Flow and Basic Payloads
- 11:03Crafting Malicious Queries and Comment Techniques
- 16:40Reconnaissance and Database Enumeration
- 26:40Detection Methods and Automated Scanners
- 35:00Defenses and Prevention Strategies
Full Transcript — Download SRT & Markdown
Speaker A
In the name of God, the Most Gracious, the Most Merciful. Welcome everyone to the fourth lecture of the fifth chapter.
Speaker A
We will talk about injection attacks. They are considered to be among the strongest, okay, the strongest types of attacks. Or among the most famous attacks that happen against.
Speaker A
We will talk in this section about, They naturally happen against whom? Against websites that are linked or hosted for us on the web. Alright.
Speaker A
So, an introduction to what? The It is a type of attack. It exploits the weakness in applying security and protection commands on the database. Alright.
Speaker A
What happens is the user enters incorrect data into my. And consequently, it results in It gets executed on the database. So it produces harmful data or harmful actions for us. Alright. We will see examples of them.
Speaker A
So it remains one of the strongest and most damaging ones existing where? In the attacks that occur on the network .
Speaker A
It exploits the vulnerabilities found in the database. Specifically in systems of . What does it do in input fields like a field or a field?
Speaker A
It enters wrong data, or rather, not exactly wrong data. It enters, alright, a set of symbols that it inputs. And consequently, it allows it to perform harmful acts through the databases. Such as, for example, taking what it is not
Speaker A
authorized to take. Or deleting from the database. Or modifying the database. Or displaying the data inside the database .
Speaker A
After this corrupted or rigged input arrives, what does it do? It proceeds to execute it on the server , and as a result, it either displays data not available to it, or it modifies data that it has no permission to access.
Speaker A
Well, it tells me in the year 2013 We had more than 94,000 requests to one site in 2013, in 2021 a wide, globally famous site.
Speaker A
Which is Alright. This is a global site, okay. Famous. It displays for us who? The risks. That are present globally. It said.
Speaker A
That it took third place globally among the top ten positions in. More than 35%of the ones present in the world in 2016 were hacked using.
Speaker A
It is considered one of the top two. Of the hacking techniques that existed in 2016. So how does it happen?
Speaker A
First of all, we have the as we said, it is related to whom? To the. So websites are not static pages . As long as they are not static pages, this means the data inside them is read from our databases. To read data from
Speaker A
our databases, I must access the database and create; it is created based on the existing page or based on what you entered, whether in search fields or input fields. Alright, as we said, modern ones are what?
Speaker A
Meaning they are not static pages, and consequently, it must take information from you and send it to whom? To the database. This data must eventually reach the database.
Speaker A
Our application server builds its, based on the data you provided, in order to communicate with whom?
Speaker A
With the database. To the database, then in that case, what does it do? You go and retrieve data based on whom? Based on the data you have collected. Right.
Speaker A
What are the goals and consequences of any successful attack? Attacks can make it possible to take a massive set of the data you have . Retrieve it for themselves.
Speaker A
And be able to benefit from it, either by blackmailing others, publishing your data, or exploiting it in one way or another.
Speaker A
Just like what happens on our websites. For example, it tells you that on such-and-such website, passwords and usernames were leaked. Other sites have had mobile numbers leaked. Other sites have had, for example, client accounts on that site leaked. And so on. Right.
Speaker A
The second type can do is modify the data within the database. Like a student who can hack the university website.
Speaker A
They can simply change their grades in courses and others. They might delete data. This is very dangerous.
Speaker A
That they can, by executing certain related commands. And in this case, the issue goes beyond just the database.
Speaker A
It becomes that they are able to control whom? The capabilities of the system we have. The fourth type is denial of service. I, quite simply, if my database crashes, my entire service cannot be displayed to people.
Speaker A
It tells me, what happens to my personal information? And well An attack becomes possible in three cases. What are the three cases? It says the first case is that I haven't filtered my data.
Speaker A
Or that I haven't—I mean, I want to say that when this field receives this, this field must be—the fourth field must be text, and so on, right?
Speaker A
The last thing is what? That I haven't done any—I can't remove it from there, and consequently, it causes us a problem, right?
Speaker A
What results from it? The first thing is they need to find a vulnerability. How do they find a vulnerability?
Speaker A
They need to probe your application to find a vulnerability, that this field enters from this place without any process being done.
Speaker A
After they manage to know where the vulnerability is on your site, they will send what?
Speaker A
Send to whom? To the Consists of whom? Consists of an input field, consists of text, consists of, right?
Speaker A
What will they do? They will direct it to the application, they will build it, and send it to whom?
Speaker A
To the database. After it reaches the database, it is executed from what you have.
Speaker A
Executed as an incorrect statement. What will happen for them? They will either get data they are not authorized to access, or delete your data, or modify your data.
Speaker A
Alright, then, after that happens, they return what—they build your result with the new data that came back, right? And the data then becomes, what, present for you? So, when we come to talk about how the attack happens? The first thing is
Speaker A
you need to find a vulnerability on your site right? I have a vulnerability on the site, that in such-and-such page, in the such-and-such, this field's data is not checked, it isn't—and when they send it , it isn't, right?
Speaker A
What do I do? We found it, so I go and write in it, like saying here "one equals one," for example.
Speaker A
Then it says "one equals one." Now, if the statement had a WHERE clause like "admin equals admin" and "password equals something," okay, I tell it...
Speaker A
Okay, I closed this, then I tell it " one equals one," and then what do I do to it?
Speaker A
Two marks like this. What does that mean he did? It means our WHERE condition is always true, so it will proceed. Well, what did he do? He sent it.
Speaker A
It reached the server, and the server, in turn, didn't check the data and sent it to whom?
Speaker A
The database built the query based on this, executed the query, and after it executed the query, then what? The site needs to rebuild the webpage from scratch, the webpage with the requested data.
Speaker A
It sent you the data you weren't authorized to access; it sent you all the data in the table, so now you have all the data.
Speaker A
That’s it, good job, all the data is yours. Okay. We have three things: we have the database, of course, and we have the attacker, and who else? The link between them. So we have the database, the attacker, and the link between them,
Speaker A
which is... Okay, the attacker will come and write statements. Okay, he will send them to whom?
Speaker A
The database will execute them and return data to me incorrectly, okay. He says the first thing I need to do is what?
Speaker A
Assume this is the statement. " ShipCity equals," followed by a comma like this, okay. He said plus who?
Speaker A
The "ShipCity" that comes from where? That comes from the input field we have here. Assume this input field hasn't had any filtering, and here is the single quote. He says the first thing we need to do is what?
Speaker A
We need to close it with this single quote, so my attack statement begins with what?
Speaker A
With a single quote. He also says at the end you now need to put who? Your command. Now what did I tell it? WHERE ShipCity equals a single quote. I can tell it my command is "OR one equals one
Speaker A
," or rather, who equals who? One. In this case, my query became "SELECT*FROM Orders table." He says the ShipCity, okay, opened its single quote, and I closed it with another single quote, " OR one equals one," so this became
Speaker A
always true, returning all orders located where? In the orders table. In this case, are we done? He says no, I have another single quote here that we haven't dealt with. If I don't get rid of it, what will happen? We will get an
Speaker A
error, so he says you need to make it what? An indicator, to end it, put the dash-dash. This dash-dash means what? It means that everything after these two symbols in the SQL statement is considered what?
Speaker A
It is a comment; don't execute it. Thus , you have a query built with what? With incorrect data or incorrect input, input containing malicious data, and consequently, he was able to take all the data you have in the orders table
Speaker A
without any filtering being applied to it okay. For example, we said that a normal user , as we mentioned a moment ago...Would write the city name like this, "Redmond ." Okay, that's the city name. So, what would the malicious user do?
Speaker A
He will tell me no, don't enter it like this. If the malicious user types this malicious input: Boston; DROP TABLE Orders; --, what will happen?
Speaker A
He will say the following: it's City, okay, it's Boston, okay, semicolon like this, which is this one after Boston, closing it, meaning the query is completely finished for us.
Speaker A
What did I tell him after that? I told him delete the table for me, put this, what will the meaning of the speech be?
Speaker A
Who will be stopped? The final dash, and thus, from the first query, he told me the city is Boston, and the second query deleted the table completely from the database we have.
Speaker A
Okay, who are the people related or who is the primary source for whom? For As we saw a little while ago, it's providing wrong data.
Speaker A
Okay. Okay, if it was stored in the data in the database without being cleaned, it will cause me a problem.
Speaker A
Okay, the third thing is what? Second-order injection, where the malicious data is already in our system , okay, it doesn't execute, but the attack happens later when this data is used. We will see examples of it, okay.
Speaker A
Well, what else do we have? He tells me via cookies, or what are cookies?
Speaker A
He says simply, we have for every browser. We have small bits of data when you visit every site. The data is stored in the browser. We call it something we call cookies. This data becomes your search preferences for the next visit to
Speaker A
the site. Through it, he comes and tells you, last time you visited one, two, three. It is also stored where? In the cookies. So I can inject the cookies in case the developer who built my site stored sensitive data in the cookies,
Speaker A
meaning I found username equals A, and I went and removed it and put admin, so he started treating me as an admin. This is through whom? Cookies.
Speaker A
The third thing, I can visit barcodes or RFID tags so that their content is, who is it?
Speaker A
Not numbers, but their content is SQL injection symbols, okay? So we have five avenues: user input, the environment variables, that Which is cookies, and we have physical user input, okay.
Speaker A
We have three types. I request from this page and it returns the data to me on this page. Okay.
Speaker A
Directly. Inference says I don't have direct access to the database. Okay, what happens to me?
Speaker A
I want to monitor the database behavior , get data from the first page, the second page, the third page, and the fourth page; I want to try to find the links between them, okay?
Speaker A
In case I managed to find the links between them, I was able to retrieve data and link data in an unauthorized way for me to access.
Speaker A
He says no, I have I send the data in, for example, an input to the database, it simply sends me an email.
Speaker A
I created and went and sent the data, it executed, it won't be displayed to whom ?
Speaker A
On the page, no, he says he will send it to me, for example, via email. Okay? So who is this? Out-of-band leaves us with three.
Speaker A
Which one is it? It is when the page I request returns the data within it.
Speaker A
Out-of-band: I request the page, but it won't return to me through another medium. The last point it mentions is that I will start performing an inferential attack.
Speaker A
I will start gathering data from the site until I can cross-reference data and form a complete picture of the database contents you have.
Speaker A
So, let's take the example of user input here. If you entered the user input with the name equal to empty like this, okay, and said "or 1 equals 1," and did this move , what would happen?
Speaker A
Quite simply, everything in the table will return to us, why? Because the username is equal to empty, or 1 equals 1; 1 equals 1 is always true, and "or true" is always true, so the result is always, what? True.
Speaker A
Right. For example, I want to bypass the password so it cannot verify me correctly, it cannot verify me, what, correctly? I mean, I want to give it the admin, and my admin is what?
Speaker A
The admin, which is the username "admin ," and I don't know the password, so I tell it "admin" and for the password, I give it, who? The code we have here, which is dash-dash or one equals one up
Speaker A
to here, so the result always comes out , what? True. Alright. In an "in-band attack," I must end the line I am working on.
Speaker A
If you don't do this, your query that you tried to breach might not execute.
Speaker A
Either because of other conditions you aren't aware of, or because the SQL syntax itself becomes incorrect. And thus, we will have a problem.
Speaker A
So you must always, you must use comments. Okay, and for example, we said who?
Speaker A
And so it always happens that anything after these double dashes is what? It says in this case, the user isn't satisfied with just modifying the original query, but what do they do?
Speaker A
They go and add a completely new query to it. This new query is appended to the original query. And thus, it asks the project to do something else, for example, I want to add a semicolon. And after the semicolon, I tell it, so what
Speaker A
will happen? What will happen, quite simply, is what? Deleting entire data from the database.
Speaker A
After I finish. The original one we know and trust, what should I put at the end?
Speaker A
What does the semicolon mean? That I have finished the normal one and I want to start, who? The new one, I write the new one, and of course at its end, in this case, what will happen? Both will
Speaker A
be executed, both are what? They will be executed. So when does this happen? If my server can execute more than one, we can control the server settings and tell it , no, always just one, and thus I can
Speaker A
protect the server in this case. I can execute additional ones. It is an example of...it is an example of who? Of the...well.
Speaker A
The inferential attack. I am writing what is incorrect, okay. Or improper uses, or queries that are logically incorrect on purpose. Why?
Speaker A
Because the application server, after I give it an incorrect or wrong query, might return a message. From that message, I can know, for example, the type of database, or the names of the tables. I might know the column names
Speaker A
from it. I might know the parameter names from it. Consequently, in the next step, I will be able to write code to breach this data directly.
Speaker A
Without getting into the complexities of what type. Of database it is. Trying once for this and once for that.
Speaker A
No. I give you a wrong query. It will cause you a problem. You will return an error message to me. Saying, for example or.
Speaker A
And this is the type of error. Or this is the type of error. As soon as it tells me, I know it is or.
Speaker A
I know who it is. Well, I know the type . Sometimes it might also tell me that in table number. Such and such, you have this problem, and thus I also know the table name.
Speaker A
I might know the column names, and then I can write a second statement. What does it do? Breach this? So, what happens?
Speaker A
I write a wrong message to get the database type, the database's, or any. Any, which is weak, or that I am able to breach. Okay, what is the goal after that? The goal is for me to gather data
Speaker A
about your database, and its. So I can build, in the next step, something accurate and customized for the database.
Speaker A
So, we have what is called an inferential attack. Sometimes my website might be fully protected, and thus I cannot know anything about my database, so my attack will be a blind attack. So what do I do? What is the benefit of the
Speaker A
inferential attack in this case? The benefit of an inferential attack in this case is that I want to see how the page behaves, whether it acts correctly or incorrectly with the data. For example, I want to ask it: does the
Speaker A
admin's name start with the letter A? If the page behaves in a way that is.
Speaker A
Normally, it means I know it starts with the letter A. Okay, does it start with the letter B?
Speaker A
If it behaves incorrectly, it means I know it does not start with the letter B. So when do I use the inferential attack?
Speaker A
Sometimes the inferential attack does not give me data about the database I have, and it doesn't give me data about the database structure, so I cannot infer the database itself.
Speaker A
However, I want to infer information inside the database. Sometimes I can exploit it through a blind SQL injection and monitor the application's behavior.
Speaker A
If the page worked normally, it means the inference I injected was correct. If it didn't work correctly, it is possible that the inference I injected or the statement I gave it is. Incorrect .
Speaker A
Of course, this process is long and is usually automated so that the SQL injection is carried out through an automated process, allowing me to collect as much data as possible, alright.
Speaker A
Okay. We said I will be the sender through which I take the data via another channel like email or otherwise, okay?
Speaker A
It depends It depends on the fact that it already has the ability to send emails, okay?
Speaker A
Or otherwise, and therefore I, as the attacker, send the request through the SQL channel itself; it receives the data from me and sends the data through another channel.
Speaker A
Of course, when does the user resort to this type of attack? When retrieving data directly from the application page is limited or impossible, so the success of the attack depends on what? The database server's ability to establish an outbound connection, such as making
Speaker A
the database that we have send data or emails, and so on. How do we protect it? He tells me it is very necessary that I protect the database I have very well from unnecessary outgoing connections, is that clear?
Speaker A
Meaning, my database is forbidden from connecting, for example, to anything other than the backup server.
Speaker A
It is forbidden to connect to, say, or any external server, so I also need to set limits on what they can reach.
Speaker A
And what countermeasures do we have to control our system and prevent this? He tells me that its damages are very many and varied, and this is not enough , so we need an integrated set to protect our database, starting with the
Speaker A
first thing. I want the person who writes the code or our programmers to prevent it in their code; they should perform checks on incoming data, and if there is any problem, they should block it from reaching the database.
Speaker A
The same thing, they should do what? For whom? For those entering the database; I tell it this field accepts only numbers, this field accepts only dates, and so on, so that I prevent any incorrect data from entering the database. The second thing
Speaker A
. That I always find, I always want to create and detect any attempts, if there are attempts on the site, that means there is a vulnerability here and he is trying to exploit it, so I want to have
Speaker A
been doing it for any attempt on my database, I want to try at the first time and do what?
Speaker A
Or from the very first time an attempt to exploit it is made, so I can block access to the database. The third thing .
Speaker A
I want to do something similar to a sandbox; what does sandbox mean? That is an isolation system.
Speaker A
I want to perform a check during the execution process. I want to see if the returned results are as expected or not . Meaning, my SQL statement, my login, originally returns either one row or no rows okay?
Speaker A
Well, if I find 100 or 200 rows returned , that means there is a problem, and therefore during runtime, I want to check this, okay?
Speaker A
Which is who, the first step, the first thing to do Coding, and the second thing to do The first thing to do is work on the input fields coming to me from the web; I mean, my site is taking the data
Speaker A
fields coming in, I want to work on them , I want to ensure the type of data coming to me, I want to ensure that the numbers are coming as numbers and contain only numbers.
Speaker A
I want to use it for what? I mean, the date should originally come to me in a certain format, so I want to check that the date arrived in that format, and the mobile number must come in a certain format, so I must check
Speaker A
that the mobile number arrived in the required format. So, the first thing that falls on the developer's shoulders is to validate the data coming from the web, to check the data types, to ensure, for example, that the numbers contain only digits, and to
Speaker A
ensure they perform what is required to verify if this data is coming in the required order or not, okay. The second thing they need to do is Of course, for this first point, I haven't reached building the database
Speaker A
query statement yet, I haven't reached who yet? To building the SQL that I send to the database; it says, no, my SQL statement , when I want to build it, I want to build it in a Okay.
Speaker A
I want in a separate way, so the data that wasn't cleaned, which came from here, cannot modify my statement, it cannot modify my statement, okay.
Speaker A
Which is a set of. It allows me automatically. Automatically to check what is coming to me.
Speaker A
And do something for anything I don't have. Okay, for anything that might cause me problems, like, for example, that Okay, meaning that this field only takes , it only takes this field, this field This field, for example, is, this field
Speaker A
is, okay, it's there and ready so that I can define the data types I want to check, instead of the programmer having to write the query every time and concatenate strings manually.
Speaker A
Okay. Why do we use it? To do And thus, it gives me a secure and reliable way to access the database, its most important features Okay, for example, and at the [ parameter], I tell it who? The first one
Speaker A
, no, I put dots here, one, two, three, or I put a question mark depending on the type I'm using, the [parameter] I'm using, and then I go and pass it who?
Speaker A
I pass it, which is I pass it our [data ] okay? It's a set available to us to do; what is the reason we used it and didn't rely on what is Because it says sometimes programmers are lazy to write the entire validation
Speaker A
statement, so I'll make you use the [ parameterized queries], or sometimes we call it the [parameterization] process, okay?
Speaker A
How can I discover that we have an [SQL injection] or What are the ways to detect that we have an [SQL injection]?
Speaker A
The first is, the second is, and the third is. The first is signature-based, my [IDS] what does it do?
Speaker A
It compares attack patterns, I have all the attack patterns, the texts coming on [URL] and on whom?
Speaker A
Which is [SQL], okay? So I always want to do what? Anything that comes containing these two , this is actually an attempt at what is who?
Speaker A
Modifying or hacking our database. So anything that comes and goes to the database with a "equals equals" or "one equals one," that means I have to go check and verify this.
Speaker A
The second, the second thing I want to define what is expected from my site, and anything other than this, I will consider it what?
Speaker A
That it is things that are what? Harmful to our site. I want to define the acceptable behaviors for accessing the site, and then any behavior not included in those trained models will be considered malicious and denied access.
Speaker A
The second type focuses on any anomalous patterns that are not among those already defined for the site; that's the third method.
Speaker A
These are programs or integrated solutions that scan my site, trying to perform a penetration attempt everywhere ; if any attempt succeeds, it alerts me to a problem here; if none succeed, it says everything is fine, is that clear?
Speaker A
I know we won't be using those types of sentences. The double dash or the "one equals one" —it tells me if I see one, two, or more of these in the incoming input, it means I've detected an attempt to modify the
Speaker A
database, so stop the execution process . The second type. I determine the positive behaviors or the behaviors.
Speaker A
Authorized to access the database; any behavior other than these I will consider an anomaly or malicious, and I will block it from reaching the database .
Speaker A
The third thing is that I will use specialized tools to test my site against all possible scenarios in all possible locations to discover any potential security breach, okay?
Speaker A
What does this tell me? This is the last line of defense. The SQL check during execution is considered our last line of defense.
Speaker A
Check them all. Based on the first one I received. This should ideally always return one row; if it returns more than one row, it means there is a problem here.
Speaker A
I must perform a comparison; if I compare and the count is more than one row returned, it means there is a problem, and it means I must halt the execution process, okay, I must halt the execution process.
Speaker A
The task of the last line of defense is to prevent. It is the runtime check at the moment of execution, by comparing every query to the expected ones; it checks each query based on this, and if they match, it's
Speaker A
fine; if they don't, we have a problem and I must block the execution. In other words, I am always expecting.
Speaker A
The sentence is correct because I expect this, so if I receive a sentence that was generated and it contained something other than what was expected, the basic structure has been modified, meaning we have a problem.
Speaker A
We talked about the fact that it is an attempt to hack into websites to steal, modify, or delete data without having the authority to do so.
Speaker A
The related entities could be. Or. Like any regular input operation on the site, such as server-side ones, they are stored in what we send; I might send you data that currently won't cause problems , but if it is requested in one way or
Speaker A
another, it will cause problems. The result is not seen immediately; these are variables stored in the browser related to your behavior, your data, and identifying who you are to the site every time you send something.
Speaker A
And the last thing is that I want to make something like an input or others, I want to include data in it that causes you problems if it reaches whom? The database. The types we mentioned are The we said I send in and receive on the
Speaker A
same the second type is inferential, I do not access the data completely but what I get is where?
Speaker A
That it is normal data, okay? I take two columns from the table from the first query, two from the second, two from the third, and two from the fourth until I can build a complete model of the database you have.
Speaker A
I send to you, but you do not send the response on the same page; you send it via email or otherwise.
Speaker A
We must do We said there is no point in using only one protection technique; I need more than one technique to protect data via or and The will be caused by the fact that I will have the programmer required to
Speaker A
write strong code that checks the before executing it; I am required to build a system that checks if this is actually within the known scenario or not?
Speaker A
I will have to compare: did it match or did it not match? If it matched, I let it execute; if it did not match, I prevent it from the execution process. With that, we have finished 5.4; we will continue, God
Speaker A
willing, in the next lecture with 5.5. Thank you all.
Topics:SQL injectiondatabase securityweb securityinput validationinjection attacksOR 1=1parameterized queriespenetration testingdata center securitycybersecurity lecture











