WEBVTT

00:00.720 --> 00:02.320
All right, folks.

00:02.320 --> 00:03.860
It is that time.

00:03.880 --> 00:08.500
If you have a seat that is in between you, please collapse down.

00:08.640 --> 00:10.160
Specifically you, sir.

00:10.160 --> 00:11.200
Thank you very much.

00:11.200 --> 00:13.080
If you would bring it in close.

00:13.700 --> 00:14.180
All right.

00:14.180 --> 00:17.000
With that, we are going to go ahead and kick everything off.

00:17.080 --> 00:19.620
I would like to introduce Iggy to the stage.

00:19.620 --> 00:20.500
Thank you.

00:28.340 --> 00:33.280
So hello, DEF CON, and welcome to my talk called Ticking SQLI.

00:33.280 --> 00:34.340
And we will begin.

00:34.820 --> 00:36.460
So what's in it for you today?

00:36.460 --> 00:40.160
Today we will explore types of SQL injection.

00:40.160 --> 00:44.320
We will focus a bit on time-based SQL injection.

00:44.660 --> 00:50.160
We will see the impact Team Ghost Shell did in the past using these kinds of techniques.

00:50.340 --> 00:52.660
We will understand why it's still relevant today.

00:52.660 --> 00:56.640
And you will have a good time with a pretty much good presenter today.

00:57.180 --> 00:58.220
So who am I?

00:58.220 --> 01:00.980
My name is Igor, but please call me Iggy.

01:00.980 --> 01:03.220
It's my nickname since childhood.

01:03.320 --> 01:05.740
I'm a security engineer at Axonius.

01:05.740 --> 01:22.520
One sentence about Axonius is it's a cybersecurity asset management platform that maps all your digital assets across your organization, normalizes them, duplicates them, and gives you comprehensive insights about them and much more.

01:22.520 --> 01:23.540
And why am I here today?

01:23.540 --> 01:35.560
I'm here today because I love learning stuff, especially in cybersecurity, from low level to high level, from lock-picking to RFIDs, and I'm studying a lot.

01:35.700 --> 01:41.260
And for my studies, I came to this idea to talk about this topic today.

01:41.700 --> 01:52.800
And the last thing about me, it's the first time I'm presenting, so thank you AppSecVillage for giving me this opportunity today to be in such an honorable stage as AppSecVillage and DEF CON.

01:52.820 --> 01:54.860
I truly appreciate it.

01:55.380 --> 01:56.280
And we'll begin.

01:56.280 --> 01:59.540
We'll begin by introducing what is SQL injection.

01:59.540 --> 02:06.940
SQL injection is a technique where attackers insert malicious SQL code into some input fields.

02:06.940 --> 02:12.120
It can be log-in forms, search boxes, or URL parameters.

02:12.700 --> 02:20.300
And they do it mainly to retrieve sensitive information from the database for the application.

02:21.020 --> 02:29.660
They can retrieve sensitive information, delete tables, and a lot of things that we'll see in the next slides.

02:30.580 --> 02:35.880
But the

02:50.440 --> 02:59.400
example that I like the most to show what it is, a SQL injection, is to see how it looks through the code.

02:59.480 --> 03:03.380
We have a query where the username and the password flows to its parameters.

03:04.120 --> 03:06.300
In the UI it looks something like this.

03:06.300 --> 03:08.000
You get a log-in form.

03:08.000 --> 03:12.380
It's like to demonstrate the most basic type of SQL injection.

03:12.960 --> 03:23.680
You have the username, you can enter admin, and some malicious payload to the password that basically means a single quote and some old condition that always evaluates to true.

03:24.240 --> 03:27.620
This flows to the query.

03:27.780 --> 03:33.580
The username gets the admin and the password gets some payload that always evaluates to true.

03:33.580 --> 03:46.720
And by that the attacker can bypass the authentication because it's sending it to the web application, sending it to its database, and it retrieves authentication bypass.

03:49.060 --> 03:53.240
We have some different types of SQL injection.

03:53.240 --> 03:56.020
First type called in-band or classic.

03:56.020 --> 04:02.960
What it means is that you see the results of your payload directly in HTTP response.

