All right, folks. It is that time. If you have a seat that is in between you, please collapse down. Specifically you, sir. Thank you very much. If you would bring it in close. All right. With that, we are going to go ahead and kick everything off. I would like to introduce Iggy to the stage. Thank you. So hello, DEF CON, and welcome to my talk called Ticking SQLI. And we will begin. So what's in it for you today? Today we will explore types of SQL injection. We will focus a bit on time-based SQL injection. We will see the impact Team Ghost Shell did in the past using these kinds of techniques. We will understand why it's still relevant today. And you will have a good time with a pretty much good presenter today. So who am I? My name is Igor, but please call me Iggy. It's my nickname since childhood. I'm a security engineer at Axonius. 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. And why am I here today? 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. And for my studies, I came to this idea to talk about this topic today. 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. I truly appreciate it. And we'll begin. We'll begin by introducing what is SQL injection. SQL injection is a technique where attackers insert malicious SQL code into some input fields. It can be log-in forms, search boxes, or URL parameters. And they do it mainly to retrieve sensitive information from the database for the application. They can retrieve sensitive information, delete tables, and a lot of things that we'll see in the next slides. But the example that I like the most to show what it is, a SQL injection, is to see how it looks through the code. We have a query where the username and the password flows to its parameters. In the UI it looks something like this. You get a log-in form. It's like to demonstrate the most basic type of SQL injection. 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. This flows to the query. The username gets the admin and the password gets some payload that always evaluates to true. 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. We have some different types of SQL injection. First type called in-band or classic. What it means is that you see the results of your payload directly in HTTP response. Actually it also can be served as self-category, but I want to stick as many resources I'll state in it. So we have the in-band that you see the response directly into the web application. It also divided into two categories. One of them is error-based. 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. And you have union-based type. 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. Or we can say that it's two select statements that combined into one result. We combine to some expected data, additional concatenation of a table that retrieves sensitive information. We will see it in the next slides. So to demonstrate the error-based SQL injection, we can see that we should try to probe the application. 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. 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. And for the double single quotes, 200 okay. 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. And if you close it in single quotes, it suddenly is okay. So there's some probably manipulation that you can do on the SQL. So we'll try to do some manipulation. We can send a curl command that looks a bit messy, but it's very simple. It's trying to convert the version function that you sent to the database to retrieve its version. You try to convert it to an integer and compare it to one just so the well-closed will operate correctly. It will look something like this when it flows to the query. And you get the error, conversion failed. You get the MySQL that the server uses MySQL with a specific version. And by this, by this we retrieve a sensitive information. I want to state here that something important. I stick to this example of retrieving the version of the database in many additional slides that you will see later. I like this example 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 these techniques you can do something even more advanced to retrieve hash passwords and so on. 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. So, now we'll move to the union base as we showed before. And this presenting expected regular curl command to a server that I built. We send query equals to Alice and we'll retrieve some expected information. 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. We of course need to encode it and send it 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 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. So, this is how union based attack looks like. After that we have many resources dividing into these categories. One of them is out of band. 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, but it's something much, not so common, so we won't elaborate about it too much. 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. 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. It is divided into two categories, one of them is boolean based. I will explain by example what is boolean based and what is in-band. 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. To see an example of it, I will show 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 payload of substring to the version of the database. 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. We flow it to the search field and we see that the 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 exist. 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. And in this kind of blind SQL injections, you need to enumerate each character until you get the whole picture. But that's how it looks like. And the last type of inferential blind that we will focus a bit more today called time-based. Time-based in a way is similar to Boolean-based, but it relies on the time delays that you get from the server. And that's how you can infer your SQL payload by sending a time delay of, for example, 10 seconds. 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. And that's how a time-blind SQL injection will look like. To my web server I added a parameter of elapsed time to see how much it takes for the server to respond. So in particular query where it equals to Alice, the elapsed time was immediate. 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. 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. So in general what it means is that the time delay was successfully executed. Before we continue about time delays, I want to elaborate a bit about tools that will be connected. There are many tools to uncover SQL injection. One of them is a bit less popular called Havij. 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. 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. 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. But the most common tool for SQL injection and uncovering them is called SQL Map. I'm so happy that I was able to use this tool. 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 batch command, what it means is a non-interactive command that won't interfere in the process of executing. And please retrieve us the database version. When we run it, we can see that SQL Map uncovers that we have Boolean based, time based and union, union attack seal. And we see the stuff that we wanted to retrieve that the database uses SQLite behind the curtain. To show you, of course, SQL Map can do a bit more advanced stuff, like in this example. We can 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 banner of the database. And we can see that it successfully works. We can retrieve the banner of equals to 8.3.0. And before I continue to the next slide, I want to emphasize something important. For my personal opinion, we cannot rely on many automation tools. We always need to have the ability to write our own scripts to some particular 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 master the automating tools and writing our own scripts. And a script of executing time delay can look something simple as this. We can have a script with, of course, some constants and some expected parameters. But in general, it will be divided into three functions. One function that will check the delay of the HTTP response and will record it. The second function will extract the version character. It takes the position that we are checking in our payload. It compares it to the character. Character enumerates for all the ASCII's. It compares to the position in the version that we want to retrieve. If it got the sleep time, then it means that we successfully executed it. Or if not, it didn't work. And the first function, it continues to enumerate all the ASCII's that we want to retrieve. It takes all the next indexes in the version number and recalls the version that we are retrieving of the database. And eventually it will look something like this when we are running it. Extracting the database 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 show you a few stuff. One of them, a real world example of a guy called Mola. Here is YouTube and his site. I really like to learn about real world examples because it really demonstrates what we need, what's truly important. 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. 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. He got truly five seconds delay. Then he executed this payload. This payload is exactly as the substring we saw before. The mid is equal to the substring, but particular to MySQL version. And it checks the version fills 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 delay. But when he changed the five to eight, he could successfully gain 15 seconds delay. And by that, he gained a bounty. Just to show you a bit more real world examples, one of them looks something like this. It's some bounty that uses XOR, an interesting payload that always evaluates to true. And some bounty that was discovered in Department of Defense in HackerOne system. The second one was pretty simple concatenation to expected parameters of sleep seven seconds, also disclosed to HackerOne and found in the automatic website. And the third one, my favorite, combines script, union and sleep commands. Some real combination of all of them. And the third bounty gained, what I found from resources when I checked it, got bounty of $2,100. So, all of those stuff that we seen was utilized by Tim Gorshel in the past. They used a lot of SQL injection, especially time delays, something given what they did. They were operating in 2012. And they utilized even simpler SQL commands that we saw before. And as I said, they were operating in 2012. They are not related to APT39 or some Iranian government. They actually were a hacktivist group. I'm just curious, how many people of you know what hacktivism is? Please raise your hands. Okay, okay, not bad. Approximately half. 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. And that's what Tim Gorshel will. They were a hacktivist collective. And just to see what they did and who they were, they started to operate in 2012. They hacked the University of Arkansas because one of the guys there called Zoom was arrested. So, they hacked it in terms of protest. After that, DeadMallocs was appealed. DeadMallocs was the admin of the group. 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. But on the other hand, we will leak a bunch of stuff in the coming year. So, as he promised, he started, they started to attack the government, make additional hacking projects. They had Project Dragonfly where they hacked China government and leaked thousands of sensitive information. It included like hash passwords, some personal data and like everything they got. Later, Hellfire. In Project Hellfire, they hacked governments, financial sectors and other companies. In Project West Wing, they focused on universities around the globe from Harvard, Stanford to University of Rome and Tokyo. And they even declared a war in Project Black Star against Russia. 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. But many of this information was publicly already disclosed. Still, on the other hand, it was sensitive information that truly was released. But what they achieved through it, they achieved their main cause, to raise awareness to their hacktivism and to their operations. So, later, in Project White Fox, they basically hacked everyone to raise awareness to hacktivism. And they introduced their new cool logo. Later came Sunrise Hacks of Africa. 2015 introduced a new term of dark hacktivism that's raising the normal hacktivism into cyber warfare levels in a much more scale. And in 2016, this story came to an end when Dead Melox, the leader, came clean. He came clean to some newspaper, sent them an email that, hi, it's me. I'm Eugene, the man who's behind Dead Melox, the leader of Team Goshel. He sent his passport and even a picture. 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. So, why they did what they did? It's typical for hacktivism. For example, Westmin, they hacked to raise awareness to the foreign students' standards of the education today. In Blackstar, they claimed that the Russian is a government of tyranny and regret. They criticized their government. In White Fox, essentially, they wanted to promote hacktivism worldwide and draw attention to the freedom of information. And they had many other causes, like even in Japan, they wanted to piss them off just as it is. So, I want all of you to know this today. 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. We can see some statistics. In our top ten, SQL injection is part of the injection section. It's still on the top. In many years, it was the first one and now it's like the third one. Oops, it confused me for a second. Yes, it was. NVD is ranking SQL injection in the second place for many, many years. It's considered one of the most stubborn weaknesses ranked in the third place by Mitre. 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. 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. You can use similar techniques to other attacks. And if I still didn't convince you, you can earn bug bounties easily using those kinds of techniques like this one. It was disclosed critical vulnerability to Department of Defense. And so we are coming to an end and I want to leave you with some homework. I don't want to state here ten resources, but I want to state one and good one that I use. I don't get money by PulseWiggle, by the way. I truly recommend them because it's free resource, theoretical and practical combined. Very recommended and it dives deep. 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. So I tried my best and if you gain even one small little thing today, I will be genuinely happy. And that's it if you want to connect with me like LinkedIn and Twitter. And that's it.