1 00:00:00,000 --> 00:00:08,120 Hello and good afternoon, everyone. My name is Sid, and I'll be talking about how SQL injection worms can affect the Oracle applications. 2 00:00:08,800 --> 00:00:14,860 Most of you must be aware that there was a worm which affected the Internet like a year ago. 3 00:00:14,960 --> 00:00:18,220 That mainly targeted the MSSQL backend database. 4 00:00:18,500 --> 00:00:22,860 So I'm going to be presenting how these worms could target the Oracle applications. 5 00:00:24,040 --> 00:00:28,540 A little bit about me. I work as a senior IT security consultant in the UK. 6 00:00:28,540 --> 00:00:31,040 And that's my blog, not-so-secure.com. 7 00:00:31,400 --> 00:00:34,000 All the tools and the demos will be available on this blog. 8 00:00:35,420 --> 00:00:39,400 I'm a little bit pressed for time, so if you can keep your questions to the end. 9 00:00:39,460 --> 00:00:44,220 And if I'm not able to answer them, just catch me after the talk, and I'm happy to answer them. 10 00:00:46,060 --> 00:00:47,320 So let's get started. 11 00:00:48,140 --> 00:00:54,620 When we talk about SQL injection in Oracle, there can be two broad categories, depending on where your injection point is. 12 00:00:54,940 --> 00:00:58,140 Your injection point could be in an anonymous PLSQL blog. 13 00:00:58,540 --> 00:01:00,780 Which will typically be called as a PLSQL injection. 14 00:01:01,320 --> 00:01:05,380 Or you can have the injection in a single SQL statement, like a SELECT query. 15 00:01:05,720 --> 00:01:10,140 So a common example is a WHERE clause in a SELECT query, where you have your injection point. 16 00:01:11,120 --> 00:01:15,420 So, if you have a PLSQL injection, mostly things are quite straightforward. 17 00:01:16,040 --> 00:01:20,700 It is more or less like having an SQL plus access to an Oracle backend. 18 00:01:20,960 --> 00:01:25,500 Where you can just copy-paste stuff, or you know, just write, just throw queries to it, and it will get executed. 19 00:01:26,520 --> 00:01:27,800 Things get a little difficult. 20 00:01:27,800 --> 00:01:32,720 When you are encountering SQL injection in a single SQL statement, like SELECT query. 21 00:01:33,960 --> 00:01:35,640 Why are they different? 22 00:01:35,840 --> 00:01:40,180 That's because if you have the injection in the SQL statements, like SELECT query, 23 00:01:40,440 --> 00:01:45,020 then Oracle by design does not support semicolon in the single SQL statements. 24 00:01:45,340 --> 00:01:47,960 So you cannot end the query and do like, create function. 25 00:01:48,340 --> 00:01:52,540 So it gets a little difficult if you are encountering injections there. 26 00:01:53,280 --> 00:01:56,260 But if it's a PLSQL injection, things are quite straightforward. 27 00:01:56,620 --> 00:01:57,780 You can execute DLN. 28 00:01:57,780 --> 00:01:58,840 You can execute DML or DDL statements. 29 00:01:59,140 --> 00:02:01,560 You can use autonomous transaction to commit changes. 30 00:02:02,140 --> 00:02:03,860 And all in all, things are quite easy. 31 00:02:04,140 --> 00:02:06,260 I'll touch upon the SQL injection a little later. 32 00:02:07,300 --> 00:02:12,400 So this is how a typical PLSQL injection would look like. 33 00:02:12,900 --> 00:02:17,480 Over here, I've created a sample procedure called orassso.test. 34 00:02:17,620 --> 00:02:18,600 It takes a variable. 35 00:02:18,880 --> 00:02:25,860 And that variable basically then gets embedded into a begin and strings. 36 00:02:26,280 --> 00:02:27,560 And it basically is used. 37 00:02:27,780 --> 00:02:31,620 In construction of an anonymous PLSQL block, which then gets dynamically executed. 38 00:02:32,100 --> 00:02:35,020 So over here, you can clearly see it's a PLSQL injection. 39 00:02:35,360 --> 00:02:37,960 And you can take control of that PLSQL block. 40 00:02:38,500 --> 00:02:44,000 So you can provide that parameter Q as a null and then execute immediate, 41 00:02:44,340 --> 00:02:45,700 maybe grant DBA to public. 42 00:02:46,640 --> 00:02:48,760 So over here, you don't have any restrictions. 43 00:02:49,120 --> 00:02:52,920 You can use semicolon and execute multiple statements. 44 00:02:53,200 --> 00:02:56,320 As I said, exploitation is fairly straightforward. 45 00:02:58,100 --> 00:03:00,460 So when we are talking about web applications, 46 00:03:00,820 --> 00:03:04,340 when will you typically encounter a PLSQL injection from web applications? 47 00:03:04,860 --> 00:03:07,820 A classical example of this is Oracle application servers. 48 00:03:08,120 --> 00:03:13,040 Now, Oracle application servers have had a series of vulnerability in the past. 49 00:03:13,280 --> 00:03:16,840 This particular example was a flaw in the PLSQL gateway, 50 00:03:17,080 --> 00:03:19,300 which was fixed by Oracle in 2006. 51 00:03:19,760 --> 00:03:25,180 And the idea to show this as an example is not to demonstrate a vulnerability which was fixed in 2006, 52 00:03:25,180 --> 00:03:30,740 but to give you a general idea of how do you go about exploiting PLSQL injection from web applications. 53 00:03:31,500 --> 00:03:37,420 So over here, this is how a standard Oracle application server's URL looks like. 54 00:03:37,900 --> 00:03:41,340 The part after PLS is called DAD, database access descriptor. 55 00:03:41,680 --> 00:03:45,180 So this vulnerability allowed you to inject arbitrary PLSQL. 56 00:03:45,780 --> 00:03:50,400 But the PLSQL which you inject gets executed with the privileges of the DAD user. 57 00:03:51,780 --> 00:03:54,140 So now, from here on, you can... 58 00:03:55,180 --> 00:03:56,500 As long as you can execute PLSQL, 59 00:03:56,800 --> 00:04:02,380 you will then be able to exploit the vulnerable packages stored in the backend database, 60 00:04:02,660 --> 00:04:06,240 and then, using the vulnerabilities in them, 61 00:04:06,660 --> 00:04:08,040 exploit them and become DBA. 62 00:04:08,440 --> 00:04:12,220 Once you become DBA, then you will be able to do nasty things like OS code execution. 63 00:04:13,760 --> 00:04:15,060 In this particular example, 64 00:04:16,020 --> 00:04:18,940 this DAD user happens to be a really low-privileged user. 65 00:04:19,240 --> 00:04:21,360 It's called ORA SSO underscore public. 66 00:04:21,680 --> 00:04:23,280 SSO stands for single sign-on. 67 00:04:23,280 --> 00:04:26,380 It's one of the default packages which it comes... 68 00:04:26,380 --> 00:04:28,640 Ships with when you install Oracle application servers. 69 00:04:29,100 --> 00:04:32,200 So this user doesn't even have the create function privileges. 70 00:04:32,560 --> 00:04:35,600 So, I mean, to get past that, 71 00:04:35,680 --> 00:04:38,600 you use something called as cursor-based injection exploits. 72 00:04:38,720 --> 00:04:41,220 And there are tons of them available on Millworm. 73 00:04:42,860 --> 00:04:46,200 Once you become DBA, then you can execute OS code. 74 00:04:46,480 --> 00:04:51,800 Again, in an earlier talk, someone touched about how do you go about executing OS code. 75 00:04:51,980 --> 00:04:53,200 I'll be showing a small example. 76 00:04:53,280 --> 00:04:53,740 For example, with Java. 77 00:04:55,520 --> 00:04:58,420 So, I wrote a simple Perl script called OAP Hacker, 78 00:04:58,580 --> 00:05:00,440 which basically exploits this flaw. 79 00:05:00,900 --> 00:05:02,780 I'm going to show a quick demo of this. 80 00:05:03,800 --> 00:05:05,240 So, what I said earlier, 81 00:05:06,260 --> 00:05:08,800 this demo is basically to prove how to... 82 00:05:08,800 --> 00:05:11,700 How do you go about exploiting PL-SQL injection from web applications. 83 00:05:25,320 --> 00:05:25,740 Right. 84 00:05:26,140 --> 00:05:26,560 So... 85 00:05:31,220 --> 00:05:35,560 So this is a default install of Oracle application server 10G second release. 86 00:05:37,380 --> 00:05:40,600 It comes with a lot of default packages. 87 00:05:40,760 --> 00:05:43,860 One of them is called SSO, or a single sign-on, 88 00:05:44,640 --> 00:05:45,980 which we will be using here. 89 00:05:46,380 --> 00:05:48,180 It is a flaw in the PL-SQL gateway. 90 00:05:48,380 --> 00:05:52,260 So it has nothing to do with the applications which you have deployed on the application server. 91 00:05:52,260 --> 00:05:56,100 Your applications which you've deployed on this server might be completely flawless. 92 00:05:56,400 --> 00:05:58,120 But because it's a flaw in the gateway, 93 00:05:58,380 --> 00:05:59,800 you still are vulnerable. 94 00:06:00,440 --> 00:06:01,820 So, using this flaw, 95 00:06:02,060 --> 00:06:06,020 you can execute SQL queries like select user from dual. 96 00:06:07,440 --> 00:06:07,920 And... 97 00:06:07,920 --> 00:06:09,700 I don't know if you can see that. 98 00:06:09,960 --> 00:06:12,460 If I throw in a query called select user from dual, 99 00:06:12,500 --> 00:06:13,960 it says ORA SSO underscore public. 100 00:06:14,220 --> 00:06:17,580 So that's the user privileges with which I'm running my SQL queries. 101 00:06:17,840 --> 00:06:20,640 So now if I change this query and do something like 102 00:06:20,640 --> 00:06:22,240 select star from system, 103 00:06:22,260 --> 00:06:24,500 which contains the password hashes, 104 00:06:24,640 --> 00:06:26,160 then you will see this will fail 105 00:06:26,160 --> 00:06:28,560 because our user doesn't have the privileges 106 00:06:28,560 --> 00:06:29,940 to query this table 107 00:06:29,940 --> 00:06:31,560 and we can't get the Oracle hashes. 108 00:06:31,920 --> 00:06:33,920 But because we can execute PL-SQL, 109 00:06:34,180 --> 00:06:35,840 now we can exploit the packages 110 00:06:35,840 --> 00:06:37,300 present in the backend database 111 00:06:37,300 --> 00:06:38,560 and elevate our privileges. 112 00:06:38,980 --> 00:06:42,600 So all you do is take this URL 113 00:06:42,600 --> 00:06:44,620 and pass this to this Perl script, 114 00:06:44,860 --> 00:06:46,020 oaphacker.pl 115 00:06:46,020 --> 00:06:48,600 and you give it the OS command 116 00:06:48,600 --> 00:06:49,560 which it wants to execute. 117 00:06:49,760 --> 00:06:51,940 Like in this case, maybe ipconfig 118 00:06:52,260 --> 00:06:52,360 or whatever. 119 00:06:53,660 --> 00:06:56,560 And it will first check if the URL is vulnerable or not. 120 00:06:56,800 --> 00:06:57,500 If it's vulnerable, 121 00:06:57,800 --> 00:06:59,940 then it will check for the current privileges 122 00:06:59,940 --> 00:07:01,620 whether you are DBA or not. 123 00:07:01,880 --> 00:07:02,760 If you are not DBA, 124 00:07:02,920 --> 00:07:04,680 then it will launch a series of exploits 125 00:07:04,680 --> 00:07:06,500 and eventually give you DBA access. 126 00:07:06,880 --> 00:07:08,040 Once you have DBA access, 127 00:07:08,260 --> 00:07:09,700 then it will build up a Java function 128 00:07:09,700 --> 00:07:11,400 with which you can execute OS code. 129 00:07:11,920 --> 00:07:13,460 So now it says we are not DBA. 130 00:07:13,620 --> 00:07:15,080 It's going to run a privilege escalation exploit. 131 00:07:17,080 --> 00:07:18,640 The first exploit maybe didn't work 132 00:07:18,640 --> 00:07:19,560 so it's going to run it again. 133 00:07:26,500 --> 00:07:28,740 So now it has given us the DBA privileges. 134 00:07:29,040 --> 00:07:30,440 Now it's going to build up a function 135 00:07:30,440 --> 00:07:31,920 for OS code execution. 136 00:07:34,760 --> 00:07:35,560 So that's it. 137 00:07:35,680 --> 00:07:37,200 It has now built up a function 138 00:07:37,200 --> 00:07:38,840 through which you can execute OS command 139 00:07:38,840 --> 00:07:42,220 and get the output in the web browser itself. 140 00:07:42,400 --> 00:07:43,840 So you don't really need any other tool. 141 00:07:44,200 --> 00:07:45,800 So now all you have to do is 142 00:07:45,800 --> 00:07:47,700 copy paste this URL into a browser, 143 00:07:48,640 --> 00:07:50,500 the argument which you want to execute, 144 00:07:51,280 --> 00:07:52,400 and that's it. You are done. 145 00:07:54,240 --> 00:07:55,940 I'm struggling to copy in this example. 146 00:08:08,500 --> 00:08:10,340 So I'm going to run the command whoami. 147 00:08:12,340 --> 00:08:13,740 If you can see it here, 148 00:08:13,820 --> 00:08:15,240 it says ntauthority slash system. 149 00:08:15,700 --> 00:08:17,860 That's basically how Oracle runs in Windows. 150 00:08:19,500 --> 00:08:20,920 So this was an example 151 00:08:20,920 --> 00:08:21,940 of how will you go about 152 00:08:22,620 --> 00:08:24,580 exploiting PLSQL injection from your applications. 153 00:08:36,260 --> 00:08:36,820 Right. 154 00:08:37,140 --> 00:08:38,440 Now we move on to something 155 00:08:38,440 --> 00:08:40,120 more difficult and something 156 00:08:40,120 --> 00:08:41,300 which you will probably more encounter, 157 00:08:41,580 --> 00:08:44,840 which is SQL injection in a single SQL statement. 158 00:08:46,560 --> 00:08:48,020 Now as I said earlier, 159 00:08:48,220 --> 00:08:49,840 Oracle by design does not support 160 00:08:50,680 --> 00:08:52,700 execution of stacked queries in SQL. 161 00:08:53,180 --> 00:08:54,560 It does so in PLSQL, 162 00:08:54,680 --> 00:08:55,540 but not in SQL. 163 00:08:55,840 --> 00:08:57,940 So if you find an injection 164 00:08:57,940 --> 00:08:59,360 in a select query such as this, 165 00:08:59,780 --> 00:09:00,840 you are really limited. 166 00:09:01,500 --> 00:09:03,880 So in order to execute multiple statements, 167 00:09:04,100 --> 00:09:04,520 like, you know, 168 00:09:04,560 --> 00:09:07,440 even if you want to exploit vulnerable packages, 169 00:09:07,720 --> 00:09:08,820 you need to find a way 170 00:09:08,820 --> 00:09:10,540 by which you can execute multiple statements. 171 00:09:10,840 --> 00:09:12,500 So you essentially need to find a way 172 00:09:12,500 --> 00:09:13,500 to inject PLSQL. 173 00:09:14,040 --> 00:09:16,280 So one of the ways to inject PLSQL 174 00:09:16,280 --> 00:09:17,540 in SQL 175 00:09:18,280 --> 00:09:20,500 is if you can call some function 176 00:09:20,500 --> 00:09:22,800 which is vulnerable to PLSQL injection. 177 00:09:23,120 --> 00:09:24,440 So you can pass the 178 00:09:24,440 --> 00:09:26,580 PLSQL as an argument to that function 179 00:09:26,580 --> 00:09:28,740 and then call that function in your SQL. 180 00:09:29,680 --> 00:09:30,200 Right. 181 00:09:30,820 --> 00:09:31,600 This will get, 182 00:09:31,760 --> 00:09:33,560 I'll elaborate on this a little bit more. 183 00:09:35,500 --> 00:09:36,940 So this is actually 184 00:09:36,940 --> 00:09:38,420 something not very new. 185 00:09:39,180 --> 00:09:40,820 In 2005 at Black Hat 186 00:09:40,820 --> 00:09:42,180 somebody actually touched on this. 187 00:09:42,500 --> 00:09:44,220 So there are other functions 188 00:09:44,220 --> 00:09:45,240 which you can call in SQL. 189 00:09:45,500 --> 00:09:47,940 There are functions which are vulnerable to buffer overflow 190 00:09:47,940 --> 00:09:48,900 which you can call here. 191 00:09:49,100 --> 00:09:50,160 For example, this one. 192 00:09:50,260 --> 00:09:52,140 This was showed in 2005 Black Hat talk. 193 00:09:53,060 --> 00:09:54,800 This was a function which basically 194 00:09:54,800 --> 00:09:56,240 was vulnerable to buffer overflow. 195 00:09:56,420 --> 00:09:57,100 And as you can see, 196 00:09:57,160 --> 00:09:58,900 you can just directly execute the command 197 00:09:58,900 --> 00:10:00,760 and it gets executed with system privileges. 198 00:10:01,200 --> 00:10:03,060 So you don't really need anything over here now. 199 00:10:04,620 --> 00:10:06,740 But I'm not going to touch buffer overflows here. 200 00:10:06,900 --> 00:10:08,520 I'm going to touch functions 201 00:10:08,520 --> 00:10:10,460 which are vulnerable to PLSQL injection. 202 00:10:12,500 --> 00:10:14,080 Functions vulnerable to PLSQL injection. 203 00:10:14,420 --> 00:10:16,200 Again, you can have two cases there. 204 00:10:16,460 --> 00:10:18,200 You can have the function defined 205 00:10:18,200 --> 00:10:19,560 with auth id definer 206 00:10:19,560 --> 00:10:21,440 or that function defined with 207 00:10:21,440 --> 00:10:22,700 auth id current underscore user. 208 00:10:23,840 --> 00:10:25,400 If the function is defined by 209 00:10:25,400 --> 00:10:27,840 auth id definer and it is owned by 210 00:10:27,840 --> 00:10:29,860 a high privilege user such as sys, 211 00:10:29,940 --> 00:10:31,900 then what it means is that you are basically 212 00:10:32,340 --> 00:10:34,080 injecting PLSQL with sys privileges. 213 00:10:34,800 --> 00:10:36,980 So in simple words, 214 00:10:37,020 --> 00:10:38,320 it means it's game over, really. 215 00:10:38,780 --> 00:10:40,900 If you are injecting PLSQL with sys privileges 216 00:10:40,900 --> 00:10:42,800 then you are DBA already. 217 00:10:43,020 --> 00:10:44,720 Just execute OS code and it's 218 00:10:44,720 --> 00:10:46,060 not very difficult. 219 00:10:46,340 --> 00:10:48,860 If you are injecting PLSQL with auth id 220 00:10:48,860 --> 00:10:50,740 current user, then it means that 221 00:10:50,740 --> 00:10:52,640 now you can execute multiple statements. 222 00:10:53,220 --> 00:10:54,720 Although you are not executing 223 00:10:54,720 --> 00:10:56,720 those statements with the high privileges, 224 00:10:57,000 --> 00:10:58,600 but because you can execute multiple 225 00:10:58,600 --> 00:11:00,520 statements, then you can exploit vulnerable 226 00:11:00,520 --> 00:11:02,220 packages and again indirectly 227 00:11:02,220 --> 00:11:04,720 do privilege escalation and then again become DBA. 228 00:11:05,740 --> 00:11:06,760 And essentially, 229 00:11:06,940 --> 00:11:08,580 so using these two vectors, 230 00:11:08,800 --> 00:11:10,560 once you become DBA, then you can execute 231 00:11:10,900 --> 00:11:10,980 OS code. 232 00:11:12,420 --> 00:11:14,480 So Oracle has had this function, 233 00:11:14,660 --> 00:11:16,740 DBMS export extension, which has 234 00:11:16,740 --> 00:11:18,800 had a series of vulnerability in the past. 235 00:11:19,240 --> 00:11:20,360 In fact, the 2009 236 00:11:20,740 --> 00:11:22,300 CPU, which was just released, 237 00:11:22,540 --> 00:11:24,760 had again addressed issues in this package. 238 00:11:25,560 --> 00:11:26,420 In particular, 239 00:11:26,660 --> 00:11:28,600 this package has a function called 240 00:11:28,600 --> 00:11:29,960 get domain index tables, 241 00:11:30,720 --> 00:11:32,780 which is vulnerable to PLSQL 242 00:11:32,780 --> 00:11:34,740 injection. Again, this is something which 243 00:11:34,740 --> 00:11:36,260 was fixed by Oracle in 2006, 244 00:11:36,500 --> 00:11:38,820 but because of the way Oracle patches 245 00:11:38,820 --> 00:11:40,280 work, it is still common to find 246 00:11:41,720 --> 00:11:42,760 databases which 247 00:11:42,760 --> 00:11:44,100 have this package 248 00:11:44,740 --> 00:11:45,920 as vulnerable still. 249 00:11:46,860 --> 00:11:47,760 So this function, 250 00:11:47,940 --> 00:11:50,360 this has the auth ID of 251 00:11:50,900 --> 00:11:52,740 definer. It is defined by sys. 252 00:11:53,160 --> 00:11:54,880 And it's vulnerable to PLSQL 253 00:11:54,880 --> 00:11:56,940 injection. So what it means is that 254 00:11:58,200 --> 00:11:58,960 you can 255 00:11:58,960 --> 00:12:00,520 now execute PLSQL 256 00:12:00,520 --> 00:12:02,640 as sys user. You don't really have to do 257 00:12:02,640 --> 00:12:04,780 anything more here. So just call this 258 00:12:04,780 --> 00:12:06,940 function in your SQL every time you find 259 00:12:06,940 --> 00:12:08,820 injection and select or 260 00:12:08,820 --> 00:12:10,880 insert or update query. Call this function 261 00:12:10,900 --> 00:12:13,100 pass the argument to this function 262 00:12:13,100 --> 00:12:14,740 whatever PLSQL you want to 263 00:12:14,740 --> 00:12:16,940 get executed, and that will execute 264 00:12:16,940 --> 00:12:17,640 with sys privileges. 265 00:12:18,420 --> 00:12:20,900 So this is a sample exploit. This was 266 00:12:20,900 --> 00:12:22,360 reported by David Litchfield. 267 00:12:22,940 --> 00:12:24,960 And it's actually mentioned in his 268 00:12:24,960 --> 00:12:27,080 book Oracle Hacker's Handbook as well. 269 00:12:27,680 --> 00:12:28,740 So we've 270 00:12:28,740 --> 00:12:30,980 declared this transaction as an autonomous 271 00:12:30,980 --> 00:12:31,500 transaction 272 00:12:32,580 --> 00:12:34,100 because we want to make it independent. 273 00:12:34,460 --> 00:12:36,760 This was fixed in 2006. There is 274 00:12:36,760 --> 00:12:38,900 yet another PLSQL injection in 275 00:12:38,900 --> 00:12:40,780 the same function, and this has 276 00:12:40,900 --> 00:12:42,400 been reported by Alexander Cornburst. 277 00:12:42,580 --> 00:12:44,760 But I'm not going to be talking about this. 278 00:12:44,860 --> 00:12:46,200 Maybe in the next DEFCON. 279 00:12:46,560 --> 00:12:48,400 And these are the vulnerable versions in which 280 00:12:48,400 --> 00:12:49,420 this will be affected. 281 00:12:50,580 --> 00:12:52,720 So I wrote up a small tool. It's called 282 00:12:52,720 --> 00:12:54,660 BSQLBF. There are n number of 283 00:12:54,660 --> 00:12:56,800 SQL injection tools out there. So I'm not going to talk 284 00:12:56,800 --> 00:12:58,560 about another SQL injection tool here. 285 00:12:59,080 --> 00:13:00,800 There are a few features of 286 00:13:00,800 --> 00:13:02,800 this tool, which I thought was quite unique. 287 00:13:03,500 --> 00:13:04,760 The latest version, version 288 00:13:04,760 --> 00:13:06,400 2.3, is dedicated to Oracle. 289 00:13:06,920 --> 00:13:08,340 It basically contains this 290 00:13:08,820 --> 00:13:10,280 DBMS export extension exploit. 291 00:13:10,900 --> 00:13:12,660 So if you find a SQL injection, 292 00:13:12,880 --> 00:13:14,380 and if you find that the database, 293 00:13:14,640 --> 00:13:16,460 the application connects to the database 294 00:13:17,020 --> 00:13:17,760 with certain 295 00:13:18,900 --> 00:13:20,700 unprivileged user in connection string like 296 00:13:20,700 --> 00:13:22,280 Scott Tiger or whatever, 297 00:13:23,660 --> 00:13:24,920 then you can use 298 00:13:24,920 --> 00:13:26,600 this tool. It will do 299 00:13:26,600 --> 00:13:28,440 two things. It will do privilege escalation. 300 00:13:28,620 --> 00:13:30,420 So normally you can extract data 301 00:13:30,420 --> 00:13:32,900 in Oracle, but with privilege 302 00:13:32,900 --> 00:13:34,720 escalation, you can extract data 303 00:13:34,720 --> 00:13:36,800 with these privileges. So maybe you can extract 304 00:13:36,800 --> 00:13:38,740 the password hashes from 305 00:13:38,740 --> 00:13:39,020 Oracle. 306 00:13:40,900 --> 00:13:42,120 Then it does OS code execution. 307 00:13:43,600 --> 00:13:44,680 For OS code execution, 308 00:13:44,880 --> 00:13:46,800 again, it takes three 309 00:13:46,800 --> 00:13:48,800 subtypes. It can execute OS code 310 00:13:48,800 --> 00:13:50,820 with Java. If you are exploiting an 311 00:13:50,820 --> 00:13:52,820 Oracle application server express edition, 312 00:13:53,000 --> 00:13:54,780 XE, then Java will not be 313 00:13:54,780 --> 00:13:56,540 installed. So you can then rely on 314 00:13:56,540 --> 00:13:59,000 DBMS scheduler. Or if you are exploiting 315 00:13:59,000 --> 00:14:00,740 Oracle 9, then it also supports 316 00:14:00,740 --> 00:14:02,440 PLSQL native make utility. 317 00:14:03,340 --> 00:14:04,420 It also gives you 318 00:14:04,420 --> 00:14:06,580 read-write access, so you can read files from 319 00:14:06,580 --> 00:14:08,880 the backend database. I don't 320 00:14:08,880 --> 00:14:10,540 really have time to show you the demo for this. 321 00:14:11,120 --> 00:14:12,880 But the demo is available on my 322 00:14:12,880 --> 00:14:14,140 website, not-so-secure.com. 323 00:14:14,620 --> 00:14:16,020 And if you want 324 00:14:16,680 --> 00:14:18,220 to go through this. So 325 00:14:18,900 --> 00:14:20,380 going back to the original 326 00:14:20,880 --> 00:14:22,660 topic, the SQL injection worm, 327 00:14:23,100 --> 00:14:24,560 those of you who 328 00:14:24,560 --> 00:14:26,540 do a little bit of forensics must have seen 329 00:14:26,540 --> 00:14:28,620 this hex string in the 330 00:14:28,620 --> 00:14:31,000 logs. This was how the MSSQL 331 00:14:31,000 --> 00:14:32,220 worm looked like. 332 00:14:32,500 --> 00:14:34,180 All it would do is basically 333 00:14:34,880 --> 00:14:36,620 find the web applications which are vulnerable 334 00:14:36,620 --> 00:14:38,600 to SQL injection. Then 335 00:14:38,600 --> 00:14:40,160 this massive string will 336 00:14:40,900 --> 00:14:42,760 look into the database, do a massive 337 00:14:42,760 --> 00:14:44,920 update, so that the web frontend 338 00:14:44,920 --> 00:14:46,340 now changes. So 339 00:14:46,740 --> 00:14:48,840 the end users who now visit these websites, 340 00:14:49,560 --> 00:14:50,800 this website now 341 00:14:50,800 --> 00:14:52,320 contains some malicious javascripts. 342 00:14:52,320 --> 00:14:54,420 And these javascripts basically points to 343 00:14:54,420 --> 00:14:55,540 some browser exploits. 344 00:14:56,700 --> 00:14:58,440 So it didn't really target 345 00:14:58,440 --> 00:15:00,620 the server so much, 346 00:15:00,760 --> 00:15:02,260 but it targeted the end users. 347 00:15:02,520 --> 00:15:04,700 That was how it operated. 348 00:15:05,200 --> 00:15:06,480 So I basically 349 00:15:06,480 --> 00:15:08,800 wrote a simple proof of concept 350 00:15:08,800 --> 00:15:10,740 on how the similar thing can 351 00:15:10,740 --> 00:15:11,320 be achieved 352 00:15:12,260 --> 00:15:13,300 under Oracle. 353 00:15:15,320 --> 00:15:16,680 Again, it's not just 354 00:15:16,680 --> 00:15:18,520 about doing a massive update and 355 00:15:18,520 --> 00:15:20,080 hacking the end users. 356 00:15:20,380 --> 00:15:22,720 As we have already seen, you can execute 357 00:15:22,720 --> 00:15:24,720 OS code and hack the Oracle server 358 00:15:24,720 --> 00:15:26,700 itself. So at this stage 359 00:15:26,700 --> 00:15:28,640 the possibilities are really 360 00:15:28,640 --> 00:15:29,020 endless. 361 00:15:31,560 --> 00:15:32,500 So yeah, exactly. 362 00:15:32,800 --> 00:15:34,740 What could the worm do from here? 363 00:15:34,980 --> 00:15:36,760 We've already seen that we could execute 364 00:15:36,760 --> 00:15:38,780 OS code on the server. We could 365 00:15:38,800 --> 00:15:40,460 do something like what 366 00:15:40,460 --> 00:15:42,540 MSSQL worm did, you know, and 367 00:15:42,540 --> 00:15:44,660 do an update and then hack the 368 00:15:44,660 --> 00:15:45,060 end users. 369 00:15:46,340 --> 00:15:48,640 Again, if you can execute code, then maybe you could do 370 00:15:48,640 --> 00:15:50,820 something like a tftp getconflicker 371 00:15:50,820 --> 00:15:52,540 and infect the internal network. 372 00:15:53,440 --> 00:15:54,100 You could, 373 00:15:54,700 --> 00:15:56,380 I mean, there could be something which 374 00:15:56,380 --> 00:15:58,420 could hack only Oracle, you know, 375 00:15:58,460 --> 00:16:00,600 specifically Oracle. There are quite a few 376 00:16:00,600 --> 00:16:02,480 things which are out there, you know, 377 00:16:02,540 --> 00:16:04,480 and begging to get hacked 378 00:16:04,480 --> 00:16:06,480 actually. Oracle secured backup. 379 00:16:06,820 --> 00:16:08,100 There was a remote code execution. 380 00:16:08,800 --> 00:16:10,580 So you just send one URL on the internal 381 00:16:10,580 --> 00:16:12,640 network and that's it. You get a reverse shell 382 00:16:12,640 --> 00:16:14,520 back from it. There was a secure backup 383 00:16:14,520 --> 00:16:16,740 exploit. I think it's integrated with Metasploit 384 00:16:16,740 --> 00:16:17,080 as well. 385 00:16:19,040 --> 00:16:20,700 SQL injection in Oracle Enterprise 386 00:16:20,700 --> 00:16:22,940 Manager. TNS listener exploits. 387 00:16:23,020 --> 00:16:24,780 There are so many things that a worm could do 388 00:16:24,780 --> 00:16:25,360 from this stage. 389 00:16:26,600 --> 00:16:28,800 So let me just quickly go through this 390 00:16:28,800 --> 00:16:30,720 demo of a sample SQL 391 00:16:30,720 --> 00:16:31,380 injection worm. 392 00:16:42,560 --> 00:16:44,560 Okay, before I play the demo, 393 00:16:44,680 --> 00:16:46,740 just a little background about this 394 00:16:46,740 --> 00:16:48,600 demo. Over here we are seeing a blind 395 00:16:48,600 --> 00:16:50,780 SQL injection. I have not shown you 396 00:16:50,780 --> 00:16:52,600 the demo for BSQLBF, but if you 397 00:16:52,600 --> 00:16:54,800 see the demo of BSQLBF, then probably 398 00:16:54,800 --> 00:16:56,240 you will be able to correlate this better. 399 00:16:56,540 --> 00:16:58,780 Because over there I first used 400 00:16:58,780 --> 00:17:00,520 the same application 401 00:17:00,520 --> 00:17:02,440 to get OS code execution. 402 00:17:02,760 --> 00:17:04,700 But over here we are not 403 00:17:04,700 --> 00:17:06,840 going through that. So in this case 404 00:17:06,840 --> 00:17:08,780 it's a PHP application, which I 405 00:17:08,800 --> 00:17:09,940 think is connecting to the back end 406 00:17:09,940 --> 00:17:11,520 Oracle database server, 10G. 407 00:17:13,040 --> 00:17:14,600 It is connecting as user 408 00:17:14,600 --> 00:17:15,660 Scott Tiger. 409 00:17:16,060 --> 00:17:18,080 So we are doing a privilege escalation, 410 00:17:18,160 --> 00:17:20,000 becoming a DBA, then doing a massive 411 00:17:20,000 --> 00:17:22,340 update. And then that update basically 412 00:17:22,340 --> 00:17:22,980 means that 413 00:17:24,200 --> 00:17:26,540 the front end, you know, after the 414 00:17:26,540 --> 00:17:28,060 worm has infected this website, 415 00:17:28,300 --> 00:17:29,540 when I refresh this page, 416 00:17:29,740 --> 00:17:32,340 the front end will change and that will 417 00:17:32,340 --> 00:17:34,680 point to the autopone 418 00:17:35,620 --> 00:17:36,460 Metasploit, browser 419 00:17:36,460 --> 00:17:38,020 autopone Metasploit module. 420 00:17:38,820 --> 00:17:40,740 So in this video 421 00:17:40,740 --> 00:17:41,960 over here, there is a 422 00:17:41,960 --> 00:17:44,160 putty session over here in which 423 00:17:44,160 --> 00:17:46,280 the attacker is running the browser autopone. 424 00:17:46,540 --> 00:17:48,680 And when I launch the worm, 425 00:17:48,840 --> 00:17:50,720 the worm basically will open 426 00:17:50,720 --> 00:17:52,300 a new window in the website 427 00:17:52,300 --> 00:17:54,740 and target and point 428 00:17:54,740 --> 00:17:55,960 to the browser autopone. 429 00:18:14,900 --> 00:18:16,940 Again, this was based on the DBMS 430 00:18:16,940 --> 00:18:19,460 export extension exploit, and this 431 00:18:19,460 --> 00:18:20,920 was doing the update query, but 432 00:18:21,580 --> 00:18:23,420 as I said, you could do a number 433 00:18:23,420 --> 00:18:24,180 of things over here. 434 00:18:25,920 --> 00:18:27,220 So I'm setting up the browser 435 00:18:27,220 --> 00:18:28,340 autopone right now in this 436 00:18:28,340 --> 00:18:29,100 window. 437 00:18:33,100 --> 00:18:34,880 So that launches our browser 438 00:18:34,880 --> 00:18:35,340 autopone. 439 00:18:35,520 --> 00:18:38,780 Now I'll give this URL to 440 00:18:38,800 --> 00:18:39,560 the worm. 441 00:18:52,940 --> 00:18:54,680 So it basically takes the 442 00:18:54,680 --> 00:18:56,520 URL as an argument. 443 00:19:04,600 --> 00:19:06,760 Okay, so that's it. 444 00:19:06,840 --> 00:19:08,480 It sends this massive URL, which 445 00:19:08,800 --> 00:19:10,320 basically injects PLSQL with its 446 00:19:10,320 --> 00:19:11,920 privileges and does the massive update. 447 00:19:13,640 --> 00:19:14,740 Now if I go 448 00:19:14,740 --> 00:19:16,500 and refresh this browser, then you will see 449 00:19:17,700 --> 00:19:18,660 the HTML 450 00:19:18,660 --> 00:19:20,620 source code now has a JavaScript tag saying 451 00:19:20,620 --> 00:19:22,760 window.open and that location 452 00:19:22,760 --> 00:19:24,900 is pointing to the browser autopone. 453 00:19:31,640 --> 00:19:32,500 So I refresh 454 00:19:32,500 --> 00:19:34,620 the website, and now a new window has opened 455 00:19:34,620 --> 00:19:36,740 which basically points to the browser autopone. 456 00:19:36,900 --> 00:19:38,140 And the browser autopone 457 00:19:38,800 --> 00:19:40,640 plugin of Metasploit is now launching a series of 458 00:19:40,640 --> 00:19:42,660 exploits in the browser to hack 459 00:19:42,660 --> 00:19:43,340 the end user. 460 00:19:44,420 --> 00:19:44,820 And 461 00:19:44,820 --> 00:19:53,920 as you will see over here, now one of the 462 00:19:55,040 --> 00:19:56,560 exploits have worked, and we now have 463 00:19:56,560 --> 00:19:57,940 a metapeter session open. 464 00:19:59,140 --> 00:19:59,540 So 465 00:20:01,080 --> 00:20:02,520 if we attach the session, and 466 00:20:02,520 --> 00:20:04,360 this is the metapeter shell 467 00:20:05,000 --> 00:20:06,400 not from the server, but from 468 00:20:06,400 --> 00:20:07,400 the end users. 469 00:20:10,520 --> 00:20:10,960 Yeah. 470 00:20:12,360 --> 00:20:13,040 Yeah, that 471 00:20:13,040 --> 00:20:13,860 basically concludes it. 472 00:20:16,160 --> 00:20:17,420 Thank you for your time.