04:03.360 --> 04:10.920
Actually it also can be served as self-category, but I want to stick as many resources I'll state in it.

04:11.040 --> 04:16.560
So we have the in-band that you see the response directly into the web application.

04:16.620 --> 04:18.680
It also divided into two categories.

04:18.680 --> 04:20.400
One of them is error-based.

04:23.980 --> 04:33.300
Error-based, what it means is that you see the results of your payload that you rely on errors that you retrieve from the database to see some sensitive information.

04:34.940 --> 04:37.740
And you have union-based type.

04:38.180 --> 04:51.680
What it means in general, we will in a second see demonstration for this, but in one sentence union-based is concatenating two data, two data, so tables into one that contains both of them.

04:51.680 --> 04:56.960
Or we can say that it's two select statements that combined into one result.

04:57.200 --> 05:06.820
We combine to some expected data, additional concatenation of a table that retrieves sensitive information.

05:06.820 --> 05:09.120
We will see it in the next slides.

05:10.040 --> 05:19.500
So to demonstrate the error-based SQL injection, we can see that we should try to probe the application.

05:19.800 --> 05:28.540
Most of the times we will try through one single quote and two single quotes is the most type of entry points, but you have additional entry points and comments.

05:29.000 --> 05:38.380
And you're starting to get a sense of some error-based attack when you get from the one single quote 500 internal server error.

05:39.400 --> 05:43.600
And for the double single quotes, 200 okay.

05:43.600 --> 05:57.280
What it means is that the SQL query behind it in the back end cannot process the query correctly because it's not expected to receive 500 internal server error.

05:57.400 --> 06:00.260
And if you close it in single quotes, it suddenly is okay.

06:00.260 --> 06:05.100
So there's some probably manipulation that you can do on the SQL.

06:05.660 --> 06:07.720
So we'll try to do some manipulation.

06:07.720 --> 06:13.000
We can send a curl command that looks a bit messy, but it's very simple.

06:13.000 --> 06:19.800
It's trying to convert the version function that you sent to the database to retrieve its version.

06:19.900 --> 06:27.120
You try to convert it to an integer and compare it to one just so the well-closed will operate correctly.

06:28.200 --> 06:31.240
It will look something like this when it flows to the query.

06:32.860 --> 06:36.320
And you get the error, conversion failed.

06:38.140 --> 06:43.800
You get the MySQL that the server uses MySQL with a specific version.

06:43.920 --> 06:47.060
And by this, by this we retrieve a sensitive information.

06:47.400 --> 06:50.200
I want to state here that something important.

06:50.200 --> 06:56.860
I stick to this example of retrieving the version of the database in many additional slides that you will see later.

06:56.880 --> 06:59.940
I like this example because it's not too basic and not too advanced.

06:59.940 --> 07:03.020
It's something in the middle so it's easy to show it.

07:03.020 --> 07:08.360
But in these techniques you can do something even more advanced to retrieve hash passwords and so on.

07:08.540 --> 07:15.800
So, but we'll stick to the version because it's truly a real world example on one hand, but on the other hand it's not too complex.

07:16.920 --> 07:20.680
So, now we'll move to the union base as we showed before.

07:20.820 --> 07:28.740
And this presenting expected regular curl command to a server that I built.

07:28.740 --> 07:33.380
We send query equals to Alice and we'll retrieve some expected information.

07:33.860 --> 07:46.760
But when we try to manipulate with a union attack, we will edit a union, select the first, oh, the user that is currently connected to the database through the web application.

07:47.900 --> 07:53.340
We of course need to encode it and send it to the server and that's what we get.

07:53.340 --> 08:08.000
We get the Alice, the query equals to Alice as we saw before and we get the current user that's connected to the database for the web application and this is information that's not supposed to be retrieved, especially so easy.

08:08.000 --> 08:10.680
So, this is how union based attack looks like.

08:11.800 --> 08:17.080
After that we have many resources dividing into these categories.

08:17.260 --> 08:18.680
One of them is out of band.

