1 00:00:00,000 --> 00:00:01,060 Hello, hello everybody. 2 00:00:01,300 --> 00:00:03,180 Buenos dias a todos los que habláis español. 3 00:00:03,500 --> 00:00:04,860 How many of you speak Spanish? 4 00:00:05,760 --> 00:00:06,600 Oh, perfect. 5 00:00:07,180 --> 00:00:10,160 Well, first of all, thank you for coming to this session 6 00:00:10,160 --> 00:00:14,000 about time-based blind SQL injection using heavy queries. 7 00:00:14,440 --> 00:00:15,620 Let me introduce myself. 8 00:00:15,820 --> 00:00:16,960 My name is Chema Alonso. 9 00:00:18,240 --> 00:00:19,460 I'm from Spain. 10 00:00:19,800 --> 00:00:21,220 And if you are wondering, 11 00:00:21,460 --> 00:00:23,560 no, I'm not a bullfighter, 12 00:00:23,560 --> 00:00:26,120 and no, I'm not a flamenco singer, 13 00:00:26,360 --> 00:00:28,020 even if you think I look like. 14 00:00:28,020 --> 00:00:31,360 I work as a security consultant in a company in Spain 15 00:00:31,360 --> 00:00:33,020 called Informatica 64, 16 00:00:33,460 --> 00:00:36,460 and I'm also a Microsoft MVP. 17 00:00:36,800 --> 00:00:39,240 MVP stands for Most Valuable Professional, 18 00:00:39,480 --> 00:00:44,200 but some people said that it stands for Most Valuable Pets. 19 00:00:44,320 --> 00:00:46,100 I'm not sure which one is the right one. 20 00:00:48,180 --> 00:00:50,500 But MVPs don't work for Microsoft. 21 00:00:50,780 --> 00:00:52,760 It's just an award that Microsoft gives 22 00:00:52,760 --> 00:00:54,380 to some technicians around the world. 23 00:00:54,500 --> 00:00:57,240 And I'm an MVP in Windows Security. 24 00:00:57,480 --> 00:00:58,000 So, thank you. 25 00:00:58,020 --> 00:00:59,880 And let me introduce my friend, my colleague, 26 00:01:00,060 --> 00:01:01,340 my co-speaker today. 27 00:01:01,800 --> 00:01:03,540 He does work for Microsoft, 28 00:01:03,740 --> 00:01:04,680 and he's happy. 29 00:01:04,800 --> 00:01:05,360 I don't know why. 30 00:01:06,720 --> 00:01:09,920 And he's a technical guy. 31 00:01:10,860 --> 00:01:13,580 He's a technical guy in a marketing department. 32 00:01:13,920 --> 00:01:16,860 He works as a Microsoft IT pro evangelist, 33 00:01:16,880 --> 00:01:19,040 helping people in the Microsoft TechNet program 34 00:01:19,040 --> 00:01:20,880 with Microsoft products and technologies 35 00:01:20,880 --> 00:01:22,760 and that kind of things. 36 00:01:23,080 --> 00:01:23,700 Go ahead. 37 00:01:23,900 --> 00:01:24,980 By the way, my name is Jose. 38 00:01:25,200 --> 00:01:26,300 Ah, Jose, of course. 39 00:01:27,180 --> 00:01:29,120 He probably is a bullfighter. 40 00:01:30,400 --> 00:01:32,660 Okay, thank you, Chema, for your presentation. 41 00:01:33,140 --> 00:01:35,700 Thank you all for your interest in this session. 42 00:01:37,280 --> 00:01:37,800 Okay. 43 00:01:40,560 --> 00:01:42,660 Well, the entire credit for this idea 44 00:01:42,660 --> 00:01:44,760 and for the vast majority of the presentation 45 00:01:44,760 --> 00:01:46,860 must be given to Chema. 46 00:01:46,980 --> 00:01:48,060 As a security consultant, 47 00:01:48,560 --> 00:01:50,520 he's an expert in many hacking techniques. 48 00:01:50,980 --> 00:01:54,620 And around one and a half years ago, 49 00:01:54,620 --> 00:01:56,480 he started his Ph.D. 50 00:01:56,520 --> 00:01:58,160 So he started writing a paper 51 00:01:58,160 --> 00:02:02,660 on blind vulnerabilities in web applications. 52 00:02:03,160 --> 00:02:06,100 He conducted a lot of research 53 00:02:06,100 --> 00:02:10,900 in things such as blind XPath injections, 54 00:02:11,680 --> 00:02:13,160 blind LDAP injections, 55 00:02:13,420 --> 00:02:15,040 and blind SQL injections. 56 00:02:15,620 --> 00:02:20,240 In fact, he's the author of one of the most in-depth papers 57 00:02:20,240 --> 00:02:21,860 about blind LDAP injections, 58 00:02:21,980 --> 00:02:24,420 about LDAP injections in general. 59 00:02:24,620 --> 00:02:26,720 And I helped him present that paper 60 00:02:27,540 --> 00:02:29,620 on Black Hat Europe 2008, 61 00:02:30,240 --> 00:02:34,600 which was held in Amsterdam around four months ago. 62 00:02:35,440 --> 00:02:36,960 Everything went well there. 63 00:02:37,380 --> 00:02:39,040 So, as you can imagine, 64 00:02:39,200 --> 00:02:42,920 we end up in a typical Amsterdam coffee shop 65 00:02:43,620 --> 00:02:45,200 smoking some kind of substance. 66 00:02:46,880 --> 00:02:50,960 And with the enthusiasm of the moment, 67 00:02:51,060 --> 00:02:51,840 we thought, okay, 68 00:02:51,860 --> 00:02:53,820 why don't we send another paper 69 00:02:54,620 --> 00:02:55,720 to DEFCON in the USA, 70 00:02:55,940 --> 00:02:59,140 since even though our English is quite poor, 71 00:02:59,340 --> 00:03:01,580 people seem to understand us. 72 00:03:01,780 --> 00:03:03,000 Okay, so that's what we did. 73 00:03:03,140 --> 00:03:04,760 We sent our paper to DEFCON. 74 00:03:05,200 --> 00:03:06,840 The organization here at DEFCON, 75 00:03:06,900 --> 00:03:08,200 I don't know why they smoke, 76 00:03:08,360 --> 00:03:10,080 but they said, okay, this is good enough. 77 00:03:10,320 --> 00:03:12,720 So come on over, 78 00:03:12,840 --> 00:03:15,520 and here we are with all of you. 79 00:03:15,700 --> 00:03:18,440 So please, Chema, introduce us into today's agenda. 80 00:03:18,900 --> 00:03:21,240 Well, this is the agenda for today's session. 81 00:03:21,480 --> 00:03:23,580 As you can see, this session has two parts. 82 00:03:23,580 --> 00:03:27,000 The first one is about things that you may probably know 83 00:03:27,000 --> 00:03:29,980 about topics as code injection, 84 00:03:30,260 --> 00:03:31,640 blind attacks, blind SQL injection, 85 00:03:31,880 --> 00:03:33,760 and time-based blind SQL injection. 86 00:03:34,900 --> 00:03:36,420 After finishing this part, 87 00:03:36,540 --> 00:03:39,800 we are going to get into the new part of this session, 88 00:03:39,920 --> 00:03:44,180 and it's about how to perform a blind SQL injection, 89 00:03:45,380 --> 00:03:47,800 time-based, but without using 90 00:03:47,800 --> 00:03:50,720 the normal time delay function that databases have. 91 00:03:50,980 --> 00:03:53,220 In this case, we are going to use a new trick. 92 00:03:53,220 --> 00:03:58,360 It's a trick to get a time delay using a heavy query. 93 00:03:58,540 --> 00:03:59,800 Let's see how it works. 94 00:04:00,200 --> 00:04:03,260 At the end, we are going to have several demos, 95 00:04:03,400 --> 00:04:05,080 and we are going to release a new tool. 96 00:04:05,320 --> 00:04:07,320 This tool is called Marathon Tool 97 00:04:07,320 --> 00:04:08,760 because it's a very slow tool, 98 00:04:08,920 --> 00:04:10,740 but it works very well. 99 00:04:11,300 --> 00:04:14,700 And after that, you are free to do whatever you want 100 00:04:14,700 --> 00:04:15,520 here in Las Vegas. 101 00:04:15,760 --> 00:04:17,160 So let's start from the beginning. 102 00:04:18,840 --> 00:04:21,400 Okay, let's start with that brief summary, 103 00:04:21,740 --> 00:04:22,880 10 to 15 minutes, 104 00:04:22,880 --> 00:04:25,640 a review about things you probably know 105 00:04:25,640 --> 00:04:28,620 if you've been following SQL injection 106 00:04:28,620 --> 00:04:32,360 or code injection attacks for the last five to six years. 107 00:04:33,700 --> 00:04:36,880 Code injection has been a security problem 108 00:04:38,700 --> 00:04:40,120 since a long time ago. 109 00:04:40,400 --> 00:04:42,800 The first time most of us heard about it 110 00:04:42,800 --> 00:04:47,600 was back in December 25th, 1998, 111 00:04:48,820 --> 00:04:52,720 when a guy that answered to the 112 00:04:52,880 --> 00:04:54,940 nickname of Rainforest Puppy 113 00:04:54,940 --> 00:04:57,800 published a paper on how to attack 114 00:04:57,800 --> 00:05:02,080 ASP application using SQL queries. 115 00:05:03,700 --> 00:05:05,680 It's been almost 10 years since then, 116 00:05:05,780 --> 00:05:09,460 but still one of the main issues in web security. 117 00:05:10,040 --> 00:05:11,800 In fact, last September, 118 00:05:11,900 --> 00:05:15,820 OWASP, Open Web Application Security Project, 119 00:05:17,760 --> 00:05:22,260 published a document rating the 10 most common 120 00:05:22,260 --> 00:05:25,660 security vulnerabilities in web application, 121 00:05:26,020 --> 00:05:30,100 and code injection was rated in second place 122 00:05:30,100 --> 00:05:34,880 right after cross-site scripting. 123 00:05:35,100 --> 00:05:38,200 Nowadays, you can find plenty of documentation, 124 00:05:38,740 --> 00:05:43,220 guides, tutorials on how to do techniques 125 00:05:43,220 --> 00:05:46,280 such as XPath injection, LDAP injection, 126 00:05:46,480 --> 00:05:48,240 or SQL injection. 127 00:05:49,520 --> 00:05:52,560 And let's go now into reviewing a little bit 128 00:05:52,560 --> 00:05:54,160 about what a blind attack is. 129 00:05:55,120 --> 00:05:57,880 Most of you probably already know, 130 00:05:58,000 --> 00:06:02,920 but when an attacker is able to inject code 131 00:06:02,920 --> 00:06:05,200 into a vulnerable web application, 132 00:06:05,560 --> 00:06:08,400 it depends where he can inject the code 133 00:06:08,400 --> 00:06:09,960 and what he wants to do. 134 00:06:10,080 --> 00:06:13,780 He can follow many methods. 135 00:06:14,000 --> 00:06:15,940 Sometimes if he can inject code 136 00:06:15,940 --> 00:06:18,220 in the name of the password, 137 00:06:18,240 --> 00:06:21,860 he can use that injection to bypass the login page 138 00:06:21,860 --> 00:06:24,860 and access a private website. 139 00:06:25,300 --> 00:06:29,080 Other times, if he's able to inject code in the URL, 140 00:06:29,320 --> 00:06:32,540 he's able to extract directly in the web page response 141 00:06:32,540 --> 00:06:34,260 data from the database. 142 00:06:34,560 --> 00:06:38,420 But some other times, he's able to inject code, 143 00:06:38,540 --> 00:06:42,660 but he doesn't get any data directly out from the database 144 00:06:42,660 --> 00:06:47,500 or any error message that he could use 145 00:06:47,500 --> 00:06:52,020 to deduce information about the database. 146 00:06:52,400 --> 00:06:58,660 So this kind of environment gives the developers 147 00:06:58,660 --> 00:07:01,040 and the testing teams, the security testing team, 148 00:07:01,460 --> 00:07:05,200 a false sense of security since... 149 00:07:06,160 --> 00:07:07,420 Can you hear me? 150 00:07:08,680 --> 00:07:09,840 Now, yes. 151 00:07:10,260 --> 00:07:17,360 Since data is not directly exposed in the web page. 152 00:07:17,500 --> 00:07:21,020 But if the attacker is able to inject code, 153 00:07:21,160 --> 00:07:25,700 injecting some LDAP, XPath, or SQL queries, 154 00:07:25,860 --> 00:07:28,520 is able to deduce data, 155 00:07:28,780 --> 00:07:30,940 if the response page that he obtained, 156 00:07:31,160 --> 00:07:32,060 depending on the data, 157 00:07:32,320 --> 00:07:35,660 is different or has different behaviors. 158 00:07:36,400 --> 00:07:40,400 Okay, so blind attacks, in summary, are possible 159 00:07:41,120 --> 00:07:43,860 when web applications behave in a different way 160 00:07:43,860 --> 00:07:46,780 when you insert a query that is always true. 161 00:07:46,780 --> 00:07:49,760 And when you insert a query that is always false. 162 00:07:49,860 --> 00:07:50,860 If you get different response, 163 00:07:51,040 --> 00:07:55,300 then that web application is possibly vulnerable. 164 00:07:55,940 --> 00:08:01,200 Okay, so let's now go into blind SQL injections attack. 165 00:08:01,620 --> 00:08:07,880 If a web application that is using a relational database, 166 00:08:08,220 --> 00:08:13,180 the attacker will, of course, inject a SQL query. 167 00:08:13,480 --> 00:08:16,200 The most easy way 168 00:08:16,200 --> 00:08:20,740 to find out a vulnerable web application to this 169 00:08:20,740 --> 00:08:23,440 is injecting something that is always true, 170 00:08:23,540 --> 00:08:24,600 like one equals to one, 171 00:08:24,740 --> 00:08:26,820 looking at the behavior of the web page, 172 00:08:29,100 --> 00:08:31,940 then introducing something that is always false, 173 00:08:32,100 --> 00:08:33,380 like one equals to two, 174 00:08:33,540 --> 00:08:36,460 looking at the response page, 175 00:08:36,680 --> 00:08:39,300 and finding the difference. 176 00:08:39,860 --> 00:08:41,920 After you find a vulnerability in a web page, 177 00:08:42,060 --> 00:08:45,020 well, the attacker's only job is to 178 00:08:45,020 --> 00:08:46,960 find these different behaviors, 179 00:08:47,340 --> 00:08:50,420 and then to construct the correct queries 180 00:08:50,780 --> 00:08:55,080 to being able to extract the data. 181 00:08:55,520 --> 00:08:58,100 So let me now go on how to, 182 00:08:58,920 --> 00:09:01,560 more deeply on how to find these different behaviors. 183 00:09:02,020 --> 00:09:05,900 Okay, back in 2004, Cameron Hopkins 184 00:09:05,900 --> 00:09:09,360 delivered a very good presentation at Black Hat. 185 00:09:09,640 --> 00:09:10,740 Let me go here. 186 00:09:10,740 --> 00:09:13,300 And title, 187 00:09:14,480 --> 00:09:15,640 Blind Attacks, 188 00:09:16,480 --> 00:09:20,140 How to Automate Blind Attacks Against a Web Application. 189 00:09:20,560 --> 00:09:23,500 In it, he described many methods 190 00:09:23,500 --> 00:09:29,960 on how to look for these different web page behaviors. 191 00:09:30,360 --> 00:09:34,380 So he used methods using different hatches, 192 00:09:34,420 --> 00:09:38,080 using different HTML structures, 193 00:09:38,080 --> 00:09:40,740 using different patterns, 194 00:09:41,060 --> 00:09:46,060 and even using different linear ASTI sums, okay? 195 00:09:46,300 --> 00:09:48,280 Before that, in 2002, 196 00:09:51,080 --> 00:09:56,060 Chris Hanley published a very famous paper 197 00:09:56,060 --> 00:10:00,180 called More Advanced SQL Injection, 198 00:10:00,200 --> 00:10:03,160 a paper in which he described 199 00:10:03,160 --> 00:10:06,280 how to use a time response 200 00:10:06,280 --> 00:10:09,880 to look for difference in the behavior 201 00:10:09,880 --> 00:10:13,460 of the web pages, okay? 202 00:10:13,900 --> 00:10:19,660 And finally, let me tell you about how to construct 203 00:10:19,660 --> 00:10:25,040 or how these queries are constructed really quickly, okay? 204 00:10:25,640 --> 00:10:27,380 So once we've got difference behavior, 205 00:10:27,700 --> 00:10:30,400 what to do is to construct the query to extract the data. 206 00:10:30,800 --> 00:10:33,040 Okay, normally we use conditional operators, 207 00:10:33,680 --> 00:10:35,980 greater than, lesser than, equals to. 208 00:10:35,980 --> 00:10:38,720 Et cetera, to compare the value 209 00:10:38,720 --> 00:10:40,540 that we want to extract from the database 210 00:10:40,540 --> 00:10:41,800 against a fixed value. 211 00:10:42,200 --> 00:10:44,540 We, depending on the response that we get, 212 00:10:44,620 --> 00:10:45,940 if it's false or true response, 213 00:10:46,220 --> 00:10:48,860 then we will change that fixed value, all right, 214 00:10:48,940 --> 00:10:50,240 and iterate that process 215 00:10:50,240 --> 00:10:54,360 until we find out the correct value. 216 00:10:54,720 --> 00:10:56,960 In the example that you have in the slide, 217 00:10:57,160 --> 00:11:02,000 you have an example to find the ASTI value 218 00:11:02,000 --> 00:11:03,680 for the first letter 219 00:11:03,680 --> 00:11:11,020 of the first user name in a database. 220 00:11:11,300 --> 00:11:14,060 The example is for my SQL server, 221 00:11:14,400 --> 00:11:16,780 MS SQL server, and Oracle database. 222 00:11:17,280 --> 00:11:18,340 At the end of the process, 223 00:11:18,460 --> 00:11:19,640 and at the end of all the iterations, 224 00:11:19,920 --> 00:11:25,880 you are able to get all the complete user name, okay? 225 00:11:27,200 --> 00:11:28,820 Well, as you can imagine, 226 00:11:28,920 --> 00:11:30,540 this is a tough task to do manually. 227 00:11:31,000 --> 00:11:32,440 So last year, 228 00:11:32,440 --> 00:11:34,700 many tools have been developed, 229 00:11:34,900 --> 00:11:36,220 and right now, 230 00:11:36,280 --> 00:11:37,980 there are a lot of tools in the internet 231 00:11:37,980 --> 00:11:39,680 to perform these kind of attacks. 232 00:11:40,000 --> 00:11:42,760 This one is SQL BF Tools. 233 00:11:43,320 --> 00:11:46,160 There are several tools in this package, 234 00:11:46,360 --> 00:11:50,360 and it's focused in MySQL databases. 235 00:11:50,780 --> 00:11:53,520 This tool is able to extract all the database structure, 236 00:11:53,920 --> 00:11:55,520 all the data in tables, 237 00:11:55,660 --> 00:11:57,260 all the values of variables, 238 00:11:57,560 --> 00:12:00,760 and also it's possible to extract files from the server 239 00:12:00,760 --> 00:12:02,280 because this tool uses 240 00:12:02,440 --> 00:12:03,980 the load file function 241 00:12:03,980 --> 00:12:07,600 that allows MySQL to load files from the server. 242 00:12:07,760 --> 00:12:09,220 So it's possible to extract, for instance, 243 00:12:09,460 --> 00:12:12,320 using Blind SQL at injection attack, 244 00:12:12,540 --> 00:12:14,760 the password file or the init file 245 00:12:14,760 --> 00:12:16,400 or whatever in the server. 246 00:12:16,660 --> 00:12:19,520 This tool only uses keyboard searching, 247 00:12:19,740 --> 00:12:23,340 so it's only for one of the methods 248 00:12:23,340 --> 00:12:24,660 that Cameron Hotkey described. 249 00:12:25,360 --> 00:12:28,240 And if we are talking about tools 250 00:12:28,240 --> 00:12:29,320 for Blind SQL injection, 251 00:12:29,580 --> 00:12:31,560 it's impossible to forget AppSynt. 252 00:12:31,560 --> 00:12:34,880 AppSynt is based on the principles 253 00:12:34,880 --> 00:12:36,520 described by Cameron Hotkey, 254 00:12:36,660 --> 00:12:40,280 and it's one of the most powerful tools 255 00:12:40,280 --> 00:12:41,960 and a well-ended tool 256 00:12:41,960 --> 00:12:44,840 to perform a Blind SQL injection attack. 257 00:12:45,180 --> 00:12:46,820 This tool is ready to work 258 00:12:46,820 --> 00:12:49,500 with Microsoft SQL Server, PostgreSQL, 259 00:12:49,880 --> 00:12:50,760 Sybase, and Oracle, 260 00:12:51,040 --> 00:12:53,400 and as you can see in this screenshot, 261 00:12:53,660 --> 00:12:56,400 it's possible to work with get and post parameter, 262 00:12:56,700 --> 00:12:58,860 with cookies, with HTTP connection 263 00:12:58,860 --> 00:13:00,820 and HTTP S connection. 264 00:13:00,820 --> 00:13:03,260 This tool should be initialized 265 00:13:03,260 --> 00:13:07,120 and is going to throw some always true injection 266 00:13:07,120 --> 00:13:08,400 and always false injection, 267 00:13:08,660 --> 00:13:10,680 and after that, it's possible to extract 268 00:13:10,680 --> 00:13:13,120 all the database structure, the username 269 00:13:13,120 --> 00:13:15,040 that the web application is using 270 00:13:15,040 --> 00:13:16,400 to connect against the database, 271 00:13:16,740 --> 00:13:19,380 the tables, and of course all the data 272 00:13:19,380 --> 00:13:22,900 that could be sport in XML files. 273 00:13:23,260 --> 00:13:25,340 This tool is not ready to work with 274 00:13:25,340 --> 00:13:27,240 time-based Blind SQL injection attacks, 275 00:13:27,460 --> 00:13:29,200 and if you want, you have to perform 276 00:13:29,200 --> 00:13:30,520 one of these tests, you need to 277 00:13:30,820 --> 00:13:32,240 use other tools. 278 00:13:32,760 --> 00:13:34,260 In some scenarios, 279 00:13:34,540 --> 00:13:37,240 in which it's possible to inject code, 280 00:13:37,400 --> 00:13:38,420 but there is no difference 281 00:13:38,420 --> 00:13:40,280 between the true answer page 282 00:13:40,280 --> 00:13:41,780 and the false answer page, 283 00:13:42,460 --> 00:13:44,540 time-based behavior should be used. 284 00:13:44,880 --> 00:13:45,500 In those scenarios, 285 00:13:46,380 --> 00:13:48,600 we can use the time delay function 286 00:13:48,600 --> 00:13:51,860 in the database to delay the answer. 287 00:13:52,200 --> 00:13:52,960 So for instance, 288 00:13:53,280 --> 00:13:55,440 in Microsoft SQL Server, 289 00:13:55,540 --> 00:13:56,840 we can use the wait for function 290 00:13:56,840 --> 00:13:59,080 to delay the answer 291 00:13:59,080 --> 00:14:01,300 if the condition is true, 292 00:14:01,440 --> 00:14:04,260 so when the condition will be true, 293 00:14:04,400 --> 00:14:06,200 we will have a delay, 294 00:14:06,420 --> 00:14:08,420 if not, we are going to have a quicker answer. 295 00:14:08,940 --> 00:14:10,620 We can do something similar 296 00:14:10,620 --> 00:14:11,580 in Oracle databases, 297 00:14:11,840 --> 00:14:13,500 but in Oracle, we have to use 298 00:14:13,500 --> 00:14:16,000 a package in PL SQL language. 299 00:14:16,220 --> 00:14:17,360 This package is called 300 00:14:18,600 --> 00:14:19,600 dbms-log, 301 00:14:19,780 --> 00:14:21,660 and the function is called sleep, 302 00:14:21,840 --> 00:14:23,640 but if you want to use this function, 303 00:14:23,920 --> 00:14:25,560 you have to inject code 304 00:14:25,900 --> 00:14:27,500 in a PL SQL procedure, 305 00:14:27,500 --> 00:14:29,600 and it's a little bit complicated 306 00:14:29,600 --> 00:14:31,060 to find an environment 307 00:14:31,060 --> 00:14:33,700 where to inject code in a PL SQL procedure. 308 00:14:34,220 --> 00:14:36,000 In MySQL, we have two options. 309 00:14:36,400 --> 00:14:38,320 One of them is the sleep function, 310 00:14:38,560 --> 00:14:41,080 that it comes along with the version 5 311 00:14:41,080 --> 00:14:43,040 and the version 6 of this database, 312 00:14:43,260 --> 00:14:44,560 and the benchmark function. 313 00:14:44,860 --> 00:14:46,200 The benchmark function is 314 00:14:46,200 --> 00:14:48,180 a special function 315 00:14:48,180 --> 00:14:50,280 that forces the database 316 00:14:50,280 --> 00:14:51,980 to work a lot of time, 317 00:14:52,140 --> 00:14:54,440 so depending on the parameter set 318 00:14:54,440 --> 00:14:55,260 with this function, 319 00:14:55,260 --> 00:14:57,100 we can measure six, 320 00:14:57,460 --> 00:14:59,020 20, or 30 seconds 321 00:14:59,020 --> 00:15:00,720 that we can use to analyze 322 00:15:00,720 --> 00:15:02,560 a true or a false behavior. 323 00:15:03,080 --> 00:15:04,940 In this example, you have 324 00:15:04,940 --> 00:15:07,600 the injection for Microsoft SQL Server. 325 00:15:08,120 --> 00:15:09,700 This injection is used 326 00:15:09,700 --> 00:15:11,000 in the wait for function, 327 00:15:11,260 --> 00:15:13,400 and the database 328 00:15:13,400 --> 00:15:15,100 will stop by a second 329 00:15:15,100 --> 00:15:17,260 if the condition, in this case, 330 00:15:17,280 --> 00:15:19,520 exceeds select asterisk from user, 331 00:15:19,780 --> 00:15:21,020 retrieve any data. 332 00:15:21,480 --> 00:15:22,340 If you are interested 333 00:15:22,340 --> 00:15:23,940 in this topic, 334 00:15:23,940 --> 00:15:25,300 last year here in DEF CON, 335 00:15:25,460 --> 00:15:26,860 people from Sense Post 336 00:15:27,480 --> 00:15:29,320 delivered a very nice presentation 337 00:15:29,940 --> 00:15:31,780 to tell it's all about the time, 338 00:15:31,920 --> 00:15:33,840 and they have a very nice paper 339 00:15:33,840 --> 00:15:34,580 on the internet, 340 00:15:34,680 --> 00:15:36,240 and you can grab it when you want. 341 00:15:37,840 --> 00:15:40,220 And this is an example 342 00:15:40,220 --> 00:15:41,260 in the real world. 343 00:15:41,600 --> 00:15:42,520 This is an exploit 344 00:15:44,940 --> 00:15:46,240 published last year 345 00:15:46,240 --> 00:15:47,840 in Millworm Web Security. 346 00:15:48,040 --> 00:15:49,060 This is an exploit for 347 00:15:51,000 --> 00:15:52,040 SolarEmpire WebGain. 348 00:15:52,160 --> 00:15:53,040 As you can see, 349 00:15:53,120 --> 00:15:53,840 some people 350 00:15:53,940 --> 00:15:54,760 cannot stand losing. 351 00:15:55,500 --> 00:15:58,420 And this is not 352 00:15:58,420 --> 00:15:59,260 the entire exploit. 353 00:15:59,500 --> 00:16:00,900 You can look for the entire exploit 354 00:16:00,900 --> 00:16:02,220 on the website, 355 00:16:02,440 --> 00:16:03,280 and you have the URL 356 00:16:03,280 --> 00:16:04,100 in the white paper 357 00:16:04,100 --> 00:16:04,900 you have in the CD. 358 00:16:05,220 --> 00:16:06,700 And this exploit 359 00:16:06,700 --> 00:16:07,960 has two parts. 360 00:16:08,120 --> 00:16:09,840 In red color 361 00:16:09,840 --> 00:16:12,100 is the time measuring, 362 00:16:12,360 --> 00:16:13,420 and in blue color 363 00:16:13,420 --> 00:16:13,980 is the injection. 364 00:16:14,340 --> 00:16:15,160 As you can see, 365 00:16:15,240 --> 00:16:15,740 in this case, 366 00:16:15,800 --> 00:16:17,540 the injection takes place 367 00:16:17,540 --> 00:16:20,340 in the user agent parameter 368 00:16:20,340 --> 00:16:21,920 of the HTTP header, 369 00:16:22,040 --> 00:16:23,460 and it's injecting 370 00:16:23,460 --> 00:16:26,420 a benchmark function 371 00:16:26,420 --> 00:16:27,620 that delays, 372 00:16:27,780 --> 00:16:28,860 force the database 373 00:16:28,860 --> 00:16:29,740 to delay 374 00:16:29,740 --> 00:16:31,260 more than seven seconds. 375 00:16:31,600 --> 00:16:32,820 So at the beginning, 376 00:16:32,960 --> 00:16:34,740 the exploit takes a timestamp. 377 00:16:34,940 --> 00:16:36,760 Then after sending the package, 378 00:16:37,000 --> 00:16:39,460 it takes another timestamp 379 00:16:39,460 --> 00:16:41,560 and compares both. 380 00:16:41,800 --> 00:16:42,580 And if difference 381 00:16:42,580 --> 00:16:44,600 is greater than seven, 382 00:16:44,700 --> 00:16:45,880 then it means 383 00:16:45,880 --> 00:16:46,880 that that letter 384 00:16:46,880 --> 00:16:49,160 who had been tried out 385 00:16:49,160 --> 00:16:51,220 is part of the password. 386 00:16:51,640 --> 00:16:52,800 It's cool, no? 387 00:16:55,480 --> 00:16:56,200 Okay. 388 00:16:56,920 --> 00:16:58,360 Here in the screenshot, 389 00:16:58,680 --> 00:17:02,120 you have another tool, 390 00:17:02,300 --> 00:17:03,440 an example of a tool 391 00:17:03,440 --> 00:17:06,160 to automate a time-based method 392 00:17:06,480 --> 00:17:09,400 to perform a SQL injection attack. 393 00:17:09,740 --> 00:17:11,840 The tool is called SQL Ninja. 394 00:17:12,460 --> 00:17:15,340 It uses the wait for function 395 00:17:15,340 --> 00:17:17,020 described by Chris Handley, 396 00:17:17,160 --> 00:17:21,280 and is ready to extract data 397 00:17:21,280 --> 00:17:24,400 out from a Microsoft SQL database 398 00:17:24,400 --> 00:17:25,500 that is behind 399 00:17:25,500 --> 00:17:27,660 a vulnerable web application. 400 00:17:29,480 --> 00:17:32,120 Well, until here, 401 00:17:32,320 --> 00:17:35,120 you probably knew all this, okay? 402 00:17:35,280 --> 00:17:36,660 It's not new stuff. 403 00:17:36,880 --> 00:17:37,620 If you've been following 404 00:17:38,320 --> 00:17:40,080 SQL injection techniques 405 00:17:40,080 --> 00:17:41,920 for the last five, six, seven years, 406 00:17:42,120 --> 00:17:44,260 you probably knew all that, okay? 407 00:17:44,340 --> 00:17:45,460 It was just a quick summary. 408 00:17:45,680 --> 00:17:47,340 But what happens in environments 409 00:17:47,920 --> 00:17:49,480 where we can inject code, 410 00:17:49,480 --> 00:17:53,620 but we don't get any different behavior 411 00:17:53,620 --> 00:17:56,420 in the web page response, okay? 412 00:17:56,580 --> 00:17:58,440 Then, normally, 413 00:17:58,640 --> 00:17:59,580 what we will use 414 00:17:59,580 --> 00:18:00,900 is what Chema just explained. 415 00:18:01,160 --> 00:18:03,960 We'll use time delays 416 00:18:04,820 --> 00:18:07,760 to perform the attack, okay? 417 00:18:07,960 --> 00:18:10,260 But what happens 418 00:18:10,260 --> 00:18:13,380 if behind that vulnerable web application, 419 00:18:13,600 --> 00:18:14,980 what we got is a database 420 00:18:14,980 --> 00:18:17,880 with no time delay functions, okay? 421 00:18:18,000 --> 00:18:19,140 We can have a database 422 00:18:19,140 --> 00:18:21,760 such as DB2, Microsoft Access, 423 00:18:22,360 --> 00:18:24,120 or even an Oracle database 424 00:18:24,120 --> 00:18:26,560 where we are not able to inject code 425 00:18:26,560 --> 00:18:30,840 in the PL SQL function, okay? 426 00:18:31,460 --> 00:18:33,240 Do you think it will be possible 427 00:18:33,240 --> 00:18:36,100 to continue our attack 428 00:18:36,100 --> 00:18:37,220 and extract information 429 00:18:37,220 --> 00:18:38,620 in an environment like that? 430 00:18:39,040 --> 00:18:39,960 Okay, how many? 431 00:18:42,360 --> 00:18:42,920 Okay. 432 00:18:44,340 --> 00:18:45,140 Not many. 433 00:18:45,360 --> 00:18:47,940 Well, we are here to explain that, okay? 434 00:18:47,940 --> 00:18:49,660 That we are able... 435 00:18:52,160 --> 00:18:53,220 Let's finish our presentation. 436 00:18:53,580 --> 00:18:54,240 Let's pack and go. 437 00:18:54,500 --> 00:18:54,740 Okay. 438 00:18:55,640 --> 00:18:56,640 If it was impossible, 439 00:18:56,960 --> 00:18:57,840 we wouldn't be here, okay? 440 00:18:57,880 --> 00:18:59,680 We are here to explain 441 00:18:59,680 --> 00:19:01,060 how it's possible 442 00:19:01,060 --> 00:19:02,460 in an environment like that 443 00:19:02,460 --> 00:19:04,340 to extract some data. 444 00:19:04,500 --> 00:19:05,020 So please, Chema, 445 00:19:05,160 --> 00:19:07,040 introduce us to this new topic. 446 00:19:08,320 --> 00:19:09,400 Just shouldn't have drank 447 00:19:09,400 --> 00:19:10,440 so much whiskey yesterday. 448 00:19:10,920 --> 00:19:11,400 Well. 449 00:19:12,360 --> 00:19:14,780 Well, before to know how to do this, 450 00:19:14,860 --> 00:19:16,240 we are going to analyze 451 00:19:16,240 --> 00:19:18,480 how a SQL query 452 00:19:19,400 --> 00:19:22,560 will be executing a database engine. 453 00:19:22,820 --> 00:19:24,260 Let's suppose this query 454 00:19:24,260 --> 00:19:26,280 with more than one condition, 455 00:19:26,460 --> 00:19:27,800 in this case with two conditions, 456 00:19:28,060 --> 00:19:30,720 and they are joined with an end operator. 457 00:19:31,460 --> 00:19:33,460 Let's suppose that the first condition, 458 00:19:33,540 --> 00:19:36,360 condition one, lasts 10 seconds, 459 00:19:36,460 --> 00:19:38,900 and the second takes 100 seconds 460 00:19:38,900 --> 00:19:41,280 to be executed in the database engine. 461 00:19:41,760 --> 00:19:43,100 So the question are, 462 00:19:43,240 --> 00:19:46,060 which condition should be executed first, 463 00:19:46,240 --> 00:19:48,960 and which condition will be executed first 464 00:19:48,960 --> 00:19:50,840 in the database we are analyzing? 465 00:19:51,380 --> 00:19:51,860 Well. 466 00:19:52,480 --> 00:19:53,480 To know this, 467 00:19:53,620 --> 00:19:55,240 let's have a look at the table, 468 00:19:55,660 --> 00:19:57,480 and let's suppose that the heavy condition 469 00:19:57,480 --> 00:19:59,120 is executed in first place. 470 00:19:59,700 --> 00:20:00,540 As you can see, 471 00:20:01,340 --> 00:20:04,840 the worst condition is executed in all the cases, 472 00:20:04,980 --> 00:20:06,700 so in all the cases, 473 00:20:06,780 --> 00:20:09,160 we obtain a very bad performance 474 00:20:09,160 --> 00:20:10,420 in the response time 475 00:20:10,420 --> 00:20:14,260 because the heavy query will be executed. 476 00:20:14,520 --> 00:20:16,080 This is a very bad tuning decision 477 00:20:16,240 --> 00:20:19,080 and databases try to avoid this situation. 478 00:20:19,740 --> 00:20:21,040 As you can see, 479 00:20:21,120 --> 00:20:22,720 only when the first one is true, 480 00:20:22,800 --> 00:20:24,640 when the heavy condition is true, 481 00:20:24,740 --> 00:20:27,560 we are going to obtain 110 seconds, 482 00:20:27,640 --> 00:20:31,160 and the difference between the true and the false 483 00:20:31,160 --> 00:20:34,040 with the heavy query is very difficult to measure 484 00:20:34,040 --> 00:20:36,460 because it's not a long time. 485 00:20:37,640 --> 00:20:39,040 On the other hand, 486 00:20:39,100 --> 00:20:42,920 if the light condition is executed in first place, 487 00:20:43,140 --> 00:20:46,220 we are going to obtain a big difference 488 00:20:46,240 --> 00:20:50,800 between the true in the first condition 489 00:20:50,800 --> 00:20:52,600 and the false in the first condition. 490 00:20:52,820 --> 00:20:53,200 I mean, 491 00:20:53,260 --> 00:20:55,240 when the light condition is true, 492 00:20:55,500 --> 00:20:58,060 the heavy condition will be executed, 493 00:20:58,360 --> 00:21:01,260 so we are going to obtain the worst performance. 494 00:21:01,580 --> 00:21:03,920 We are going to obtain a big amount of time. 495 00:21:04,260 --> 00:21:06,860 But if the first condition is false, 496 00:21:07,120 --> 00:21:11,080 it means that the second condition shouldn't be executed, 497 00:21:11,680 --> 00:21:15,240 and then only 10 seconds is going to be executed 498 00:21:15,240 --> 00:21:17,260 is going to be the time. 499 00:21:17,540 --> 00:21:18,420 So in this case, 500 00:21:18,540 --> 00:21:22,200 we have a big difference between the true and the false. 501 00:21:22,700 --> 00:21:26,280 It means if we obtain a long time, 502 00:21:26,520 --> 00:21:29,420 it means the light condition is true, 503 00:21:29,600 --> 00:21:32,000 and if we obtain a short time, 504 00:21:32,180 --> 00:21:33,940 the light condition is false. 505 00:21:34,580 --> 00:21:35,400 With this, 506 00:21:35,520 --> 00:21:37,140 we can construct a binary logic 507 00:21:37,140 --> 00:21:39,320 to extract all the information from a database. 508 00:21:39,600 --> 00:21:41,420 We are going to construct a light query 509 00:21:41,420 --> 00:21:42,620 to extract the data, 510 00:21:42,780 --> 00:21:43,780 and a heavy one 511 00:21:43,780 --> 00:21:45,220 to make a transaction. 512 00:21:45,240 --> 00:21:45,580 This is the time difference. 513 00:21:46,260 --> 00:21:46,900 Okay? 514 00:21:47,020 --> 00:21:50,920 But which condition will be executed first 515 00:21:50,920 --> 00:21:52,740 depending on the database? 516 00:21:53,120 --> 00:21:53,540 Well, 517 00:21:53,620 --> 00:21:54,160 it depends, 518 00:21:54,320 --> 00:21:56,680 because some databases have a special process 519 00:21:56,960 --> 00:21:59,080 before they execute the query. 520 00:21:59,320 --> 00:22:01,520 This process is an optimization process, 521 00:22:01,780 --> 00:22:06,280 and other databases don't have that process. 522 00:22:07,580 --> 00:22:08,220 Okay, 523 00:22:08,300 --> 00:22:10,940 so let me explain a little bit how all this works. 524 00:22:11,380 --> 00:22:11,540 Okay, 525 00:22:11,660 --> 00:22:12,740 as Chema has explained, 526 00:22:12,740 --> 00:22:14,540 enterprise databases, 527 00:22:14,820 --> 00:22:15,980 for performance purpose, 528 00:22:16,300 --> 00:22:19,360 they go through an optimization process 529 00:22:19,360 --> 00:22:21,860 before they execute a work clause. 530 00:22:21,960 --> 00:22:23,840 They try to analyze the conditions 531 00:22:23,840 --> 00:22:25,080 inside the work clause, 532 00:22:25,240 --> 00:22:28,760 so they try to execute first 533 00:22:28,760 --> 00:22:30,460 the conditions that are lighter. 534 00:22:30,880 --> 00:22:30,940 Okay? 535 00:22:33,780 --> 00:22:35,000 First of all, 536 00:22:35,020 --> 00:22:37,200 what they do is they get the statistics, 537 00:22:37,600 --> 00:22:38,400 indexes, 538 00:22:39,220 --> 00:22:41,080 density of values, etc., 539 00:22:41,080 --> 00:22:42,600 and try to find, 540 00:22:42,740 --> 00:22:42,960 and find out 541 00:22:44,440 --> 00:22:47,920 these different costs in the conditions. 542 00:22:48,140 --> 00:22:48,260 Okay? 543 00:22:48,360 --> 00:22:50,760 If they are not able to find any difference, 544 00:22:51,000 --> 00:22:54,340 they go through what is called 545 00:22:54,340 --> 00:22:55,900 a prediction algorithm 546 00:22:55,900 --> 00:23:00,940 and try to find these different costs. 547 00:23:01,200 --> 00:23:04,020 And if they are not able to do it with this method, 548 00:23:04,200 --> 00:23:07,580 then they just behave as default. 549 00:23:07,840 --> 00:23:07,980 Okay? 550 00:23:08,160 --> 00:23:10,120 Depending on the database, 551 00:23:10,120 --> 00:23:14,240 they will evaluate the work clause 552 00:23:14,240 --> 00:23:15,180 from left to right, 553 00:23:15,280 --> 00:23:18,060 or from right to left. 554 00:23:18,280 --> 00:23:20,230 So we got databases like, 555 00:23:20,800 --> 00:23:21,500 for example, 556 00:23:21,520 --> 00:23:22,040 Oracle, 557 00:23:22,300 --> 00:23:27,020 that always execute first the condition 558 00:23:27,020 --> 00:23:28,120 on the right side. 559 00:23:28,340 --> 00:23:28,620 Okay? 560 00:23:28,700 --> 00:23:31,800 So the last condition is the one that is executed first. 561 00:23:32,220 --> 00:23:35,240 Sometimes in this kind of environment, 562 00:23:36,700 --> 00:23:39,380 the performance algorithms make mistakes, 563 00:23:39,380 --> 00:23:41,200 and we may help them 564 00:23:41,200 --> 00:23:43,860 and avoid mistakes 565 00:23:44,220 --> 00:23:50,840 if we introduce little tricks into the work clause. 566 00:23:51,000 --> 00:23:51,100 Okay? 567 00:23:51,200 --> 00:23:53,960 To avoid these kind of problems. 568 00:23:54,560 --> 00:23:55,160 Other... 569 00:23:56,980 --> 00:23:57,660 Okay. 570 00:23:57,920 --> 00:23:58,720 Other databases, 571 00:23:59,060 --> 00:24:01,820 the ones that don't have optimization process, 572 00:24:02,120 --> 00:24:04,040 here is a developer task 573 00:24:04,040 --> 00:24:07,440 to establish which condition will be executed first. 574 00:24:07,700 --> 00:24:07,860 Okay? 575 00:24:07,860 --> 00:24:10,560 Databases such as Microsoft Access 576 00:24:10,560 --> 00:24:12,740 don't have performance optimization. 577 00:24:13,280 --> 00:24:15,580 So the developer must say 578 00:24:15,580 --> 00:24:17,900 which condition will be evaluated first. 579 00:24:18,340 --> 00:24:19,480 At the end, 580 00:24:19,520 --> 00:24:23,340 it is possible to conduct this type of attacks 581 00:24:23,340 --> 00:24:25,680 that we are gonna finish explaining in the next slide 582 00:24:25,680 --> 00:24:30,100 in any type of database engine. 583 00:24:30,400 --> 00:24:30,540 Okay? 584 00:24:30,640 --> 00:24:32,640 But we have to know 585 00:24:32,640 --> 00:24:37,260 which behavior the database is following 586 00:24:37,260 --> 00:24:40,660 to evaluate the conditions. 587 00:24:41,120 --> 00:24:41,560 Okay? 588 00:24:42,000 --> 00:24:42,600 Okay. 589 00:24:42,800 --> 00:24:45,060 Well, and we know 590 00:24:45,060 --> 00:24:47,040 that we can extract all the data 591 00:24:47,040 --> 00:24:49,120 with a light, with a heavy condition, 592 00:24:49,360 --> 00:24:50,960 and the last thing is how 593 00:24:50,960 --> 00:24:53,020 a heavy condition should be constructed. 594 00:24:53,560 --> 00:24:55,500 Well, the trick is very easy. 595 00:24:55,600 --> 00:24:57,480 We can use a very big cross-joint 596 00:24:57,480 --> 00:24:59,660 between a table and crossing itself 597 00:24:59,660 --> 00:25:01,780 as many times as we need 598 00:25:01,780 --> 00:25:05,520 just to cross records in memory 599 00:25:05,520 --> 00:25:06,240 and make... 600 00:25:06,240 --> 00:25:09,580 make the database work a lot of time. 601 00:25:09,940 --> 00:25:11,460 So in this example, 602 00:25:11,560 --> 00:25:12,160 as you can see, 603 00:25:12,280 --> 00:25:14,500 we are using the C user table 604 00:25:14,500 --> 00:25:18,780 and we are crossing this table eight times with itself 605 00:25:18,780 --> 00:25:21,680 and constructing a big query, 606 00:25:22,340 --> 00:25:24,300 big amount of data in memory, 607 00:25:24,700 --> 00:25:26,960 and as you can see, 608 00:25:27,100 --> 00:25:30,400 the light condition is just an always true condition 609 00:25:30,400 --> 00:25:32,620 because we are comparing the first letter of the... 610 00:25:32,620 --> 00:25:33,320 the value... 611 00:25:33,320 --> 00:25:35,260 the actual value of the first letter of the user name 612 00:25:35,260 --> 00:25:36,180 with 300, 613 00:25:36,400 --> 00:25:38,240 and all you know that it's true. 614 00:25:38,500 --> 00:25:39,220 Isn't it? 615 00:25:39,400 --> 00:25:39,420 Huh? 616 00:25:39,800 --> 00:25:40,020 Huh? 617 00:25:40,260 --> 00:25:40,820 Okay. 618 00:25:41,460 --> 00:25:42,020 Well, 619 00:25:43,000 --> 00:25:44,440 to construct heavy queries 620 00:25:44,440 --> 00:25:46,340 in different types of databases, 621 00:25:46,500 --> 00:25:48,140 we can use the normal tables. 622 00:25:48,400 --> 00:25:48,800 For instance, 623 00:25:48,940 --> 00:25:49,720 in SQL databases, 624 00:25:50,080 --> 00:25:52,160 Microsoft SQL Server databases, 625 00:25:52,280 --> 00:25:54,900 we can use the data dictionary tables. 626 00:25:55,160 --> 00:25:55,720 For instance, 627 00:25:55,920 --> 00:25:59,360 C user or C subjects or C files 628 00:25:59,360 --> 00:26:00,520 or whatever you want. 629 00:26:00,780 --> 00:26:01,500 In Oracle, 630 00:26:01,860 --> 00:26:03,940 the public views are very useful 631 00:26:03,940 --> 00:26:04,780 for this... 632 00:26:05,260 --> 00:26:05,900 for this attack. 633 00:26:06,160 --> 00:26:06,900 For instance, 634 00:26:07,020 --> 00:26:07,480 all user, 635 00:26:07,680 --> 00:26:08,320 all objects, 636 00:26:08,440 --> 00:26:09,540 or whatever you want. 637 00:26:09,860 --> 00:26:10,600 In MySQL, 638 00:26:10,800 --> 00:26:12,000 version five and six, 639 00:26:12,020 --> 00:26:13,780 we can use the schema tables. 640 00:26:14,280 --> 00:26:15,980 And in Microsoft Access, 641 00:26:16,140 --> 00:26:17,120 we can use the... 642 00:26:17,120 --> 00:26:18,360 the tables. 643 00:26:19,020 --> 00:26:20,000 Depending on the version, 644 00:26:20,220 --> 00:26:22,280 we can use msys-access-objects 645 00:26:22,280 --> 00:26:23,880 or msys-access-storage. 646 00:26:24,440 --> 00:26:26,820 Ispa is always... 647 00:26:26,820 --> 00:26:28,400 in access databases, 648 00:26:28,600 --> 00:26:31,940 we always have access privilege to these tables. 649 00:26:32,220 --> 00:26:32,680 So, 650 00:26:32,740 --> 00:26:33,260 we... 651 00:26:33,260 --> 00:26:34,220 these tables always... 652 00:26:35,260 --> 00:26:35,820 we can use it. 653 00:26:36,280 --> 00:26:37,200 And if not, 654 00:26:37,400 --> 00:26:39,720 if we don't have any table 655 00:26:39,720 --> 00:26:42,140 and we don't have access privilege 656 00:26:42,140 --> 00:26:43,920 to any of these tables, 657 00:26:44,140 --> 00:26:44,240 well, 658 00:26:44,340 --> 00:26:46,480 I suppose you can guess any table 659 00:26:46,480 --> 00:26:47,740 in the databases. 660 00:26:48,040 --> 00:26:50,020 You can use the common suspects 661 00:26:50,020 --> 00:26:51,100 like clients, 662 00:26:51,340 --> 00:26:51,640 customers, 663 00:26:51,980 --> 00:26:52,120 news, 664 00:26:52,320 --> 00:26:52,780 logins, 665 00:26:52,800 --> 00:26:53,020 user, 666 00:26:53,260 --> 00:26:53,600 providers, 667 00:26:53,800 --> 00:26:54,540 or whatever. 668 00:26:54,960 --> 00:26:57,640 And I'm sure you can imagine one of these. 669 00:26:57,800 --> 00:26:58,100 If not, 670 00:26:58,180 --> 00:26:59,020 you shouldn't be here. 671 00:27:00,700 --> 00:27:01,220 Well, 672 00:27:01,420 --> 00:27:04,420 and now we are going to do very... 673 00:27:04,420 --> 00:27:04,620 an... 674 00:27:05,280 --> 00:27:06,260 an strange demo 675 00:27:06,260 --> 00:27:08,900 because this demo is working over Windows Vista. 676 00:27:12,140 --> 00:27:14,660 And our virtual PC is the worst environment. 677 00:27:14,960 --> 00:27:15,900 So, can you imagine? 678 00:27:16,140 --> 00:27:18,280 Well, we have... 679 00:27:18,280 --> 00:27:20,040 Hey, stop. 680 00:27:21,140 --> 00:27:22,380 We have... 681 00:27:22,380 --> 00:27:23,860 in our testing environment, 682 00:27:24,080 --> 00:27:25,460 we have this application. 683 00:27:25,700 --> 00:27:28,840 This application has four databases. 684 00:27:29,300 --> 00:27:31,140 First one is SQL Server 2005. 685 00:27:31,800 --> 00:27:33,860 The second one is Oracle 10G. 686 00:27:33,860 --> 00:27:36,680 Access 2000 and Access 2007. 687 00:27:37,180 --> 00:27:39,140 The first part of the application 688 00:27:39,860 --> 00:27:42,160 is a normal application 689 00:27:42,160 --> 00:27:45,120 in which we can apply the keyword sets 690 00:27:45,120 --> 00:27:46,200 for blind attacks. 691 00:27:46,400 --> 00:27:48,700 So, we can try with n equals to 1 692 00:27:48,700 --> 00:27:51,120 and we receive this test. 693 00:27:52,100 --> 00:27:53,080 As you see. 694 00:27:53,200 --> 00:27:53,440 Oh. 695 00:27:53,780 --> 00:27:57,800 And if we inject an always false injection, 696 00:27:58,100 --> 00:27:59,440 we obtain nothing. 697 00:27:59,760 --> 00:28:00,320 Okay? 698 00:28:00,480 --> 00:28:02,820 Well, in this other environment, 699 00:28:03,040 --> 00:28:03,700 it's... 700 00:28:03,860 --> 00:28:07,040 not possible to obtain this 701 00:28:07,040 --> 00:28:09,920 because no matter what we inject, 702 00:28:10,160 --> 00:28:11,580 we always obtain the same... 703 00:28:11,580 --> 00:28:12,540 the same result. 704 00:28:12,880 --> 00:28:15,520 This is just because if any error occurs, 705 00:28:15,800 --> 00:28:19,120 the developer give us a default result. 706 00:28:19,440 --> 00:28:20,940 In this case, it's the same result. 707 00:28:21,380 --> 00:28:22,460 So, in this case, 708 00:28:22,540 --> 00:28:24,820 we can try with the wait for method. 709 00:28:25,160 --> 00:28:27,300 And we can try, for instance, 710 00:28:27,420 --> 00:28:29,800 with the wait for method. 711 00:28:31,720 --> 00:28:32,620 This one. 712 00:28:32,620 --> 00:28:33,600 This one. 713 00:28:33,600 --> 00:28:34,140 This one. 714 00:28:34,400 --> 00:28:34,860 Okay. 715 00:28:34,960 --> 00:28:35,580 In this case, 716 00:28:35,660 --> 00:28:38,300 we are going to use the wait for function 717 00:28:38,300 --> 00:28:39,400 in SQL Server. 718 00:28:42,220 --> 00:28:44,340 And if the condition is true, 719 00:28:44,500 --> 00:28:47,520 the database is going to stop for five seconds. 720 00:28:47,680 --> 00:28:50,880 This demo only works if we count in Spanish. 721 00:28:53,200 --> 00:28:54,020 One, two. 722 00:28:54,240 --> 00:28:54,760 What? 723 00:28:55,380 --> 00:28:55,980 I told you. 724 00:28:57,800 --> 00:28:58,460 I'm sorry. 725 00:28:58,580 --> 00:28:59,400 If not, exit. 726 00:28:59,560 --> 00:29:00,300 If exit. 727 00:29:03,100 --> 00:29:07,360 Uno, dos, tres, cuatro, cinco. 728 00:29:07,620 --> 00:29:08,200 Okay, perfect. 729 00:29:08,520 --> 00:29:11,940 And if we change the condition from exit to not exit, 730 00:29:12,220 --> 00:29:13,920 we obtain a quicker answer. 731 00:29:14,200 --> 00:29:14,380 Okay? 732 00:29:14,560 --> 00:29:18,120 But if we have an access to this function, 733 00:29:18,420 --> 00:29:21,960 we can use our method with heavy queries. 734 00:29:22,040 --> 00:29:22,760 In this case, 735 00:29:23,620 --> 00:29:27,920 we are going to perform a time delay 736 00:29:27,920 --> 00:29:32,240 using seven times the same table. 737 00:29:32,620 --> 00:29:33,260 In this case, 738 00:29:33,320 --> 00:29:37,680 the sys user table. 739 00:29:38,040 --> 00:29:38,820 As you can see, 740 00:29:38,920 --> 00:29:40,640 we use sys user as t1, 741 00:29:41,000 --> 00:29:42,220 sys user as t2, 742 00:29:42,380 --> 00:29:43,520 sys user as t3, 743 00:29:43,600 --> 00:29:44,840 and sys user as t7. 744 00:29:45,140 --> 00:29:45,500 Okay? 745 00:29:45,640 --> 00:29:48,940 And this condition will only be executed 746 00:29:48,940 --> 00:29:50,340 if the like condition, 747 00:29:50,600 --> 00:29:51,240 in this case, 748 00:29:51,300 --> 00:29:54,760 select count asterisk from sys user, 749 00:29:55,720 --> 00:29:57,100 retrieve any data. 750 00:29:57,380 --> 00:29:57,900 Okay? 751 00:29:58,580 --> 00:29:59,140 Understood? 752 00:29:59,820 --> 00:30:00,380 Well. 753 00:30:00,540 --> 00:30:00,780 Yes. 754 00:30:01,000 --> 00:30:01,200 Yes. 755 00:30:04,180 --> 00:30:08,700 Let's copy and let's paste in the web browser, 756 00:30:09,520 --> 00:30:11,240 Internet Explorer web browser. 757 00:30:12,620 --> 00:30:13,260 Wonderful. 758 00:30:15,040 --> 00:30:15,680 Everything? 759 00:30:16,020 --> 00:30:16,280 Okay. 760 00:30:16,740 --> 00:30:21,080 One, two, tres, cuatro, cinco. 761 00:30:21,540 --> 00:30:22,880 I don't want any problems. 762 00:30:23,240 --> 00:30:26,460 Well, we cannot set up the time delay, 763 00:30:26,680 --> 00:30:28,880 but we can measure time delay, 764 00:30:28,980 --> 00:30:29,540 and as you can see. 765 00:30:29,680 --> 00:30:30,000 Okay? 766 00:30:30,780 --> 00:30:34,200 We can perform the same with Oracle Database. 767 00:30:35,400 --> 00:30:40,100 And to answer, in this case, with all users table. 768 00:30:44,460 --> 00:30:51,760 Okay, copy the URL. 769 00:30:53,400 --> 00:30:54,300 Look them up. 770 00:30:55,600 --> 00:30:56,220 Paste. 771 00:30:56,520 --> 00:30:58,780 Well, in this case, it's the same trick. 772 00:30:58,780 --> 00:31:02,320 In this query, we are using all users table, 773 00:31:02,600 --> 00:31:05,380 as the one, as the two, as the three, ta-da. 774 00:31:05,740 --> 00:31:10,500 And this query will be execute only if the like condition, 775 00:31:10,780 --> 00:31:11,840 in this case, exceeds, 776 00:31:14,480 --> 00:31:17,460 from exceeds count aesthetics from all user, 777 00:31:17,660 --> 00:31:18,660 retrieve any data. 778 00:31:18,880 --> 00:31:21,440 This will be true, and of course, 779 00:31:21,460 --> 00:31:22,620 the heavy query will be execute. 780 00:31:22,940 --> 00:31:24,120 So, let's start. 781 00:31:25,380 --> 00:31:26,420 One, dos. 782 00:31:31,420 --> 00:31:38,440 Tres, cuatro, cinco, seis, siete, ocho, nueve, come on, Oracle. 783 00:31:39,980 --> 00:31:45,140 Once, doce, trece, catorce, quince, dieciséis. 784 00:31:45,340 --> 00:31:46,380 Could you bring me a coffee? 785 00:31:46,720 --> 00:31:47,520 Oh, perfect. 786 00:31:48,340 --> 00:31:50,460 Well, and if we change the condition, 787 00:31:52,160 --> 00:31:53,060 we obtain. 788 00:31:56,360 --> 00:31:57,960 This is easy for Oracle. 789 00:31:58,780 --> 00:32:03,220 Well, we can perform this with all the databases 790 00:32:03,220 --> 00:32:04,100 you can imagine. 791 00:32:04,380 --> 00:32:08,580 Well, the problem is how can we automate this, 792 00:32:08,760 --> 00:32:12,920 because this is an easy, tough task to do it manually. 793 00:32:13,140 --> 00:32:16,440 So, we can use a tool that we developed. 794 00:32:18,400 --> 00:32:23,840 It's public from yesterday, and the short code is available, 795 00:32:24,460 --> 00:32:28,140 and it's very similar to Absinthe, is this. 796 00:32:28,140 --> 00:32:33,400 And we can try it, for instance, with, 797 00:32:35,020 --> 00:32:36,780 first of all, with SQL Server. 798 00:32:41,260 --> 00:32:42,540 And, let's try. 799 00:32:42,800 --> 00:32:45,380 Well, first of all, we have to set up the URL, 800 00:32:46,080 --> 00:32:50,880 then the parameter ID, the default value, 801 00:32:51,900 --> 00:32:55,220 if the parameter is injectable or not. 802 00:32:55,480 --> 00:32:57,180 And this is the time. 803 00:32:57,920 --> 00:32:58,120 And this is the time. 804 00:32:58,140 --> 00:32:58,300 And we have an option. 805 00:32:58,540 --> 00:33:01,000 In this case, we are working in a local environment, 806 00:33:01,200 --> 00:33:04,300 so we can go faster than in a real environment. 807 00:33:04,720 --> 00:33:12,640 So, with SQL, we can use, for instance, six, one second. 808 00:33:14,460 --> 00:33:15,420 One second. 809 00:33:16,140 --> 00:33:18,260 Well, in the way people you have in the CD, 810 00:33:18,400 --> 00:33:21,380 you have a little explanation of this parameter, 811 00:33:21,580 --> 00:33:23,580 but are very easy to understand. 812 00:33:24,480 --> 00:33:26,660 Well, let's initiate this. 813 00:33:26,660 --> 00:33:32,220 This and let's extract the, and in this case, just the user. 814 00:33:32,540 --> 00:33:36,360 Well, we can see what the application is doing in the log. 815 00:33:36,520 --> 00:33:38,800 First of all, the application is looking for 816 00:33:38,800 --> 00:33:42,200 how many tables I need to construct a heavy query. 817 00:33:42,720 --> 00:33:44,860 In this case, it is going to use, 818 00:33:45,040 --> 00:33:48,540 the application is going to use eight or nine tables. 819 00:33:50,140 --> 00:33:54,420 Okay, and now, once the application has 820 00:33:54,420 --> 00:33:59,200 the number of tables it needs to construct the heavy queries, 821 00:33:59,900 --> 00:34:04,100 it starts to look for the length of the username, 822 00:34:04,340 --> 00:34:08,380 in this case, two, because we have the user 823 00:34:08,380 --> 00:34:12,240 that nobody set up in the SQL Server databases, you know? 824 00:34:12,580 --> 00:34:16,280 Now, the query changed it. 825 00:34:16,640 --> 00:34:20,240 I mean, we are not looking for the length of the username. 826 00:34:20,460 --> 00:34:22,620 We are looking for an axi value, 827 00:34:22,840 --> 00:34:23,760 so we need to 828 00:34:23,760 --> 00:34:25,700 try out a new heavy query, 829 00:34:25,900 --> 00:34:28,460 and now it's looking for a new heavy query. 830 00:34:29,940 --> 00:34:33,000 And when the application has a new heavy query, 831 00:34:33,440 --> 00:34:36,880 it starts looking for the values. 832 00:34:37,620 --> 00:34:39,380 In this case, the system user, 833 00:34:40,190 --> 00:34:43,060 and as you can imagine, the first one is the S. 834 00:34:44,460 --> 00:34:45,860 Can you get the second one? 835 00:34:46,160 --> 00:34:47,620 And the second one is, 836 00:34:48,640 --> 00:34:51,560 well, come on, come on, come on. 837 00:34:53,560 --> 00:34:54,900 Well, it finished. 838 00:34:55,180 --> 00:34:56,440 The second one is the A, 839 00:34:56,700 --> 00:34:59,280 so at the end you can get the system user. 840 00:34:59,680 --> 00:35:02,940 Well, let's do this, but with an access database. 841 00:35:03,260 --> 00:35:05,580 In access, we don't have any time delay function, 842 00:35:05,840 --> 00:35:08,660 so we have to use mandatory this method 843 00:35:08,660 --> 00:35:10,920 if we can extract the information from there. 844 00:35:11,460 --> 00:35:14,880 And we clear the log. 845 00:35:15,860 --> 00:35:16,380 Yes. 846 00:35:16,380 --> 00:35:16,460 Yes. 847 00:35:17,000 --> 00:35:18,760 Do you really want to clear the log? 848 00:35:18,860 --> 00:35:19,040 Si. 849 00:35:19,740 --> 00:35:20,300 Perfect. 850 00:35:25,820 --> 00:35:27,000 I love my country. 851 00:35:27,680 --> 00:35:29,980 Access 2000 and, 2000. 852 00:35:33,060 --> 00:35:36,540 Now we set up access 2000. 853 00:35:39,240 --> 00:35:39,960 The same ID. 854 00:35:40,320 --> 00:35:43,040 Now we are going to use the same parameters, 855 00:35:43,380 --> 00:35:46,360 and as you can see here, we have, uh, 856 00:35:46,360 --> 00:35:46,960 a default table. 857 00:35:47,140 --> 00:35:48,900 In this case, MC is access object, 858 00:35:49,040 --> 00:35:51,400 but we can use whatever we want. 859 00:35:52,460 --> 00:35:54,140 And let's initialize. 860 00:35:54,380 --> 00:35:57,640 And now, the panel changed, 861 00:35:57,960 --> 00:36:02,380 because in access we don't have data dictionary, 862 00:36:02,640 --> 00:36:08,880 so we have to use the table name and the column name. 863 00:36:09,160 --> 00:36:11,440 Well, you can perform a brute force attack 864 00:36:11,440 --> 00:36:13,240 or a dictionary attack looking for table 865 00:36:13,240 --> 00:36:14,780 using the same method, okay? 866 00:36:14,780 --> 00:36:18,100 And we can get the data, okay? 867 00:36:19,340 --> 00:36:20,860 And it's going to perform the same. 868 00:36:21,060 --> 00:36:24,620 In this case, the log has a verbosity level, 869 00:36:24,820 --> 00:36:28,360 so you can set to see a summary, 870 00:36:28,560 --> 00:36:30,080 as we are seeing now, 871 00:36:30,280 --> 00:36:34,640 or we can see all the query that is being thrown in. 872 00:36:34,800 --> 00:36:37,940 So you can see the URL and the whole query 873 00:36:37,940 --> 00:36:41,800 with all the tables and too much information for me 874 00:36:41,800 --> 00:36:42,720 at this time in the morning. 875 00:36:45,780 --> 00:36:50,240 So, now the engine, now the name of, 876 00:36:50,300 --> 00:36:52,680 the number of users in this table is four, 877 00:36:52,880 --> 00:36:55,880 and the application is going to be working 878 00:36:55,880 --> 00:37:00,620 until it extracts all the data. 879 00:37:01,100 --> 00:37:03,020 Let's see the tool working, 880 00:37:03,240 --> 00:37:06,100 and we are going to finish the slides. 881 00:37:10,160 --> 00:37:12,920 Working over Windows Vista, incredible. 882 00:37:18,660 --> 00:37:24,200 Well, in the slide you have all the demos, 883 00:37:24,400 --> 00:37:28,960 but with the WebGet tool, 884 00:37:30,700 --> 00:37:32,820 and you can see all the queries that we are, 885 00:37:33,600 --> 00:37:36,380 that we have thrown against the database. 886 00:37:37,060 --> 00:37:40,680 Well, this is the tool, marathon tool, and conclusion. 887 00:37:41,920 --> 00:37:43,720 Okay, so conclusion's time. 888 00:37:44,780 --> 00:37:46,320 Well, as you have seen, 889 00:37:47,450 --> 00:37:49,960 this method works with any kind of database, 890 00:37:50,200 --> 00:37:51,500 and it doesn't matter if the database 891 00:37:51,870 --> 00:37:54,900 have a delay function or not. 892 00:37:56,260 --> 00:37:58,880 It's not a very quick method, it's slow, 893 00:37:59,040 --> 00:38:01,420 depending on the queries we have to build, 894 00:38:01,620 --> 00:38:04,860 but it's very useful finding vulnerabilities 895 00:38:04,860 --> 00:38:09,020 that are not shown up using other methods. 896 00:38:09,480 --> 00:38:11,000 It's not a silver bullet, 897 00:38:11,180 --> 00:38:12,240 we don't think it's a silver bullet, 898 00:38:12,320 --> 00:38:14,440 but it's just another bullet, 899 00:38:14,440 --> 00:38:18,200 a bullet in your pocket that you can use if you have to. 900 00:38:18,480 --> 00:38:23,480 Okay, so now, we'll leave you here our contact information, 901 00:38:23,700 --> 00:38:25,880 and information about some other people 902 00:38:25,880 --> 00:38:28,680 that have helped us with this presentation, 903 00:38:28,960 --> 00:38:31,640 coding the application, and doing some research. 904 00:38:32,140 --> 00:38:33,880 And we are going to be there, 905 00:38:34,040 --> 00:38:38,040 and we will be in room 104 for questions on this session, 906 00:38:38,300 --> 00:38:42,140 and we'll be heavily enjoying Las Vegas until Sunday. 907 00:38:42,340 --> 00:38:43,840 So, have a nice DevCon. 908 00:38:44,440 --> 00:38:44,540 Thank you all.