1 00:00:00,560 --> 00:00:07,280 And today I will talk about a new topic for me, so database DB2 security. 2 00:00:08,080 --> 00:00:15,640 And if you look in the internet, normally the first way is always to go to Google and search for DB2 security experts. 3 00:00:16,000 --> 00:00:20,280 But so far there are no real DB2 security experts available. 4 00:00:21,000 --> 00:00:27,980 And I think the majority of the security crowd is not looking at vulnerabilities in DB2. 5 00:00:28,760 --> 00:00:41,180 And today I want to show you a little bit of my research and also give you the resources with links to VMware's 6 00:00:41,180 --> 00:00:49,700 that you can also start a little bit research if you want, because I think it's a juicy target as well. 7 00:00:52,440 --> 00:00:57,020 Okay. I'm not sure who has experience with DB2. 8 00:00:59,880 --> 00:01:03,880 Okay. A few. I have difficulties to see. Okay. 9 00:01:06,060 --> 00:01:12,800 And when I start looking into a new topic, everyone is looking at Google. 10 00:01:14,000 --> 00:01:18,800 And my experience is that IBM is quite slow in releasing patches. 11 00:01:19,080 --> 00:01:20,620 So that's one of the first thing. 12 00:01:21,120 --> 00:01:26,760 Even after zero days were released, it took a few months until they, 13 00:01:27,980 --> 00:01:29,580 released new security patches. 14 00:01:30,940 --> 00:01:38,420 The latest version of DB2, LUV, Linux Unix Windows, is version 9.7 called Cobra. 15 00:01:39,030 --> 00:01:43,080 And this version is, will be supported until 2014. 16 00:01:44,500 --> 00:01:49,280 And here you can see when the patch sets are coming out, the fixed packs. 17 00:01:49,480 --> 00:01:55,560 Then we have version 9.5 and version 9.1. 18 00:01:55,620 --> 00:01:56,720 And 9.1 will, 19 00:01:57,980 --> 00:02:00,660 run out of the normal support, end of 2012. 20 00:02:01,080 --> 00:02:06,060 So people should start slowly thinking about migrating to 9.7. 21 00:02:08,180 --> 00:02:13,560 One of the questions, and in the IBM world, it's much more complicated to get 22 00:02:14,580 --> 00:02:16,040 the database software. 23 00:02:16,620 --> 00:02:19,220 You can get the free express edition. 24 00:02:20,120 --> 00:02:25,060 And this free express edition is available, thank you, for different platforms. 25 00:02:25,620 --> 00:02:27,900 But in some places, 26 00:02:27,980 --> 00:02:29,040 they are quite limited. 27 00:02:29,220 --> 00:02:34,800 For example, the express edition does not support PLSQL, and some other nice things. 28 00:02:35,540 --> 00:02:39,320 There are also trial versions, 90 days, available from IBM. 29 00:02:39,560 --> 00:02:40,540 But you have to register. 30 00:02:40,800 --> 00:02:45,600 The biggest problem for me, if you don't have a support contract with IBM, 31 00:02:45,860 --> 00:02:47,400 is to get old versions. 32 00:02:47,520 --> 00:02:52,180 Because if you are looking for security vulnerabilities, and if you want to play with exploits, 33 00:02:52,440 --> 00:02:56,040 you're normally more interested in older versions than in newer versions. 34 00:02:56,040 --> 00:02:58,440 But that's quite complicated to get. 35 00:03:00,240 --> 00:03:01,740 There are also some 36 00:03:03,420 --> 00:03:04,640 VMWare images available. 37 00:03:05,380 --> 00:03:10,760 One is created by a guy called db2hitman. 38 00:03:10,940 --> 00:03:13,980 And he has an Ubuntu version. 39 00:03:15,180 --> 00:03:21,460 So you can just download this VM, and then you can start playing with it. 40 00:03:21,700 --> 00:03:25,080 So that's probably the fastest way to start with db2. 41 00:03:26,340 --> 00:03:29,500 Because you save all the time to set up and configure the database. 42 00:03:31,320 --> 00:03:37,200 And there are also express edition, and IBM has also a data server, 43 00:03:37,420 --> 00:03:39,440 but sometimes it's difficult to find. 44 00:03:39,660 --> 00:03:44,480 So whenever I want to download the IBM website, for me it's a nightmare. 45 00:03:44,780 --> 00:03:47,920 So I have always difficulties to find something there. 46 00:03:48,920 --> 00:03:52,620 So this is the architecture, but I don't want to spend too much time here. 47 00:03:54,660 --> 00:03:55,920 For me, and... 48 00:03:56,040 --> 00:03:59,360 many other people, the first time when you work with a database, 49 00:03:59,660 --> 00:04:03,280 probably the biggest challenge is how to connect to this damn database. 50 00:04:03,700 --> 00:04:08,820 So I saw it so many times that people want to connect to an Oracle database in a training, 51 00:04:08,980 --> 00:04:16,180 and it took sometimes 30, 40 minutes before they were able to connect with their laptop to the database. 52 00:04:17,260 --> 00:04:24,840 So Oracle has the IBM db2, they have a small command line utility, CLP. 53 00:04:25,920 --> 00:04:32,140 And you start it, db2cmd, then you connect to the database, and then you can run statements. 54 00:04:33,740 --> 00:04:36,940 It's not nice, it's not ugly, it's similar to SQL+. 55 00:04:37,640 --> 00:04:42,500 A little bit more convenient is the SQL Plus clone from IBM as well. 56 00:04:42,600 --> 00:04:45,340 So if you install it, it's part of the installation. 57 00:04:45,560 --> 00:04:52,300 It's called CLP Plus, and you have even a history, something SQL Plus doesn't have in 20 years. 58 00:04:55,140 --> 00:04:57,780 Now I want to show you exploits. 59 00:04:57,800 --> 00:05:01,960 And if you search in the internet, you will only find a few of these exploits, 60 00:05:01,980 --> 00:05:07,180 because most of these exploits are coming from IBM itself. 61 00:05:08,460 --> 00:05:13,100 Because IBM is releasing a lot of exploit code. 62 00:05:14,020 --> 00:05:19,660 So if you go to their support pages, you find a lot of working exploits there. 63 00:05:19,740 --> 00:05:23,780 The problem, the IBM guys are not aware that this code is exploit code. 64 00:05:25,020 --> 00:05:27,280 And I will show you some of them. 65 00:05:28,400 --> 00:05:30,960 So far there are only a few exploits available. 66 00:05:31,320 --> 00:05:37,020 If you come from the Oracle world, it's really a small amount of exploits available. 67 00:05:38,360 --> 00:05:44,380 So one problem, I always say Oracle, I did it too long. 68 00:05:44,560 --> 00:05:47,600 db2 may have problems with unsecure random numbers. 69 00:05:49,060 --> 00:05:52,820 This was fixed in 9.7 fixpack 1. 70 00:05:52,820 --> 00:05:59,120 And the majority of the exploits in the db2 world are denial of service exploits. 71 00:05:59,460 --> 00:06:06,520 So whatever I saw, it's crashing the database, creating a denial of service, killing something, and so on. 72 00:06:12,540 --> 00:06:14,520 In 9.7 it's similar. 73 00:06:15,320 --> 00:06:21,660 So unsecure random number, if you call the random number generator two times, you're getting the same value back. 74 00:06:21,660 --> 00:06:24,280 So this is not always a good idea. 75 00:06:25,780 --> 00:06:29,020 And this was one of the few zero-day exploits. 76 00:06:29,120 --> 00:06:37,140 A Russian guy released zero-day exploits, and it took four or five months before IBM released fixes for it. 77 00:06:37,320 --> 00:06:43,860 So by running such a simple select statement, you were able to crash the database. 78 00:06:44,080 --> 00:06:47,320 So the load went to 100% and stayed at 100%. 79 00:06:47,320 --> 00:06:50,080 So this would be a candidate if you are... 80 00:06:50,080 --> 00:06:57,300 If you have a SQL injection in a web application, you can just use a union statement, append the select statement, 81 00:06:57,600 --> 00:07:00,840 and then you are able to do a denial of service. 82 00:07:08,060 --> 00:07:09,800 Somehow my keyboard is not working. 83 00:07:16,320 --> 00:07:21,800 So this is from a guy from Ukraine, Denis Yuryshev. 84 00:07:21,940 --> 00:07:28,360 By sending this special package, you were able also to create a denial of service attack. 85 00:07:29,600 --> 00:07:34,600 And Denis was also reporting another one, but it's too big. 86 00:07:34,860 --> 00:07:39,320 So by using fuzzing, I'm quite sure you will be able to find a lot of... 87 00:07:39,960 --> 00:07:40,760 Vulnerabilities there. 88 00:07:42,640 --> 00:07:47,300 And this is one of the exploits from IBM. 89 00:07:48,480 --> 00:07:54,880 And the easiest way to find these exploits is you go whenever IBM releases a new fixpack. 90 00:07:55,060 --> 00:07:57,580 For example, fixpack 4 or fixpack 3. 91 00:07:57,860 --> 00:08:00,620 Then you go through all the security bugs. 92 00:08:01,500 --> 00:08:04,800 And you should also go through the instance crash bugs. 93 00:08:05,180 --> 00:08:08,420 Because the majority of the database vendors, they say, 94 00:08:08,420 --> 00:08:11,360 if you crash a database, that's not a security problem. 95 00:08:11,600 --> 00:08:16,340 So if you run a select statement and the database dies, that's not a security problem. 96 00:08:16,580 --> 00:08:21,060 That's the opinion of IBM, Microsoft, and also of DB2. 97 00:08:21,640 --> 00:08:31,000 And only if you release it to the press and you explicitly say that's a security vulnerability, then they are fixing it. 98 00:08:31,280 --> 00:08:38,200 But the majority of denial of service and database crashes are not handled from the database vendors. 99 00:08:38,420 --> 00:08:40,900 As a security bug. 100 00:08:43,160 --> 00:08:50,300 And this is a good example that the entire quality of DB2, I talked also to several DB2 DBAs, 101 00:08:50,340 --> 00:08:53,060 is not that good comparing to Oracle. 102 00:08:53,540 --> 00:08:57,180 For example, here you have the problem if you have a duplicate predicate. 103 00:08:57,540 --> 00:09:01,980 So if you have the same condition two times, the database dies. 104 00:09:02,640 --> 00:09:04,520 So this was fixed a few months ago. 105 00:09:05,160 --> 00:09:07,340 And that's really weird that 106 00:09:07,340 --> 00:09:10,640 if you use the same condition, the database dies. 107 00:09:10,940 --> 00:09:14,680 So the entire parsing engine from DB2, from my experience, 108 00:09:14,780 --> 00:09:20,960 is less stable than the engine from Oracle or SQL Server. 109 00:09:21,260 --> 00:09:23,460 SQL Server is the most secure for my... 110 00:09:25,220 --> 00:09:29,540 And then also if you use special constructs. 111 00:09:29,540 --> 00:09:31,580 For example, a single byte partition. 112 00:09:31,780 --> 00:09:33,880 So you create this object and the database dies. 113 00:09:35,520 --> 00:09:37,320 And you get this entire code. 114 00:09:37,340 --> 00:09:38,660 As a test case. 115 00:09:38,840 --> 00:09:41,320 So the database vendors say it's a test case. 116 00:09:41,480 --> 00:09:43,260 In the security world, it's an exploit. 117 00:09:43,520 --> 00:09:45,600 You can get it from the IBM pages. 118 00:09:46,320 --> 00:09:50,380 And I think IBM should rethink about their strategy 119 00:09:50,380 --> 00:09:54,360 to release this kind of code to the public. 120 00:09:55,900 --> 00:09:58,160 Also here, if you create such a table 121 00:09:59,480 --> 00:10:02,040 and run a select statement against it, 122 00:10:02,160 --> 00:10:04,180 then the database dies. 123 00:10:07,340 --> 00:10:07,820 We had this. 124 00:10:08,880 --> 00:10:12,140 Also here, if you use a keyword as a column name, 125 00:10:12,860 --> 00:10:14,080 you have the same problem. 126 00:10:15,200 --> 00:10:17,840 But it's not that bad for IBM. 127 00:10:17,960 --> 00:10:19,900 If you look at the Oracle side, 128 00:10:20,540 --> 00:10:21,700 it's quite the same. 129 00:10:21,880 --> 00:10:24,480 So if you use really weird SQL statements, 130 00:10:24,900 --> 00:10:27,800 the chances that you crash the database are quite big. 131 00:10:28,460 --> 00:10:30,700 So especially if you use reserved words, 132 00:10:30,840 --> 00:10:31,960 if you use short words, 133 00:10:32,080 --> 00:10:33,760 if you use special characters, and so on. 134 00:10:34,840 --> 00:10:36,380 And here, it's quite difficult 135 00:10:37,340 --> 00:10:38,480 to protect against these attacks. 136 00:10:39,780 --> 00:10:44,240 Because there is no privilege which could be revoked. 137 00:10:44,380 --> 00:10:49,880 You just have to wait until IBM is releasing a bug fix. 138 00:10:54,640 --> 00:10:56,520 Also here, outer join is probably 139 00:10:56,520 --> 00:10:58,740 one of the most complicated constructs. 140 00:10:58,920 --> 00:11:01,300 Oracle, in the last few years, 141 00:11:01,360 --> 00:11:04,680 and also IBM and Microsoft SQL Server, 142 00:11:04,780 --> 00:11:06,980 they always had problems with outer joins. 143 00:11:07,560 --> 00:11:09,820 And here, by using this outer join, 144 00:11:10,040 --> 00:11:11,200 you can crash the database. 145 00:11:12,160 --> 00:11:14,160 Sometimes you are also getting wrong results. 146 00:11:16,600 --> 00:11:20,020 Also by using weird insert statements, 147 00:11:20,120 --> 00:11:21,760 you can also crash the instance. 148 00:11:23,000 --> 00:11:24,660 That's also one of my favorites. 149 00:11:24,860 --> 00:11:27,040 Just by using a lot of union statements, 150 00:11:27,420 --> 00:11:28,540 you can crash the database. 151 00:11:28,940 --> 00:11:30,640 So if you do a SQL injection, 152 00:11:30,880 --> 00:11:32,660 and you append too many unions, 153 00:11:32,840 --> 00:11:33,840 the database will die. 154 00:11:35,040 --> 00:11:37,320 But it's not a security problem. 155 00:11:37,320 --> 00:11:38,640 It's a vulnerability for IBM. 156 00:11:39,940 --> 00:11:45,060 This was one vulnerability on the command line. 157 00:11:45,920 --> 00:11:50,120 So there's a small program from IBM 158 00:11:50,120 --> 00:11:52,140 called db2-license-manager. 159 00:11:52,260 --> 00:11:53,840 And with this db2-license-manager, 160 00:11:54,040 --> 00:11:57,040 you can change the ownership of a file. 161 00:11:57,900 --> 00:12:02,060 So normally, db2 does not run with root privileges 162 00:12:02,060 --> 00:12:03,580 on a Unix system. 163 00:12:03,720 --> 00:12:06,100 But using this db2-license-manager, 164 00:12:06,100 --> 00:12:10,320 you're able to change the ownership 165 00:12:11,640 --> 00:12:13,480 from root files and other files. 166 00:12:17,080 --> 00:12:23,620 So you see there are a lot of potential issues there. 167 00:12:24,700 --> 00:12:28,820 But if I compare the different databases, 168 00:12:29,480 --> 00:12:30,560 so in the Oracle world, 169 00:12:30,720 --> 00:12:32,600 you have 10 times more vulnerabilities. 170 00:12:34,500 --> 00:12:37,860 And IBM db2 is between Microsoft, 171 00:12:38,260 --> 00:12:40,200 which is the best system so far, 172 00:12:40,400 --> 00:12:44,280 and Oracle. 173 00:12:44,480 --> 00:12:46,180 So it's in the middle. 174 00:12:48,000 --> 00:12:51,060 And the fixpacks are normally the most interesting way 175 00:12:51,060 --> 00:12:52,520 to find new issues. 176 00:12:52,960 --> 00:12:54,560 So just go to the websites, 177 00:12:54,740 --> 00:12:58,640 look for everything which can crash the database. 178 00:12:58,780 --> 00:13:02,040 It's also a good idea to do this on the MySQL, 179 00:13:02,040 --> 00:13:03,340 bug database. 180 00:13:03,660 --> 00:13:07,260 Just look for database crashes or for strange results. 181 00:13:07,700 --> 00:13:11,360 And then you can often create your own exploit for it. 182 00:13:11,420 --> 00:13:13,380 Because the majority of administrators 183 00:13:14,020 --> 00:13:16,580 does not have the time to fix, 184 00:13:16,720 --> 00:13:21,320 to apply all the fixpacks just in time. 185 00:13:21,420 --> 00:13:23,080 It often takes months or years 186 00:13:23,080 --> 00:13:24,880 before they apply the latest fixpacks. 187 00:13:25,160 --> 00:13:27,800 So that's common for all the big databases. 188 00:13:30,260 --> 00:13:31,620 What I also saw, 189 00:13:31,620 --> 00:13:34,960 and so far there's no paper about it, 190 00:13:35,020 --> 00:13:38,840 it's SQL injection in custom PLSQL code. 191 00:13:40,440 --> 00:13:44,600 Because a lot of database vendors, 192 00:13:44,820 --> 00:13:45,980 database developers, 193 00:13:46,340 --> 00:13:51,060 are creating their own start procedure code 194 00:13:51,060 --> 00:13:51,760 in the database 195 00:13:52,620 --> 00:13:54,200 to be more performant. 196 00:13:54,700 --> 00:13:58,560 And since db2 9.7, 197 00:13:59,940 --> 00:14:01,600 there are now two possibilities. 198 00:14:01,620 --> 00:14:04,580 To write your own start procedure code. 199 00:14:04,740 --> 00:14:05,700 One is SQL PL. 200 00:14:05,960 --> 00:14:07,360 That's the old classic version. 201 00:14:07,740 --> 00:14:08,960 And two, 202 00:14:11,640 --> 00:14:14,460 the second possibility is to use PLSQL. 203 00:14:14,800 --> 00:14:17,500 So they license PLSQL from the Postgres guys. 204 00:14:19,440 --> 00:14:22,100 Because they hope that Oracle customers 205 00:14:22,100 --> 00:14:24,640 will switch from Oracle to db2. 206 00:14:25,540 --> 00:14:26,640 And here is, 207 00:14:27,780 --> 00:14:30,820 before we look at the SQL injection vulnerabilities, 208 00:14:30,820 --> 00:14:33,940 two, three nice things, 209 00:14:34,080 --> 00:14:36,600 which are helpful if you work with security. 210 00:14:37,980 --> 00:14:39,780 A lot of the interesting commands 211 00:14:39,780 --> 00:14:41,860 cannot be executed from a select statement. 212 00:14:42,120 --> 00:14:44,440 Something like exporting a table 213 00:14:44,440 --> 00:14:47,640 or describing a table. 214 00:14:47,820 --> 00:14:50,280 That's not possible from a normal SQL command. 215 00:14:50,840 --> 00:14:53,200 And to circumvent this problem, 216 00:14:53,480 --> 00:14:57,580 there's a built-in start procedure from IBM 217 00:14:57,580 --> 00:14:59,480 called admincmd. 218 00:14:59,480 --> 00:15:01,540 And with this admincmd command, 219 00:15:01,880 --> 00:15:03,640 you can run from SQL 220 00:15:05,500 --> 00:15:07,220 these db2 commands. 221 00:15:08,100 --> 00:15:10,700 So for example, we can export a file 222 00:15:10,700 --> 00:15:15,120 or we can kill a session of another user. 223 00:15:16,160 --> 00:15:18,640 But it's clear that you need advanced privileges 224 00:15:18,640 --> 00:15:20,760 to call this start procedure. 225 00:15:23,640 --> 00:15:25,900 There was, a few months ago, 226 00:15:26,020 --> 00:15:28,700 there was a problem with a start procedure 227 00:15:28,700 --> 00:15:31,480 called monreport.currentsql. 228 00:15:32,000 --> 00:15:33,500 In some fixpacks, 229 00:15:33,680 --> 00:15:34,900 it was granted to public. 230 00:15:35,220 --> 00:15:38,500 And this start procedure 231 00:15:38,500 --> 00:15:43,080 is revealing the entire SQL cache. 232 00:15:43,920 --> 00:15:46,180 So all the statements which were executed 233 00:15:46,180 --> 00:15:47,640 by other people are visible 234 00:15:47,640 --> 00:15:52,100 via this monreport function. 235 00:15:52,940 --> 00:15:54,400 And this is quite useful 236 00:15:54,400 --> 00:15:56,720 if you are doing performance tuning 237 00:15:56,720 --> 00:15:57,900 or if you're looking for, 238 00:15:57,900 --> 00:16:01,180 if you are looking for problems and bottlenecks. 239 00:16:01,620 --> 00:16:04,380 But it's also a security problem 240 00:16:04,620 --> 00:16:06,780 because every statement also 241 00:16:06,780 --> 00:16:08,180 insert into a password table. 242 00:16:08,340 --> 00:16:10,720 This statement is visible in this 243 00:16:12,440 --> 00:16:14,860 current SQL function. 244 00:16:15,740 --> 00:16:18,940 Or if you are inserting numbers 245 00:16:18,940 --> 00:16:20,400 into a credit card table, 246 00:16:20,520 --> 00:16:21,560 it's also visible here. 247 00:16:22,020 --> 00:16:24,960 That's why you should be careful 248 00:16:25,620 --> 00:16:27,460 with this start procedure. 249 00:16:30,040 --> 00:16:31,040 And sometimes, 250 00:16:31,160 --> 00:16:32,880 if you work with SQL injection, 251 00:16:33,280 --> 00:16:34,980 it's interesting to know 252 00:16:34,980 --> 00:16:37,380 how to create a semicolon separated list. 253 00:16:38,720 --> 00:16:42,760 So this is useful to get more out of a database. 254 00:16:43,040 --> 00:16:44,640 So if you're doing SQL injection, 255 00:16:44,960 --> 00:16:47,680 you're normally getting row by row. 256 00:16:48,100 --> 00:16:48,900 So if you have, 257 00:16:49,810 --> 00:16:52,060 if a query returns 100 rows, 258 00:16:52,280 --> 00:16:53,920 you're getting 100 lines. 259 00:16:54,520 --> 00:16:55,880 And with this statement, 260 00:16:56,080 --> 00:16:57,540 it's possible to get 261 00:16:57,540 --> 00:16:58,680 a semicolon or here, 262 00:16:58,760 --> 00:16:59,780 a comma separated list 263 00:17:01,120 --> 00:17:03,140 in one row, one column. 264 00:17:03,860 --> 00:17:06,000 So this can be useful for SQL injection 265 00:17:06,000 --> 00:17:07,660 because with one SQL statement, 266 00:17:07,900 --> 00:17:09,680 you can get the entire table back 267 00:17:09,680 --> 00:17:10,740 instead of doing, 268 00:17:10,880 --> 00:17:12,900 instead of enumerating it row by row. 269 00:17:14,640 --> 00:17:15,980 And it's special because 270 00:17:16,540 --> 00:17:17,740 every database vendor 271 00:17:17,740 --> 00:17:19,480 has its own special dialect. 272 00:17:19,660 --> 00:17:21,240 It's not part of the normal syntax. 273 00:17:21,620 --> 00:17:24,920 So every vendor has a different approach. 274 00:17:25,200 --> 00:17:26,940 So in MySQL, for example, 275 00:17:26,940 --> 00:17:29,200 it's called group concat to do this. 276 00:17:31,220 --> 00:17:31,860 Okay. 277 00:17:32,080 --> 00:17:35,340 So now we're looking at vulnerabilities in custom code. 278 00:17:35,580 --> 00:17:38,500 And all the code I reviewed so far 279 00:17:38,500 --> 00:17:41,420 in the internet and also at the customer side 280 00:17:41,420 --> 00:17:41,980 was . 281 00:17:41,980 --> 00:17:45,180 So I never saw database developers 282 00:17:45,180 --> 00:17:46,920 doing input validation. 283 00:17:48,720 --> 00:17:51,040 So it's difficult to understand 284 00:17:51,040 --> 00:17:52,160 why they are not doing it. 285 00:17:52,240 --> 00:17:55,900 Probably they think we are too close to the database 286 00:17:55,900 --> 00:17:58,340 and nobody will ever inject code. 287 00:17:58,800 --> 00:18:00,180 But that's not the case. 288 00:18:01,820 --> 00:18:03,960 So here we have a typical example. 289 00:18:04,840 --> 00:18:06,960 And you can see even without 290 00:18:07,900 --> 00:18:10,340 deep DB2 or database knowledge, 291 00:18:10,600 --> 00:18:11,880 you can find this vulnerability. 292 00:18:12,200 --> 00:18:13,700 We have a stored procedure. 293 00:18:17,240 --> 00:18:18,620 Administrator ground privileges. 294 00:18:19,000 --> 00:18:21,420 And here we have a parameter OS user. 295 00:18:22,260 --> 00:18:24,260 And you see there's no input validation. 296 00:18:24,260 --> 00:18:26,140 So the input validation here is missing. 297 00:18:26,520 --> 00:18:29,280 And the developer of this code was doing the following. 298 00:18:29,540 --> 00:18:33,280 He's concatenating the value of OS user 299 00:18:33,280 --> 00:18:35,520 which is coming from the stored procedure. 300 00:18:35,700 --> 00:18:37,420 And this is concatenated here. 301 00:18:37,600 --> 00:18:39,080 And after that, it's executed. 302 00:18:40,020 --> 00:18:41,380 So this is one vulnerability. 303 00:18:41,920 --> 00:18:42,980 The second vulnerability 304 00:18:42,980 --> 00:18:45,400 is a second level order SQL injection. 305 00:18:46,280 --> 00:18:49,440 So the developer is trusting 306 00:18:50,000 --> 00:18:52,060 that the table names 307 00:18:52,060 --> 00:18:54,860 are always sanitized. 308 00:18:54,980 --> 00:18:56,200 But as a developer, 309 00:18:56,340 --> 00:18:58,240 you can never guarantee 310 00:18:58,240 --> 00:19:00,520 what is the real table name. 311 00:19:01,540 --> 00:19:04,480 For example, you can create a table called 312 00:19:06,000 --> 00:19:07,340 exclamation mark IM. 313 00:19:07,720 --> 00:19:12,340 Or you can use minus minus in a table name. 314 00:19:12,680 --> 00:19:13,880 In this case, 315 00:19:14,700 --> 00:19:17,380 this custom code is concatenated 316 00:19:17,380 --> 00:19:19,040 without doing input validation. 317 00:19:20,260 --> 00:19:21,580 So whenever you see 318 00:19:21,580 --> 00:19:22,260 such code, 319 00:19:22,480 --> 00:19:24,100 you should try to find 320 00:19:24,100 --> 00:19:25,160 the responsible developer. 321 00:19:25,800 --> 00:19:28,200 And he should use bind variables. 322 00:19:28,380 --> 00:19:29,900 Or if this is not possible here, 323 00:19:30,060 --> 00:19:30,740 for example, 324 00:19:30,900 --> 00:19:32,500 then he should do input validation. 325 00:19:32,920 --> 00:19:35,000 So he has to validate 326 00:19:35,000 --> 00:19:37,080 that the table name is proper. 327 00:19:37,560 --> 00:19:39,300 And you have to validate 328 00:19:39,300 --> 00:19:40,360 that the OS user 329 00:19:40,360 --> 00:19:41,880 is in the right format. 330 00:19:43,080 --> 00:19:44,440 And here another example. 331 00:19:45,660 --> 00:19:48,020 And if you go to the Internet, 332 00:19:48,160 --> 00:19:49,020 it's really easy 333 00:19:49,020 --> 00:19:50,380 to find vulnerable code. 334 00:19:50,380 --> 00:19:53,600 Because I never found people 335 00:19:53,600 --> 00:19:54,620 doing input validation. 336 00:19:54,640 --> 00:19:56,640 So the chances that you'll find something 337 00:19:56,640 --> 00:19:57,820 are really, really high. 338 00:19:58,500 --> 00:20:00,140 So here we have two parameters, 339 00:20:00,580 --> 00:20:03,160 the old table schema 340 00:20:03,160 --> 00:20:04,800 and the old table name. 341 00:20:06,020 --> 00:20:07,120 And you see here, 342 00:20:07,160 --> 00:20:08,720 they are just concatenating the values 343 00:20:09,140 --> 00:20:10,600 without doing input validation. 344 00:20:12,280 --> 00:20:14,440 Or here it's similar. 345 00:20:16,900 --> 00:20:18,280 They create a string, 346 00:20:18,460 --> 00:20:20,140 concatenate everything together, 347 00:20:20,140 --> 00:20:21,520 and then they call this 348 00:20:21,520 --> 00:20:22,800 with admin CMD. 349 00:20:23,220 --> 00:20:24,380 Here's one limitation. 350 00:20:24,940 --> 00:20:27,320 If you use admin CMD, 351 00:20:27,460 --> 00:20:28,700 you are not able 352 00:20:28,700 --> 00:20:30,120 to use command signs. 353 00:20:30,440 --> 00:20:31,820 So you cannot use minus minus 354 00:20:31,820 --> 00:20:33,180 to put something at the end. 355 00:20:33,280 --> 00:20:34,860 Or you cannot use a semicolon 356 00:20:34,860 --> 00:20:37,660 to expand the query. 357 00:20:42,180 --> 00:20:44,180 Since db2 9.7, 358 00:20:44,340 --> 00:20:45,540 it's also possible 359 00:20:45,540 --> 00:20:47,780 to use PLSQL code. 360 00:20:48,000 --> 00:20:49,080 And with PLSQL, 361 00:20:49,360 --> 00:20:50,120 you have the ability 362 00:20:50,140 --> 00:20:51,960 to have a bunch of new vulnerabilities 363 00:20:51,960 --> 00:20:53,420 coming into the system. 364 00:20:54,320 --> 00:21:00,360 So the way in the db2 version of PLSQL, 365 00:21:01,060 --> 00:21:03,740 you have to use DBMS SQL 366 00:21:03,740 --> 00:21:05,900 to create dynamic SQL statements. 367 00:21:06,720 --> 00:21:08,300 So the problem here is, 368 00:21:08,400 --> 00:21:10,240 we have a function. 369 00:21:10,380 --> 00:21:11,420 This function looks 370 00:21:11,420 --> 00:21:12,460 if the table is empty. 371 00:21:12,940 --> 00:21:14,340 And we have a parameter, 372 00:21:14,560 --> 00:21:15,120 the table name. 373 00:21:15,920 --> 00:21:16,840 And this table name 374 00:21:16,840 --> 00:21:19,640 is concatenated to the query 375 00:21:19,640 --> 00:21:22,580 and the query is executed here with parse. 376 00:21:22,960 --> 00:21:25,600 It's parsed and then executed and fetched. 377 00:21:26,720 --> 00:21:28,420 So if you use a union 378 00:21:28,420 --> 00:21:29,780 or a minus minus 379 00:21:29,780 --> 00:21:31,920 at the end of this parameter, 380 00:21:32,260 --> 00:21:34,200 you can extend this query 381 00:21:34,200 --> 00:21:35,800 and you can run whatever you want. 382 00:21:37,580 --> 00:21:39,240 And this is quite common. 383 00:21:39,540 --> 00:21:42,360 And whenever you do a security audit 384 00:21:42,360 --> 00:21:43,400 for db2 databases, 385 00:21:43,540 --> 00:21:45,540 you should also look at a custom code. 386 00:21:45,960 --> 00:21:47,000 Because the vendors 387 00:21:47,000 --> 00:21:48,660 are getting better and better. 388 00:21:48,660 --> 00:21:51,620 But typical database developer, 389 00:21:51,920 --> 00:21:53,880 they do not get money or time 390 00:21:53,880 --> 00:21:55,200 to develop secure code. 391 00:21:55,420 --> 00:21:57,140 That's why you will find 392 00:21:57,140 --> 00:21:58,160 a lot of these vulnerabilities. 393 00:22:04,560 --> 00:22:05,660 In my experience, 394 00:22:05,820 --> 00:22:07,620 the fastest way to do it 395 00:22:07,620 --> 00:22:10,380 is just extract the entire 396 00:22:11,000 --> 00:22:12,320 stored procedure code 397 00:22:12,320 --> 00:22:13,300 to a text file, 398 00:22:13,420 --> 00:22:14,400 to one big text file, 399 00:22:14,520 --> 00:22:16,000 and then use the CREP statement 400 00:22:16,630 --> 00:22:18,120 or use a text editor 401 00:22:18,660 --> 00:22:20,080 and search for strings like 402 00:22:20,360 --> 00:22:22,300 execute immediate and dbmssql. 403 00:22:22,620 --> 00:22:24,240 And then you can search back. 404 00:22:24,440 --> 00:22:25,580 For example, here, 405 00:22:26,600 --> 00:22:27,640 dbmssql execute, 406 00:22:27,920 --> 00:22:28,980 where is it coming from? 407 00:22:29,180 --> 00:22:30,400 From this parameter. 408 00:22:30,780 --> 00:22:32,140 And then you can search 409 00:22:32,140 --> 00:22:34,060 if the parameters are validated or not. 410 00:22:34,920 --> 00:22:37,040 So it's not real magic. 411 00:22:37,160 --> 00:22:38,340 It's quite simple 412 00:22:38,340 --> 00:22:41,320 and easy way to find this. 413 00:22:43,940 --> 00:22:46,340 And for PLSQL, 414 00:22:46,580 --> 00:22:48,040 there's a source code analysis tool 415 00:22:48,660 --> 00:22:49,400 from Fortify. 416 00:22:49,540 --> 00:22:51,140 But for SQLPL, 417 00:22:51,320 --> 00:22:51,820 I'm not aware 418 00:22:51,820 --> 00:22:54,480 if there's source code analysis available. 419 00:22:55,520 --> 00:22:58,100 But I think doing it manually 420 00:22:58,100 --> 00:22:59,960 is also sufficient 421 00:22:59,960 --> 00:23:04,480 if you don't have tons of SQLPL code. 422 00:23:07,400 --> 00:23:08,980 What is also interesting 423 00:23:08,980 --> 00:23:11,680 is how to escape from the database. 424 00:23:11,960 --> 00:23:14,060 So the typical ways to escape 425 00:23:14,060 --> 00:23:15,660 is read or write files, 426 00:23:16,380 --> 00:23:17,620 access the network, 427 00:23:18,660 --> 00:23:19,560 send something to the network, 428 00:23:19,740 --> 00:23:21,640 or escape to the operating system 429 00:23:21,640 --> 00:23:23,020 and then from the operating system 430 00:23:23,020 --> 00:23:24,980 to a different system. 431 00:23:26,440 --> 00:23:27,460 And accessing files, 432 00:23:27,660 --> 00:23:28,580 there are different possibilities 433 00:23:28,580 --> 00:23:29,780 available in DB2. 434 00:23:30,500 --> 00:23:32,980 So you can use the load data command. 435 00:23:33,320 --> 00:23:34,620 You can import, export. 436 00:23:35,020 --> 00:23:37,940 You can use user-defined function. 437 00:23:38,500 --> 00:23:40,980 And the newest UTL file 438 00:23:40,980 --> 00:23:42,820 and dbmssql from the Oracle world. 439 00:23:44,360 --> 00:23:45,100 And I... 440 00:23:46,380 --> 00:23:47,840 So in the Oracle world, 441 00:23:47,840 --> 00:23:50,320 UTL file and dbmssql are granted to public, 442 00:23:50,540 --> 00:23:51,740 which is not a good idea. 443 00:23:51,940 --> 00:23:52,580 And what do you think 444 00:23:52,580 --> 00:23:55,560 what is the default configuration of DB2? 445 00:23:57,140 --> 00:23:58,600 It's also granted to public. 446 00:24:00,460 --> 00:24:00,960 Okay. 447 00:24:01,460 --> 00:24:03,280 So with load data, 448 00:24:03,540 --> 00:24:04,540 it's quite simple. 449 00:24:07,860 --> 00:24:09,180 With import-export, 450 00:24:09,380 --> 00:24:10,300 I played a little bit. 451 00:24:10,760 --> 00:24:11,260 It's... 452 00:24:11,840 --> 00:24:14,220 By using this ADMCMD, 453 00:24:14,340 --> 00:24:15,580 it's quite easy to use. 454 00:24:17,160 --> 00:24:19,120 So you say export to, 455 00:24:19,280 --> 00:24:21,180 and then you are creating a test file. 456 00:24:22,840 --> 00:24:26,860 And what I did on my test system on Windows, 457 00:24:27,200 --> 00:24:29,460 I was able to override the boot.ini. 458 00:24:30,660 --> 00:24:34,080 So this export command 459 00:24:34,080 --> 00:24:36,940 does not protect your files. 460 00:24:37,180 --> 00:24:39,160 So if you override the executable, 461 00:24:40,180 --> 00:24:42,180 this executable is overwritten 462 00:24:42,180 --> 00:24:43,500 by the export statement. 463 00:24:43,500 --> 00:24:46,460 So you can use it for a denial of service 464 00:24:46,460 --> 00:24:49,980 to destroy files on the database server. 465 00:24:56,220 --> 00:24:59,080 The third possibility is a user-defined function. 466 00:24:59,920 --> 00:25:01,800 And for a user-defined function, 467 00:25:02,080 --> 00:25:04,200 you need a start procedure, 468 00:25:04,520 --> 00:25:05,460 create read file, 469 00:25:05,660 --> 00:25:08,840 and the read file is calling a user-defined function. 470 00:25:10,060 --> 00:25:11,520 And in the sample code 471 00:25:11,520 --> 00:25:13,420 from IBM, 472 00:25:13,660 --> 00:25:15,640 this is granted to public, 473 00:25:15,860 --> 00:25:17,160 which is also a bad idea. 474 00:25:17,760 --> 00:25:19,860 So if you play on the test system, 475 00:25:20,020 --> 00:25:21,460 you should not run it to public. 476 00:25:21,780 --> 00:25:22,620 And additionally, 477 00:25:22,820 --> 00:25:24,180 you need a C function. 478 00:25:24,600 --> 00:25:30,020 And the C function is here limited, 479 00:25:30,220 --> 00:25:32,540 so you can read a file 480 00:25:32,540 --> 00:25:33,720 from the operating system. 481 00:25:34,040 --> 00:25:36,200 And the usage itself is quite simple. 482 00:25:36,280 --> 00:25:37,760 You say select staff from table, 483 00:25:37,980 --> 00:25:39,680 and then you specify the function, 484 00:25:39,880 --> 00:25:41,000 and you see the result 485 00:25:41,000 --> 00:25:43,720 from the file in your statement. 486 00:25:44,000 --> 00:25:46,160 So it's really easy to use. 487 00:25:49,420 --> 00:25:51,820 Next possibility is utl file. 488 00:25:52,800 --> 00:25:55,680 To use PL-SQL in DB2, 489 00:25:55,860 --> 00:25:58,420 you have to set a special environment variable. 490 00:25:59,580 --> 00:26:02,180 And I would recommend not to use it. 491 00:26:02,300 --> 00:26:05,520 So if you don't need PL-SQL, 492 00:26:05,800 --> 00:26:07,980 you should remove it from the database. 493 00:26:08,580 --> 00:26:10,000 Because I think 494 00:26:10,000 --> 00:26:11,140 in the future, 495 00:26:11,220 --> 00:26:15,360 you will find a lot of vulnerabilities here. 496 00:26:16,720 --> 00:26:18,920 And I'm not sure if it's a good idea 497 00:26:18,920 --> 00:26:20,680 to use systems, 498 00:26:23,680 --> 00:26:25,060 to use a language 499 00:26:25,060 --> 00:26:27,480 from a different database vendor. 500 00:26:29,500 --> 00:26:30,840 And if you use it, 501 00:26:30,880 --> 00:26:31,640 then you should revoke 502 00:26:31,640 --> 00:26:33,120 all the public privileges. 503 00:26:36,000 --> 00:26:38,700 You should revoke the privileges from public. 504 00:26:40,760 --> 00:26:42,420 You can also remove files. 505 00:26:42,720 --> 00:26:44,820 So if you look at the documentation 506 00:26:44,820 --> 00:26:46,420 from the utl file package, 507 00:26:46,680 --> 00:26:47,760 you can rename files, 508 00:26:47,940 --> 00:26:48,760 you can remove files. 509 00:26:49,000 --> 00:26:50,180 So whatever you need 510 00:26:51,260 --> 00:26:53,020 on the operating system level 511 00:26:53,020 --> 00:26:54,600 can be easily done with 512 00:26:54,600 --> 00:26:57,160 a simple PL-SQL function 513 00:26:57,160 --> 00:26:58,600 or anonymous block. 514 00:27:00,860 --> 00:27:02,040 The second possibility 515 00:27:03,420 --> 00:27:04,840 to read files 516 00:27:04,840 --> 00:27:07,220 is the function dbms-lob. 517 00:27:07,320 --> 00:27:08,700 And here we have also 518 00:27:10,340 --> 00:27:11,900 a function, 519 00:27:12,180 --> 00:27:14,460 or that's a copy-paste failure. 520 00:27:17,020 --> 00:27:18,200 Accessing the network, 521 00:27:18,380 --> 00:27:19,980 I haven't found something 522 00:27:19,980 --> 00:27:22,980 from the original db2 part, 523 00:27:23,240 --> 00:27:27,900 but the Oracle stuff in db2 524 00:27:27,900 --> 00:27:31,540 has two problematic packages. 525 00:27:31,880 --> 00:27:33,260 One is utl-smtp 526 00:27:33,260 --> 00:27:34,940 and the second utl-mail. 527 00:27:35,240 --> 00:27:37,700 With utl-smtp, 528 00:27:37,860 --> 00:27:39,260 you can write 529 00:27:39,260 --> 00:27:41,580 a small start procedure block 530 00:27:42,260 --> 00:27:43,500 and then you can define 531 00:27:44,140 --> 00:27:45,900 the message, 532 00:27:46,220 --> 00:27:46,620 the date, 533 00:27:47,580 --> 00:27:49,020 the smtp server, 534 00:27:51,060 --> 00:27:52,560 and then you send the email. 535 00:27:54,180 --> 00:27:56,060 If db2 is configured, 536 00:27:56,240 --> 00:27:58,100 so for using utl-mail, 537 00:27:58,300 --> 00:27:59,520 you have to configure 538 00:27:59,520 --> 00:28:01,680 the smtp server in your system. 539 00:28:01,840 --> 00:28:02,960 And in this case, 540 00:28:03,000 --> 00:28:04,000 you can just use 541 00:28:04,000 --> 00:28:06,640 this call utl-mail.send 542 00:28:06,640 --> 00:28:07,820 and then you specify 543 00:28:07,820 --> 00:28:09,840 sender, recipients, and so on. 544 00:28:12,720 --> 00:28:13,680 The last thing, 545 00:28:13,740 --> 00:28:14,920 accessing operating system, 546 00:28:15,140 --> 00:28:16,280 I found so far 547 00:28:16,280 --> 00:28:17,300 only the way via 548 00:28:17,300 --> 00:28:18,440 user-defined functions. 549 00:28:19,580 --> 00:28:22,420 And this is also quite simple. 550 00:28:23,560 --> 00:28:24,780 You can more or less 551 00:28:24,780 --> 00:28:25,720 use every language. 552 00:28:25,940 --> 00:28:26,700 Here I'm showing 553 00:28:26,700 --> 00:28:28,220 an example in C. 554 00:28:29,740 --> 00:28:31,260 First, we have to create 555 00:28:31,260 --> 00:28:32,140 an export file, 556 00:28:32,940 --> 00:28:34,040 library.dev, 557 00:28:34,820 --> 00:28:35,960 and we copy it 558 00:28:35,960 --> 00:28:36,940 to the SQL lib. 559 00:28:36,940 --> 00:28:39,840 Then we create a function, 560 00:28:40,100 --> 00:28:41,500 execute the function, 561 00:28:41,700 --> 00:28:42,140 that's it. 562 00:28:44,360 --> 00:28:46,200 So similar to this read function, 563 00:28:46,360 --> 00:28:47,940 we have here a function system call. 564 00:28:48,620 --> 00:28:49,760 And this system call 565 00:28:49,760 --> 00:28:52,280 is calling the external file 566 00:28:52,280 --> 00:28:53,580 OS call system call. 567 00:28:54,400 --> 00:28:55,940 And you grant this to public. 568 00:28:56,100 --> 00:28:57,420 Also here, it's a bad idea 569 00:28:57,420 --> 00:28:58,000 to do this. 570 00:29:00,160 --> 00:29:01,600 And this is the C code 571 00:29:01,600 --> 00:29:02,340 and you see here 572 00:29:02,340 --> 00:29:03,600 the system call, 573 00:29:03,760 --> 00:29:04,720 system command, 574 00:29:05,000 --> 00:29:06,340 and here you are executing 575 00:29:06,340 --> 00:29:06,900 the status. 576 00:29:06,940 --> 00:29:09,100 And once you installed it 577 00:29:09,100 --> 00:29:09,640 in the database, 578 00:29:09,960 --> 00:29:13,560 you can just run the system call 579 00:29:13,560 --> 00:29:15,280 and can do whatever you want. 580 00:29:20,620 --> 00:29:21,740 Hardening DB2 581 00:29:21,740 --> 00:29:24,420 is much more easier 582 00:29:24,420 --> 00:29:25,420 in my experience 583 00:29:25,420 --> 00:29:27,540 than hardening Oracle 584 00:29:27,540 --> 00:29:29,000 because you have less 585 00:29:29,000 --> 00:29:30,500 public privileges. 586 00:29:32,220 --> 00:29:35,880 And the big difference is 587 00:29:35,880 --> 00:29:37,460 you are hardening more 588 00:29:37,460 --> 00:29:38,820 on the operating system level. 589 00:29:39,000 --> 00:29:39,640 So you are running 590 00:29:40,920 --> 00:29:41,980 special commands 591 00:29:42,600 --> 00:29:43,700 and then you are 592 00:29:43,700 --> 00:29:45,080 changing the configuration. 593 00:29:46,120 --> 00:29:48,260 And the DB2 CIS benchmark 594 00:29:48,260 --> 00:29:49,140 is quite good. 595 00:29:49,300 --> 00:29:50,240 So if you compare 596 00:29:50,240 --> 00:29:51,600 the CIS benchmark 597 00:29:51,600 --> 00:29:54,560 for MySQL or Oracle, 598 00:29:54,780 --> 00:29:56,340 the DB2 benchmark 599 00:29:56,340 --> 00:29:57,100 is quite good. 600 00:29:57,360 --> 00:29:58,720 And I would recommend 601 00:29:58,720 --> 00:29:59,580 to use this 602 00:29:59,580 --> 00:30:00,460 as a starting point. 603 00:30:01,260 --> 00:30:02,280 So they have a lot 604 00:30:02,280 --> 00:30:03,820 of good recommendations. 605 00:30:03,820 --> 00:30:06,060 And from my experience 606 00:30:06,060 --> 00:30:07,720 from security audits, 607 00:30:08,780 --> 00:30:10,700 I normally recommend 608 00:30:10,700 --> 00:30:11,880 disable everything 609 00:30:11,880 --> 00:30:13,100 which is not necessary. 610 00:30:13,480 --> 00:30:14,400 In DB2, 611 00:30:14,520 --> 00:30:16,160 it's much easier 612 00:30:16,160 --> 00:30:17,460 because for a lot 613 00:30:17,460 --> 00:30:18,580 of additional functionality, 614 00:30:18,720 --> 00:30:19,900 you need a license file. 615 00:30:20,260 --> 00:30:21,820 And you have to pay 616 00:30:21,820 --> 00:30:22,420 for functionality. 617 00:30:22,820 --> 00:30:23,240 In Oracle, 618 00:30:23,420 --> 00:30:25,320 everything can be installed 619 00:30:25,320 --> 00:30:26,620 without additional license. 620 00:30:26,720 --> 00:30:28,060 That's why people often 621 00:30:28,060 --> 00:30:28,860 install everything. 622 00:30:29,040 --> 00:30:30,420 And in DB2, 623 00:30:30,620 --> 00:30:32,260 they normally install 624 00:30:32,260 --> 00:30:33,580 only what is necessary. 625 00:30:35,860 --> 00:30:37,640 Do not install the PLSQL 626 00:30:37,640 --> 00:30:38,700 if it's not needed. 627 00:30:38,940 --> 00:30:40,780 And check the OS credentials. 628 00:30:41,900 --> 00:30:45,860 So in most of the cases, 629 00:30:46,500 --> 00:30:47,780 the biggest problem 630 00:30:47,780 --> 00:30:49,080 in other databases 631 00:30:49,080 --> 00:30:50,080 are the user credentials. 632 00:30:50,560 --> 00:30:52,540 So developers are lazy guys. 633 00:30:52,820 --> 00:30:54,860 And if you have a user name, 634 00:30:55,020 --> 00:30:56,640 they often use the same 635 00:30:57,920 --> 00:30:59,280 string as a password. 636 00:31:00,680 --> 00:31:03,080 And this is also the case 637 00:31:03,080 --> 00:31:04,520 in the DB2 world. 638 00:31:04,760 --> 00:31:06,280 But it's not a DB2 problem. 639 00:31:06,500 --> 00:31:07,680 It's an operating system problem. 640 00:31:08,120 --> 00:31:09,800 So finding credentials 641 00:31:09,800 --> 00:31:12,060 like DB2-inst or DB2-admin, 642 00:31:12,100 --> 00:31:13,900 DB2-admin is not uncommon. 643 00:31:14,840 --> 00:31:15,740 So it really depends 644 00:31:15,740 --> 00:31:16,720 from the configuration 645 00:31:16,720 --> 00:31:17,900 of the underlying 646 00:31:17,900 --> 00:31:18,820 operating system. 647 00:31:19,220 --> 00:31:20,460 But in general, 648 00:31:20,600 --> 00:31:22,080 the situation is better 649 00:31:22,080 --> 00:31:23,060 than other systems. 650 00:31:25,020 --> 00:31:25,740 Okay. 651 00:31:25,800 --> 00:31:27,100 What are the typical steps 652 00:31:27,100 --> 00:31:29,660 to harden the DB2 database? 653 00:31:31,840 --> 00:31:33,000 You should have 654 00:31:33,080 --> 00:31:35,000 a look at the OS credentials. 655 00:31:35,620 --> 00:31:36,720 You should... 656 00:31:38,640 --> 00:31:39,940 In the real world, 657 00:31:40,020 --> 00:31:41,860 you find weak OS credentials. 658 00:31:41,860 --> 00:31:44,300 You find that the discovery mode 659 00:31:44,300 --> 00:31:44,800 is enabled. 660 00:31:44,940 --> 00:31:45,760 The discovery mode 661 00:31:46,900 --> 00:31:49,320 is announcing in the network 662 00:31:49,320 --> 00:31:51,680 what databases are available. 663 00:31:52,320 --> 00:31:53,980 And just by disabling 664 00:31:53,980 --> 00:31:55,700 this discovery mode, 665 00:31:56,700 --> 00:31:58,680 you will be much more secure 666 00:31:58,680 --> 00:31:59,980 because it's much more difficult 667 00:31:59,980 --> 00:32:01,100 to find the database. 668 00:32:01,100 --> 00:32:04,260 What I heard in DB2-10, 669 00:32:04,500 --> 00:32:06,200 this will be removed from... 670 00:32:06,200 --> 00:32:07,300 This discovery mode 671 00:32:07,300 --> 00:32:09,420 will be removed in DB2-10, 672 00:32:09,540 --> 00:32:10,660 version 10. 673 00:32:11,380 --> 00:32:12,980 And we have too many privileges, 674 00:32:13,380 --> 00:32:14,440 weak default configuration, 675 00:32:15,000 --> 00:32:15,840 missing patches, 676 00:32:16,080 --> 00:32:17,460 and unsecured program code. 677 00:32:17,700 --> 00:32:19,640 So this is more or less normal 678 00:32:19,640 --> 00:32:21,380 like every other database vendor. 679 00:32:23,380 --> 00:32:24,040 Okay. 680 00:32:24,700 --> 00:32:25,900 So the hardening. 681 00:32:27,000 --> 00:32:28,480 Disable the discovery mode. 682 00:32:28,560 --> 00:32:29,620 Change default port. 683 00:32:31,000 --> 00:32:32,880 So this discovery mode 684 00:32:32,880 --> 00:32:34,260 is disabled by using 685 00:32:34,260 --> 00:32:35,860 these two DB2 commands. 686 00:32:37,820 --> 00:32:39,980 And after doing this, 687 00:32:39,980 --> 00:32:41,480 it's disabled. 688 00:32:42,660 --> 00:32:44,180 Then you can change the port. 689 00:32:45,260 --> 00:32:46,440 It's also recommended 690 00:32:46,440 --> 00:32:47,580 in the CIS benchmark. 691 00:32:47,780 --> 00:32:49,060 I was never a big fan 692 00:32:49,060 --> 00:32:50,120 of changing the port, 693 00:32:50,260 --> 00:32:52,120 but if you live better with it, 694 00:32:52,220 --> 00:32:53,420 it's okay. 695 00:32:53,800 --> 00:32:55,080 Normally with a port scanner, 696 00:32:55,140 --> 00:32:56,340 you will find the port 697 00:32:56,340 --> 00:32:57,780 even if it's running 698 00:32:57,780 --> 00:32:59,600 on a quite strange port. 699 00:33:01,040 --> 00:33:02,480 Then here are some 700 00:33:02,480 --> 00:33:03,280 of the privileges 701 00:33:03,280 --> 00:33:04,420 which should be removed 702 00:33:04,420 --> 00:33:05,640 from public. 703 00:33:07,040 --> 00:33:08,760 So you can just put it 704 00:33:08,760 --> 00:33:09,980 into a script and run it. 705 00:33:11,100 --> 00:33:12,400 There are quite of them. 706 00:33:14,840 --> 00:33:16,500 Then here are some other 707 00:33:16,500 --> 00:33:18,440 useful parameters. 708 00:33:18,860 --> 00:33:20,580 And you should check 709 00:33:20,580 --> 00:33:22,000 that you have these 710 00:33:23,020 --> 00:33:24,880 strong settings available. 711 00:33:26,120 --> 00:33:27,620 Also discovery authentication 712 00:33:28,320 --> 00:33:29,560 that the authentication 713 00:33:29,620 --> 00:33:31,120 is encrypted and so on. 714 00:33:33,800 --> 00:33:35,980 That's something I'm a big fan 715 00:33:35,980 --> 00:33:37,000 of logon trigger. 716 00:33:37,360 --> 00:33:38,560 Because the majority 717 00:33:38,560 --> 00:33:40,300 of database administrator, 718 00:33:40,700 --> 00:33:42,380 doesn't matter what vendor, 719 00:33:42,640 --> 00:33:43,680 they have no idea 720 00:33:43,680 --> 00:33:44,640 who is connecting 721 00:33:44,640 --> 00:33:45,460 to their database. 722 00:33:48,400 --> 00:33:51,980 And that's why it's really important 723 00:33:52,480 --> 00:33:54,340 to know who is connecting 724 00:33:54,340 --> 00:33:55,560 from what machine 725 00:33:55,560 --> 00:33:56,620 with what account. 726 00:33:57,320 --> 00:33:58,300 Only in this case, 727 00:33:58,300 --> 00:34:00,240 you can limit access 728 00:34:00,240 --> 00:34:01,000 to the database. 729 00:34:01,300 --> 00:34:02,340 So you can say, 730 00:34:02,420 --> 00:34:04,640 okay, only from this machine, 731 00:34:04,740 --> 00:34:06,200 the agent account is enabled 732 00:34:06,200 --> 00:34:07,280 to do this. 733 00:34:08,740 --> 00:34:10,620 And there's a new functionality 734 00:34:10,620 --> 00:34:12,040 called connect proc. 735 00:34:12,400 --> 00:34:13,800 And with this connect proc, 736 00:34:14,000 --> 00:34:15,640 it's quite easy to implement 737 00:34:16,600 --> 00:34:18,220 logon trigger functionality. 738 00:34:21,620 --> 00:34:23,420 So what we do first 739 00:34:23,420 --> 00:34:24,900 is to create a table. 740 00:34:24,980 --> 00:34:27,260 And this table is storing 741 00:34:27,260 --> 00:34:29,200 the information about the user ID, 742 00:34:29,420 --> 00:34:30,880 the event and the timestamp. 743 00:34:31,000 --> 00:34:32,240 So you know at least 744 00:34:32,240 --> 00:34:33,920 who's connecting to the system. 745 00:34:35,880 --> 00:34:37,300 If you play with this, 746 00:34:38,320 --> 00:34:40,160 you should probably extend it 747 00:34:40,160 --> 00:34:42,260 to a few additional values. 748 00:34:42,920 --> 00:34:44,320 But I think for the beginning, 749 00:34:44,480 --> 00:34:45,720 it's quite a good idea. 750 00:34:46,460 --> 00:34:47,660 And then you create 751 00:34:47,660 --> 00:34:48,880 a start procedure. 752 00:34:49,080 --> 00:34:50,000 And it's important 753 00:34:50,000 --> 00:34:50,880 that the start procedure 754 00:34:50,880 --> 00:34:52,020 doesn't have a parameter. 755 00:34:52,200 --> 00:34:53,760 So only if the start procedure 756 00:34:54,700 --> 00:34:56,060 runs without parameter, 757 00:34:56,340 --> 00:34:56,900 it works. 758 00:34:57,860 --> 00:34:59,580 And here we are inserting 759 00:35:00,260 --> 00:35:03,340 this, we are inserting 760 00:35:03,340 --> 00:35:04,960 in this audit table 761 00:35:04,960 --> 00:35:05,880 we created before 762 00:35:05,880 --> 00:35:08,600 the connect and the timestamp 763 00:35:08,600 --> 00:35:09,120 and the username. 764 00:35:10,160 --> 00:35:12,200 Then we update the configuration. 765 00:35:15,000 --> 00:35:16,460 And here it's important 766 00:35:16,460 --> 00:35:17,820 that we first set it to null. 767 00:35:18,300 --> 00:35:20,920 And after it, 768 00:35:21,000 --> 00:35:25,400 we specify the function. 769 00:35:29,320 --> 00:35:31,140 So the next time when we connect, 770 00:35:32,220 --> 00:35:34,740 we can see this connect string 771 00:35:34,740 --> 00:35:36,800 here in the select state, 772 00:35:36,980 --> 00:35:38,660 in this table. 773 00:35:40,840 --> 00:35:42,040 And I would recommend 774 00:35:42,040 --> 00:35:42,840 in the beginning, 775 00:35:42,920 --> 00:35:46,480 look after a few hours 776 00:35:46,480 --> 00:35:48,020 into this table to avoid 777 00:35:48,020 --> 00:35:49,760 that it's filled up quite fast. 778 00:35:50,400 --> 00:35:52,060 And if you have a process 779 00:35:52,060 --> 00:35:52,880 which is connecting 780 00:35:53,160 --> 00:35:54,040 every few seconds 781 00:35:54,040 --> 00:35:54,940 to the system, 782 00:35:55,220 --> 00:35:56,300 you should probably 783 00:35:56,300 --> 00:35:57,100 add an extension 784 00:35:57,100 --> 00:35:58,220 and saying, okay, 785 00:35:58,300 --> 00:35:59,640 if this special user 786 00:35:59,640 --> 00:36:00,700 from this IP address 787 00:36:00,700 --> 00:36:01,980 is connecting to the system, 788 00:36:02,100 --> 00:36:04,900 do not record this activity. 789 00:36:09,220 --> 00:36:11,580 So I see I was quite fast, 790 00:36:11,680 --> 00:36:15,060 faster than in my trainings, 791 00:36:16,220 --> 00:36:17,480 in my preparation. 792 00:36:18,720 --> 00:36:19,800 So at the moment, 793 00:36:21,460 --> 00:36:23,600 there is nearly no 794 00:36:23,600 --> 00:36:25,320 DB2 security resources. 795 00:36:25,700 --> 00:36:26,600 So if you look in the web, 796 00:36:26,700 --> 00:36:28,440 there are a few outdated books 797 00:36:28,440 --> 00:36:33,260 and there are no modules 798 00:36:33,260 --> 00:36:34,240 in Metasploit, 799 00:36:34,400 --> 00:36:35,540 as far as I remember. 800 00:36:35,840 --> 00:36:36,640 And the majority 801 00:36:36,640 --> 00:36:37,920 of the security crowd 802 00:36:37,920 --> 00:36:39,720 is not looking at DB2. 803 00:36:40,620 --> 00:36:41,860 But I'm quite sure 804 00:36:41,860 --> 00:36:42,680 if you look at it, 805 00:36:42,740 --> 00:36:43,560 you will find a lot 806 00:36:43,560 --> 00:36:44,560 of interesting stuff. 807 00:36:47,080 --> 00:36:48,740 And the most interesting 808 00:36:48,740 --> 00:36:50,940 security bugs are at the moment 809 00:36:50,940 --> 00:36:51,860 published by IBM. 810 00:36:51,860 --> 00:36:53,640 But sooner or later, 811 00:36:53,720 --> 00:36:54,780 they will also realize 812 00:36:54,780 --> 00:36:55,780 that it's a bad idea 813 00:36:55,780 --> 00:36:57,020 to publish exploit code. 814 00:37:01,340 --> 00:37:02,700 And concerning 815 00:37:02,700 --> 00:37:04,100 the password problem, 816 00:37:04,300 --> 00:37:05,400 which is the biggest problem 817 00:37:05,400 --> 00:37:06,320 in other databases, 818 00:37:08,920 --> 00:37:10,280 like Oracle, 819 00:37:11,240 --> 00:37:12,420 it's not existing 820 00:37:12,420 --> 00:37:15,100 because DB2 delegated 821 00:37:15,420 --> 00:37:15,940 this problem 822 00:37:15,940 --> 00:37:19,260 to the operating system. 823 00:37:19,600 --> 00:37:20,660 But I'm aware 824 00:37:20,660 --> 00:37:21,880 there are also plugins 825 00:37:21,880 --> 00:37:24,260 where you can use your, 826 00:37:24,900 --> 00:37:26,380 where you can use a table 827 00:37:26,960 --> 00:37:28,580 for connecting to the database. 828 00:37:28,880 --> 00:37:29,920 So people migrated 829 00:37:30,260 --> 00:37:31,180 the Oracle concept 830 00:37:31,180 --> 00:37:32,320 of a username table 831 00:37:32,320 --> 00:37:33,860 to the DB2 world. 832 00:37:34,040 --> 00:37:34,800 But it's quite rare 833 00:37:34,800 --> 00:37:35,500 that you find this. 834 00:37:39,280 --> 00:37:39,840 Okay. 835 00:37:42,980 --> 00:37:44,280 Thank you for the time. 836 00:37:45,600 --> 00:37:47,020 So it was quite fast. 837 00:37:48,380 --> 00:37:49,780 And I updated 838 00:37:49,780 --> 00:37:51,840 this slide a little bit, 839 00:37:51,880 --> 00:37:53,140 this slide deck. 840 00:37:53,620 --> 00:37:55,060 And you will get 841 00:37:55,060 --> 00:37:56,260 the updated version as PDF.