[00:00.720 --> 00:07.620] All right, folks. It is that time. If you have a seat that is in between you, please collapse [00:07.620 --> 00:14.180] down. Specifically you, sir. Thank you very much. If you would bring it in close. All right. [00:14.180 --> 00:18.640] With that, we are going to go ahead and kick everything off. I would like to introduce Iggy [00:18.640 --> 00:33.500] to the stage. Thank you. So hello, DEF CON, and welcome to my talk called Ticking SQLI. And we [00:33.500 --> 00:40.240] will begin. So what's in it for you today? Today we will explore types of SQL injection. We [00:40.240 --> 00:47.600] will focus a bit on time-based SQL injection. We will see the impact Team Ghost Shell did in [00:47.600 --> 00:52.860] the past using these kinds of techniques. We will understand why it's still relevant today. And [00:52.860 --> 00:58.900] you will have a good time with a pretty much good presenter today. So who am I? My name is [00:58.900 --> 01:04.620] Igor, but please call me Iggy. It's my nickname since childhood. I'm a security engineer at [01:04.620 --> 01:13.300] Axonius. One sentence about Axonius is it's a cybersecurity asset management platform that maps [01:13.300 --> 01:18.840] all your digital assets across your organization, normalizes them, duplicates them, and gives [01:18.840 --> 01:24.160] you comprehensive insights about them and much more. And why am I here today? I'm here today [01:24.160 --> 01:31.880] because I love learning stuff, especially in cybersecurity, from low level to high level, from [01:31.880 --> 01:38.900] lock-picking to RFIDs, and I'm studying a lot. And for my studies, I came to this idea to talk [01:38.900 --> 01:44.660] about this topic today. And the last thing about me, it's the first time I'm presenting, so [01:44.660 --> 01:50.440] thank you AppSecVillage for giving me this opportunity today to be in such an honorable stage [01:50.440 --> 01:57.860] as AppSecVillage and DEF CON. I truly appreciate it. And we'll begin. We'll begin by introducing [01:57.860 --> 02:05.900] what is SQL injection. SQL injection is a technique where attackers insert malicious SQL code into [02:05.900 --> 02:15.720] some input fields. It can be log-in forms, search boxes, or URL parameters. And they do it mainly [02:15.720 --> 02:22.240] to retrieve sensitive information from the database for the application. They can retrieve [02:22.240 --> 02:35.880] sensitive information, delete tables, and a lot of things that we'll see in the next slides. But the [02:50.440 --> 02:58.780] example that I like the most to show what it is, a SQL injection, is to see how it looks through the [02:58.780 --> 03:04.840] code. We have a query where the username and the password flows to its parameters. In the UI it [03:04.840 --> 03:10.920] looks something like this. You get a log-in form. It's like to demonstrate the most basic type of [03:10.920 --> 03:17.220] SQL injection. You have the username, you can enter admin, and some malicious payload to the [03:17.220 --> 03:22.800] password that basically means a single quote and some old condition that always evaluates to [03:22.800 --> 03:32.200] true. This flows to the query. The username gets the admin and the password gets some payload [03:32.200 --> 03:37.800] that always evaluates to true. And by that the attacker can bypass the authentication because it's [03:38.400 --> 03:45.560] sending it to the web application, sending it to its database, and it retrieves authentication [03:45.560 --> 03:56.340] bypass. We have some different types of SQL injection. First type called in-band or classic. What [03:56.340 --> 04:04.860] it means is that you see the results of your payload directly in HTTP response. Actually it also can be [04:04.860 --> 04:12.560] served as self-category, but I want to stick as many resources I'll state in it. So we have the in-band [04:12.560 --> 04:18.800] that you see the response directly into the web application. It also divided into two categories. One [04:18.800 --> 04:26.320] of them is error-based. Error-based, what it means is that you see the results of your payload [04:26.340 --> 04:35.580] that you rely on errors that you retrieve from the database to see some sensitive information. And you [04:35.580 --> 04:42.260] have union-based type. What it means in general, we will in a second see demonstration for this, but in [04:42.260 --> 04:51.000] one sentence union-based is concatenating two data, two data, so tables into one that contains both of [04:51.000 --> 04:59.000] them. Or we can say that it's two select statements that combined into one result. We combine to some [04:59.820 --> 05:07.200] expected data, additional concatenation of a table that retrieves sensitive information. We will see [05:07.200 --> 05:17.820] it in the next slides. So to demonstrate the error-based SQL injection, we can see that we should try to [05:17.820 --> 05:24.140] probe the application. Most of the times we will try through one single quote and two single quotes is the [05:24.140 --> 05:30.440] most type of entry points, but you have additional entry points and comments. And you're starting to get [05:30.580 --> 05:40.960] a sense of some error-based attack when you get from the one single quote 500 internal server error. And for [05:40.960 --> 05:47.180] the double single quotes, 200 okay. What it means is that the SQL query behind it in the back end [05:47.180 --> 05:57.800] cannot process the query correctly because it's not expected to receive 500 internal server error. And if [05:57.800 --> 06:02.960] you close it in single quotes, it suddenly is okay. So there's some probably manipulation that you can [06:02.960 --> 06:11.840] do on the SQL. So we'll try to do some manipulation. We can send a curl command that looks a bit messy, but [06:11.840 --> 06:18.900] it's very simple. It's trying to convert the version function that you sent to the database to retrieve its [06:18.900 --> 06:26.120] version. You try to convert it to an integer and compare it to one just so the well-closed will operate [06:26.120 --> 06:35.080] correctly. It will look something like this when it flows to the query. And you get the error, conversion [06:35.080 --> 06:45.080] failed. You get the MySQL that the server uses MySQL with a specific version. And by this, by this we [06:45.080 --> 06:51.600] retrieve a sensitive information. I want to state here that something important. I stick to this example of [06:52.480 --> 06:57.820] retrieving the version of the database in many additional slides that you will see later. I like this example [06:57.820 --> 07:03.660] because it's not too basic and not too advanced. It's something in the middle so it's easy to show it. But in [07:03.660 --> 07:09.420] these techniques you can do something even more advanced to retrieve hash passwords and so on. So, but we'll [07:09.420 --> 07:14.960] stick to the version because it's truly a real world example on one hand, but on the other hand it's not too [07:14.960 --> 07:26.340] complex. So, now we'll move to the union base as we showed before. And this presenting expected regular curl [07:26.340 --> 07:32.580] command to a server that I built. We send query equals to Alice and we'll retrieve some expected [07:32.580 --> 07:40.820] information. But when we try to manipulate with a union attack, we will edit a union, select the first, oh, the user [07:40.820 --> 07:51.720] that is currently connected to the database through the web application. We of course need to encode it and send it [07:51.720 --> 07:59.260] to the server and that's what we get. We get the Alice, the query equals to Alice as we saw before and we get the [07:59.260 --> 08:05.720] current user that's connected to the database for the web application and this is information that's not supposed to [08:05.720 --> 08:14.900] be retrieved, especially so easy. So, this is how union based attack looks like. After that we have many resources [08:14.900 --> 08:22.720] dividing into these categories. One of them is out of band. I won't elaborate about it too much because it's something [08:22.720 --> 08:31.320] 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 [08:31.320 --> 08:38.020] cannot communicate with the web application, the server directly and you need to utilize some external server to [08:38.020 --> 08:46.420] exfiltrate data through the database and you use some HTTP request and DNS queries to exfiltrate this data, but it's [08:46.420 --> 08:52.700] something much, not so common, so we won't elaborate about it too much. The third category of attacks is [08:52.720 --> 09:00.620] in-kind, inferential or blind type of SQL injection is generally a bit of the opposite of the in-band of course. It's [09:00.620 --> 09:08.020] type of attacks that you cannot see your payload or the results of your payload directly in the web page and you need [09:08.020 --> 09:15.940] to infer the results of your payload from the behavior of the web application. It is divided into two categories, one [09:15.940 --> 09:22.700] of them is boolean based. I will explain by example what is boolean based and what is in-band. In-band is [09:22.720 --> 09:27.840] something that you can see the results of your payload, but generally speaking it evaluates your payload to true or false in [09:27.840 --> 09:35.120] some way of behavior of the web application and like that you can infer the results. To see an example of it, I will show [09:35.120 --> 09:44.280] you by demonstrating on B-Web. It's a buggy web application. It's a cool application to practice on. You can see here a [09:44.280 --> 09:52.700] payload of substring to the version of the database. In short, what it means, it takes the version, checks the field of [09:52.720 --> 10:04.400] character and compares it to 6 in this case and comments all the rest. We flow it to the search field and we see that the [10:04.400 --> 10:13.500] movie does not exist. But when we change the 6 to a 5 and we flow it again to the search box, we get that the movie does [10:13.500 --> 10:20.080] exist. So we can infer by that that when you compare it to 5, the first character of the version of the database is [10:20.080 --> 10:32.500] starting with a 5. And in this kind of blind SQL injections, you need to enumerate each character until you get the [10:32.500 --> 10:43.780] whole picture. But that's how it looks like. And the last type of inferential blind that we will focus a bit more today [10:43.780 --> 10:50.160] called time-based. Time-based in a way is similar to Boolean-based, but it relies on the time delays that you get [10:50.160 --> 11:00.360] from the server. And that's how you can infer your SQL payload by sending a time delay of, for example, 10 seconds. [11:00.360 --> 11:07.860] The database is delayed with its response for 10 seconds and that's how you can infer if your payload was evaluated to [11:07.860 --> 11:20.730] true or false. And that's how a time-blind SQL injection will look like. To my web server I added a parameter of elapsed [11:20.730 --> 11:28.010] time to see how much it takes for the server to respond. So in particular query where it equals to Alice, the elapsed [11:28.010 --> 11:37.250] time was immediate. But when we try to run a time-based payload, for example, it will look like this with closing [11:37.250 --> 11:45.810] single quote so the SQL payload will operate normally. And a sleep command that causes the server to delay for 5 [11:45.810 --> 11:55.470] seconds, we encode it and we will construct in the URL, sending it back, and we can suddenly see that with the sleep [11:55.470 --> 12:01.710] command of 5 seconds, the elapsed time was 5 seconds. So in general what it means is that the time delay was [12:01.710 --> 12:09.010] successfully executed. Before we continue about time delays, I want to elaborate a bit about tools that will be [12:09.010 --> 12:19.530] connected. There are many tools to uncover SQL injection. One of them is a bit less popular called Havij. I decided to [12:19.530 --> 12:26.470] include it because when I researched about Team Goshel, some resources stated they used this tool and I never met it [12:26.470 --> 12:35.610] before. 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 [12:35.610 --> 12:48.910] less popular or a good tool. We have many DAS tools, like personally here is a BELP suite by Paul Swigel that can scan your [12:48.910 --> 12:58.430] site as a DAS tool and find the SQL injection as we see here in the picture that I scanned my web server. But the most common [12:58.430 --> 13:05.590] tool for SQL injection and uncovering them is called SQL Map. I'm so happy that I was able to use this tool. [13:07.270 --> 13:15.790] So, SQL Map will look something like this. You run SQL command on the URL that you want to scan. In this example, we see [13:15.790 --> 13:23.990] batch command, what it means is a non-interactive command that won't interfere in the process of executing. And please [13:23.990 --> 13:33.210] retrieve us the database version. When we run it, we can see that SQL Map uncovers that we have Boolean based, time [13:33.210 --> 13:41.630] based and union, union attack seal. And we see the stuff that we wanted to retrieve that the database uses SQLite [13:41.630 --> 13:51.770] behind the curtain. To show you, of course, SQL Map can do a bit more advanced stuff, like in this example. We can [13:51.770 --> 14:02.210] execute SQL Map with a time delay of 5 seconds. I'll run it with a batch command as before. And please return us the [14:02.210 --> 14:14.010] banner of the database. And we can see that it successfully works. We can retrieve the banner of equals to 8.3.0. [14:15.210 --> 14:22.810] And before I continue to the next slide, I want to emphasize something important. For my personal opinion, we cannot [14:22.810 --> 14:30.530] rely on many automation tools. We always need to have the ability to write our own scripts to some particular [14:30.530 --> 14:37.010] cases. We don't need to be afraid. And like in a perfect world, we need to master a combination of the two. We can [14:37.010 --> 14:45.130] master the automating tools and writing our own scripts. And a script of executing time delay can look something [14:45.770 --> 14:54.090] simple as this. We can have a script with, of course, some constants and some expected parameters. But in general, it [14:54.090 --> 15:00.510] will be divided into three functions. One function that will check the delay of the HTTP response and will record [15:00.530 --> 15:07.830] it. The second function will extract the version character. It takes the position that we are checking in our [15:07.830 --> 15:16.090] payload. It compares it to the character. Character enumerates for all the ASCII's. It compares to the position in [15:16.090 --> 15:22.990] the version that we want to retrieve. If it got the sleep time, then it means that we successfully executed it. Or [15:22.990 --> 15:30.510] if not, it didn't work. And the first function, it continues to enumerate all the ASCII's that we want to [15:30.530 --> 15:35.710] retrieve. It takes all the next indexes in the version number and recalls the version that we are retrieving of [15:35.710 --> 15:44.550] the database. And eventually it will look something like this when we are running it. Extracting the database [15:44.550 --> 15:58.310] version. So it's very simple. Simple as that. As we can see. To move to a bit more real world examples, I want to [15:58.310 --> 16:08.990] show you a few stuff. One of them, a real world example of a guy called Mola. Here is YouTube and his site. I [16:08.990 --> 16:16.010] really like to learn about real world examples because it really demonstrates what we need, what's truly [16:16.010 --> 16:25.290] important. And here he claims that he earned a bounty of $5,000 finding the next payload that you will see in a [16:25.290 --> 16:33.170] fast billing site. What he claims that he did to execute this bounty, he ran a steep command that we saw [16:33.170 --> 16:42.210] before, concatenated to some parameter that the site had, per page equals to one, and executed time delay. He got [16:42.210 --> 16:50.230] truly five seconds delay. Then he executed this payload. This payload is exactly as the substring we saw before. The [16:50.230 --> 16:56.510] mid is equal to the substring, but particular to MySQL version. And it checks the version fills [16:56.510 --> 17:04.930] character. If it equals to five, go to sleep for 15 seconds. If not, return zero. And in this case, it didn't get any [17:04.930 --> 17:13.270] delay. But when he changed the five to eight, he could successfully gain 15 seconds delay. And by that, he gained [17:13.450 --> 17:23.790] a bounty. Just to show you a bit more real world examples, one of them looks something like this. It's some bounty [17:23.790 --> 17:30.270] that uses XOR, an interesting payload that always evaluates to true. And some bounty that was discovered in [17:30.270 --> 17:39.570] Department of Defense in HackerOne system. The second one was pretty simple concatenation to expected [17:39.570 --> 17:49.630] parameters of sleep seven seconds, also disclosed to HackerOne and found in the automatic website. And the third [17:49.630 --> 18:05.670] one, my favorite, combines script, union and sleep commands. Some real combination of all of them. And the third [18:05.670 --> 18:19.250] bounty gained, what I found from resources when I checked it, got bounty of $2,100. So, all of those stuff that we [18:19.250 --> 18:26.710] seen was utilized by Tim Gorshel in the past. They used a lot of SQL injection, especially time delays, something [18:26.710 --> 18:35.650] given what they did. They were operating in 2012. And they utilized even simpler SQL commands that we [18:37.910 --> 18:46.590] saw before. And as I said, they were operating in 2012. They are not related to APT39 or some Iranian [18:46.590 --> 18:54.570] government. They actually were a hacktivist group. I'm just curious, how many people of you know what [18:54.570 --> 19:02.750] hacktivism is? Please raise your hands. Okay, okay, not bad. Approximately half. So, hacktivism is when [19:02.750 --> 19:10.570] you attack a group that is trying to promote some political change or some social agenda that you believe [19:10.570 --> 19:19.210] in and you promote it by hacking. And that's what Tim Gorshel will. They were a hacktivist collective. And [19:19.210 --> 19:25.250] just to see what they did and who they were, they started to operate in 2012. They hacked the University [19:25.250 --> 19:32.730] of Arkansas because one of the guys there called Zoom was arrested. So, they hacked it in terms of [19:32.750 --> 19:43.130] protest. After that, DeadMallocs was appealed. DeadMallocs was the admin of the group. He appealed [19:43.130 --> 19:49.050] in their main communication channel in Facebook stating that he doesn't, in an ironic way, that he [19:49.050 --> 19:54.570] doesn't want to fight with FBI or CIA or something like this. But on the other hand, we will leak a [19:54.570 --> 20:02.730] bunch of stuff in the coming year. So, as he promised, he started, they started to attack the [20:02.750 --> 20:10.070] government, make additional hacking projects. They had Project Dragonfly where they hacked China [20:10.070 --> 20:17.370] government and leaked thousands of sensitive information. It included like hash passwords, some [20:17.370 --> 20:23.150] personal data and like everything they got. Later, Hellfire. In Project Hellfire, they hacked [20:23.150 --> 20:29.150] governments, financial sectors and other companies. In Project West Wing, they focused on [20:29.150 --> 20:36.670] universities around the globe from Harvard, Stanford to University of Rome and Tokyo. And they [20:36.670 --> 20:45.850] even declared a war in Project Black Star against Russia. In all of these projects, they hacked [20:45.850 --> 20:55.690] like, they leaked thousands to millions of records from personal information to hash passwords, as [20:55.690 --> 21:01.770] I said before. But many of this information was publicly already disclosed. Still, on the other [21:01.770 --> 21:09.290] hand, it was sensitive information that truly was released. But what they achieved through it, they [21:09.290 --> 21:16.610] achieved their main cause, to raise awareness to their hacktivism and to their operations. So, [21:16.610 --> 21:21.970] later, in Project White Fox, they basically hacked everyone to raise awareness to hacktivism. And [21:21.970 --> 21:33.570] they introduced their new cool logo. Later came Sunrise Hacks of Africa. 2015 introduced a new term [21:33.570 --> 21:39.070] of dark hacktivism that's raising the normal hacktivism into cyber warfare levels in a much more [21:39.070 --> 21:46.070] scale. And in 2016, this story came to an end when Dead Melox, the leader, came clean. He came clean to [21:46.070 --> 21:53.210] some newspaper, sent them an email that, hi, it's me. I'm Eugene, the man who's behind Dead Melox, [21:53.210 --> 21:59.150] the leader of Team Goshel. He sent his passport and even a picture. They still didn't believe him, [21:59.150 --> 22:04.890] so he posted on his Twitter account to the next web, the journal that he came clean to, that, hello, [22:04.890 --> 22:15.890] it's truly me. So, why they did what they did? It's typical for hacktivism. For example, Westmin, [22:15.890 --> 22:24.670] they hacked to raise awareness to the foreign students' standards of the education today. In Blackstar, [22:24.670 --> 22:34.030] they claimed that the Russian is a government of tyranny and regret. They criticized their government. [22:34.610 --> 22:40.650] In White Fox, essentially, they wanted to promote hacktivism worldwide and draw attention to the [22:40.650 --> 22:47.930] freedom of information. And they had many other causes, like even in Japan, they wanted to piss [22:47.930 --> 22:56.890] them off just as it is. So, I want all of you to know this today. I know that you are thinking SQL [22:56.890 --> 23:02.630] injection is old and Team Goshel was operated in 2012, but I will show you that what is old is still [23:02.630 --> 23:09.390] worth gold. We can see some statistics. In our top ten, SQL injection is part of the injection [23:09.390 --> 23:16.250] section. It's still on the top. In many years, it was the first one and now it's like the third one. [23:18.930 --> 23:31.570] Oops, it confused me for a second. Yes, it was. NVD is ranking SQL injection in the second place for many, [23:31.570 --> 23:40.050] many years. It's considered one of the most stubborn weaknesses ranked in the third place by Mitre. And [23:41.230 --> 23:47.070] GitHub security advisor also stating that, and it's truly stated that SQL injection is not relevant to [23:47.070 --> 23:52.750] modern languages like Vue, React, Python, stuff like this. But for my opinion, what's important to [23:52.750 --> 23:58.390] know here is that the concepts or the mindset that you set for yourself when you are learning about [23:58.390 --> 24:04.490] these attacks can be implemented to many other fields because they are all related. You can use [24:04.490 --> 24:10.850] similar techniques to other attacks. And if I still didn't convince you, you can earn [24:10.850 --> 24:17.010] bug bounties easily using those kinds of techniques like this one. It was disclosed critical [24:17.010 --> 24:23.970] vulnerability to Department of Defense. And so we are coming to an end and I want to leave you [24:23.970 --> 24:29.310] with some homework. I don't want to state here ten resources, but I want to state one and good one [24:29.310 --> 24:35.510] that I use. I don't get money by PulseWiggle, by the way. I truly recommend them because it's free [24:35.510 --> 24:44.090] resource, theoretical and practical combined. Very recommended and it dives deep. So to recap, [24:44.090 --> 24:50.250] it's hard to make a 25 minute lecture because I want to talk about many stuff and I only have 25 [24:50.250 --> 24:56.010] minutes. So I tried my best and if you gain even one small little thing today, I will be genuinely [24:56.010 --> 25:03.370] happy. And that's it if you want to connect with me like LinkedIn and Twitter. And that's it.