08:18.680 --> 08:46.020
I won't elaborate about it too much because it's something not so popular, but to say it, to explain it in one or two sentences, out of band attacks are the kind of attacks that you cannot communicate with the web application, the server directly and you need to utilize some external server to exfiltrate data through the database and you use some HTTP request and DNS queries to exfiltrate this data,

08:46.020 --> 08:51.380
but it's something much, not so common, so we won't elaborate about it too much.

08:52.140 --> 09:00.080
The third category of attacks is in-kind, inferential or blind type of SQL injection is generally a bit of the opposite of the in-band of course.

09:00.300 --> 09:13.480
It's type of attacks that you cannot see your payload or the results of your payload directly in the web page and you need to infer the results of your payload from the behavior of the web application.

09:13.820 --> 09:17.640
It is divided into two categories, one of them is boolean based.

09:19.480 --> 09:22.700
I will explain by example what is boolean based and what is in-band.

09:22.700 --> 09:33.220
In-band is something that you can see the results of your payload , but generally speaking it evaluates your payload to true or false in some way of behavior of the web application and like that you can infer the results.

09:33.340 --> 09:38.160
To see an example of it, I will show you by demonstrating on B-Web.

09:38.320 --> 09:40.320
It's a buggy web application.

09:40.320 --> 09:43.260
It's a cool application to practice on.

09:43.260 --> 09:47.820
You can see here a payload of substring to the version of the database.

09:49.020 --> 09:59.520
In short, what it means, it takes the version, checks the field of character and compares it to 6 in this case and comments all the rest.

10:00.060 --> 10:06.400
We flow it to the search field and we see that the movie does not exist.

10:06.400 --> 10:14.220
But when we change the 6 to a 5 and we flow it again to the search box, we get that the movie does exist.

10:14.220 --> 10:21.480
So we can infer by that that when you compare it to 5, the first character of the version of the database is starting with a 5.

10:21.840 --> 10:33.520
And in this kind of blind SQL injections, you need to enumerate each character until you get the whole picture.

10:33.720 --> 10:35.420
But that's how it looks like.

10:38.780 --> 10:44.880
And the last type of inferential blind that we will focus a bit more today called time-based.

10:44.880 --> 10:51.460
Time-based in a way is similar to Boolean-based, but it relies on the time delays that you get from the server.

10:52.140 --> 11:00.360
And that's how you can infer your SQL payload by sending a time delay of, for example, 10 seconds.

11:00.360 --> 11:09.500
The database is delayed with its response for 10 seconds and that's how you can infer if your payload was evaluated to true or false.

11:12.990 --> 11:17.150
And that's how a time-blind SQL injection will look like.

11:17.150 --> 11:23.970
To my web server I added a parameter of elapsed time to see how much it takes for the server to respond.

11:24.210 --> 11:29.670
So in particular query where it equals to Alice, the elapsed time was immediate.

11:30.270 --> 11:42.270
But when we try to run a time-based payload, for example, it will look like this with closing single quote so the SQL payload will operate normally.

11:42.270 --> 11:59.070
And a sleep command that causes the server to delay for 5 seconds, we encode it and we will construct in the URL, sending it back, and we can suddenly see that with the sleep command of 5 seconds, the elapsed time was 5 seconds.

11:59.450 --> 12:03.650
So in general what it means is that the time delay was successfully executed.

12:04.910 --> 12:09.990
Before we continue about time delays, I want to elaborate a bit about tools that will be connected.

12:10.730 --> 12:14.530
There are many tools to uncover SQL injection.

12:14.530 --> 12:18.630
One of them is a bit less popular called Havij.

12:18.690 --> 12:27.390
I decided to include it because when I researched about Team Goshel, some resources stated they used this tool and I never met it before.

12:27.770 --> 12:38.690
And it's a tool that was used back then a few years ago, but it's still, people can use it today, but it's much less popular or a good tool.

12:39.370 --> 12:56.430
We have many DAS tools, like personally here is a BELP suite by Paul Swigel that can scan your site as a DAS tool and find the SQL injection as we see here in the picture that I scanned my web server.

12:56.850 --> 13:02.750
But the most common tool for SQL injection and uncovering them is called SQL Map.

13:04.010 --> 13:05.590
I'm so happy that I was able to use this tool.

