1 00:00:02,540 --> 00:00:07,900 web applications that use Oracle databases there are of course prerequisites things you're gonna 2 00:00:07,900 --> 00:00:11,800 have to know a little bit about to be able to get through this presentation and that's going 3 00:00:11,800 --> 00:00:15,200 to be hopefully a little bit of our knowledge about how sequel works I'll show you briefly 4 00:00:15,200 --> 00:00:19,420 but if you know about that that'll probably help you a lot figure out what's going on also if any 5 00:00:19,420 --> 00:00:24,900 of you guys have done you know developed in PHP or JSP or ASP you know a little bit about how 6 00:00:24,900 --> 00:00:30,240 web apps work and how they develop data and how they access databases that'll probably help you 7 00:00:30,240 --> 00:00:35,320 guys a lot for everyone else hopefully I'll do a good job and you'll be able to understand so 8 00:00:35,320 --> 00:00:42,500 we're gonna start out here we're gonna start out here looking at just what a normal web application 9 00:00:42,500 --> 00:00:48,500 looks like I'm also going to note to everyone here that this was all put together and literally the 10 00:00:48,500 --> 00:00:53,680 last like 10 hours I'd like to thank Phil brass over there help me out a lot and other people so 11 00:00:53,680 --> 00:00:54,880 you know this isn't 12 00:00:54,900 --> 00:01:00,080 pretty and this isn't what you're likely to see on major corporation incorporated website or 13 00:01:00,080 --> 00:01:05,140 anything but it will do for our demonstration purposes so everyone's used to seeing stuff like 14 00:01:05,140 --> 00:01:11,400 this here can you guys hear me back there cool all right let's say we know some guys email 15 00:01:11,400 --> 00:01:16,080 address and they have a web application set up that I can get their phone number from the website 16 00:01:16,080 --> 00:01:21,580 for instance again this is all using the sample Oracle presentation data and everything so it's 17 00:01:21,580 --> 00:01:24,460 pretty simple I enter that and I get back 18 00:01:24,900 --> 00:01:29,220 their first name the last name and their phone number what sequel injection is going to allow you 19 00:01:29,220 --> 00:01:33,300 to do is instead of getting back their first name last name and phone number you're going to be 20 00:01:33,300 --> 00:01:41,340 able to actually control what information comes back from the database so the first thing we're 21 00:01:41,340 --> 00:01:47,240 going to look at here is the ASP source code of what we're going to be seeing because that's going 22 00:01:47,240 --> 00:01:50,300 to help us understand it normally of course you're not going to have access to their source 23 00:01:50,300 --> 00:01:54,880 code but here is what we're looking at here is the ASP source code of what we're looking at here 24 00:01:54,900 --> 00:02:03,680 is the line we're interested in select first name last name phone number from employees or email 25 00:02:03,680 --> 00:02:10,740 equals and you see this is the value that gets passed up here in the URI part of the request we 26 00:02:10,740 --> 00:02:17,440 control what that part is and because we control what the value of email is we can change the sequel 27 00:02:17,440 --> 00:02:23,460 statement and make it return different information back from the database other than first name last 28 00:02:24,920 --> 00:02:28,520 name now you're going to run into a lot of sites that are going to stop you from doing this in a 29 00:02:28,520 --> 00:02:33,500 couple ways they're not going to allow you to send characters like spaces or single quotes and those 30 00:02:33,500 --> 00:02:38,220 are the pages that other than a couple tricks that in certain circumstances can let you get 31 00:02:38,220 --> 00:02:42,600 through which I may show you later if we have time those are the pages that are not going to 32 00:02:42,600 --> 00:02:47,400 be vulnerable but I don't know if anyone's who use this technique before probably it's been around 33 00:02:47,400 --> 00:02:53,560 a couple years now but the amount of sites that are vulnerable to this is just enormous I've seen 34 00:02:53,560 --> 00:02:54,460 major you know 35 00:02:55,440 --> 00:03:02,520 communications corporations credit card companies investment banks all kinds of stuff so the first 36 00:03:02,520 --> 00:03:06,240 thing I'm going to do to show you how we're going to change what's getting back to the server is 37 00:03:06,780 --> 00:03:08,920 we're going to throw in a single quote here 38 00:03:17,080 --> 00:03:18,760 assuming this thing will work great 39 00:03:26,140 --> 00:03:27,660 okay um what's me 40 00:03:32,520 --> 00:03:33,420 all right 41 00:03:34,620 --> 00:03:35,840 forget that part 42 00:03:38,520 --> 00:03:41,480 want to try again guys help from the audience 43 00:03:43,440 --> 00:03:49,960 there we go thank you very much what we have here is this is an error message that is come back from 44 00:03:49,960 --> 00:03:54,780 the database server and it says quoted string not properly term at determine a 45 00:03:55,440 --> 00:04:01,300 Let's look at when we sent the value for email, a single quote, what the database server saw. 46 00:04:05,460 --> 00:04:08,140 This is Oracle SQL Plus Terminal. 47 00:04:08,200 --> 00:04:10,880 It's allowing me, normally, again, you wouldn't have access to this. 48 00:04:11,080 --> 00:04:16,340 But for demonstration purposes, to show everyone, it's very helpful for my presentation. 49 00:04:16,860 --> 00:04:23,020 So instead of all the stuff here for email, where it's modifying the source code, we're going to put in that single quote. 50 00:04:24,960 --> 00:04:26,720 So now we're going to see what happens here. 51 00:04:27,220 --> 00:04:28,560 It got sent this line. 52 00:04:28,780 --> 00:04:34,160 Of course, having the three quotes in a row, anyone who's done any programming can tell you that that's not a valid literal value. 53 00:04:34,780 --> 00:04:36,580 So it gave you back this error message. 54 00:04:37,920 --> 00:04:40,060 Now, our goal is to change that. 55 00:04:40,100 --> 00:04:45,980 Instead of using a single quote, put that little injection part to something very useful to be able to manipulate what comes back from the database. 56 00:04:46,760 --> 00:04:49,920 So let's go back and let's look at the web applications we have available. 57 00:04:51,340 --> 00:04:52,660 Here's another simple one. 58 00:04:52,720 --> 00:04:53,360 This is login. 59 00:04:54,140 --> 00:04:54,880 Enter username. 60 00:04:54,900 --> 00:04:55,600 Enter username and password. 61 00:04:56,120 --> 00:05:02,980 Let's change, instead of using an invalid username and password, of course, you get invalid login. 62 00:05:03,440 --> 00:05:08,480 Let's try quote for 1 equals single quote 1. 63 00:05:08,860 --> 00:05:12,000 And we're going to use that for both of these. 64 00:05:12,720 --> 00:05:14,480 I see people laughing about there. 65 00:05:14,520 --> 00:05:16,880 Maybe you've seen how many places this actually works on. 66 00:05:21,220 --> 00:05:23,560 And, of course, as we all know, behind... 67 00:05:24,980 --> 00:05:29,420 Behind each login form, as we all know, exists very sensitive corporate information. 68 00:05:30,660 --> 00:05:33,280 This actually happens to be a WorldCom SEC filing. 69 00:05:37,220 --> 00:05:39,140 So we're going to go back and we're going to look. 70 00:05:39,260 --> 00:05:40,260 We're going to open up. 71 00:05:40,260 --> 00:05:41,480 I'm going to show you the source of the login. 72 00:05:41,660 --> 00:05:49,280 We're going to see exactly what happened that allowed me to just jump right through the login and get to sensitive financial information. 73 00:05:51,640 --> 00:05:52,960 Let's look what goes on here. 74 00:05:53,120 --> 00:05:54,580 This is basic form. 75 00:05:54,580 --> 00:05:54,820 Form stuff. 76 00:05:55,120 --> 00:05:56,180 You send the username. 77 00:05:56,460 --> 00:05:57,720 You send the password. 78 00:05:58,000 --> 00:05:59,440 And let's see what it does with it. 79 00:05:59,620 --> 00:06:02,560 This is basic, you know, ASP, ODBC driver stuff. 80 00:06:02,620 --> 00:06:03,600 We're connecting to the database. 81 00:06:03,980 --> 00:06:05,580 Get the values from the URI. 82 00:06:05,960 --> 00:06:07,200 Now, here's what goes on. 83 00:06:07,260 --> 00:06:08,400 Here's how it authenticates. 84 00:06:08,840 --> 00:06:15,520 Select username from users where username equals username and password equals password. 85 00:06:16,080 --> 00:06:17,000 Now, let's see. 86 00:06:17,320 --> 00:06:24,440 If that statement fails, for instance, there is no row in the database where username and password... 87 00:06:24,580 --> 00:06:33,200 If it's matched like that, what's going to happen, rs.eof, if there are no records in the returned record set, then your login is invalid. 88 00:06:34,400 --> 00:06:39,300 If not, and again, this is very simple sample stuff that I put together, you know, in the last couple hours. 89 00:06:39,540 --> 00:06:40,140 It's been unbelievable. 90 00:06:41,100 --> 00:06:46,100 You get your access granted and you get sensitive financial information. 91 00:06:47,180 --> 00:06:51,500 So let's see what happens when we take the SQL statement here. 92 00:06:52,960 --> 00:06:54,560 And we plug in the VAT. 93 00:06:54,560 --> 00:07:13,700 We plug in the values that the quote, quote thing, where username equals quote, and here's where we start changing things, username equals no, or username can equal one equals one. 94 00:07:14,180 --> 00:07:16,000 Here's the part where we manipulate it. 95 00:07:16,200 --> 00:07:18,600 I want everyone to look real hard at that statement. 96 00:07:19,040 --> 00:07:21,920 Where username equals no, there is no username. 97 00:07:22,100 --> 00:07:24,480 Or where one is equal. 98 00:07:24,560 --> 00:07:31,720 I don't know if anyone here has ever done any programming, but that statement will always, 100% of the time, be true. 99 00:07:32,200 --> 00:07:37,160 You will get records back from the database and they do the same exact thing with password. 100 00:07:41,940 --> 00:07:44,780 And we're going to remove the double quotes there that came from the ASP. 101 00:07:46,000 --> 00:07:51,480 Simple note for people who have SQL injected against SQL Server, you can do quote, quote equals quote. 102 00:07:51,940 --> 00:07:54,460 Oracle, for your information, does not see that. 103 00:07:54,560 --> 00:07:56,500 No equals no will return a no. 104 00:07:56,540 --> 00:07:57,560 It will not return true. 105 00:07:57,820 --> 00:07:59,860 So you do have to actually use one. 106 00:08:00,060 --> 00:08:02,760 Or you can use a or anything as long as they'll match up. 107 00:08:02,860 --> 00:08:04,960 It's going to slap that single quote onto the end for you. 108 00:08:05,640 --> 00:08:06,600 Is everyone following me here? 109 00:08:06,640 --> 00:08:07,780 Does anyone have any questions so far? 110 00:08:09,020 --> 00:08:09,900 Okay then, we're good. 111 00:08:10,280 --> 00:08:11,480 Let's see what comes back there. 112 00:08:11,640 --> 00:08:13,700 As you see, we can get the full list of usernames. 113 00:08:13,700 --> 00:08:14,800 It returns multiple records. 114 00:08:15,100 --> 00:08:16,980 So our statement evaluated true. 115 00:08:18,080 --> 00:08:24,460 Now that we've got our basic stuff together, we're going to start looking at, and I've shown you the most simple things. 116 00:08:24,480 --> 00:08:24,540 And I've shown you the most simple things. 117 00:08:24,540 --> 00:08:27,240 The authentication bypass is the easiest thing you can do. 118 00:08:27,700 --> 00:08:34,080 We're going to go back to this script where it returns three columns of specific information from the database and displays them in the web application. 119 00:08:35,340 --> 00:08:41,540 Now, I'm going to show you real simple here how select union query would work using what I have here. 120 00:08:42,220 --> 00:08:47,600 Select, let's say, username that's, you know, let's change that to just sample information. 121 00:08:48,620 --> 00:08:49,880 Change, you know, A. 122 00:08:50,780 --> 00:08:52,500 In A, it'll return two rows. 123 00:08:52,560 --> 00:08:54,300 Of course, these are literals, not real records. 124 00:08:54,540 --> 00:08:54,940 These are in the database. 125 00:08:55,720 --> 00:09:01,620 Select AA from valid table name where username equals condition. 126 00:09:03,240 --> 00:09:06,040 And here's where we start what it's doing called a union. 127 00:09:06,300 --> 00:09:10,700 A union is used to put basically two select queries together. 128 00:09:10,880 --> 00:09:17,680 It's just a programming device to help programmers return information from two different places in one SQL query. 129 00:09:18,260 --> 00:09:19,420 Union, select. 130 00:09:19,700 --> 00:09:21,600 And let's try different information. 131 00:09:21,800 --> 00:09:23,700 B, comma, B. 132 00:09:24,540 --> 00:09:25,860 Let's say different tables. 133 00:09:26,120 --> 00:09:26,880 A table. 134 00:09:27,020 --> 00:09:30,660 I happen to know in all Oracle databases, there's a table called dual. 135 00:09:31,100 --> 00:09:33,180 The table dual does not contain information. 136 00:09:33,580 --> 00:09:35,100 It is a special kind of table. 137 00:09:35,160 --> 00:09:35,840 It exists again. 138 00:09:35,880 --> 00:09:41,140 It's a programming device that it will always return what's selected from it, one record set of it. 139 00:09:41,240 --> 00:09:45,600 So on every Oracle server you ever see, you can guarantee that there is a table called dual. 140 00:09:46,680 --> 00:09:49,280 And make, you know, universally true condition. 141 00:09:50,580 --> 00:09:51,060 Yeah. 142 00:09:51,440 --> 00:09:54,440 . . . 143 00:09:54,440 --> 00:09:59,360 As you can see, where username equals quote, quote, return false, it returned no records. 144 00:09:59,620 --> 00:10:03,120 But the union select part returned both. 145 00:10:03,300 --> 00:10:12,120 Now let's say if I were to modify that to where one equals one, we would get both back. 146 00:10:12,440 --> 00:10:14,180 Does everyone understand how the union works? 147 00:10:14,440 --> 00:10:15,940 It just puts two queries together. 148 00:10:16,120 --> 00:10:17,260 It's returning both. 149 00:10:17,480 --> 00:10:21,100 Select B, B from dual and select AA from users at the same time. 150 00:10:21,380 --> 00:10:24,420 . . . 151 00:10:24,420 --> 00:10:29,680 In SQL plus worksheet, no, because Larry Ellison hates everyone and does everything in Java, which really hates everything. 152 00:10:31,080 --> 00:10:32,320 We're going to go back here. 153 00:10:32,640 --> 00:10:34,080 Could everyone see that, though? 154 00:10:34,140 --> 00:10:38,600 This is the important stuff, what you're doing from a web browser, what you're going to be actually doing when you're running this against a site. 155 00:10:40,680 --> 00:10:41,800 So we're going to look here. 156 00:10:43,040 --> 00:10:43,920 Union select. 157 00:10:44,480 --> 00:10:46,800 And here's where you have to start paying attention. 158 00:10:47,980 --> 00:10:48,880 Let's try this. 159 00:10:48,980 --> 00:10:53,360 Union select table name from all tables. 160 00:10:53,480 --> 00:10:54,060 . . . 161 00:10:54,060 --> 00:10:57,260 All tables is another table that occurs in all Oracle databases. 162 00:10:57,500 --> 00:11:00,280 It simply contains a list of all the tables that are on the database. 163 00:11:00,780 --> 00:11:02,720 It's got the list of everything in there. 164 00:11:02,860 --> 00:11:04,860 And you can always depend that it's going to be there. 165 00:11:05,340 --> 00:11:09,100 Where, of course, we're going to put our magical little string here that will make it return records. 166 00:11:10,000 --> 00:11:15,460 And I'm going to copy that so I can show you back in PL-SQL terminal for those of you who are sitting close enough that you can actually see. 167 00:11:15,540 --> 00:11:15,860 I'm sorry. 168 00:11:16,480 --> 00:11:17,940 And we're going to see what we get back. 169 00:11:18,540 --> 00:11:21,100 Query block has incorrect number of result columns. 170 00:11:21,280 --> 00:11:22,480 I'll show you why that happens. 171 00:11:24,060 --> 00:11:27,720 What we've got here, and I'm really sorry about the font size, but there's nothing you can do. 172 00:11:28,200 --> 00:11:33,080 Oracle did not have the foresight to put font size information in the SQL plus worksheet application. 173 00:11:34,160 --> 00:11:42,080 Is that when you run a union select query, you have to have the same amount of selected columns in select. 174 00:11:42,860 --> 00:11:48,040 And you have to have the same amount of columns in the second select, in the union part. 175 00:11:48,360 --> 00:11:52,720 See if I were to delete the second column, it's going to complain. 176 00:11:53,180 --> 00:11:56,240 Well, that's complaining because I still have the comma there, but there you go. 177 00:11:56,780 --> 00:12:01,660 So what you have to do is you have to look at the legitimate output. 178 00:12:01,800 --> 00:12:05,940 We also, this returns three columns, first name, last name, and phone number. 179 00:12:06,260 --> 00:12:08,240 So we need three columns here. 180 00:12:09,680 --> 00:12:13,220 One, two, and of course I'm just using the literals here as dummy strings. 181 00:12:16,940 --> 00:12:21,460 And this time, instead of getting back first name, last name, and phone number, 182 00:12:21,460 --> 00:12:25,840 we have a list of every table in the Oracle database here. 183 00:12:27,300 --> 00:12:30,320 Now what we're going to go through is we're going to look, 184 00:12:30,400 --> 00:12:33,140 and of course you go through and you find the table names that look interesting. 185 00:12:33,400 --> 00:12:37,360 But before we do that, I'm going to show you a couple things that can occur in the SQL syntax 186 00:12:37,360 --> 00:12:39,100 that can make this a little confusing. 187 00:12:39,740 --> 00:12:43,340 Not all SQL statements are going to look exactly like this. 188 00:12:43,620 --> 00:12:46,460 You're going to have some programmers who are going to do little different things. 189 00:12:47,780 --> 00:12:48,960 One thing you're going to see, 190 00:12:52,740 --> 00:12:54,660 is, let's get down to the SQL statement, 191 00:12:55,560 --> 00:12:57,360 in addition to the single quote, 192 00:12:57,960 --> 00:13:01,720 they're putting what you control, email, also around parentheses. 193 00:13:02,200 --> 00:13:04,880 So let's go real simple, I'll show you how to get around that. 194 00:13:04,960 --> 00:13:07,880 It's very simple, it's the same concept, most of you have probably caught on by now. 195 00:13:08,400 --> 00:13:09,900 You end that right there, 196 00:13:11,060 --> 00:13:11,960 union select, 197 00:13:14,380 --> 00:13:15,300 all tables, 198 00:13:16,200 --> 00:13:16,660 sorry, 199 00:13:20,220 --> 00:13:21,140 table name, 200 00:13:22,280 --> 00:13:24,280 a, a, got to do our column matching, 201 00:13:25,160 --> 00:13:26,920 from all tables, 202 00:13:27,780 --> 00:13:28,140 where, 203 00:13:29,580 --> 00:13:34,720 and you put the parentheses right there so it matches up what it's got at the beginning and the end, 204 00:13:34,840 --> 00:13:36,100 just like we showed it to, 205 00:13:39,420 --> 00:13:40,760 and you get your table back. 206 00:13:41,020 --> 00:13:43,120 If you don't have the parentheses in there, 207 00:13:46,120 --> 00:13:48,300 Oracle actually, I don't know if any of you, again, 208 00:13:48,420 --> 00:13:49,940 SQL Server is the most common thing out there, 209 00:13:49,940 --> 00:13:51,880 SQL Server just tells you you have a syntax error, 210 00:13:52,080 --> 00:13:54,260 Oracle will actually tell you, you're missing a parentheses. 211 00:13:58,080 --> 00:14:00,740 Now I know, just one thing I'm going to point out here, 212 00:14:00,780 --> 00:14:03,900 SQL injection is not a problem in the database. 213 00:14:04,460 --> 00:14:08,240 The problem is, it's occurring here in the ASP programmer's code, 214 00:14:08,480 --> 00:14:11,200 that they're not stripping out things like single quotes, 215 00:14:11,300 --> 00:14:13,720 and they're not limiting the amount of information that can be passed. 216 00:14:14,120 --> 00:14:16,660 For instance, this application that I've been showing you, 217 00:14:16,740 --> 00:14:18,260 it searches for an email address. 218 00:14:18,260 --> 00:14:21,320 Does anyone know of anyone who has an email address that is that long? 219 00:14:22,160 --> 00:14:24,440 Your common sense for your programmer should be, 220 00:14:24,540 --> 00:14:27,860 have maximum for your email address something like 10 characters, 221 00:14:28,100 --> 00:14:29,860 do not let commas through, 222 00:14:30,060 --> 00:14:31,440 do not let single quotes through, 223 00:14:31,560 --> 00:14:32,600 do not let spaces through. 224 00:14:33,080 --> 00:14:35,300 So the problem isn't the database server, 225 00:14:35,560 --> 00:14:38,040 the problem is the web application programmer. 226 00:14:38,380 --> 00:14:40,980 He's not doing what is called input sanitization. 227 00:14:41,340 --> 00:14:41,720 Yeah? 228 00:14:42,860 --> 00:14:43,380 . 229 00:14:45,600 --> 00:14:46,120 . 230 00:14:47,680 --> 00:14:48,040 . 231 00:14:48,840 --> 00:14:49,200 Yes? 232 00:14:50,700 --> 00:14:51,060 . 233 00:14:54,380 --> 00:14:56,880 Uh, there will, and I will get to that later. 234 00:14:57,000 --> 00:14:59,680 Another thing you'll have to do is you'll have to match the data types of the columns. 235 00:14:59,780 --> 00:15:01,020 I'll show you that to you in a minute though. 236 00:15:02,740 --> 00:15:04,300 Uh, see we're going to have here, 237 00:15:04,860 --> 00:15:05,880 yeah, you have to do that. 238 00:15:06,480 --> 00:15:08,460 So while Oracle will return you, 239 00:15:08,540 --> 00:15:10,760 for instance, Oracle will say, 240 00:15:10,880 --> 00:15:12,060 you're missing a right parentheses, 241 00:15:12,320 --> 00:15:13,660 and of course this error message 242 00:15:13,660 --> 00:15:15,340 is for the benefit of, 243 00:15:16,120 --> 00:15:20,300 The application developer and not the end user, the customer, they're telling it to 244 00:15:20,300 --> 00:15:24,460 you anyway because the person who's running the web server and the ODBC server hasn't 245 00:15:24,460 --> 00:15:27,140 taken the time to disable error messages. 246 00:15:27,580 --> 00:15:31,800 Some web user out there looking at their site on the internet should never be able to see 247 00:15:31,800 --> 00:15:33,960 debugging error messages that are coming from your site. 248 00:15:36,060 --> 00:15:39,940 And while Oracle tells you missing right parentheses, one thing that it will not do is if you've 249 00:15:39,940 --> 00:15:44,260 ever seen a SQL server error message, it gives you parts of the SQL query that will 250 00:15:44,260 --> 00:15:45,400 run in the error message. 251 00:15:46,200 --> 00:15:47,560 Oracle will never do that. 252 00:15:47,880 --> 00:15:51,940 And while in SQL server it's really easy to pick some things like syntax or table name 253 00:15:51,940 --> 00:15:56,140 and stuff out of there because you get them in the error messages, on Oracle you are on 254 00:15:56,140 --> 00:15:56,540 your own. 255 00:15:57,720 --> 00:15:59,960 Another thing you're going to run into is a like query. 256 00:16:00,340 --> 00:16:03,160 Like queries are used in SQL for searching for things. 257 00:16:03,300 --> 00:16:04,200 They use wildcards. 258 00:16:04,700 --> 00:16:09,100 For instance, this one you'll notice, enter as much as you know of a Genericorp employee's 259 00:16:09,100 --> 00:16:13,100 last name to obtain their phone number, because I'm sure everyone saw the last time I used 260 00:16:13,100 --> 00:16:13,640 S King. 261 00:16:13,640 --> 00:16:18,440 Let's say I forgot their first name, but I know that their email address ends in King. 262 00:16:20,320 --> 00:16:23,580 And I got, look, two employees happen to have the last name King here. 263 00:16:23,960 --> 00:16:25,460 Here's what it looks like in code. 264 00:16:33,540 --> 00:16:39,460 First part's the same, but at the end, where email, like, and these percent signs here, 265 00:16:39,520 --> 00:16:40,520 they're the same as asterisks. 266 00:16:40,540 --> 00:16:41,740 They're basically wildcards. 267 00:16:42,500 --> 00:16:47,440 Now the way you get around this, and remember, you want to make sure that their SQL query 268 00:16:48,160 --> 00:16:51,640 select last, first name, last name, phone number from employees, you want to make sure 269 00:16:51,640 --> 00:16:52,520 that doesn't return records. 270 00:16:52,720 --> 00:16:53,580 You don't want to see them. 271 00:16:53,980 --> 00:16:59,200 So what we're going to do here is going to go something that's obviously not going to 272 00:16:59,200 --> 00:17:00,520 turn up in their email address database. 273 00:17:00,740 --> 00:17:02,260 Return no records, for instance. 274 00:17:04,180 --> 00:17:07,640 Union select all tables. 275 00:17:08,420 --> 00:17:09,440 Ah, did it again. 276 00:17:09,560 --> 00:17:10,560 Table name, that's right. 277 00:17:11,320 --> 00:17:11,720 All tables. 278 00:17:17,920 --> 00:17:21,420 Where, and you have to match what they have, so we're going to use a like here. 279 00:17:25,000 --> 00:17:32,040 Where table name, got to use a valid table name, like, or you actually don't have to 280 00:17:32,040 --> 00:17:32,420 match the like. 281 00:17:32,440 --> 00:17:33,300 We're going to do it anyway here. 282 00:17:33,360 --> 00:17:33,940 I just thought of something. 283 00:17:34,600 --> 00:17:40,460 Or like, and remember, at the end of what you put, they are going to throw in percent, 284 00:17:40,540 --> 00:17:41,060 quote. 285 00:17:42,620 --> 00:17:46,760 Like, does not occur in DB. 286 00:17:49,720 --> 00:17:50,960 That should look good. 287 00:17:52,900 --> 00:17:53,440 One sec. 288 00:17:54,440 --> 00:17:55,900 No, you want, I'm sorry, everyone. 289 00:17:56,080 --> 00:17:59,000 This one you want to return wildcard, because this is your union select. 290 00:17:59,140 --> 00:18:02,720 You want this one to return as many as possible, so you're actually going to leave that blank. 291 00:18:08,240 --> 00:18:09,520 And again, you get that back. 292 00:18:09,600 --> 00:18:10,480 I'll show you this one. 293 00:18:38,500 --> 00:18:41,720 And what happens here is you get, because you used the table name, you're going to have to match all the tables. 294 00:18:41,720 --> 00:18:46,880 If you used a single quote there, you get like, percent, and I said, the like is wildcard. 295 00:18:47,180 --> 00:18:49,560 You will get full matches will return back. 296 00:18:50,940 --> 00:18:55,140 The third thing you're going to see, where's my IE, there it is, nope. 297 00:18:55,500 --> 00:18:57,460 That's all we're doing for, we have time constraints. 298 00:18:57,580 --> 00:19:00,420 I wish I could show everyone everything with inserts, but we're going to move along here. 299 00:19:00,820 --> 00:19:03,440 So now we're going to use the most simple one, because it's going to be the easiest 300 00:19:03,440 --> 00:19:06,560 for me to get through the presentation, and I think you've all got the concept here. 301 00:19:06,780 --> 00:19:08,740 Just to check, does anyone have any questions thus far? 302 00:19:10,780 --> 00:19:11,140 Yeah. 303 00:19:15,840 --> 00:19:17,000 Yeah, you can. 304 00:19:17,080 --> 00:19:18,700 I'm going to go through all the different stuff you can do. 305 00:19:19,740 --> 00:19:23,000 So the first name, now that we've got our list of tables. 306 00:19:37,420 --> 00:19:38,220 Oh, typo. 307 00:19:39,540 --> 00:19:40,340 Oh, typo. 308 00:19:44,240 --> 00:19:48,880 Now that we've got this list, we're going to look through and see what tables look interesting. 309 00:19:49,280 --> 00:19:54,180 Since I happen to design this database myself, I will tell you that there is a very interesting 310 00:19:54,180 --> 00:19:56,380 table called users here. 311 00:19:58,860 --> 00:20:02,380 We're going to look, and the next thing we need to do, now we've got a table name, right? 312 00:20:03,760 --> 00:20:07,900 We need to know, before we can do a query on this table, we need to know what the column 313 00:20:07,900 --> 00:20:10,340 names are, or else what kind of information are we going to get back? 314 00:20:10,340 --> 00:20:19,360 Just like there is in all tables, there is a table called all tab columns. 315 00:20:20,660 --> 00:20:24,260 It's got the argument names, column name, and you'll see up here the two C's and stuff, 316 00:20:24,360 --> 00:20:28,080 Internet Explorer, when you send it through HTTP, it will encode certain things. 317 00:20:28,320 --> 00:20:29,300 I'll show that to you. 318 00:20:30,540 --> 00:20:37,740 Union select, column name, again, garbage, garbage. 319 00:20:38,480 --> 00:20:39,020 From. 320 00:20:40,240 --> 00:20:40,600 All. 321 00:20:40,800 --> 00:20:41,260 What is it? 322 00:20:41,400 --> 00:20:42,060 User columns? 323 00:20:42,420 --> 00:20:44,300 I guess I should know this when I'm asking you guys. 324 00:20:45,340 --> 00:20:45,840 One second. 325 00:20:51,040 --> 00:21:01,380 All tab columns, which is, of course, all table columns, where, and we specify, and 326 00:21:01,380 --> 00:21:04,200 again, all tab columns is another one of those standard Oracle tables. 327 00:21:04,360 --> 00:21:07,420 You can look it up in the Oracle reference documentation if you want what the rest of 328 00:21:07,420 --> 00:21:08,440 the column names are and stuff. 329 00:21:09,020 --> 00:21:11,280 Where table name equal, and here's what we want. 330 00:21:11,340 --> 00:21:11,860 We want user. 331 00:21:12,200 --> 00:21:18,120 And remember that Oracle is most of the time with the nvarchar data type that most database 332 00:21:18,120 --> 00:21:19,140 administrators are going to use. 333 00:21:19,260 --> 00:21:20,580 It will be case sensitive. 334 00:21:20,780 --> 00:21:24,380 Capital user will not be the same table as lowercase user. 335 00:21:25,040 --> 00:21:29,120 And, of course, we know that our ASP scripts lands an extra single quote onto the end 336 00:21:29,120 --> 00:21:31,120 and one onto the beginning, so we've got our syntax matched. 337 00:21:34,060 --> 00:21:35,980 And, amazingly enough, one sec. 338 00:21:37,060 --> 00:21:37,540 . 339 00:21:37,540 --> 00:21:37,900 . 340 00:21:37,900 --> 00:21:37,920 . 341 00:21:37,920 --> 00:21:38,140 . 342 00:21:38,140 --> 00:21:38,580 . 343 00:21:38,580 --> 00:21:38,640 . 344 00:21:38,640 --> 00:21:39,000 . 345 00:21:39,000 --> 00:21:39,780 . 346 00:21:40,440 --> 00:21:41,080 . 347 00:21:52,860 --> 00:21:53,500 . 348 00:21:53,500 --> 00:21:54,040 . 349 00:21:54,040 --> 00:21:54,200 . 350 00:21:54,200 --> 00:21:54,220 . 351 00:21:54,220 --> 00:21:54,240 . 352 00:21:57,900 --> 00:21:58,540 . 353 00:22:01,160 --> 00:22:01,800 . 354 00:22:01,800 --> 00:22:02,420 . 355 00:22:02,420 --> 00:22:02,560 . 356 00:22:02,560 --> 00:22:02,660 . 357 00:22:02,660 --> 00:22:02,720 . 358 00:22:02,720 --> 00:22:02,780 . 359 00:22:02,780 --> 00:22:03,100 . 360 00:22:03,100 --> 00:22:03,280 . 361 00:22:08,340 --> 00:22:08,980 . 362 00:22:08,980 --> 00:22:12,620 password. Now that we know that, we're going to run back 363 00:22:12,620 --> 00:22:15,620 here. We're going to plug in username 364 00:22:19,040 --> 00:22:19,460 password 365 00:22:21,060 --> 00:22:23,160 and it's coming from the table 366 00:22:26,640 --> 00:22:28,860 users where, and of course we don't need this part 367 00:22:28,860 --> 00:22:29,160 anymore. 368 00:22:33,160 --> 00:22:36,280 Check that out for a second. We're selecting username, password, and A 369 00:22:36,280 --> 00:22:39,400 from users where 1 equals 1. 370 00:22:40,460 --> 00:22:44,700 And as you can see, they have a very strict password policy on this site 371 00:22:44,700 --> 00:22:48,700 and for anyone who thinks things like this are unlikely, I recently did like a 372 00:22:48,700 --> 00:22:52,660 pen test on a large communications company and their admin password really 373 00:22:52,660 --> 00:22:55,900 was the administrator's username followed by 2002. 374 00:22:57,560 --> 00:23:00,200 So now we're going to use that and we're going to go back 375 00:23:00,200 --> 00:23:04,360 to another login page. Now this login page 376 00:23:04,360 --> 00:23:08,560 because it's designed a slightly different way and I'll show you, you can't do the quote equals 377 00:23:08,560 --> 00:23:10,440 1 equals 1 thing on. 378 00:23:12,720 --> 00:23:16,820 What happens in this one is it does the same thing 379 00:23:16,820 --> 00:23:19,580 select username from users where username is password 380 00:23:20,740 --> 00:23:24,480 but in ASP code, which we can't tamper with 381 00:23:24,480 --> 00:23:28,020 it actually looks on this part to check 382 00:23:28,020 --> 00:23:32,500 is the record that it returned back the same as the variable I have for username? 383 00:23:34,580 --> 00:23:38,580 So in this one, we're not going to be able to SQL inject our way through our 384 00:23:38,580 --> 00:23:42,520 authorization bypass. Excuse me, authentication bypass. 385 00:23:42,620 --> 00:23:43,860 I was waiting for someone to call me on that. 386 00:23:45,500 --> 00:23:47,920 So, now since we SQL injected 387 00:23:47,920 --> 00:23:52,800 and we got Kidman's username, and his secret password, 388 00:23:54,920 --> 00:23:57,160 we can go through and we can still recover 389 00:23:57,720 --> 00:24:04,340 sensitive financial information. Now that's the basics about how your select SQL injection is going to work. 390 00:24:04,340 --> 00:24:09,420 And now I'm going to go into some Oracle-specific things I've figured out, going through reference manuals and things. 391 00:24:09,840 --> 00:24:17,300 Oracle databases are huge, and they contain almost all of their configuration information within system tables. 392 00:24:17,680 --> 00:24:20,540 There are system tables for all kinds of things. 393 00:24:20,860 --> 00:24:27,140 One of the things that they have a table for is, for instance, the password policy. 394 00:24:27,140 --> 00:24:32,980 If you can't get out, if in the improbable event, and I say improbable because I've done this on many, many sites, 395 00:24:33,160 --> 00:24:39,260 and it seems like no one really understands that it's a pretty good idea to hash your passwords instead of keeping them in clear text, 396 00:24:39,760 --> 00:24:42,200 you can get the password policy. 397 00:24:42,880 --> 00:24:45,480 In this case, and this, by the way, is the default configuration. 398 00:24:45,600 --> 00:24:51,520 I just want to point out that Oracle, by default, will let you try to log on as many times as you like, and it will not bother you. 399 00:24:52,440 --> 00:24:54,740 You can get failed login attempts. 400 00:24:56,060 --> 00:24:56,980 Password grace time. 401 00:24:57,140 --> 00:25:00,180 And this only will work, again, this is for the Oracle logon. 402 00:25:00,260 --> 00:25:02,300 This is not for the web application. 403 00:25:02,460 --> 00:25:03,500 It may be completely different. 404 00:25:04,120 --> 00:25:08,840 If you can get the Oracle server by your network, this information is unbelievably useful. 405 00:25:09,200 --> 00:25:13,220 If they do have a policy in place, and you have maximum amount of attempts, 406 00:25:13,320 --> 00:25:17,060 this stuff can really help you design tools that will cut down your brute force time dramatically. 407 00:25:18,740 --> 00:25:22,820 Another interesting thing about modern database servers is, 408 00:25:22,960 --> 00:25:26,740 they basically got their own enormous programming languages built in. 409 00:25:27,140 --> 00:25:32,540 They want developers to use nothing but Oracle tools, they want them to buy the devkits, they want them to do all kinds of stuff. 410 00:25:32,820 --> 00:25:39,640 And as a result, they contain some very, very interesting procedures and built-in commands as part of their database. 411 00:25:40,720 --> 00:25:47,820 One of the interesting things I found in the Oracle is there is a package called UTLHTDP, the HTTP utility, 412 00:25:48,560 --> 00:25:50,740 and it has a method called request. 413 00:25:51,340 --> 00:25:56,880 This will allow you, in a SQL statement, to make an HTTP request to another server, 414 00:25:56,880 --> 00:26:00,260 and return your result as part of the record set. 415 00:26:01,780 --> 00:26:05,520 If anyone can see up here, and it's probably not large enough, 416 00:26:06,040 --> 00:26:10,160 what this basically, what has happened here, is as part of my SQL statement, 417 00:26:10,360 --> 00:26:12,980 and I'll show you again on the founder page in a minute, 418 00:26:13,100 --> 00:26:18,880 it has pulled back an HTTP request and put it in the record set. 419 00:26:20,360 --> 00:26:25,040 And I'm also going to point out that there are like tens of thousands of these methods and procedures in Oracle, 420 00:26:25,240 --> 00:26:26,540 and there's not a database administrator. 421 00:26:26,880 --> 00:26:30,500 It's in the face of the earth that, you know, remembers to lock all this stuff down. 422 00:26:30,640 --> 00:26:31,420 It's simply unbelievable. 423 00:26:32,640 --> 00:26:34,560 So we're going to look at this and see how to do that. 424 00:26:36,020 --> 00:26:41,840 Union, select, UTL, http.request. 425 00:26:42,000 --> 00:26:44,240 And in this case, I'm not connecting this box to internet, 426 00:26:44,860 --> 00:26:49,520 so I'm just going to do localhost, which I know is, you know, really impressive. 427 00:26:52,360 --> 00:26:53,420 Scripts, what's another one? 428 00:26:53,600 --> 00:26:56,760 Phone, or let's use login like I showed you in the bookmark. 429 00:26:57,340 --> 00:26:58,140 Login.asp. 430 00:27:00,700 --> 00:27:05,520 Match your columns from union, select, localhost, jmp. 431 00:27:06,160 --> 00:27:07,880 Dual, I told you about the dual table. 432 00:27:08,120 --> 00:27:10,980 It doesn't really have anything in it, but it'll make sure you get your result back. 433 00:27:12,020 --> 00:27:15,660 Where, and we're going to match the end so that it works nicely with what's in the ASP code. 434 00:27:19,820 --> 00:27:21,420 Invalid relation, I'll hop around in a second. 435 00:27:23,220 --> 00:27:25,580 Union, select, UTL, http.request. 436 00:27:26,880 --> 00:27:28,620 From union, where, when, which one? 437 00:27:28,960 --> 00:27:30,160 One sec, sorry guys. 438 00:27:31,320 --> 00:27:33,980 Was it? Is that my relational operator problem? 439 00:27:34,400 --> 00:27:43,360 Yeah, thank you for solving all of my relational operator problems, man in the back. 440 00:27:44,240 --> 00:27:45,140 And we get that. 441 00:27:45,220 --> 00:27:49,720 Now I want everyone to think about the implication from this, of the implications of this. 442 00:27:50,100 --> 00:27:54,740 This request is being made from where your Oracle database server is, 443 00:27:54,740 --> 00:28:01,220 which is probably, although in some places people really do put the Oracle server on the exact same box as the web server, 444 00:28:01,420 --> 00:28:07,760 this is probably behind a firewall, and there's a very good chance you have no other way of getting at this Oracle box. 445 00:28:08,220 --> 00:28:11,280 You can make the Oracle box from inside the firewall, 446 00:28:12,460 --> 00:28:18,280 you can make requests to internal IP addresses, and you can scan for internet web servers using this thing 447 00:28:18,280 --> 00:28:21,820 that you normally would not be able to get through from the internet, which is really great. 448 00:28:22,000 --> 00:28:23,720 Another interesting thing about Oracle, 449 00:28:23,720 --> 00:28:28,920 in order to show everyone how it integrates great with web services and web applications, 450 00:28:29,600 --> 00:28:32,900 Oracle has taken the liberty of when you install the Oracle database, 451 00:28:33,160 --> 00:28:38,480 it installs an HTTP server, it's built on top of Apache, it's Oracle application server, 452 00:28:38,680 --> 00:28:40,540 on the same box as the Oracle server. 453 00:28:40,980 --> 00:28:44,700 I just set an Oracle server up on this test box a couple hours ago, 454 00:28:44,820 --> 00:28:48,340 and I can tell you that it is impossible to disable it in the installation, 455 00:28:48,640 --> 00:28:53,200 it will not let you uncheck the box, and by default it runs automatically as a service, 456 00:28:53,200 --> 00:28:54,120 and it will start it. 457 00:28:54,220 --> 00:28:57,120 So be sure you check localhost 80 when you get this, 458 00:28:57,260 --> 00:29:02,320 because there's a good chance that you're going to have a web server running on the Oracle database server 459 00:29:02,320 --> 00:29:04,060 and the administrator doesn't even know it. 460 00:29:06,700 --> 00:29:07,980 Other interesting stuff, 461 00:29:08,240 --> 00:29:09,540 you can get, 462 00:29:11,080 --> 00:29:11,940 union select, 463 00:29:12,640 --> 00:29:14,340 the column name is SQL text, 464 00:29:15,420 --> 00:29:16,540 and then you have, 465 00:29:18,160 --> 00:29:19,200 SQL text, 466 00:29:19,420 --> 00:29:21,280 there's the second one, yeah, 467 00:29:21,320 --> 00:29:22,060 SQL text, 468 00:29:22,060 --> 00:29:22,760 from, 469 00:29:23,000 --> 00:29:24,440 there's a table called SQL text, 470 00:29:24,900 --> 00:29:28,100 these are all the previous SQL queries that have been run against the database. 471 00:29:28,700 --> 00:29:31,580 They contain all kinds of interesting information. 472 00:29:32,640 --> 00:29:34,300 I didn't even run any of these, 473 00:29:34,400 --> 00:29:35,100 I never did this, 474 00:29:35,200 --> 00:29:36,860 this is something the system does by itself, 475 00:29:37,080 --> 00:29:39,000 and you can go through it all at your leisure, 476 00:29:39,160 --> 00:29:40,400 through SQL injection. 477 00:29:42,120 --> 00:29:43,880 See that, you guys remember all this stuff? 478 00:29:45,100 --> 00:29:47,300 All stored in the database, Oracle forgets nothing. 479 00:29:48,520 --> 00:29:49,640 Other interesting stuff, 480 00:29:52,040 --> 00:29:52,440 yeah, 481 00:29:54,340 --> 00:29:56,780 I apologize, like I said, I just set this up, 482 00:29:56,860 --> 00:29:58,980 this is not on your DEF CON CD ROMs, 483 00:29:58,980 --> 00:29:59,480 this presentation, 484 00:30:00,180 --> 00:30:02,440 but we will have it posted, I'll get Tangent, 485 00:30:02,500 --> 00:30:04,020 he'll put it on the DEF CON dot org site, 486 00:30:04,580 --> 00:30:06,360 and our company's website, 487 00:30:08,480 --> 00:30:09,820 www.spidynamics.com, 488 00:30:10,520 --> 00:30:11,900 we'll have all this information, 489 00:30:12,240 --> 00:30:15,120 we'll have a pretty document, white paper, whatever thing that we can give to suits, 490 00:30:15,180 --> 00:30:16,760 and it won't frighten them, and you guys can read, 491 00:30:16,900 --> 00:30:19,280 and pick out all kinds of interesting table names 492 00:30:19,280 --> 00:30:20,020 that I'm using here, 493 00:30:20,100 --> 00:30:21,240 you'll be able to have this information, 494 00:30:21,560 --> 00:30:24,140 so if you're not writing everything down at the speed of light here, 495 00:30:24,220 --> 00:30:25,020 don't worry about it. 496 00:30:28,900 --> 00:30:30,280 But, since you asked, 497 00:30:30,740 --> 00:30:32,320 table name, SQL text, 498 00:30:32,540 --> 00:30:34,880 and remember this is all in your standard Oracle documentation, 499 00:30:35,160 --> 00:30:37,460 this is completely in there for anyone who bothers to read it, 500 00:30:38,640 --> 00:30:40,100 column name is SQL text. 501 00:30:41,220 --> 00:30:42,200 Other great stuff, 502 00:30:42,840 --> 00:30:43,640 your privileges, 503 00:30:45,860 --> 00:30:46,300 username, 504 00:30:46,840 --> 00:30:47,620 granted role, 505 00:30:48,080 --> 00:30:48,500 from, 506 00:30:49,540 --> 00:30:50,800 user role privs. 507 00:30:51,740 --> 00:30:54,280 Now, this will give you a couple of interesting things, 508 00:30:54,360 --> 00:30:55,380 the first thing it tells you, 509 00:30:55,480 --> 00:30:57,200 is what your username is. 510 00:30:57,440 --> 00:30:59,240 In this case, I have it set up, 511 00:30:59,240 --> 00:31:01,220 it uses the username web user, 512 00:31:01,340 --> 00:31:02,840 and I see that I have 513 00:31:03,430 --> 00:31:05,200 rights to connect, which is an obvious one, 514 00:31:05,340 --> 00:31:07,680 also, interestingly enough, I have DBA privileges. 515 00:31:08,220 --> 00:31:10,440 And for anyone who thinks it is unlikely 516 00:31:11,000 --> 00:31:15,220 that the Oracle administrators will set up the web application user as DBA, 517 00:31:15,660 --> 00:31:17,300 I can tell you for a fact that, 518 00:31:17,620 --> 00:31:18,260 people do it all the time, 519 00:31:18,400 --> 00:31:20,780 because then they don't have to bother setting up like, 520 00:31:20,800 --> 00:31:23,340 it's privileges and rights and things like that. 521 00:31:23,500 --> 00:31:25,400 It will automatically have access to what it needs, you see. 522 00:31:25,600 --> 00:31:26,400 And so will we. 523 00:31:27,240 --> 00:31:28,960 So we've automatically got, 524 00:31:29,100 --> 00:31:30,220 we've got our privileges. 525 00:31:30,560 --> 00:31:31,620 Other interesting stuff, 526 00:31:33,440 --> 00:31:34,720 Oracle version info. 527 00:31:35,120 --> 00:31:36,120 This table name, 528 00:31:37,100 --> 00:31:37,980 is called, 529 00:31:39,060 --> 00:31:40,720 the dollar sign version, 530 00:31:41,960 --> 00:31:44,480 and the column name is banner, 531 00:31:44,620 --> 00:31:46,960 and it gives you all the information about what it's running, 532 00:31:47,740 --> 00:31:48,760 other great stuff, 533 00:31:49,960 --> 00:31:51,140 and this one will take a minute, 534 00:31:51,200 --> 00:31:52,220 because it's a very long query, 535 00:31:52,280 --> 00:31:53,080 and I'll tell you why it's long. 536 00:31:54,060 --> 00:31:54,860 Oracle stores, 537 00:31:55,660 --> 00:31:56,820 stored procedure information, 538 00:31:57,500 --> 00:31:58,300 in tables. 539 00:31:59,100 --> 00:32:00,400 You can get the source, 540 00:32:00,440 --> 00:32:02,560 to the Oracle stored procedures, 541 00:32:02,620 --> 00:32:03,980 by accessing tables, 542 00:32:04,100 --> 00:32:05,180 you see it's loading real slow, 543 00:32:05,280 --> 00:32:06,240 because it pulls back, 544 00:32:06,320 --> 00:32:07,460 you can go through the source code, 545 00:32:07,660 --> 00:32:09,600 for all the stored procedures on the database. 546 00:32:11,540 --> 00:32:12,760 This one's going to take a minute, 547 00:32:12,860 --> 00:32:14,760 so we're going to head to another browser while that one loads. 548 00:32:15,820 --> 00:32:16,760 Other great stuff, 549 00:32:20,860 --> 00:32:22,680 God, the Oracle server's going to be swamped. 550 00:32:22,720 --> 00:32:24,500 This is running on like a VMware box, 551 00:32:24,640 --> 00:32:25,660 and Win 2K Pro, 552 00:32:25,900 --> 00:32:27,540 so this isn't happening none too quickly. 553 00:32:32,420 --> 00:32:33,980 We may just have to wait for this one. 554 00:32:35,260 --> 00:32:36,060 I tell you what, 555 00:32:36,060 --> 00:32:36,720 I'll do this one right, 556 00:32:36,780 --> 00:32:37,440 oh, there we go. 557 00:32:38,500 --> 00:32:39,420 I have here, 558 00:32:39,540 --> 00:32:40,540 we're selecting name, 559 00:32:42,100 --> 00:32:42,780 line number, 560 00:32:42,960 --> 00:32:43,820 and like I said, 561 00:32:43,840 --> 00:32:45,560 if you're trying to write this all down, 562 00:32:45,640 --> 00:32:46,680 you don't have to worry about it, 563 00:32:46,760 --> 00:32:47,680 we'll get this stuff on the net, 564 00:32:47,720 --> 00:32:48,960 so that everyone can now see it. 565 00:32:49,900 --> 00:32:50,700 Select name, 566 00:32:51,360 --> 00:32:51,760 line, 567 00:32:52,220 --> 00:32:53,020 and text, 568 00:32:53,160 --> 00:32:53,820 from, 569 00:32:53,980 --> 00:32:56,120 table name is all underscore source, 570 00:32:56,660 --> 00:32:58,460 and another good nice thing about Oracle, 571 00:32:58,700 --> 00:33:01,480 is that it has an identifier called Ronum. 572 00:33:03,260 --> 00:33:05,240 Ronum is a universal column name, 573 00:33:05,780 --> 00:33:08,880 and you can use it to limit the amount of rows that are returned. 574 00:33:09,040 --> 00:33:10,280 In fact, I will show you this query, 575 00:33:10,380 --> 00:33:12,680 and I'll actually inject it myself, 576 00:33:12,920 --> 00:33:14,320 so that you can make sure you're getting all this, 577 00:33:14,420 --> 00:33:16,000 but just go through this stuff. 578 00:33:16,000 --> 00:33:18,560 It's all kinds of unbelievable stuff, 579 00:33:18,740 --> 00:33:20,260 you can see in the stored procedure source, 580 00:33:20,440 --> 00:33:21,780 about how the database is set up, 581 00:33:21,860 --> 00:33:23,160 what kind of other stuff is. 582 00:33:23,480 --> 00:33:24,840 On a really large database, 583 00:33:24,980 --> 00:33:26,980 you can have so many user defined table names, 584 00:33:27,140 --> 00:33:28,980 if you look through the stored procedure source code, 585 00:33:29,040 --> 00:33:30,820 you can usually figure out which ones are interesting, 586 00:33:31,000 --> 00:33:31,640 and which ones aren't. 587 00:33:32,260 --> 00:33:33,040 I'll go back, 588 00:33:33,180 --> 00:33:34,020 and that is name, 589 00:33:34,100 --> 00:33:34,960 two-tar line number, 590 00:33:35,160 --> 00:33:35,780 all source. 591 00:33:38,520 --> 00:33:38,920 Union, 592 00:33:39,140 --> 00:33:39,680 select, 593 00:33:41,380 --> 00:33:41,780 fuck, 594 00:33:41,780 --> 00:33:42,120 I forgot, 595 00:33:42,340 --> 00:33:42,500 I'm sorry. 596 00:33:45,060 --> 00:33:45,460 Yeah, 597 00:33:46,000 --> 00:33:46,720 two-tar and text. 598 00:33:48,900 --> 00:33:49,620 Select name, 599 00:33:49,840 --> 00:33:51,360 which is going to be your procedure name, 600 00:33:52,400 --> 00:33:54,220 two-tar line, 601 00:33:54,600 --> 00:33:56,080 and I will show you why we do that, 602 00:33:56,140 --> 00:33:57,020 two-tar in just a minute, 603 00:33:57,140 --> 00:33:58,980 just what I told that guy over there, 604 00:33:59,080 --> 00:34:02,500 is that you have to do certain type of data type matching on Union queries, 605 00:34:02,620 --> 00:34:04,320 I probably should have started with that at the beginning, 606 00:34:04,380 --> 00:34:04,980 we'll have to go back. 607 00:34:05,440 --> 00:34:06,180 Two-tar line, 608 00:34:06,420 --> 00:34:07,360 and of course text, 609 00:34:09,060 --> 00:34:10,380 from all source, 610 00:34:12,420 --> 00:34:13,840 where one equals one. 611 00:34:13,960 --> 00:34:15,340 And you'll notice that none of this stuff, 612 00:34:15,340 --> 00:34:17,340 is using like exploits, 613 00:34:17,360 --> 00:34:19,000 none of this stuff is underground information, 614 00:34:19,120 --> 00:34:20,120 we're using the SQL injection, 615 00:34:20,600 --> 00:34:23,500 this is just stuff that is stored in the Oracle database, 616 00:34:23,780 --> 00:34:25,360 and yours for the taking if you want it, 617 00:34:25,400 --> 00:34:26,020 and you know where it is. 618 00:34:27,580 --> 00:34:28,360 And of course, 619 00:34:28,380 --> 00:34:29,000 as we can see, 620 00:34:29,060 --> 00:34:30,420 it would take another half an hour to load, 621 00:34:30,540 --> 00:34:31,260 but we're not going to wait, 622 00:34:31,860 --> 00:34:32,880 that is how it works. 623 00:34:33,680 --> 00:34:36,160 Here is the part about type matching. 624 00:34:37,620 --> 00:34:39,040 I don't know why I skipped over it, 625 00:34:39,100 --> 00:34:42,220 but it's going to take a minute. 626 00:34:42,840 --> 00:34:44,280 I'll open it up over the ASP, 627 00:34:44,280 --> 00:34:45,140 and I'll show you what's happening. 628 00:34:52,540 --> 00:34:55,460 One part of the Union query, 629 00:35:01,900 --> 00:35:02,220 select, 630 00:35:02,460 --> 00:35:04,000 and I'll do this with literals and numbers, 631 00:35:04,040 --> 00:35:04,820 to make it real simple, 632 00:35:05,460 --> 00:35:06,080 from dual, 633 00:35:06,260 --> 00:35:08,380 now remember I just told you guys again, 634 00:35:08,620 --> 00:35:09,500 the dual table, 635 00:35:09,600 --> 00:35:10,380 it's not a real table, 636 00:35:10,460 --> 00:35:11,760 it will just return back what you give it, 637 00:35:11,780 --> 00:35:13,160 in this case it will return A and 1, 638 00:35:13,160 --> 00:35:15,520 where 1 equals 1. 639 00:35:17,860 --> 00:35:18,980 Union select, 640 00:35:19,240 --> 00:35:19,820 now watch this, 641 00:35:20,560 --> 00:35:23,900 let's say we have A and A, 642 00:35:24,180 --> 00:35:25,320 from dual, 643 00:35:25,420 --> 00:35:27,100 where 1 equals 1. 644 00:35:28,620 --> 00:35:30,660 Oracle does not like this. 645 00:35:30,900 --> 00:35:32,120 I'll show you what's happening. 646 00:35:32,480 --> 00:35:35,660 Expression must have some data type as corresponding expression. 647 00:35:36,280 --> 00:35:38,740 Not only do you have to have one two columns here, 648 00:35:38,760 --> 00:35:39,680 and one two columns here, 649 00:35:39,880 --> 00:35:42,120 the types have to match. 650 00:35:42,320 --> 00:35:43,080 If they don't match, 651 00:35:43,160 --> 00:35:43,580 you're in trouble. 652 00:35:44,680 --> 00:35:46,040 So what you have to do, 653 00:35:46,060 --> 00:35:48,180 is once you know how many columns there are, 654 00:35:48,380 --> 00:35:49,920 what you're going to want to do, 655 00:35:50,020 --> 00:35:51,260 is if you start getting errors, 656 00:35:52,500 --> 00:35:53,980 you're going to have to start playing with things. 657 00:35:54,120 --> 00:35:54,480 Generally, 658 00:35:54,920 --> 00:35:56,060 people are going to have, 659 00:35:56,560 --> 00:35:58,720 three different kinds of general data types, 660 00:35:58,820 --> 00:35:59,180 of course, 661 00:35:59,180 --> 00:36:01,020 nvarchar is different from nvarchar2, 662 00:36:01,120 --> 00:36:02,340 but they convert implicitly. 663 00:36:02,840 --> 00:36:03,820 But what you're going to have, 664 00:36:03,880 --> 00:36:05,020 you're going to try a letter, 665 00:36:05,840 --> 00:36:07,140 you're going to try a number, 666 00:36:07,580 --> 00:36:08,820 and you're going to try a date. 667 00:36:08,960 --> 00:36:10,600 And I'll tell you the easiest way to do dates, 668 00:36:10,600 --> 00:36:12,600 is not to try to do stuff like this, 669 00:36:12,600 --> 00:36:13,980 there is a function, 670 00:36:15,000 --> 00:36:15,800 called sysdate, 671 00:36:16,320 --> 00:36:17,640 and it will hand you back, 672 00:36:17,740 --> 00:36:19,300 the current date in that record set. 673 00:36:20,720 --> 00:36:21,680 In this case, 674 00:36:21,720 --> 00:36:23,240 let's say I try sysdate first, 675 00:36:25,000 --> 00:36:26,580 front key would not have been expected, 676 00:36:28,060 --> 00:36:28,460 sysdate, 677 00:36:30,160 --> 00:36:31,400 sysdate may not be a function, 678 00:36:31,520 --> 00:36:32,560 it just may be a normal term, 679 00:36:32,700 --> 00:36:32,940 one sec. 680 00:36:38,700 --> 00:36:39,360 There you go. 681 00:36:39,500 --> 00:36:40,720 It doesn't like sysdate, 682 00:36:40,800 --> 00:36:41,320 which by the way, 683 00:36:41,360 --> 00:36:41,920 case sensitive, 684 00:36:42,600 --> 00:36:42,860 like that. 685 00:36:43,420 --> 00:36:44,660 But let's say we make it one, 686 00:36:45,420 --> 00:36:46,760 and it gets happy. 687 00:36:47,640 --> 00:36:48,260 Gets happy. 688 00:36:48,340 --> 00:36:49,120 Real technical here. 689 00:36:52,220 --> 00:36:53,880 So I don't have any questions at this point. 690 00:36:53,980 --> 00:36:55,780 I've been moving kind of quickly and haphazardly. 691 00:36:55,880 --> 00:36:56,620 Anyone want to know anything? 692 00:37:00,260 --> 00:37:01,720 Yeah, and that's what we do here, 693 00:37:01,760 --> 00:37:02,160 in this one, 694 00:37:02,320 --> 00:37:03,740 which is still trying to load 695 00:37:03,740 --> 00:37:04,920 for some silly reason. 696 00:37:09,660 --> 00:37:10,580 Top ten, what? 697 00:37:12,720 --> 00:37:13,480 The loading, 698 00:37:14,080 --> 00:37:16,320 this is on like a VMware box with no RAM, 699 00:37:16,460 --> 00:37:17,520 so if it's taking a long time, 700 00:37:17,580 --> 00:37:18,660 we can't do much about it. 701 00:37:19,540 --> 00:37:20,460 You see here, 702 00:37:20,540 --> 00:37:21,620 line is a number, 703 00:37:21,740 --> 00:37:23,420 and in order to get it to return it, 704 00:37:26,500 --> 00:37:27,360 in the column, 705 00:37:28,780 --> 00:37:30,440 yeah, this one just takes a long time. 706 00:37:31,900 --> 00:37:33,600 Let's limit this with where, 707 00:37:37,000 --> 00:37:37,380 ronum, 708 00:37:38,100 --> 00:37:39,040 it's less than one, 709 00:37:39,100 --> 00:37:39,960 ronum, very useful. 710 00:37:46,520 --> 00:37:48,640 It still may actually go through 711 00:37:48,640 --> 00:37:49,360 and seek all of them, 712 00:37:49,400 --> 00:37:51,180 and only return what ronum is less than one. 713 00:37:52,120 --> 00:37:52,520 Anyway, 714 00:37:53,220 --> 00:37:53,840 I don't, 715 00:37:53,860 --> 00:37:55,140 we don't have probably time for this. 716 00:37:55,140 --> 00:37:56,500 I don't want to cut into the next speaker's time. 717 00:37:57,900 --> 00:37:59,360 We have two char here, 718 00:37:59,580 --> 00:38:01,300 and we're using this to convert line, 719 00:38:01,540 --> 00:38:02,220 which is a number, 720 00:38:02,300 --> 00:38:05,200 so we can do our character type matching to that. 721 00:38:06,100 --> 00:38:07,560 Other good stuff you can find, 722 00:38:14,920 --> 00:38:17,520 this whole thing may be waiting on the queries that may run, 723 00:38:17,640 --> 00:38:19,140 whether or not I've canceled this thing. 724 00:38:19,620 --> 00:38:21,940 You can get the name of the operating system, 725 00:38:22,760 --> 00:38:24,980 the operating system user you are running under 726 00:38:26,920 --> 00:38:28,040 using this query, 727 00:38:29,900 --> 00:38:30,300 syscontext. 728 00:38:30,480 --> 00:38:31,660 Oh, that's right, I should go through that. 729 00:38:32,680 --> 00:38:34,880 There is a function in Oracle. 730 00:38:35,060 --> 00:38:36,980 Most functions are stuff like to char. 731 00:38:37,840 --> 00:38:39,040 Most functions, you know, 732 00:38:39,040 --> 00:38:40,360 are things like they're going to help you add, 733 00:38:40,540 --> 00:38:41,860 divide, multiply, subtract, 734 00:38:42,040 --> 00:38:42,580 or plug in, 735 00:38:42,600 --> 00:38:43,380 put data types together, 736 00:38:43,440 --> 00:38:44,140 things like that. 737 00:38:44,460 --> 00:38:45,780 There's a very interesting one 738 00:38:47,120 --> 00:38:47,560 called, 739 00:38:47,760 --> 00:38:48,180 union, 740 00:38:49,060 --> 00:38:50,740 it's called syscontext. 741 00:38:50,980 --> 00:38:52,240 It returns information 742 00:38:53,100 --> 00:38:55,000 about the current session you're in. 743 00:38:55,960 --> 00:38:57,220 You give it a table space, 744 00:38:57,440 --> 00:38:59,000 which the one you want to use is userN, 745 00:38:59,080 --> 00:39:00,800 if it's probably the only ones you have permissions to, 746 00:39:01,460 --> 00:39:02,780 and you can get interesting stuff. 747 00:39:03,100 --> 00:39:05,540 And the second argument in the syscontext function, 748 00:39:08,120 --> 00:39:08,820 for instance, 749 00:39:08,960 --> 00:39:09,600 IP address. 750 00:39:09,880 --> 00:39:11,680 It will tell you the IP address 751 00:39:11,680 --> 00:39:12,580 of the box you're running under. 752 00:39:12,600 --> 00:39:12,700 Hang on. 753 00:39:12,940 --> 00:39:14,580 You select syscontext there. 754 00:39:15,220 --> 00:39:16,660 Of course, we have three columns. 755 00:39:20,500 --> 00:39:21,360 We're going to use dual. 756 00:39:21,720 --> 00:39:23,320 Don't have to bother with going to a real table. 757 00:39:23,460 --> 00:39:24,600 We'll just return back what we want, 758 00:39:24,700 --> 00:39:25,380 syscontext. 759 00:39:30,920 --> 00:39:31,920 Missing select keyword. 760 00:39:32,520 --> 00:39:33,460 I'm a real genius. 761 00:39:33,680 --> 00:39:35,080 You've all figured it out by now. 762 00:39:35,780 --> 00:39:36,480 There we go. 763 00:39:38,160 --> 00:39:40,720 And we get back an IP address. 764 00:39:40,860 --> 00:39:42,120 Now, you're noticing, of course, 765 00:39:42,120 --> 00:39:44,360 this is 192.168, 766 00:39:44,500 --> 00:39:45,500 which is, of course, disappointing. 767 00:39:45,680 --> 00:39:46,960 I'll tell you two reasons that's happening. 768 00:39:47,360 --> 00:39:48,700 One reason is, of course, 769 00:39:48,700 --> 00:39:49,860 I'm not connected to a LAN. 770 00:39:49,940 --> 00:39:51,640 That's really this box's only IP address. 771 00:39:55,300 --> 00:39:57,000 The second reason it's happening 772 00:39:57,000 --> 00:39:59,240 is because there's certain ways of configuring Oracle 773 00:39:59,240 --> 00:40:00,860 that it's the only Ethernet adapter 774 00:40:00,860 --> 00:40:02,760 that it will recognize as your local one. 775 00:40:03,540 --> 00:40:06,660 However, this information is still very, very useful 776 00:40:07,260 --> 00:40:10,320 because we can, using our HTTP proxy, 777 00:40:10,320 --> 00:40:14,900 we now know what to start scanning for 778 00:40:14,900 --> 00:40:18,520 when we, like, for instance, 779 00:40:22,480 --> 00:40:24,180 we've already determined that we can use 780 00:40:25,920 --> 00:40:28,940 utlhttp.request to pull information back. 781 00:40:30,360 --> 00:40:32,380 And what you can do is you can set up a script 782 00:40:32,380 --> 00:40:35,800 that'll try 192.168. 783 00:40:35,840 --> 00:40:37,140 This is stuff on the internal network. 784 00:40:37,180 --> 00:40:38,820 Obviously, you can't get it from the net, 785 00:40:38,880 --> 00:40:40,260 but if you can SQL inject to an org, 786 00:40:40,320 --> 00:40:40,620 to an Oracle host, 787 00:40:40,800 --> 00:40:42,280 you can get your information back. 788 00:40:42,480 --> 00:40:44,540 You can start at, you know, .1, .0. 789 00:40:45,180 --> 00:40:46,340 You can make that request. 790 00:40:46,780 --> 00:40:48,140 See if there's a web server there. 791 00:40:48,260 --> 00:40:49,460 If you don't, if you get a null response, 792 00:40:49,800 --> 00:40:50,540 there's nothing there. 793 00:40:51,400 --> 00:40:53,040 Try two and try three, 794 00:40:53,100 --> 00:40:53,920 and you can work that way, 795 00:40:53,960 --> 00:40:55,360 and you can basically turn the Oracle box 796 00:40:55,360 --> 00:40:56,840 into an HTTP port scanner. 797 00:40:57,140 --> 00:40:58,940 And if there are Internet web servers running, 798 00:40:59,080 --> 00:41:00,400 they're going to have interesting stuff on them. 799 00:41:00,500 --> 00:41:00,740 Yes, sir? 800 00:41:00,940 --> 00:41:01,340 . 801 00:41:02,700 --> 00:41:03,440 Yeah, absolutely. 802 00:41:03,700 --> 00:41:05,160 This works pretty standard sequence. 803 00:41:05,440 --> 00:41:07,020 One thing I tried, I was disappointed, 804 00:41:07,200 --> 00:41:07,920 does not work. 805 00:41:08,020 --> 00:41:10,240 I know you can, 806 00:41:10,320 --> 00:41:14,660 not do, like, file colon slash slash, 807 00:41:14,800 --> 00:41:15,500 and that pissed me off, 808 00:41:15,580 --> 00:41:16,360 because I was hoping for that. 809 00:41:16,400 --> 00:41:17,620 You could pull files from the local host. 810 00:41:18,160 --> 00:41:18,520 Yeah? 811 00:41:19,320 --> 00:41:19,680 What? 812 00:41:24,520 --> 00:41:27,220 Your question requires a pretty lengthy answer. 813 00:41:27,300 --> 00:41:27,900 I'll get to it in a minute. 814 00:41:28,220 --> 00:41:29,640 Yours, yeah, you can do HTTPS. 815 00:41:30,580 --> 00:41:32,420 It'll do all the negotiated stuff for you. 816 00:41:32,500 --> 00:41:32,740 Yeah? 817 00:41:33,780 --> 00:41:34,140 . 818 00:41:34,720 --> 00:41:36,580 Can you do, like, any other characters 819 00:41:36,580 --> 00:41:37,680 besides the single quote 820 00:41:37,680 --> 00:41:38,680 to break out of the, 821 00:41:38,680 --> 00:41:40,540 you know, the, 822 00:41:40,660 --> 00:41:41,020 the, 823 00:41:41,020 --> 00:41:41,660 the block? 824 00:41:43,180 --> 00:41:44,340 Um, generally not. 825 00:41:45,380 --> 00:41:47,040 Uh, if you can use parentheses. 826 00:41:47,860 --> 00:41:50,080 I haven't actually tested on this one, 827 00:41:50,240 --> 00:41:51,240 but let's see. 828 00:41:52,280 --> 00:41:52,680 I, 829 00:41:53,220 --> 00:41:54,180 he wants to know, 830 00:41:54,220 --> 00:41:56,780 let's say that you can't get, 831 00:41:56,840 --> 00:41:57,160 um, 832 00:41:57,800 --> 00:41:58,980 single quotes through the, 833 00:41:59,060 --> 00:42:00,400 the web server is your question, right? 834 00:42:00,760 --> 00:42:03,300 The web application's filtering out single quotes. 835 00:42:03,380 --> 00:42:04,540 You want enough so you can use double quotes 836 00:42:04,540 --> 00:42:05,240 and stuff like that? 837 00:42:05,440 --> 00:42:06,700 Uh, double quotes, I'll tell you, 838 00:42:06,720 --> 00:42:07,300 will not work. 839 00:42:07,300 --> 00:42:08,520 What you want to look for, 840 00:42:08,580 --> 00:42:09,880 and I don't have the information in front of me, 841 00:42:09,920 --> 00:42:10,280 I'm sorry, 842 00:42:10,400 --> 00:42:11,160 when I post the information, 843 00:42:11,260 --> 00:42:11,820 I'll get it to you, 844 00:42:12,700 --> 00:42:13,660 is, uh, like, 845 00:42:13,740 --> 00:42:15,040 if there's a char function, for instance, 846 00:42:15,580 --> 00:42:16,740 that's gonna be a good, bad one. 847 00:42:19,720 --> 00:42:20,560 Let's see if we get, uh, 848 00:42:20,560 --> 00:42:21,540 a character in the first column. 849 00:42:30,240 --> 00:42:30,940 Just an exploration. 850 00:42:31,160 --> 00:42:32,040 No, I don't have sequel, 851 00:42:32,160 --> 00:42:34,280 syntax information for this in front of me. 852 00:42:34,740 --> 00:42:36,300 Uh, I'll find out about that, though. 853 00:42:36,780 --> 00:42:37,600 Yes, sir, back there? 854 00:42:37,800 --> 00:42:39,260 What if you use the hex code? 855 00:42:40,120 --> 00:42:41,180 The hex code in here, 856 00:42:41,300 --> 00:42:41,920 and the char function? 857 00:42:42,460 --> 00:42:43,520 No, just, like, 858 00:42:43,680 --> 00:42:44,400 you know, 859 00:42:44,460 --> 00:42:45,900 a percentage hex code, 860 00:42:46,040 --> 00:42:46,540 but... 861 00:42:46,540 --> 00:42:47,340 Your web server, 862 00:42:47,940 --> 00:42:48,420 when it, 863 00:42:48,440 --> 00:42:49,700 when it gets to the web server, 864 00:42:49,740 --> 00:42:51,220 the web server will understand that, 865 00:42:52,280 --> 00:42:54,480 but what it will do is it will convert that 866 00:42:54,480 --> 00:42:55,340 to the real character 867 00:42:55,920 --> 00:42:57,940 before the ASP script gets a hold of it. 868 00:42:58,160 --> 00:42:59,920 So the ASP script will see, 869 00:43:00,000 --> 00:43:01,360 not the hex escape code, 870 00:43:01,760 --> 00:43:02,960 it'll see the real character, 871 00:43:03,080 --> 00:43:04,600 and if it's told to block single quotes, 872 00:43:04,760 --> 00:43:05,740 even if you have some coded, 873 00:43:05,740 --> 00:43:06,740 it'll still block it. 874 00:43:07,500 --> 00:43:08,100 Yes, sir? 875 00:43:08,360 --> 00:43:09,320 Uh, do you know why 876 00:43:09,320 --> 00:43:10,640 single quotes do not work? 877 00:43:10,860 --> 00:43:12,760 It does not until 4.0. 878 00:43:13,180 --> 00:43:14,820 It does not until 4.0, 879 00:43:14,840 --> 00:43:15,600 this man right here says. 880 00:43:17,320 --> 00:43:17,720 Um, 881 00:43:19,140 --> 00:43:20,440 the other question about, 882 00:43:20,620 --> 00:43:20,920 is there, 883 00:43:20,960 --> 00:43:22,540 do you have XP command shell, 884 00:43:22,660 --> 00:43:24,080 do you have arbitrary command execution? 885 00:43:25,000 --> 00:43:25,400 Uh, 886 00:43:25,940 --> 00:43:27,440 the answer to that is, 887 00:43:27,560 --> 00:43:28,760 I haven't found a way yet. 888 00:43:28,860 --> 00:43:29,860 I'm still working on it. 889 00:43:29,920 --> 00:43:30,640 The problem with this is 890 00:43:30,640 --> 00:43:31,820 I'm not an Oracle DBA. 891 00:43:32,120 --> 00:43:33,840 I'm a web application security guy. 892 00:43:34,360 --> 00:43:35,720 So there are all kinds of stuff 893 00:43:35,740 --> 00:43:37,340 in Oracle that I've been looking through. 894 00:43:37,500 --> 00:43:38,800 One thing I will tell you, 895 00:43:38,860 --> 00:43:40,800 and that anyone who's done this with SQL Server loves, 896 00:43:41,000 --> 00:43:41,780 is you can use 897 00:43:42,500 --> 00:43:42,980 semicolon 898 00:43:43,660 --> 00:43:45,280 to do multiple command statements. 899 00:43:45,860 --> 00:43:47,760 The Oracle ODBC driver 900 00:43:47,760 --> 00:43:49,380 will not let you pass 901 00:43:49,380 --> 00:43:50,360 a semicolon. 902 00:43:50,420 --> 00:43:52,080 The semicolons will never see the web server, 903 00:43:52,320 --> 00:43:53,320 and you'll, the, 904 00:43:53,460 --> 00:43:55,000 and you'll get an error message back. 905 00:43:55,400 --> 00:43:56,900 As far as arbitrage, 906 00:43:57,100 --> 00:43:58,340 is there a stored procedure 907 00:43:58,340 --> 00:44:00,240 to execute OS level commands? 908 00:44:00,520 --> 00:44:01,500 I don't think there is. 909 00:44:02,080 --> 00:44:02,900 Sir, over here. 910 00:44:03,180 --> 00:44:03,500 Yeah, 911 00:44:03,500 --> 00:44:04,960 I've run the metric 912 00:44:04,960 --> 00:44:05,420 to, 913 00:44:05,740 --> 00:44:07,880 to run the site on .NET 914 00:44:07,880 --> 00:44:09,340 of secure.net. 915 00:44:09,600 --> 00:44:10,320 Mm-hmm. 916 00:44:10,360 --> 00:44:10,920 It's really funny. 917 00:44:11,500 --> 00:44:12,140 It's a, 918 00:44:12,260 --> 00:44:14,120 it's a good forcer 919 00:44:14,120 --> 00:44:14,940 for Oracle, 920 00:44:15,740 --> 00:44:17,260 and it also 921 00:44:17,260 --> 00:44:18,080 uploads 922 00:44:18,080 --> 00:44:20,020 the TV doc 923 00:44:20,740 --> 00:44:21,260 and, 924 00:44:21,360 --> 00:44:23,760 and executes it. 925 00:44:24,000 --> 00:44:24,160 Yeah. 926 00:44:24,220 --> 00:44:25,280 And it's also, 927 00:44:27,640 --> 00:44:29,580 it works also for, 928 00:44:29,660 --> 00:44:30,540 for . 929 00:44:31,480 --> 00:44:32,800 Okay, what he's saying is that, 930 00:44:32,900 --> 00:44:34,140 what is the URL there again? 931 00:44:34,660 --> 00:44:35,300 What? 932 00:44:35,740 --> 00:44:36,640 Your friend's site. 933 00:44:36,800 --> 00:44:37,180 What is the, 934 00:44:37,280 --> 00:44:38,180 where can you get the tool? 935 00:44:39,220 --> 00:44:39,580 Hmm? 936 00:44:39,800 --> 00:44:40,160 . 937 00:44:41,000 --> 00:44:42,300 I don't have a net access 938 00:44:42,300 --> 00:44:43,000 on this right now. 939 00:44:43,080 --> 00:44:43,900 Can you just tell us again? 940 00:44:44,820 --> 00:44:45,180 . 941 00:44:46,400 --> 00:44:46,760 Yeah. 942 00:44:47,160 --> 00:44:47,520 . 943 00:44:48,480 --> 00:44:48,840 . 944 00:44:49,520 --> 00:44:49,880 Okay. 945 00:44:50,120 --> 00:44:51,480 While he's running up here, 946 00:44:51,940 --> 00:44:52,300 I'm, 947 00:44:52,340 --> 00:44:53,180 I'm gonna tell you that 948 00:44:53,180 --> 00:44:54,560 my presentation is covering 949 00:44:54,560 --> 00:44:55,320 clean things you can do 950 00:44:55,320 --> 00:44:56,060 with SQL injections. 951 00:44:56,360 --> 00:44:56,600 . 952 00:44:57,380 --> 00:44:58,320 Just type it up there. 953 00:44:58,360 --> 00:44:58,800 People see it. 954 00:44:59,540 --> 00:45:00,140 Is that, 955 00:45:00,180 --> 00:45:01,460 of course there are, 956 00:45:01,540 --> 00:45:02,500 you've got buffer overflow 957 00:45:02,500 --> 00:45:03,660 exports for Oracle. 958 00:45:03,800 --> 00:45:04,400 You've got privilege 959 00:45:04,400 --> 00:45:05,480 escalation techniques. 960 00:45:05,680 --> 00:45:06,940 My presentation isn't 961 00:45:06,940 --> 00:45:07,480 all in that stuff. 962 00:45:07,620 --> 00:45:08,760 That's database layer security. 963 00:45:08,960 --> 00:45:10,260 I'm doing web application stuff 964 00:45:10,260 --> 00:45:10,900 just showing you, 965 00:45:10,900 --> 00:45:11,620 you what you can do 966 00:45:11,620 --> 00:45:13,220 without getting to Oracle 967 00:45:13,220 --> 00:45:14,320 specific exploits. 968 00:45:14,600 --> 00:45:15,600 If you guys, 969 00:45:15,620 --> 00:45:15,920 you know, 970 00:45:15,940 --> 00:45:16,660 follow bug track, 971 00:45:16,800 --> 00:45:17,580 there's a ton of ways 972 00:45:17,580 --> 00:45:18,580 that once you are really 973 00:45:18,580 --> 00:45:19,720 putting information in there, 974 00:45:19,860 --> 00:45:20,820 you can, 975 00:45:20,860 --> 00:45:21,960 you can use buffer overflows. 976 00:45:22,040 --> 00:45:23,320 You can probably get OS commands 977 00:45:23,320 --> 00:45:23,860 executed. 978 00:45:24,220 --> 00:45:24,700 But, 979 00:45:24,820 --> 00:45:25,700 for instance, 980 00:45:25,780 --> 00:45:26,540 in SQL Server, 981 00:45:26,660 --> 00:45:27,500 in MS SQL Server, 982 00:45:27,600 --> 00:45:28,320 they have a procedure 983 00:45:28,320 --> 00:45:29,660 called XP command shell 984 00:45:29,660 --> 00:45:31,360 that very cleanly 985 00:45:31,360 --> 00:45:32,640 and with the server's permission 986 00:45:33,340 --> 00:45:34,220 will execute 987 00:45:34,220 --> 00:45:35,360 your commands for you. 988 00:45:35,380 --> 00:45:36,520 Oracle doesn't have that 989 00:45:36,520 --> 00:45:37,380 nice, easy functionality 990 00:45:37,380 --> 00:45:38,240 to get that done. 991 00:45:38,420 --> 00:45:38,760 Yes, sir. 992 00:45:47,600 --> 00:45:48,800 If you are using 993 00:45:48,800 --> 00:45:49,600 stored procedures, 994 00:45:49,900 --> 00:45:51,280 I don't have a demo web 995 00:45:51,280 --> 00:45:52,080 application for that. 996 00:45:52,200 --> 00:45:52,640 Yes, 997 00:45:53,220 --> 00:45:53,720 you can, 998 00:45:53,800 --> 00:45:54,160 you know, 999 00:45:54,240 --> 00:45:55,240 you can inject into 1000 00:45:55,240 --> 00:45:55,920 stored procedures. 1001 00:45:55,940 --> 00:45:56,540 Let's say, 1002 00:45:57,840 --> 00:45:58,280 right, 1003 00:45:58,740 --> 00:45:59,600 just a second. 1004 00:46:03,060 --> 00:46:03,980 Sorry about that. 1005 00:46:05,820 --> 00:46:06,960 Let's say that they've got, 1006 00:46:07,000 --> 00:46:07,340 you know, 1007 00:46:08,100 --> 00:46:08,740 stored procedure, 1008 00:46:08,960 --> 00:46:10,400 my stored procedure, 1009 00:46:11,520 --> 00:46:12,300 and they've got, 1010 00:46:12,720 --> 00:46:13,740 what you need to do, 1011 00:46:13,820 --> 00:46:14,520 you need to match 1012 00:46:14,520 --> 00:46:15,140 when you're breaking 1013 00:46:15,140 --> 00:46:16,200 through stored procedures, 1014 00:46:16,600 --> 00:46:17,420 is you need to match 1015 00:46:17,420 --> 00:46:18,220 the number of arguments. 1016 00:46:20,480 --> 00:46:20,800 So, 1017 00:46:20,860 --> 00:46:21,580 and you have to match 1018 00:46:21,580 --> 00:46:22,060 it at the end. 1019 00:46:22,140 --> 00:46:22,260 So, 1020 00:46:22,280 --> 00:46:22,860 let's say they've got 1021 00:46:22,860 --> 00:46:23,540 a stored procedure 1022 00:46:23,540 --> 00:46:24,960 and the correct syntax, 1023 00:46:26,400 --> 00:46:27,360 the stored procedure, 1024 00:46:27,540 --> 00:46:28,240 and I'm just typing it 1025 00:46:28,240 --> 00:46:28,460 up here. 1026 00:46:28,580 --> 00:46:29,120 This isn't, 1027 00:46:29,120 --> 00:46:29,520 you know, 1028 00:46:29,560 --> 00:46:30,080 this is obviously, 1029 00:46:30,400 --> 00:46:31,180 this is ASP. 1030 00:46:31,200 --> 00:46:32,540 This isn't how you would do it. 1031 00:46:32,780 --> 00:46:33,800 This isn't how it would appear 1032 00:46:33,800 --> 00:46:34,200 on the web application. 1033 00:46:34,200 --> 00:46:34,500 This is on the web server. 1034 00:46:34,740 --> 00:46:35,340 Great, 1035 00:46:35,360 --> 00:46:36,000 I'm losing people. 1036 00:46:36,280 --> 00:46:36,820 Bye, guys. 1037 00:46:38,780 --> 00:46:39,700 Let's say that 1038 00:46:39,920 --> 00:46:41,200 your correct syntax 1039 00:46:41,200 --> 00:46:42,160 looked like this, 1040 00:46:42,320 --> 00:46:42,540 right? 1041 00:46:43,620 --> 00:46:44,700 Three arguments. 1042 00:46:49,240 --> 00:46:50,920 And your injection, 1043 00:46:51,140 --> 00:46:52,760 and let's say you got 1044 00:46:52,760 --> 00:46:53,300 to control 1045 00:46:53,300 --> 00:46:54,480 the value 1046 00:46:54,480 --> 00:46:55,400 of the first argument, 1047 00:46:55,560 --> 00:46:55,960 right? 1048 00:46:56,660 --> 00:46:58,060 Your injection string 1049 00:46:58,060 --> 00:46:58,720 looked like 1050 00:46:58,720 --> 00:46:59,280 that, 1051 00:46:59,540 --> 00:47:00,860 union select, 1052 00:47:01,160 --> 00:47:01,800 and then blah, 1053 00:47:01,860 --> 00:47:02,160 blah, blah. 1054 00:47:03,580 --> 00:47:04,180 And, 1055 00:47:04,200 --> 00:47:04,880 and that was in there. 1056 00:47:05,280 --> 00:47:05,620 Yeah. 1057 00:47:08,540 --> 00:47:09,440 This stuff here 1058 00:47:09,440 --> 00:47:10,280 is no good 1059 00:47:10,280 --> 00:47:10,960 because this is 1060 00:47:10,960 --> 00:47:11,740 what it would look like. 1061 00:47:15,460 --> 00:47:15,800 Yeah. 1062 00:47:20,360 --> 00:47:21,020 That's obviously 1063 00:47:21,020 --> 00:47:22,000 not valid syntax. 1064 00:47:22,260 --> 00:47:22,360 So, 1065 00:47:22,400 --> 00:47:22,780 what you would have 1066 00:47:22,780 --> 00:47:23,220 to do 1067 00:47:23,740 --> 00:47:24,960 is your injection string, 1068 00:47:25,080 --> 00:47:25,560 you would have to, 1069 00:47:25,660 --> 00:47:26,020 and it'll do 1070 00:47:26,020 --> 00:47:26,620 the same way 1071 00:47:26,620 --> 00:47:27,060 it'll give you 1072 00:47:27,060 --> 00:47:27,560 an error message 1073 00:47:27,560 --> 00:47:28,220 as it'll tell you 1074 00:47:28,220 --> 00:47:28,580 when you've got 1075 00:47:28,580 --> 00:47:29,100 the wrong number 1076 00:47:29,100 --> 00:47:29,580 of columns. 1077 00:47:31,620 --> 00:47:32,360 You'd have to go 1078 00:47:32,360 --> 00:47:32,940 A, 1079 00:47:33,840 --> 00:47:34,180 A, 1080 00:47:34,180 --> 00:47:35,380 close the parenthesis, 1081 00:47:35,440 --> 00:47:36,200 send it, 1082 00:47:36,220 --> 00:47:36,660 see if you get 1083 00:47:36,660 --> 00:47:37,080 an error message. 1084 00:47:37,320 --> 00:47:37,740 If not, 1085 00:47:37,900 --> 00:47:39,040 you keep adding them 1086 00:47:39,040 --> 00:47:39,440 and eventually 1087 00:47:40,160 --> 00:47:41,140 you'd have to go like that, 1088 00:47:44,940 --> 00:47:46,160 and you'd put that in there 1089 00:47:46,160 --> 00:47:47,220 and the database server 1090 00:47:47,220 --> 00:47:48,340 would end up seeing something 1091 00:47:48,820 --> 00:47:49,840 that would look like that 1092 00:47:49,840 --> 00:47:50,760 and of course at the end 1093 00:47:50,760 --> 00:47:51,620 you would have to clean it up 1094 00:47:51,620 --> 00:47:52,220 and have something 1095 00:47:52,220 --> 00:47:53,100 with three arguments, too. 1096 00:47:53,160 --> 00:47:53,880 But you can do it. 1097 00:47:54,820 --> 00:47:55,600 Any other questions? 1098 00:47:55,780 --> 00:47:56,120 Yes here. 1099 00:47:56,760 --> 00:47:57,620 So, you've been looking 1100 00:47:57,620 --> 00:47:58,420 to a lot of websites 1101 00:47:58,420 --> 00:47:59,080 and going to assessments 1102 00:47:59,080 --> 00:47:59,620 and so forth 1103 00:47:59,620 --> 00:48:00,900 and see a lot of select statements. 1104 00:48:01,080 --> 00:48:01,600 Do you see a lot 1105 00:48:04,340 --> 00:48:07,340 Yeah, insert is vulnerable in the same kind of way. 1106 00:48:07,480 --> 00:48:12,020 The insert syntax was different, and we have time constraints here. 1107 00:48:12,160 --> 00:48:13,860 How much time do I have left here? 1108 00:48:15,780 --> 00:48:18,200 All right, yeah, like I said, if I tried to do insert, too, 1109 00:48:18,240 --> 00:48:20,120 it requires its own unique set of things to look for. 1110 00:48:20,180 --> 00:48:21,640 I just didn't have the time to present it here. 1111 00:48:22,140 --> 00:48:23,280 You can do it with insert. 1112 00:48:24,120 --> 00:48:27,820 Occasionally, you run across the sites that are running really weird-looking SQL queries. 1113 00:48:27,820 --> 00:48:32,080 If you're changing your password, it may have, like, an alter command or something like that. 1114 00:48:32,440 --> 00:48:36,020 Nearly anything is injectable as long as your web application 1115 00:48:36,020 --> 00:48:39,280 is not protecting against single quotes and stuff like that. 1116 00:48:40,240 --> 00:48:41,180 Any other questions? 1117 00:48:41,900 --> 00:48:44,740 Can you do a quick round, or what we need to do is tighten it up? 1118 00:48:45,560 --> 00:48:46,540 Just tighten it up. 1119 00:48:46,540 --> 00:48:48,080 Yeah, I guess some people here want to know that. 1120 00:48:50,580 --> 00:48:52,740 Here is a real simple... 1121 00:48:53,420 --> 00:48:55,020 I'm about to release... 1122 00:48:55,020 --> 00:48:57,720 Check www.spydynamics.com. 1123 00:48:57,820 --> 00:48:58,780 SPI is S-P-I. 1124 00:48:58,980 --> 00:48:59,980 There's about to be... 1125 00:48:59,980 --> 00:49:03,440 I have a whole paper written on secure web application and database server interaction, 1126 00:49:04,700 --> 00:49:08,520 which covers what you need to do to tighten up in terms of web application 1127 00:49:08,520 --> 00:49:11,660 and how to lock down your database server with correct roles and permissions 1128 00:49:11,660 --> 00:49:17,000 in case, if someone can inject, the amount of damage they can do is greatly minimized. 1129 00:49:18,200 --> 00:49:19,380 So let's look at... 1130 00:49:19,380 --> 00:49:22,320 Let's take fonder.asp, and let's say... 1131 00:49:25,280 --> 00:49:26,480 See, email request. 1132 00:49:26,620 --> 00:49:27,800 That's where it pulls it. 1133 00:49:27,820 --> 00:49:28,120 That's where it pulls it off. 1134 00:49:29,460 --> 00:49:32,180 That's where it pulls your user argument from your UI out. 1135 00:49:32,340 --> 00:49:34,320 Let's say we did two things here. 1136 00:49:35,760 --> 00:49:36,120 Replace... 1137 00:49:38,020 --> 00:49:38,380 What's that? 1138 00:49:39,560 --> 00:49:42,120 I'm not an ASP programmer, and I don't intend to be, 1139 00:49:42,180 --> 00:49:43,960 but this is what I had in front of me when I had to build this. 1140 00:49:46,320 --> 00:49:47,820 Replace single quote with... 1141 00:49:49,120 --> 00:49:50,740 Let's say this is what PHP does. 1142 00:49:51,860 --> 00:49:53,980 Backslash single quote, or you can do it with null. 1143 00:49:54,340 --> 00:49:57,380 It'll kick all of the single quotes out of there. 1144 00:49:58,080 --> 00:49:59,180 What else you might want to do? 1145 00:50:05,160 --> 00:50:05,800 Replace commas. 1146 00:50:06,760 --> 00:50:08,540 What does an email address need commas in it for? 1147 00:50:10,520 --> 00:50:13,240 Replace it with a bad character, or for instance, nothing. 1148 00:50:16,200 --> 00:50:16,520 Yeah? 1149 00:50:17,820 --> 00:50:21,920 Yeah, the best way to do it is to regex everything else out, 1150 00:50:22,080 --> 00:50:24,500 but I don't even know how to run regex on ASP. 1151 00:50:24,580 --> 00:50:25,540 It probably doesn't support it. 1152 00:50:26,640 --> 00:50:27,680 It does? Thank you, Phil. 1153 00:50:33,740 --> 00:50:36,280 Like I said, I'll have all this in a paper, proper. 1154 00:50:36,760 --> 00:50:39,320 Default and eye filtering is always the best way to do things. 1155 00:50:39,740 --> 00:50:41,580 This is basic stuff you can do real quick. 1156 00:50:44,480 --> 00:50:47,520 Other stuff you want to do is simply limit the length. 1157 00:50:49,380 --> 00:50:50,700 You would do that real easy. 1158 00:50:50,800 --> 00:50:52,840 Email equals left. 1159 00:50:56,460 --> 00:50:57,680 No, not quote email. 1160 00:50:57,820 --> 00:51:01,580 Email, and I think that's the correct syntax on the ASP programmer. 1161 00:51:02,340 --> 00:51:03,920 You would limit it to 10 characters. 1162 00:51:04,260 --> 00:51:06,920 You're not going to be able to do a whole lot in SQL 1163 00:51:06,920 --> 00:51:09,640 with only 10 characters to clean everything up 1164 00:51:09,640 --> 00:51:10,840 and get what you want back. 1165 00:51:11,220 --> 00:51:12,540 So those are your quick steps. 1166 00:51:14,460 --> 00:51:16,160 Default and eye filtering, like this guy said, 1167 00:51:16,220 --> 00:51:16,960 he was completely right. 1168 00:51:17,020 --> 00:51:17,840 I wasn't thinking up here. 1169 00:51:18,580 --> 00:51:21,300 And limiting length, and also data type. 1170 00:51:21,640 --> 00:51:24,660 If your argument, in this case, it's a string, 1171 00:51:24,760 --> 00:51:26,500 but if your argument is a numeric type, 1172 00:51:26,640 --> 00:51:27,680 and someone is trying, 1173 00:51:27,680 --> 00:51:29,020 and you're trying to pass letters into it, 1174 00:51:29,060 --> 00:51:30,340 it goes with the deny filtering, 1175 00:51:30,540 --> 00:51:31,220 don't let them do that. 1176 00:51:32,340 --> 00:51:34,500 Other things you want to do is on the database server. 1177 00:51:34,760 --> 00:51:36,800 It's a really bad idea to let the web application 1178 00:51:36,800 --> 00:51:41,400 access your database server with DBA privileges and stuff. 1179 00:51:41,640 --> 00:51:43,660 What you want to do is you want to take 1180 00:51:43,660 --> 00:51:46,240 all the functionality of your web application, 1181 00:51:46,420 --> 00:51:47,500 break it down into roles, 1182 00:51:48,140 --> 00:51:49,820 logically break that down into users, 1183 00:51:50,080 --> 00:51:52,760 and default, deny, and only grant those users 1184 00:51:52,760 --> 00:51:55,340 the right to execute certain stored procedures. 1185 00:51:55,780 --> 00:51:56,600 It's another thing. 1186 00:51:56,600 --> 00:51:58,460 Try to stay away from building SQL statements. 1187 00:51:58,660 --> 00:51:59,400 It's not a great idea. 1188 00:51:59,760 --> 00:52:02,680 You're much better off using prepared statements 1189 00:52:02,680 --> 00:52:03,480 and stored procedures. 1190 00:52:03,660 --> 00:52:06,140 That gets into the database programming, 1191 00:52:06,420 --> 00:52:07,800 which this isn't a presentation on. 1192 00:52:08,300 --> 00:52:10,180 Like I said, there'll be a separate paper on this. 1193 00:52:10,240 --> 00:52:11,980 This is really a demonstration of attack techniques. 1194 00:52:12,300 --> 00:52:12,600 Yes, sir? 1195 00:52:12,840 --> 00:52:15,520 This also works pretty easily for a service. 1196 00:52:15,940 --> 00:52:17,900 If you just put in really complex query statements. 1197 00:52:18,660 --> 00:52:19,980 There is all kinds of stuff, 1198 00:52:20,080 --> 00:52:21,240 particularly if you're in DBA, 1199 00:52:21,400 --> 00:52:22,840 you can go to those system tables, 1200 00:52:22,900 --> 00:52:24,400 like all tables or all columns. 1201 00:52:24,820 --> 00:52:26,500 You can start messing with stuff. 1202 00:52:26,500 --> 00:52:29,240 And their database will probably stop working. 1203 00:52:31,160 --> 00:52:32,300 Have any other questions? 1204 00:52:34,680 --> 00:52:36,880 Okay, I think I am done up here then. 1205 00:52:36,960 --> 00:52:39,620 I apologize again for having this put on together so quickly. 1206 00:52:47,400 --> 00:52:48,820 Thank you very much. 1207 00:52:48,980 --> 00:52:50,080 If you want more in-