1 00:00:00,000 --> 00:00:02,680 So yeah, we're going to be talking to you guys today about a tool we've been working 2 00:00:02,680 --> 00:00:06,720 on called Barbecue Sequel. First we're going to talk a little bit about ourselves because 3 00:00:06,720 --> 00:00:11,760 we are narcissists. My name is Ben Taves. I'm a security consultant and researcher at 4 00:00:11,760 --> 00:00:17,540 NeoHapsys. NeoHapsys is a small pen testing shop and application security shop in Chicago. 5 00:00:18,740 --> 00:00:24,580 I do mostly network and application pen tests. And my name is Scott Behrens. I'm a senior 6 00:00:24,580 --> 00:00:29,680 security consultant at NeoHapsys. Similar background as Ben, doing AppSec work, a lot 7 00:00:29,680 --> 00:00:36,240 of social engineering, pen tests, that kind of stuff and research. So we are here to talk to 8 00:00:36,240 --> 00:00:41,220 you guys, like I said, about Barbecue Sequel. Barbecue Sequel, it's a SQL injection 9 00:00:41,220 --> 00:00:46,500 exploitation tool. In some senses it's a new dog that we're teaching old tricks. Like I said, 10 00:00:46,500 --> 00:00:52,260 it exploits SQL injection. There's about a million other tools that do that. It's also, though, 11 00:00:52,280 --> 00:00:57,980 a new dog that we're teaching a new trick. It's stupidly fast. It's easy to use. And it gets 12 00:00:57,980 --> 00:00:59,540 those hard to reach spots. 13 00:01:00,160 --> 00:01:03,260 And we'll be talking a lot more about what the hell I mean by that. 14 00:01:04,260 --> 00:01:09,000 Cool. All right. So just so we get everybody on the same page and we know you guys all come from 15 00:01:09,000 --> 00:01:13,540 different backgrounds, we're just going to do like a really quick explanation of what SQL is 16 00:01:13,540 --> 00:01:19,820 and what SQL injection is. I'm hoping this will go pretty quickly. Oh, yeah. And then we'll just 17 00:01:19,820 --> 00:01:29,660 get right into it. So what is SQL, right? And I'm assuming most of you guys have probably set up a 18 00:01:29,680 --> 00:01:33,340 database at some point or you write applications and interact with SQL, right? And it's a structured 19 00:01:33,340 --> 00:01:39,840 query language in which we use to interact with the database system. SQL injection is when we 20 00:01:39,840 --> 00:01:44,200 inject syntax into the application SQL queries, right? And this is when we do all the fun stuff 21 00:01:44,200 --> 00:01:49,500 when we're doing, you know, application security assessments and that kind of work. So let's go 22 00:01:49,500 --> 00:01:54,540 ahead and walk through basic SQL injection, right? We got some pseudo code up here. Have the 23 00:01:54,540 --> 00:01:59,280 user name masked the Yeti and the password secret, right? And we kind of imagine this query is we're 24 00:01:59,680 --> 00:02:04,480 going to select everything from the user's table where user name is the user name and password is 25 00:02:04,480 --> 00:02:08,620 password, right? And so the query evaluates and this is generic, right? This is database 26 00:02:08,620 --> 00:02:13,700 agnostic we're talking about here. So we have, you know, select star from users where user name 27 00:02:13,700 --> 00:02:23,060 is masked the Yeti and password is secret. All right. So what does SQL injection look like, 28 00:02:23,100 --> 00:02:29,660 right? So SQL injection, we're trying to kind of break out of that query syntax. We're trying to 29 00:02:30,300 --> 00:02:36,160 break out of that query statement. We can kind of start to construct our own query on top of the 30 00:02:36,160 --> 00:02:40,520 query that the application is supposed to execute, right? So we have some more pseudo code up here. 31 00:02:40,920 --> 00:02:46,300 We're inserting in the value you name so we can kind of imagine like a web request, right? You 32 00:02:46,300 --> 00:02:51,260 know, you're passing in parameters and whatnot. So we have the user name parameter and the 33 00:02:51,260 --> 00:02:57,860 password parameter and we're going to go ahead and pass in pwned, tick or 1 equal 1. There's a typo 34 00:02:59,680 --> 00:03:04,140 there. So basically that's kind of going to, when you look down at the way the query evaluates to, 35 00:03:04,360 --> 00:03:08,880 you see that it kind of basically breaks us out of the way that the query looks. So if we step 36 00:03:08,880 --> 00:03:14,540 back and look at how the query should look, inserting that tick symbol allows us to escape out 37 00:03:14,540 --> 00:03:22,520 of the query and basically say, well, if the user name is pwned or it's 1 equals 1, and since 1 38 00:03:22,520 --> 00:03:29,660 equals 1 always evaluates to true, we basically, we basically get, you know, we get a lot of 39 00:03:29,680 --> 00:03:35,220 access to the system, right? So blind SQL injection, which is what we're going to mainly be 40 00:03:35,220 --> 00:03:40,800 focusing on, because this is the primary use case for our tool, is when you're still trying to 41 00:03:40,800 --> 00:03:46,140 alter SQL syntax, but you really can't see the results of what you're doing, right? So it's not 42 00:03:46,140 --> 00:03:49,560 like you're injecting something and something's getting displayed to the screen showing you what 43 00:03:49,560 --> 00:03:54,980 you're executing. You're actually more interested in other kinds of use cases, which will give you 44 00:03:54,980 --> 00:03:59,340 clues on it if your injection string is working or not. It's a little bit more 45 00:03:59,340 --> 00:03:59,660 complicated than that, but it's a little bit more complicated than that, but it's a little bit more 46 00:03:59,680 --> 00:04:05,580 complex SQL syntax, not quite as trivial as SQL injection attacks out there. But the primary 47 00:04:05,580 --> 00:04:11,560 goal is to dump the database and, you know, winning as much as you can. So let's take a look at 48 00:04:11,960 --> 00:04:17,000 the blind SQL injection case. And so we'll kind of walk through this. And I'm sure you guys have 49 00:04:17,000 --> 00:04:22,460 seen this before, but basically we're going to do the same kind of attack we were doing 50 00:04:22,460 --> 00:04:27,220 earlier, but we're not going to be able to see the results, right? So we're escaping out of the 51 00:04:27,220 --> 00:04:29,660 query with the tick, and then we're going to do a subset, and then we're going to do a 52 00:04:29,660 --> 00:04:34,160 string, which I'll explain in a little bit what that is, to grab the user name. And the 53 00:04:34,160 --> 00:04:38,900 query evaluates to something like you see below. And this stuff in gray is commented out. 54 00:04:39,340 --> 00:04:45,080 The double tick ‑‑ I'm sorry, the double dash is basically a comment character. And as 55 00:04:45,080 --> 00:04:49,320 you guys are familiar with SQL know that there's a couple different ways to terminate a 56 00:04:49,320 --> 00:04:56,740 SQL string. So let's go ahead and kind of walk through what the blind SQL injection looks 57 00:04:56,740 --> 00:05:01,040 like or what these components are so you have a better understanding of how this works. So 58 00:05:01,040 --> 00:05:08,180 we're selecting star from users where password equals tick tick and user name equals ‑‑ and 59 00:05:08,180 --> 00:05:11,340 then we kind of tick at that ‑‑ we kind of close out at that point and here's where we 60 00:05:11,340 --> 00:05:16,680 inject our code, right? So we're saying or the ASCII, which is going to take a character and 61 00:05:16,680 --> 00:05:21,460 turn it into an int, the substring command, which is going to basically slice the string, 62 00:05:22,000 --> 00:05:26,380 all right? And the way that works is it's going to slice the first position, so which 63 00:05:26,380 --> 00:05:26,720 happens to be the first string, and then the second string, which is going to slice the 64 00:05:26,740 --> 00:05:32,880 string. So basically what we're saying here is we're going to grab the first ‑‑ we're 65 00:05:32,880 --> 00:05:38,620 going to first query the user object. And then you see the one and the one ‑‑ let me 66 00:05:38,620 --> 00:05:44,340 highlight where that's at right here. We're going to grab the first character and we're 67 00:05:44,340 --> 00:05:47,940 going to grab one character. So we're going to select users. So let's say users root, right? 68 00:05:48,360 --> 00:05:53,180 And we're going to convert root ‑‑ that first letter R into an ASCII equivalent. I don't 69 00:05:53,180 --> 00:05:56,720 know what R is. And then we're going to say is it greater than 63? And then we're going to 70 00:05:56,720 --> 00:06:01,500 say 63. 63 happens to be a question mark. If that happens to be true, we're going to have 71 00:06:01,500 --> 00:06:06,680 some different interaction with maybe the response of the web server. So let's go ahead and 72 00:06:06,680 --> 00:06:12,160 say that we're doing a Boolean‑based blind SQL injection. And based on the status code of 73 00:06:12,160 --> 00:06:18,000 the server, we might get a 404 if we do something that evaluates to true. Or we get a 200 if 74 00:06:18,000 --> 00:06:22,160 we do something that evaluates to false, right? So that's the thing with blind SQL injection. 75 00:06:22,460 --> 00:06:26,320 We're kind of trying to ‑‑ we're keeping track of different objects of the HTTP request, 76 00:06:26,320 --> 00:06:31,120 things like the amount of time it takes for ‑‑ all right, we have to do a shot here. 77 00:06:31,360 --> 00:06:36,540 I'm sorry. It's DEF CON tradition, first‑time speakers, they have to do a shot. How about a 78 00:06:36,540 --> 00:06:41,460 round of applause for these guys? All right. 79 00:06:47,720 --> 00:06:50,480 That's good. Yeah, I'll need those back. 80 00:06:53,800 --> 00:06:55,620 My eyes lit up when he pulled out the whiskey. 81 00:06:58,600 --> 00:07:03,160 So what we're really kind of talking about here is, you know, we're thinking about these 82 00:07:03,160 --> 00:07:06,960 different ways that we can determine if what we're doing is correct and incorrect. And we're 83 00:07:06,960 --> 00:07:10,460 not going to spend too much time talking about the different ways to validate blind SQL 84 00:07:10,460 --> 00:07:16,300 injection. But we're going to go ahead and just kind of move forward here to kind of explain 85 00:07:16,780 --> 00:07:20,800 where this problem arise and why we kind of even started working on a tool in the first place 86 00:07:20,800 --> 00:07:25,700 when there's all these other awesome tools out there. When you're doing blind SQL injection, 87 00:07:26,320 --> 00:07:29,580 there are a couple different ways you can kind of search through the data, right? And the way 88 00:07:29,580 --> 00:07:34,680 that the current scripts and tools work, typically it's some sort of binary search. That binary 89 00:07:34,680 --> 00:07:38,960 search helps you determine if your character is, you know, the right character and it logs 90 00:07:38,960 --> 00:07:44,040 in, et cetera. It tends to be one character at a time. Some of the tools out there have options 91 00:07:44,040 --> 00:07:48,280 to do multi‑threading and whatnot. I think SQL map you can do up to ten threads at a time. But 92 00:07:48,280 --> 00:07:53,040 we kind of noticed that performance can be a little bit questionable and sometimes you might 93 00:07:53,040 --> 00:07:56,300 get some false data. And it's generally very time‑consuming. So we're going to go ahead and 94 00:07:56,300 --> 00:07:59,400 look at some of the tools out there. You're not executing one query to get the results you 95 00:07:59,400 --> 00:08:04,320 want. You have to execute multiple queries and you kind of have to step through all this kind 96 00:08:04,320 --> 00:08:10,780 of junk to get the end result. And like I mentioned earlier, there are awesome tools out 97 00:08:10,780 --> 00:08:20,320 there. SQL map, awesome. I, you know, use it on many assessments, SQL ninja, the mole. They all 98 00:08:20,320 --> 00:08:24,380 have great features and they're sweet. But when these tools don't work, what do you guys end up 99 00:08:24,380 --> 00:08:26,280 doing, right? You know, you're going to have to do a lot of things. You're going to have to do a lot of 100 00:08:26,300 --> 00:08:29,120 things. You kind of end up maybe coming up with your own query. Maybe there's some weird 101 00:08:29,120 --> 00:08:36,540 nuance where your requests have to be double URL encoded. Or you can't use ASCII for some reason. 102 00:08:36,640 --> 00:08:40,420 Or maybe some command that you think you should be able to run on the database server just 103 00:08:40,420 --> 00:08:45,640 doesn't work. Maybe the database administrator has made some specific policy or rule that won't 104 00:08:45,640 --> 00:08:49,880 allow you to run some of these kinds of commands. So you end up firing up a Ruby script or a Python 105 00:08:49,880 --> 00:08:53,620 script and you kind of write out your own logic and like it's kind of a pain in the ass, right? 106 00:08:53,820 --> 00:08:56,280 And it takes a lot of time. And you, you know, you test and you use it and you kind of get the 107 00:08:56,280 --> 00:09:02,360 debug, you test and debug. And we were kind of thinking about what if there was a way where we 108 00:09:02,360 --> 00:09:07,720 could kind of take that process out of it. The whole part where you have to write these very 109 00:09:07,720 --> 00:09:15,480 customized scripts for when things don't work. And that's when we enter awesome artwork. We 110 00:09:15,480 --> 00:09:21,500 take some really tasty meat on the left and some like sweet looking IBM graphic of how databases 111 00:09:21,500 --> 00:09:26,260 look. And then we enter Barbecue Sequel, right? And then we go to the database server and we 112 00:09:31,680 --> 00:09:32,080 play around with it. And then we run some really cool stuff, you know, like some of the 113 00:09:32,080 --> 00:09:35,560 stuff that's a little bit more complicated. So like Scott was saying, the point of the tool is to 114 00:09:35,560 --> 00:09:40,180 exploit blind sequel injection. And hopefully you guys all are at least a little bit familiar now 115 00:09:40,180 --> 00:09:46,960 with what the hell that means. So for those hard to reach spots, compared to some of those other 116 00:09:46,960 --> 00:09:52,240 tools that we're talking about, this is not automatic. The point of the tool is not to find the 117 00:09:52,240 --> 00:09:56,240 volume for you. It's not to do your job for you. This is for helping you explore the game, get a lot of 118 00:09:56,260 --> 00:09:58,400 exploit something you already know how to exploit. This is not 119 00:09:58,400 --> 00:10:03,840 a skiddy tool. So a lot of the benefits that we see from making 120 00:10:03,840 --> 00:10:06,840 you do a little bit more of the leg work is that we can be very 121 00:10:06,840 --> 00:10:10,060 versatile and very database agnostic. So it doesn't really 122 00:10:10,060 --> 00:10:13,000 matter where you're trying to use it, how you're trying to use 123 00:10:13,000 --> 00:10:16,260 it. It's just performing the logic. It's performing the 124 00:10:16,260 --> 00:10:19,960 request. So you do have to do more leg work but you get a lot 125 00:10:19,960 --> 00:10:23,640 of benefits out of that. Versatility and speed. We put a 126 00:10:23,640 --> 00:10:27,520 lot of work into trying to make this thing very performant. And I 127 00:10:27,520 --> 00:10:31,420 think we really did a pretty good job with that. I'm going to 128 00:10:31,420 --> 00:10:35,680 talk a little bit about the use of the tool. So like any tool 129 00:10:35,680 --> 00:10:38,700 that is going to be making HTTP requests for you, you need to 130 00:10:38,700 --> 00:10:42,640 specify what request you want it to make. So you need to tell it 131 00:10:42,640 --> 00:10:48,680 what URL, the HTTP method. That's the basics. On top of 132 00:10:48,680 --> 00:10:53,540 that, you can specify any other aspect of the HTTP request. A lot 133 00:10:53,640 --> 00:10:57,480 of the other tools out there, it's limited in what it will 134 00:10:57,480 --> 00:11:00,820 allow you to do. The way that we built the tool, it's sitting on 135 00:11:00,820 --> 00:11:03,980 top of a really, really cool HTTP library that I'll talk 136 00:11:03,980 --> 00:11:08,020 about a little bit more later. And that library itself is very 137 00:11:08,020 --> 00:11:10,700 versatile and we really try to leverage that to give you as 138 00:11:10,700 --> 00:11:13,780 much control as possible and to really build out the exact 139 00:11:14,420 --> 00:11:18,000 request that you're trying to make. So you can specify cookies, 140 00:11:18,240 --> 00:11:21,740 headers, encoding methods, what it should do if it encounters a 141 00:11:21,740 --> 00:11:23,620 redirect. If you want to do a 142 00:11:23,640 --> 00:11:26,380 multi-part file upload as a part of your attack, you can do 143 00:11:26,380 --> 00:11:32,220 that. HTTP authentication, basic or digest or what not. If you 144 00:11:32,220 --> 00:11:35,320 need to chain it through proxies, you can specify all of 145 00:11:35,320 --> 00:11:40,120 that. So in addition to those things, which most other tools 146 00:11:40,120 --> 00:11:43,160 will hopefully allow you to provide, there's a couple other 147 00:11:43,160 --> 00:11:45,480 things that you have to provide. And this is when we start 148 00:11:45,480 --> 00:11:48,160 talking about it being more of a semi-automatic tool as opposed 149 00:11:48,160 --> 00:11:52,100 to an automatic tool. You need to specify where the injection is 150 00:11:52,100 --> 00:11:53,160 going to go into that request. 151 00:11:53,640 --> 00:11:55,880 So it's not going to find the bone for you. It's not supposed 152 00:11:55,880 --> 00:11:58,540 to find the bone for you. This is an exploitation tool. So you 153 00:11:58,540 --> 00:12:01,800 need to tell it where the vulnerability is, where it's 154 00:12:01,800 --> 00:12:05,900 going to be injecting the SQL logic, the SQL syntax into the 155 00:12:05,900 --> 00:12:09,960 existing request. Additionally, you're going to need to specify 156 00:12:09,960 --> 00:12:13,160 what that syntax looks like. This is what allows us to be 157 00:12:13,160 --> 00:12:15,840 database agnostic. For people who have worked with a variety 158 00:12:15,840 --> 00:12:19,160 of databases, there's a lot of syntax variations, which is kind 159 00:12:19,160 --> 00:12:23,540 of crazy because it's SQL, you know. But I don't know. Whenever 160 00:12:23,640 --> 00:12:27,440 I find myself trying to exploit SQL injection on an Oracle 161 00:12:27,440 --> 00:12:30,620 database, I have the hardest time because I don't like 162 00:12:30,620 --> 00:12:33,400 selecting from dual. If I want to select one, I don't want to 163 00:12:33,400 --> 00:12:38,660 select from dual. I hate Oracle. I'm a MySQL guy. So I 164 00:12:39,130 --> 00:12:41,900 like the fact that it doesn't matter what the database is 165 00:12:42,450 --> 00:12:45,240 because you are the one providing the syntax. Once again, 166 00:12:45,320 --> 00:12:48,340 this is what makes it a semi-automatic tool as opposed 167 00:12:48,340 --> 00:12:52,220 to an automatic tool. And by the way, we made up that verbiage. 168 00:12:54,140 --> 00:12:57,560 We made up the term semi-automatic. I hope that's 169 00:12:57,560 --> 00:13:01,500 okay with you guys. So, yeah. That first part I was talking 170 00:13:01,500 --> 00:13:06,380 about where you specify where in the query, I'm sorry, where in 171 00:13:06,380 --> 00:13:10,320 the HTTP request the SQL syntax is going to be injected, where 172 00:13:10,320 --> 00:13:14,680 the vulnerability is essentially. I don't know if I can 173 00:13:14,680 --> 00:13:18,400 get my mouse. Yep, there we go. Oh, shit, this is going to be 174 00:13:18,400 --> 00:13:23,620 hard. All right. So right over here, you see this is the 175 00:13:23,640 --> 00:13:26,720 what looks like a templating language and that is because it 176 00:13:26,720 --> 00:13:32,360 is a templating language. I opted not to use an existing 177 00:13:32,360 --> 00:13:35,320 templating language. I kind of rolled my own because it was 178 00:13:35,320 --> 00:13:40,260 simpler for this. So here you see a URL or here, too, 179 00:13:40,320 --> 00:13:44,940 actually. You see the URL and then you see this thing called 180 00:13:44,940 --> 00:13:49,560 query inside of this dollar sign, curly brackets. So that is 181 00:13:49,560 --> 00:13:52,560 where the syntax, that's where the vulnerability is, that's 182 00:13:52,560 --> 00:13:53,620 where the SQL is going to get injected. So that's where the 183 00:13:53,640 --> 00:13:56,760 vulnerability is going to get injected into the URL. But the 184 00:13:56,760 --> 00:14:01,040 cool thing is, I was telling you how you can use or how you can 185 00:14:01,040 --> 00:14:04,280 specify pretty much any part of the HTTP request. You can 186 00:14:04,280 --> 00:14:06,980 specify anything you want. You can also put the injection 187 00:14:06,980 --> 00:14:10,020 anywhere you want. So if you have some, like, if the 188 00:14:11,140 --> 00:14:14,040 vulnerability is in the host header or if it's in the user 189 00:14:14,040 --> 00:14:17,360 agent or if it's in a cookie or if it's in the file from the 190 00:14:17,360 --> 00:14:20,380 multi-part upload, I'm pretty sure you could even do 191 00:14:20,380 --> 00:14:23,620 injection in the HTTP method. I think that would be a pretty 192 00:14:23,640 --> 00:14:25,420 good idea. I think that would probably break a lot of things 193 00:14:25,420 --> 00:14:29,080 and probably not a good idea. And probably wouldn't work. But, 194 00:14:29,120 --> 00:14:33,520 yeah, so you use this templating language where you specify query 195 00:14:33,960 --> 00:14:37,020 with this in these brackets. It's kind of a templating tag. 196 00:14:37,380 --> 00:14:40,060 And you can put that anywhere. So down below you see the data. 197 00:14:40,220 --> 00:14:42,620 That's going to be the data section of the URL or of the 198 00:14:42,620 --> 00:14:46,540 HTTP request. You can put it in there, in the cookies. One of 199 00:14:46,540 --> 00:14:48,920 the other kind of cool things that I tried to do, and I got 200 00:14:48,920 --> 00:14:53,620 some flack from some Python guys for this. I made a little bit of 201 00:14:53,640 --> 00:14:57,360 it so for specifying cookies and for headers, you don't have to 202 00:14:57,360 --> 00:15:01,580 write it out like it is in the raw HTTP packet because that's 203 00:15:01,580 --> 00:15:04,240 how a lot of tools are. You can specify it as a dictionary, like 204 00:15:04,240 --> 00:15:08,040 a Python dictionary. I know a lot of security folks are Python 205 00:15:08,040 --> 00:15:11,180 people so I thought that would be really handy because I really 206 00:15:11,180 --> 00:15:15,760 hate trying to, like, specify in SQL map how I want a header to 207 00:15:15,760 --> 00:15:20,340 look. So, yeah, as you can see here with cookies and it's, like 208 00:15:20,340 --> 00:15:23,620 I said, exactly the same with headers. Oh, shit, I 209 00:15:23,640 --> 00:15:27,580 lost my mouse. Sorry. The fourth line down. You can 210 00:15:27,580 --> 00:15:30,580 specify cookies and headers as a dictionary and I think that's 211 00:15:30,580 --> 00:15:35,080 pretty cool. But, yeah, the benefit of this, making you 212 00:15:35,080 --> 00:15:37,820 specify where the vulnerability is, is that the tool doesn't 213 00:15:37,820 --> 00:15:40,500 have to understand your data. You can be doing some totally 214 00:15:40,500 --> 00:15:44,140 bizarre serialization format, anything you want. The tool 215 00:15:44,140 --> 00:15:47,520 doesn't give a crap. The tool just wants to know what your 216 00:15:47,520 --> 00:15:52,600 request looks like and where it needs to inject. So, yeah, this 217 00:15:53,640 --> 00:15:54,400 is really cool. So, if you're doing serialization formats, if 218 00:15:54,400 --> 00:15:57,060 there's some weird processes that you have to go through to 219 00:15:57,060 --> 00:15:59,580 make the request work, it doesn't care about that. 220 00:15:59,660 --> 00:16:03,840 Encodings doesn't care. We'll actually walk through a 221 00:16:03,840 --> 00:16:07,080 demo later. Yes. Something we've been seeing very frequently on 222 00:16:07,730 --> 00:16:10,480 web application assessments is requiring HMAC signing of 223 00:16:10,480 --> 00:16:14,620 particular values and the URI. We've been seeing this more 224 00:16:14,620 --> 00:16:18,320 often. So, we actually will talk about ways to use the tool to do 225 00:16:18,320 --> 00:16:20,720 some of the more kind of advanced stuff that might be a 226 00:16:20,720 --> 00:16:22,940 little bit more difficult using some of the other tools that are 227 00:16:22,940 --> 00:16:23,600 out there. So... 228 00:16:25,280 --> 00:16:27,680 Yes. So, yeah, and then the second thing that I said that 229 00:16:27,680 --> 00:16:29,560 you need to provide that you might not need to provide in 230 00:16:29,560 --> 00:16:32,880 other tools is some of the SQL syntax. Again, here you see the 231 00:16:32,880 --> 00:16:39,640 templating language that I was talking about. So, here is the 232 00:16:40,140 --> 00:16:43,000 what is going to be injected into the spot that we were 233 00:16:43,000 --> 00:16:45,940 talking about in the previous slide. And you're going to need 234 00:16:45,940 --> 00:16:48,600 to specify a variety of things in order to make a blind SQL 235 00:16:48,600 --> 00:16:53,300 attack work. Scott was talking a little bit earlier about how 236 00:16:53,640 --> 00:16:55,960 usually when you're doing a binary search in blind SQL 237 00:16:55,960 --> 00:17:00,220 injection, you're going to be trying to modulate things like 238 00:17:00,220 --> 00:17:03,380 what row you're trying to select, what substring you're 239 00:17:03,380 --> 00:17:05,940 trying to do. So, if you're selecting user from the 240 00:17:05,940 --> 00:17:08,200 database, you're trying to grab the first character and you're 241 00:17:08,200 --> 00:17:09,860 trying to figure out what that is before you move on to the 242 00:17:09,860 --> 00:17:12,740 second and third character. So, you need to use this templating 243 00:17:12,740 --> 00:17:16,360 language to specify where all those variables go. And we'll 244 00:17:16,360 --> 00:17:20,960 actually, when we do the demo, we'll step through pretty much 245 00:17:20,960 --> 00:17:23,620 all the tags that you can use when using the tool. And we'll 246 00:17:23,640 --> 00:17:27,640 see how they work. So, if this seems a little confusing now, it 247 00:17:27,640 --> 00:17:30,280 actually will make a lot more sense when we go through and run 248 00:17:30,280 --> 00:17:34,380 the demo. Yeah. And nine times out of ten, you're hopefully 249 00:17:34,380 --> 00:17:38,200 going to be able to reuse one of these queries that we've 250 00:17:38,200 --> 00:17:40,600 already written. It looks a bit intimidating. I agree. I'm 251 00:17:40,600 --> 00:17:45,120 intimidated. But, yeah, the benefit here, like I was saying, 252 00:17:45,220 --> 00:17:48,680 is database agnostic. So, if you're using a database that 253 00:17:49,220 --> 00:17:53,520 isn't using SQL at all, but you can still do a blind SQL 254 00:17:53,640 --> 00:17:56,240 injection attack, or I guess it would just be a blind injection 255 00:17:56,240 --> 00:17:59,560 attack, but if you're using something with a screwy syntax, 256 00:17:59,920 --> 00:18:03,280 it doesn't matter. You just need to specify what the query is 257 00:18:03,280 --> 00:18:07,100 going to look like overall and where you can control these 258 00:18:07,100 --> 00:18:11,440 pieces of information within the query. So, yeah, this helps you 259 00:18:11,440 --> 00:18:14,360 to not need to care about SQL syntax, character limitations. It 260 00:18:14,360 --> 00:18:17,860 also can be useful for evading IDS and IPS because a lot of 261 00:18:17,860 --> 00:18:23,620 times you'll see people doing ‑‑ taking ASCII codes and 262 00:18:23,640 --> 00:18:30,260 generating their strings from that to ‑‑ because of character 263 00:18:30,260 --> 00:18:33,740 limitations. So, if you need to do that, you can do it. That's 264 00:18:34,260 --> 00:18:39,320 the point there. The other cool thing is if you need to do 265 00:18:39,320 --> 00:18:43,040 something really crazy, like Scott was saying, HMAX signing, 266 00:18:43,200 --> 00:18:45,700 I don't know any tools where you can specify that some 267 00:18:45,700 --> 00:18:49,020 parameter needs to have an HMAX signature. Let's say you need to 268 00:18:49,020 --> 00:18:53,580 do quadruple URL encoding. If you need to do something weird, we 269 00:18:53,640 --> 00:18:58,140 put in hooks. So, you can provide your own Python that 270 00:18:58,140 --> 00:19:02,300 will ‑‑ it's a method and it will be provided with each HTTP 271 00:19:02,300 --> 00:19:05,380 request before it's sent. If you need to do something absolutely 272 00:19:05,380 --> 00:19:08,480 bizarre, you can specify that that needs to be done. That's 273 00:19:08,480 --> 00:19:09,940 another thing we're going to talk about in the demo. We're 274 00:19:09,940 --> 00:19:13,920 going to give an example of the HMAX signing. I think this is one 275 00:19:13,920 --> 00:19:15,980 of the really cool features about this tool is that it really 276 00:19:15,980 --> 00:19:19,540 allows you to totally customize things. If you need to do 277 00:19:19,540 --> 00:19:22,140 something totally crazy, you can do it. It's not our problem. 278 00:19:22,280 --> 00:19:23,620 It's not the tool's problem. You just need to do it. It's not 279 00:19:23,640 --> 00:19:26,540 the way you do it. So, you need to know what you're doing. But 280 00:19:26,540 --> 00:19:29,540 this ‑‑ and there's multiple places where you can get the 281 00:19:29,540 --> 00:19:32,560 hooks at. So, if you need to do weird processing on the response, 282 00:19:32,840 --> 00:19:35,780 you can do that, too. Pre request and post request, these 283 00:19:35,780 --> 00:19:37,900 are all things that I'm borrowing from this request HTTP 284 00:19:37,900 --> 00:19:40,340 library that I was talking about. We'll get into that a bit 285 00:19:40,340 --> 00:19:46,940 more later. Now, I believe it's time for a demo. If anyone is 286 00:19:46,940 --> 00:19:52,260 still awake. I love my nuts. What's up? Oh, yeah. This is the 287 00:19:52,260 --> 00:19:53,040 chopper. Okay. 288 00:19:56,620 --> 00:20:00,220 All right. So ‑‑ oh, yeah. Scott, what website should we 289 00:20:00,220 --> 00:20:03,960 try to attack? Attack the NSA. Oh, you think we should try to go 290 00:20:03,960 --> 00:20:06,640 after the NSA? I bet you can pull this out. Oh, yeah. Okay. 291 00:20:06,780 --> 00:20:08,780 All right. So ‑‑ all right. I guess we're going to try to 292 00:20:08,780 --> 00:20:11,480 take down the NSA. Yeah. It's going to look pretty cool. Yeah. 293 00:20:11,480 --> 00:20:16,560 All right. So, let's see. What's their website? NSA.gov? That's 294 00:20:16,560 --> 00:20:19,780 right. All right. So, here we have the NSA. Awesome. Do you 295 00:20:19,780 --> 00:20:22,000 think they're super ‑‑ I'm sure there's probably a really 296 00:20:22,000 --> 00:20:23,620 awesome admin log in for the NSA. I'm sure there's probably a 297 00:20:23,640 --> 00:20:24,920 really awesome admin log in for this website. See if you can 298 00:20:24,920 --> 00:20:27,100 find it. All right. I'm just going to ‑‑ We just ran a 299 00:20:27,100 --> 00:20:29,680 dirt buster on it all day. Yeah. All right. So, look what we 300 00:20:29,680 --> 00:20:35,060 found. There's a file on the NSA.gov called SQL. Never 301 00:20:35,060 --> 00:20:37,720 expect that. Oh, look at that awesome log in. Look at that 302 00:20:37,720 --> 00:20:43,260 awesome log in, guys. That's crazy. All right. All right. So, 303 00:20:44,540 --> 00:20:47,540 basically, the password for this user is secret, right? So, we 304 00:20:47,540 --> 00:20:50,460 get a message when we log in. It says, you are auth as user one. 305 00:20:50,580 --> 00:20:53,620 Here are some secrets. When Ben types an incorrect password, you 306 00:20:54,880 --> 00:20:57,740 get a different response. And we're going to kind of use this as 307 00:20:57,740 --> 00:21:01,760 a seat for our attack, right? So, we're going to conduct a blind 308 00:21:01,760 --> 00:21:04,380 SQL injection attack against this log in form. We're going to 309 00:21:04,380 --> 00:21:08,240 use the fact that the response sizes are different. And as you 310 00:21:08,240 --> 00:21:10,680 see Ben right now, he's kind of doing the or one equals one. 311 00:21:10,880 --> 00:21:16,080 He's trying to ‑‑ yeah, good job zooming in there. Trying to ‑‑ 312 00:21:17,180 --> 00:21:20,480 yep, and now we're auth as user one. So, go ahead and do or one 313 00:21:20,480 --> 00:21:23,620 equals two. All right. All right. All right. All right. All 314 00:21:23,640 --> 00:21:26,220 right. So, now we have kind of a true and false statement. And we 315 00:21:26,220 --> 00:21:29,000 know that we can pivot off the fact that the response code size 316 00:21:29,000 --> 00:21:31,560 is going to be of a different length, right? So, that will be 317 00:21:31,560 --> 00:21:35,080 what we're going to use when we actually conduct the attack to 318 00:21:35,080 --> 00:21:39,100 determine if what we're doing is working or not. All right. So, 319 00:21:39,160 --> 00:21:44,000 go ahead and do a little bit more of an advanced string here. 320 00:21:44,840 --> 00:21:47,260 Actually, I'm going to build this out in an editor. 321 00:21:47,800 --> 00:21:52,580 Excellent. Or I could be lazy and just use the one I wrote earlier. 322 00:21:53,640 --> 00:22:01,000 There we go. So, we're going to go ahead and copy out kind of a prebuilt 323 00:22:01,000 --> 00:22:03,580 out string we've done here. This is very similar to the demo we walked 324 00:22:03,580 --> 00:22:06,940 through earlier, right? We're going to do a sub string of the user and 325 00:22:06,940 --> 00:22:09,240 we're going to see if it's greater than the value of zero. We're going 326 00:22:09,240 --> 00:22:11,900 to comment out the rest of the query. So, we're taking the first 327 00:22:11,900 --> 00:22:15,600 character of the user name and looking at the ASCII value of that and 328 00:22:15,600 --> 00:22:18,720 we're trying to guess what that is essentially. All right. So, this 329 00:22:18,720 --> 00:22:23,540 is pretty straightforward blind SQL injection. We wanted to keep the 330 00:22:23,640 --> 00:22:26,480 demo simple, but you can kind of imagine that query string could be 331 00:22:26,480 --> 00:22:29,160 anything you could possibly imagine. We'll show you why that's the case 332 00:22:29,160 --> 00:22:32,100 when we actually run the tool. And the reason why I just copied 333 00:22:32,100 --> 00:22:35,340 something different is because that is a URL encoded version of that. 334 00:22:35,640 --> 00:22:40,460 So, things like the hash character don't get interpreted as the fragment 335 00:22:40,460 --> 00:22:45,260 portion of the URL. All right. Cool. So, we know that we got our 336 00:22:45,260 --> 00:22:50,180 query built out and we know that it's working. So, at this point, go 337 00:22:50,180 --> 00:22:53,620 ahead and do a false statement. So, see here, we're looking at the 338 00:22:53,640 --> 00:22:58,340 first character and if we say it's greater than zero, it turns out to be 339 00:22:58,340 --> 00:23:02,400 true because the first character has an ASCII value that's greater than 340 00:23:02,400 --> 00:23:07,800 zero. If we ask if it's less than zero, we get a false statement. It 341 00:23:07,800 --> 00:23:11,580 interprets as false. Cool. All right. So, at this point, we got our 342 00:23:11,580 --> 00:23:14,680 query built out. Now it's time to run barbecue SQL. So, I'm going to 343 00:23:14,680 --> 00:23:19,080 talk a little bit about the UI here. Basically, this probably looks 344 00:23:19,080 --> 00:23:22,700 familiar. Anybody use the social engineering toolkit? Anybody? 345 00:23:23,640 --> 00:23:27,320 Okay. A handful of folks. Yeah. So, Dave, I talked to Dave because I 346 00:23:27,320 --> 00:23:31,140 really like this UI. He said go for it. So, we kind of took his code and 347 00:23:31,140 --> 00:23:34,460 just hacked the hell out of it, added a couple of feature improvements to 348 00:23:34,460 --> 00:23:38,060 make it a little bit more slick. But this user interface gives you a 349 00:23:38,060 --> 00:23:42,840 really nice way to set up all the complicated request options. And so, 350 00:23:42,920 --> 00:23:45,620 we'll kind of go ahead and just walk through some of the different 351 00:23:45,620 --> 00:23:48,540 configuration options, some of the features of barbecue SQL that make it 352 00:23:48,540 --> 00:23:51,260 distinct and unique. So, first, let's go ahead and take a look at the 353 00:23:51,260 --> 00:23:52,180 barbecue SQL options. 354 00:23:56,320 --> 00:24:00,880 Cool. All right. So, barbecue SQL has the following configuration 355 00:24:00,880 --> 00:24:03,780 parameters and we'll kind of walk through each one. Let's go ahead and 356 00:24:03,780 --> 00:24:13,540 take a look at query first. Cool. You guys see this okay or is it pretty hard to read? 357 00:24:15,200 --> 00:24:23,560 Working on it. Okay. That will do. That's what we're enjoying. Cool. 358 00:24:23,640 --> 00:24:25,880 So, this is what we're injecting. So, I'll talk a little bit about the 359 00:24:25,880 --> 00:24:30,800 template tags here and how this works. As I kind of mentioned before, you need to specify 360 00:24:30,800 --> 00:24:36,820 template tags for particular areas of the query that you want to inject in. And it's pretty 361 00:24:36,820 --> 00:24:42,640 straightforward here. We're basically saying we're going to do the substring for selecting 362 00:24:42,640 --> 00:24:48,060 data from data. And we're going to use row index, right? So, row index is going to specify 363 00:24:48,060 --> 00:24:53,620 which row we're going after the data. Character index is going to specify where is the data and if 364 00:24:53,640 --> 00:24:56,960 which character position are we going after? You'll see this 365 00:24:56,960 --> 00:25:02,540 notation that we have a colon and then we have a number. These 366 00:25:02,540 --> 00:25:04,860 are kind of the default values you want to specify. So we're 367 00:25:04,860 --> 00:25:07,140 basically saying we're going to start with row one. We're going 368 00:25:07,140 --> 00:25:09,540 to start with character position one. And then we need to 369 00:25:09,540 --> 00:25:12,560 specify our comparison operator, right? Typically you're going to 370 00:25:12,560 --> 00:25:15,740 want to specify the greater than operator. And then we're going 371 00:25:15,740 --> 00:25:18,100 to compare that against the character value zero. Once again 372 00:25:18,100 --> 00:25:21,340 that's just a default value. So you don't need to be too 373 00:25:21,340 --> 00:25:23,400 concerned about that. There's a couple other tags you can 374 00:25:23,400 --> 00:25:26,580 actually specify that we're not using in this example. Let's say 375 00:25:26,580 --> 00:25:30,460 you're doing a time based blind SQL injection attack. And you'll 376 00:25:30,460 --> 00:25:32,640 see in the description here we try to do a pretty good job with 377 00:25:32,640 --> 00:25:35,860 the documentation. You can specify the template sleep, for 378 00:25:35,860 --> 00:25:38,880 example. And then you can specify the number of seconds or 379 00:25:38,880 --> 00:25:43,000 milliseconds you want to sleep. So you can do time based blind 380 00:25:43,000 --> 00:25:46,820 SQL injection as well. And one other thing that's important to 381 00:25:46,820 --> 00:25:50,180 note here. We were talking about how queries will either evaluate 382 00:25:50,180 --> 00:25:53,180 as true or false essentially based on the comparator value. 383 00:25:53,400 --> 00:25:56,720 So these default values, you want to build out something 384 00:25:56,720 --> 00:25:59,820 that's going to evaluate as true. And that way the tool can 385 00:25:59,820 --> 00:26:02,200 start to learn what a true response looks like versus a 386 00:26:02,200 --> 00:26:04,260 false response when it starts switching between the greater 387 00:26:04,260 --> 00:26:07,000 than and less than symbol. Exactly. All right. So let's go 388 00:26:07,000 --> 00:26:12,220 ahead and so a couple other options we have here. And we'll 389 00:26:12,220 --> 00:26:15,360 just kind of just walk through them. We have the CSV output 390 00:26:15,360 --> 00:26:17,840 file. So if you want to, you can dump all your results to a CSV. 391 00:26:18,620 --> 00:26:22,320 We can specify techniques. One thing that Ben was doing when he 392 00:26:22,320 --> 00:26:23,380 was doing the research for the SQL injection attack was he was 393 00:26:23,400 --> 00:26:25,580 looking for some of the libraries here was could we 394 00:26:25,580 --> 00:26:28,860 improve our exfiltration of data by doing a frequency based 395 00:26:28,860 --> 00:26:32,920 analysis search. And in some circumstances we actually found 396 00:26:32,920 --> 00:26:35,400 that it was more effective. But in general binary search is what 397 00:26:35,400 --> 00:26:39,700 we recommend using. Comparison attribute, you'll see when you 398 00:26:39,700 --> 00:26:42,700 actually click and take a look at that particular section. But 399 00:26:42,700 --> 00:26:45,580 you can specify. Go ahead and show that so they can see all 400 00:26:45,580 --> 00:26:50,300 the different options. We can determine if we're doing the 401 00:26:50,300 --> 00:26:53,060 injection correctly based on the following attribute. Status code. 402 00:26:53,400 --> 00:26:56,480 URL. Time. Size. Text. Content and coding. Right? So you have 403 00:26:56,480 --> 00:26:58,740 all these things you can kind of queue off of. And the tool is 404 00:26:58,740 --> 00:27:01,140 intelligent enough to help you determine if those things are 405 00:27:01,140 --> 00:27:08,640 changing or whatnot. So let's go ahead and do size. Cool. And 406 00:27:08,640 --> 00:27:10,540 then one of the really sweetness things about barbecue 407 00:27:10,540 --> 00:27:13,740 SQL is concurrency. Ben will go into greater detail when we 408 00:27:13,740 --> 00:27:16,520 finish the demonstration about how this tool is wicked fast. 409 00:27:16,920 --> 00:27:19,960 But here you can specify the number of concurrent micro 410 00:27:19,960 --> 00:27:23,120 threads you want attacking the database. We're going to go with 411 00:27:23,400 --> 00:27:27,140 25 because that sounds pretty cool. So one other thing to say 412 00:27:27,140 --> 00:27:32,960 about the comparison attribute. So this is what's changing when 413 00:27:32,960 --> 00:27:36,420 you switch between true and false. So if it's time, if the 414 00:27:36,420 --> 00:27:38,800 query takes longer to evaluate when it's true, you specify 415 00:27:38,800 --> 00:27:42,740 time. If it's the size of the response, you specify size. Just 416 00:27:43,320 --> 00:27:47,280 to make that clear. Cool. And then let's go ahead and take a 417 00:27:47,280 --> 00:27:50,480 look at the HTTP parameters. At a minimum you need to specify the 418 00:27:50,480 --> 00:27:53,060 URL and the method that you're going to use. But as we kind of 419 00:27:53,400 --> 00:27:55,520 talked about earlier, you could specify any of these different 420 00:27:56,500 --> 00:27:59,600 attributes. You could specify data. You could specify if you 421 00:27:59,600 --> 00:28:04,200 need to provide auth, basic auth or something like that. So here 422 00:28:04,200 --> 00:28:06,160 you just kind of configure. And one thing we should mention is 423 00:28:06,160 --> 00:28:10,600 that if you enter something incorrectly, so let's say you're 424 00:28:10,600 --> 00:28:14,160 typing out a URL or some sort of value and you just botch it and 425 00:28:14,160 --> 00:28:17,480 you have like seven back slashes or something in it, we have 426 00:28:17,480 --> 00:28:19,600 these validator methods and we'll talk a little bit about 427 00:28:19,600 --> 00:28:22,280 that later that will make sure that what you're entering is 428 00:28:22,280 --> 00:28:23,380 like actually well-tuned. So that's kind of what we're going 429 00:28:23,400 --> 00:28:23,620 to do here. And then we can create like the 430 00:28:23,620 --> 00:28:24,860 using it in the form of format of data. And that can be kind of 431 00:28:24,860 --> 00:28:27,920 handy when you're sending up a really complicated request. If 432 00:28:27,920 --> 00:28:30,680 you imagine, you know, doing that on the command line and it's 433 00:28:30,680 --> 00:28:32,600 not really working very well and you're like what the hell, 434 00:28:32,660 --> 00:28:34,580 what did I do wrong, well, here we're trying to check each 435 00:28:34,580 --> 00:28:36,540 individual component and we'll spit something out and it says 436 00:28:36,540 --> 00:28:39,960 you're not doing it right. When your SQL command takes up 437 00:28:39,960 --> 00:28:43,760 the whole terminal? Yeah. Yeah, that sucks. All right. 438 00:28:48,280 --> 00:28:52,120 So in the URL you'll see that we're basically specifying a tag 439 00:28:52,120 --> 00:28:53,380 injection, right? So there will be a specific thing that you 440 00:28:53,400 --> 00:28:56,880 this is where we're going to say, this is where we're going to inject our query into. The tag 441 00:28:56,880 --> 00:29:01,140 must be specified in some part of the HTTP request. As Ben mentioned earlier, it doesn't 442 00:29:01,140 --> 00:29:05,200 need to be in the URL. It can be in a cookie. It can be in a header. It can be in pretty much 443 00:29:05,200 --> 00:29:12,620 any object of the HTTP request. All right. So let's go back. And now for the fun stuff. So 444 00:29:12,620 --> 00:29:21,060 let's go ahead and run the exploit. What it's doing right now is, like I was 445 00:29:21,060 --> 00:29:26,360 saying, trying to establish what it means for a response to evaluate as true or false. It's 446 00:29:26,360 --> 00:29:31,240 doing some test ones and then it asks you for a confirmation. So we're kind of seeing here, 447 00:29:31,340 --> 00:29:35,760 right, we see this, the response size for the following is 3644. We can kind of tell that 448 00:29:35,760 --> 00:29:39,840 that's definitely different than 3602. And when we are kind of building out and testing our 449 00:29:39,840 --> 00:29:44,240 query in the first place by hand, this looks pretty good. So let's go ahead and fire it up. 450 00:29:47,160 --> 00:29:51,040 All right. So basically what's happening right now is we are at super, super high quality 451 00:29:51,060 --> 00:29:59,160 for crazy high speeds, doing Boolean based or binary search, blind SQL injection based off the 452 00:29:59,160 --> 00:30:06,600 size. So this is all data from the database. You see the number of requests in the bottom left 453 00:30:06,600 --> 00:30:11,540 here, number of failures. We see how many rows we're enumerating. We see the working number of 454 00:30:11,540 --> 00:30:16,480 threads. We see the time of the attack and the amount of characters per second. So right now 455 00:30:16,480 --> 00:30:21,040 we're averaging 38 characters per second, which is pretty damn quick. So we're kind of 456 00:30:21,040 --> 00:30:27,520 waiting. And we'll wait until the tool finishes running. Why the hell does the NSA have this 457 00:30:27,520 --> 00:30:42,680 in their database? Cool. All right. Thanks, guys. So at this point it dumps out all 458 00:30:42,680 --> 00:30:49,720 your data into a list object. A Python list. Python list. And you can just hop into your Python 459 00:30:49,720 --> 00:30:51,020 interpreter, start working with it. And then you can go ahead and start working with the data. So 460 00:30:51,540 --> 00:30:57,480 you know, Ben's going to go ahead and just reformat it, maybe print it out, clean it up a little 461 00:30:57,480 --> 00:31:03,220 bit. Here we go. So, you know, it gives you the data right at your fingertips so you can start 462 00:31:03,220 --> 00:31:13,220 munging with it and formatting it the way you want to format it. Cool. All right. 463 00:31:17,220 --> 00:31:21,020 Back to PowerPoint. All right. All right. All right. All right. All right. All right. All 464 00:31:21,020 --> 00:31:27,580 right. So like I mentioned earlier, one of the things that we really tried to work hard on with 465 00:31:27,580 --> 00:31:33,180 this tool is getting it to be very, very fast. There's two main things that we were playing with 466 00:31:33,180 --> 00:31:39,080 with this. The first is how we're making our HTTP requests. So a lot of tools and I 467 00:31:39,080 --> 00:31:45,120 historically also have used threading when I needed to do many things at the same time. We're 468 00:31:45,120 --> 00:31:51,000 not doing that here. The other thing that I'm going to be talking about in terms of speed is, you know, 469 00:31:51,020 --> 00:31:55,940 the search algorithms that we're using. Scott touched on that briefly earlier. I'll cover it in 470 00:31:55,940 --> 00:32:04,880 more depth very shortly. So first the concurrency. I'm using a library called G requests. And I'm 471 00:32:04,880 --> 00:32:11,260 sure not many people have heard of that. It's a combination of Python's G event and the Python 472 00:32:11,780 --> 00:32:16,860 requests library. First I'm going to talk a little bit about what G event is. G event is a 473 00:32:16,860 --> 00:32:20,520 coroutine based Python networking library that uses greenlit to provide high level 474 00:32:20,520 --> 00:32:21,000 synchronization. And it's a very, very powerful tool. It's a very, very powerful tool. It's a 475 00:32:22,640 --> 00:32:27,580 very, very powerful tool. All right. Can I move on? All right. So I'm going to talk a little bit 476 00:32:27,580 --> 00:32:33,260 about what that means. So what we have is coroutines. And you can think about coroutines as 477 00:32:33,260 --> 00:32:37,480 being functions essentially. But you're spawning a bunch of them that run at the same time. So 478 00:32:37,480 --> 00:32:43,880 this seems familiar if you've done threading. But the thing here is that we, the event or the 479 00:32:44,620 --> 00:32:50,940 process scheduling is much more explicit and we have much more access to that. So you're spawning a 480 00:32:50,940 --> 00:32:56,120 up all of these functions, all of these code routines, only one of them is actually running 481 00:32:56,120 --> 00:33:02,520 at a time. And what happens is that it runs until it hits blocking IO. And what blocking is, 482 00:33:02,640 --> 00:33:07,380 is when you're trying to read and whatever you're trying to read isn't ready to be read, so 483 00:33:07,380 --> 00:33:11,520 for example if you're trying to read off of a socket, that's blocking IO. So if you have one 484 00:33:11,520 --> 00:33:15,260 thread and you're not doing any sort of event driven stuff, when you hit blocking, the 485 00:33:15,260 --> 00:33:20,400 program just hangs and waits until it can read. So with Geovent, though, when it hits 486 00:33:20,400 --> 00:33:26,580 blocking it jumps to that next code routine and then execution picks up there. And then as 487 00:33:26,580 --> 00:33:31,600 soon as that code routine or that function hits blocking IO it jumps to the next one and then to 488 00:33:31,600 --> 00:33:35,600 the next one as it hits this blocking. And what you wind up with is what's called an event 489 00:33:35,600 --> 00:33:39,820 loop where you have something that seems a lot like threading but you're not actually doing 490 00:33:39,820 --> 00:33:46,060 threads. And you don't have a lot of the overhead that you have with threading, but it's 491 00:33:46,920 --> 00:33:50,140 functionally like threading. And this is different also than a lot of the other event driven 492 00:33:50,140 --> 00:33:50,380 stuff. It's a little bit different from threading. It's a little bit more complex than threading. 493 00:33:50,400 --> 00:33:54,680 stuff, this is not callback based. This is co‑routine based which makes it a lot more 494 00:33:54,680 --> 00:33:58,460 accessible to those of you who have worked with threading before. What you can do though is 495 00:33:58,460 --> 00:34:04,200 because you have this ability to jump to the next co‑routine when you hit blocking, you can 496 00:34:04,200 --> 00:34:10,040 have hundreds of outstanding requests. So you can make an HTTP request and then when you're 497 00:34:10,040 --> 00:34:13,400 waiting for the response, you're not sitting there waiting, you're executing code in the 498 00:34:13,400 --> 00:34:17,620 next co‑routine. So this is what allows you to have a lot of shit going on at the same 499 00:34:17,620 --> 00:34:23,760 time. And we get a lot of performance out of that. So then the other thing that G request 500 00:34:23,760 --> 00:34:30,840 does is it combines G event with requests. Requests is a really, really cool library. They 501 00:34:30,840 --> 00:34:37,840 call themselves HTTP for humans. This was designed by Kenneth Wrights. He's a really 502 00:34:37,840 --> 00:34:43,840 awesome API designer. He's written a lot of cool stuff. He's a great developer. I've had 503 00:34:43,840 --> 00:34:47,600 fun trying to contribute to this library. It's a really cool API. It's a really cool API. It's 504 00:34:47,620 --> 00:34:51,240 really, really nice. For those of you who are Python people and who have worked with 505 00:34:51,240 --> 00:34:58,240 URLib 2, I really, really, really hate URLib 2. It sucks to use. I'm sorry if whoever wrote 506 00:34:58,240 --> 00:35:03,040 that is here. I really doubt that they are. But I don't like talking crap about other 507 00:35:03,040 --> 00:35:09,920 people's stuff. But I hate URLib 2. This really is HTTP for humans. It makes your life way 508 00:35:09,920 --> 00:35:16,380 easier if you're ever doing anything like this tool. So yeah. When you combine G event and 509 00:35:16,380 --> 00:35:17,600 request library, it's a really cool API. It's a really cool API. It's a really cool API. It's a 510 00:35:17,620 --> 00:35:22,020 really cool API. You wind up with G requests. So you're able to do good evented HTTP in 511 00:35:22,020 --> 00:35:28,960 Python, which is a pretty cool thing to be able to do without much work. The other main thing 512 00:35:28,960 --> 00:35:33,400 that we're doing for performance is we're using different search algorithms. So when we're 513 00:35:33,400 --> 00:35:37,880 talking about how we're grabbing that substring and we're grabbing the first character of the 514 00:35:37,880 --> 00:35:44,400 user name and we're getting the ASCII value of that, what you intuitively might want to do is 515 00:35:44,400 --> 00:35:47,600 you want to check that value against each point in the string. So you want to check the 516 00:35:47,600 --> 00:35:53,000 possible ASCII value. So this is what's called a linear search. It takes a long time. Here's 517 00:35:53,000 --> 00:35:58,460 kind of an example. Hopefully that makes sense. If it doesn't, I'm sorry. You're going one at a 518 00:35:58,460 --> 00:36:04,600 time until you find the right answer. So you're saying is the first letter of the user name, is 519 00:36:04,600 --> 00:36:09,900 it an A, is it a B, is it a C, until you find whatever it is. The average case with this is N 520 00:36:09,900 --> 00:36:17,300 over 2. Best case is 1. Worst case is N. For those of you, I guess people who know what that 521 00:36:17,300 --> 00:36:22,340 means probably already know that. So the typical thing that you'll see with the SQL injection 522 00:36:22,340 --> 00:36:26,980 tool is what's called a binary search. Here you're still looking for that value. You're trying to 523 00:36:26,980 --> 00:36:32,540 figure out what the first letter of the user name is in the example that we've been using. But 524 00:36:32,540 --> 00:36:37,460 instead of going one by one, you take the whole space of possible values, you chop it in half, 525 00:36:37,560 --> 00:36:41,200 you say is it in this half or is it in this half. That's why we're using those greater than 526 00:36:41,200 --> 00:36:46,960 and less than symbols in the blind SQL syntax. And then you keep going down and down and down, 527 00:36:47,300 --> 00:36:51,800 saying it in half and half and half until you find the value. And the performance of this 528 00:36:52,320 --> 00:36:59,580 average case is O log N, which is a significant improvement over a linear search. And that's by 529 00:36:59,580 --> 00:37:04,880 default what BBQ SQL is using. The other thing that we were playing with and it can be 530 00:37:04,880 --> 00:37:09,920 beneficial in some instances is to do frequency based search. I know some other tools have done 531 00:37:09,920 --> 00:37:15,420 this before. I decided to try it myself. It's fun. So what I did is I analyzed thousands of 532 00:37:15,420 --> 00:37:22,600 open source books for the character frequency. And what I found, which isn't surprising for 533 00:37:22,600 --> 00:37:26,520 anyone who's done any cryptography, is that the most common character in all of these books was 534 00:37:26,520 --> 00:37:32,640 the space character followed by E, followed by T, followed by O, followed by A. So here when I 535 00:37:32,640 --> 00:37:36,520 was talking about that linear search where we're checking against one character at a time, 536 00:37:36,580 --> 00:37:41,140 saying is the first character A, is it B, is it C, is it D, here instead of going A, B, C, D, 537 00:37:41,240 --> 00:37:45,400 we're going based on the likelihood that we're going to encounter that character. So we're 538 00:37:45,420 --> 00:37:51,360 going to start with E, T, O, A. And that's what's ‑‑ that should be pretty familiar for 539 00:37:51,360 --> 00:37:56,500 anyone who's done any sort of cryptography. The other thing that I did to kind of enhance 540 00:37:56,500 --> 00:38:01,720 that a little bit is doing a diagram for diagram frequency analysis where we're not only 541 00:38:01,720 --> 00:38:05,740 looking at what's the most common character, we look at the last character we found and we 542 00:38:05,740 --> 00:38:09,160 say what's the most common character that's going to follow that. So the most common 543 00:38:09,160 --> 00:38:15,040 characters that are going to follow an E are an R or an N or a space. So instead of ‑‑ and we 544 00:38:15,040 --> 00:38:18,780 try to factor that into the decision of what order we're doing when we're doing a linear 545 00:38:18,780 --> 00:38:23,900 search. So if you think about English, you know, if you see an L, you're probably going to see 546 00:38:23,900 --> 00:38:27,000 another L after that. That's the most common thing. So that's what we're talking about here. 547 00:38:28,340 --> 00:38:33,580 This is very, very effective against nonentropic data. So if you aren't looking at hashes, if 548 00:38:33,580 --> 00:38:38,280 you're looking at English, if you're looking at plain text, it's very good because there is 549 00:38:38,280 --> 00:38:44,420 that structure and that order and that well‑defined frequency. So here with English, I was 550 00:38:44,420 --> 00:38:50,320 essentially dumping the books that I had previously used for generating the sample. About 10 551 00:38:50,320 --> 00:38:55,000 requests per character. Python, which is a little bit more structured because it's a 552 00:38:55,000 --> 00:38:58,240 programming language, we see even better performance with eight requests per character. I 553 00:38:58,240 --> 00:39:03,880 think I was trying to dump the whole Django source code, which is kind of a lot, but I wound 554 00:39:03,880 --> 00:39:10,580 up getting eight requests per character, which is good. Credit card numbers, I got about 5.5, 555 00:39:10,620 --> 00:39:14,400 which is kind of funny because with a normal binary search, you're going to have a lot of 556 00:39:15,500 --> 00:39:19,200 performance improvement. With a normal linear search, you'd expect to get five exactly, but 557 00:39:19,200 --> 00:39:23,160 somehow I managed to get 5.5. So not quite as good. Yeah, I kind of screwed that one up, I 558 00:39:23,160 --> 00:39:28,640 guess. Yeah, but when you compare it to a binary search with English, you get 12 characters, or 559 00:39:28,640 --> 00:39:33,720 12 requests per character, so you get a slight performance improvement. One other thing we 560 00:39:33,720 --> 00:39:37,880 kind of wanted to step through real quick was why don't you show the hooks that we're working 561 00:39:37,880 --> 00:39:41,760 on today. Sorry, yeah. So yeah, before we were coming here, we were trying to think of ‑‑ we 562 00:39:41,760 --> 00:39:44,380 added this functionality that we were kind of mentioning earlier that we're going to use in the 563 00:39:45,300 --> 00:39:50,040 request object to do really funky stuff when you're doing blind SQL injection. And one of the 564 00:39:50,040 --> 00:39:55,400 things that I came across on a recent assessment is that I needed to H max sign each request, and it 565 00:39:55,400 --> 00:40:00,720 was kind of a pain in the ass. And, you know, you kind of imagine that like if you're trying to do 566 00:40:00,720 --> 00:40:03,840 an assessment and you have to do that, you're like, well, this is kind of frustrating when I 567 00:40:03,840 --> 00:40:08,920 have to whip up some Python proxy and do all this stuff. If you find blind SQL injection on that 568 00:40:08,920 --> 00:40:14,360 type of object, you can use the hook code that I'll talk about here. Yeah. So, you know, I'm 569 00:40:14,380 --> 00:40:19,000 like I was saying, we have these hooks, so you can intercept each and every request right before it 570 00:40:19,000 --> 00:40:23,460 gets sent or you can intercept the response right after it gets received. And what this allows you 571 00:40:23,460 --> 00:40:28,080 to do is it allows you to do funky things like H max signing parameters. So the way that you 572 00:40:28,080 --> 00:40:33,020 implement this or the way that you use it with the tool, the way that you use it with the tool is 573 00:40:33,020 --> 00:40:38,900 that you create a file called barbecue SQL underscore hooks dot py in your current working 574 00:40:38,900 --> 00:40:43,760 directory. And if anyone can think of a better way of doing this, please let me know. It's hard to 575 00:40:44,740 --> 00:40:49,940 import in Python from arbitrary files like user defined files. If anyone knows a good solution 576 00:40:49,940 --> 00:40:54,880 for that, let me know. So, yeah, you have to make the barbecue SQL underscore hooks dot py. And 577 00:40:54,880 --> 00:41:00,940 then in here, you'll define your own functions. And for a request hook, you're going to have a 578 00:41:00,940 --> 00:41:06,820 function that accepts your request. And this object is from that request library that I was 579 00:41:06,820 --> 00:41:09,560 talking about. And once again, if you haven't checked it out and you're a Python person, you 580 00:41:09,560 --> 00:41:14,360 should definitely check it out. So, yeah, it's going to take the request object and then it's going 581 00:41:14,360 --> 00:41:18,840 to do whatever the hell you want to it. So if you want to grab the URL and you want to parse it is 582 00:41:18,840 --> 00:41:25,680 what we're doing here. And then we're H max signing the query portion of the URL, grabbing the hex 583 00:41:25,680 --> 00:41:33,140 digest. Now I have an H max. You can put that back into the URL and then return the request. So 584 00:41:33,140 --> 00:41:39,040 now you're H max signing every single request, which is pretty cool. Right. And we can do all 585 00:41:39,040 --> 00:41:43,780 sorts of things. Another hook file that we actually wrote was the quadruple URL in code. I've never 586 00:41:43,780 --> 00:41:47,880 come across that on an assessment. Sometimes you see double. Sometimes you see double if you're 587 00:41:47,880 --> 00:41:52,640 attacking an Oracle database or something, right? So I don't think we have enough time to do the 588 00:41:52,640 --> 00:42:02,540 demo, so we'll just step back. Is that all for me? No. Okay. So I talked a little bit earlier, 589 00:42:02,680 --> 00:42:06,720 but the UI is basically built on the source for the social engineering tool kit. And I also 590 00:42:06,720 --> 00:42:11,160 mentioned that input validation is performed on each configuration option. This is really 591 00:42:11,160 --> 00:42:13,760 handy. At least we found it to be pretty handy. Because you can do a lot of things with it. You 592 00:42:14,540 --> 00:42:18,540 know, you're setting up these really complicated requests and things can get hairy pretty 593 00:42:18,540 --> 00:42:24,540 quickly, right? Especially if you're doing something weird. So by performing input validation on 594 00:42:24,540 --> 00:42:30,200 each of those objects within the UI, we can kind of help you or guide you along the way of you 595 00:42:30,200 --> 00:42:34,660 building out your complicated requests. Let's say you build out that really awesome complicated 596 00:42:34,660 --> 00:42:38,780 request. And you're like, all right, well, this is kind of a pain in the ass, I got it all built 597 00:42:38,780 --> 00:42:43,740 out. You can go ahead and export that to a configuration file. Reason using the config parser a lot. But it's 598 00:42:43,740 --> 00:42:48,520 library in Python. So it's really easy to work with. From there you can kind of just go and 599 00:42:48,520 --> 00:42:52,200 let's say you've built out this complicated request, you can kind of copy some of the 600 00:42:52,200 --> 00:42:56,720 configs and maybe at this point you're just changing the query object, right? And as we 601 00:42:56,720 --> 00:43:02,880 also mentioned, you can also export the results as a CSV file. So in a nutshell, that's 602 00:43:02,880 --> 00:43:08,900 barbecue SQL. And, you know, here's our credits and whatnot. We want to once again thanks 603 00:43:09,400 --> 00:43:13,180 Dave Kennedy for the social engineering toolkit stuff and him being so kind letting us 604 00:43:13,180 --> 00:43:18,900 use his awesome UI. And we thank you guys for coming and hearing about this new tool. And 605 00:43:18,900 --> 00:43:23,160 also Neo Hapsis is hiring if you guys are in AppSec and want to talk to us, come talk to us. 606 00:43:23,320 --> 00:43:27,500 We get a bonus if you come work for us. And download the tool.