13:07.270 --> 13:11.230
So, SQL Map will look something like this.

13:11.350 --> 13:14.870
You run SQL command on the URL that you want to scan.

13:14.870 --> 13:23.530
In this example, we see batch command, what it means is a non-interactive command that won't interfere in the process of executing.

13:23.550 --> 13:26.450
And please retrieve us the database version.

13:26.710 --> 13:36.310
When we run it, we can see that SQL Map uncovers that we have Boolean based, time based and union, union attack seal.

13:36.550 --> 13:42.910
And we see the stuff that we wanted to retrieve that the database uses SQLite behind the curtain.

13:44.170 --> 13:49.290
To show you, of course, SQL Map can do a bit more advanced stuff, like in this example.

13:51.110 --> 13:56.330
We can execute SQL Map with a time delay of 5 seconds.

13:56.790 --> 13:59.230
I'll run it with a batch command as before.

13:59.590 --> 14:04.610
And please return us the banner of the database.

14:04.790 --> 14:07.750
And we can see that it successfully works.

14:07.750 --> 14:14.010
We can retrieve the banner of equals to 8.3.0.

14:15.210 --> 14:19.190
And before I continue to the next slide, I want to emphasize something important.

14:20.430 --> 14:25.330
For my personal opinion, we cannot rely on many automation tools.

14:26.170 --> 14:31.370
We always need to have the ability to write our own scripts to some particular cases.

14:31.370 --> 14:32.590
We don't need to be afraid.

14:32.590 --> 14:36.830
And like in a perfect world, we need to master a combination of the two.

14:36.830 --> 14:41.330
We can master the automating tools and writing our own scripts.

14:41.810 --> 14:47.470
And a script of executing time delay can look something simple as this.

14:47.470 --> 14:53.130
We can have a script with, of course, some constants and some expected parameters.

14:53.130 --> 14:56.030
But in general, it will be divided into three functions.

14:56.130 --> 15:01.230
One function that will check the delay of the HTTP response and will record it.

15:01.850 --> 15:04.770
The second function will extract the version character.

15:04.770 --> 15:08.650
It takes the position that we are checking in our payload.

15:08.890 --> 15:11.150
It compares it to the character.

15:11.150 --> 15:14.050
Character enumerates for all the ASCII's.

15:14.310 --> 15:18.050
It compares to the position in the version that we want to retrieve.

15:18.050 --> 15:22.790
If it got the sleep time, then it means that we successfully executed it.

15:22.790 --> 15:25.590
Or if not, it didn't work.

15:26.150 --> 15:30.530
And the first function, it continues to enumerate all the ASCII's that we want to retrieve .

15:30.530 --> 15:36.610
It takes all the next indexes in the version number and recalls the version that we are retrieving of the database.

15:37.510 --> 15:41.590
And eventually it will look something like this when we are running it.

15:43.490 --> 15:45.370
Extracting the database version.

15:48.570 --> 15:50.170
So it's very simple.

15:50.170 --> 15:51.430
Simple as that.

15:52.010 --> 15:53.370
As we can see.

15:55.130 --> 16:01.410
To move to a bit more real world examples, I want to show you a few stuff.

16:01.410 --> 16:05.210
One of them, a real world example of a guy called Mola.

16:05.210 --> 16:08.690
Here is YouTube and his site.

16:08.690 --> 16:16.970
I really like to learn about real world examples because it really demonstrates what we need, what's truly important.

16:17.150 --> 16:27.410
And here he claims that he earned a bounty of $5,000 finding the next payload that you will see in a fast billing site.

16:28.550 --> 16:41.370
What he claims that he did to execute this bounty, he ran a steep command that we saw before, concatenated to some parameter that the site had, per page equals to one, and executed time delay.

16:41.770 --> 16:44.530
He got truly five seconds delay.

16:45.130 --> 16:47.070
Then he executed this payload.

16:47.070 --> 16:50.110
This payload is exactly as the substring we saw before.

16:50.110 --> 16:54.710
The mid is equal to the substring, but particular to MySQL version.

16:54.890 --> 16:57.290
And it checks the version fills character.

