1 00:00:00,000 --> 00:00:06,600 Thank you. All right. So we're going to do just a real brief thing about SQL injection. 2 00:00:07,220 --> 00:00:12,460 SQL injection often happens on websites. You have someone that has, say, a password thing. 3 00:00:12,880 --> 00:00:20,040 In this example, we got, you know, select star from users, and then you just pull it right out of the request object. 4 00:00:21,700 --> 00:00:28,300 So what you can do is you can insert and code in there and make the database do all sorts of fun stuff for you. 5 00:00:28,300 --> 00:00:33,220 For example, you can make the database server make DNS requests. 6 00:00:34,560 --> 00:00:43,880 So you just, in your SQL injection, make it so the database, in order to get its answer, it needs to look up an Internet host address. 7 00:00:45,340 --> 00:00:51,520 So you can look up a fictional host that we own. There can be really arbitrary data in there. 8 00:00:51,820 --> 00:00:57,940 So there's an outbound connection, but it's made by the DNS server, so it's probably not. 9 00:00:59,120 --> 00:01:03,280 Trapped by a firewall. Probably the IDS isn't going to catch it. 10 00:01:03,980 --> 00:01:06,200 And it's really not all that hard. 11 00:01:06,640 --> 00:01:10,680 So I'm going to show you a tool that we did to make it work. 12 00:01:12,620 --> 00:01:18,360 I'm assuming you have some knowledge of SQL injection, and you know something about DNS, web security. 13 00:01:19,500 --> 00:01:25,020 There's lots of different ways you can do SQL injection, and you can get data back. 14 00:01:25,400 --> 00:01:28,280 But we're just going to... 15 00:01:28,300 --> 00:01:29,660 We're going to talk about DNS exfiltration. 16 00:01:30,160 --> 00:01:33,020 So this tool is called Atomic Braille. 17 00:01:35,020 --> 00:01:36,400 So why did we do it? 18 00:01:36,500 --> 00:01:40,840 Well, DNS is usually available, so we can do that. 19 00:01:42,200 --> 00:01:46,880 It also turns out that it's a lot faster than some of the exfiltration techniques. 20 00:01:46,960 --> 00:01:49,560 For example, timing and change in page. 21 00:01:50,180 --> 00:01:55,120 You can often only do around a bit of information per injection. 22 00:01:55,400 --> 00:01:57,920 We can grab 200 bytes. 23 00:01:58,300 --> 00:01:59,040 If we want to. 24 00:02:00,820 --> 00:02:04,560 I also looked at some of the tools, and they kind of fell over in places. 25 00:02:04,740 --> 00:02:08,520 And I said, you know, it would be fun to do a tool that kind of does some of that. 26 00:02:10,580 --> 00:02:12,980 And then, you know, it's fun, too. 27 00:02:15,620 --> 00:02:16,020 Okay. 28 00:02:16,620 --> 00:02:18,440 And this tool attacks Oracle. 29 00:02:18,720 --> 00:02:20,680 Well, why would we attack Oracle? 30 00:02:21,020 --> 00:02:22,780 You know, there's a lot of Oracle tools. 31 00:02:23,800 --> 00:02:25,220 Oracle systems out there. 32 00:02:25,740 --> 00:02:27,980 Lots of the hacker tools seem to go against... 33 00:02:28,680 --> 00:02:33,320 Microsoft, SQL Server, MySQL. 34 00:02:33,620 --> 00:02:38,180 I haven't seen a DNS exfiltration against Oracle before. 35 00:02:38,800 --> 00:02:43,740 So let's show you a demo of it working. 36 00:02:52,080 --> 00:02:52,780 All right. 37 00:02:52,820 --> 00:02:54,400 So we're going to do a Wireshark capture. 38 00:02:54,680 --> 00:02:57,680 And then I'm going to make this laptop SQL inject. 39 00:02:57,760 --> 00:02:58,280 The one... 40 00:02:58,300 --> 00:02:58,420 Down here. 41 00:03:05,540 --> 00:03:08,980 So, as you can see, we're getting some HTTP requests. 42 00:03:09,540 --> 00:03:11,620 It's making DNS requests back. 43 00:03:12,580 --> 00:03:16,960 I'm not connected to the Internet, so the laptop is actually making DNS requests to itself, 44 00:03:17,220 --> 00:03:22,540 which the tool is capturing, extracting the information, and using that to do further injection. 45 00:03:23,000 --> 00:03:26,720 So, I don't know if you guys can see. 46 00:03:28,300 --> 00:03:29,120 What it did. 47 00:03:29,220 --> 00:03:32,280 But this is an example of one of the queries. 48 00:03:32,400 --> 00:03:34,580 I guess you can't see what it actually looks like. 49 00:03:34,680 --> 00:03:37,680 But there's a lot of data in some of these. 50 00:03:40,580 --> 00:03:41,020 So... 51 00:03:43,580 --> 00:03:46,020 I'm going to show you a command line interface. 52 00:03:47,760 --> 00:03:50,760 And now I'm just going to run it on this machine here. 53 00:03:50,940 --> 00:03:51,280 So... 54 00:03:56,860 --> 00:03:57,300 Okay. 55 00:03:57,400 --> 00:03:57,780 So... 56 00:03:58,520 --> 00:03:59,580 Let's see what it does. 57 00:04:00,340 --> 00:04:03,000 Right now, it's, you know, getting started. 58 00:04:03,480 --> 00:04:05,280 It's doing DNS exfiltration. 59 00:04:06,100 --> 00:04:08,100 There, it just got the schema for you. 60 00:04:08,220 --> 00:04:11,740 It got two lines of text from all those tables for you. 61 00:04:12,100 --> 00:04:12,880 There, we're done. 62 00:04:13,000 --> 00:04:14,940 It took, what, like 10 seconds? 63 00:04:17,760 --> 00:04:18,200 So... 64 00:04:22,680 --> 00:04:25,300 Let's look at some command line parameters we can do. 65 00:04:25,800 --> 00:04:28,040 We can tell it what IP to go to. 66 00:04:28,300 --> 00:04:29,480 What port to hit. 67 00:04:29,780 --> 00:04:30,960 You know, all the standard things. 68 00:04:31,440 --> 00:04:34,860 We can also tell it how many threads to use. 69 00:04:35,160 --> 00:04:39,580 We can tell it how big of DNS requests we want to make. 70 00:04:40,620 --> 00:04:42,960 So, if you want to be a little more stealthy, 71 00:04:43,000 --> 00:04:45,520 you could push that down so it looks a little more standard. 72 00:04:48,440 --> 00:04:49,940 All sorts of stuff like that. 73 00:04:50,140 --> 00:04:50,980 So, let's see. 74 00:04:52,880 --> 00:04:55,720 Let's take a look at another thing that this tool does. 75 00:04:56,160 --> 00:04:57,700 Which is, it gets... 76 00:04:57,700 --> 00:05:00,960 Kind of non-standard column names pretty easily. 77 00:05:01,120 --> 00:05:03,980 So, this is another schema that we're grabbing right here. 78 00:05:04,240 --> 00:05:07,360 And it's got table names like valid table name. 79 00:05:07,440 --> 00:05:10,560 With spaces and uppercase, lowercase letters. 80 00:05:13,360 --> 00:05:17,160 So, that's something that some tools aren't able to do. 81 00:05:17,420 --> 00:05:20,160 It's interesting to get that working. 82 00:05:20,850 --> 00:05:25,160 So, we'll go back to the presentation. 83 00:05:32,680 --> 00:05:34,480 Oh, it was nice enough to go back to the beginning. 84 00:05:36,160 --> 00:05:36,800 All right. 85 00:05:36,880 --> 00:05:39,940 So, what did we just do in the demo? 86 00:05:40,080 --> 00:05:41,880 I mean, it went through kind of fast. 87 00:05:41,960 --> 00:05:42,940 What just happened? 88 00:05:43,320 --> 00:05:50,180 This is an example of what it looks like on the database and web server. 89 00:05:50,640 --> 00:05:55,220 You know, it generated some spikes in the CPU 90 00:05:55,220 --> 00:05:57,120 because nothing else was happening on the system. 91 00:05:57,700 --> 00:05:58,420 But I had it home. 92 00:05:59,340 --> 00:06:04,460 In this case, I was running a server that was a little slower. 93 00:06:04,560 --> 00:06:06,680 So, it took about three minutes to get all the data. 94 00:06:07,600 --> 00:06:10,640 This is going on Oracle's HR schema, 95 00:06:10,720 --> 00:06:13,140 which is one of the standard schemas that comes with Oracle. 96 00:06:13,420 --> 00:06:17,440 So, if you install Oracle Express Edition, you get this HR schema. 97 00:06:17,700 --> 00:06:25,060 I added one table just because that's what I was keying off of in the SQL injection. 98 00:06:26,700 --> 00:06:27,600 I got that. 99 00:06:27,700 --> 00:06:31,660 I got out, in addition to the whole schema and all the data, 100 00:06:32,460 --> 00:06:34,300 I got out how it authenticates, 101 00:06:34,400 --> 00:06:36,620 the username that the web server connects as, 102 00:06:37,180 --> 00:06:39,180 the web server's internal IP, 103 00:06:39,420 --> 00:06:40,420 the database's IP, 104 00:06:41,960 --> 00:06:43,580 what language it uses, 105 00:06:44,960 --> 00:06:46,220 and its host name. 106 00:06:46,720 --> 00:06:49,860 Now, you could, after getting this sort of information, 107 00:06:50,140 --> 00:06:56,320 you could use SQL injection to do other things like port scan the internal network, 108 00:06:57,820 --> 00:06:58,980 and then you could use this to do other things, 109 00:06:58,980 --> 00:06:59,220 and then you could use it to do other things, 110 00:06:59,220 --> 00:07:02,520 but this tool is just grabbing data. 111 00:07:02,880 --> 00:07:06,260 So, all right. 112 00:07:06,380 --> 00:07:08,560 So, let's talk about Absinthe. 113 00:07:08,700 --> 00:07:13,200 I think it's kind of a de facto standard of SQL injection tools. 114 00:07:13,500 --> 00:07:14,640 A lot of people use it. 115 00:07:14,680 --> 00:07:15,280 It's a great tool. 116 00:07:17,040 --> 00:07:19,740 So, I think it serves a useful comparison. 117 00:07:20,180 --> 00:07:24,480 Absinthe and Oracle, it likes to do change in page comparisons. 118 00:07:25,680 --> 00:07:26,160 So, 119 00:07:28,000 --> 00:07:29,280 on the graph, 120 00:07:29,560 --> 00:07:35,800 we see how long it took to get a portion of what I got in my tool. 121 00:07:36,280 --> 00:07:38,700 So, this is about three minutes like the last one. 122 00:07:39,000 --> 00:07:41,500 With Absinthe, what we were able to get out is 123 00:07:41,500 --> 00:07:45,460 the username and the names of the tables in three minutes. 124 00:07:46,220 --> 00:07:48,280 So, we didn't get any column data. 125 00:07:48,840 --> 00:07:50,660 We didn't get any of the rows of data. 126 00:07:50,940 --> 00:07:52,800 So, okay. 127 00:07:52,860 --> 00:07:54,460 Well, how bad can that be, right? 128 00:07:58,200 --> 00:08:00,920 So, once again, 20 seconds for the schema, 129 00:08:01,520 --> 00:08:03,980 three minutes for all the data in my tool. 130 00:08:06,300 --> 00:08:09,840 So, if we were to get all the columns for the employees table, 131 00:08:09,980 --> 00:08:10,680 which is the biggest, 132 00:08:10,980 --> 00:08:13,920 it ends up taking about 10 minutes in Absinthe, 133 00:08:14,460 --> 00:08:16,320 in this case, on this server. 134 00:08:16,500 --> 00:08:19,860 So, there's a fairly big speed difference. 135 00:08:20,060 --> 00:08:24,620 Now, obviously, you're doing about one bit versus 200 characters. 136 00:08:24,660 --> 00:08:25,960 There's going to be a speed difference. 137 00:08:28,980 --> 00:08:30,240 So, how do we do it? 138 00:08:30,820 --> 00:08:33,280 This is where I'm going to tell you 139 00:08:33,900 --> 00:08:35,940 what sequence my code goes through, 140 00:08:36,500 --> 00:08:37,700 how we encode it. 141 00:08:37,960 --> 00:08:40,160 So, you can build your own, 142 00:08:40,200 --> 00:08:42,440 or you can see what I did. 143 00:08:44,300 --> 00:08:45,760 So, the sequence is, first of all, 144 00:08:45,820 --> 00:08:46,780 we're going to see if it works. 145 00:08:47,760 --> 00:08:50,000 And I just put a tag in there that says, 146 00:08:50,160 --> 00:08:52,400 okay, if I get this back in DNS, 147 00:08:52,680 --> 00:08:54,860 I know it's working, and I got you. 148 00:08:55,460 --> 00:08:57,560 So, then, also in that, 149 00:08:57,700 --> 00:09:00,300 first request, I get back the number of tables in your database. 150 00:09:00,960 --> 00:09:02,840 So, then, we can get the table names, 151 00:09:03,180 --> 00:09:04,140 get the column names, 152 00:09:05,040 --> 00:09:06,820 get the column data types. 153 00:09:07,920 --> 00:09:11,580 You know, all that stuff Oracle keeps around in its database 154 00:09:11,580 --> 00:09:12,480 just for me to grab. 155 00:09:14,860 --> 00:09:17,420 And, also, we got username and other metadata. 156 00:09:19,480 --> 00:09:22,040 So, the DNS exfiltration part 157 00:09:22,700 --> 00:09:25,620 isn't just, you know, slap data into DNS. 158 00:09:26,360 --> 00:09:27,500 You've got to remember that 159 00:09:27,500 --> 00:09:29,140 the database is making the request. 160 00:09:31,180 --> 00:09:34,680 So, the database has to think it's a valid DNS request, 161 00:09:34,920 --> 00:09:36,560 or it's not going to make it. 162 00:09:37,000 --> 00:09:38,780 So, that's the first thing to remember. 163 00:09:40,940 --> 00:09:42,560 So, what we did is, 164 00:09:42,640 --> 00:09:44,620 this is an example of what would come back. 165 00:09:44,940 --> 00:09:51,940 So, 0414243 is an example of some hex data. 166 00:09:52,400 --> 00:09:54,680 You can get numbers, you can get strings. 167 00:09:57,500 --> 00:10:00,600 We also have some characters in there 168 00:10:00,600 --> 00:10:03,720 to make sure that this is actually a request that I sent out 169 00:10:03,720 --> 00:10:06,240 and we're not getting it back out of order. 170 00:10:07,780 --> 00:10:10,140 And then you have your domain name on the end 171 00:10:10,140 --> 00:10:12,760 so it resolves back to your computer. 172 00:10:20,140 --> 00:10:23,460 For example, on an integer, how would you do this? 173 00:10:25,280 --> 00:10:27,660 How many of you can't read this? 174 00:10:29,340 --> 00:10:31,160 Okay, people in the back can't read. 175 00:10:34,940 --> 00:10:40,320 Basically, what we're doing is select utilinatter.gethostaddress. 176 00:10:40,460 --> 00:10:45,600 That tells Oracle, hey, do a DNS request. 177 00:10:46,300 --> 00:10:47,900 And then we're going to do a case 178 00:10:47,900 --> 00:10:50,340 because we can't have a null in there 179 00:10:50,340 --> 00:10:52,760 or that's going to throw everything off 180 00:10:52,760 --> 00:10:53,440 because nulls are going to throw everything off. 181 00:10:53,440 --> 00:10:56,820 A null will say, oh, well, that's no longer a valid DNS request. 182 00:10:57,060 --> 00:10:59,840 Everything's got to be 1 to 63 characters. 183 00:11:00,100 --> 00:11:01,140 We've got to smash it in there. 184 00:11:01,720 --> 00:11:06,440 So then we say, okay, is this a negative number? 185 00:11:07,240 --> 00:11:11,680 Okay, in this case, it's not going to be negative 186 00:11:11,680 --> 00:11:13,220 because it's the length of a name, 187 00:11:13,380 --> 00:11:16,320 but it does it the same for every number. 188 00:11:16,480 --> 00:11:18,500 So is this small enough? 189 00:11:18,540 --> 00:11:19,560 Is this negative? 190 00:11:20,620 --> 00:11:23,300 So if it's negative, then we put a tag on that. 191 00:11:23,440 --> 00:11:25,760 If it's not negative, then we just return it 192 00:11:25,760 --> 00:11:29,100 because you can't have a dash at the beginning of a DNS field. 193 00:11:29,300 --> 00:11:30,280 That would be invalid. 194 00:11:30,640 --> 00:11:31,720 So things like that, 195 00:11:32,320 --> 00:11:34,540 you've just got to pay attention to when you're doing a tool. 196 00:11:38,840 --> 00:11:39,740 So let's see. 197 00:11:39,820 --> 00:11:40,580 Here's another one. 198 00:11:40,820 --> 00:11:43,060 This one is for getting raw data, 199 00:11:43,200 --> 00:11:45,460 like you can get blobs out of the database with this. 200 00:11:45,860 --> 00:11:49,960 So basically, you need to do a substring 201 00:11:49,960 --> 00:11:53,020 to make sure, once again, you smash it down to the right size. 202 00:11:53,440 --> 00:11:55,840 You do a util raw cast from number. 203 00:11:55,980 --> 00:11:56,940 So you've got a number here. 204 00:11:57,300 --> 00:12:00,940 You're going to return it as hex-encoded data. 205 00:12:01,420 --> 00:12:04,860 And Oracle is happy to do that for you, 206 00:12:04,920 --> 00:12:08,320 and hex-encoded data fits nice into DNS. 207 00:12:09,360 --> 00:12:11,200 So once again, you've got to trap. 208 00:12:11,320 --> 00:12:13,020 Make sure you don't get too many characters. 209 00:12:13,480 --> 00:12:16,020 You can't get zero characters, so you've got to trap null. 210 00:12:17,620 --> 00:12:20,440 Or for strings, you trap empty string too. 211 00:12:20,780 --> 00:12:22,260 Strings are a little tricky. 212 00:12:22,960 --> 00:12:23,280 Tricky. 213 00:12:23,440 --> 00:12:24,260 I've just done them as raw, 214 00:12:24,360 --> 00:12:27,600 but I ended up having a little more fun with it. 215 00:12:27,860 --> 00:12:29,880 I actually do a regex to see, 216 00:12:30,020 --> 00:12:33,240 is this a nice valid string for me that I can just throw through, 217 00:12:33,960 --> 00:12:35,840 or do I need to do some modifications, 218 00:12:36,020 --> 00:12:41,040 like do I need to encode it as raw? 219 00:12:41,360 --> 00:12:42,460 Is it too big? 220 00:12:42,620 --> 00:12:44,420 Do I need to chop it down? 221 00:12:47,380 --> 00:12:49,940 So that's how I'm handling strings. 222 00:12:50,640 --> 00:12:52,660 So atomic braille, what is it? 223 00:12:53,440 --> 00:12:56,260 It's a tool to exfiltrate arbitrary data from Oracle. 224 00:12:57,540 --> 00:12:59,880 It automates generating the injection strings. 225 00:13:00,220 --> 00:13:03,580 So, I mean, you didn't see me typing out anything of how to inject it. 226 00:13:03,700 --> 00:13:05,560 That all gets built for you automatically. 227 00:13:06,200 --> 00:13:08,600 It receives and processes the DNS queries. 228 00:13:08,820 --> 00:13:11,180 You don't have to look at Wireshark to see what's coming back. 229 00:13:11,820 --> 00:13:12,980 Read the data out yourself. 230 00:13:13,180 --> 00:13:14,480 It all does it behind the scenes. 231 00:13:15,040 --> 00:13:18,620 And then it just says, oh, well, this is how many tables you have. 232 00:13:18,920 --> 00:13:19,980 Let me go grab them. 233 00:13:20,280 --> 00:13:21,100 This is a table. 234 00:13:21,220 --> 00:13:22,280 How many columns does it have? 235 00:13:22,560 --> 00:13:22,960 All right. 236 00:13:23,000 --> 00:13:23,420 Let me go grab them. 237 00:13:24,880 --> 00:13:26,860 The tool doesn't do everything. 238 00:13:27,260 --> 00:13:28,700 It won't cook you dinner, even. 239 00:13:29,940 --> 00:13:32,280 But some other things it won't do for you. 240 00:13:32,420 --> 00:13:36,020 It won't find SQL injection sites for you. 241 00:13:36,240 --> 00:13:39,680 It doesn't process what Oracle calls the long data type, 242 00:13:39,840 --> 00:13:42,940 because you can't do any of your nice functions on it. 243 00:13:43,400 --> 00:13:45,340 You can't say how long it is. 244 00:13:45,500 --> 00:13:47,200 You can't take a substring of it. 245 00:13:47,420 --> 00:13:50,480 It's pretty useless, and it's deprecated by Oracle nicely. 246 00:13:52,240 --> 00:13:53,420 So related work is a lot of work. 247 00:13:53,420 --> 00:13:59,260 I got a lot of the ideas of how to do this from some of these things. 248 00:13:59,380 --> 00:14:02,160 You can read up on this sort of stuff if you want. 249 00:14:02,660 --> 00:14:08,660 Future work, the tool has issues with retrying things that fail. 250 00:14:09,040 --> 00:14:11,160 And obviously, they could fail sometime. 251 00:14:11,960 --> 00:14:17,240 I don't have a GUI, as you saw, a command line interface, other stuff like that, 252 00:14:17,480 --> 00:14:20,880 you know, threading, better support for certain things. 253 00:14:20,880 --> 00:14:25,700 So what can people do to prevent this sort of attack? 254 00:14:26,080 --> 00:14:31,760 Well, an easy thing to do would be to revoke privileges on you to Lynn Adder 255 00:14:31,760 --> 00:14:35,220 to your web, where you're connecting on the web. 256 00:14:35,860 --> 00:14:37,420 That will solve this problem. 257 00:14:37,580 --> 00:14:40,620 It will not solve timing, change in page, anything like that. 258 00:14:43,700 --> 00:14:48,620 You should set up your DMZ so it's not making DNS requests, 259 00:14:48,820 --> 00:14:49,600 because that's not... 260 00:14:50,880 --> 00:14:51,700 It's not going to be useful to you. 261 00:14:52,840 --> 00:14:54,720 But the most important thing is, you know, 262 00:14:54,740 --> 00:14:56,980 fixing those SQL injection sites in the first place. 263 00:14:57,540 --> 00:15:03,460 You just can't fix bad programming with patches all the time. 264 00:15:05,500 --> 00:15:07,500 Check inputs, double check. 265 00:15:12,100 --> 00:15:15,440 So once again, I think I said some of these things, 266 00:15:15,520 --> 00:15:17,860 but SQL injection is bad. 267 00:15:18,180 --> 00:15:19,580 It's fun to exploit, though. 268 00:15:20,260 --> 00:15:20,860 It's fun to exploit. 269 00:15:20,880 --> 00:15:21,160 It's fun to block DNS. 270 00:15:22,860 --> 00:15:27,140 So we have T-shirts at the back of the room over there. 271 00:15:27,400 --> 00:15:29,340 We're going to have them in the Q&A session 272 00:15:29,340 --> 00:15:31,020 if you want to come by and talk to us. 273 00:15:32,480 --> 00:15:34,180 And you can go to our website. 274 00:15:34,560 --> 00:15:36,080 You can email me if you want. 275 00:15:36,680 --> 00:15:39,320 We'll be in room 104 for Q&A. 276 00:15:40,680 --> 00:15:47,120 And I think if someone has a question that they'd like the whole group for, 277 00:15:47,280 --> 00:15:49,000 or we can just head over to the Q&A group. 278 00:15:51,580 --> 00:15:51,880 We'll be right back.