start	end	text
720	7620	All right, folks. It is that time. If you have a seat that is in between you, please collapse
7620	14180	down. Specifically you, sir. Thank you very much. If you would bring it in close. All right.
14180	18640	With that, we are going to go ahead and kick everything off. I would like to introduce Iggy
18640	33500	to the stage. Thank you. So hello, DEF CON, and welcome to my talk called Ticking SQLI. And we
33500	40240	will begin. So what's in it for you today? Today we will explore types of SQL injection. We
40240	47600	will focus a bit on time-based SQL injection. We will see the impact Team Ghost Shell did in
47600	52860	the past using these kinds of techniques. We will understand why it's still relevant today. And
52860	58900	you will have a good time with a pretty much good presenter today. So who am I? My name is
58900	64620	Igor, but please call me Iggy. It's my nickname since childhood. I'm a security engineer at
64620	73300	Axonius. One sentence about Axonius is it's a cybersecurity asset management platform that maps
73300	78840	all your digital assets across your organization, normalizes them, duplicates them, and gives
78840	84160	you comprehensive insights about them and much more. And why am I here today? I'm here today
84160	91880	because I love learning stuff, especially in cybersecurity, from low level to high level, from
91880	98900	lock-picking to RFIDs, and I'm studying a lot. And for my studies, I came to this idea to talk
98900	104660	about this topic today. And the last thing about me, it's the first time I'm presenting, so
104660	110440	thank you AppSecVillage for giving me this opportunity today to be in such an honorable stage
110440	117860	as AppSecVillage and DEF CON. I truly appreciate it. And we'll begin. We'll begin by introducing
117860	125900	what is SQL injection. SQL injection is a technique where attackers insert malicious SQL code into
125900	135720	some input fields. It can be log-in forms, search boxes, or URL parameters. And they do it mainly
135720	142240	to retrieve sensitive information from the database for the application. They can retrieve
142240	155880	sensitive information, delete tables, and a lot of things that we'll see in the next slides. But the
170440	178780	example that I like the most to show what it is, a SQL injection, is to see how it looks through the
178780	184840	code. We have a query where the username and the password flows to its parameters. In the UI it
184840	190920	looks something like this. You get a log-in form. It's like to demonstrate the most basic type of
190920	197220	SQL injection. You have the username, you can enter admin, and some malicious payload to the
197220	202800	password that basically means a single quote and some old condition that always evaluates to
202800	212200	true. This flows to the query. The username gets the admin and the password gets some payload
212200	217800	that always evaluates to true. And by that the attacker can bypass the authentication because it's
218400	225560	sending it to the web application, sending it to its database, and it retrieves authentication
225560	236340	bypass. We have some different types of SQL injection. First type called in-band or classic. What
236340	244860	it means is that you see the results of your payload directly in HTTP response. Actually it also can be
244860	252560	served as self-category, but I want to stick as many resources I'll state in it. So we have the in-band
252560	258800	that you see the response directly into the web application. It also divided into two categories. One
258800	266320	of them is error-based. Error-based, what it means is that you see the results of your payload
266340	275580	that you rely on errors that you retrieve from the database to see some sensitive information. And you
275580	282260	have union-based type. What it means in general, we will in a second see demonstration for this, but in
282260	291000	one sentence union-based is concatenating two data, two data, so tables into one that contains both of
291000	299000	them. Or we can say that it's two select statements that combined into one result. We combine to some
299820	307200	expected data, additional concatenation of a table that retrieves sensitive information. We will see
307200	317820	it in the next slides. So to demonstrate the error-based SQL injection, we can see that we should try to
317820	324140	probe the application. Most of the times we will try through one single quote and two single quotes is the
324140	330440	most type of entry points, but you have additional entry points and comments. And you're starting to get
330580	340960	a sense of some error-based attack when you get from the one single quote 500 internal server error. And for
340960	347180	the double single quotes, 200 okay. What it means is that the SQL query behind it in the back end
347180	357800	cannot process the query correctly because it's not expected to receive 500 internal server error. And if
357800	362960	you close it in single quotes, it suddenly is okay. So there's some probably manipulation that you can
362960	371840	do on the SQL. So we'll try to do some manipulation. We can send a curl command that looks a bit messy, but
371840	378900	it's very simple. It's trying to convert the version function that you sent to the database to retrieve its
378900	386120	version. You try to convert it to an integer and compare it to one just so the well-closed will operate
386120	395080	correctly. It will look something like this when it flows to the query. And you get the error, conversion
395080	405080	failed. You get the MySQL that the server uses MySQL with a specific version. And by this, by this we
405080	411600	retrieve a sensitive information. I want to state here that something important. I stick to this example of
412480	417820	retrieving the version of the database in many additional slides that you will see later. I like this example
417820	423660	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
423660	429420	these techniques you can do something even more advanced to retrieve hash passwords and so on. So, but we'll
429420	434960	stick to the version because it's truly a real world example on one hand, but on the other hand it's not too
434960	446340	complex. So, now we'll move to the union base as we showed before. And this presenting expected regular curl
446340	452580	command to a server that I built. We send query equals to Alice and we'll retrieve some expected
452580	460820	information. But when we try to manipulate with a union attack, we will edit a union, select the first, oh, the user
460820	471720	that is currently connected to the database through the web application. We of course need to encode it and send it
471720	479260	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
479260	485720	current user that's connected to the database for the web application and this is information that's not supposed to
485720	494900	be retrieved, especially so easy. So, this is how union based attack looks like. After that we have many resources
494900	502720	dividing into these categories. One of them is out of band. I won't elaborate about it too much because it's something
502720	511320	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
511320	518020	cannot communicate with the web application, the server directly and you need to utilize some external server to
518020	526420	exfiltrate data through the database and you use some HTTP request and DNS queries to exfiltrate this data, but it's
526420	532700	something much, not so common, so we won't elaborate about it too much. The third category of attacks is
532720	540620	in-kind, inferential or blind type of SQL injection is generally a bit of the opposite of the in-band of course. It's
540620	548020	type of attacks that you cannot see your payload or the results of your payload directly in the web page and you need
548020	555940	to infer the results of your payload from the behavior of the web application. It is divided into two categories, one
555940	562700	of them is boolean based. I will explain by example what is boolean based and what is in-band. In-band is
562720	567840	something that you can see the results of your payload, but generally speaking it evaluates your payload to true or false in
567840	575120	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
575120	584280	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
584280	592700	payload of substring to the version of the database. In short, what it means, it takes the version, checks the field of
592720	604400	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
604400	613500	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
613500	620080	exist. So we can infer by that that when you compare it to 5, the first character of the version of the database is
620080	632500	starting with a 5. And in this kind of blind SQL injections, you need to enumerate each character until you get the
632500	643780	whole picture. But that's how it looks like. And the last type of inferential blind that we will focus a bit more today
643780	650160	called time-based. Time-based in a way is similar to Boolean-based, but it relies on the time delays that you get
650160	660360	from the server. And that's how you can infer your SQL payload by sending a time delay of, for example, 10 seconds.
660360	667860	The database is delayed with its response for 10 seconds and that's how you can infer if your payload was evaluated to
667860	680730	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
680730	688010	time to see how much it takes for the server to respond. So in particular query where it equals to Alice, the elapsed
688010	697250	time was immediate. But when we try to run a time-based payload, for example, it will look like this with closing
697250	705810	single quote so the SQL payload will operate normally. And a sleep command that causes the server to delay for 5
705810	715470	seconds, we encode it and we will construct in the URL, sending it back, and we can suddenly see that with the sleep
715470	721710	command of 5 seconds, the elapsed time was 5 seconds. So in general what it means is that the time delay was
721710	729010	successfully executed. Before we continue about time delays, I want to elaborate a bit about tools that will be
729010	739530	connected. There are many tools to uncover SQL injection. One of them is a bit less popular called Havij. I decided to
739530	746470	include it because when I researched about Team Goshel, some resources stated they used this tool and I never met it
746470	755610	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
755610	768910	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
768910	778430	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
778430	785590	tool for SQL injection and uncovering them is called SQL Map. I'm so happy that I was able to use this tool.
787270	795790	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
795790	803990	batch command, what it means is a non-interactive command that won't interfere in the process of executing. And please
803990	813210	retrieve us the database version. When we run it, we can see that SQL Map uncovers that we have Boolean based, time
813210	821630	based and union, union attack seal. And we see the stuff that we wanted to retrieve that the database uses SQLite
821630	831770	behind the curtain. To show you, of course, SQL Map can do a bit more advanced stuff, like in this example. We can
831770	842210	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
842210	854010	banner of the database. And we can see that it successfully works. We can retrieve the banner of equals to 8.3.0.
855210	862810	And before I continue to the next slide, I want to emphasize something important. For my personal opinion, we cannot
862810	870530	rely on many automation tools. We always need to have the ability to write our own scripts to some particular
870530	877010	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
877010	885130	master the automating tools and writing our own scripts. And a script of executing time delay can look something
885770	894090	simple as this. We can have a script with, of course, some constants and some expected parameters. But in general, it
894090	900510	will be divided into three functions. One function that will check the delay of the HTTP response and will record
900530	907830	it. The second function will extract the version character. It takes the position that we are checking in our
907830	916090	payload. It compares it to the character. Character enumerates for all the ASCII's. It compares to the position in
916090	922990	the version that we want to retrieve. If it got the sleep time, then it means that we successfully executed it. Or
922990	930510	if not, it didn't work. And the first function, it continues to enumerate all the ASCII's that we want to
930530	935710	retrieve. It takes all the next indexes in the version number and recalls the version that we are retrieving of
935710	944550	the database. And eventually it will look something like this when we are running it. Extracting the database
944550	958310	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
958310	968990	show you a few stuff. One of them, a real world example of a guy called Mola. Here is YouTube and his site. I
968990	976010	really like to learn about real world examples because it really demonstrates what we need, what's truly
976010	985290	important. And here he claims that he earned a bounty of $5,000 finding the next payload that you will see in a
985290	993170	fast billing site. What he claims that he did to execute this bounty, he ran a steep command that we saw
993170	1002210	before, concatenated to some parameter that the site had, per page equals to one, and executed time delay. He got
1002210	1010230	truly five seconds delay. Then he executed this payload. This payload is exactly as the substring we saw before. The
1010230	1016510	mid is equal to the substring, but particular to MySQL version. And it checks the version fills
1016510	1024930	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
1024930	1033270	delay. But when he changed the five to eight, he could successfully gain 15 seconds delay. And by that, he gained
1033450	1043790	a bounty. Just to show you a bit more real world examples, one of them looks something like this. It's some bounty
1043790	1050270	that uses XOR, an interesting payload that always evaluates to true. And some bounty that was discovered in
1050270	1059570	Department of Defense in HackerOne system. The second one was pretty simple concatenation to expected
1059570	1069630	parameters of sleep seven seconds, also disclosed to HackerOne and found in the automatic website. And the third
1069630	1085670	one, my favorite, combines script, union and sleep commands. Some real combination of all of them. And the third
1085670	1099250	bounty gained, what I found from resources when I checked it, got bounty of $2,100. So, all of those stuff that we
1099250	1106710	seen was utilized by Tim Gorshel in the past. They used a lot of SQL injection, especially time delays, something
1106710	1115650	given what they did. They were operating in 2012. And they utilized even simpler SQL commands that we
1117910	1126590	saw before. And as I said, they were operating in 2012. They are not related to APT39 or some Iranian
1126590	1134570	government. They actually were a hacktivist group. I'm just curious, how many people of you know what
1134570	1142750	hacktivism is? Please raise your hands. Okay, okay, not bad. Approximately half. So, hacktivism is when
1142750	1150570	you attack a group that is trying to promote some political change or some social agenda that you believe
1150570	1159210	in and you promote it by hacking. And that's what Tim Gorshel will. They were a hacktivist collective. And
1159210	1165250	just to see what they did and who they were, they started to operate in 2012. They hacked the University
1165250	1172730	of Arkansas because one of the guys there called Zoom was arrested. So, they hacked it in terms of
1172750	1183130	protest. After that, DeadMallocs was appealed. DeadMallocs was the admin of the group. He appealed
1183130	1189050	in their main communication channel in Facebook stating that he doesn't, in an ironic way, that he
1189050	1194570	doesn't want to fight with FBI or CIA or something like this. But on the other hand, we will leak a
1194570	1202730	bunch of stuff in the coming year. So, as he promised, he started, they started to attack the
1202750	1210070	government, make additional hacking projects. They had Project Dragonfly where they hacked China
1210070	1217370	government and leaked thousands of sensitive information. It included like hash passwords, some
1217370	1223150	personal data and like everything they got. Later, Hellfire. In Project Hellfire, they hacked
1223150	1229150	governments, financial sectors and other companies. In Project West Wing, they focused on
1229150	1236670	universities around the globe from Harvard, Stanford to University of Rome and Tokyo. And they
1236670	1245850	even declared a war in Project Black Star against Russia. In all of these projects, they hacked
1245850	1255690	like, they leaked thousands to millions of records from personal information to hash passwords, as
1255690	1261770	I said before. But many of this information was publicly already disclosed. Still, on the other
1261770	1269290	hand, it was sensitive information that truly was released. But what they achieved through it, they
1269290	1276610	achieved their main cause, to raise awareness to their hacktivism and to their operations. So,
1276610	1281970	later, in Project White Fox, they basically hacked everyone to raise awareness to hacktivism. And
1281970	1293570	they introduced their new cool logo. Later came Sunrise Hacks of Africa. 2015 introduced a new term
1293570	1299070	of dark hacktivism that's raising the normal hacktivism into cyber warfare levels in a much more
1299070	1306070	scale. And in 2016, this story came to an end when Dead Melox, the leader, came clean. He came clean to
1306070	1313210	some newspaper, sent them an email that, hi, it's me. I'm Eugene, the man who's behind Dead Melox,
1313210	1319150	the leader of Team Goshel. He sent his passport and even a picture. They still didn't believe him,
1319150	1324890	so he posted on his Twitter account to the next web, the journal that he came clean to, that, hello,
1324890	1335890	it's truly me. So, why they did what they did? It's typical for hacktivism. For example, Westmin,
1335890	1344670	they hacked to raise awareness to the foreign students' standards of the education today. In Blackstar,
1344670	1354030	they claimed that the Russian is a government of tyranny and regret. They criticized their government.
1354610	1360650	In White Fox, essentially, they wanted to promote hacktivism worldwide and draw attention to the
1360650	1367930	freedom of information. And they had many other causes, like even in Japan, they wanted to piss
1367930	1376890	them off just as it is. So, I want all of you to know this today. I know that you are thinking SQL
1376890	1382630	injection is old and Team Goshel was operated in 2012, but I will show you that what is old is still
1382630	1389390	worth gold. We can see some statistics. In our top ten, SQL injection is part of the injection
1389390	1396250	section. It's still on the top. In many years, it was the first one and now it's like the third one.
1398930	1411570	Oops, it confused me for a second. Yes, it was. NVD is ranking SQL injection in the second place for many,
1411570	1420050	many years. It's considered one of the most stubborn weaknesses ranked in the third place by Mitre. And
1421230	1427070	GitHub security advisor also stating that, and it's truly stated that SQL injection is not relevant to
1427070	1432750	modern languages like Vue, React, Python, stuff like this. But for my opinion, what's important to
1432750	1438390	know here is that the concepts or the mindset that you set for yourself when you are learning about
1438390	1444490	these attacks can be implemented to many other fields because they are all related. You can use
1444490	1450850	similar techniques to other attacks. And if I still didn't convince you, you can earn
1450850	1457010	bug bounties easily using those kinds of techniques like this one. It was disclosed critical
1457010	1463970	vulnerability to Department of Defense. And so we are coming to an end and I want to leave you
1463970	1469310	with some homework. I don't want to state here ten resources, but I want to state one and good one
1469310	1475510	that I use. I don't get money by PulseWiggle, by the way. I truly recommend them because it's free
1475510	1484090	resource, theoretical and practical combined. Very recommended and it dives deep. So to recap,
1484090	1490250	it's hard to make a 25 minute lecture because I want to talk about many stuff and I only have 25
1490250	1496010	minutes. So I tried my best and if you gain even one small little thing today, I will be genuinely
1496010	1503370	happy. And that's it if you want to connect with me like LinkedIn and Twitter. And that's it.
