1 00:00:00,000 --> 00:00:03,000 SQL injection presentation. Give it up. 2 00:00:09,300 --> 00:00:14,140 Hi, everybody. I'm Cameron Hotchkiss. I'm here from Hexanity.org, and I'd like to thank you for coming. 3 00:00:14,320 --> 00:00:17,440 It's the hardcore of DEF CON that shows up to the last talk on the Sunday. 4 00:00:17,660 --> 00:00:19,960 Some people were coming in with their luggage, so that's pretty awesome. 5 00:00:20,380 --> 00:00:21,800 So thanks to you guys for showing up. 6 00:00:22,140 --> 00:00:25,180 I'm going to be talking about automating blind SQL exploitation. 7 00:00:25,180 --> 00:00:31,460 So I'm not going to focus on detecting blind SQL injections, more on getting the goodies from a blind SQL injection. 8 00:00:32,940 --> 00:00:34,580 So we're going to start off pretty basic. 9 00:00:36,020 --> 00:00:37,940 We'll start off with what is a SQL injection. 10 00:00:38,380 --> 00:00:41,020 Hopefully most of you have encountered the term at least before. 11 00:00:41,360 --> 00:00:43,420 It comes down to pretty much just one thing. 12 00:00:43,640 --> 00:00:50,820 It's client-supplied data, and it's passed to a web application, and it's not appropriately validated for bad stuff. 13 00:00:51,620 --> 00:00:55,160 Once this stuff goes on, because it wasn't validated, it goes on to be bad. 14 00:00:55,180 --> 00:00:59,160 It's going to be processed by commands, by the database, and that's when you have your fun. 15 00:01:01,040 --> 00:01:06,740 SQL injection, every type of SQL injection you're probably going to encounter can be used to do one of a couple things, 16 00:01:06,940 --> 00:01:09,300 which comes down to performing operations on the database. 17 00:01:09,780 --> 00:01:14,180 So when I say that, I mean you could use it to bypass authentication mechanisms. 18 00:01:14,880 --> 00:01:18,700 You could use it to read information that you probably shouldn't have privileges to, 19 00:01:18,800 --> 00:01:21,480 and people are assuming you don't have privileges to, but you do. 20 00:01:21,880 --> 00:01:24,600 And writing information to the database, 21 00:01:24,600 --> 00:01:30,360 such as new accounts or bogus data, stuff that's really going to mess up the DBA and make him cry in his sleep. 22 00:01:36,240 --> 00:01:41,620 So SQL injection comes down to roughly three main forms, breaking things down as we go along. 23 00:01:42,180 --> 00:01:47,360 The first form, well it's three main forms, is when you're reading information you're not supposed to get. 24 00:01:47,500 --> 00:01:50,880 And that's what we're going to be focusing on, that's what I mean by when we go on to exploit it. 25 00:01:52,880 --> 00:01:54,260 So the first method, 26 00:01:54,600 --> 00:01:56,620 is redirection and reshaping of the query. 27 00:01:56,980 --> 00:01:59,880 That's where the web application's displaying stuff in tables, 28 00:02:00,000 --> 00:02:03,560 and you can reshape the query to dump everything, beautifully formatted for you, 29 00:02:03,700 --> 00:02:06,740 print it out, show your friends, it's like, look at this, they even formatted it nicely. 30 00:02:08,700 --> 00:02:09,060 Usually, 31 00:02:10,860 --> 00:02:13,120 you'll need to know some of the schema to go about doing that, 32 00:02:13,200 --> 00:02:15,960 but if you're lucky, you can dump the schema in the tables and go from there. 33 00:02:16,660 --> 00:02:17,620 The second method, 34 00:02:17,760 --> 00:02:21,860 and the method a lot of people are familiar with, is the error-based injection. 35 00:02:22,200 --> 00:02:24,580 And that's predominantly in Microsoft SQL, 36 00:02:24,580 --> 00:02:31,100 it's a SQL server, you'll put in a SQL query that's poorly formed, 37 00:02:31,260 --> 00:02:34,100 it'll create an error message, and through the error message, 38 00:02:34,240 --> 00:02:37,080 you can reverse engineer that query that it was called with, 39 00:02:37,220 --> 00:02:39,640 then reverse engineer the schema of the database, 40 00:02:39,880 --> 00:02:45,440 and then start to pull out the actual information by forming bogus queries that says, 41 00:02:45,540 --> 00:02:48,580 oh, I can't convert the password to an integer, because the password's not an integer, 42 00:02:48,780 --> 00:02:50,660 but it displays the password right there for you. 43 00:02:51,140 --> 00:02:54,360 And the third method, the method we're going to be using for the rest of this talk, 44 00:02:54,580 --> 00:02:55,520 is blind injection. 45 00:03:01,500 --> 00:03:05,080 Now, when I say blind injection, there's a couple different definitions of that as well, 46 00:03:05,220 --> 00:03:07,440 so I'm just going to focus on the one that I mean. 47 00:03:08,020 --> 00:03:13,260 And when I say blind injection, I mean you can pass data to the web application, 48 00:03:13,680 --> 00:03:17,880 and it's still going to pass information back to you, but it's going to pass it very, very subtly, 49 00:03:17,960 --> 00:03:20,820 it's simply going to be able to respond to yes or no questions. 50 00:03:21,400 --> 00:03:23,560 So, you send a question to the database, 51 00:03:24,580 --> 00:03:26,680 it responds somehow, and it says, the answer is yes. 52 00:03:27,120 --> 00:03:34,360 So, but the problem is that any form of SQL injection can result in significant data leakage or data modification attacks. 53 00:03:34,760 --> 00:03:39,780 So, it's not that it's better or worse than another type of injection, 54 00:03:40,000 --> 00:03:44,140 they all have the same end result, which is the person running the web application getting screwed. 55 00:03:44,980 --> 00:03:48,800 So, with blind attacks, we're playing 20 questions with the web server. 56 00:03:48,940 --> 00:03:52,820 I'm sure everybody's played 20 questions when they were younger, it's like, are you a mineral? 57 00:03:53,280 --> 00:03:53,720 Yes. 58 00:03:54,240 --> 00:03:55,740 Tank? Excellent! 59 00:03:58,980 --> 00:04:02,200 But why focus on blind SQL injections? 60 00:04:03,200 --> 00:04:08,880 Well, the thing is, blind is just as common as almost any other form of SQL injection out there, 61 00:04:08,960 --> 00:04:13,220 and in fact, even the other SQL injections can be treated as blind if you'd want to. 62 00:04:13,880 --> 00:04:16,840 Most of the time you wouldn't want to because you actually want the information now, 63 00:04:17,400 --> 00:04:21,960 but the other problem with blind is that blind involves a false sense of security on the host. 64 00:04:22,160 --> 00:04:24,460 The $4 an hour Visual Basic program, 65 00:04:24,580 --> 00:04:28,260 or who put up that web application, who heard of SQL injection once in some class, 66 00:04:28,480 --> 00:04:32,540 decided, oh, there's error messages, they're bad, I'll hide them from everybody, and then I'm okay. 67 00:04:33,180 --> 00:04:33,780 He's not. 68 00:04:34,360 --> 00:04:37,600 So there's a false sense of security going on where they think they're safe, 69 00:04:37,640 --> 00:04:41,460 yet they're still just as vulnerable, except through a slightly modified attack. 70 00:04:42,300 --> 00:04:44,700 The big problem with blind SQL injections, though, 71 00:04:44,860 --> 00:04:48,620 the part of people who still are aware of them, they don't take them as seriously 72 00:04:48,620 --> 00:04:52,380 because they take far too long to perform manually. 73 00:04:52,420 --> 00:04:53,800 It's a large investment of time. 74 00:04:54,580 --> 00:04:58,640 And it's very time-consuming, tedious, painful to actually implement them. 75 00:04:59,040 --> 00:05:03,800 Has anybody in the room here actually performed a blind SQL injection by hand before? 76 00:05:05,280 --> 00:05:05,940 All right. 77 00:05:07,040 --> 00:05:07,960 That's about what I'm thinking. 78 00:05:11,740 --> 00:05:15,640 So at Hex90, we decided this was a pain in the ass, 79 00:05:15,720 --> 00:05:19,160 so we're going to write a tool to do it for us because we're really, really lazy up there. 80 00:05:19,460 --> 00:05:24,560 So we figured we needed an automated tool because we know we're playing 20Quest, 81 00:05:24,580 --> 00:05:27,000 but the reason we stopped playing 20Questions when we were four 82 00:05:27,000 --> 00:05:28,940 was the fact that it's really, really boring. 83 00:05:29,200 --> 00:05:30,760 But we can ask as many as we want. 84 00:05:30,820 --> 00:05:32,600 We don't have to stop at 20 and just keep on asking. 85 00:05:33,440 --> 00:05:35,780 As long as we have questions, the database will still answer 86 00:05:35,780 --> 00:05:38,000 as long as we haven't dossed it to oblivion. 87 00:05:39,040 --> 00:05:40,300 But we want the username. 88 00:05:40,480 --> 00:05:43,580 The username of the database, say it's a SQL server database, 89 00:05:44,460 --> 00:05:46,200 and they changed the username away from SA. 90 00:05:46,360 --> 00:05:47,120 They did something right. 91 00:05:47,920 --> 00:05:51,320 So we want to find out what the first letter of the username actually is. 92 00:05:51,680 --> 00:05:54,200 Well, that's going to take seven requests back and forth. 93 00:05:54,580 --> 00:05:58,660 But if there's eight characters in this username they're using, 94 00:05:59,220 --> 00:06:01,620 that's going to be 56 requests in total. 95 00:06:01,800 --> 00:06:03,440 Eight times 56, it's not that hard. 96 00:06:03,920 --> 00:06:07,400 But to find out that it was an eight-letter username in the first place, 97 00:06:07,580 --> 00:06:09,680 that's another six requests to the web server, 98 00:06:09,760 --> 00:06:10,900 just asking yes or no questions. 99 00:06:11,820 --> 00:06:14,540 So we're already at 62 questions for the username. 100 00:06:14,820 --> 00:06:16,680 The username really doesn't do us any good. 101 00:06:16,820 --> 00:06:18,120 It was just sort of, oh, I wonder what it is. 102 00:06:18,500 --> 00:06:22,880 So we're at 62 requests, and that's already starting to add up. 103 00:06:23,740 --> 00:06:24,560 So, of course, we're going to have to figure out how to do that. 104 00:06:24,580 --> 00:06:27,340 So a fairly conservative estimate is typing this into a web browser. 105 00:06:27,880 --> 00:06:32,740 This is going to take about 10 seconds per query to the web server. 106 00:06:33,140 --> 00:06:34,860 And assuming you don't make any mistakes, 107 00:06:35,100 --> 00:06:37,120 you haven't had too much coffee while you're doing it, 108 00:06:37,660 --> 00:06:40,640 then you're already looking at over 10 minutes 109 00:06:40,640 --> 00:06:43,700 just to get that eight-character username sitting there at your computer. 110 00:06:43,800 --> 00:06:48,660 It's like, and the username's value is greater than whatever. 111 00:06:48,900 --> 00:06:50,720 It's very, very painful to do. 112 00:06:50,980 --> 00:06:53,860 But as I said, the username isn't our goal. 113 00:06:53,860 --> 00:06:55,780 Probably, you're not going to run off to your friends like, 114 00:06:55,860 --> 00:06:56,580 I got the username! 115 00:06:57,460 --> 00:06:59,900 You're going to want to go, and you're going to want to get the schema. 116 00:07:00,180 --> 00:07:01,860 You're going to want to get the entire database. 117 00:07:02,140 --> 00:07:05,120 You're going to want to get basically the gold that's locked in the database. 118 00:07:10,880 --> 00:07:15,220 So if you want to perform a non-trivial penetration off of a web application, 119 00:07:15,900 --> 00:07:17,520 you're going to want the table names. 120 00:07:17,800 --> 00:07:19,160 You're going to want the column names. 121 00:07:19,460 --> 00:07:21,760 You're going to want the data types of the columns. 122 00:07:21,980 --> 00:07:23,660 You're going to want the actual data stored, 123 00:07:23,660 --> 00:07:29,460 and all of a sudden, you've gone from 10 minutes to hours, or days, or months, 124 00:07:29,620 --> 00:07:31,780 possibly years, depending on the size of the database. 125 00:07:36,860 --> 00:07:38,940 Now, writing a tool might sound simple, 126 00:07:39,020 --> 00:07:41,460 but for an effective and comprehensive tool, 127 00:07:41,660 --> 00:07:45,840 I can assure you it is slightly more complex than a few shell scripts in NetCap. 128 00:07:49,280 --> 00:07:52,300 Now, I've got a couple of examples for you to ease the boredom here. 129 00:07:53,660 --> 00:07:57,080 This is Bob's Bike Shop, probably the ugliest web application you've ever seen. 130 00:07:57,160 --> 00:07:58,460 We designed it as well. 131 00:07:58,520 --> 00:07:59,960 We were focusing more on the tool, though. 132 00:08:00,360 --> 00:08:03,520 But it's got everything that a web application vaguely should have. 133 00:08:03,640 --> 00:08:05,580 It's got a pretty banner at the top. 134 00:08:05,820 --> 00:08:09,220 It's got a menu along the side where you can choose different types of stuff you're going to buy. 135 00:08:09,640 --> 00:08:15,820 It's got an ugly green table that shows you the bike information that you're looking at. 136 00:08:16,820 --> 00:08:20,920 Apparently, the Schwinn bike that this customer was looking at is going for $30, 137 00:08:21,060 --> 00:08:22,420 so these guys are going out of business. 138 00:08:24,120 --> 00:08:27,420 It's got everything that a standard web application might have, 139 00:08:28,100 --> 00:08:29,340 including a SQL injection. 140 00:08:30,520 --> 00:08:32,800 So, if you probably can't see it, 141 00:08:32,840 --> 00:08:35,500 hopefully you can notice that it changed a little there. 142 00:08:35,660 --> 00:08:37,760 Watch the address bar. It grows a little. 143 00:08:38,480 --> 00:08:41,940 What I've appended onto that is simply and 1 equals 1. 144 00:08:42,620 --> 00:08:44,360 1 equals 1 is true. 145 00:08:44,520 --> 00:08:47,060 It's a fairly straightforward logical statement. 146 00:08:48,320 --> 00:08:50,240 So, it didn't change the page. 147 00:08:50,420 --> 00:08:52,900 After we added that to the product ID field 148 00:08:52,900 --> 00:08:53,960 in the address bar. 149 00:08:54,940 --> 00:08:58,700 That's a very simplistic basic building block of a blind SQL injection there, 150 00:08:58,800 --> 00:09:00,680 because we've asked it what a true is, 151 00:09:00,820 --> 00:09:02,140 and it returned the same page. 152 00:09:03,060 --> 00:09:05,800 Now, if we change the 1 equals 1 in the address bar 153 00:09:05,800 --> 00:09:07,220 to 1 equals 0, 154 00:09:07,780 --> 00:09:10,100 it's telling us it couldn't find any information anymore. 155 00:09:10,560 --> 00:09:13,680 So, it's safe to assume at this point that we've got 156 00:09:13,680 --> 00:09:17,400 the product ID field there is directly sent to the database 157 00:09:17,400 --> 00:09:20,820 where it says, send us all the bikes where the product ID is equal to, 158 00:09:20,940 --> 00:09:22,060 in this case, 2. 159 00:09:22,900 --> 00:09:25,460 And then this is where we append our extra logical statement 160 00:09:25,460 --> 00:09:27,060 and 1 is equal to 0. 161 00:09:27,340 --> 00:09:30,640 Well, so it sends back all the bikes where the product ID is 2. 162 00:09:31,060 --> 00:09:34,100 When 1 is equal to 0, it never sends anything back. 163 00:09:34,260 --> 00:09:35,220 We've got a false statement. 164 00:09:35,520 --> 00:09:38,260 Therefore, we know that the database is sending us back 165 00:09:38,260 --> 00:09:39,520 Boolean values of true and false. 166 00:09:43,940 --> 00:09:46,360 I'm going to take a little sidestep here for a minute. 167 00:09:47,060 --> 00:09:49,680 And when I was talking about getting the username, 168 00:09:49,840 --> 00:09:52,380 it takes 7 requests and 8 requests. 169 00:09:52,900 --> 00:09:54,660 I wasn't pulling those numbers out of my ass. 170 00:09:54,900 --> 00:09:56,200 There's actually a method to it. 171 00:09:56,440 --> 00:09:58,260 And what we do is, 172 00:09:58,520 --> 00:10:02,680 you can convert anything in the SQL Server to an integer. 173 00:10:03,000 --> 00:10:05,180 And what you do in this case is, 174 00:10:05,880 --> 00:10:07,240 once you've converted it to an integer, 175 00:10:07,520 --> 00:10:10,200 it's very easy to pull it down just using logical statements. 176 00:10:10,460 --> 00:10:14,960 You can create a recursive routine to select a range, 177 00:10:15,140 --> 00:10:17,740 start off maybe at 0, nice middle area, 178 00:10:18,040 --> 00:10:19,680 and then increase the value, 179 00:10:19,900 --> 00:10:22,380 start off, increase it by 2, increase it by 4, 180 00:10:22,380 --> 00:10:23,180 increase it by 8, 181 00:10:23,280 --> 00:10:25,060 until you find a value that's higher 182 00:10:25,060 --> 00:10:26,660 than the integer you're dealing with. 183 00:10:26,880 --> 00:10:28,100 Once you've found that range, 184 00:10:28,400 --> 00:10:30,000 basically the last one you stopped at 185 00:10:30,000 --> 00:10:30,880 and the previous one before, 186 00:10:31,180 --> 00:10:32,540 you start cutting that in half 187 00:10:32,540 --> 00:10:35,320 and exponentially drop it 188 00:10:36,000 --> 00:10:38,820 until you've zeroed in on the actual integer you're searching for. 189 00:10:39,360 --> 00:10:42,300 And what you can do if it's not an integer 190 00:10:42,300 --> 00:10:43,380 that you're actually searching for, 191 00:10:43,460 --> 00:10:45,420 if it's a character, search for the ASCII value. 192 00:10:45,600 --> 00:10:46,320 That's an integer. 193 00:10:46,560 --> 00:10:49,560 If it's a binary field, 194 00:10:49,900 --> 00:10:52,280 you can convert each element 195 00:10:52,380 --> 00:10:54,840 to the ASCII value and then grab that number. 196 00:10:54,980 --> 00:10:57,440 If it's a date, you can convert it to text, 197 00:10:57,660 --> 00:10:59,280 which then goes to ASCII, which is an integer. 198 00:10:59,740 --> 00:11:01,440 Everything can be converted to an integer 199 00:11:01,440 --> 00:11:03,240 and pulled out, albeit slowly, 200 00:11:03,500 --> 00:11:05,540 can be pulled out through this method. 201 00:11:10,040 --> 00:11:12,120 So now that we know we can pull the information 202 00:11:12,120 --> 00:11:13,100 out of the web server, 203 00:11:13,280 --> 00:11:14,200 we found the hole, 204 00:11:14,380 --> 00:11:16,820 we figured out how we're going to go about pulling all the data, 205 00:11:17,280 --> 00:11:19,020 we just have one more problem, 206 00:11:19,480 --> 00:11:22,160 and that's how do we recognize a true page 207 00:11:22,380 --> 00:11:24,240 on a false page from the web server? 208 00:11:24,800 --> 00:11:26,460 Well, for us, it was pretty simple. 209 00:11:26,580 --> 00:11:28,740 For a true page, there was an ugly green table 210 00:11:28,740 --> 00:11:31,820 with an undervalued byte and a price there. 211 00:11:32,260 --> 00:11:34,680 And for the false page, it just said no rows found. 212 00:11:34,960 --> 00:11:36,060 You can spot it like that. 213 00:11:36,360 --> 00:11:39,000 But the problem is a computer can't do it as easily. 214 00:11:39,380 --> 00:11:41,300 There might be other stuff going on. 215 00:11:42,480 --> 00:11:44,760 It just sees a collection of ASCII values. 216 00:11:45,020 --> 00:11:48,260 So it's a bit harder for the pattern recognition to take place. 217 00:11:48,460 --> 00:11:50,800 It's not that complex to understand 218 00:11:50,800 --> 00:11:52,360 that the computer doesn't see things we do. 219 00:11:52,360 --> 00:11:53,540 We're pretty much used to that. 220 00:11:55,680 --> 00:11:57,600 So big thing is a lot of people 221 00:11:57,600 --> 00:11:59,040 want to just do a straight string comparison. 222 00:11:59,320 --> 00:12:00,360 You've got the true page. 223 00:12:00,560 --> 00:12:01,620 You've got the false page. 224 00:12:01,860 --> 00:12:03,240 And then just copy those strings, 225 00:12:03,420 --> 00:12:04,240 compare the strings. 226 00:12:04,400 --> 00:12:05,880 If they're equal, then move on with that. 227 00:12:06,140 --> 00:12:10,280 But web applications aren't getting less complex. 228 00:12:10,360 --> 00:12:11,380 They're getting more complex. 229 00:12:11,720 --> 00:12:12,940 Everybody wants to show off. 230 00:12:13,040 --> 00:12:14,700 Everybody wants to add extra bells and whistles. 231 00:12:16,300 --> 00:12:18,440 So there's going to be more dynamic content 232 00:12:18,440 --> 00:12:20,240 as web applications go around. 233 00:12:20,560 --> 00:12:22,300 You might find a lot of web applications 234 00:12:22,360 --> 00:12:24,240 currently you could just do a string compare on, 235 00:12:24,340 --> 00:12:26,360 but it's growing really, really quickly, 236 00:12:26,480 --> 00:12:29,180 the fact that there's going to be extra stuff going on. 237 00:12:29,760 --> 00:12:32,400 There's going to be an increasing chance 238 00:12:32,400 --> 00:12:34,600 that the dynamic content on the page 239 00:12:34,600 --> 00:12:37,660 is unrelated to the actual dynamic content you're viewing. 240 00:12:39,580 --> 00:12:41,740 So there's a lot of extra stuff going on. 241 00:12:41,840 --> 00:12:43,460 The string comparison might work 242 00:12:43,460 --> 00:12:45,940 for something along the lines of an error-based injection, 243 00:12:46,660 --> 00:12:48,820 but where you've got constant strings 244 00:12:48,820 --> 00:12:50,160 you can sort of target in on, 245 00:12:50,280 --> 00:12:51,780 but not for a blind injection 246 00:12:51,780 --> 00:12:52,520 such as this. 247 00:12:56,240 --> 00:12:59,500 Back to the false page that I showed you earlier. 248 00:13:00,400 --> 00:13:03,060 If you look right above the no rows found, 249 00:13:04,380 --> 00:13:06,480 if you're in the back, it looks like a gray bar. 250 00:13:06,680 --> 00:13:07,640 It's basically a date, 251 00:13:08,880 --> 00:13:10,520 and it's including the time. 252 00:13:10,620 --> 00:13:12,880 So that means that section is changing every second. 253 00:13:13,120 --> 00:13:14,540 So every time you do a query, 254 00:13:14,660 --> 00:13:16,100 you've got a little bar that's changing. 255 00:13:16,440 --> 00:13:18,820 We can see that and immediately dismiss it as a date. 256 00:13:18,940 --> 00:13:19,680 It doesn't matter. 257 00:13:19,680 --> 00:13:22,240 But it's going to be something that's changing 258 00:13:22,240 --> 00:13:23,340 in terms of the overall string. 259 00:13:23,960 --> 00:13:25,660 Then underneath the no rows found, 260 00:13:25,780 --> 00:13:27,220 it's telling you what page you requested. 261 00:13:27,960 --> 00:13:29,640 Now, that seems a bit contrived, 262 00:13:29,700 --> 00:13:31,600 but if you've ever gone to a news site 263 00:13:31,600 --> 00:13:33,700 or any site where somebody wants you 264 00:13:33,700 --> 00:13:34,960 to refer to a friend, 265 00:13:35,580 --> 00:13:37,460 well, the refer to a friend is just a link 266 00:13:37,460 --> 00:13:38,980 to the URL you requested, 267 00:13:39,200 --> 00:13:41,480 and if you're injecting over the get request, 268 00:13:41,720 --> 00:13:43,980 then that's going to change every time 269 00:13:43,980 --> 00:13:45,680 that you hit the site as well. 270 00:13:50,560 --> 00:13:52,280 So first possible solution 271 00:13:52,280 --> 00:13:54,660 for dealing with the true pages 272 00:13:54,660 --> 00:13:55,780 versus the false pages 273 00:13:55,780 --> 00:13:57,140 versus the pages you want to know 274 00:13:57,140 --> 00:13:58,160 whether they're true or they're false 275 00:13:58,160 --> 00:13:59,940 is use an MD5 sum. 276 00:14:00,120 --> 00:14:02,600 Take an MD5 of the true, take an MD5 of the false, 277 00:14:02,780 --> 00:14:05,240 then the unknown, and which one's the closest? 278 00:14:06,080 --> 00:14:07,520 Well, as I said earlier, 279 00:14:07,680 --> 00:14:09,480 over and over, web applications 280 00:14:09,480 --> 00:14:10,520 are designed to be dynamic. 281 00:14:11,100 --> 00:14:13,160 There's going to be a lot of extra stuff going on. 282 00:14:13,560 --> 00:14:15,820 And the way MD5 was designed, 283 00:14:15,900 --> 00:14:16,800 it's a message digest, 284 00:14:17,160 --> 00:14:18,900 which means it was designed 285 00:14:19,680 --> 00:14:21,780 to highlight small changes 286 00:14:21,780 --> 00:14:23,840 by making large changes in the actual sum. 287 00:14:25,260 --> 00:14:26,580 So take a look at this. 288 00:14:27,000 --> 00:14:28,420 I took the home page of Google, 289 00:14:28,580 --> 00:14:30,020 a very, very simple page, 290 00:14:30,220 --> 00:14:32,100 and I saved it, 291 00:14:32,140 --> 00:14:33,300 took the MD5 sum of it, 292 00:14:33,340 --> 00:14:35,640 then I changed the title tag, 293 00:14:35,860 --> 00:14:37,340 changed it from Google to Hoogle, 294 00:14:37,480 --> 00:14:39,440 increased the ASCII value of the entire thing 295 00:14:39,440 --> 00:14:39,980 just by one. 296 00:14:40,540 --> 00:14:42,420 And this is a different MD5 sum. 297 00:14:42,940 --> 00:14:44,320 So the original is the blue, 298 00:14:44,480 --> 00:14:46,020 the changed one is the red. 299 00:14:46,220 --> 00:14:48,300 It only changed by one character, 300 00:14:50,180 --> 00:14:51,700 and they're nothing similar. 301 00:14:51,840 --> 00:14:53,680 You can't even tell where they changed. 302 00:14:53,900 --> 00:14:56,200 It should be at point two. 303 00:14:56,640 --> 00:14:57,940 I know that because I did it, 304 00:14:58,080 --> 00:15:01,000 but the numbers don't even line up 305 00:15:01,000 --> 00:15:01,760 to the actual lines 306 00:15:01,760 --> 00:15:04,400 because an MD5 sum is always going to be the same size. 307 00:15:09,220 --> 00:15:11,600 So overall, we know that MD5 sums 308 00:15:11,600 --> 00:15:13,400 can't handle the changes well 309 00:15:13,400 --> 00:15:15,000 for something like this 310 00:15:15,000 --> 00:15:16,940 where there's going to be small incremental changes 311 00:15:17,480 --> 00:15:18,980 that we want to sort of filter out. 312 00:15:19,680 --> 00:15:20,600 We don't really care about them. 313 00:15:21,180 --> 00:15:23,620 And it might work for the same applications 314 00:15:23,620 --> 00:15:25,660 where the straight string comparison might work, 315 00:15:25,800 --> 00:15:27,640 but it's not going to be comprehensive. 316 00:15:28,060 --> 00:15:30,060 And if the string comparison worked, 317 00:15:30,300 --> 00:15:32,100 then why bother with the extra time 318 00:15:32,100 --> 00:15:32,920 with the MD5? 319 00:15:35,580 --> 00:15:37,760 So another possible solution 320 00:15:38,980 --> 00:15:40,220 would be to 321 00:15:40,900 --> 00:15:41,980 parse the 322 00:15:41,980 --> 00:15:43,580 actual HTML 323 00:15:43,580 --> 00:15:45,540 into a tree data structure. 324 00:15:45,900 --> 00:15:46,960 You go on, 325 00:15:46,960 --> 00:15:49,540 and you represent the HTML entity 326 00:15:49,680 --> 00:15:51,840 as nodes in the data structure. 327 00:15:52,560 --> 00:15:54,000 And you look for differences 328 00:15:54,000 --> 00:15:55,420 in the shape of the tree. 329 00:15:55,480 --> 00:15:57,840 You write recursive traversal algorithms. 330 00:15:58,960 --> 00:15:59,400 But 331 00:15:59,400 --> 00:16:01,120 a couple problems with that. 332 00:16:01,520 --> 00:16:03,440 And the first one is I'm lazy. 333 00:16:03,720 --> 00:16:04,880 That's a bit more complex 334 00:16:04,880 --> 00:16:06,200 than what I wanted to do 335 00:16:06,200 --> 00:16:07,280 when I was writing a tool. 336 00:16:07,660 --> 00:16:10,060 But a big problem with it is 337 00:16:10,060 --> 00:16:12,000 that if non-markup data is changing, 338 00:16:12,640 --> 00:16:14,860 then it's not going to change the shape of the tree. 339 00:16:14,960 --> 00:16:16,380 If it's just the textual content, 340 00:16:16,580 --> 00:16:17,620 which is altogether possible, 341 00:16:19,680 --> 00:16:20,480 somewhat regularly, 342 00:16:21,420 --> 00:16:23,720 then you're going to have to find a different way 343 00:16:23,720 --> 00:16:25,820 to figure out 344 00:16:25,820 --> 00:16:27,640 what's going on in the actual nodes of the tree. 345 00:16:28,320 --> 00:16:30,000 And the other thing is 346 00:16:30,000 --> 00:16:31,120 it's easier to implement 347 00:16:31,120 --> 00:16:32,980 an XHTML parser 348 00:16:32,980 --> 00:16:34,880 than a realistic HTML parser. 349 00:16:35,100 --> 00:16:37,580 By that, I mean that auto-generated crap 350 00:16:37,580 --> 00:16:39,860 that FrontPage spewed out for years and years and years, 351 00:16:40,000 --> 00:16:41,880 and the auto-generated crap 352 00:16:41,880 --> 00:16:43,500 that lots of people still write 353 00:16:43,500 --> 00:16:45,280 through their web applications. 354 00:16:45,480 --> 00:16:46,760 The kind of stuff where 355 00:16:46,760 --> 00:16:49,180 it's just chunks and chunks and chunks 356 00:16:49,680 --> 00:16:50,120 and you can actually read it 357 00:16:50,120 --> 00:16:51,840 if you had to fix it for some reason 358 00:16:51,840 --> 00:16:52,940 and you're pulling out your hair. 359 00:16:53,260 --> 00:16:55,220 It's just as bad to go through 360 00:16:55,220 --> 00:16:57,720 and parse with a tree data structure. 361 00:17:03,180 --> 00:17:04,780 So, the third solution, 362 00:17:05,860 --> 00:17:08,060 the one I actually ended up using, 363 00:17:09,020 --> 00:17:10,440 was linear representation 364 00:17:10,440 --> 00:17:11,840 of ASCII sums. 365 00:17:12,460 --> 00:17:14,060 Now, what I mean by that 366 00:17:14,060 --> 00:17:17,120 is take the HTML file 367 00:17:17,120 --> 00:17:17,780 that you get 368 00:17:17,780 --> 00:17:19,200 for each response 369 00:17:19,680 --> 00:17:21,260 and delimit it 370 00:17:22,120 --> 00:17:23,380 by carriage returns. 371 00:17:23,940 --> 00:17:24,860 So you basically 372 00:17:24,860 --> 00:17:26,440 split it up by lines, 373 00:17:26,600 --> 00:17:29,420 take the ASCII sum of each character in the lines, 374 00:17:30,200 --> 00:17:31,660 and so now you have 375 00:17:31,660 --> 00:17:33,780 a single value for each line in the HTML file. 376 00:17:34,700 --> 00:17:35,540 From here, 377 00:17:35,580 --> 00:17:37,400 it's just one array 378 00:17:37,400 --> 00:17:38,260 that you can work with. 379 00:17:38,820 --> 00:17:40,840 And because of the magnitude 380 00:17:40,840 --> 00:17:42,520 of the sums that you're dealing with, 381 00:17:42,800 --> 00:17:45,760 small changes by one or two characters 382 00:17:45,760 --> 00:17:47,320 aren't going to make that much of a difference. 383 00:17:47,520 --> 00:17:49,240 This is the same graph of Google 384 00:17:49,680 --> 00:17:50,920 that I showed you earlier 385 00:17:50,920 --> 00:17:52,200 with the MD5 sums. 386 00:17:52,840 --> 00:17:55,140 It's section two down there, 387 00:17:55,780 --> 00:17:57,260 down there, down there, 388 00:17:58,020 --> 00:17:59,760 that you can't even see it 389 00:17:59,760 --> 00:18:01,600 just because you're dealing with 390 00:18:01,600 --> 00:18:03,580 the closest range is 391 00:18:03,580 --> 00:18:05,460 20,000, that's the notch there, 392 00:18:05,560 --> 00:18:07,000 so a change of one 393 00:18:07,000 --> 00:18:08,240 isn't going to show up too much. 394 00:18:14,560 --> 00:18:15,040 So, 395 00:18:15,580 --> 00:18:17,700 we figured out how we're going to get the signatures. 396 00:18:18,000 --> 00:18:19,420 We still have to do comparisons 397 00:18:19,680 --> 00:18:21,140 to figure out how we can 398 00:18:22,220 --> 00:18:24,240 recognize the trues versus the falses 399 00:18:24,240 --> 00:18:26,020 since we found a way to represent them. 400 00:18:26,460 --> 00:18:27,460 And to do this, 401 00:18:27,460 --> 00:18:28,460 we're going to need base cases. 402 00:18:29,160 --> 00:18:30,880 You do this initially anyways 403 00:18:30,880 --> 00:18:32,120 when you're trying to figure out 404 00:18:32,120 --> 00:18:33,160 and learn the web application. 405 00:18:34,620 --> 00:18:36,620 So, you know you can find 406 00:18:36,620 --> 00:18:38,540 a true page versus a false page 407 00:18:38,540 --> 00:18:39,240 at this point. 408 00:18:39,860 --> 00:18:42,260 You always know that one is going to be equal to one. 409 00:18:42,400 --> 00:18:43,820 I can guarantee that to you. 410 00:18:44,120 --> 00:18:46,380 And you know that one is never going to be equal to zero. 411 00:18:47,160 --> 00:18:47,580 Hopefully. 412 00:18:49,680 --> 00:18:50,220 Once you do this, 413 00:18:50,280 --> 00:18:53,520 you use known true pages, 414 00:18:53,600 --> 00:18:54,420 known false pages, 415 00:18:54,600 --> 00:18:57,320 and you found a base set of cases to work with 416 00:18:57,320 --> 00:18:59,800 for your HTML comparisons. 417 00:19:02,220 --> 00:19:02,700 So, 418 00:19:02,820 --> 00:19:04,520 from Bob's Bike Shop, 419 00:19:04,740 --> 00:19:06,740 the web app I showed you earlier, 420 00:19:06,960 --> 00:19:09,620 this is the true page versus the false page 421 00:19:09,620 --> 00:19:10,940 compared on a graph 422 00:19:10,940 --> 00:19:12,940 with the linear representation 423 00:19:12,940 --> 00:19:14,000 of the ASCII sums. 424 00:19:14,480 --> 00:19:17,120 So, the blue, you can see it 425 00:19:17,120 --> 00:19:18,860 follows the same as the brown 426 00:19:19,680 --> 00:19:21,020 starts at about 10. 427 00:19:21,340 --> 00:19:23,560 That's where the difference takes place 428 00:19:23,560 --> 00:19:24,540 where the no rows found 429 00:19:24,540 --> 00:19:27,360 versus the green table shows up. 430 00:19:27,520 --> 00:19:29,660 So, the green table takes up 431 00:19:29,660 --> 00:19:31,720 more space on the 432 00:19:32,560 --> 00:19:33,080 blue 433 00:19:33,080 --> 00:19:34,880 and then it eventually tails off 434 00:19:34,880 --> 00:19:36,940 and finishes the same way that the brown does 435 00:19:36,940 --> 00:19:38,300 because it has a single line 436 00:19:38,300 --> 00:19:39,700 and is a bit shorter. 437 00:19:45,980 --> 00:19:47,260 Just in case you think 438 00:19:47,260 --> 00:19:48,580 that was a bit too contrived, 439 00:19:49,680 --> 00:19:50,040 this is a realistic signature. 440 00:19:50,380 --> 00:19:52,980 This is a real commercial web application 441 00:19:52,980 --> 00:19:54,400 that's somewhere out on the web 442 00:19:54,400 --> 00:19:56,140 that has a blind SQL injection. 443 00:19:56,860 --> 00:19:58,880 I don't remember which page 444 00:19:58,880 --> 00:19:59,620 I took this from, 445 00:19:59,740 --> 00:20:01,380 so don't ask me after the talk. 446 00:20:02,700 --> 00:20:04,620 But it's still vulnerable 447 00:20:04,620 --> 00:20:05,540 as far as I know. 448 00:20:08,240 --> 00:20:08,820 So, 449 00:20:09,660 --> 00:20:11,040 I said earlier that 450 00:20:11,040 --> 00:20:12,440 this linear representation, 451 00:20:12,840 --> 00:20:14,600 small changes in the input 452 00:20:14,600 --> 00:20:16,880 means small changes in the output. 453 00:20:17,180 --> 00:20:18,520 But the fact is, 454 00:20:20,420 --> 00:20:22,460 you can't do a straight up comparison. 455 00:20:23,960 --> 00:20:24,480 So, 456 00:20:24,560 --> 00:20:26,140 when these changes take place 457 00:20:26,140 --> 00:20:27,880 such as the time changing by one 458 00:20:27,880 --> 00:20:29,880 increasing the value in very small increments, 459 00:20:30,080 --> 00:20:31,280 it's going to make 460 00:20:31,280 --> 00:20:33,880 very, very minor changes 461 00:20:33,880 --> 00:20:35,560 that we would sort of ignore 462 00:20:35,560 --> 00:20:38,080 and we can actually use a tolerance 463 00:20:38,080 --> 00:20:39,720 instead of a straight comparison 464 00:20:41,360 --> 00:20:43,020 for comparing these values. 465 00:20:43,200 --> 00:20:44,720 If you've done any numerical analysis 466 00:20:44,720 --> 00:20:46,480 you know you never use equals. 467 00:20:46,640 --> 00:20:47,860 You always use a subtraction 468 00:20:48,200 --> 00:20:49,380 for a tolerance. 469 00:20:49,680 --> 00:20:50,960 You do the same thing here. 470 00:20:51,320 --> 00:20:53,720 So you just take the sum of the known 471 00:20:53,720 --> 00:20:55,700 minus the sum of the unknown 472 00:20:55,700 --> 00:20:56,620 take the absolute value 473 00:20:56,620 --> 00:20:58,300 toss it over the sum of the known 474 00:20:58,300 --> 00:21:00,500 and if that value is equal 475 00:21:00,500 --> 00:21:01,800 to your preset tolerance 476 00:21:01,800 --> 00:21:04,100 or less than your preset tolerance 477 00:21:04,100 --> 00:21:05,580 then you treat it as an equivalency. 478 00:21:07,440 --> 00:21:07,920 Oops. 479 00:21:09,800 --> 00:21:10,500 There we go. 480 00:21:11,220 --> 00:21:12,780 And this is the same thing 481 00:21:12,780 --> 00:21:13,860 with the tolerance band. 482 00:21:14,180 --> 00:21:15,980 Just sort of illustrating what I meant by 483 00:21:15,980 --> 00:21:18,780 you can see that as it starts off 484 00:21:20,040 --> 00:21:21,260 they're in the same tolerance 485 00:21:21,260 --> 00:21:22,420 because they are the exact same 486 00:21:22,420 --> 00:21:24,420 but once it gets to the parts 487 00:21:24,420 --> 00:21:26,020 where it's supposed to diverge 488 00:21:26,020 --> 00:21:27,400 the tolerance at this point 489 00:21:27,400 --> 00:21:30,240 isn't enough to create a false negative 490 00:21:30,240 --> 00:21:31,180 or a false positive 491 00:21:33,160 --> 00:21:36,360 and so there's no problems with that 492 00:21:36,360 --> 00:21:37,680 but it still allows for minor changes. 493 00:21:38,660 --> 00:21:40,080 The tolerance shown here 494 00:21:40,080 --> 00:21:41,000 is about 10%. 495 00:21:41,000 --> 00:21:42,900 If you're ever doing this on your own 496 00:21:42,900 --> 00:21:44,620 I wouldn't recommend anything higher 497 00:21:44,620 --> 00:21:46,000 than .01% 498 00:21:46,000 --> 00:21:49,100 or you're going to get a lot of false positives 499 00:21:49,820 --> 00:21:51,440 The realistic one I showed you 500 00:21:51,440 --> 00:21:53,660 would trip up if it was higher than .01%. 501 00:21:56,900 --> 00:21:57,400 So, 502 00:21:58,200 --> 00:21:59,820 tolerance works for the most part. 503 00:22:00,080 --> 00:22:02,140 It'll work a good chunk of the time 504 00:22:02,140 --> 00:22:03,620 but there's 505 00:22:03,620 --> 00:22:05,420 better ways to go about it. 506 00:22:06,440 --> 00:22:07,440 It doesn't 507 00:22:08,320 --> 00:22:09,320 it does 508 00:22:09,320 --> 00:22:10,940 extra calculations, comparisons 509 00:22:10,940 --> 00:22:12,240 it doesn't really need to be doing 510 00:22:12,240 --> 00:22:14,600 and it doesn't take advantage of stuff 511 00:22:14,600 --> 00:22:16,820 that is known to be bogus data 512 00:22:16,820 --> 00:22:17,660 we don't care about. 513 00:22:24,240 --> 00:22:24,720 So, 514 00:22:25,600 --> 00:22:27,540 we decided to create a filter 515 00:22:27,540 --> 00:22:29,140 to the data that we're dealing with. 516 00:22:29,600 --> 00:22:31,040 On the left is 517 00:22:31,040 --> 00:22:32,780 the Bob's bike's true signature 518 00:22:32,780 --> 00:22:35,060 you've seen it on graph, now this is the array form 519 00:22:35,540 --> 00:22:37,340 and on the right is the false page 520 00:22:37,340 --> 00:22:39,060 know that because it's a bit shorter 521 00:22:39,600 --> 00:22:41,160 and if we identify 522 00:22:41,680 --> 00:22:43,260 every element between the two 523 00:22:43,260 --> 00:22:44,260 that are in the same position 524 00:22:44,260 --> 00:22:46,400 that are equivalent to each other 525 00:22:46,400 --> 00:22:49,040 then we know that those values 526 00:22:49,680 --> 00:22:50,480 have nothing to do with the injection 527 00:22:50,480 --> 00:22:53,900 they have nothing to do with the actual information being presented to us 528 00:22:53,900 --> 00:22:55,440 so if they're the same at this point 529 00:22:55,440 --> 00:22:57,200 they should be the same at every other point 530 00:22:57,200 --> 00:22:59,320 and we know they don't matter to what we're doing. 531 00:22:59,660 --> 00:23:00,880 So, get rid of them. 532 00:23:01,680 --> 00:23:03,160 At this point we've halved 533 00:23:03,500 --> 00:23:04,820 the data that we're comparing against 534 00:23:05,440 --> 00:23:06,060 each other 535 00:23:06,060 --> 00:23:08,140 and this saves us a bit of time 536 00:23:08,140 --> 00:23:09,720 this page is really small 537 00:23:09,720 --> 00:23:12,880 in a larger page it cuts out an even larger chunk. 538 00:23:19,740 --> 00:23:20,760 But why stop there? 539 00:23:21,020 --> 00:23:23,880 There's still extra stuff we know is crap 540 00:23:23,880 --> 00:23:26,040 we know will trip up our web application 541 00:23:26,040 --> 00:23:28,200 the stuff we filter out by eye 542 00:23:28,200 --> 00:23:29,260 think of the time 543 00:23:29,260 --> 00:23:30,880 or the referral to a friend 544 00:23:30,880 --> 00:23:32,580 we've got one to still get rid of that 545 00:23:32,580 --> 00:23:34,680 so we have a second filter we apply 546 00:23:34,680 --> 00:23:37,680 and this allows the application 547 00:23:37,680 --> 00:23:38,440 we're attacking 548 00:23:38,440 --> 00:23:41,200 to be profiled a little bit more 549 00:23:41,200 --> 00:23:43,220 before we go on to proceed 550 00:23:43,220 --> 00:23:44,060 with the actual attack 551 00:23:44,600 --> 00:23:46,700 so we want to remove the junk data 552 00:23:46,700 --> 00:23:48,200 that's going to screw up the results 553 00:23:49,680 --> 00:23:51,920 we have to get more than the initial set of base cases 554 00:23:51,920 --> 00:23:53,840 but really overall 555 00:23:54,620 --> 00:23:55,620 we're going to be doing 556 00:23:55,620 --> 00:23:57,480 thousands and thousands and thousands 557 00:23:57,480 --> 00:23:58,800 of queries against the web server 558 00:23:58,800 --> 00:24:01,380 an extra five really isn't going to hurt it too much 559 00:24:01,380 --> 00:24:04,140 if it is, then your attack wasn't going to happen anyways 560 00:24:07,800 --> 00:24:08,200 so 561 00:24:09,300 --> 00:24:11,720 we've already applied the subtractive filter to these two 562 00:24:11,720 --> 00:24:13,660 and they're supposed to be two true pages 563 00:24:14,200 --> 00:24:15,260 all we've asked is 564 00:24:15,260 --> 00:24:17,380 one is equal to one, which is true 565 00:24:17,380 --> 00:24:18,840 is two equal to two? 566 00:24:19,680 --> 00:24:19,860 it is 567 00:24:19,860 --> 00:24:22,680 so the pages should be the same 568 00:24:22,680 --> 00:24:23,860 because it's the same answer 569 00:24:25,920 --> 00:24:27,040 but they aren't 570 00:24:27,560 --> 00:24:29,320 so anything that's changed over this 571 00:24:29,320 --> 00:24:30,900 two queries 572 00:24:30,900 --> 00:24:32,660 and we asked a couple more just to be sure 573 00:24:33,240 --> 00:24:34,940 anything that's changed at this point 574 00:24:35,580 --> 00:24:38,200 we know this has nothing to do with our injection 575 00:24:38,200 --> 00:24:39,660 this is changing on its own 576 00:24:39,660 --> 00:24:41,180 and it's going to come back to bite us later 577 00:24:41,180 --> 00:24:42,320 so get rid of it now 578 00:24:42,320 --> 00:24:43,820 don't even look at it later 579 00:24:43,820 --> 00:24:46,820 because it just will screw us up 580 00:24:46,820 --> 00:24:49,120 so we clear that out and what we do is 581 00:24:49,680 --> 00:24:50,340 we save in memory 582 00:24:50,340 --> 00:24:52,360 which elements of the signature 583 00:24:52,360 --> 00:24:53,820 that are actually used for the comparison 584 00:24:53,820 --> 00:24:57,080 so it's like hit element 12 hit element 13 hit element 14 585 00:24:57,640 --> 00:24:59,480 if that's what we're looking for 586 00:24:59,480 --> 00:25:00,640 then we know it's a good signature 587 00:25:00,640 --> 00:25:02,520 otherwise we assume it's a false 588 00:25:07,660 --> 00:25:08,180 so 589 00:25:09,120 --> 00:25:12,020 the benefits of using the second filter 590 00:25:12,020 --> 00:25:12,800 is 591 00:25:12,800 --> 00:25:15,080 at this point we're pretty sure 592 00:25:15,080 --> 00:25:16,220 we can get rid of the tolerance 593 00:25:16,220 --> 00:25:19,120 you don't have to if you're not 100% on it 594 00:25:19,680 --> 00:25:21,820 I've been pretty comfortable not using that tolerance anymore 595 00:25:21,820 --> 00:25:23,640 when I've been doing my comparisons 596 00:25:23,640 --> 00:25:25,160 works out pretty safely 597 00:25:25,160 --> 00:25:28,100 at this point if something doesn't exactly line up 598 00:25:28,100 --> 00:25:30,280 that means I have to readjust my filters 599 00:25:30,280 --> 00:25:31,180 and move on from there 600 00:25:31,840 --> 00:25:33,280 and it will remove 601 00:25:33,280 --> 00:25:36,080 a large portion of the dynamic content 602 00:25:36,080 --> 00:25:37,560 that's unrelated to 603 00:25:37,560 --> 00:25:39,280 the actual injection we're performing 604 00:25:41,320 --> 00:25:43,960 so this is the part where I introduce Squeal 605 00:25:43,960 --> 00:25:45,660 Squeal is a tool 606 00:25:45,660 --> 00:25:46,560 that we created 607 00:25:47,220 --> 00:25:49,420 sort of I've been presenting how Squeal 608 00:25:49,680 --> 00:25:50,480 actually works here 609 00:25:50,480 --> 00:25:53,520 and we created it to perform 610 00:25:53,520 --> 00:25:55,980 blind Squeal exploitation automatically for us 611 00:25:55,980 --> 00:25:57,340 we wrote it in C sharp 612 00:25:57,340 --> 00:25:59,140 I wrote it in C sharp in Linux 613 00:25:59,140 --> 00:26:00,920 which annoys some people 614 00:26:00,920 --> 00:26:03,540 but it works in Windows and Linux 615 00:26:03,540 --> 00:26:04,860 if you want to use Linux 616 00:26:04,860 --> 00:26:06,660 get Mono 1.0 or later 617 00:26:07,500 --> 00:26:09,060 Mono's become pretty stable recently 618 00:26:09,680 --> 00:26:12,120 but there's a Windows.Forms 619 00:26:12,120 --> 00:26:13,640 version for 620 00:26:13,640 --> 00:26:14,680 Win32 621 00:26:14,680 --> 00:26:16,980 and the GTK sharp version 622 00:26:16,980 --> 00:26:19,560 they should both be on the CD but I haven't had a chance to look yet 623 00:26:20,560 --> 00:26:22,460 and it's free for non-commercial use 624 00:26:22,460 --> 00:26:23,920 free for educational 625 00:26:23,920 --> 00:26:25,040 if you're presenting it to people 626 00:26:25,040 --> 00:26:26,760 check out what I can do with this 627 00:26:26,760 --> 00:26:30,100 and the fun stuff is 628 00:26:30,760 --> 00:26:32,060 any data you pull 629 00:26:32,060 --> 00:26:32,880 through Squeal 630 00:26:32,880 --> 00:26:34,220 it'll save to XML 631 00:26:34,220 --> 00:26:36,200 so it's very easy for you to read 632 00:26:36,200 --> 00:26:38,100 you don't need Squeal to work with the data again later 633 00:26:38,100 --> 00:26:40,000 you can just print it out and view it any way you want 634 00:26:42,920 --> 00:26:43,320 so 635 00:26:43,320 --> 00:26:45,500 here's a sort of example 636 00:26:45,500 --> 00:26:47,320 of the XML that Squeal uses 637 00:26:48,140 --> 00:26:48,940 it's the 638 00:26:49,680 --> 00:26:51,340 this looks like the actual signature 639 00:26:51,340 --> 00:26:53,060 of the attack that we use 640 00:26:53,520 --> 00:26:55,260 so it's got the target address 641 00:26:55,260 --> 00:26:56,700 the method that you're using 642 00:26:56,700 --> 00:26:58,080 whether you're using SSL 643 00:26:58,880 --> 00:27:01,100 there's some extra parameters that might get stored there 644 00:27:01,100 --> 00:27:02,520 depending on if you're using them or not 645 00:27:02,520 --> 00:27:05,060 every parameter that's required for the injection 646 00:27:05,060 --> 00:27:06,960 whether or not it's the injection point 647 00:27:07,660 --> 00:27:09,580 and every time you 648 00:27:09,580 --> 00:27:11,280 once you initialize 649 00:27:12,000 --> 00:27:13,740 which is gathering your base cases 650 00:27:13,740 --> 00:27:15,460 then it will actually save 651 00:27:15,460 --> 00:27:16,760 the signature sets for you 652 00:27:16,760 --> 00:27:19,520 so you only have to do that once and you can play again later 653 00:27:22,180 --> 00:27:24,280 and here is the actual tool 654 00:27:25,220 --> 00:27:27,100 this is the Windows version 655 00:27:27,600 --> 00:27:29,200 pretty Windows XP version 656 00:27:30,260 --> 00:27:30,740 and 657 00:27:31,800 --> 00:27:33,060 basically what you would do 658 00:27:33,060 --> 00:27:33,500 is you 659 00:27:33,500 --> 00:27:34,860 select the type of injection 660 00:27:34,860 --> 00:27:35,460 which is 661 00:27:35,460 --> 00:27:36,680 the only choice you have is blind 662 00:27:36,680 --> 00:27:38,560 so that's pretty easy choice right now 663 00:27:38,560 --> 00:27:41,480 and enter the target URL right around here 664 00:27:42,700 --> 00:27:44,080 running a local host test 665 00:27:44,080 --> 00:27:45,760 just because we're going to show you a demo shortly 666 00:27:46,280 --> 00:27:46,760 and 667 00:27:47,540 --> 00:27:48,800 choose whether you want to do 668 00:27:49,680 --> 00:27:50,240 a host or a get 669 00:27:50,240 --> 00:27:52,060 whether you want to use SSL 670 00:27:52,060 --> 00:27:54,340 if you want to comment the end of the query 671 00:27:54,920 --> 00:27:56,840 squeal only runs for SQL Server at the moment 672 00:27:56,840 --> 00:27:59,380 so that just means it's appending a dash dash to the end 673 00:28:00,060 --> 00:28:01,640 and this is fun over here 674 00:28:02,140 --> 00:28:03,500 this is for people who want to 675 00:28:03,500 --> 00:28:04,800 send it through a proxy 676 00:28:05,280 --> 00:28:06,880 if you want to do this anonymously 677 00:28:06,880 --> 00:28:08,340 don't know why you'd want to do that 678 00:28:08,340 --> 00:28:10,940 because nobody would want to be anonymous while running this 679 00:28:10,940 --> 00:28:12,940 but it's fun stuff 680 00:28:14,220 --> 00:28:14,620 and 681 00:28:15,180 --> 00:28:16,480 once you've filled out that information 682 00:28:16,480 --> 00:28:19,440 go on to enter the information about the actual 683 00:28:19,680 --> 00:28:21,580 parameters, the stuff that goes after the question mark 684 00:28:21,580 --> 00:28:23,320 usually, or if it's a post 685 00:28:23,320 --> 00:28:25,100 any of the stuff that's being returned 686 00:28:25,100 --> 00:28:27,400 so you enter the name, the default value 687 00:28:27,400 --> 00:28:29,040 whether or not it's injectable 688 00:28:29,580 --> 00:28:31,400 if it's a string injection 689 00:28:31,400 --> 00:28:33,280 you're doing, simply put the 690 00:28:33,280 --> 00:28:35,340 closing tick on the end and it'll 691 00:28:36,160 --> 00:28:37,600 recognize the apostrophe 692 00:28:37,600 --> 00:28:38,480 and work with it from there 693 00:28:38,480 --> 00:28:40,580 you also have the option to 694 00:28:41,100 --> 00:28:41,540 add 695 00:28:43,540 --> 00:28:44,420 HTTP headers 696 00:28:44,420 --> 00:28:45,780 aka cookies 697 00:28:46,640 --> 00:28:49,420 so if you have to squeeze by authentic 698 00:28:49,680 --> 00:28:51,480 authentication with your own cookies 699 00:28:51,480 --> 00:28:52,180 you can do that 700 00:28:52,180 --> 00:28:54,100 and once you've got that set up 701 00:28:54,100 --> 00:28:55,220 you click the initialize injection 702 00:28:56,720 --> 00:28:58,400 and it gathers your base cases 703 00:28:59,440 --> 00:29:00,780 once you've done all that 704 00:29:00,780 --> 00:29:03,140 it only takes about a second to gather the base cases 705 00:29:03,840 --> 00:29:05,600 unless you're running through a really slow proxy 706 00:29:06,640 --> 00:29:07,440 you can 707 00:29:07,440 --> 00:29:08,540 move on to 708 00:29:08,540 --> 00:29:10,940 do stuff like grab the username 709 00:29:11,580 --> 00:29:12,640 takes a couple seconds 710 00:29:12,640 --> 00:29:14,660 comes back, we're running as SA 711 00:29:15,340 --> 00:29:16,700 does anyone see a problem with that? 712 00:29:18,380 --> 00:29:18,780 no? 713 00:29:19,680 --> 00:29:20,140 alright 714 00:29:21,640 --> 00:29:22,600 but um 715 00:29:23,380 --> 00:29:24,340 yeah, SA 716 00:29:25,960 --> 00:29:27,520 then once you've got that 717 00:29:27,520 --> 00:29:28,760 you don't even need the username 718 00:29:28,760 --> 00:29:30,460 that's one of those curiosity things 719 00:29:30,460 --> 00:29:32,260 it doesn't help you, you don't use it later 720 00:29:33,000 --> 00:29:34,920 since you're just asking yes or no questions 721 00:29:34,920 --> 00:29:36,340 you don't have to authenticate 722 00:29:36,340 --> 00:29:38,040 they've already done that for you 723 00:29:38,040 --> 00:29:39,500 those friendly web app coders 724 00:29:41,380 --> 00:29:43,040 but you can load the table information 725 00:29:43,740 --> 00:29:45,280 and that means the name 726 00:29:45,280 --> 00:29:47,580 the ID stored internally 727 00:29:47,580 --> 00:29:49,120 the number of records 728 00:29:49,800 --> 00:29:51,500 in each table 729 00:29:51,500 --> 00:29:53,400 once you've got the table information 730 00:29:53,400 --> 00:29:54,380 load the field information 731 00:29:54,380 --> 00:29:56,600 and for the customers table 732 00:29:56,600 --> 00:29:57,820 I've already done this for you 733 00:29:57,820 --> 00:29:59,700 it takes a little bit longer than 734 00:29:59,700 --> 00:30:01,860 what I'd like it to take right here 735 00:30:01,860 --> 00:30:04,640 takes about 5-10 minutes to grab all this information 736 00:30:04,640 --> 00:30:06,260 but it's better than doing it by hand 737 00:30:06,260 --> 00:30:08,720 so you can go make yourself a coffee while it's doing it 738 00:30:09,500 --> 00:30:11,080 so we know we've got 739 00:30:11,080 --> 00:30:12,400 the fields customer number 740 00:30:12,400 --> 00:30:14,900 customer name, customer address 741 00:30:14,900 --> 00:30:17,140 customer phone, customer fax 742 00:30:17,500 --> 00:30:18,660 customer CC number 743 00:30:19,680 --> 00:30:20,280 fun stuff 744 00:30:20,280 --> 00:30:22,100 what are we going to do with this? 745 00:30:24,000 --> 00:30:24,620 so 746 00:30:24,620 --> 00:30:26,640 we want their name 747 00:30:28,940 --> 00:30:31,400 we want this CC number 748 00:30:32,340 --> 00:30:33,940 don't know what that might be 749 00:30:35,300 --> 00:30:37,420 and we want to save it 750 00:30:37,420 --> 00:30:38,340 so 751 00:30:46,360 --> 00:30:47,920 and we start downloading 752 00:30:47,920 --> 00:30:49,240 now it's not instant 753 00:30:49,680 --> 00:30:50,980 because you're doing a 754 00:30:51,480 --> 00:30:52,700 ton of queries right now 755 00:30:52,700 --> 00:30:53,760 so we'll go back to the slides 756 00:30:56,240 --> 00:30:56,720 so 757 00:30:57,220 --> 00:30:59,760 what it does when it gathers the table information 758 00:30:59,760 --> 00:31:01,780 this is just basically batch stored procedures 759 00:31:01,780 --> 00:31:03,320 so if you've done this by hand 760 00:31:03,320 --> 00:31:05,320 you know this by heart right now 761 00:31:05,320 --> 00:31:07,340 this is probably the last thing you want to see 762 00:31:07,340 --> 00:31:09,180 but what Squill does 763 00:31:09,180 --> 00:31:10,660 is it goes through 764 00:31:10,660 --> 00:31:12,360 and it gathers the 765 00:31:12,960 --> 00:31:14,500 ID numbers for every table 766 00:31:14,500 --> 00:31:17,280 it wants the numerical ID numbers because those are easier to work with 767 00:31:17,280 --> 00:31:18,800 and they're already integers for us 768 00:31:19,680 --> 00:31:21,780 start off get the count 769 00:31:21,780 --> 00:31:23,400 which is the number of tables in the database 770 00:31:23,400 --> 00:31:24,800 it's a fairly small integer 771 00:31:24,800 --> 00:31:26,480 go up, down, find it 772 00:31:26,480 --> 00:31:28,220 then you want the smallest ID 773 00:31:28,220 --> 00:31:30,040 go up, down, find it 774 00:31:30,040 --> 00:31:31,320 then you work through 775 00:31:31,320 --> 00:31:33,220 get the next smallest, next smallest, next smallest 776 00:31:33,220 --> 00:31:35,240 until you've found all the IDs in the table 777 00:31:36,740 --> 00:31:39,560 so once you've grabbed the table IDs 778 00:31:40,300 --> 00:31:42,380 which means you don't have to worry about 779 00:31:42,380 --> 00:31:44,620 apostrophes getting filtered out anymore 780 00:31:46,440 --> 00:31:47,860 because you're not working with strings 781 00:31:47,860 --> 00:31:48,740 you're working with numbers 782 00:31:49,980 --> 00:31:51,960 you get the length of the name 783 00:31:51,960 --> 00:31:52,960 matching that ID 784 00:31:52,960 --> 00:31:54,620 then you get the 785 00:31:54,620 --> 00:31:56,280 each ASCII value 786 00:31:56,280 --> 00:31:59,340 you just basically choose the ASCII value for the first letter 787 00:31:59,340 --> 00:32:00,480 second letter, third letter 788 00:32:00,480 --> 00:32:03,440 and work your way through until you've got the entire table name 789 00:32:04,100 --> 00:32:06,040 and all that information is saved 790 00:32:06,660 --> 00:32:07,860 gathering the field information 791 00:32:07,860 --> 00:32:09,200 it's very very similar 792 00:32:09,200 --> 00:32:11,220 you get the number of 793 00:32:11,220 --> 00:32:13,220 columns that are in each table 794 00:32:13,220 --> 00:32:15,040 which you reference by the table ID 795 00:32:15,040 --> 00:32:16,320 you already got 796 00:32:17,220 --> 00:32:18,400 once you've found these 797 00:32:19,680 --> 00:32:20,140 you get the column number 798 00:32:20,140 --> 00:32:22,840 now unlike the table IDs which are long integers 799 00:32:22,840 --> 00:32:25,860 so don't use 32 bit integers 800 00:32:25,860 --> 00:32:27,140 because it will crash on you 801 00:32:27,540 --> 00:32:28,680 you're going to want a long integer 802 00:32:29,340 --> 00:32:30,720 that's fairly weird 803 00:32:30,720 --> 00:32:31,980 the column IDs are different 804 00:32:31,980 --> 00:32:33,840 for SQL Server at least 805 00:32:33,840 --> 00:32:34,920 they start at one 806 00:32:34,920 --> 00:32:38,260 they end up whatever the last column is 807 00:32:38,260 --> 00:32:38,900 it's always sequential 808 00:32:38,900 --> 00:32:40,620 it's just an ordering internally 809 00:32:40,620 --> 00:32:42,900 so really you could probably guess 810 00:32:42,900 --> 00:32:47,580 but this is just for completeness sake 811 00:32:47,580 --> 00:32:49,540 so once you've got the ID number 812 00:32:49,680 --> 00:32:50,820 which it does reference it by 813 00:32:52,720 --> 00:32:54,500 do the same thing to grab 814 00:32:54,500 --> 00:32:57,620 the length of the name 815 00:32:57,620 --> 00:32:59,200 grab each character in the name 816 00:32:59,200 --> 00:33:00,540 then once you've done that 817 00:33:00,540 --> 00:33:01,820 you're going to want the data type 818 00:33:01,820 --> 00:33:03,020 because that's going to change 819 00:33:03,020 --> 00:33:05,320 how you're pulling the information from the database later 820 00:33:05,320 --> 00:33:07,000 because an integer you just grab 821 00:33:07,000 --> 00:33:08,940 if it's a text string you grab the ASCII value 822 00:33:08,940 --> 00:33:11,600 otherwise convert to text 823 00:33:11,600 --> 00:33:12,900 then grab the ASCII value 824 00:33:12,900 --> 00:33:14,520 then convert back when you've got it 825 00:33:15,040 --> 00:33:16,660 so the X type is 826 00:33:17,420 --> 00:33:19,660 the data type that they actually mean 827 00:33:19,680 --> 00:33:20,800 when they reference the 828 00:33:21,460 --> 00:33:21,980 columns 829 00:33:21,980 --> 00:33:24,820 which is stored conveniently for us 830 00:33:24,820 --> 00:33:25,780 as an integer 831 00:33:25,780 --> 00:33:28,880 and this is taken from MSDE 832 00:33:29,540 --> 00:33:31,640 just pulled it out by hand earlier 833 00:33:31,640 --> 00:33:33,640 and to save you guys some time 834 00:33:33,640 --> 00:33:35,780 if you want to work on something like this later 835 00:33:35,780 --> 00:33:37,640 these are just the numerical values 836 00:33:37,640 --> 00:33:39,640 that match up to each data type 837 00:33:39,640 --> 00:33:41,340 that you probably encounter 838 00:33:49,680 --> 00:33:51,080 okay running time 839 00:33:51,080 --> 00:33:52,020 looks like it's done 840 00:33:52,020 --> 00:33:54,920 so we will go to fun explorer 841 00:33:55,540 --> 00:33:55,820 and 842 00:33:57,120 --> 00:33:58,520 where did I put it 843 00:33:59,800 --> 00:34:00,620 that's embarrassing 844 00:34:03,040 --> 00:34:04,480 ah my documents 845 00:34:04,480 --> 00:34:05,960 not even my laptop 846 00:34:11,920 --> 00:34:13,120 this looks like it 847 00:34:15,260 --> 00:34:17,300 so hopefully you guys can see that 848 00:34:17,300 --> 00:34:19,040 from the back, can everybody see that 849 00:34:20,100 --> 00:34:21,500 this is the information 850 00:34:21,500 --> 00:34:23,220 we pulled out from the database 851 00:34:24,620 --> 00:34:25,460 looks like 852 00:34:25,460 --> 00:34:27,480 I'm a victim of my own blind sequel 853 00:34:27,480 --> 00:34:28,720 injection here but I'm not alone 854 00:34:28,720 --> 00:34:31,540 some people should have known better than to buy from Bob's bike shop 855 00:34:33,180 --> 00:34:33,700 that's 856 00:34:33,700 --> 00:34:35,420 not really DT's credit card number 857 00:34:35,420 --> 00:34:37,120 so you can stop writing over there 858 00:34:38,940 --> 00:34:39,460 but 859 00:34:39,460 --> 00:34:41,260 it basically pulls all the information out 860 00:34:41,260 --> 00:34:43,080 it stores it in XML 861 00:34:43,460 --> 00:34:44,720 it will store it with the 862 00:34:44,720 --> 00:34:47,700 primary key from the table whether or not you asked 863 00:34:47,700 --> 00:34:49,560 for it because it needed it to grab it 864 00:34:49,680 --> 00:34:51,420 so if you need to work with it later 865 00:34:51,420 --> 00:34:52,880 when you're messing around 866 00:34:52,880 --> 00:34:55,300 and decide to change somebody's expiry date on them 867 00:34:55,300 --> 00:34:55,700 for fun 868 00:34:57,600 --> 00:34:58,200 so 869 00:34:59,860 --> 00:35:01,400 back to powerpoint 870 00:35:01,400 --> 00:35:02,900 and running time 871 00:35:03,660 --> 00:35:05,640 so to grab all the information 872 00:35:05,640 --> 00:35:06,620 I showed you 873 00:35:06,620 --> 00:35:08,240 grab the username that was there 874 00:35:08,240 --> 00:35:09,300 there was only two characters 875 00:35:09,300 --> 00:35:13,100 to grab the table names 876 00:35:13,100 --> 00:35:14,360 the table contents 877 00:35:15,040 --> 00:35:16,480 the field information 878 00:35:16,480 --> 00:35:18,840 plus just those four records 879 00:35:19,680 --> 00:35:21,820 that's already over 2700 HTTP requests 880 00:35:22,220 --> 00:35:22,900 to the server 881 00:35:23,600 --> 00:35:25,120 if you use the ten second rule 882 00:35:25,120 --> 00:35:26,240 we talked about earlier 883 00:35:26,240 --> 00:35:28,120 that I claim is fairly conservative 884 00:35:28,120 --> 00:35:31,780 this would have taken over seven and a half hours non-stop 885 00:35:31,780 --> 00:35:33,060 that's not a work day 886 00:35:33,060 --> 00:35:35,140 that means not stopping to play quake 887 00:35:35,140 --> 00:35:37,200 that means not stopping to get coffee 888 00:35:37,200 --> 00:35:39,260 that's seven and a half hours non-stop 889 00:35:39,260 --> 00:35:41,300 so who was it that said 890 00:35:41,300 --> 00:35:42,480 that they'd done this by hand before 891 00:35:42,480 --> 00:35:43,660 all the way through 892 00:35:44,700 --> 00:35:46,260 what size t-shirt do you guys have 893 00:35:46,260 --> 00:35:46,580 where 894 00:35:49,680 --> 00:35:50,060 okay 895 00:35:50,060 --> 00:35:52,340 I don't know if they're pulling one over on me 896 00:35:52,340 --> 00:35:53,580 but I'm feeling generous 897 00:35:57,740 --> 00:35:58,560 extra large 898 00:36:06,840 --> 00:36:07,960 bear with the 899 00:36:07,960 --> 00:36:09,440 I can't find anything 900 00:36:12,260 --> 00:36:12,800 and 901 00:36:13,400 --> 00:36:14,440 slowing me down 902 00:36:14,440 --> 00:36:15,900 I'll find yours afterwards 903 00:36:15,900 --> 00:36:18,460 it's a nice fancy internet villain t-shirt 904 00:36:19,680 --> 00:36:19,940 that I represent 905 00:36:21,760 --> 00:36:24,060 but yeah so in reality 906 00:36:24,060 --> 00:36:26,180 that would have taken seven and a half hours 907 00:36:26,180 --> 00:36:26,920 to do by hand 908 00:36:27,540 --> 00:36:30,480 in reality it's going to take a lot longer 909 00:36:30,480 --> 00:36:31,940 in a real production database 910 00:36:31,940 --> 00:36:33,520 it's going to be more than four records 911 00:36:33,520 --> 00:36:34,120 you're pulling down 912 00:36:34,120 --> 00:36:37,000 hopefully otherwise you're wasting your time attacking them 913 00:36:37,000 --> 00:36:39,240 I mean testing against them 914 00:36:42,240 --> 00:36:43,360 we're all good guys here 915 00:36:45,080 --> 00:36:45,560 so 916 00:36:45,560 --> 00:36:46,640 nothing's perfect 917 00:36:46,640 --> 00:36:48,500 I don't claim to be 918 00:36:49,680 --> 00:36:51,660 because there are still problems with 919 00:36:51,660 --> 00:36:53,480 squeal as it scans right now 920 00:36:53,480 --> 00:36:55,300 the first big problem is 921 00:36:55,300 --> 00:36:56,720 noise generation and 922 00:36:56,720 --> 00:36:58,840 server log denial of service 923 00:36:59,540 --> 00:37:01,780 when you're doing thousands and thousands 924 00:37:01,780 --> 00:37:03,640 and thousands of requests against your web 925 00:37:03,640 --> 00:37:05,600 server chances are they're going 926 00:37:05,600 --> 00:37:06,780 to notice at some point 927 00:37:06,780 --> 00:37:09,260 just a string of SQL statements in their logs 928 00:37:09,260 --> 00:37:10,620 if they don't then 929 00:37:11,780 --> 00:37:13,600 whew good admin 930 00:37:13,600 --> 00:37:15,720 but chances are 931 00:37:15,720 --> 00:37:16,280 they're going to notice 932 00:37:16,280 --> 00:37:19,480 and if it's a big database there's a chance that you might 933 00:37:19,680 --> 00:37:21,360 have to fill up their hard drive before you pull out 934 00:37:21,360 --> 00:37:22,880 all the information from the database 935 00:37:23,560 --> 00:37:25,000 because they might have decided 936 00:37:25,000 --> 00:37:27,400 oh yeah 100 megs is enough 937 00:37:27,400 --> 00:37:28,200 for the web server 938 00:37:28,200 --> 00:37:30,060 but I need a 5 gig database 939 00:37:30,940 --> 00:37:31,700 falls apart 940 00:37:33,420 --> 00:37:35,400 also if it's a very small 941 00:37:35,400 --> 00:37:37,300 web server experimentally 942 00:37:37,300 --> 00:37:38,640 we've kind of noticed that 943 00:37:38,640 --> 00:37:40,980 it can knock out the web server 944 00:37:40,980 --> 00:37:42,220 for a second or two 945 00:37:42,220 --> 00:37:45,080 resulting in a real denial of service 946 00:37:45,080 --> 00:37:47,500 so run this on your own systems 947 00:37:48,360 --> 00:37:48,840 um 948 00:37:49,680 --> 00:37:50,980 the other problem is 949 00:37:50,980 --> 00:37:52,260 has a couple problems 950 00:37:52,260 --> 00:37:54,380 it has issues at the moment with 951 00:37:54,380 --> 00:37:56,120 if there's no carriage returns 952 00:37:56,120 --> 00:37:58,260 in the auto generated HTML 953 00:37:58,260 --> 00:38:00,600 that means the guy who wrote it 954 00:38:00,600 --> 00:38:01,880 didn't think of putting in 955 00:38:01,880 --> 00:38:02,780 the carriage return 956 00:38:03,860 --> 00:38:04,400 character 957 00:38:05,760 --> 00:38:07,700 so that means if you were to view it by hand 958 00:38:07,700 --> 00:38:09,120 it's just one long string 959 00:38:09,120 --> 00:38:11,600 I'm sure everybody's seen one long string 960 00:38:11,600 --> 00:38:13,540 nobody likes to work with that 961 00:38:13,540 --> 00:38:14,180 not even SQL 962 00:38:14,180 --> 00:38:19,300 but there's ways to possibly get around that too 963 00:38:20,520 --> 00:38:22,500 so one of the first options 964 00:38:22,500 --> 00:38:24,600 that people immediately think of 965 00:38:24,600 --> 00:38:26,600 is why not just force the carriage return 966 00:38:26,600 --> 00:38:27,920 after a certain number of characters 967 00:38:30,220 --> 00:38:30,720 but 968 00:38:31,320 --> 00:38:32,340 if you've got 969 00:38:32,980 --> 00:38:34,140 random stuff changing 970 00:38:34,140 --> 00:38:35,520 changing in length as well 971 00:38:35,520 --> 00:38:36,840 then all of a sudden your signatures 972 00:38:36,840 --> 00:38:37,600 are going to be offset 973 00:38:37,600 --> 00:38:41,440 and it doesn't seem to make much sense anymore 974 00:38:41,440 --> 00:38:42,920 because they don't match up 975 00:38:42,920 --> 00:38:44,460 the filters don't work anymore 976 00:38:44,460 --> 00:38:46,200 because things are shifting 977 00:38:46,200 --> 00:38:48,220 because of that one forced carriage return 978 00:38:49,680 --> 00:38:51,300 throws off the comparison techniques 979 00:38:51,300 --> 00:38:53,460 at this point you'd need an HTML 980 00:38:53,460 --> 00:38:54,740 parser of some kind 981 00:38:54,740 --> 00:38:56,780 it might be the tree parser I discussed earlier 982 00:38:57,480 --> 00:38:58,520 another option 983 00:38:58,520 --> 00:39:01,300 would be to run something along the lines of 984 00:39:01,300 --> 00:39:02,020 HTML tidy 985 00:39:02,020 --> 00:39:04,820 you'd have to double check to make sure it's deterministic 986 00:39:04,820 --> 00:39:07,500 which means I'm going to be double checking to make sure it's deterministic 987 00:39:07,500 --> 00:39:09,560 make sure the same thing comes out every time 988 00:39:09,560 --> 00:39:11,700 and at that point 989 00:39:11,700 --> 00:39:13,080 it's filtered out 990 00:39:13,080 --> 00:39:15,440 and cleaned up so that SQL can read it 991 00:39:15,440 --> 00:39:16,020 and work from there 992 00:39:17,720 --> 00:39:19,580 or an option that was suggested 993 00:39:19,680 --> 00:39:20,740 by Black Hat was to 994 00:39:21,620 --> 00:39:23,760 instead of doing something along those 995 00:39:23,760 --> 00:39:24,920 instead of always 996 00:39:25,480 --> 00:39:26,640 delimiting by carriage returns 997 00:39:26,640 --> 00:39:28,500 give the users the option to 998 00:39:29,180 --> 00:39:30,740 delimit by other characters 999 00:39:30,740 --> 00:39:33,100 which is something we're looking at rolling into the next version 1000 00:39:37,500 --> 00:39:39,440 so where do we go from here 1001 00:39:39,440 --> 00:39:40,560 well 1002 00:39:41,360 --> 00:39:43,160 same techniques could be utilized 1003 00:39:43,160 --> 00:39:45,140 in other types of applications 1004 00:39:45,480 --> 00:39:47,560 that still interpret results from 1005 00:39:47,560 --> 00:39:48,480 HTML responses 1006 00:39:49,680 --> 00:39:50,800 as long as you're trying to read 1007 00:39:51,440 --> 00:39:53,040 values, read information 1008 00:39:53,720 --> 00:39:55,520 subtly from what comes back 1009 00:39:55,520 --> 00:39:57,760 you can use a similar signature set 1010 00:39:57,760 --> 00:39:58,660 to work from there 1011 00:39:58,660 --> 00:40:00,180 and filter it out similarly 1012 00:40:00,180 --> 00:40:02,440 even if it's more than two 1013 00:40:02,440 --> 00:40:03,900 you can just filter out the three 1014 00:40:03,900 --> 00:40:05,540 and do comparisons along the three or more 1015 00:40:06,700 --> 00:40:08,740 but you guys want to know fun stuff, right? 1016 00:40:09,120 --> 00:40:11,640 so we know that we've been able 1017 00:40:11,640 --> 00:40:12,980 to automate blind SQL injection 1018 00:40:12,980 --> 00:40:14,940 which means we've been able to automate 1019 00:40:14,940 --> 00:40:17,460 the process of putting stuff on 1020 00:40:17,460 --> 00:40:19,220 and reading stuff off of the SQL server 1021 00:40:19,680 --> 00:40:21,620 so, fun stuff, SQL IRC 1022 00:40:22,780 --> 00:40:23,260 yay 1023 00:40:23,900 --> 00:40:25,720 could be idle, could be lag, nobody's 1024 00:40:25,720 --> 00:40:27,880 really sure, but everybody loves IRC 1025 00:40:27,880 --> 00:40:29,320 so why not implement it that way 1026 00:40:30,040 --> 00:40:31,800 another possible option that could 1027 00:40:31,800 --> 00:40:33,740 be used for something like this is 1028 00:40:33,740 --> 00:40:34,820 SQL FTP 1029 00:40:34,820 --> 00:40:37,220 and if you guys can't read the 1030 00:40:37,220 --> 00:40:39,360 almost Linus Torvalds quote there 1031 00:40:39,360 --> 00:40:41,920 that means, only wimps use take back up 1032 00:40:41,920 --> 00:40:43,580 real men just upload their important 1033 00:40:43,580 --> 00:40:45,200 stuff to somebody else's SQL server 1034 00:40:48,420 --> 00:40:49,660 something else you could possibly 1035 00:40:49,680 --> 00:40:51,220 do, I don't know if you can even see that 1036 00:40:51,220 --> 00:40:52,520 SQL Quake 1037 00:40:53,540 --> 00:40:54,560 no, that wouldn't work 1038 00:40:56,300 --> 00:40:56,660 but 1039 00:40:57,460 --> 00:40:59,000 if you missed Johnny Long's talk 1040 00:40:59,940 --> 00:41:01,720 not really sure where you might 1041 00:41:01,720 --> 00:41:02,860 be able to find sites 1042 00:41:03,980 --> 00:41:05,420 because you just want to test 1043 00:41:05,420 --> 00:41:07,300 but you want to find stuff 1044 00:41:07,300 --> 00:41:08,120 and you want to play around 1045 00:41:09,600 --> 00:41:11,020 where would you go about finding 1046 00:41:11,020 --> 00:41:13,460 sites you could play around with that are possibly 1047 00:41:13,460 --> 00:41:14,820 injectable, well 1048 00:41:15,220 --> 00:41:17,480 I'm going to break it to you, nobody's going to email 1049 00:41:17,480 --> 00:41:19,400 you randomly out of the blue 1050 00:41:19,980 --> 00:41:21,880 just doesn't happen in this day and age 1051 00:41:23,860 --> 00:41:25,680 nobody's going to email you unsolicited 1052 00:41:26,580 --> 00:41:27,920 it's not going to be a stranger 1053 00:41:27,920 --> 00:41:29,660 that emails you, you know the guy that's 1054 00:41:29,660 --> 00:41:31,580 emailing you, and they're not going to email 1055 00:41:31,580 --> 00:41:33,760 you with random stuff that you 1056 00:41:33,760 --> 00:41:34,480 don't care about 1057 00:41:35,680 --> 00:41:37,520 and if they do email you 1058 00:41:37,520 --> 00:41:39,760 they're not going to email you 1059 00:41:39,760 --> 00:41:40,660 a SQL injection 1060 00:41:44,780 --> 00:41:45,260 yeah 1061 00:41:45,960 --> 00:41:46,780 I'm not joking 1062 00:41:49,980 --> 00:41:50,960 but then again 1063 00:41:51,470 --> 00:41:52,980 if they did email you 1064 00:41:53,560 --> 00:41:55,620 and they did email you a SQL 1065 00:41:55,620 --> 00:41:57,680 injection, it's not like 1066 00:41:57,680 --> 00:41:59,700 they're the kind of people that want to remain anonymous 1067 00:41:59,700 --> 00:42:01,280 and don't want to be tracked down 1068 00:42:05,360 --> 00:42:05,860 so 1069 00:42:08,380 --> 00:42:09,780 just closing up here 1070 00:42:09,780 --> 00:42:11,400 a couple suggested 1071 00:42:11,960 --> 00:42:12,940 papers that 1072 00:42:12,940 --> 00:42:15,400 if you don't have a lot of experience with SQL injection 1073 00:42:15,400 --> 00:42:17,860 yet and you're looking at learning more about it 1074 00:42:17,860 --> 00:42:19,500 the first two are from 1075 00:42:19,680 --> 00:42:21,220 NGS systems by Chris Anley 1076 00:42:21,220 --> 00:42:22,860 very good papers 1077 00:42:22,860 --> 00:42:25,080 both related to SQL Server 1078 00:42:25,470 --> 00:42:27,120 primarily the error-based stuff 1079 00:42:27,980 --> 00:42:29,360 the third one 1080 00:42:29,360 --> 00:42:31,320 is the blind SQL injection paper 1081 00:42:31,320 --> 00:42:32,480 from Spy Dynamics 1082 00:42:33,420 --> 00:42:34,860 by Kevin Spett 1083 00:42:34,860 --> 00:42:36,420 another very good paper 1084 00:42:36,420 --> 00:42:39,280 detailing the processes that I was talking about 1085 00:42:39,280 --> 00:42:40,160 automating here 1086 00:42:40,160 --> 00:42:43,160 and the fourth one is another one on 1087 00:42:43,160 --> 00:42:44,820 blind SQL injection from Imperva 1088 00:42:44,820 --> 00:42:47,180 I don't have the actual link to it at the moment 1089 00:42:47,180 --> 00:42:49,600 but it's easy to find off of 1090 00:42:49,680 --> 00:42:50,340 imperva.com 1091 00:42:51,700 --> 00:42:53,300 they take a couple different approaches 1092 00:42:53,300 --> 00:42:54,660 than the Spy Dynamics guys do 1093 00:42:54,660 --> 00:42:55,880 so you might want to check that out 1094 00:42:57,700 --> 00:42:59,500 so I'm going to open it up to 1095 00:42:59,500 --> 00:43:00,800 questions right now 1096 00:43:02,080 --> 00:43:03,780 if you're looking for this tool 1097 00:43:03,780 --> 00:43:04,520 it's not up yet 1098 00:43:04,520 --> 00:43:05,720 it should be on the CD 1099 00:43:05,720 --> 00:43:07,600 it will be available at this website 1100 00:43:07,600 --> 00:43:09,660 there's a couple other tools that are available there as well 1101 00:43:09,660 --> 00:43:11,840 so does anybody have any questions? 1102 00:43:11,980 --> 00:43:12,480 I see you 1103 00:43:16,100 --> 00:43:17,200 at the moment 1104 00:43:17,200 --> 00:43:18,680 we just took SQL Server 1105 00:43:19,680 --> 00:43:20,100 on time 1106 00:43:20,100 --> 00:43:22,060 and most of the examples are for that 1107 00:43:22,060 --> 00:43:24,240 but as long as you have access to 1108 00:43:24,240 --> 00:43:26,220 the equivalent of the SysObjects table 1109 00:43:26,220 --> 00:43:28,780 or read access to the schema 1110 00:43:28,780 --> 00:43:30,740 you should be able to do it 1111 00:43:31,640 --> 00:43:33,480 we're looking at trying to figure out 1112 00:43:33,480 --> 00:43:34,240 how to do it with Oracle 1113 00:43:34,240 --> 00:43:36,860 although Oracle DBAs are usually a bit better 1114 00:43:36,860 --> 00:43:38,140 about locking down their systems 1115 00:43:38,140 --> 00:43:39,380 than SQL Server DBAs 1116 00:43:39,380 --> 00:43:42,860 so as long as there is a SysObjects table 1117 00:43:42,860 --> 00:43:44,120 that you can get access to 1118 00:43:45,000 --> 00:43:46,540 there's a way to exploit it that way 1119 00:43:54,660 --> 00:43:57,620 the question is 1120 00:43:57,620 --> 00:43:59,340 do I have any experience 1121 00:43:59,340 --> 00:44:02,220 attacking Java applications 1122 00:44:02,220 --> 00:44:03,820 in terms of SQL injections 1123 00:44:05,140 --> 00:44:06,220 I don't 1124 00:44:06,220 --> 00:44:07,080 myself 1125 00:44:07,700 --> 00:44:09,540 I basically pick on the weak 1126 00:44:10,200 --> 00:44:12,120 which is the ASP coders out there 1127 00:44:12,120 --> 00:44:13,140 do you have any? 1128 00:44:13,840 --> 00:44:15,360 but I'm told it's doable 1129 00:44:15,360 --> 00:44:17,080 by people who know more than I do 1130 00:44:17,080 --> 00:44:19,000 is there a specific question 1131 00:44:19,000 --> 00:44:19,660 related to it? 1132 00:44:26,160 --> 00:44:28,100 basically as far as languages go 1133 00:44:29,000 --> 00:44:30,040 you're going to find 1134 00:44:30,040 --> 00:44:31,760 that as long as the language supports 1135 00:44:32,740 --> 00:44:33,560 parameterized queries 1136 00:44:33,560 --> 00:44:34,800 that's the big thing 1137 00:44:34,800 --> 00:44:37,460 if you're looking at locking down a database 1138 00:44:37,460 --> 00:44:40,620 make sure you're using parameterized queries 1139 00:44:40,620 --> 00:44:42,420 and if you have the option to use stored procedures 1140 00:44:42,420 --> 00:44:44,480 that's another layer that makes it more complex 1141 00:44:44,480 --> 00:44:46,460 for the attacker to get through 1142 00:44:46,460 --> 00:44:47,340 and chances are 1143 00:44:47,340 --> 00:44:49,040 if they're not targeting you specifically 1144 00:44:49,680 --> 00:44:50,000 they're going to move on 1145 00:44:50,000 --> 00:44:50,880 because it's not worth their time 1146 00:44:53,040 --> 00:44:53,760 parameterized queries 1147 00:44:53,760 --> 00:44:54,840 I can't stress this enough 1148 00:44:55,560 --> 00:44:57,420 .NET has it, Java has it 1149 00:44:57,420 --> 00:44:59,540 later versions of PHP should have it 1150 00:44:59,540 --> 00:45:01,560 and if you're not using it 1151 00:45:01,560 --> 00:45:02,300 you really should be 1152 00:45:02,300 --> 00:45:04,660 if the language you're using isn't using it 1153 00:45:04,660 --> 00:45:06,080 find a different one 1154 00:45:06,080 --> 00:45:07,900 there's a lot of ones to choose from at the moment 1155 00:45:08,400 --> 00:45:10,060 unfortunately a lot of textbooks out there 1156 00:45:10,060 --> 00:45:12,180 tend to start off with 1157 00:45:12,180 --> 00:45:13,200 this is your database code 1158 00:45:13,200 --> 00:45:15,240 create it on the fly, there you go 1159 00:45:19,680 --> 00:45:20,200 there's a lot of examples for 1160 00:45:20,200 --> 00:45:21,780 SQL connections right off the bat 1161 00:45:21,780 --> 00:45:23,420 and it's not until three chapters later 1162 00:45:23,420 --> 00:45:24,820 where you stop reading at this point 1163 00:45:24,820 --> 00:45:26,680 that it gets into safer database calls 1164 00:45:26,680 --> 00:45:29,040 so look for parameterized queries 1165 00:45:29,040 --> 00:45:30,180 of some kind or another 1166 00:45:30,180 --> 00:45:32,180 where you actually identify the name 1167 00:45:32,180 --> 00:45:34,620 of each element that you're hitting 1168 00:45:34,620 --> 00:45:36,040 and the data type that it's going to 1169 00:45:36,040 --> 00:45:37,600 is there any more questions? 1170 00:45:37,880 --> 00:45:38,240 yes 1171 00:45:50,980 --> 00:45:52,200 the question was 1172 00:45:52,200 --> 00:45:53,720 can you insert a delay 1173 00:45:53,720 --> 00:45:55,300 to the web server 1174 00:45:55,300 --> 00:45:57,560 the current version of SQL 1175 00:45:57,560 --> 00:45:58,900 doesn't support throttling 1176 00:45:58,900 --> 00:45:59,960 as far as the delay 1177 00:45:59,960 --> 00:46:01,380 I believe that's what you're asking 1178 00:46:02,020 --> 00:46:03,360 it could be done 1179 00:46:08,520 --> 00:46:10,220 yeah, sort of having it pause 1180 00:46:10,220 --> 00:46:11,340 before it does the next one 1181 00:46:11,340 --> 00:46:13,760 the current version doesn't do this 1182 00:46:13,760 --> 00:46:16,280 there's something I'm looking at putting into the next version 1183 00:46:16,280 --> 00:46:18,480 because of that other denial of service problem 1184 00:46:19,740 --> 00:46:22,040 so the next version will have that 1185 00:46:22,040 --> 00:46:22,900 but currently 1186 00:46:22,900 --> 00:46:24,620 it doesn't support it right now 1187 00:46:24,620 --> 00:46:26,080 it's just simply that 1188 00:46:28,060 --> 00:46:29,940 one, it just fires them off 1189 00:46:29,940 --> 00:46:30,700 as fast as it can 1190 00:46:30,700 --> 00:46:33,940 so it's about three or four per second 1191 00:46:33,940 --> 00:46:35,540 I think it fires it off right now 1192 00:46:37,140 --> 00:46:37,620 yes 1193 00:46:43,780 --> 00:46:44,740 you can 1194 00:46:44,740 --> 00:46:47,480 you can only stop 1195 00:46:47,480 --> 00:46:48,840 in between where the buttons are 1196 00:46:49,980 --> 00:46:51,840 so it's like you can load the tables 1197 00:46:51,840 --> 00:46:52,780 load the table information 1198 00:46:53,280 --> 00:46:54,880 and then stop that, come back 1199 00:46:54,880 --> 00:46:55,760 load the field information 1200 00:46:56,880 --> 00:46:59,780 so the general answer to what you wanted 1201 00:46:59,780 --> 00:47:00,260 was no 1202 00:47:00,260 --> 00:47:00,860 oh 1203 00:47:04,920 --> 00:47:05,720 you basically 1204 00:47:06,360 --> 00:47:08,360 you have to grab all the table names 1205 00:47:08,360 --> 00:47:08,860 at once 1206 00:47:08,860 --> 00:47:10,920 but you just grab the fields for each table 1207 00:47:10,920 --> 00:47:11,540 as you need it 1208 00:47:12,500 --> 00:47:15,040 then you can just grab the specific information you need 1209 00:47:16,940 --> 00:47:17,500 is there 1210 00:47:17,500 --> 00:47:18,660 any more questions? 1211 00:47:22,960 --> 00:47:23,560 no 1212 00:47:35,500 --> 00:47:36,780 it's a binary search 1213 00:47:36,780 --> 00:47:39,260 all the integer searches 1214 00:47:39,260 --> 00:47:41,220 that take place are binary searches 1215 00:47:41,220 --> 00:47:43,480 because even for an alphabet 1216 00:47:43,480 --> 00:47:45,460 you're looking at 14 1217 00:47:45,460 --> 00:47:47,660 at the maximum for a binary search 1218 00:47:47,660 --> 00:47:48,780 I believe, whereas 1219 00:47:49,680 --> 00:47:50,940 if you do it by 1220 00:47:51,960 --> 00:47:53,460 a non-binary search 1221 00:47:53,460 --> 00:47:55,140 it's going to be longer than 14 on average 1222 00:47:55,540 --> 00:47:57,560 so it's faster, even if it's just an alphabet 1223 00:47:57,560 --> 00:47:58,460 with a limited range 1224 00:47:58,460 --> 00:48:00,080 you're still going to want to do a binary search 1225 00:48:00,080 --> 00:48:01,680 I think the only difference with that 1226 00:48:01,680 --> 00:48:04,020 is that we know the top and the end point 1227 00:48:04,020 --> 00:48:06,320 we start between 0 and 1228 00:48:07,340 --> 00:48:08,640 255 and then go from there 1229 00:48:09,180 --> 00:48:10,860 for ASCII values 1230 00:48:11,820 --> 00:48:12,940 when we're doing it that way 1231 00:48:17,120 --> 00:48:18,140 any more questions? 1232 00:48:19,680 --> 00:48:19,900 no 1233 00:48:21,380 --> 00:48:23,380 well thanks everybody for sticking around 1234 00:48:23,380 --> 00:48:24,820 my name is Cameron Hodgson