1 00:00:00,240 --> 00:00:06,520 Today I'm talking about Oracle Rootkits and a little bit about Oracle Viruses, the first 2 00:00:06,520 --> 00:00:11,480 and the second generation. Short introduction of myself, my name is Alexander Kornprost 3 00:00:11,480 --> 00:00:20,880 from Germany and my company Red Database Security is specialized in Oracle Security. Okay, we 4 00:00:20,880 --> 00:00:29,340 have only limited time so I start fast. Operating systems and databases are quite similar in 5 00:00:29,340 --> 00:00:34,140 the architecture. In both systems you have users, you have processes, you have jobs, 6 00:00:34,280 --> 00:00:39,520 executables and symbolic links. And then I made the assumption, okay, if this is the 7 00:00:39,520 --> 00:00:46,660 case then a database is a kind of operating system. It's not identical but it's a kind 8 00:00:46,660 --> 00:00:54,300 of. And to prove my assumption I made a chart so you can see the PS command in the operating 9 00:00:54,300 --> 00:00:59,200 system world. It's a select star from V dollar process in Oracle or select star from 10 00:00:59,340 --> 00:01:07,220 sys processes in SQL server. In the database you can kill database jobs or database processes 11 00:01:07,220 --> 00:01:14,220 with the alter system command. You have executables like view, packages, procedures, functions. 12 00:01:14,660 --> 00:01:21,040 You can execute executables, for example, with select star from view or exec procedure. 13 00:01:21,740 --> 00:01:27,940 And in some databases you have even a kind of CD. In Oracle you can switch into different 14 00:01:27,940 --> 00:01:29,320 schemas with Oracle. 15 00:01:29,340 --> 00:01:36,560 Alter session set current schema equal and then the name of the schema. And then my assumption 16 00:01:36,560 --> 00:01:41,900 was, okay, if a database is a kind of operating system then it's possible to migrate all the 17 00:01:41,900 --> 00:01:46,420 malware stuff from the operating system world into the database world. Because it's the 18 00:01:46,420 --> 00:01:53,800 same, it's only a migration. And my first idea, okay, let's do a proof of concept virus 19 00:01:53,800 --> 00:01:58,980 in Oracle. Everybody here in the room knows, okay, viruses 20 00:01:59,340 --> 00:02:05,840 replicates itself, yada, yada, yada. And we have different type of viruses. We have 21 00:02:05,840 --> 00:02:11,520 append viruses, companion viruses. So if you start in the beginning, 15, 20 years ago. 22 00:02:12,740 --> 00:02:18,960 And the classical append virus in the operating system world looked like this. We had our 23 00:02:18,960 --> 00:02:24,360 executable code and then we append the virus code at the end and we jump from the beginning 24 00:02:24,360 --> 00:02:26,620 to the end, execute the code and then jump back. 25 00:02:28,480 --> 00:02:29,000 Okay. 26 00:02:29,080 --> 00:02:29,220 Okay. 27 00:02:29,340 --> 00:02:34,420 So we want to migrate this concept into the Oracle world or the database world. First, 28 00:02:34,600 --> 00:02:39,360 instead of using the operating system, we are using the database. Instead of using a 29 00:02:39,880 --> 00:02:44,480 binary file, we are using a view. And instead of using assembler, we are using PL, SQL. 30 00:02:46,360 --> 00:02:52,380 And it looks quite similar. So we have a view and we append our view at the end of this 31 00:02:52,380 --> 00:02:52,640 view. 32 00:02:53,540 --> 00:02:59,320 And now this is a proof of concept virus. 33 00:02:59,320 --> 00:03:04,460 This is a proof of concept. So on the left side, we have the views, my employee, select 34 00:03:04,460 --> 00:03:09,880 staff from employees for salary bigger than 5,000. And on the right side, we are appending 35 00:03:09,880 --> 00:03:16,280 a PL, SQL function. And every time you run a select from the view, from the now infected 36 00:03:16,280 --> 00:03:21,840 view, this function is executed. And this function is looking for new, uninfected views. 37 00:03:25,580 --> 00:03:28,400 And we can also spread. So virus must spread. 38 00:03:28,400 --> 00:03:35,940 So via database links, we can also connect to other databases. We can do HTTP requests 39 00:03:35,940 --> 00:03:44,720 from the database in many cases. And then we can go to Google, retrieve data. And I 40 00:03:44,720 --> 00:03:50,400 did a little bit research. I was able to implement six, seven different concept of database viruses. 41 00:03:51,320 --> 00:03:55,820 I don't think database viruses will become a big problem. For me, it was only to sharp 42 00:03:55,820 --> 00:03:57,320 my skills, a proof of concept. 43 00:03:57,500 --> 00:03:57,700 Okay. 44 00:03:58,400 --> 00:04:03,320 And here's an example how to do the first infection. For example, this is possible 45 00:04:03,320 --> 00:04:11,540 via the web. Two and a half years ago, I found a bug in Oracle package. And you can execute 46 00:04:12,140 --> 00:04:17,960 your own code. You can also create functions and procedures over the web. So if you do 47 00:04:17,960 --> 00:04:24,240 a Google search for PLS and DAD, like portal or something like this, you can call the package 48 00:04:24,240 --> 00:04:26,080 via iLoad validate statement. 49 00:04:26,520 --> 00:04:28,380 And then you can infect the first infection. 50 00:04:28,380 --> 00:04:28,460 Okay. 51 00:04:28,460 --> 00:04:33,360 And this is the first function in the database. Because all these commands are executed with 52 00:04:33,360 --> 00:04:40,800 DBA privileges. And then we create our first virus. Then we grant privileges. And then 53 00:04:40,800 --> 00:04:41,780 we infect the view. 54 00:04:43,860 --> 00:04:49,100 So this was the first proof of concept that it's possible to migrate malware from the 55 00:04:49,100 --> 00:04:55,520 operating system world to the database world. I think it's not a big problem or will not 56 00:04:55,520 --> 00:04:58,300 become a big problem. And then I... 57 00:04:58,300 --> 00:05:06,240 I tried the next step, operating system or rootkits. So everybody here in the room knows 58 00:05:06,240 --> 00:05:13,820 rootkits, I guess. You can use it to protect your music from being stolen, like Sony. Here 59 00:05:13,820 --> 00:05:21,940 without the Sony rootkit, you see this $sys, $rk.exe. And if the Sony rootkit is running, 60 00:05:22,120 --> 00:05:27,500 it's no longer visible. And you can also hide operating system users. 61 00:05:28,500 --> 00:05:35,180 If you want to migrate this concept into the database world, we must do an informal definition 62 00:05:35,180 --> 00:05:42,960 of a rootkit. A rootkit is informal. We are hiding objects like users, jobs, and processes 63 00:05:43,570 --> 00:05:49,640 in the operating system. And now we are trying to hide operating system use...database users 64 00:05:49,640 --> 00:05:57,320 in the database. And generally, there are two concepts to implement a rootkit. One possibility 65 00:05:57,500 --> 00:06:03,080 is we can modify the object itself. For example, in the operating system world, we modify the 66 00:06:03,080 --> 00:06:10,420 ls command. Or we change the execution path, like the path. And I presented the database 67 00:06:10,420 --> 00:06:17,340 rootkit last year at Black Hat Europe. And today I will give a short introduction from 68 00:06:17,340 --> 00:06:22,580 the stuff last year and the second generation. And the second generation does no longer need 69 00:06:22,580 --> 00:06:24,220 modifications in the data dictionary. 70 00:06:25,600 --> 00:06:27,480 And it's also possible to write a new code. You can write a new code in your database. 71 00:06:27,500 --> 00:06:32,620 third generation rootkits because Oracle released with Oracle 10g release to an 72 00:06:32,620 --> 00:06:37,860 API and with this API you can directly access the memory of the database and 73 00:06:37,860 --> 00:06:47,860 you can also modify the memory in the database the first generation is easy to 74 00:06:47,860 --> 00:06:52,800 find easy to implement and it affects all databases all relational databases 75 00:06:52,800 --> 00:06:58,060 not only Oracle I'm Oracle expert so I did everything with Oracle and on other 76 00:06:58,060 --> 00:07:02,360 databases it's a little bit more complicated and in sequel server 2005 77 00:07:02,360 --> 00:07:07,880 Microsoft already implemented some anti database rootkit technologies so they 78 00:07:07,880 --> 00:07:12,300 are signing views and if the view is modified you are getting a warning but 79 00:07:12,300 --> 00:07:20,540 Oracle is not so fast to do this before hiding operating database users we must 80 00:07:20,540 --> 00:07:20,980 you 81 00:07:22,400 --> 00:07:27,380 check our and a maker solution so what happens if you are checking for user 82 00:07:27,380 --> 00:07:32,540 name the normal committee selected user name from the users if you are doing 83 00:07:32,540 --> 00:07:36,600 this article checks first is still a local object it occurred schema cold 84 00:07:36,600 --> 00:07:42,960 users if yes use it normally did nós such an object then we are looking for 85 00:07:42,960 --> 00:07:47,160 privates and immune is also normally not to privates in the mean then we are 86 00:07:47,160 --> 00:07:50,480 looking for public's new name and normally does the public suggestions 87 00:07:50,480 --> 00:07:57,620 synonym DBA users. And after everything, before it's executed, Oracle checks if there's a 88 00:07:57,620 --> 00:08:02,900 virtual private database rule, a special concept of Oracle, and then it's possible to modify 89 00:08:02,900 --> 00:08:09,560 the statement via virtual private database. So we have here from top to down, if we are 90 00:08:09,560 --> 00:08:14,320 user one, Oracle looks first for the object itself, then for private synonym, and then 91 00:08:14,320 --> 00:08:23,400 for public synonym. So we can modify the objects, but we can also change the execution path 92 00:08:23,400 --> 00:08:28,680 by creating a local object with the same name. We can create a private synonym pointing to 93 00:08:28,680 --> 00:08:34,940 a different object. We can also create or modify a public synonym, or we can switch 94 00:08:34,940 --> 00:08:43,120 to a different schema with alter session sets, current schema. And the user management is 95 00:08:43,540 --> 00:08:44,180 quite simple. 96 00:08:44,220 --> 00:08:44,300 It's a very simple process. It's a very simple process. It's a very simple process. 97 00:08:44,300 --> 00:08:49,840 In Oracle, we have users and we have roles, and both objects are stored together in the 98 00:08:49,840 --> 00:08:55,460 same table, this user dollar. And users have to flag type number one and roles to flag 99 00:08:55,460 --> 00:09:02,160 type number zero. And to make everything access easier and simpler, Oracle provides two views, 100 00:09:02,460 --> 00:09:08,600 DBA users and all users, and public synonyms. So wherever you are in the database, you can 101 00:09:08,600 --> 00:09:13,780 submit a select star from all users. Okay. 102 00:09:13,780 --> 00:09:20,120 If you create a user, create user identified by hacker, grant DBA to a hacker. A clever 103 00:09:20,120 --> 00:09:26,640 hacker would never use such an obvious username. He would use something more similar to an 104 00:09:26,640 --> 00:09:32,200 Oracle account, like mtsys, or, which sounds like an Oracle account. And then if you are 105 00:09:32,200 --> 00:09:39,620 submitting the select username from DBA users, we see here the username hacker. But nowadays, 106 00:09:39,980 --> 00:09:43,760 in times of graphical user interfaces, most DBAs, they don't have the same username as 107 00:09:43,760 --> 00:09:46,760 the user integrators. The DBAs are using for the daily work graphical user interfaces. 108 00:09:47,600 --> 00:09:52,440 Quite common is Oracle Enterprise Manager, the Java version, and we see there's a user 109 00:09:52,440 --> 00:10:00,560 hacker or the database or grid control or tools like Toad from Quest, third party vendor. 110 00:10:02,280 --> 00:10:08,160 Now comes the trick. We are just modifying the view and we add one single line, and uname 111 00:10:08,160 --> 00:10:12,000 not equal hacker. This means the view shows everything except the user hacker. 112 00:10:13,760 --> 00:10:19,800 doing this simple modification and our user disappears and also from database 113 00:10:19,800 --> 00:10:24,600 security scanners and stuff like that most of the tools are using views 114 00:10:24,600 --> 00:10:31,760 instead of the base objects only tote in tote the user is still visible now you 115 00:10:31,760 --> 00:10:36,420 can say okay Oracle is doing crappy software that's not always the case is 116 00:10:36,420 --> 00:10:41,520 tote a better program no tote is just using a different view the view all 117 00:10:41,520 --> 00:10:49,980 users so if you modify the view all users and add our end user name not 118 00:10:49,980 --> 00:10:57,500 equal hacker then the user is also gone in tote and in most cases if you don't 119 00:10:57,500 --> 00:11:02,980 see something then it's invisible you can still look up in the table this user 120 00:11:02,980 --> 00:11:11,460 dollar but most DBAs are looking in the DBA users view so you should never 121 00:11:11,460 --> 00:11:20,340 trust use for critical objects and in this case we modify to view here in the 122 00:11:20,340 --> 00:11:24,520 source object but we could also create a private zoom in pointing to different 123 00:11:24,520 --> 00:11:30,080 objects so there are endless possibilities okay now we have an 124 00:11:30,080 --> 00:11:36,960 invisible user not 100% invisible but for most cases now we can hide 125 00:11:36,960 --> 00:11:41,400 processes it's the same game we have also different views for 126 00:11:41,400 --> 00:11:48,620 sessions in Oracle and with select SID serial number program from the dollar 127 00:11:48,620 --> 00:11:53,420 session we can get a list of the running sessions at the moment and then 128 00:11:53,420 --> 00:12:00,300 by doing for modification in for objects we can hide this information from the 129 00:12:00,300 --> 00:12:08,820 typical select statement or user interfaces one of the problems is if you 130 00:12:08,820 --> 00:12:11,280 apply as a security update on 131 00:12:11,280 --> 00:12:17,760 normal database patch set Oracle quite often recreates the views and then our 132 00:12:17,760 --> 00:12:23,000 invisible user is gone that's why it's always useful for an attacker to create 133 00:12:23,000 --> 00:12:28,540 a database job and the database job is looking once a day if the change still 134 00:12:28,540 --> 00:12:35,280 persists and then if not the job is doing the modification of the object so 135 00:12:35,280 --> 00:12:40,000 we can survive database updates so here we can create a view 136 00:12:43,700 --> 00:12:50,640 and then we see okay the view is visible and then same game we modify the 137 00:12:50,640 --> 00:12:57,260 view and the job is still running but it's not shown if you apply update you 138 00:12:57,260 --> 00:13:02,760 will see it but then the DBA you have this short time frame between the job is 139 00:13:02,760 --> 00:13:09,580 running and the modification again so this is quite easy everybody in this 140 00:13:09,580 --> 00:13:11,180 room can can modify the view and then the job is running and the modification again so this is quite easy everybody in this room can can modify 141 00:13:11,280 --> 00:13:20,120 this it's so simple and it's also simple to find even if the views are 142 00:13:20,120 --> 00:13:27,420 quite long if you have if you have a deeper look in the views you can find 143 00:13:27,420 --> 00:13:35,260 a modification this is a simple first-generation rootkit as a script so 144 00:13:35,260 --> 00:13:41,160 first Oracle has a package called tbms metadata and with DBMS metadata you can 145 00:13:41,160 --> 00:13:43,520 can create a DDL statement of an object. 146 00:13:44,920 --> 00:13:47,560 And then we spool the result in a text file. 147 00:13:47,780 --> 00:13:50,580 And then we say, OK, get the DDL statement 148 00:13:50,580 --> 00:13:52,100 of the view all users. 149 00:13:52,520 --> 00:13:57,000 And then we replace where username not equal hacker. 150 00:13:57,880 --> 00:14:01,380 And then this is written in the file RK underscore source. 151 00:14:02,200 --> 00:14:04,980 And then we create a user and execute the view. 152 00:14:05,520 --> 00:14:08,860 And after doing this, we have at least the user hacker 153 00:14:08,860 --> 00:14:10,500 is not visible in the normal tools. 154 00:14:12,860 --> 00:14:16,540 But modification in views is always too obvious. 155 00:14:16,960 --> 00:14:22,480 So it would be much better if we implement our backdoor 156 00:14:22,480 --> 00:14:25,040 in an Oracle database package. 157 00:14:25,340 --> 00:14:28,460 Oracle comes with a lot of functions and procedures. 158 00:14:28,800 --> 00:14:33,280 In Oracle 10G, there are 8,000 function and procedures 159 00:14:33,280 --> 00:14:34,240 granted to public. 160 00:14:35,240 --> 00:14:38,540 But all Oracle packages are obfuscated. 161 00:14:38,600 --> 00:14:38,840 Oracle 10G is not visible. 162 00:14:38,840 --> 00:14:39,800 Oracle calls this wrapping. 163 00:14:40,520 --> 00:14:42,920 And a few days ago at a Black Hat, 164 00:14:44,760 --> 00:14:46,560 Pete Finnegan gave a presentation 165 00:14:46,560 --> 00:14:47,760 how to unwrap this. 166 00:14:48,380 --> 00:14:50,300 But there are also working unwrappers there. 167 00:14:50,460 --> 00:14:54,840 So you can convert the wrapped system packages from Oracle 168 00:14:54,840 --> 00:14:55,740 into text file. 169 00:14:56,500 --> 00:15:01,400 Then we can implement our backdoor, wrap the stuff again, 170 00:15:01,600 --> 00:15:02,920 and install it in the database. 171 00:15:04,360 --> 00:15:05,660 So here's one. 172 00:15:06,120 --> 00:15:07,640 I have also such an unwrapper. 173 00:15:07,820 --> 00:15:08,820 This is quite useful. 174 00:15:08,820 --> 00:15:10,620 It's quite useful if you are looking for security bugs. 175 00:15:10,820 --> 00:15:14,720 Because just with simple crap statements, 176 00:15:14,840 --> 00:15:16,380 you find vulnerabilities. 177 00:15:17,260 --> 00:15:20,560 And here I'm unwrapping the package DBMS output, 178 00:15:20,900 --> 00:15:23,120 which is a quite common package. 179 00:15:24,480 --> 00:15:25,980 And now there's one possibility. 180 00:15:26,500 --> 00:15:28,600 We can say if this package is executed, 181 00:15:28,980 --> 00:15:32,380 and if it's Sunday or Saturday, we 182 00:15:32,380 --> 00:15:34,360 escalate the privileges of the user's code. 183 00:15:34,560 --> 00:15:37,680 This is normally much more intelligent than creating 184 00:15:37,680 --> 00:15:38,660 a user with DBA. 185 00:15:38,660 --> 00:15:38,920 So if you change the DBA privileges, 186 00:15:39,440 --> 00:15:42,720 if you change password and privileges, 187 00:15:43,440 --> 00:15:45,560 because quite often this is not audited. 188 00:15:46,400 --> 00:15:48,860 And then on the normal weekdays, 189 00:15:49,020 --> 00:15:51,500 we revoke the DBA privileges from Scott. 190 00:15:51,740 --> 00:15:55,700 So during a normal security audit, during business hours, 191 00:15:55,800 --> 00:15:58,880 during the week, you will never find this vulnerability. 192 00:15:59,440 --> 00:16:02,560 Because the package is wrapped, and during the week, 193 00:16:02,560 --> 00:16:03,420 everything looks fine. 194 00:16:03,500 --> 00:16:08,560 And at the weekend, you have DBA privileges. 195 00:16:11,100 --> 00:16:14,160 Then we wrap this package again, install it in the database. 196 00:16:14,860 --> 00:16:20,620 So the only thing which was changed is modified checksum. 197 00:16:23,060 --> 00:16:30,740 Another possible approach is we can call a function. 198 00:16:31,340 --> 00:16:33,400 Here we have the same function enable. 199 00:16:33,760 --> 00:16:36,680 And if the value of the buffer size is 31337, 200 00:16:37,960 --> 00:16:38,640 we can call a function. 201 00:16:38,660 --> 00:16:40,580 Then we grant privileges. 202 00:16:41,020 --> 00:16:42,760 So whenever we need DBA privileges, 203 00:16:43,560 --> 00:16:46,580 we are calling this procedure with a special value. 204 00:16:46,780 --> 00:16:47,960 And after that, we add DBA. 205 00:16:48,320 --> 00:16:50,060 And we are doing our work. 206 00:16:50,760 --> 00:16:52,540 And then we can reset it again. 207 00:16:53,520 --> 00:16:54,880 So this is more ancient. 208 00:16:55,120 --> 00:16:58,060 You would have DBA privileges on request. 209 00:16:59,760 --> 00:17:00,660 Install it again. 210 00:17:00,880 --> 00:17:01,640 And so on. 211 00:17:02,700 --> 00:17:04,140 This was all stuff. 212 00:17:05,880 --> 00:17:08,640 And if you're using checksum, so we add all this stuff, 213 00:17:08,640 --> 00:17:15,260 it's easy to find. So checksum about all objects and if there are modifications 214 00:17:15,260 --> 00:17:22,020 then you should have a deeper look in the modify objects. But my goal was to 215 00:17:22,870 --> 00:17:27,980 to have a rootkit without modification in the data dictionary because then you 216 00:17:27,980 --> 00:17:38,340 cannot use checksums to find this stuff. And I found several possibilities how to 217 00:17:38,340 --> 00:17:44,080 implement this. One possibility is the modification of binary files. So what 218 00:17:44,080 --> 00:17:48,380 happens if you connect to an Oracle database? Oracle looks up in the table 219 00:17:48,380 --> 00:17:53,580 this user dollar. The question is how does Oracle know to look up in this table? 220 00:17:53,720 --> 00:17:59,780 Because it's somewhere hard coded. And in Oracle 10g for example there are 106 221 00:17:59,780 --> 00:18:05,040 occurrences in the binary file. And all the select statements in the binary files 222 00:18:05,040 --> 00:18:08,080 are not obfuscated. So with a simple text 223 00:18:08,080 --> 00:18:19,000 editor you can rename this table. So if you log on to the database Oracle is now 224 00:18:19,000 --> 00:18:23,940 looking in a different table. The old table still exists. So a security auditor 225 00:18:24,760 --> 00:18:29,520 which heard of database rootkit first generation even if you look up in the 226 00:18:29,520 --> 00:18:38,040 this user dollar table he will not find the back door. So the guy is looking in 227 00:18:38,040 --> 00:18:46,700 the wrong table. So here we create a user with DBA privileges. Then we create a table 228 00:18:46,700 --> 00:18:56,600 because we must do this before we change the table name in the binary file. So first we 229 00:18:56,600 --> 00:19:01,900 create a hacker. This hacker is created in this user dollar table. Then we create a copy 230 00:19:01,900 --> 00:19:06,680 of this user dollar table containing the user hacker. And then we drop the user hacker from 231 00:19:06,680 --> 00:19:07,420 this user dollar. 232 00:19:08,040 --> 00:19:14,480 So it's not available in this user dollar but in this table. Then shut down the database, 233 00:19:14,760 --> 00:19:22,560 replace everything. And then we can log on with this user. Sometimes it depends on the 234 00:19:22,560 --> 00:19:27,700 database. If you have a lot of user creation activities you can think about the possibility 235 00:19:27,700 --> 00:19:32,160 to create a trigger on the ASAR table. So every time, yes? 236 00:19:37,120 --> 00:19:42,780 You can do this with a trigger but it depends on the database. Quite often for example 237 00:19:42,780 --> 00:19:47,280 in the SAP database you have only five or six users and there's no change. So there's 238 00:19:47,280 --> 00:19:56,980 no need to synchronize this stuff. But for synchronizing you can use a trigger. But to 239 00:19:56,980 --> 00:20:02,100 do this a trigger does not work on this object. You must create an object in the 240 00:20:02,160 --> 00:20:02,680 different schema. 241 00:20:06,980 --> 00:20:12,160 So this is the way how to do this. It's quite simple. And the protection from Oracle. Oracle 242 00:20:12,160 --> 00:20:19,000 should sign their binaries. So I think it's not a good idea to allow users to patch SQL 243 00:20:19,000 --> 00:20:24,600 statement in the binaries. You should use checksum tools. It depends on your level of 244 00:20:24,600 --> 00:20:32,060 paranoia on the binary files. And you should harden your database to avoid hackers. And 245 00:20:32,160 --> 00:20:40,480 it's also a good programming style to obfuscate the SQL statements in the binary. Normally 246 00:20:40,480 --> 00:20:44,940 if you do a normal strings, something like this, you should never see SQL statements. 247 00:20:48,160 --> 00:20:49,620 This was one possibility. 248 00:20:52,020 --> 00:21:00,680 Second possibility. Oracle has a feature called PLSQL native. In PLSQL native you can convert 249 00:21:00,680 --> 00:21:09,000 a PLSQL statement into C code. And the C code is compiled on the platform and then executed. 250 00:21:09,360 --> 00:21:16,620 So instead of executing the PLSQL procedure, you are executing a binary. And Oracle generates 251 00:21:16,620 --> 00:21:26,080 a C file. And in Oracle 9i, these C files are, these DLLs libraries are stored in the 252 00:21:26,080 --> 00:21:30,660 file system. And in 10g, Oracle copies the file system. 253 00:21:30,660 --> 00:21:33,380 And in 10g, Oracle copies the file system from the database, from the file system into 254 00:21:33,380 --> 00:21:40,760 the database. This PLSQL native feature is also the fastest way to run operating system 255 00:21:40,760 --> 00:21:47,060 commands. Because there's a command alter session set PLSQL native make utility. And 256 00:21:47,060 --> 00:21:54,160 I just said, okay, I want to use the make utility calc. And then every time I create 257 00:21:54,160 --> 00:22:00,480 or modify a PLSQL procedure, the Windows calculator pops up on the database server. 258 00:22:02,740 --> 00:22:12,260 In 10g, Oracle changed this. So in 10g, Oracle is looking in the registry where Microsoft 259 00:22:12,260 --> 00:22:18,120 Visual Studio is installed or in the environment variable and is taking the value from there. 260 00:22:21,020 --> 00:22:28,320 And in 10g, Oracle is looking up for the compiler statement in this text file. So if you compile 261 00:22:28,320 --> 00:22:29,800 a statement, Oracle calls this. 262 00:22:30,660 --> 00:22:31,220 And then it generates the file. 263 00:22:33,760 --> 00:22:39,640 To switch in this PLSQL native mode, you can say alter session set PLSQL compiler flex 264 00:22:39,640 --> 00:22:45,500 equal native. And then alter procedure, my procedure compile. In this case, Oracle generates 265 00:22:45,500 --> 00:22:52,700 the C file, compiles the C file, and the result is a DLL. In 10g, this DLL is loaded 266 00:22:52,700 --> 00:22:55,040 into the, into a CLOB in the database. 267 00:22:56,420 --> 00:22:59,100 This is a part of the generated C file. 268 00:23:03,000 --> 00:23:03,600 This and this. 269 00:23:03,600 --> 00:23:12,000 Now we implement a backdoor in our procedure. And the result is Oracle generates a C file. 270 00:23:12,220 --> 00:23:18,020 Then compiles the C file. And now we have a DLL with a backdoor. From this file we are 271 00:23:18,020 --> 00:23:18,840 creating a copy. 272 00:23:20,460 --> 00:23:28,540 Now we undo the change. So Oracle again creates the C file and creates a DLL without the backdoor. 273 00:23:28,540 --> 00:23:39,120 And Oracle is not monitoring these files on the operating system level, so we are replacing the copy with the backdoor without backdoor. 274 00:23:39,540 --> 00:23:48,320 So now every time we execute the my procedure, Oracle is executing the backdoored version in the operating system. 275 00:23:50,780 --> 00:23:57,700 So just by doing checksums in the database, you are not able to find this kind of rootkit. 276 00:24:00,540 --> 00:24:04,740 So if you don't need PLSQL native, I would recommend not to use it. 277 00:24:04,880 --> 00:24:13,040 And you should also check there are some data dictionary tables where you can look up if PLSQL native is used in your environment. 278 00:24:15,320 --> 00:24:17,520 The third possibility is pinning. 279 00:24:17,720 --> 00:24:18,300 I will show you how. 280 00:24:18,320 --> 00:24:24,420 Oracle in older versions had a bigger problem with memory fragmentation of the memory of the database. 281 00:24:25,000 --> 00:24:27,720 So they introduced a concept called pinning. 282 00:24:28,620 --> 00:24:38,260 With a package DBMS share pool, you are able to pin PLSQL packages into the memory for performance reasons and to avoid fragmentation. 283 00:24:39,220 --> 00:24:47,780 The problem is these changed objects are not automatically reloaded into the memory if you change these in the database. 284 00:24:47,780 --> 00:24:48,300 So this is the problem. 285 00:24:49,960 --> 00:24:52,120 So the concept is identical. 286 00:24:52,300 --> 00:24:53,280 We have a procedure. 287 00:24:54,160 --> 00:24:55,860 Then we create a backdoor. 288 00:24:56,460 --> 00:25:04,720 And then with DBMS shared pool.keep, we are loading this backdoored procedure into the memory. 289 00:25:05,040 --> 00:25:13,800 And from now on, Oracle will always execute the my procedure in the memory instead of the package in the database. 290 00:25:16,040 --> 00:25:18,060 Then we remove the backdoor. 291 00:25:18,060 --> 00:25:26,420 so our data dictionary again is clean not no modification and the problem is 292 00:25:26,420 --> 00:25:33,660 if you change the package if you don't do a drop and recreate the package is 293 00:25:33,660 --> 00:25:39,600 available in the database until you stop the database or you clean the cache but 294 00:25:39,600 --> 00:25:45,800 normally databases are quite stable so it talks sometimes databases are not 295 00:25:45,800 --> 00:25:52,720 restarted for months or even years so if you are responsible for the security 296 00:25:52,720 --> 00:25:58,300 you should check if DBMS shared pool is installed and you should check from time 297 00:25:58,300 --> 00:26:02,800 to time for pin packages if you do some forensics before stopping the database 298 00:26:02,800 --> 00:26:09,360 you should always do a dump of the memory so you have a proof of concept 299 00:26:09,360 --> 00:26:15,300 that you have some evidence if there's something in the memory an Oracle has a 300 00:26:15,300 --> 00:26:15,780 you have some evidence if there's something in the memory an Oracle has a 301 00:26:15,780 --> 00:26:23,960 small tool dump SGA to do this Oracle has so many possibilities that I expect 302 00:26:24,940 --> 00:26:31,720 much more possibilities to implement rootkits without modifications Oracle 303 00:26:31,720 --> 00:26:35,300 has a functionality called virtual private database and this 304 00:26:35,300 --> 00:26:41,600 functionality is able to modify a sequel statement afterwards so you run a 305 00:26:41,600 --> 00:26:45,100 select staff from table and Oracle at the end 306 00:26:45,100 --> 00:26:45,860 select staff from table and Oracle at the end 307 00:26:45,860 --> 00:26:52,700 user name not equal something so this is possible and then by using special VPD 308 00:26:52,700 --> 00:26:53,200 user name not equal something so this is possible and then by using special VPD 309 00:26:53,200 --> 00:27:02,260 rules we can remove table content and you can only find these kind of 310 00:27:02,260 --> 00:27:02,800 rules we can remove table content and you can only find these kind of 311 00:27:02,800 --> 00:27:04,320 vulnerabilities if you have a special privilege exempt access policy or if 312 00:27:04,320 --> 00:27:06,420 vulnerabilities if you have a special privilege exempt access policy or if 313 00:27:06,420 --> 00:27:11,740 you're working as so my recommendation if you are doing a security audit you 314 00:27:11,740 --> 00:27:11,880 you're working as so my recommendation if you are doing a security audit you 315 00:27:11,880 --> 00:27:14,760 should always work with the highest number of 316 00:27:14,760 --> 00:27:14,920 should always work with the highest number of 317 00:27:19,080 --> 00:27:25,440 privileges. Another possibility is in Oracle feature called query rewrite. For 318 00:27:25,440 --> 00:27:30,840 performance reason the Oracle optimizer is able to completely rewrite the select 319 00:27:30,840 --> 00:27:36,200 statement. For example you submit a select star from table A, then Oracle is 320 00:27:36,200 --> 00:27:41,580 able to say okay it's much faster if I use a materialized view so Oracle 321 00:27:41,580 --> 00:27:46,900 changed this in select star from table B. And it's completely transparent so you 322 00:27:46,900 --> 00:27:51,440 don't see anything. You just get the result back and even if you look up okay 323 00:27:51,440 --> 00:27:58,800 I submitted a select star from table A, Oracle is doing something else. And I 324 00:27:58,800 --> 00:28:03,880 haven't worked with this feature but I also think it's possible to do 325 00:28:03,880 --> 00:28:11,560 something with this. The third generation I mentioned it already. I think 326 00:28:11,560 --> 00:28:17,200 it's quite difficult to implement. You need operating system access and there 327 00:28:17,200 --> 00:28:21,560 are already some tools available. The question is why has Oracle implemented 328 00:28:21,560 --> 00:28:27,160 such a feature. The reason is simple if you have a problem with your database 329 00:28:27,160 --> 00:28:32,420 and you are not able to submit SQL statements to check for performance 330 00:28:32,420 --> 00:28:39,040 problems. Then you can directly connect to the memory and do your 331 00:28:39,040 --> 00:28:41,540 modifications. You can change values and so on. 332 00:28:41,560 --> 00:28:48,820 You can change data blocks. And these rootkits will be much more difficult to 333 00:28:48,820 --> 00:28:54,940 find but you need operating system access. So one of the big problems I 334 00:28:54,940 --> 00:28:59,480 mentioned it already is to survive updates. For example what happens if you 335 00:29:01,200 --> 00:29:10,840 import or if you update the database dictionary or the binaries. Oracle rebuilds 336 00:29:10,840 --> 00:29:11,360 everything from 337 00:29:11,560 --> 00:29:18,940 scratch. And to protect our rootkit we could create a special database job. I 338 00:29:18,940 --> 00:29:24,620 showed this already. Or we can modify the glogin.sql. This is an auto 339 00:29:24,620 --> 00:29:29,660 startup file on the database server. And if someone calls sqlplus on the 340 00:29:29,660 --> 00:29:35,200 database server the entire content in this file is executed. So we could also 341 00:29:35,200 --> 00:29:40,580 implement something in the glogin file. Oracle has also a database startup 342 00:29:40,580 --> 00:29:40,980 trigger. 343 00:29:41,560 --> 00:29:45,400 And this code is always executed if you start a database. So we can also 344 00:29:45,400 --> 00:29:50,360 implement something in the database startup trigger. Or instead of backdooring 345 00:29:50,360 --> 00:29:56,220 Oracle packages we can backdoor custom packages because quite often the 346 00:29:56,760 --> 00:30:01,540 customer has his own application also written in PL SQL and you can also 347 00:30:01,540 --> 00:30:08,180 implement backdoors there. To find rootkits like always in the rootkit world 348 00:30:08,180 --> 00:30:09,820 checksums baselines. 349 00:30:10,380 --> 00:30:11,120 So you check 350 00:30:11,120 --> 00:30:17,340 you should check some database objects. You should check some binary files. And 351 00:30:17,340 --> 00:30:22,280 for the advanced one you should check if PL SQL native is active. DBMS shared 352 00:30:22,280 --> 00:30:26,860 pool is installed. And it's quite important to harden your database. From 353 00:30:26,860 --> 00:30:34,440 my experience in most cases you can break into the database. So because 354 00:30:34,440 --> 00:30:41,020 patches are missing, default passwords, the same old game. And in most cases 355 00:30:41,120 --> 00:30:48,400 it's not a challenge to become DBA of a database. In 10G Oracle did a quite good job. So 10G 356 00:30:48,400 --> 00:30:55,880 is much more difficult to hack and it separates the men from the boys. But in 8i and 9i it's 357 00:30:55,880 --> 00:30:57,100 quite easy to become DBA. 358 00:31:01,700 --> 00:31:08,920 And Oracle is much more powerful than SQL Server for example. That's why you have a 359 00:31:08,920 --> 00:31:09,160 bigger 360 00:31:09,160 --> 00:31:13,960 you have more complexity and more complexity means also more security 361 00:31:13,960 --> 00:31:26,040 holes and more possibilities. So at the moment you should you should try to get 362 00:31:26,040 --> 00:31:28,420 rid of all unneeded features in the database. 363 00:31:30,940 --> 00:31:32,320 Ok questions? 364 00:31:39,440 --> 00:31:40,720 Ok thank you.