16:57.390 --> 17:00.290
If it equals to five, go to sleep for 15 seconds.

17:00.290 --> 17:01.930
If not, return zero.

17:02.150 --> 17:05.610
And in this case, it didn't get any delay.

17:05.630 --> 17:12.390
But when he changed the five to eight, he could successfully gain 15 seconds delay.

17:12.390 --> 17:14.230
And by that, he gained a bounty.

17:15.670 --> 17:22.990
Just to show you a bit more real world examples, one of them looks something like this.

17:22.990 --> 17:28.210
It's some bounty that uses XOR, an interesting payload that always evaluates to true.

17:28.210 --> 17:34.330
And some bounty that was discovered in Department of Defense in HackerOne system.

17:34.630 --> 17:48.730
The second one was pretty simple concatenation to expected parameters of sleep seven seconds, also disclosed to HackerOne and found in the automatic website.

17:49.070 --> 17:55.870
And the third one, my favorite, combines script, union and sleep commands.

17:55.870 --> 18:00.170
Some real combination of all of them.

18:04.310 --> 18:12.690
And the third bounty gained, what I found from resources when I checked it, got bounty of $2,100.

18:14.490 --> 18:23.130
So, all of those stuff that we seen was utilized by Tim Gorshel in the past.

18:23.130 --> 18:28.350
They used a lot of SQL injection, especially time delays, something given what they did.

18:28.350 --> 18:31.570
They were operating in 2012.

18:32.090 --> 18:39.590
And they utilized even simpler SQL commands that we saw before.

18:40.070 --> 18:43.710
And as I said, they were operating in 2012.

18:43.710 --> 18:47.230
They are not related to APT39 or some Iranian government.

18:47.230 --> 18:49.730
They actually were a hacktivist group.

18:51.330 --> 18:56.050
I'm just curious, how many people of you know what hacktivism is?

18:56.050 --> 18:57.330
Please raise your hands.

18:58.090 --> 18:59.550
Okay, okay, not bad.

18:59.630 --> 19:01.010
Approximately half.

19:01.010 --> 19:13.290
So, hacktivism is when you attack a group that is trying to promote some political change or some social agenda that you believe in and you promote it by hacking.

19:13.410 --> 19:15.750
And that's what Tim Gorshel will.

19:15.750 --> 19:17.910
They were a hacktivist collective.

19:18.970 --> 19:24.350
And just to see what they did and who they were, they started to operate in 2012.

19:24.350 --> 19:30.990
They hacked the University of Arkansas because one of the guys there called Zoom was arrested.

19:31.010 --> 19:33.590
So, they hacked it in terms of protest.

19:34.650 --> 19:40.830
After that, DeadMallocs was appealed.

19:40.830 --> 19:42.790
DeadMallocs was the admin of the group.

19:42.790 --> 19:52.170
He appealed in their main communication channel in Facebook stating that he doesn't, in an ironic way, that he doesn't want to fight with FBI or CIA or something like this.

19:52.170 --> 19:58.590
But on the other hand, we will leak a bunch of stuff in the coming year.

19:58.630 --> 20:06.090
So, as he promised, he started, they started to attack the government, make additional hacking projects.

20:06.110 --> 20:14.750
They had Project Dragonfly where they hacked China government and leaked thousands of sensitive information.

20:15.070 --> 20:20.570
It included like hash passwords, some personal data and like everything they got.

20:20.630 --> 20:21.790
Later, Hellfire.

20:21.790 --> 20:27.590
In Project Hellfire, they hacked governments, financial sectors and other companies.

20:27.610 --> 20:35.070
In Project West Wing, they focused on universities around the globe from Harvard, Stanford to University of Rome and Tokyo.

20:35.730 --> 20:40.810
And they even declared a war in Project Black Star against Russia.

20:42.850 --> 20:56.570
In all of these projects, they hacked like, they leaked thousands to millions of records from personal information to hash passwords, as I said before.

20:56.570 --> 21:00.650
But many of this information was publicly already disclosed.

21:00.650 --> 21:05.790
Still, on the other hand, it was sensitive information that truly was released.

