SQL Injection | Complete Guide — Transcript
Full transcript
- 0:01hi everyone welcome back to another
- 0:03video in the web security academy series
- 0:06in today's video we'll be discussing the
- 0:08theory behind sql injection
- 0:10vulnerabilities
- 0:12this video is pretty much a brain dump
- 0:13of everything that i consider to be
- 0:15fundamental knowledge when it comes to
- 0:17sequel injection attacks and so it's
- 0:19going to be a long one
- 0:20so if you're only interested in a
- 0:22specific topic related to sql injection
- 0:24then i would recommend
- 0:26going to the description and checking
- 0:28out the timestamps that i have mapped
- 0:29out to the different topics that i cover
- 0:31in this video
- 0:33okay let's get started we'll start off
- 0:36with describing what a sequel injection
- 0:38vulnerability is
- 0:39and the technical details behind this
- 0:41category of vulnerabilities
- 0:43so in this section we'll discuss topics
- 0:46like
- 0:47what are sql injection vulnerabilities
- 0:49what are the different types of sql
- 0:50injection vulnerabilities
- 0:52how common are sql injection
- 0:54vulnerabilities and so on
- 0:56next we'll cover how to find sql
- 0:58injection vulnerabilities from both the
- 1:00black box
- 1:01and the white box perspective so if
- 1:03you're given
- 1:04an application and possibly even the
- 1:06source code of the application
- 1:08how would you approach testing the
- 1:10application in order to determine if
- 1:12it's vulnerable to sql injection
- 1:16in the third section we'll cover how to
- 1:18exploit sql injection vulnerabilities
- 1:22so imagine you're testing an application
- 1:24and you discover
- 1:25that one of the input vectors or one of
- 1:28the
- 1:28parameters is potentially vulnerable to
- 1:30sql injection
- 1:31in that case how do you go about
- 1:33exploiting that vulnerability
- 1:35in order to gain access to sensitive
- 1:37information or even potentially gain
- 1:38remote code execution
- 1:40on that server
- 1:44last but not least now that you have
- 1:46successfully found and exploited a sql
- 1:48injection vulnerability
- 1:50what recommendations can you give to the
- 1:52client in order to remediate the
- 1:54vulnerabilities that you found
- 1:57so in this section we'll cover the
- 1:58different techniques that you can use to
- 2:00prevent sql injection vulnerabilities
- 2:03okay let's start off with the first
- 2:05section what is sql injection
- 2:08sql injection is a vulnerability that
- 2:10consists of an
- 2:11attacker interfering with the sql
- 2:13queries that an application makes to the
- 2:15backend database
- 2:17so if you as an attacker can manage to
- 2:19interact and change the sql query
- 2:21by adding sql characters or sql code
- 2:24in an input vector of an application
- 2:27then the application is definitely
- 2:28vulnerable to sql injection
- 2:30now to better understand this let's take
- 2:33an example
- 2:34imagine you have an attacker a web
- 2:37server
- 2:37and a database the application that the
- 2:40web server hosts has an authentication
- 2:42functionality where the user has to put
- 2:44in their
- 2:46username and password and once the
- 2:49username and password
- 2:50are put in equity is made to the
- 2:52database to see if this username and
- 2:54password
- 2:54are in the database and if they are then
- 2:57the user is presented with
- 2:58uh his or her profile page if the user
- 3:02enters an incorrect username or password
- 3:04then the user is presented with an error
- 3:06message that says
- 3:07you have entered an incorrect username
- 3:09or password
- 3:11so in this case we clearly have two
- 3:13input vectors the username field and the
- 3:15password field a talk to the backend
- 3:17database so they get included in a query
- 3:19in the backend database
- 3:21and so we definitely need to test these
- 3:23input vectors
- 3:24for a sql injection vulnerability to see
- 3:26if that input
- 3:27is validated in any way
- 3:31so let's see what an attacker can do in
- 3:33this case
- 3:34what an attacker is doing is in the
- 3:36username field instead of just adding a
- 3:38username
- 3:39the attacker adds the username admin the
- 3:42account that the attacker wants to
- 3:44compromise but then the attacker also
- 3:47adds some sql characters
- 3:49after the username so add single quote
- 3:53and then add double dash which stands
- 3:55for a comment
- 3:57so what happens is that
- 4:00this username gets included in a query
- 4:03so what the query does
- 4:04at the back end is it says select star
- 4:06from users so select all the entries
- 4:08from the users table
- 4:10where username is equal to whatever
- 4:12username is put in here
- 4:14and password is equal to whatever
- 4:15password is put in here
- 4:18now if this input is properly validated
- 4:21and we'll talk about that
- 4:22in the next couple of sections if this
- 4:25input is properly validated then the
- 4:27database will literally look for a
- 4:29username
- 4:30that is equal to admin dash admin code
- 4:34dash dash in the database
- 4:35and it won't find one because no one has
- 4:37that username and so the attacker would
- 4:39be presented with
- 4:40an incorrect username or password
- 4:44um however if this application is
- 4:47vulnerable to sql injection so it
- 4:49doesn't use parameterized queries it
- 4:51doesn't validate
- 4:52user input then what will happen is that
- 4:55any sql characters or sql code that the
- 4:58attacker adds as part of the payload
- 5:00will become part of the query and so in
- 5:02this case what's happening
- 5:03is select star from users so select the
- 5:06entries from the users table
- 5:07where username is equal to admin the
- 5:10single quote over here that the
- 5:12attacker included closes the string or
- 5:14the username
- 5:16and then the double dash stands for a
- 5:18comment and so it says comment out the
- 5:20rest of the query
- 5:22and so what happens is the query becomes
- 5:25this so select
- 5:26all the entries from the users table
- 5:27where username is equal to
- 5:30admin now admin is an existing username
- 5:33in the database
- 5:34and so what happens is that the database
- 5:37will return the admin user profile
- 5:39and the attacker gets logged in as the
- 5:41admin user
- 5:42so essentially what happened over here
- 5:45is that the attacker
- 5:47exploited a sql injection vulnerability
- 5:49in the login functionality of the
- 5:51application
- 5:52in order to bypass authentication so in
- 5:54this case the attacker no longer needed
- 5:56to know the admins password
- 5:58because the attacker was able to change
- 6:00the query to no longer
- 6:02ask for the admins password so that's
- 6:04one
- 6:05example of how you could use uh sql
- 6:07injection vulnerabilities
- 6:09in order to um in order to bypass
- 6:12authentication
- 6:13on login functionality now let's talk
- 6:16about
- 6:16what are other impacts of sql injection
- 6:20attacks
- 6:20and the real answer to this is that it
- 6:23really depends on the context
- 6:24of the sql injection that you're
- 6:26exploiting so some sql injection
- 6:28vulnerabilities will only allow you to
- 6:30view data
- 6:31whereas others will allow you to
- 6:32actually modify data
- 6:34so when i was coming up with this slide
- 6:36instead of listing the infinite
- 6:38number of things that you could do to
- 6:40applications with sql injection
- 6:42vulnerabilities
- 6:43i instead decided to just compare it to
- 6:45the asea triad
- 6:46so how it affects confidentiality
- 6:49integrity
- 6:50and availability so in terms of
- 6:52confidentiality
- 6:53some sql injection vulnerabilities will
- 6:55allow you to view sensitive information
- 6:57such as usernames
- 6:58and passwords so the application's
- 7:00username and password
- 7:02and that's an example of how you impact
- 7:05the confidentiality
- 7:06of an application by accessing
- 7:08information that you shouldn't
- 7:10have access to in terms of integrity
- 7:13some sql injection vulnerabilities will
- 7:15allow you to alter
- 7:16data in a database and an example of
- 7:19that
- 7:19that i exploited not too long ago is an
- 7:22application that allows you to
- 7:24update an email address and so because
- 7:27this was vulnerable to sql injection
- 7:29i was able to update another user's
- 7:31email address
- 7:33to one that i control and so uh what i
- 7:36did
- 7:36is because i control this email address
- 7:38i reset the password
- 7:40of the user and the reset token was sent
- 7:42to the email address that
- 7:43i own and so i hijacked the user's
- 7:46account and that's an example of how to
- 7:49effect the integrity of the application
- 7:51because you were able to alter data that
- 7:53you shouldn't
- 7:54have otherwise been able to alter it
- 7:56also affected the availability
- 7:58of the application because i denied when
- 8:00i reset the user's password i denied
- 8:03access to the user's account
- 8:07and so i affected the availability of
- 8:09the application
- 8:12and of course in certain scenarios sql
- 8:15injections could actually lead to remote
- 8:17code execution
- 8:18on the operating system and that affects
- 8:20confidentiality integrity
- 8:22and availability all at once and you
- 8:25would gain
- 8:26access to the operating system with the
- 8:28same privilege that the database is
- 8:30running with
- 8:30and so you got to be very careful in
- 8:32terms of
- 8:33making sure that the database runs with
- 8:36the least privilege
- 8:36possible and we'll discuss that in the
- 8:39last section
- 8:40when we're talking about things like
- 8:42defense in depth
- 8:43and how to prevent sql injection
- 8:45vulnerabilities
- 8:47okay so um we talked about the impact
- 8:50of sql injection vulnerabilities now the
- 8:53question
- 8:54is how common and how critical are sigma
- 8:57injection vulnerabilities
- 8:59and one way to measure that and it's not
- 9:01bulletproof is the
- 9:02awasp top 10 list so for those of you
- 9:06that have never heard of the oas top 10
- 9:08project
- 9:09it's essentially the list of top 10 most
- 9:12critical
- 9:12security risks to web applications it's
- 9:15updated every couple of years so you
- 9:16could see over here i've got the 2010
- 9:18list
- 9:19the 2013 list and then the 2017 uh
- 9:22list i believe 2020 is in the works so i
- 9:26think it was submitted but has not been
- 9:28approved yet but i could be wrong so i
- 9:30think
- 9:302017 is the latest one that we have
- 9:32right now and you'll notice over here it
- 9:34does change across the years so you've
- 9:35got cross-site scripturing
- 9:37was the second most critical risk to web
- 9:40applications in 2010
- 9:43and then it it became the third most
- 9:46critical risk in 2013
- 9:49and then it dropped all the way to uh
- 9:51the seventh most critical risk
- 9:53in 2017 and you'll see some of them
- 9:56completely disappear
- 9:57so insufficient transport layer
- 9:59protection was number nine
- 10:01of most critical risks in 2010 but that
- 10:04but it completely disappeared in 2013
- 10:06and 2017
- 10:07um and that's probably because it's so
- 10:09easy to now get certificates
- 10:10and use https on your side even
- 10:13malicious sites use https right now so
- 10:15it's definitely
- 10:16um not a risk anymore but then you see
- 10:19also new ones get added so
- 10:21for example insecurity serialization
- 10:23over here
- 10:24was never a risk in 2010 or 2013 was not
- 10:27part of the list
- 10:28and in 2017 it became part of the list
- 10:32now for sql injection vulnerabilities
- 10:35they fall
- 10:36under the first most critical risk
- 10:39to web applications so they fall under
- 10:42the injection category however it's
- 10:45worth
- 10:46mentioning that this covers all of
- 10:48injection vulnerabilities not just sql
- 10:50injection vulnerabilities
- 10:52in fact uh the likelihood of sql
- 10:54injection vulnerabilities
- 10:55existing in applications has decreased
- 10:58across the years for many reasons and
- 11:00we'll discuss that in the last section
- 11:02when we discuss how to prevent sql
- 11:03injection vulnerabilities
- 11:05nevertheless um it is still a critical
- 11:08risk
- 11:08because as we saw in the
- 11:11past couple of slides if you do have
- 11:14even just one parameter that is
- 11:16vulnerable to sql injection it could
- 11:18potentially lead to
- 11:20remote code execution on the server so a
- 11:22full compromise of the underlying server
- 11:25all right so in the past couple of
- 11:27slides we got a high level overview of
- 11:29what sql injection vulnerabilities are
- 11:32now we're going to go at a more granular
- 11:34level and talk about the different types
- 11:36of sql injection
- 11:38sql injection vulnerabilities can be
- 11:40classified into three
- 11:42major categories the first is in bend
- 11:45or classic sql injection the second
- 11:48is inferential or blind sql injection
- 11:51and the third is out-of-band sql
- 11:54injection
- 11:55now in-band or also known as classic
- 11:58sql injection vulnerabilities are ones
- 12:01where the attacker
- 12:02uses the same communication channel to
- 12:04both launch
- 12:05the attack and gather the results of the
- 12:07attack if that doesn't make much sense
- 12:09to you that's okay
- 12:10don't worry i actually have a couple of
- 12:12slides explaining each type in detail
- 12:15right now i'm simply giving you a high
- 12:17level overview of what each type is
- 12:20now inbend or classic sql injection is
- 12:23divided into two types
- 12:25error-based sql injection and
- 12:26union-based sql injection
- 12:28error-based sql injection is a technique
- 12:30where you force the database
- 12:32to generate an error giving you more
- 12:34information about how things
- 12:36operate at the back end so an example
- 12:39would be if you have a parameter that is
- 12:41vulnerable to sql injection
- 12:43and then you put into that parameter a
- 12:45single quote and that breaks the backend
- 12:47query which generates
- 12:48um an error at the application level and
- 12:51so
- 12:52what happens is that the error tells you
- 12:54things like
- 12:55uh the version of the database so the
- 12:57type of database that they're using at
- 12:59the backend
- 13:00the version of the database and
- 13:02sometimes the
- 13:03error will also tell you the exact sql
- 13:05query that is being used at the backend
- 13:07and this would make your life so much
- 13:08easier because if you know the exact
- 13:10query you don't have to guess it using
- 13:12trial and error
- 13:13and this way you could just build your
- 13:15sql payload so that's an example of
- 13:17error-based sql injection for union
- 13:20based sql injection it's a technique
- 13:21that leverages the union operator to
- 13:24combine the results of two queries into
- 13:26a single result set
- 13:27so in this technique you don't just
- 13:29output the result of the original query
- 13:31that the application
- 13:32makes but you also output the result of
- 13:34a query of your choosing
- 13:36and of course something that you would
- 13:38be interested in is
- 13:39uh for example the usernames and
- 13:42passwords of the users of the
- 13:43application
- 13:44so you would use the union operator to
- 13:46output
- 13:48the credentials of the users of the
- 13:50application and again we'll see examples
- 13:52of that in the next coming
- 13:54slides the next category which is
- 13:57inferential
- 13:58or also known as blind sql injection in
- 14:01this type of vulnerability there's no
- 14:03actual transfer of data
- 14:05via the web application so you don't see
- 14:07the results
- 14:09in the application itself instead you're
- 14:11stuck asking the application true or
- 14:12false questions
- 14:14which is what boolean base sql injection
- 14:16is
- 14:17or causing the database uh to pause for
- 14:20a specified period of time
- 14:22which is time-based sql injection in
- 14:24order to determine if what you're asking
- 14:26the application is correct or not
- 14:28obviously the way you exploit to blind
- 14:31sql injections is more difficult
- 14:33than classic sql injections however uh
- 14:36the
- 14:36impact even if you're not seeing the
- 14:38results right away in your application
- 14:40the impact of exploiting the
- 14:41vulnerability is still as bad as
- 14:44in bend or classic sql injection and
- 14:46we'll see examples of that in a bit
- 14:48okay the third and last category
- 14:51is out-of-band sql injection this occurs
- 14:54when the attacker is unable to use the
- 14:56same channel to launch the attack and
- 14:58gather the results of the attack
- 15:00it usually relies on the ability of an
- 15:02application
- 15:03to make a network connection so for
- 15:05example a dns
- 15:06or http request to deliver data to an
- 15:09attacker
- 15:11i've seen people loop this type of sql
- 15:14injection
- 15:15under inferential or blind sql injection
- 15:19which is a fair thing to do however
- 15:22if you look at resources online most of
- 15:24the resources out there will separate
- 15:26them into uh three different categories
- 15:28and that's why i decided to also
- 15:30separate them into
- 15:31three different categories in my video
- 15:34okay let's go more in depth about each
- 15:37type starting with
- 15:38in-band or classic sql injection
- 15:42we talked about in-band sql injection
- 15:45vulnerabilities
- 15:46occurring when the attacker is able to
- 15:48use the same communication channel
- 15:50to both launch an attack and gather the
- 15:52results of an attack
- 15:54so to put this in plain simple english
- 15:57if you exploit a sql injection
- 15:58vulnerability by sending a sql payload
- 16:01in one of the fields of an application
- 16:03and then you see the result
- 16:04of your sql payload presented directly
- 16:07to you
- 16:07in the application then this falls under
- 16:09the
- 16:11category of in-band sql injection now
- 16:14uh just by the nature of how this
- 16:17specific type of vulnerability works
- 16:19it's much easier to exploit than other
- 16:21categories of vulnerabilities
- 16:23and the reason behind that is because
- 16:25you actually see the result of your
- 16:27attack in the response of the
- 16:28application versus having to infer the
- 16:31result like you would have to
- 16:32in a blind sql injection again we said
- 16:35that there's two types of
- 16:37in-band sql injection error-based sql
- 16:39injection
- 16:40and union-based sql injection and we'll
- 16:43start off with error-based sql injection
- 16:46error-based sql injection is an in-band
- 16:49sql
- 16:50injection technique that forces the
- 16:52database to generate an
- 16:54error giving the attacker information
- 16:56that could potentially
- 16:57aid in developing the injection payload
- 17:00so
- 17:00let's take an example imagine you have
- 17:03an
- 17:04application www.random.com that has an
- 17:07id parameter that is vulnerable
- 17:09to sql injection in this case we're
- 17:12putting a single quote in the id field
- 17:14and because that is a sequel character
- 17:16and this is vulnerable to sql injection
- 17:19that single quote will become a part of
- 17:21the query and so
- 17:22it'll break the backend query and it'll
- 17:25output an error and an example error
- 17:27is you have an error in your sql syntax
- 17:29check the manual that corresponds to
- 17:31your mysql server version
- 17:33blah blah blah so in this case it tells
- 17:35you that you're using mysql
- 17:37that's good information to know it might
- 17:39also tell you the version
- 17:40and again in certain scenarios the error
- 17:42might also give you the query that
- 17:44happens when you
- 17:45put an id parameter so what's happening
- 17:47when um
- 17:49you put for example an integer in the id
- 17:51parameter
- 17:52uh the exact query that happens uh at
- 17:54the back end and this way if you have
- 17:56the exact query it's so much easier for
- 17:58you to develop your payload versus
- 18:00sending a bunch of requests to the
- 18:01um the application in order to determine
- 18:04what the payload is
- 18:06and so this is in-band sql injection or
- 18:09classic sql injection because you see
- 18:11the output of your sql injection right
- 18:13there in the application
- 18:15and it's error-based because the idea is
- 18:18that you
- 18:19put an error in the application
- 18:22next we have union based sql injection
- 18:26union based sql injection is a type of
- 18:29in-band sql injection technique
- 18:31that uses the union sql operator to
- 18:33combine the results of two queries into
- 18:36a single result
- 18:37set again i mentioned in the previous
- 18:39couple of slides
- 18:40that i don't want to output just the
- 18:43result of the original query
- 18:45i want to output a query of my choosing
- 18:48and if an application is vulnerable to
- 18:51union based sql injection then i get the
- 18:53ability to
- 18:54output the result of a query of my
- 18:56choosing and combine it with the
- 18:58original
- 18:58query that the application is with the
- 19:01result of the original query that the
- 19:02application is making
- 19:04let's take an example you have your
- 19:06application www.random.com it has an id
- 19:10field that is vulnerable to a union
- 19:13based sql injection
- 19:15and if you put in a valid id then the
- 19:17page will display all the products that
- 19:19are associated to that id
- 19:22now instead of just displaying the
- 19:24products associated to a specific id
- 19:26i want to output the results of another
- 19:28query and in this case the query is
- 19:31select the username
- 19:32and the password from the users table so
- 19:35output all the usernames and passwords
- 19:37from the users table and then comment
- 19:39out the rest of the query
- 19:41so in this case it will
- 19:44output the results of this query over
- 19:46here we didn't put an id
- 19:47and so that would be empty and then
- 19:49it'll combine it with the results of
- 19:50this query over here which is the
- 19:52username
- 19:52so carlos an administrator and the
- 19:54passwords of the
- 19:56users in the users table now
- 19:59of course the union operator has certain
- 20:01conditions for it to work and so it's
- 20:03not as simple as hey i'm going to output
- 20:05whatever i want
- 20:06in as many fields as i want um it's
- 20:09it's not the case instead there are
- 20:11certain conditions that you have to
- 20:12follow and we'll discuss that in
- 20:14the exploitation section of this video
- 20:18okay so that covers in-bend or classic
- 20:21sql injection
- 20:22next let's talk about inferential or
- 20:24blind sql injection
- 20:27inferential or blind sql injection is
- 20:30a sql injection vulnerability where
- 20:32there's no actual transfer of data via
- 20:34the web application
- 20:36so unlike in-band sql injection where we
- 20:39directly saw the output of the sql
- 20:41injection displayed for us in the
- 20:43application
- 20:44in the case of blind sql injection the
- 20:46database does not
- 20:47output data to the web page and so this
- 20:50forces the attacker to steal
- 20:52data by asking the database a series of
- 20:54true and false questions
- 20:55and then determining based on how the
- 20:58application responds
- 21:00whether uh whether the application
- 21:02responded with yes this is a true
- 21:04statement versus no this is not a true
- 21:06statement
- 21:07um and again uh this will become more
- 21:09clear once we discuss the different
- 21:11types of
- 21:11blind sql injection and we take uh
- 21:14examples
- 21:15uh now just because an attacker can't
- 21:17directly display data from the database
- 21:18that doesn't mean that this is a
- 21:20harmless vulnerability
- 21:21like i said in the previous slides in
- 21:23fact it's just as dangerous as embedded
- 21:25sql injection
- 21:26because you can extract information from
- 21:28the database by ex
- 21:30by asking true and false questions it's
- 21:32just that this type of vulnerability
- 21:33takes a little bit longer and a little
- 21:36bit more skill set
- 21:37in order to exploit
- 21:42okay and we said there are two types of
- 21:44blind sql injection boolean based sql
- 21:46injection
- 21:47and time based sql injection let's talk
- 21:50about
- 21:51boolean based sql injection
- 21:54boolean based sql injection is a blind
- 21:57sql injection technique that uses
- 21:59boolean conditions to return a different
- 22:01result set
- 22:01depending on whether the query returns
- 22:04true or
- 22:05a false result so in simple english
- 22:08again the attacker sends different sql
- 22:10payloads that ask the database
- 22:12true and false questions and depending
- 22:14on the how the database responds then
- 22:16you could infer whether the data
- 22:17responded
- 22:18the application responded with true or
- 22:21false
- 22:22this is sometimes referred to as content
- 22:24based blind sql
- 22:25injection so you'll see those two terms
- 22:28used uh
- 22:29interchangeably now let's take an
- 22:32example so that this becomes
- 22:34a little bit more clearer imagine again
- 22:36you have an application www.random.com
- 22:40and it has an id parameter that is
- 22:43vulnerable to a blind sql injection
- 22:45and imagine in this case you can't
- 22:47simply use the union operator to output
- 22:50data in the database like we did
- 22:52with union union-based sql injection so
- 22:55in this case what you can try
- 22:56uh to test if the field is vulnerable to
- 22:59sql injection
- 23:00is first inject it with a false payload
- 23:02so force a payload that you know is
- 23:04false
- 23:04and then see how the application
- 23:06responds and then force a payload that
- 23:08you know is true
- 23:09and see how the application responds and
- 23:11if the application responds
- 23:13differently in the false payload versus
- 23:15the true payload then this is
- 23:17uh vulnerable to boolean based blind sql
- 23:20injection
- 23:22so let's take the backend query so
- 23:24imagine over here
- 23:26when you enter an id number
- 23:29the query this is the query that happens
- 23:31at the backend so select the title
- 23:34from the product table where id is equal
- 23:36to one and because id is equal to one is
- 23:38a valid id in the table
- 23:40the application will display the title
- 23:44of the products that are associated to
- 23:46id1
- 23:48now if we want to force a false
- 23:51payload what we can do is we could use a
- 23:54conditional statement
- 23:55and one is equal to two so the back end
- 23:58query would be select the title
- 24:00from the product table where id is equal
- 24:02to one and one is equal to
- 24:04two now we said id is equal to one well
- 24:06is a valid id
- 24:07and so this will evaluate to true and
- 24:09one is equal to two
- 24:11um we'll evaluate to false because one
- 24:13will never be equal to two and so
- 24:15because this is an
- 24:16and statement over here you're using the
- 24:19and operator
- 24:20they both have to be true in order for
- 24:22the entire where clause to evaluate to
- 24:24true so this evaluates to true this
- 24:26evaluates to false
- 24:28true and false is equal to false
- 24:31and so the entire where condition
- 24:32evaluates to false
- 24:34and so it won't display a title uh from
- 24:37the product table
- 24:38so in this case if you force the false
- 24:40statement you won't get the title of the
- 24:42products that are associated to id is
- 24:44equal to 1.
- 24:46now let's see what happens when you
- 24:47force a true statement
- 24:49so we'll use conditional statements and
- 24:52we'll say id is equal to 1
- 24:53and 1 is equal to 1. now we said id is
- 24:56equal to 1 evaluates to true because
- 24:58this is a valid id in the table
- 25:00and one is equal to one one will always
- 25:02be equal to one
- 25:03and so this will always evaluate to true
- 25:06true and true
- 25:07evaluates to true and so the where
- 25:08clause evaluates to true and so the
- 25:10title
- 25:12of the products that are associated to
- 25:13id one
- 25:15will be outputted on the page and so
- 25:18right now
- 25:19i have two different responses depending
- 25:21on whether i force a false statement
- 25:23versus a true statement and so i'm able
- 25:25to tell when the application is telling
- 25:27me yes this is a true statement versus
- 25:29no this is not a true statement
- 25:32and so now you might be wondering well
- 25:34it's nice that i can play around with
- 25:35the application and get it to output
- 25:37true or false but how does that
- 25:39actually matter and how does that help
- 25:41me in
- 25:42exploiting a sql injection vulnerability
- 25:44to get
- 25:45sensitive information from the database
- 25:48to answer that let's take another use
- 25:51case so imagine the same application
- 25:53the application has a login
- 25:55functionality and so it has a users
- 25:56table in the database
- 25:57and the users table has the usernames
- 26:00of the users of the application so in
- 26:02this case administrator
- 26:04and the hashed passwords of the users in
- 26:07the application
- 26:09and so i want to extract this hash
- 26:11password for the administrator
- 26:13but i can't simply output it on the page
- 26:16like i would for union-based sql
- 26:18injection
- 26:20and so i have to use my boolean based
- 26:22sql injection um
- 26:24in order to output it and that's only
- 26:26done using by
- 26:27asking the application true and false
- 26:29questions and so
- 26:30the way i'm going to do that is by using
- 26:33this payload over here which generates
- 26:35this query over here
- 26:37so you've got i'll use the substring
- 26:40function and what that function does it
- 26:42extracts
- 26:44some characters from a string so the
- 26:46first method the first parameter
- 26:48that it takes is the string that you
- 26:50want to extract from
- 26:52the second parameter that it takes is
- 26:53the start position
- 26:55or the extraction and the third
- 26:57parameter that it takes
- 26:59is the number of characters to extract
- 27:02so in this case
- 27:03i'm saying that string to extract from
- 27:07is the output of this query so select
- 27:09the password from the users table where
- 27:11username is equal to
- 27:12administrator this query will output
- 27:14this hashed
- 27:15string over here and then i'm asking it
- 27:18extract the first character in the
- 27:21string and
- 27:22only one character and so it will um
- 27:25extract the first character over here of
- 27:28the hashed password and then i'm asking
- 27:30it is this first character
- 27:31equal to s in this case the first
- 27:34character is not equal to
- 27:36s because the first character is e and
- 27:39so
- 27:39this this statement over here evaluates
- 27:43to false
- 27:44true and false evaluates to false and so
- 27:48the where clause evaluates to false and
- 27:50you shouldn't see a title
- 27:52from the products page and so nothing is
- 27:55returned on the page
- 27:57that means it returned false that means
- 28:00i know that s
- 28:01is not a first character in the hashed
- 28:02password
- 28:04now imagine i keep looping through the
- 28:07characters and i get to e
- 28:10and i ask it again is the first
- 28:13character of the hashed password equal
- 28:16to e
- 28:18that evaluates to true right so the
- 28:20backend query would be
- 28:22true and true so the entire where clause
- 28:24evaluates to true and so the title
- 28:27of the products that are associated to
- 28:29id1 are returned on the page
- 28:32and this gives me an indication that it
- 28:34returned true
- 28:36which again tells me that e is the first
- 28:39character of the hashed password
- 28:41and so right now you should get an
- 28:43indication of how you're going to
- 28:45extract information from the database
- 28:47and why i said it takes more skill set
- 28:49and more time than
- 28:50union-based injection and that's because
- 28:53you're
- 28:54asking the application true and false
- 28:56questions and you're going to have to do
- 28:57that for each
- 28:58character so you start off with the
- 28:59first character you loop through
- 29:02all the alphanumeric characters until
- 29:04you get a true result once you get a
- 29:06true result that means you know you
- 29:08discovered what the character is
- 29:09which is e over here and then you move
- 29:12on to the next one
- 29:13and then you loop through the
- 29:14alphanumeric characters until you get
- 29:16another true statement and then that
- 29:18means you discovered what this character
- 29:19is
- 29:20and then again you loop through all the
- 29:22alphanumeric characters
- 29:23until you discover what this character
- 29:25is and so on until
- 29:27you output the entire uh string of the
- 29:29hashed password and this could take
- 29:31thousands of requests
- 29:32obviously you can do it manually and so
- 29:35you have to automate
- 29:36the tasks and we'll do that in one of
- 29:38the videos where we
- 29:40use burp intruder to automate it we'll
- 29:42also write a python script
- 29:44that does it for you and it might seem
- 29:46like it's something that is very
- 29:47difficult but it's not
- 29:49um writing the script in python takes
- 29:51about five minutes five to ten minutes
- 29:53max
- 29:54and then outputting the um the string is
- 29:57going to take less than one minute
- 29:58putting the entire hashed uh password so
- 30:01that's boolean based
- 30:03uh blind sql injection next
- 30:06let's talk about time-based blind sql
- 30:09injection
- 30:11time-based sql injection is a
- 30:13blind-based sql injection technique
- 30:15that relies on the database pausing for
- 30:18a specified amount of time
- 30:20then returning the results indicating a
- 30:21successful sql
- 30:23query execution so just like
- 30:26uh just like we did for boolean based
- 30:28sql injection what we do for time-based
- 30:30sql injection
- 30:32is we inject a payload in the parameter
- 30:35that is vulnerable and what that payload
- 30:37does
- 30:37it pauses the application the response
- 30:40of the application for a certain period
- 30:41of time so in postgres sql you would use
- 30:44the pg
- 30:44sleep command and and put a certain
- 30:47number of seconds so if i use pg sleep
- 30:4910 that means
- 30:50i ask the application to sleep for 10
- 30:52seconds
- 30:53and so if the response time takes 10
- 30:55seconds to get back to me then i know
- 30:57it's vulnerable to
- 30:58time based sequel injection if it
- 31:00doesn't take 10 seconds
- 31:01so it takes the general one second to
- 31:03get back to me then it's not vulnerable
- 31:05to
- 31:05time-based sql injection and
- 31:09the example is the same for
- 31:10boolean-based sql injection the way you
- 31:11would extract
- 31:13information from the database is
- 31:16by asking the application true and false
- 31:18questions except the condition over here
- 31:20is not a response in the application
- 31:22the indication of whether it's true or
- 31:24false is going to be based on
- 31:26the response time of the application and
- 31:28so i'm going to say if the first
- 31:30character of the administrators hashed
- 31:32password is an a then wait for 10
- 31:34seconds
- 31:35and if the response time takes 10
- 31:37seconds to respond to me
- 31:39then the first letter is a if it doesn't
- 31:41take 10 seconds then the first letter
- 31:43is not a and again this can't be done
- 31:47manually
- 31:48you're going to have to script it and
- 31:50you can do that in python where you
- 31:52measure the response time
- 31:53and then depending on what the response
- 31:54time is you determine whether it's true
- 31:57or false okay
- 32:00last but not least uh let's talk about
- 32:03out-of-band
- 32:04sql injection out-of-band sql injection
- 32:09is a vulnerability that consists of
- 32:10triggering an
- 32:11out-of-band network connection to a
- 32:13system that you control
- 32:15so this technique is usually used when
- 32:17you can't apply any of the other
- 32:18techniques that we learned about so far
- 32:21and it's not a common technique because
- 32:23it does rely
- 32:24on certain features being enabled in the
- 32:26database for it to actually make that
- 32:29network connection now to exploit this
- 32:31vulnerability you could use a variety of
- 32:32protocols
- 32:34but you'll see that the most commonly
- 32:35used ones are dns
- 32:37and http and one that we will look at in
- 32:40the videos it's in the web security
- 32:42academy so in the upcoming videos we
- 32:44where we gain hands-on experience doing
- 32:46this is this example over here
- 32:49where you exploit the vulnerability by
- 32:52using the
- 32:52xp dir-3 stored procedure in ms
- 32:56sql to perform a lookup of
- 32:59this domain over here so this domain was
- 33:02generated using burp collaborator
- 33:04and so you own it um since this is the
- 33:06domain that you control
- 33:08you can confirm if there were any dns
- 33:11lookups
- 33:11if there was then this is vulnerable to
- 33:13add a banned sql injection
- 33:15if it's not vulnerable then you won't
- 33:16see the dns lookup we'll see how to do
- 33:18this
- 33:19in the lab videos now once you've
- 33:21confirmed that you have an out-of-band
- 33:22sql injection
- 33:24in some cases you might be able to
- 33:25directly exfiltrate data
- 33:27whereas in other cases you might have to
- 33:30use conditional statements like we did
- 33:32with
- 33:32boolean and time-based sql injection
- 33:35where if you do get a dns lookup then
- 33:37yes
- 33:38this is a true scenario if you don't get
- 33:40a dns lookup then no it's not a true
- 33:42scenario
- 33:45all right in the past couple of slides
- 33:47we discussed the different types of sql
- 33:49injection vulnerabilities
- 33:51now in this section we'll discuss how to
- 33:53find sql injection vulnerabilities
- 33:55so imagine you've been given an
- 33:57application and asked to test it how
- 33:59would you go about testing the
- 34:00application
- 34:01to see if it's vulnerable to any sql
- 34:04injection vulnerabilities
- 34:08before we cover that it's worth
- 34:11mentioning that the methodology used for
- 34:13finding sql injection vulnerabilities
- 34:15differs from one person to another
- 34:17person
- 34:18and it's usually developed by experience
- 34:21so just because i give you my
- 34:23methodology doesn't mean that you have
- 34:25to follow it to the letter
- 34:26instead i would recommend that you take
- 34:28what is useful for you from it
- 34:30and then build and add on to your own
- 34:32methodology as you gain more and more
- 34:34experience
- 34:35in pen testing web applications and
- 34:38that statement applies for finding all
- 34:41the vulnerabilities not just
- 34:43sql injection vulnerabilities okay
- 34:46so finding sql injection vulnerabilities
- 34:48i've decided to split
- 34:50uh this into two categories depending on
- 34:53the perspective
- 34:54of uh testing and the two categories
- 34:57are black box testing and white box
- 35:00testing for those of you that have
- 35:02never heard of these terms before
- 35:03blackbox web application patent testing
- 35:06is when the tester is given little to no
- 35:08information about the system
- 35:10usually the only information that the
- 35:12tester has access to
- 35:14is the url of the application and the
- 35:16scope of the engagement so this is
- 35:18uh similar to mimicking an external
- 35:21attacker that
- 35:22is trying to attack your system the
- 35:24attacker usually doesn't know anything
- 35:25about the application
- 35:27other than the main url of the
- 35:28application
- 35:30now for whitebox web application pen
- 35:32testing it's the complete opposite the
- 35:34tester would be given complete access to
- 35:36the system including access to the
- 35:38source code
- 35:39of the application now there's a third
- 35:41category that i haven't
- 35:43included on the slide and it's called
- 35:45grey box
- 35:46web application pen testing this is a
- 35:48combination of white box and black box
- 35:50pen testing where the tester is given
- 35:52limited information
- 35:53and access to the system for example
- 35:56instead
- 35:57of just giving the tester a url of the
- 36:00application like you would with blackbox
- 36:02pen testing the tester is also given
- 36:04accounts to the application
- 36:06so when it comes to my methodology of
- 36:08finding sql injection vulnerabilities i
- 36:10loop both grey box and black box pen
- 36:12testing into one category and that's
- 36:14because my methodology is the same
- 36:16regardless of the category the way i see
- 36:18it
- 36:18is if i'm approaching it from a black
- 36:20box perspective
- 36:21my scope will be much more limited than
- 36:23the gray box perspective unless i find
- 36:26authentication bypass vulnerability
- 36:28nevertheless the methodology is still
- 36:30the same for
- 36:31finding sql injection vulnerabilities
- 36:32whether i'm doing it
- 36:34in a public or an authenticated page
- 36:37and that's why they're looped in
- 36:39together now when it comes to white box
- 36:41pen testing that's a whole different
- 36:43methodology because you actually gain
- 36:44access to the source code of the
- 36:46application and reviewing source code is
- 36:48a whole different realm
- 36:50than approaching an application from the
- 36:52outside
- 36:55all right let's start off by talking
- 36:57about how to test applications from a
- 36:59black box perspective the first thing
- 37:01that i do when testing an application
- 37:03is map the application and what that
- 37:05means is i literally visit the url of
- 37:07the application
- 37:08i walk through all the pages that are
- 37:10accessible to me within the user context
- 37:12that i'm running as
- 37:13i make note of all the input vectors
- 37:15that potentially talk to the back end
- 37:17i understand how the application
- 37:19functions i try to figure out
- 37:21the logic of the application i try to
- 37:24find subdomains in the application
- 37:26i enumerate directories and
- 37:29pages that might not be directly visible
- 37:32to me through the application
- 37:34and so on and while i do all of that i
- 37:37have my
- 37:38proxy listening silently and
- 37:40intercepting all the requests that i'm
- 37:42making to the application
- 37:43so mapping the application is such an
- 37:46underrated step when it comes to pen
- 37:48testing applications
- 37:49although i would argue it's probably the
- 37:51most important
- 37:52step and the reason i say that is
- 37:55because i usually see beginners in this
- 37:56field
- 37:57get way too excited about the fact that
- 38:00they're testing an
- 38:00application and then the first thing
- 38:02that they do is start throwing
- 38:03potentially malicious input vectors
- 38:06into the application to see if the
- 38:08application responds in an unusual way
- 38:10and although this is a valid way of
- 38:12testing an application
- 38:13it doesn't make you any different from
- 38:15an automated tool
- 38:16so this is exactly what web application
- 38:18vulnerability scanners do they crawl the
- 38:20application
- 38:21they locate all the input vectors and
- 38:23then they throw a ton of malicious
- 38:24payloads at these input vectors
- 38:26and depending on how the application
- 38:28responds the scanner logs the behavior
- 38:30as a potential vulnerability
- 38:32and this way of testing usually only uh
- 38:35discovers the
- 38:36low hanging vulnerabilities so if you're
- 38:39doing exactly what a scanner can already
- 38:41do then your testing is really not
- 38:43adding any value
- 38:44instead of doing that what i would
- 38:46recommend is you leave that up to the
- 38:48scanners
- 38:49and instead spend quite a bit of time
- 38:53understanding how the application works
- 38:55because most of the critical
- 38:56vulnerabilities found in applications
- 38:58are logic flaws that a scanner is not
- 39:01capable of finding on its own
- 39:02or um the vulnerabilities are embedded
- 39:05in pages that the scanner can't crawl so
- 39:09technologies that the scanner can crawl
- 39:11okay so once you've mapped the
- 39:14application
- 39:15and you've listed all the input vectors
- 39:17that are potentially included in queries
- 39:20that are interacting with the sql
- 39:21database then it's a matter of fuzzing
- 39:23the application
- 39:25and that's because we're looking for sql
- 39:26injection vulnerabilities you'd be
- 39:28fuzzing the application with sql
- 39:30specific characters so what that means
- 39:32is you add special characters in the
- 39:34input vectors
- 39:35and see if the application responds in
- 39:38an unusual way
- 39:39now depending on how the application
- 39:42responds you start refining your query
- 39:44until you achieve your end goal and
- 39:46that's what makes you different from a
- 39:47scanner
- 39:48because a scanner just simply throws a
- 39:50bunch of input
- 39:51at the application you as a human being
- 39:55is capable you're capable of
- 39:57understanding the output
- 39:59of the sql injection and so you're able
- 40:02to refine your sql injection using
- 40:04multiple requests
- 40:05until you actually achieve your goal and
- 40:07we'll see how to do that in the
- 40:08exploitation section
- 40:10of this video okay again fuzzing the
- 40:13application means
- 40:14adding special characters and input
- 40:16vectors and seeing if the application
- 40:17responds
- 40:18in an unusual way now that can be done
- 40:21in many ways
- 40:21the first thing that i try to do is
- 40:24submit sql specific characters such as
- 40:26the quote or the double quote or the
- 40:29hash or the
- 40:30dashes that represent comments and see
- 40:32if the application outputs an
- 40:34error now errors are really important
- 40:38and really useful because they give you
- 40:40information about how the backend
- 40:42operates so sometimes they give you the
- 40:45database that you're using they give you
- 40:47the version of the database we discussed
- 40:48that sometimes they actually give you
- 40:50the exact query
- 40:52if they gave you the query then you hit
- 40:53gold because this way you don't have to
- 40:56develop your payload across multiple
- 40:57requests instead you already know what
- 40:59the backend query is and so you just
- 41:01develop your payload based on that query
- 41:04and so the first thing that i do is try
- 41:06to output an error once i have an
- 41:08error i try to build my query um
- 41:11using multiple requests so i refine my
- 41:13query based on the errors that i get and
- 41:15i build my query now in certain
- 41:16scenarios you don't actually get an
- 41:18error like for a blind sql injection and
- 41:21so you also have to submit boolean
- 41:22conditions such as
- 41:24you know and or one equal to one
- 41:27and one is equal to two and look for
- 41:30differences in the applications
- 41:31responses
- 41:32so if you can get the application to
- 41:34respond differently when you force a
- 41:36true use case versus when you force
- 41:38a false use case that means it's
- 41:39vulnerable to boolean
- 41:41injection uh next i
- 41:45i do the same thing as boolean injection
- 41:47instead it would be
- 41:48to trigger time delays in the
- 41:51application and then see
- 41:52if there's a difference in the time it
- 41:55takes to respond
- 41:56so if you input a function that causes a
- 42:00time delay and you
- 42:01actually observe that time delay that
- 42:02means that the application is vulnerable
- 42:04to
- 42:05time-based sql injection last but not
- 42:08least
- 42:09i also submit out-of-band payloads
- 42:12that are designed to trigger a network
- 42:15interaction with a server that i control
- 42:18and if i get that network interaction
- 42:20whether it's a dns lookup or it's done
- 42:22through http
- 42:23that means that the application is
- 42:26vulnerable to out a band sql injection
- 42:29and if i don't get them that means it's
- 42:31not vulnerable to add a band sql
- 42:32injection
- 42:34so that's a high level overview of my
- 42:38methodology when it comes to
- 42:39testing from a black box perspective
- 42:42there's really
- 42:43two steps first mapping the application
- 42:45so
- 42:46listing all the input vectors in the
- 42:48application
- 42:49and then fuzzing the input vectors to
- 42:52see
- 42:52if i can if i can find a sql injection
- 42:55and again when it comes to fuzzing the
- 42:57input vectors
- 42:58you can refine your requests based on
- 43:00the responses that the application
- 43:03gives you okay next is
- 43:06whitebox testing perspective so where
- 43:08you're given the source code of the
- 43:10application
- 43:11in this case the first thing that i do
- 43:13is i enable
- 43:14web server logging and i enable database
- 43:17logging enabling
- 43:19logging at the web server level will
- 43:21help because
- 43:23when you're fuzzing the application like
- 43:24we did with blackbox perspective
- 43:26it will generate errors on all the
- 43:29different
- 43:30um invalid characters that you input
- 43:33into the application and then that helps
- 43:35you
- 43:36to detect that a sql injection uh
- 43:40exists and then also to refine your
- 43:42payload
- 43:43later on similarly for database logging
- 43:45i enable that because when i
- 43:47think that there's a sql injection
- 43:49vulnerability and i enter a sql
- 43:51injection payload in the parameter i'd
- 43:53like to see how it was logged at the
- 43:54back end
- 43:55and then depending on how it was logged
- 43:57at the backend i can see what characters
- 43:59made it through and in what format they
- 44:00made it through and then i could say
- 44:02um with maybe a 90 accuracy that yes
- 44:05this is vulnerable to sql injection
- 44:07before
- 44:08i even look at the source code of the
- 44:10application
- 44:13so once i have my logging enabled the
- 44:15next thing that i do is map the
- 44:17application just like i would with
- 44:19a black box perspective so i'll start
- 44:22with the applications
- 44:24graphical user interface i'll map all
- 44:26the visible functionality in the
- 44:28application all the input vectors that
- 44:29potentially talk to the backend
- 44:32and i'll make a list on them next
- 44:34because i do have access to the source
- 44:36code i'll also do a resurrect search
- 44:39on all instances in the code that talk
- 44:41to the database and that really
- 44:42that really depends on how the
- 44:44application is programmed and then
- 44:46which database it uses and so on
- 44:50but i would have regex strings
- 44:53that i look for in the code to see
- 44:56if i've missed anything that i haven't
- 44:58mapped from a black box perspective and
- 45:00you'll see that there are certain pages
- 45:03that
- 45:03might not have been directly accessible
- 45:05through the main page of the application
- 45:07and you didn't discover them through
- 45:09directory brute forcing and so it's
- 45:11useful to actually look at the code and
- 45:13see if there's anything that you missed
- 45:15once i have a list of everything what i
- 45:18would do
- 45:18is i would literally fuzz the
- 45:21application so
- 45:22i would submit sql characters
- 45:26that could potentially break the query i
- 45:28will look at how
- 45:30they were logged using database logging
- 45:33that i enabled in the first step
- 45:34and then uh based on that i can usually
- 45:37tell if it's vulnerable to
- 45:38do sql code injection and if i feel like
- 45:41it's vulnerable to sql code injection
- 45:43then i actually do a code review
- 45:45of that functionality so for example if
- 45:48i think the login page is vulnerable to
- 45:49sql injection what i would do
- 45:51is i will look for the login
- 45:53functionality so the function that
- 45:55implements that in the code and then i
- 45:57would do a walkthrough of the entire
- 45:59functionality
- 46:00from beginning to end until until i have
- 46:03confirmed that it is
- 46:04vulnerable to sql injection in theory
- 46:06and then to confirm in practice that it
- 46:08is vulnerable to sql injection
- 46:10then i would test it out and depending
- 46:13on the response i get from the
- 46:14application that means
- 46:16it's vulnerable to sql injection
- 46:19so again that's my methodology doesn't
- 46:21mean that it's a methodology that you
- 46:22should follow
- 46:23i do know people that would
- 46:25automatically just go into the source
- 46:27code and then do a search for
- 46:29insecure functions when it comes to
- 46:32parameterized queries and so on and so
- 46:36if they find an insecure function
- 46:37they'll start with that instead of
- 46:39doing kind of a hybrid approach of
- 46:42both black box and white box which is
- 46:45the way that i the methodology that i
- 46:47described
- 46:50okay in the past two sections we talked
- 46:53about the different types of sql
- 46:55injection vulnerabilities
- 46:56and how to test an application to see if
- 46:59it's vulnerable to sql injection
- 47:01now in this section we'll talk about how
- 47:03to exploit sql injection vulnerabilities
- 47:06in order to achieve your end goal and uh
- 47:09that really depends on the sql injection
- 47:11vulnerability that you're trying to
- 47:13exploit
- 47:13uh we so far talked about four different
- 47:15uh sorry actually five different types
- 47:17error-based sql injection union-based
- 47:19sql injection
- 47:20boolean based blind sql injection based
- 47:23blind sql injection and out of band sql
- 47:26injection so in this section we'll talk
- 47:28about how to exploit
- 47:28each one of these vulnerabilities
- 47:32and we'll start off with error-based sql
- 47:34injection
- 47:36now as a reminder we said error-based
- 47:38sql injection is an
- 47:39in-band sql injection technique that
- 47:41forces the database to generate an error
- 47:44giving the attacker information upon
- 47:46which to refine
- 47:47a query so a successful exploitation of
- 47:51an error-based sql injection
- 47:52is the fact that you can get the
- 47:54application to output an error so
- 47:56there's really not much to explaining
- 47:58this vulnerability all you would do is
- 48:00submit sql specific characters
- 48:02again such as the single quote or the
- 48:04double quote and you
- 48:06look for errors in the application
- 48:09now different characters can give you
- 48:11different errors so it's good to fuzz
- 48:13the application with the commonly known
- 48:15characters
- 48:16to generate errors next
- 48:19is a union-based sql injection
- 48:22exploiting this vulnerability is a
- 48:23little bit more involved
- 48:24as a reminder we said union-based sql
- 48:27injection is an in-band sql injection
- 48:30technique
- 48:31that leverages the union sql operator
- 48:34to combine the results of two queries
- 48:36into a single result set
- 48:38now in order for you to use the union
- 48:40operator you have to follow
- 48:42the rules of the union operator and
- 48:43there's two basic rules the first one is
- 48:46that the number
- 48:46and the order of the columns must be the
- 48:48same in all queries
- 48:50and the second one is that the data
- 48:52types must be
- 48:53compatible so the query that the
- 48:54application is making
- 48:56and the query that you want to make have
- 48:58to satisfy these two rules
- 49:00and so when you're exploiting union
- 49:02based sql injection the first thing that
- 49:04you need to do is figure out the number
- 49:05of columns that the query is making
- 49:08we'll talk about that in a bit and we've
- 49:09got two ways of doing that
- 49:11next you figure out the data types of
- 49:12the columns
- 49:14we're mainly interested with string data
- 49:16because we want to extract things like
- 49:18usernames and passwords and so on and so
- 49:20that's usually saved in string format
- 49:22and so we need to find a data type that
- 49:25outputs
- 49:26uh string data and this way we could
- 49:28output the data that we want to extract
- 49:31and then once you've figured out the
- 49:32number of columns that the query is
- 49:33making and the data types of the columns
- 49:35then you could use the union operator to
- 49:38output information from the database
- 49:40sometimes
- 49:41you don't actually get the data type
- 49:43that you want and so it's a dead end
- 49:46you can only extract for example
- 49:48integers or so on so
- 49:49it depends on the sql injection and the
- 49:52context that you're running with on
- 49:53whether you could actually exploit it to
- 49:55extract information from the backend
- 49:57database
- 49:58okay so i said there's two different uh
- 50:00ways
- 50:01of determining the number of columns
- 50:03that that are required in a sql
- 50:05injection union attack and one of the
- 50:07ways is using the
- 50:08order by clause
- 50:11now this clause orders uh the result set
- 50:14of a query by a specified column list
- 50:17so let's take an example if you've got
- 50:19select the title
- 50:20and the cost from the product table
- 50:23where id is equal to one
- 50:25and then you say order by 1 what that
- 50:27means
- 50:28is that you're ordering by the first
- 50:31column which is by the title column over
- 50:33here
- 50:35now the way to figure out the number of
- 50:37columns
- 50:38is to incrementally inject a series of
- 50:41order by clauses
- 50:42until you get an error or observe a
- 50:45different behavior in the application
- 50:48so if i say order by one
- 50:51it'll order by the first column if i say
- 50:54order by two it'll order by the second
- 50:56column
- 50:56now if i say order by three that column
- 50:59doesn't exist
- 51:00and so i get an error saying the order
- 51:02by position number three
- 51:04is out of range of the number of items
- 51:06in the select list
- 51:08and so this way i know that 3 is not a
- 51:11column and since
- 51:12i incrementally increase the value of
- 51:15the order by
- 51:16integer over here i know then the number
- 51:19of columns is this value minus 1 so 3
- 51:21minus 1 which is
- 51:232. so i know that number of columns that
- 51:25are being used in the sql query
- 51:27is 2. so that's the way to do it using
- 51:31the order by clause you could also
- 51:33figure out the number of columns
- 51:35required in a sql injection
- 51:37using null values
- 51:40so again let's take example of a query
- 51:43that does select the title
- 51:45and the cost from the product table
- 51:48where id is equal to one
- 51:50and then you say union select null
- 51:53and then dash dash for a comment
- 51:55character
- 51:57now because a union using the union
- 52:00operator requires that
- 52:02this query has the same number of
- 52:03columns as this query
- 52:05if you don't use the same number of
- 52:06columns you will get an error
- 52:08so if you incrementally inject a series
- 52:11of union select payloads specifying a
- 52:13different number of null values
- 52:14until you no longer get an error then
- 52:16you could figure out the number of
- 52:18columns that are required by a sql
- 52:20injection so
- 52:22for example this when i put this payload
- 52:25over here which is the one over here
- 52:27it'll give me an error saying something
- 52:29like all queries combined using a union
- 52:32intersect or except operator
- 52:35must have an equal number of expressions
- 52:37in their target list
- 52:38so it's telling me you're using the
- 52:40union operator but your two queries
- 52:42don't have the same number of columns
- 52:43and so i know that the query does not
- 52:45have
- 52:46only one column so i increase the number
- 52:49of null values again by one so now i
- 52:51have two null values
- 52:52and i try it out and i see if it gives
- 52:55me an error that means
- 52:56it has more than two columns and i try
- 52:58three and so on until i no longer get an
- 53:00error
- 53:00now in this case we only have two
- 53:02columns and so this will
- 53:04um this will output uh the results
- 53:08of this query over here and then the
- 53:10null values over here so this won't give
- 53:12me an error
- 53:13and that means that the number of
- 53:15columns that i have
- 53:17are is equal to the number of null
- 53:20values that i entered which is 2.
- 53:21so you could either do it by the order
- 53:23by clause or
- 53:25use by adding union select payloads
- 53:27specifying
- 53:28different numbers of null values
- 53:32okay so that's how to find out
- 53:35the number of columns that the query is
- 53:38using next we need to find a useful data
- 53:41type
- 53:42in these columns and so the way to do
- 53:45that
- 53:45is to probe each column to test whether
- 53:48it can hold string data
- 53:50by submitting a series of union select
- 53:52payloads that place a string value into
- 53:54each column in turn so
- 53:57over here what i would do now i know
- 53:59that it has two columns right
- 54:01from the previous exercise that we just
- 54:03did so what i would do
- 54:05is i would um add a string value
- 54:08so a in the first in the first column
- 54:10value and see if it outputs an
- 54:12error if it outputs an error saying that
- 54:15i don't know it's incompatible with a
- 54:16certain type so in this case we're
- 54:18saying that the first
- 54:19uh the first value is actually integer
- 54:22and so i get an error saying that it's
- 54:24incompatible which means that the first
- 54:26column does not allow you to
- 54:28is not a string data type so
- 54:31next i try the second column over here
- 54:34so i keep this as null and i try the
- 54:36second column and if i get an error that
- 54:38means this
- 54:38also is not does not accept string
- 54:41values and i keep doing that
- 54:43until i find a value that allows me to
- 54:46enter a string data and again in some
- 54:48cases you might not actually find a
- 54:50value and that's why some sql injections
- 54:52allow you to do things like extract data
- 54:54from a database whereas others you're
- 54:56very limited in what you're
- 54:58like the data type that you're allowed
- 54:59to extract
- 55:01okay and so going back to the slide um
- 55:04explaining union based sql injection we
- 55:06talked about how to figure out the
- 55:08number of columns
- 55:09that the query is making we also talked
- 55:11about how to figure out the data types
- 55:12of the columns
- 55:13if you have um columns that are being
- 55:16outputted on the page
- 55:17and they use string data then you could
- 55:20use
- 55:21the union operator to output information
- 55:23from the database
- 55:25and that's how you exploit union based
- 55:27sql injection
- 55:29next let's talk about exploiting boolean
- 55:31based blind sql injection
- 55:33so uh the first thing to do is submit a
- 55:36boolean condition that evaluates to
- 55:38false
- 55:39and note the response i've got an error
- 55:41here it should say
- 55:42note the next thing to do is submit a
- 55:45boolean condition that evaluates to true
- 55:48and again note the response if the
- 55:51response
- 55:51is different or when you force the false
- 55:54statement versus a true statement then
- 55:56you have a boolean baseline sql
- 55:58injection and the way to exploit that we
- 56:00already talked about that
- 56:01is to write a program that uses
- 56:02conditional statements to ask the
- 56:04database a series of true and false
- 56:06questions
- 56:06and then monitor the responses if the
- 56:09response
- 56:09is the same as the response you got when
- 56:12it evaluated to true that means
- 56:14uh the question that you're asking the
- 56:16application is true
- 56:17if the response is the same as the
- 56:19response that you got when you
- 56:20force the false statements that means
- 56:22the question that you're asking the
- 56:24application
- 56:25is false and that's how you extract data
- 56:27from the database when it comes to
- 56:29boolean-based
- 56:30blind sql injection next
- 56:33is time-based blind sql injection
- 56:36what you do is you submit a payload that
- 56:38pauses the application for a specified
- 56:40period of time
- 56:41if the application does actually pause
- 56:44for that specified period of time that
- 56:46means it's vulnerable to time-based sql
- 56:48injection
- 56:48and then it's a matter of doing the same
- 56:50thing that you did for boolean based sql
- 56:52injection you
- 56:53just write a program that uses
- 56:55conditional statements to ask the
- 56:57a series of true and false questions and
- 56:59you monitor the response time
- 57:00if there's a delay in the response time
- 57:02that means the question you're asking
- 57:04the application is true
- 57:05if there's no delay in the response time
- 57:07that means the question you're asking
- 57:08the application is false and then you
- 57:10send a bunch of those requests until you
- 57:12enumerate
- 57:13or you extract the thing that you want
- 57:14to extract from the database
- 57:17and we'll gain experience in all of
- 57:18these different types of
- 57:20sql injection vulnerabilities like
- 57:22hands-on experience in the next upcoming
- 57:24videos
- 57:26okay so explaining how to ban sql
- 57:29injection
- 57:29um again a reminder this is a
- 57:31vulnerability that consists of
- 57:33triggering
- 57:33an out-of-band network connection to a
- 57:35system that you control
- 57:37and the way to exploit it is to submit
- 57:40out-of-band payloads designed to trigger
- 57:42an out-of-band network interaction when
- 57:44executed within
- 57:45a sql query and monitor for any
- 57:48resulting
- 57:48uh interactions so this is a database
- 57:52specific
- 57:52obviously so knowing the type of
- 57:54database that you're using
- 57:56will be very useful in in this scenario
- 58:00and it depends on whether the database
- 58:01has these functions enabled
- 58:03and so if you do get that network
- 58:06connection if you receive that network
- 58:07connection
- 58:08again whether it's a dns lookup or
- 58:09something else that means that
- 58:11the application is vulnerable to add a
- 58:13band sql injection
- 58:15and in certain scenarios you might be
- 58:16able to immediately expel
- 58:19data from the application so directly
- 58:22excel data from the application whereas
- 58:24in other cases you're again stuck asking
- 58:26true and false questions just like you
- 58:27would for
- 58:29line based sql injection
- 58:32okay i didn't want to end this section
- 58:34without talking about
- 58:35automated exploitation tools so one of
- 58:38the famous ones and it's open source
- 58:40is a sql map it's a tool that is used to
- 58:43find sql injection vulnerabilities
- 58:46it's very very powerful and it's very
- 58:49customizable
- 58:50in the sense that you select what
- 58:52parameters you could
- 58:53inject you also select the figurosity of
- 58:56your testing you also select
- 58:58the angle of your testing so if it does
- 59:00find a sql injection vulnerability
- 59:02sometimes you have the ability to say
- 59:03try to
- 59:04get a shell on the system or try to dump
- 59:07the usernames and passwords of the
- 59:09applications on the system and so on and
- 59:11so this is a very important tool to look
- 59:13into when it comes to finding sql
- 59:15injection vulnerabilities
- 59:16other tools that you could use which are
- 59:18more for detection versus
- 59:20uh actually exploiting it to to
- 59:23achieve your end goal our web
- 59:25application vulnerability scanners
- 59:28we talked quite a bit about these in
- 59:30this video
- 59:31there are scanners that crawl the
- 59:33application and look for vulnerabilities
- 59:35so not just sql injection
- 59:37vulnerabilities they look for all types
- 59:38of vulnerabilities
- 59:39in an application um and they usually
- 59:41report it as a vulnerability they don't
- 59:43actually go
- 59:44all the way to explaining it to get a
- 59:46shell on the system or to dump
- 59:47usernames and passwords and some of
- 59:50these tools
- 59:51are open source whereas others are
- 59:54paid so something to look into of course
- 59:57these tools have limitations
- 1:00:00and uh maybe i'll do a video specific on
- 1:00:03that because that's what my research was
- 1:00:05on but these tools have
- 1:00:07limitations and they operate from a
- 1:00:08black box uh perspective so there are
- 1:00:11other tools that operate from a white
- 1:00:12box perspective
- 1:00:13they're called static analysis tools
- 1:00:15whereas these are called dynamic
- 1:00:17analysis tools so something to look into
- 1:00:19when you want to automate a portion of
- 1:00:22your
- 1:00:23web application testing
- 1:00:26all right now that you know what a sql
- 1:00:28injection vulnerability is
- 1:00:30how to find it and how to exploit it the
- 1:00:32next thing to learn is how to prevent
- 1:00:34sql injection vulnerabilities
- 1:00:36and that will come in really handy when
- 1:00:38you're writing pen testing reports and
- 1:00:40you need to provide recommendations to
- 1:00:41your client on how to remediate the
- 1:00:43vulnerabilities that you discovered
- 1:00:46so there are the primary defenses
- 1:00:50and the additional defenses which use
- 1:00:53the concept
- 1:00:54of defense in depth we'll talk about
- 1:00:57each defense in the next couple of
- 1:00:59slides
- 1:01:00and those are the ones that are
- 1:01:01mentioned in the web application hackers
- 1:01:04handbook
- 1:01:05but the idea is i have this highlighted
- 1:01:07over here because this is the correct
- 1:01:10way of preventing sql injection
- 1:01:13vulnerabilities and that is by using
- 1:01:15prepared statements
- 1:01:16or parameterized queries instead of
- 1:01:19string concatenation within a query all
- 1:01:21the other options are partial options
- 1:01:24and should be used only as a last resort
- 1:01:26with the knowledge
- 1:01:27that they might be bypassed or they
- 1:01:29might be implemented incorrectly and
- 1:01:31they might cause a sql injection in the
- 1:01:34in the future
- 1:01:36and so let's talk about each one in
- 1:01:38order starting with the correct
- 1:01:40way of defending against sql injection
- 1:01:43vulnerabilities and that's
- 1:01:45using prepared statements
- 1:01:48okay so let's take an example first so
- 1:01:51you've got
- 1:01:52a code block over here the first one
- 1:01:54which is query over here
- 1:01:56as a select the account balance from the
- 1:01:59user data table
- 1:02:00where username is equal to
- 1:02:03request.getparameter customername
- 1:02:05so what this does is it takes user input
- 1:02:08so user controlled input customer name
- 1:02:10and it
- 1:02:11adds it directly to the query and then
- 1:02:15it defines the structure so it's
- 1:02:17defining the structure of the query
- 1:02:19and then it executes the query do you
- 1:02:22spot the issue over here
- 1:02:23it's a bit obvious the user supplied
- 1:02:26input customer name over here is
- 1:02:28embedded directly into the sql
- 1:02:31statement and so anything that the user
- 1:02:34adds over here might actually be
- 1:02:37interpreted as
- 1:02:38a part of the query
- 1:02:43okay so using uh prepared statements can
- 1:02:46prevent
- 1:02:48can prevent sql injection attacks and
- 1:02:49that's because the construction
- 1:02:51of the sql statement is performed in two
- 1:02:53steps the first being the
- 1:02:55application specifies the query
- 1:02:57structure with placeholders for each
- 1:02:59user
- 1:03:00supplied input and then the application
- 1:03:03specifies the content of each
- 1:03:05placeholder this way there's no way that
- 1:03:07a user-supplied input that is specified
- 1:03:10in this step over here can ever
- 1:03:12interfere with the structure of the
- 1:03:14query
- 1:03:14in this first step and that's because
- 1:03:16the query structure had already been
- 1:03:18defined
- 1:03:18and now any placeholder data is
- 1:03:21interpreted in a safe way
- 1:03:23as literally data versus sql code
- 1:03:27and so let's take an example of code
- 1:03:29that is not vulnerable
- 1:03:32so in this code over here you could see
- 1:03:35there is uh
- 1:03:36the variable uh cust name it takes and
- 1:03:39user supplied input customer name
- 1:03:43you've got the query over here being
- 1:03:46defined
- 1:03:48and then over here it prepares the
- 1:03:50statement through a database connection
- 1:03:52so the prepare statement method is
- 1:03:54invoked
- 1:03:55to interpret this query and fix the
- 1:03:57structure of the query and then
- 1:03:59the set string method is used to specify
- 1:04:01the parameters actual value
- 1:04:03now uh because the query structure is
- 1:04:05already has already been fixed
- 1:04:08in the prepared statement this value can
- 1:04:11contain
- 1:04:11any data without affecting the structure
- 1:04:14of the query because it will literally
- 1:04:15be interpreted as data versus as part of
- 1:04:17the query so if the user over here had
- 1:04:20put in sql characters like a quote or a
- 1:04:22double quote or so on
- 1:04:24that won't be interpreted as data and it
- 1:04:26can't ever change the structure of the
- 1:04:28query because the structure has already
- 1:04:29been
- 1:04:30determined and fixed and that's how you
- 1:04:33prevent
- 1:04:34sql injection vulnerabilities that's the
- 1:04:36correct way of preventing sql injection
- 1:04:38vulnerabilities
- 1:04:40now there are partial options that the
- 1:04:43book talks about
- 1:04:44one is the use of stored procedures
- 1:04:48so start procedures are batches of
- 1:04:51statements
- 1:04:52grouped as a logical unit and stored in
- 1:04:54a database um
- 1:04:56this is not a not always a safe way of
- 1:04:59preventing sequel injection
- 1:05:00uh vulnerabilities because if it's
- 1:05:02implemented incorrectly it could still
- 1:05:04be vulnerable to sql injections so it
- 1:05:06still needs to be called in a
- 1:05:07parameterized way
- 1:05:08in order for it to be safe against sql
- 1:05:11injection vulnerabilities
- 1:05:12um and uh the reason that some people
- 1:05:15would use
- 1:05:16uh stored procedures or any of the
- 1:05:17partial options is because
- 1:05:19uh there are certain parameters that you
- 1:05:22can't specify as
- 1:05:23placeholders in parameterized queries
- 1:05:26and for example the table name or the
- 1:05:28column name
- 1:05:29and so if that's user controllable you
- 1:05:31have to use one of the partial options
- 1:05:33in order to prevent sql injection
- 1:05:35attacks now
- 1:05:36the correct way of doing it is that this
- 1:05:38should never be user controllable but if
- 1:05:40it has to be user controllable then you
- 1:05:42use one of the partial options
- 1:05:44that's option two option number three is
- 1:05:46whitelist input validation so define
- 1:05:48which values are authorized
- 1:05:50everything else is considered to be
- 1:05:51unauthorized and we talked about
- 1:05:53parameters that can be placeholders like
- 1:05:55the table name and the column name
- 1:05:56in this case a whitelist input
- 1:05:58validation would be you know
- 1:06:00exactly the column name should be or the
- 1:06:03table name should be users and so you
- 1:06:05only accept the value users and nothing
- 1:06:07else
- 1:06:07and this way you prevent the attacker
- 1:06:10from injecting
- 1:06:11other characters or other strings that
- 1:06:14could potentially
- 1:06:15interfere with your query option number
- 1:06:19four
- 1:06:19is escape all user input the validate
- 1:06:22user input
- 1:06:23and um that should only be used as a
- 1:06:25last resort again it's a partial option
- 1:06:27versus
- 1:06:28something that for sure prevents sql
- 1:06:30injection vulnerabilities
- 1:06:33okay additional defenses uh before we
- 1:06:36talk about that let's talk about
- 1:06:38the concept of defense in depth
- 1:06:41so the idea is to make it as difficult
- 1:06:43as possible for the attacker to
- 1:06:45compromise your organization
- 1:06:46and that's done by providing additional
- 1:06:48protection in the event
- 1:06:50at the frontline defenses bill so
- 1:06:53if me as an attacker i want to gain
- 1:06:56access to your organization
- 1:06:58and i managed to get past the first
- 1:07:01block that you had put in my way
- 1:07:03then i would have two other obstacles
- 1:07:06that i need to get through before i get
- 1:07:09to your organization
- 1:07:10and so in the same sense although you
- 1:07:12use parameterized queries
- 1:07:14just in case you by chance forgot to
- 1:07:18include it on one parameter um in one
- 1:07:21page
- 1:07:22you want to have defenses in place that
- 1:07:24if a sql injection vulnerability was
- 1:07:26exploited the attacker gets
- 1:07:30gets another obstacle in their way
- 1:07:32before they could achieve their goal and
- 1:07:33so
- 1:07:34one is least privilege so the
- 1:07:36application should use the lowest
- 1:07:38possible of privileges when accessing
- 1:07:40the database
- 1:07:41and the reason behind that is if a sql
- 1:07:44injection exists in your application
- 1:07:46and an attacker exploits it to gain
- 1:07:49remote code execution
- 1:07:51on the server that the database is
- 1:07:53installed on
- 1:07:54then the attacker will gain the same
- 1:07:57level of privilege that the database is
- 1:07:59running with and so
- 1:08:00if the database is running a system or
- 1:08:02route then the attacker already has
- 1:08:04all the privileges that the attacker
- 1:08:06needs on that server however if it was
- 1:08:08running with a service account
- 1:08:10that has all the privileges stripped
- 1:08:11then the attacker has to find ways to
- 1:08:14escalate privileges on the server before
- 1:08:17they can for example move laterally
- 1:08:19within the organization
- 1:08:20and so the application should always use
- 1:08:22the lowest possible
- 1:08:24level of privilege when accessing the
- 1:08:25database
- 1:08:27any unnecessary default functionality in
- 1:08:29the database should be removed or
- 1:08:30disabled that includes things like
- 1:08:35functions that allow you to execute
- 1:08:37system commands from the database
- 1:08:39also functions that allow you to make a
- 1:08:41network connection that we talked about
- 1:08:43out of band sql injection right
- 1:08:45so functions that allowed that allow you
- 1:08:47to do that
- 1:08:48so any unnecessary default functionality
- 1:08:50that you don't need
- 1:08:51for the application to function that
- 1:08:53should be removed because
- 1:08:55it decreases the
- 1:08:58amount of things that an attacker can
- 1:08:59use in order to penetrate your
- 1:09:01organization
- 1:09:04ensure cis benchmarks for the database
- 1:09:07in use is applied
- 1:09:08so there are benchmarks for most of uh
- 1:09:10the databases out there
- 1:09:12and these are rules uh on the way to
- 1:09:15configure
- 1:09:16your database in order to ensure that
- 1:09:19it's secure
- 1:09:20and it includes things like the
- 1:09:22application should use the lowest
- 1:09:23possible level of privilege
- 1:09:24and removing any default functionality
- 1:09:26and so on
- 1:09:28so look up your database version and you
- 1:09:30should be able to find a cs benchmark
- 1:09:33for it
- 1:09:35and last but not least this one's
- 1:09:36obvious all vendor issued security
- 1:09:38patches should be applied in a timely
- 1:09:40fashion
- 1:09:40so if you get notified uh that the
- 1:09:43database version that you're using
- 1:09:45is vulnerable to some kind of
- 1:09:46vulnerability then you should
- 1:09:49patch your database as soon as possible
- 1:09:52decrease the window of time that the
- 1:09:53attacker has
- 1:09:54to attack your database and to exploit
- 1:09:57the vulnerability
- 1:09:59and then this one we already discussed
- 1:10:01it so whitelist
- 1:10:03input validation so although you have
- 1:10:05parameterized queries another
- 1:10:07an additional defense so a defense and
- 1:10:09depth is to still whitelist
- 1:10:11um all the input values that come from
- 1:10:16come from the user so come from the
- 1:10:17client side
- 1:10:20okay and that wraps up the last section
- 1:10:24before i close this video let's talk
- 1:10:26about the resources that were used to
- 1:10:29create this video one is the web
- 1:10:31security academy so the sql injection
- 1:10:33module and that's the module that we'll
- 1:10:35be following for the next couple of
- 1:10:36videos
- 1:10:38next is the web application hackers
- 1:10:40handbook so chapter 9
- 1:10:42attacking data stores if you want to
- 1:10:44learn more about this topic you should
- 1:10:46go and read this
- 1:10:47chapter and then we've got the oasp
- 1:10:51guide for sql injection
- 1:10:52and sql injection prevention cheat sheet
- 1:10:55i also included the pen test monkey
- 1:10:57url and the reason behind that is
- 1:11:00because
- 1:11:00it lists all the different sql injection
- 1:11:02payloads
- 1:11:04that you could use depending on the
- 1:11:07database that you're using and then
- 1:11:08there's other ones like payload all the
- 1:11:10things and so on we'll see a lot of this
- 1:11:12when it comes to
- 1:11:13the videos to wrap up in this video we
- 1:11:16learned about sql injection
- 1:11:17vulnerabilities how to find them
- 1:11:19how to exploit them and how to prevent
- 1:11:21them you can find a link to the slides
- 1:11:23in the description
- 1:11:24in the next couple of videos we will
- 1:11:27gain hands-on experience
- 1:11:29exploiting all the different types of
- 1:11:30sql injection vulnerabilities that we
- 1:11:32learned about
- 1:11:33in this video
- 1:11:36if you made it this far thank you for
- 1:11:38watching make sure to hit the subscribe
- 1:11:40button and share the video so that it
- 1:11:42reaches a wider audience
- 1:11:44also comment below what you liked about
- 1:11:45the video and the type of videos you
- 1:11:47would like to see in the future
- 1:11:48thank you and see you in the next video
About this transcript
This page contains the full transcript of SQL Injection | Complete Guide by Rana Khalil, generated from the public captions YouTube serves with the video. The transcript has 12,141 words across 2,145 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.