21:05.790 --> 21:15.070
But what they achieved through it, they achieved their main cause, to raise awareness to their hacktivism and to their operations.

21:16.170 --> 21:21.510
So, later, in Project White Fox, they basically hacked everyone to raise awareness to hacktivism.

21:21.510 --> 21:26.110
And they introduced their new cool logo.

21:27.890 --> 21:30.850
Later came Sunrise Hacks of Africa.

21:31.350 --> 21:39.990
2015 introduced a new term of dark hacktivism that's raising the normal hacktivism into cyber warfare levels in a much more scale.

21:40.090 --> 21:45.390
And in 2016, this story came to an end when Dead Melox, the leader, came clean.

21:45.390 --> 21:49.950
He came clean to some newspaper, sent them an email that, hi, it's me.

21:49.990 --> 21:54.230
I'm Eugene, the man who's behind Dead Melox, the leader of Team Goshel.

21:54.230 --> 21:57.070
He sent his passport and even a picture.

21:57.210 --> 22:06.150
They still didn't believe him, so he posted on his Twitter account to the next web, the journal that he came clean to, that, hello, it's truly me.

22:08.230 --> 22:12.270
So, why they did what they did?

22:12.510 --> 22:14.550
It's typical for hacktivism.

22:14.830 --> 22:23.630
For example, Westmin, they hacked to raise awareness to the foreign students' standards of the education today.

22:23.890 --> 22:31.050
In Blackstar, they claimed that the Russian is a government of tyranny and regret.

22:31.050 --> 22:34.030
They criticized their government.

22:34.610 --> 22:42.530
In White Fox, essentially, they wanted to promote hacktivism worldwide and draw attention to the freedom of information.

22:43.390 --> 22:50.510
And they had many other causes, like even in Japan, they wanted to piss them off just as it is.

22:51.470 --> 22:55.310
So, I want all of you to know this today.

22:55.310 --> 23:03.650
I know that you are thinking SQL injection is old and Team Goshel was operated in 2012, but I will show you that what is old is still worth gold.

23:04.430 --> 23:06.130
We can see some statistics.

23:06.130 --> 23:10.150
In our top ten, SQL injection is part of the injection section.

23:10.150 --> 23:11.850
It's still on the top.

23:12.090 --> 23:16.250
In many years, it was the first one and now it's like the third one.

23:18.930 --> 23:22.210
Oops, it confused me for a second.

23:22.450 --> 23:24.590
Yes, it was.

23:24.790 --> 23:32.550
NVD is ranking SQL injection in the second place for many, many years.

23:33.030 --> 23:38.930
It's considered one of the most stubborn weaknesses ranked in the third place by Mitre.

23:39.530 --> 23:50.050
And GitHub security advisor also stating that, and it's truly stated that SQL injection is not relevant to modern languages like Vue, React, Python, stuff like this.

23:50.050 --> 24:03.870
But for my opinion, what's important to know here is that the concepts or the mindset that you set for yourself when you are learning about these attacks can be implemented to many other fields because they are all related.

24:03.870 --> 24:07.010
You can use similar techniques to other attacks.

24:07.930 --> 24:15.150
And if I still didn't convince you, you can earn bug bounties easily using those kinds of techniques like this one.

24:15.290 --> 24:19.390
It was disclosed critical vulnerability to Department of Defense.

24:21.430 --> 24:25.090
And so we are coming to an end and I want to leave you with some homework.

24:25.090 --> 24:30.510
I don't want to state here ten resources, but I want to state one and good one that I use.

24:30.510 --> 24:33.570
I don't get money by PulseWiggle, by the way.

24:33.630 --> 24:39.290
I truly recommend them because it's free resource, theoretical and practical combined.

24:39.290 --> 24:41.610
Very recommended and it dives deep.

24:42.470 --> 24:51.070
So to recap, it's hard to make a 25 minute lecture because I want to talk about many stuff and I only have 25 minutes.

24:51.070 --> 24:56.910
So I tried my best and if you gain even one small little thing today, I will be genuinely happy.

24:58.070 --> 25:02.230
And that's it if you want to connect with me like LinkedIn and Twitter.

25:02.510 --> 25:03.370
And that's it.

