1 00:00:00,000 --> 00:00:03,520 Thanks very much for coming to this talk. We are going to be looking at hacking and 2 00:00:03,920 --> 00:00:09,440 forensicating an Oracle database server. Although I just gave this talk at Black Hat and I had an 3 00:00:09,440 --> 00:00:13,260 hour and a half to do it. I've just found out I've got 50 minutes so I've had to like slice some of 4 00:00:13,260 --> 00:00:17,180 the talk. So I think the boring forensic side can go and the hacking side is the fun part, 5 00:00:17,240 --> 00:00:24,060 especially for this audience. So we'll concentrate on that. So who am I? If you're wondering who I 6 00:00:24,060 --> 00:00:30,200 am, I'm a vulnerability researcher. I started out in buffer overflow exploitation. The last bit 7 00:00:30,200 --> 00:00:35,700 of work I did that I'm really proud of was back in 2003. That was defeating the stack-based 8 00:00:35,700 --> 00:00:44,740 protection built into Windows 2003 server. I then started moving into database security. If anyone 9 00:00:44,740 --> 00:00:53,660 remembers the SQL slammer worm, I was partly responsible for that, unfortunately. And when 10 00:00:53,660 --> 00:00:54,040 Oracle came out, I was part of the SQL slammer worm. I was part of the SQL slammer worm. I was 11 00:00:54,060 --> 00:00:57,460 turned around and said their products were unbreakable. I laughed a little bit and did some 12 00:00:57,460 --> 00:01:04,320 research and proved it wasn't unbreakable by any stretch of the imagination. So I've been 13 00:01:04,320 --> 00:01:11,140 concentrating on the CNE side of things or had been up until about 2007, 2008, and started 14 00:01:11,140 --> 00:01:14,800 looking to the forensic side because obviously it was so trivial to break into database servers 15 00:01:14,800 --> 00:01:22,920 and continues to this day to be trivial to break into database servers. Read Oracle. The whole idea 16 00:01:22,920 --> 00:01:28,300 of, well, if someone is breaking in, how do we find out what they did when they got there and what 17 00:01:28,780 --> 00:01:36,080 we can do to, you know, work out what we can do to prevent them from doing the same thing. So that led 18 00:01:36,080 --> 00:01:41,760 on to the forensic side. I recently, well, recently, a couple of years ago, I sold my company, 19 00:01:41,820 --> 00:01:46,240 so I get to do free stuff now. I have no commercial presses, which is great. So everything 20 00:01:47,260 --> 00:01:52,900 presented here is all the white papers are free, all the tools, which I probably won't have time to 21 00:01:52,900 --> 00:01:56,780 for, but you can go to the Verity website and download them. They're all free. There's no 22 00:01:56,780 --> 00:02:02,580 commercial version of it or anything like that. So, yeah, if you want to follow my research, I can 23 00:02:02,580 --> 00:02:09,720 be found on D. Litchfield on Twitter or email me at David at Verity.com with a three for an E. 24 00:02:11,620 --> 00:02:16,720 So database breaches are common. That's much as a given these days. I don't think I need to 25 00:02:16,720 --> 00:02:22,840 convince many people here that databases are where the goodies are at. I recently, 26 00:02:22,900 --> 00:02:27,580 recently did a survey on the Oracle L mailing list, which is like for DBAs and programmers and 27 00:02:27,580 --> 00:02:35,880 stuff like that. It's a fairly good list, and I asked who's doing checks on their logs, you know, 28 00:02:35,920 --> 00:02:40,200 like security logs and so on, and only one-third of DBAs are actually checking their stuff, and 29 00:02:40,200 --> 00:02:43,980 most of those are using grep, and I find that astonishing because, let's face it, grep's not 30 00:02:43,980 --> 00:02:50,660 going to work on, you know, binary-based, you know, bespoke custom file formats that most 31 00:02:50,660 --> 00:02:51,680 databases have. 32 00:02:53,540 --> 00:02:57,760 Forensics seems to be this, or database forensics specifically seems to be this no-man's land where 33 00:02:57,760 --> 00:03:04,100 the incident response people are saying, well, you know, I understand the IR stuff really well, 34 00:03:04,960 --> 00:03:10,060 like analyzing hard drives and so on, but databases, well, that's this whole other extra stuff I need 35 00:03:10,060 --> 00:03:14,660 to learn, and right now I'm working with too many other cases, and the database guys are like, 36 00:03:14,740 --> 00:03:20,020 whoa, I know all about how to, like, improve the speed of a database and so on, but when it comes 37 00:03:20,020 --> 00:03:22,380 to IR stuff, yeah, that's way over my head. 38 00:03:22,900 --> 00:03:23,560 I'm just going to stick to the stuff I know. 39 00:03:23,700 --> 00:03:28,960 So there just seems to be this no-man's land where no one seems to be doing any work, and as a consequence, 40 00:03:29,200 --> 00:03:32,340 it lags behind on the forensics front. 41 00:03:33,460 --> 00:03:34,880 So getting to the good stuff. 42 00:03:35,540 --> 00:03:36,420 Compromising the database. 43 00:03:38,340 --> 00:03:41,880 So in a typical database compromise, there are several stages. 44 00:03:42,240 --> 00:03:43,900 First off, there's gaining access, obviously. 45 00:03:45,300 --> 00:03:49,400 Once they've managed to gain access, they obviously then need to elevate privileges if they want 46 00:03:49,400 --> 00:03:51,140 to have full control over that database server. 47 00:03:51,140 --> 00:03:56,300 Once they've got the privileges, the requisite privileges to do whatever they want, they 48 00:03:56,300 --> 00:03:57,740 might want to modify data. 49 00:03:57,960 --> 00:03:59,380 They might want to exfiltrate data. 50 00:03:59,540 --> 00:04:03,420 There's a whole number of things that they want to do, and thereafter, they might want 51 00:04:03,420 --> 00:04:08,080 to use that database server as a staging platform to attack the rest of the network, you know, 52 00:04:08,080 --> 00:04:13,420 so that might include breaking out the database to run operating system commands and then 53 00:04:13,420 --> 00:04:14,740 download their toolkits and so on. 54 00:04:14,860 --> 00:04:16,880 So we'll look at each of these sections individually. 55 00:04:18,140 --> 00:04:18,580 Okay. 56 00:04:18,920 --> 00:04:21,120 So I've been playing around with this. 57 00:04:21,140 --> 00:04:26,040 I've been playing with Oracle for ten years, give or take a year or so. 58 00:04:27,660 --> 00:04:33,780 And yeah, it all started when Larry Ellison announced at his conference that Oracle was 59 00:04:33,780 --> 00:04:34,380 unbreakable. 60 00:04:34,820 --> 00:04:39,880 And you know, you say that to a hacker, and that's like a Red Bull to a flag? 61 00:04:40,180 --> 00:04:41,360 A red flag to a bull. 62 00:04:42,800 --> 00:04:46,860 And I was drinking Red Bull earlier, and I think that's why I'm speaking so fast as 63 00:04:46,860 --> 00:04:48,740 well, and I've got Red Bull in the brain, not red flags. 64 00:04:51,280 --> 00:04:51,760 Yeah. 65 00:04:51,900 --> 00:04:58,340 My brother and I did quite a bit of research, and Mark found, my brother Mark found a really 66 00:04:58,340 --> 00:04:58,960 interesting flaw. 67 00:04:59,200 --> 00:05:05,240 And this is, remember, an EAL four plus certified products under the common criteria. 68 00:05:05,600 --> 00:05:10,220 And Mark found a flaw basically where if you entered an overly long user name, there 69 00:05:10,220 --> 00:05:12,660 was a stack-based buffer overflow, which was trivial to exploit. 70 00:05:13,540 --> 00:05:20,540 So a product which, under the common criteria, is supposedly secure, you know, could, in 71 00:05:20,540 --> 00:05:22,920 the authentication mechanism alone, be trivially compromised. 72 00:05:23,780 --> 00:05:25,340 And of course, that wasn't the only flaw. 73 00:05:25,460 --> 00:05:27,540 There were a number of issues. 74 00:05:28,060 --> 00:05:29,580 Buffer overflows in the TNS listener. 75 00:05:29,800 --> 00:05:32,600 I'll explain in a minute what, in fact, let's explain what the TNS listener is. 76 00:05:32,720 --> 00:05:32,860 Okay. 77 00:05:33,120 --> 00:05:35,220 So you have the Oracle database server. 78 00:05:35,640 --> 00:05:41,140 The first port of call a client connects to is the TNS listener. 79 00:05:41,280 --> 00:05:44,920 The TNS listener is responsible for communication on the Oracle database server. 80 00:05:45,600 --> 00:05:47,200 This is really disconcerting, by the way. 81 00:05:47,280 --> 00:05:50,200 I can't see anyone's faces, you know, so always I can see these bright lights. 82 00:05:50,200 --> 00:05:55,220 But anyway, the TNS listener is responsible for communication. 83 00:05:56,020 --> 00:06:01,260 So when a client connects to the TNS listener, it hands off the connection to the Oracle 84 00:06:01,260 --> 00:06:04,220 database process and communication takes place thereafter. 85 00:06:05,300 --> 00:06:12,140 Now the TNS listener itself has had a number of buffer overflows in it in the past. 86 00:06:12,280 --> 00:06:16,900 So again, without a user ID and password, an attacker can exploit these to trivially 87 00:06:16,900 --> 00:06:17,400 gain control. 88 00:06:17,640 --> 00:06:19,460 But a much more interesting attack. 89 00:06:19,460 --> 00:06:24,680 One that doesn't require exploitation of buffer overflows was a thing known as external 90 00:06:24,680 --> 00:06:26,420 procedures exploitation, XPROC. 91 00:06:26,540 --> 00:06:28,680 So I'll go into that very, very quickly. 92 00:06:29,140 --> 00:06:34,140 So let's say you're using the database normally and you want to execute PL, SQL code. 93 00:06:34,480 --> 00:06:39,940 PL, SQL code is like the way you extend the Oracle database server and can, like, execute 94 00:06:39,940 --> 00:06:43,760 stuff that basically allows business logic to take place and so on. 95 00:06:43,940 --> 00:06:48,800 Now let's say PL, SQL, which is, you know, a fairly substantial language, doesn't do 96 00:06:48,800 --> 00:06:51,480 what you require it to do, what you can do is can we 97 00:06:51,480 --> 00:06:59,320 see library and hook that into the database server by using external procedures. 98 00:07:00,080 --> 00:07:06,240 Now what happens is, once we compile our library, we then tell the database server 99 00:07:06,240 --> 00:07:08,300 about it by doing our create library statement. 100 00:07:08,680 --> 00:07:14,980 And we wrap that library within a procedure basically which then calls the function within 101 00:07:14,980 --> 00:07:15,440 the library. 102 00:07:15,660 --> 00:07:16,720 Now what happens is.... 103 00:07:17,640 --> 00:07:20,580 the Oracle process connects back to the TNS listener 104 00:07:20,580 --> 00:07:23,520 and says, will you load this library, 105 00:07:23,760 --> 00:07:26,400 execute this function, and pass it these parameters? 106 00:07:26,840 --> 00:07:29,980 And the TNS listener goes, well, you know, I won't do it for you, 107 00:07:30,020 --> 00:07:31,800 but I'll tell you what, I know a program that will. 108 00:07:31,940 --> 00:07:33,940 And it launches this program called Xproc 109 00:07:33,940 --> 00:07:36,800 and tells the Oracle process to connect to Xproc, 110 00:07:36,880 --> 00:07:42,560 and the Oracle database process then says to Xproc, 111 00:07:42,640 --> 00:07:44,840 load this library, execute this function, 112 00:07:44,980 --> 00:07:46,060 and pass it these parameters. 113 00:07:46,720 --> 00:07:48,720 And Xproc goes and does that for it. 114 00:07:49,020 --> 00:07:52,020 Now, normally this happens over named pipes, 115 00:07:52,630 --> 00:07:58,420 but it turns out that you can use TCP as well, which is great, 116 00:07:58,520 --> 00:08:00,820 because me on the other side of the Internet 117 00:08:00,820 --> 00:08:02,300 can connect to a TNS listener, 118 00:08:02,420 --> 00:08:04,100 providing, of course, the firewall allows access, 119 00:08:04,300 --> 00:08:06,800 and there are unfirewalled Oracle servers out there, 120 00:08:06,880 --> 00:08:09,180 and say to the TNS listener, 121 00:08:09,960 --> 00:08:12,580 I'm the Oracle process, wink, wink, nudge, nudge, 122 00:08:12,700 --> 00:08:14,600 will you load this library for me? 123 00:08:14,680 --> 00:08:16,560 And the TNS listener sends back, 124 00:08:16,720 --> 00:08:18,480 me a message over TCP, 125 00:08:19,140 --> 00:08:21,520 and says, no, but if you connect to this port, 126 00:08:22,880 --> 00:08:23,840 Xproc will do it for you. 127 00:08:23,940 --> 00:08:27,260 So I then connect to that TCP port that Xproc is now listening on, 128 00:08:27,380 --> 00:08:29,540 and then I say to Xproc, hey, do me a favor, will you? 129 00:08:29,740 --> 00:08:31,740 Load this library, execute this function, 130 00:08:31,800 --> 00:08:32,540 and pass it these parameters. 131 00:08:32,900 --> 00:08:35,700 And Xproc goes, yeah, no worries, and there you go. 132 00:08:35,780 --> 00:08:37,000 Without a user ID and password, 133 00:08:37,180 --> 00:08:38,920 we can load any library we want, 134 00:08:39,060 --> 00:08:40,900 execute any function, and pass it any parameters. 135 00:08:41,060 --> 00:08:45,500 So, of course, we could use load msvcrt.dll, 136 00:08:45,660 --> 00:08:46,700 the Microsoft VM, 137 00:08:46,720 --> 00:08:47,280 Visual C runtime, 138 00:08:47,580 --> 00:08:48,780 and execute the system function. 139 00:08:49,100 --> 00:08:50,200 Or if it's a Unix system, 140 00:08:50,320 --> 00:08:52,200 we could call LibC and do exactly the same thing. 141 00:08:52,500 --> 00:08:53,860 So we now are running code 142 00:08:53,860 --> 00:08:57,400 as the user account that Oracle runs under. 143 00:08:57,580 --> 00:08:59,220 So on Windows, that's going to be local system, 144 00:08:59,360 --> 00:09:02,540 or Linux, it's going to be the Oracle user. 145 00:09:03,060 --> 00:09:05,580 Either way, as far as the database is concerned, 146 00:09:05,720 --> 00:09:06,160 you are God. 147 00:09:07,420 --> 00:09:08,820 So Oracle fixed that, 148 00:09:09,800 --> 00:09:11,180 and it's a really funny, 149 00:09:12,020 --> 00:09:13,400 yeah, it is actually funny, 150 00:09:14,160 --> 00:09:16,040 fix whereby they said, okay, 151 00:09:16,040 --> 00:09:18,040 what we're going to do now is limit 152 00:09:18,040 --> 00:09:20,140 where you can load libraries from. 153 00:09:20,920 --> 00:09:23,140 And any attempt to load a library 154 00:09:23,140 --> 00:09:26,480 outside of the designated place 155 00:09:26,480 --> 00:09:28,240 will log that, 156 00:09:28,340 --> 00:09:32,180 just so there's some forensics information there. 157 00:09:32,740 --> 00:09:37,360 And they did that by using SprintF 158 00:09:37,360 --> 00:09:41,480 to pass the library name into a stack-based buffer. 159 00:09:42,020 --> 00:09:44,160 And anyone who programs in C here 160 00:09:44,160 --> 00:09:45,380 and with a fixed size, 161 00:09:46,040 --> 00:09:48,280 buffer on the stack without any length checking done, 162 00:09:48,540 --> 00:09:50,880 you immediately know, well, SprintF is going to lead 163 00:09:50,880 --> 00:09:52,400 to a stack-based buffer overflow vulnerability. 164 00:09:52,740 --> 00:09:55,900 So even though they limited the library, 165 00:09:55,960 --> 00:09:57,520 where the library could be loaded from, 166 00:09:57,580 --> 00:09:59,840 all I needed to do to regain control 167 00:09:59,840 --> 00:10:00,980 without a user ID and password 168 00:10:00,980 --> 00:10:02,980 was exploit this new buffer overflow 169 00:10:02,980 --> 00:10:03,840 in the logging process. 170 00:10:04,700 --> 00:10:06,900 So Oracle, we were informed about that, 171 00:10:07,120 --> 00:10:09,560 and they fixed it by putting a length check 172 00:10:09,560 --> 00:10:10,860 before calling SprintF. 173 00:10:11,060 --> 00:10:13,060 Why they didn't call SNPrintF, I don't know, 174 00:10:13,140 --> 00:10:14,800 but they decided to remain with the SprintF. 175 00:10:15,160 --> 00:10:16,020 Now, it turns out, 176 00:10:16,020 --> 00:10:18,240 that any environment variable names 177 00:10:18,240 --> 00:10:21,020 within the library name are expanded, 178 00:10:21,300 --> 00:10:23,880 but that's expanded after the length check now. 179 00:10:24,480 --> 00:10:27,520 So if I go $PATH, 180 00:10:27,760 --> 00:10:28,460 and let's face it, 181 00:10:28,540 --> 00:10:31,240 a path is maybe 200, 500 characters 182 00:10:31,240 --> 00:10:32,000 or something like that, 183 00:10:32,080 --> 00:10:34,420 suddenly we get to exploit this buffer overflow again 184 00:10:34,420 --> 00:10:36,620 just by going $PATH, $PATH, $PATH. 185 00:10:36,920 --> 00:10:38,380 We find the sweet spot, 186 00:10:38,460 --> 00:10:39,720 because let's, to be honest, 187 00:10:39,800 --> 00:10:41,320 the path might be different on one system 188 00:10:41,320 --> 00:10:42,440 against another system, 189 00:10:42,560 --> 00:10:44,000 but when we find that sweet spot 190 00:10:44,000 --> 00:10:45,200 where, you know, 191 00:10:45,220 --> 00:10:46,000 the communication is good, 192 00:10:46,020 --> 00:10:46,520 it's just reset, 193 00:10:46,660 --> 00:10:47,240 because, you know, 194 00:10:47,340 --> 00:10:49,100 the X-Proc dies, 195 00:10:49,500 --> 00:10:50,980 we can then move backwards, 196 00:10:51,080 --> 00:10:51,980 byte by byte by byte, 197 00:10:52,620 --> 00:10:53,720 overwrite the save return address, 198 00:10:53,960 --> 00:10:55,600 and we have an expression in the UK, 199 00:10:55,720 --> 00:10:56,220 Bob's your uncle, 200 00:10:56,340 --> 00:10:57,280 I don't know if you've got it over here. 201 00:10:58,400 --> 00:10:59,040 Bob's your uncle, 202 00:10:59,140 --> 00:11:00,100 you own the process again. 203 00:11:02,480 --> 00:11:04,880 So, yeah, the thing is, 204 00:11:04,940 --> 00:11:05,760 even to this day, 205 00:11:06,260 --> 00:11:09,080 if you are local to an Oracle database server, 206 00:11:09,240 --> 00:11:09,860 in other words, 207 00:11:09,860 --> 00:11:11,140 let's say you've got SSH access, 208 00:11:11,560 --> 00:11:12,300 if you're local, 209 00:11:12,400 --> 00:11:14,540 you can still do this trick locally 210 00:11:14,540 --> 00:11:15,880 to get code to run, 211 00:11:16,020 --> 00:11:16,500 someone else. 212 00:11:16,660 --> 00:11:18,340 So, 10 years after the fact, 213 00:11:18,480 --> 00:11:19,420 we can still do this stuff. 214 00:11:19,640 --> 00:11:20,620 Oh, and incidentally, of course, 215 00:11:21,440 --> 00:11:22,980 if UTL TCP is available, 216 00:11:23,300 --> 00:11:25,240 once we're connected to the database server, 217 00:11:25,820 --> 00:11:27,840 as a low-privileged user, 218 00:11:27,920 --> 00:11:28,920 we can use UTL TCP 219 00:11:29,380 --> 00:11:30,840 to create the right packets, 220 00:11:30,960 --> 00:11:32,500 and because we're now suddenly local, 221 00:11:32,700 --> 00:11:33,960 so from the Oracle process, 222 00:11:34,240 --> 00:11:36,480 we are communicating directly 223 00:11:36,480 --> 00:11:37,940 with the listener and X-Proc, 224 00:11:38,040 --> 00:11:39,900 so again, we can still affect this kind of attack. 225 00:11:40,120 --> 00:11:41,740 And today, Oracle is still vulnerable 226 00:11:41,740 --> 00:11:42,600 to this kind of thing. 227 00:11:42,980 --> 00:11:43,300 Now, 228 00:11:45,420 --> 00:11:46,000 one reason, 229 00:11:46,000 --> 00:11:46,360 one would think 230 00:11:46,360 --> 00:11:49,180 that dropping msvcrt.dll 231 00:11:49,180 --> 00:11:50,420 in the directory 232 00:11:51,000 --> 00:11:53,340 where Oracle allows you to load libraries from 233 00:11:53,340 --> 00:11:54,520 is a bad idea, right? 234 00:11:54,980 --> 00:11:55,960 Well, guess what's in there? 235 00:11:56,300 --> 00:11:58,260 You know, it should be in the Windows system 32 directory, 236 00:11:58,440 --> 00:11:59,220 but for some reason, 237 00:11:59,280 --> 00:11:59,580 they thought, 238 00:11:59,660 --> 00:12:01,560 well, we don't want it in there as well. 239 00:12:01,760 --> 00:12:04,780 Sorry, we need it in the Oracle home directory, 240 00:12:04,880 --> 00:12:05,460 in the bin directory. 241 00:12:05,620 --> 00:12:05,820 It's like, 242 00:12:06,280 --> 00:12:08,300 so they make all these fixes 243 00:12:08,300 --> 00:12:10,780 to prevent you from calling the system function 244 00:12:10,780 --> 00:12:12,360 in msvcrt.dll, 245 00:12:12,500 --> 00:12:14,340 but they go ahead and then dump the DLL 246 00:12:14,340 --> 00:12:15,440 in the same directory. 247 00:12:16,280 --> 00:12:18,100 So it's all for naught. 248 00:12:18,180 --> 00:12:19,680 So I really don't understand 249 00:12:19,680 --> 00:12:22,640 what kind of security questions 250 00:12:22,640 --> 00:12:24,500 are being asked at that organization. 251 00:12:24,880 --> 00:12:26,300 Like, we're about to do this. 252 00:12:26,380 --> 00:12:27,620 Is it a good idea? 253 00:12:28,340 --> 00:12:29,820 If not, let's not do it 254 00:12:29,820 --> 00:12:30,740 and find another solution. 255 00:12:31,700 --> 00:12:35,060 That's the minimum kind of security question 256 00:12:35,060 --> 00:12:35,780 that should be going on, 257 00:12:35,860 --> 00:12:37,380 and it's clearly not going on 258 00:12:37,380 --> 00:12:38,120 as far as I'm concerned. 259 00:12:39,080 --> 00:12:41,020 So anyway, there's a whole bunch of ways 260 00:12:41,020 --> 00:12:42,820 that we can use to gain access 261 00:12:43,320 --> 00:12:44,840 without a user ID and password. 262 00:12:46,580 --> 00:12:47,620 And of course, 263 00:12:47,660 --> 00:12:50,560 Oracle is one of these great database servers 264 00:12:50,560 --> 00:12:51,160 that has, 265 00:12:51,840 --> 00:12:53,540 depending upon the applications you install, 266 00:12:53,760 --> 00:12:54,980 a number of default accounts 267 00:12:54,980 --> 00:12:56,940 with default user IDs and passwords installed. 268 00:12:57,460 --> 00:13:00,680 Now, this has changed, obviously, in 10G. 269 00:13:00,760 --> 00:13:02,640 You now have to set a username and password, 270 00:13:02,900 --> 00:13:04,820 sorry, the password for the key accounts, 271 00:13:04,960 --> 00:13:06,580 sys, sysman, db and smp, 272 00:13:06,640 --> 00:13:10,080 and, sorry, sys, sysman, system, db and smp 273 00:13:10,080 --> 00:13:11,260 during the install process. 274 00:13:12,760 --> 00:13:14,100 Whilst you're installing, though, 275 00:13:14,140 --> 00:13:15,360 the default passwords are in place. 276 00:13:15,420 --> 00:13:15,600 So, 277 00:13:15,600 --> 00:13:18,620 sys has the passwords of change on install by default. 278 00:13:18,880 --> 00:13:21,220 But during the installation of the Oracle server, 279 00:13:21,460 --> 00:13:23,380 the password is still change on install. 280 00:13:23,640 --> 00:13:25,320 So if you can find someone installing Oracle 281 00:13:25,320 --> 00:13:26,240 at that particular moment, 282 00:13:26,780 --> 00:13:28,940 you can obviously still connect as sys 283 00:13:28,940 --> 00:13:31,620 with the password of change on install 284 00:13:31,620 --> 00:13:33,840 and do your nefarious stuff 285 00:13:33,840 --> 00:13:35,420 whilst the server's being installed. 286 00:13:35,580 --> 00:13:37,180 Obviously, you have to hit the moment right. 287 00:13:37,600 --> 00:13:38,400 To be fair, 288 00:13:38,480 --> 00:13:40,540 it's probably never going to happen in the real world. 289 00:13:40,620 --> 00:13:42,220 It's just one of those things 290 00:13:42,220 --> 00:13:44,420 you observe in the background. 291 00:13:45,600 --> 00:13:47,240 But there's a whole bunch of accounts out there 292 00:13:47,240 --> 00:13:49,380 that are typically locked 293 00:13:49,380 --> 00:13:51,120 but still have a default password in place. 294 00:13:51,320 --> 00:13:54,100 And you'll find in the wild 295 00:13:54,100 --> 00:13:56,440 there are instances of servers out there 296 00:13:56,440 --> 00:13:59,480 with a db and smp still with its db and smp password. 297 00:13:59,820 --> 00:14:02,320 ctx sys still has its password of ctx sys. 298 00:14:02,380 --> 00:14:05,860 In fact, there are about 600 to 700 accounts 299 00:14:05,860 --> 00:14:08,440 depending upon what products have been installed 300 00:14:08,440 --> 00:14:10,040 with default usernames and passwords. 301 00:14:10,540 --> 00:14:14,560 So even if you can't exploit any buffer overflows, 302 00:14:14,560 --> 00:14:18,720 trying a username with the username as its password 303 00:14:18,720 --> 00:14:19,840 is a good guess. 304 00:14:21,360 --> 00:14:22,460 And so, yeah, 305 00:14:23,040 --> 00:14:26,440 there's a whole number of weak passwords 306 00:14:26,440 --> 00:14:28,160 and account compromises available. 307 00:14:29,320 --> 00:14:31,020 And if we have access to the file system, 308 00:14:31,180 --> 00:14:33,600 what you'll find is that the passwords are often logged. 309 00:14:33,840 --> 00:14:34,540 They're encrypted, 310 00:14:34,740 --> 00:14:36,000 but they can be decrypted 311 00:14:36,000 --> 00:14:37,060 because we know what the keys are. 312 00:14:38,700 --> 00:14:39,640 On the file system, 313 00:14:39,820 --> 00:14:40,640 there are certain log files 314 00:14:40,640 --> 00:14:42,320 where we can staff the passwords out. 315 00:14:42,460 --> 00:14:42,860 So again, 316 00:14:43,440 --> 00:14:43,660 if... 317 00:14:43,660 --> 00:14:44,540 Oh, and they're world-readers. 318 00:14:44,560 --> 00:14:45,280 They're world-readable, of course, as well. 319 00:14:45,580 --> 00:14:47,120 And so, yeah, 320 00:14:47,200 --> 00:14:48,760 even if we don't have a user ID and password 321 00:14:48,760 --> 00:14:50,160 and we have local access to the box, 322 00:14:50,220 --> 00:14:51,060 we can still gain access 323 00:14:52,400 --> 00:14:53,540 by snuffing these passwords. 324 00:14:54,520 --> 00:14:55,180 And of course, 325 00:14:55,220 --> 00:14:56,560 if we're dealing with a web-based application, 326 00:14:57,340 --> 00:14:58,680 then we can just piggyback. 327 00:14:59,160 --> 00:15:01,260 If it's vulnerable to SQL injection, 328 00:15:01,480 --> 00:15:02,120 we can just piggyback. 329 00:15:02,280 --> 00:15:03,660 The whole, you know, 330 00:15:03,720 --> 00:15:05,540 account authorization process is... 331 00:15:06,400 --> 00:15:07,560 Sorry, authentication process 332 00:15:07,560 --> 00:15:09,720 is handled for us by the application. 333 00:15:10,020 --> 00:15:12,560 So we just piggyback our SQL injection 334 00:15:12,560 --> 00:15:13,380 off the back of it. 335 00:15:14,620 --> 00:15:15,180 Okay. 336 00:15:15,400 --> 00:15:19,240 So assuming we get access, 337 00:15:20,360 --> 00:15:20,920 let's... 338 00:15:20,920 --> 00:15:22,220 I'm just going to create an account. 339 00:15:22,340 --> 00:15:28,600 Create user defcon 340 00:15:32,340 --> 00:15:34,860 identified by password. 341 00:15:37,080 --> 00:15:38,000 Oh, great. 342 00:15:38,140 --> 00:15:38,360 Quick. 343 00:15:50,660 --> 00:15:54,580 So I'm going to give this defcon user 344 00:15:56,480 --> 00:15:58,900 a grant create session, rather, 345 00:16:00,320 --> 00:16:01,020 to defcon. 346 00:16:02,260 --> 00:16:04,100 The only privilege required 347 00:16:04,100 --> 00:16:05,560 to connect to the database server 348 00:16:05,560 --> 00:16:06,340 is create session. 349 00:16:07,720 --> 00:16:09,500 I'm then going to connect as this guy. 350 00:16:09,620 --> 00:16:10,060 Okay. 351 00:16:10,120 --> 00:16:13,960 Create defcon password. 352 00:16:14,220 --> 00:16:14,480 Okay. 353 00:16:14,560 --> 00:16:15,960 So this is the account we're going to use 354 00:16:18,240 --> 00:16:20,240 to run our nefarious stuff. 355 00:16:20,320 --> 00:16:21,500 Select staff from session privs. 356 00:16:21,560 --> 00:16:21,800 We'll see. 357 00:16:21,900 --> 00:16:22,500 That's all he's got. 358 00:16:27,100 --> 00:16:27,540 Okay. 359 00:16:27,620 --> 00:16:28,080 Create session. 360 00:16:28,380 --> 00:16:30,700 So basically, this user, 361 00:16:30,820 --> 00:16:32,920 the only privilege he's been granted directly 362 00:16:32,920 --> 00:16:34,600 is the create session privilege. 363 00:16:34,820 --> 00:16:36,440 So he can connect to the database server, 364 00:16:36,560 --> 00:16:38,440 and he can't do anything himself 365 00:16:38,960 --> 00:16:40,040 from here on in, 366 00:16:40,120 --> 00:16:42,260 but there's a special user account called public, 367 00:16:42,340 --> 00:16:43,180 which means... 368 00:16:43,800 --> 00:16:46,000 means everyone on the database server, essentially. 369 00:16:46,260 --> 00:16:47,520 So whatever public can do, 370 00:16:47,680 --> 00:16:49,300 defcon user can do as well. 371 00:16:49,860 --> 00:16:53,420 Now, I spoke about PLSQL earlier on 372 00:16:53,420 --> 00:16:55,300 when I was referencing external procedures. 373 00:16:56,380 --> 00:17:01,260 The default security mechanism 374 00:17:01,260 --> 00:17:04,340 for executing PLSQL objects, 375 00:17:04,440 --> 00:17:06,680 such as procedures, packages, and functions, and so on, 376 00:17:06,780 --> 00:17:10,680 is the definer's privileges are used 377 00:17:10,680 --> 00:17:12,200 to execute... 378 00:17:12,200 --> 00:17:13,140 to execute... 379 00:17:13,140 --> 00:17:14,640 the object. 380 00:17:14,960 --> 00:17:21,960 So if the sys user creates a PLSQL package, 381 00:17:22,460 --> 00:17:23,860 he is the definer. 382 00:17:23,940 --> 00:17:26,940 Any vulnerabilities in that, as the definer, 383 00:17:27,020 --> 00:17:28,660 will execute with sys privileges. 384 00:17:29,000 --> 00:17:29,640 That's the default. 385 00:17:30,300 --> 00:17:32,380 You can also specify, 386 00:17:33,020 --> 00:17:34,880 using the auth ID keyword, 387 00:17:35,160 --> 00:17:37,440 the current user's privileges should be used, 388 00:17:37,520 --> 00:17:39,360 but by default, it's the definer's privileges. 389 00:17:39,940 --> 00:17:43,120 So any package which is owned by a highly... 390 00:17:43,140 --> 00:17:45,080 privileged user and is vulnerable to PLSQL injection 391 00:17:45,080 --> 00:17:48,400 can be abused by an attacker to gain full control... 392 00:17:48,400 --> 00:17:49,000 well, not full control. 393 00:17:49,240 --> 00:17:51,500 It depends on who owns the package, 394 00:17:51,580 --> 00:17:52,480 but in the case of sys, 395 00:17:52,560 --> 00:17:54,640 sys has all the privileges that's required. 396 00:17:55,260 --> 00:18:00,340 So, yeah, if sys owns a vulnerable package, 397 00:18:00,620 --> 00:18:04,120 then an attacker with only create session privileges 398 00:18:04,120 --> 00:18:06,480 can exploit this flaw to gain full control 399 00:18:06,480 --> 00:18:07,240 of the database server. 400 00:18:07,560 --> 00:18:10,760 Now, Oracle has probably had about 401 00:18:10,760 --> 00:18:12,720 three to four hundred... 402 00:18:13,140 --> 00:18:15,920 such issues found in sys-owned packages. 403 00:18:16,160 --> 00:18:17,380 So we're not just talking about 404 00:18:17,380 --> 00:18:19,700 a one-in-two case scenario kind of thing. 405 00:18:19,780 --> 00:18:21,480 This is the Achilles' floor 406 00:18:21,480 --> 00:18:23,180 in the Oracle database server, 407 00:18:23,740 --> 00:18:24,960 and continues to be. 408 00:18:25,080 --> 00:18:25,960 So every three months, 409 00:18:26,120 --> 00:18:27,960 Oracle releases a critical patch update. 410 00:18:28,420 --> 00:18:30,260 Sometimes they fix five critical flaws, 411 00:18:30,380 --> 00:18:32,400 sometimes 20 to 30 critical flaws. 412 00:18:33,260 --> 00:18:34,660 More often than not, 413 00:18:34,760 --> 00:18:37,160 there are at least one or two, if not more, 414 00:18:37,400 --> 00:18:39,600 PLSQL injection vulnerabilities in Oracle. 415 00:18:39,840 --> 00:18:42,200 So I'm going to show you a fake one, 416 00:18:42,260 --> 00:18:43,120 because I don't want to... 417 00:18:46,320 --> 00:18:49,160 I'm just going to show you one that I made. 418 00:18:50,620 --> 00:18:53,340 So if you want real ones, 419 00:18:53,560 --> 00:18:56,820 look at the critical patch update from last time, 420 00:18:56,920 --> 00:18:58,840 or if you want a brand spanking new one, 421 00:18:58,900 --> 00:18:59,720 wait for the next one, 422 00:19:00,200 --> 00:19:02,060 critical patch update to come out. 423 00:19:02,820 --> 00:19:04,420 They're two a penny, these kind of flaws. 424 00:19:08,280 --> 00:19:10,800 So we would, as an attacker, 425 00:19:11,000 --> 00:19:12,200 let's say, remember, 426 00:19:12,300 --> 00:19:13,100 we only have the create session, 427 00:19:13,120 --> 00:19:13,960 session privileges. 428 00:19:14,200 --> 00:19:17,820 If we wanted to do things like delete the audit trail, 429 00:19:17,940 --> 00:19:19,200 we obviously need the privileges to do that. 430 00:19:19,260 --> 00:19:21,280 We can use these SQL injection flaws 431 00:19:21,280 --> 00:19:23,140 in high-privileged packages 432 00:19:23,140 --> 00:19:24,720 to do things like that, 433 00:19:24,780 --> 00:19:27,000 or we might alternatively just say grant ourselves DBA. 434 00:19:27,180 --> 00:19:29,500 Now, that would be a very noisy thing to do, 435 00:19:29,580 --> 00:19:31,060 obviously, in a real-world attack, 436 00:19:31,180 --> 00:19:32,560 and you probably wouldn't want to do that. 437 00:19:33,760 --> 00:19:35,800 So what you might find is 438 00:19:36,880 --> 00:19:39,160 people inserting directly into the sysauth table, 439 00:19:39,740 --> 00:19:42,940 which essentially does the same thing as the DDL, 440 00:19:43,120 --> 00:19:45,360 which is a statement for grant DBA, 441 00:19:45,560 --> 00:19:50,460 but it uses an insert instead to grant those privileges. 442 00:19:50,900 --> 00:19:51,920 And even then, you probably, 443 00:19:52,660 --> 00:19:54,380 all of this kind of stuff is making noise, 444 00:19:54,980 --> 00:19:57,880 and probably won't be done. 445 00:19:58,040 --> 00:19:59,480 But for the sake of argument, 446 00:20:00,040 --> 00:20:02,180 it's a nice demonstration here, so let's do it. 447 00:20:04,020 --> 00:20:07,480 So there was a nice little attack previously, 448 00:20:07,760 --> 00:20:09,580 or a way of facilitating attack, 449 00:20:09,700 --> 00:20:12,060 where we could generate our own cursor 450 00:20:12,060 --> 00:20:12,880 that, 451 00:20:12,880 --> 00:20:15,920 that we would pass our nefarious SQL on, 452 00:20:16,020 --> 00:20:21,560 and we would inject the dbms underscore sql dot execute function 453 00:20:21,560 --> 00:20:23,840 into the vulnerable procedure, 454 00:20:24,600 --> 00:20:27,900 and that would go ahead and execute with the higher privileges. 455 00:20:28,060 --> 00:20:30,280 So whatever SQL we pass, be it grant DBA, 456 00:20:30,480 --> 00:20:32,040 would execute with the higher privileges. 457 00:20:32,220 --> 00:20:33,560 But Oracle went ahead and fixed that. 458 00:20:33,640 --> 00:20:36,280 So what we need now is another way 459 00:20:36,280 --> 00:20:40,640 of looking for ways of running arbitrary SQL. 460 00:20:41,760 --> 00:20:42,560 With SQL, 461 00:20:42,560 --> 00:20:45,120 with Microsoft SQL Server, you can batch SQL statements. 462 00:20:45,380 --> 00:20:47,640 So you can just like do a select, then an insert, 463 00:20:47,780 --> 00:20:49,800 then a grant, and a create, whatever you want, 464 00:20:49,840 --> 00:20:52,220 one after the other in any kind of SQL injection situation. 465 00:20:53,160 --> 00:20:54,660 With Oracle, you can't batch statements. 466 00:20:54,980 --> 00:20:59,260 So if we wanted to say something like grant DBA to public, 467 00:20:59,700 --> 00:21:03,360 and it's in the middle of a select statement, 468 00:21:03,520 --> 00:21:04,440 that's, you know, where the vulnerable, 469 00:21:05,460 --> 00:21:06,680 actually, let's talk about that quickly. 470 00:21:06,900 --> 00:21:08,780 Here's the sample that we're gonna use. 471 00:21:09,060 --> 00:21:10,340 Can everyone see that at the back? 472 00:21:10,440 --> 00:21:11,720 Is the font big enough? 473 00:21:11,720 --> 00:21:12,520 Yeah, it should be. 474 00:21:13,020 --> 00:21:16,300 So all we're doing is the procedure owned by Sys, 475 00:21:16,300 --> 00:21:17,600 in this case, I've called it vulnproc, 476 00:21:17,700 --> 00:21:20,120 and it takes the user input, str, 477 00:21:20,940 --> 00:21:24,220 and concatenates it into this query select object name 478 00:21:24,220 --> 00:21:26,360 from all objects where owner equals user input, 479 00:21:26,520 --> 00:21:28,020 and then executes that query. 480 00:21:28,340 --> 00:21:31,120 Now, this here is an example of PL SQL injection, 481 00:21:31,420 --> 00:21:32,920 but because it's a select statement, 482 00:21:33,000 --> 00:21:34,280 we're injecting into a select statement, 483 00:21:34,480 --> 00:21:36,940 we would be limited to, without an additional hack, 484 00:21:37,240 --> 00:21:40,500 we'd be limited to doing another select statement, 485 00:21:40,500 --> 00:21:41,180 like a union select, 486 00:21:41,180 --> 00:21:41,960 or something like that. 487 00:21:42,680 --> 00:21:45,280 But that doesn't get us DBA privileges, 488 00:21:45,420 --> 00:21:47,460 so what we need to do is, you know, 489 00:21:47,480 --> 00:21:48,460 work out another way of doing that. 490 00:21:48,540 --> 00:21:53,860 So we have our auxiliary inject function, 491 00:21:54,000 --> 00:21:55,500 in this case, it's the new context function 492 00:21:55,500 --> 00:21:58,160 on the DBMS underscore XML query package. 493 00:21:58,640 --> 00:22:02,640 Now, what this does is basically takes an SQL query, 494 00:22:02,740 --> 00:22:06,980 such as select star from dual, and executes that. 495 00:22:07,200 --> 00:22:08,560 But it doesn't have to be 496 00:22:11,180 --> 00:22:11,340 a select statement. 497 00:22:11,660 --> 00:22:16,120 It could be a grant DBA statement, 498 00:22:16,320 --> 00:22:18,320 which we'll show you in a second once that's finished. 499 00:22:19,040 --> 00:22:21,620 I've just freshly started the Oracle database service, 500 00:22:21,800 --> 00:22:24,300 so things need to load into memory. 501 00:22:24,440 --> 00:22:24,820 Right, great. 502 00:22:24,920 --> 00:22:25,360 That's it done. 503 00:22:25,600 --> 00:22:27,460 And that will return very well. 504 00:22:27,720 --> 00:22:31,760 So now we're going to use this to exploit the flaw. 505 00:22:33,360 --> 00:22:35,540 And let me put sys in front of that. 506 00:22:36,320 --> 00:22:36,760 Phew. 507 00:22:40,540 --> 00:22:41,160 That's a lot of time. 508 00:22:41,160 --> 00:22:41,700 before doing that. 509 00:22:42,020 --> 00:22:43,720 Let's show you it's vulnerable to SQL injection. 510 00:22:44,020 --> 00:22:45,760 So we're going to execute foo. 511 00:22:47,260 --> 00:22:48,980 That's how you would execute it normally. 512 00:22:49,240 --> 00:22:53,200 So what would happen is foo would be placed into str, and 513 00:22:53,820 --> 00:22:54,660 the query would execute. 514 00:22:56,340 --> 00:22:59,760 If I put a single quote in there, we see SQL command not 515 00:22:59,760 --> 00:23:00,880 properly ended. 516 00:23:01,020 --> 00:23:03,980 So that's indicative of a SQL injection flaw. 517 00:23:04,720 --> 00:23:05,860 Go minus minus. 518 00:23:06,680 --> 00:23:09,480 And that minus minus basically chops off the rest of the 519 00:23:09,480 --> 00:23:09,640 statement. 520 00:23:11,080 --> 00:23:12,160 So we're all good there. 521 00:23:12,300 --> 00:23:14,880 So now we can go ahead and exploit that to gain. 522 00:23:17,180 --> 00:23:17,680 Did you? 523 00:23:17,880 --> 00:23:19,520 Sorry, I thought someone said something behind my back. 524 00:23:19,580 --> 00:23:20,560 It was a ghost or something. 525 00:23:23,400 --> 00:23:24,200 Lost my train of thought. 526 00:23:24,280 --> 00:23:24,420 Right. 527 00:23:24,560 --> 00:23:27,880 If I do set role DBA, first off, you'll see we've not 528 00:23:27,880 --> 00:23:28,820 been given the DBA role. 529 00:23:30,840 --> 00:23:32,640 DBA role hasn't been granted or does not exist. 530 00:23:32,880 --> 00:23:34,900 So now we're going to gain DBA privileges. 531 00:23:37,140 --> 00:23:38,940 So what we've done there is injected. 532 00:23:38,940 --> 00:23:40,540 This is our little trick, by the way. 533 00:23:40,600 --> 00:23:45,260 Remember I said if we're in a select statement, we can't do 534 00:23:45,260 --> 00:23:47,580 anything other than a union select or whatever, or a 535 00:23:47,580 --> 00:23:47,980 subselect. 536 00:23:48,360 --> 00:23:50,740 Well, this declare pragma autonomous transaction 537 00:23:50,740 --> 00:23:55,220 basically tells the PL SQL compiler, this query is fine 538 00:23:55,220 --> 00:23:56,360 to execute on its own. 539 00:23:56,440 --> 00:23:57,680 It's its own transaction. 540 00:23:58,000 --> 00:23:58,840 Go ahead. 541 00:23:58,960 --> 00:23:59,800 Everything will be safe. 542 00:24:00,200 --> 00:24:05,680 And now, as a consequence, we can execute arbitrary PL SQL. 543 00:24:05,980 --> 00:24:08,860 And in this case, it's begin, execute immediate, grant 544 00:24:08,940 --> 00:24:11,620 DBA to public, and we end that. 545 00:24:11,940 --> 00:24:15,620 And we get the message it's successfully completed. 546 00:24:15,840 --> 00:24:22,520 So if we go set role DBA now, DBA, role has been set. 547 00:24:23,700 --> 00:24:27,900 And if we do select star from session privileges, honestly, 548 00:24:29,200 --> 00:24:30,800 it's so easy to break into Oracle, 549 00:24:30,940 --> 00:24:32,660 you don't need to applaud me on that, you know? 550 00:24:34,100 --> 00:24:35,800 Select star from session. 551 00:24:36,120 --> 00:24:36,860 But thank you. 552 00:24:37,060 --> 00:24:37,960 It is appreciated. 553 00:24:37,960 --> 00:24:39,380 I'm here all week. 554 00:24:39,460 --> 00:24:40,180 Try the steak. 555 00:24:40,900 --> 00:24:43,140 So we've now got all these session privileges. 556 00:24:43,960 --> 00:24:47,560 So we've gone from create session only through to 557 00:24:47,560 --> 00:24:50,440 exploiting a PL SQL injection floor, which there are three 558 00:24:50,440 --> 00:24:54,200 to 400 of, depending upon the version of Oracle that you're 559 00:24:54,200 --> 00:24:54,520 looking at. 560 00:24:55,360 --> 00:24:58,980 And suddenly, we're God, as far as this database is 561 00:24:58,980 --> 00:24:59,220 concerned. 562 00:24:59,440 --> 00:25:07,400 So now I'm going to do alter user sys identified by 563 00:25:07,960 --> 00:25:08,220 password. 564 00:25:08,660 --> 00:25:11,200 So I'm now changing the password for the sys user. 565 00:25:12,600 --> 00:25:17,940 And as you'll see in a minute, logging in as sys 566 00:25:17,940 --> 00:25:20,440 is going to give us some fun stuff. 567 00:25:21,140 --> 00:25:26,220 Connect sys slash password at orcl as sys DBA. 568 00:25:27,640 --> 00:25:29,940 OK, so we're now connected as the sys user. 569 00:25:30,620 --> 00:25:32,600 We're going to start playing with a thing called 570 00:25:32,600 --> 00:25:36,620 or a debugger, which is a nice little facility that allows us 571 00:25:36,620 --> 00:25:37,560 to read. 572 00:25:37,560 --> 00:25:40,720 Read from the Oracle process memory, write to the Oracle 573 00:25:40,720 --> 00:25:44,220 process memory, and also execute arbitrary functions 574 00:25:44,220 --> 00:25:44,740 and so on. 575 00:25:45,320 --> 00:25:50,340 So before we do that, yeah, breaking out of the database. 576 00:25:50,460 --> 00:25:51,100 How are we doing for time? 577 00:25:51,280 --> 00:25:52,360 We're doing OK, great. 578 00:25:53,220 --> 00:25:55,120 Breaking out of the database, running arbitrary code. 579 00:25:55,240 --> 00:25:59,160 Well, obviously, if there are buffer overflows, and again, 580 00:25:59,320 --> 00:26:03,760 maybe each CPU, one buffer overflow. 581 00:26:04,460 --> 00:26:06,660 Sometimes there's zero buffer overflows being fixed. 582 00:26:06,660 --> 00:26:10,640 But actually, I think there's at least one or more being fixed 583 00:26:10,640 --> 00:26:12,820 in every critical patch update. 584 00:26:13,820 --> 00:26:14,940 Sometimes there's lots. 585 00:26:15,620 --> 00:26:18,120 Yeah, sometimes we get a slew of flaws coming in. 586 00:26:18,460 --> 00:26:20,960 But we're specifically going to look at the or a debug stuff 587 00:26:20,960 --> 00:26:21,200 here. 588 00:26:21,480 --> 00:26:25,540 Now, what or a debug does is basically, as I said, 589 00:26:25,600 --> 00:26:29,660 it allows us to peek and poke at memory or a debug. 590 00:26:31,520 --> 00:26:34,340 Or a debug has been documented before, by the way. 591 00:26:34,380 --> 00:26:35,220 So this is nothing new. 592 00:26:36,660 --> 00:26:39,360 People have been speaking about using or a debug as a hacking 593 00:26:39,360 --> 00:26:40,740 facility for a long, long time. 594 00:26:41,160 --> 00:26:43,320 So yeah, this isn't like Oday I'm dropping 595 00:26:43,320 --> 00:26:44,580 by any stretch of the imagination. 596 00:26:46,580 --> 00:26:48,280 So if I go or a debug help. 597 00:26:48,680 --> 00:26:50,900 So here's the help options. 598 00:26:52,960 --> 00:26:54,580 Some of them are very interesting. 599 00:26:55,260 --> 00:26:57,300 Some of them are not so interesting. 600 00:26:57,660 --> 00:27:02,220 But we're going to be looking at these two, peek and poke 601 00:27:04,580 --> 00:27:05,380 and call. 602 00:27:05,380 --> 00:27:07,260 Which basically takes a function name, 603 00:27:07,900 --> 00:27:09,600 and you can call that function. 604 00:27:10,160 --> 00:27:12,020 So here's one I made earlier. 605 00:27:15,160 --> 00:27:20,800 OK, so first off we need to set the process ID we want to debug. 606 00:27:21,040 --> 00:27:23,340 And we're just going to use the process ID of my given process. 607 00:27:23,740 --> 00:27:26,540 So set my PID. 608 00:27:29,320 --> 00:27:31,780 So one of the great things about or a debug, 609 00:27:32,040 --> 00:27:33,760 well, let me rephrase that. 610 00:27:35,380 --> 00:27:36,640 I'm glad that we can do this with or a debug. 611 00:27:36,960 --> 00:27:38,700 But one of the good things thereafter 612 00:27:38,700 --> 00:27:44,380 is any time you use or a debug, a trace file is created. 613 00:27:44,640 --> 00:27:51,260 CD, DR, actually, find str, forward slash i, 614 00:27:51,280 --> 00:27:54,620 forward slash c, or a debug. 615 00:28:00,040 --> 00:28:00,560 OK. 616 00:28:06,100 --> 00:28:15,640 I just want to find the current slash od, 6, 20, 28. 617 00:28:15,820 --> 00:28:19,300 OK, so this is our current one type. 618 00:28:24,120 --> 00:28:27,060 So we can see, remember the first or a debug command 619 00:28:27,060 --> 00:28:27,880 I issued was help. 620 00:28:29,040 --> 00:28:30,540 That's written to this trace file. 621 00:28:31,340 --> 00:28:33,520 And then I did set my PID and so on. 622 00:28:33,660 --> 00:28:34,840 That's written to the trace file. 623 00:28:34,840 --> 00:28:37,100 So any time you use or a debug, it's 624 00:28:37,100 --> 00:28:38,260 being written to a trace file, which 625 00:28:38,260 --> 00:28:40,120 is great when it comes to forensics. 626 00:28:41,560 --> 00:28:44,380 So what we're going to do here is we're 627 00:28:44,380 --> 00:28:46,060 going to run an operating system command. 628 00:28:46,200 --> 00:28:48,140 Because remember on Windows, Oracle 629 00:28:48,140 --> 00:28:50,580 runs as the local system user. 630 00:28:50,940 --> 00:28:54,280 So any arbitrary code I execute is 631 00:28:54,280 --> 00:28:56,580 going to execute with the privileges of the local system 632 00:28:56,580 --> 00:28:56,820 user. 633 00:28:57,020 --> 00:29:00,020 And in this case, I'm going to create a user account called 634 00:29:00,020 --> 00:29:04,220 or a hack with a password of PWD and add it. 635 00:29:05,920 --> 00:29:07,700 And I'm going to call the system function. 636 00:29:07,900 --> 00:29:13,960 So what I'm going to do first is write to this memory address 637 00:29:14,640 --> 00:29:20,720 four bytes, which is net space. 638 00:29:20,900 --> 00:29:23,800 So that's the net space of the net user add command. 639 00:29:24,480 --> 00:29:28,540 And then, so all this here is basically net user add, 640 00:29:29,680 --> 00:29:33,000 PWD slash, sorry, net user or a hack, PWD slash add. 641 00:29:33,240 --> 00:29:34,520 And I'm going to write that into memory. 642 00:29:34,520 --> 00:29:38,460 And you can see here, I increment the address, 643 00:29:38,580 --> 00:29:39,140 obviously, by four. 644 00:29:39,280 --> 00:29:40,940 Because if I didn't do that, obviously, we just 645 00:29:40,940 --> 00:29:42,380 overwrite the same bit of memory. 646 00:29:44,740 --> 00:29:50,020 So what you'll see here, let's clear the screen. 647 00:29:50,160 --> 00:29:55,920 So oh, don't do that to me, right? 648 00:29:58,080 --> 00:29:59,140 Give me two secs. 649 00:29:59,300 --> 00:30:01,420 Because I restarted the system, the memory's gone. 650 00:30:01,500 --> 00:30:02,700 So I'm just going to fudge one. 651 00:30:15,060 --> 00:30:18,920 We can do this, by the way, again, using or a debug. 652 00:30:19,100 --> 00:30:20,760 We can dump a stack trace. 653 00:30:20,980 --> 00:30:23,600 And then, using UTL file, we can read that in. 654 00:30:23,780 --> 00:30:26,740 But I'm just going to cheat, because that takes a wee bit 655 00:30:26,740 --> 00:30:28,160 longer, 4372. 656 00:30:32,660 --> 00:30:34,080 vodump minus p. 657 00:30:35,060 --> 00:30:35,540 4372. 658 00:30:37,000 --> 00:30:38,760 OK, pick one at random. 659 00:30:43,080 --> 00:30:45,140 OK, we don't need execute read write. 660 00:30:45,200 --> 00:30:46,080 We just need read write. 661 00:30:55,800 --> 00:30:57,660 OK, reserve, that will do. 662 00:30:58,080 --> 00:30:58,560 Right. 663 00:31:00,520 --> 00:31:01,860 1, e, 2, 3. 664 00:31:03,320 --> 00:31:03,800 Edit. 665 00:31:03,880 --> 00:31:04,320 Find. 666 00:31:04,600 --> 00:31:05,080 Replace. 667 00:31:06,940 --> 00:31:08,160 1, d, d, f. 668 00:31:09,580 --> 00:31:10,260 Replace all. 669 00:31:10,500 --> 00:31:10,960 OK. 670 00:31:13,660 --> 00:31:17,140 Home and Control-C. Right, let's try this again. 671 00:31:19,380 --> 00:31:20,080 OK, great. 672 00:31:20,340 --> 00:31:24,500 So what we've done there is written the net space part. 673 00:31:25,580 --> 00:31:27,180 So let's add the rest of it. 674 00:31:30,280 --> 00:31:32,140 So I now have written in memory. 675 00:31:33,000 --> 00:31:36,480 The net user AuraHack pwd slash add. 676 00:31:37,120 --> 00:31:39,200 That's the operating system command I want to execute. 677 00:31:40,300 --> 00:31:46,040 Now I basically call the system function here and pass to it 678 00:31:46,040 --> 00:31:49,360 the address at which can be found the operating system 679 00:31:49,360 --> 00:31:50,620 command, the net user add stuff. 680 00:31:51,880 --> 00:31:54,400 So before I do that, if I go net user. 681 00:31:55,080 --> 00:31:55,580 Whoops. 682 00:31:55,700 --> 00:31:56,320 Net user. 683 00:31:56,500 --> 00:31:59,280 We can see I've got VMware user administrator David and guest. 684 00:31:59,420 --> 00:32:01,380 There's no AuraHack account right now. 685 00:32:02,680 --> 00:32:06,480 But I'm going to get Oracle to now create the user 686 00:32:06,480 --> 00:32:07,600 by calling the system function. 687 00:32:08,480 --> 00:32:10,100 Function returns zero as it should do. 688 00:32:10,960 --> 00:32:15,040 So net user now shows us we've got this AuraHack account in there. 689 00:32:15,320 --> 00:32:16,840 So thank you. 690 00:32:20,380 --> 00:32:25,840 So what we've done is from a lowly create session privileged user account, 691 00:32:26,060 --> 00:32:30,380 jump privileges to DBA, change the sys password, 692 00:32:30,380 --> 00:32:31,940 and now we're connected to sys. 693 00:32:31,960 --> 00:32:35,220 We can then start poking and peeking into memory 694 00:32:35,220 --> 00:32:37,380 and running arbitrary functions. 695 00:32:37,640 --> 00:32:40,840 Now, of course, we're only limited by our imagination 696 00:32:40,840 --> 00:32:45,580 in terms of what we want to do as far as executing arbitrary code is concerned. 697 00:32:45,700 --> 00:32:52,300 We could use this to send us back a reverse shell or anything we want. 698 00:32:52,460 --> 00:32:55,020 We just obviously need to create the right structures in memory, 699 00:32:55,160 --> 00:32:59,200 get the right addresses, and send them to the function basically. 700 00:33:00,620 --> 00:33:04,680 And one of the great things, of course, is when you call a function, 701 00:33:04,900 --> 00:33:10,600 the value, the return value, whatever EAX is returned in EAX, 702 00:33:10,660 --> 00:33:12,140 is basically dumped in here. 703 00:33:12,260 --> 00:33:14,220 So if we, like, call the socket function, 704 00:33:14,480 --> 00:33:18,420 we can get the socket handle by looking at whatever the function returns 705 00:33:18,420 --> 00:33:19,800 and so on in there. 706 00:33:20,520 --> 00:33:23,080 Okay, and then we can then add that in and so on. 707 00:33:24,780 --> 00:33:30,300 But I think the key takeaway from there is every time you use RDBug, 708 00:33:30,380 --> 00:33:31,260 it's in that trace file. 709 00:33:31,440 --> 00:33:34,120 So what we can do is look in that trace file. 710 00:33:39,620 --> 00:33:45,220 You can see the stuff I've written to memory I can now extract. 711 00:33:45,500 --> 00:33:47,180 And then as a forensic investigator, 712 00:33:47,560 --> 00:33:51,640 I can go ahead and start working out what the attacker attempted to do. 713 00:33:51,900 --> 00:33:55,300 So if they indeed tried to spawn a reverse shell or something like that, 714 00:33:55,440 --> 00:33:56,840 their code is going to be in memory. 715 00:33:57,020 --> 00:33:58,220 Not in memory, in this trace file. 716 00:33:58,220 --> 00:34:00,260 So we can build up a very good picture, 717 00:34:00,380 --> 00:34:02,800 so anything they're doing is in there. 718 00:34:03,220 --> 00:34:06,200 But you do have to remember, of course, that we're connected to SIS. 719 00:34:06,820 --> 00:34:08,940 As far as that database is concerned, we are God. 720 00:34:09,040 --> 00:34:11,180 So if we wanted to, we could delete that trace file. 721 00:34:13,460 --> 00:34:15,420 Suffice it to say, though, if they don't delete the trace file, 722 00:34:15,500 --> 00:34:16,660 it's a wonderful source of information. 723 00:34:19,220 --> 00:34:19,620 Right. 724 00:34:20,260 --> 00:34:23,520 And, of course, we can run operating system commands in other ways. 725 00:34:26,300 --> 00:34:28,900 We spoke about external procedures earlier. 726 00:34:29,400 --> 00:34:30,120 Let's do that. 727 00:34:34,120 --> 00:34:36,620 First off, I'm going to do one that will fail. 728 00:34:38,140 --> 00:34:40,940 And the reason I'm doing that is because I want to show you 729 00:34:43,940 --> 00:34:45,440 another useful bit of information. 730 00:34:46,020 --> 00:34:47,320 Remember I said it was logged. 731 00:34:47,760 --> 00:34:49,300 The name of the library is logged. 732 00:34:50,760 --> 00:34:52,860 Let's actually run in the back. 733 00:34:58,700 --> 00:34:59,100 OK. 734 00:35:03,700 --> 00:35:04,100 Right. 735 00:35:04,340 --> 00:35:08,300 Now, because I've just specified msvcrt.dll, 736 00:35:08,380 --> 00:35:09,960 I haven't specified a path or anything like that, 737 00:35:10,080 --> 00:35:13,840 it will look through the system path for the, you know, the right DLL 738 00:35:13,840 --> 00:35:16,980 and decide that it's not in the right location, 739 00:35:17,100 --> 00:35:17,900 it's not in the Oracle home, 740 00:35:17,980 --> 00:35:22,360 so we'll get a message being logged saying that it's an invalid DLL path. 741 00:35:22,360 --> 00:35:25,680 So, remember I said you have to wrap it, 742 00:35:25,700 --> 00:35:29,040 this bit of code at the bottom wraps the call. 743 00:35:29,960 --> 00:35:31,100 So, let's create that. 744 00:35:31,600 --> 00:35:34,380 And remember that this is going to fail when I execute the function. 745 00:35:36,480 --> 00:35:37,360 So, and... 746 00:35:39,820 --> 00:35:41,460 We'll get the invalid DLL path. 747 00:35:42,040 --> 00:35:43,360 But if we look here... 748 00:35:47,360 --> 00:35:48,320 Uh... 749 00:35:50,300 --> 00:35:52,340 Where did it create it? 750 00:35:55,580 --> 00:35:56,980 Mm-mm-mm. 751 00:35:57,940 --> 00:35:58,900 Edit. 752 00:35:59,200 --> 00:36:00,160 Find. 753 00:36:00,920 --> 00:36:01,400 HS. 754 00:36:06,080 --> 00:36:08,120 There we go. 755 00:36:13,360 --> 00:36:14,300 Jump to... 756 00:36:18,280 --> 00:36:18,800 OK. 757 00:36:18,980 --> 00:36:20,500 We can see in there, uh, 758 00:36:21,320 --> 00:36:23,600 someone tried to load msvcrt.dll, 759 00:36:24,200 --> 00:36:25,840 uh, and it was sys, 760 00:36:25,840 --> 00:36:28,240 and the library name was this and everything like that. 761 00:36:28,320 --> 00:36:29,960 So, again, useful forensics information, 762 00:36:30,300 --> 00:36:30,880 uh, 763 00:36:31,780 --> 00:36:33,560 worth looking at that directory. 764 00:36:34,140 --> 00:36:35,680 But let's make it work now. 765 00:36:35,720 --> 00:36:36,980 Remember I said, um, 766 00:36:37,640 --> 00:36:42,960 they dropped msvcrt.dll in the bin directory in Oracle home. 767 00:36:42,960 --> 00:36:43,260 So... 768 00:36:45,760 --> 00:36:48,140 So, we can now go ahead and recreate that. 769 00:36:50,800 --> 00:36:52,500 If I do net user, 770 00:36:53,580 --> 00:36:55,200 uh, we've got the Oracle hack, 771 00:36:55,380 --> 00:36:56,440 or our hack user. 772 00:36:56,640 --> 00:36:58,660 We're now going to create our hack2, 773 00:36:58,820 --> 00:36:59,740 the password. 774 00:37:03,940 --> 00:37:05,840 So, we get that successful, completely, 775 00:37:06,920 --> 00:37:07,720 completed successfully. 776 00:37:08,640 --> 00:37:09,860 Uh, and that user, 777 00:37:09,940 --> 00:37:12,400 we've now got the our hack2 user in there and so on. 778 00:37:12,400 --> 00:37:15,940 So, dropping msvcrt.dll in there wasn't a smart idea. 779 00:37:16,140 --> 00:37:18,020 But to be fair, if you think about it, 780 00:37:18,500 --> 00:37:22,600 watch this, uh, cd backslash app, cd... 781 00:37:28,180 --> 00:37:29,940 db home, cd bin. 782 00:37:30,080 --> 00:37:32,340 OK, this is the Oracle home directory. 783 00:37:34,560 --> 00:37:35,680 That's all attack surface. 784 00:37:36,300 --> 00:37:38,620 You know, these, these are in there by default. 785 00:37:38,940 --> 00:37:40,500 Uh, any function on there, 786 00:37:40,560 --> 00:37:42,380 we can obviously call, you know, and... 787 00:37:42,400 --> 00:37:43,460 and if there's, you know, 788 00:37:43,980 --> 00:37:46,080 susceptible to things like overflow or whatever, 789 00:37:46,220 --> 00:37:48,720 then we can still use this external library thing. 790 00:37:48,940 --> 00:37:50,040 What Oracle should do 791 00:37:50,040 --> 00:37:52,460 is have a, an area 792 00:37:53,240 --> 00:37:55,360 where there are no DLLs by default. 793 00:37:55,500 --> 00:37:57,540 There are no code objects by default. 794 00:37:57,800 --> 00:38:00,040 And if you want to add your own stuff, 795 00:38:00,120 --> 00:38:00,920 you can put it in there. 796 00:38:01,180 --> 00:38:02,920 Uh, having it as the Oracle home 797 00:38:02,920 --> 00:38:04,520 is, is too lax as far as I'm concerned. 798 00:38:05,380 --> 00:38:05,780 So... 799 00:38:06,320 --> 00:38:08,280 Yeah, all of this is attack surface, basically, 800 00:38:08,360 --> 00:38:10,960 from external, from an external procedure point of view. 801 00:38:11,200 --> 00:38:12,040 So, yeah. 802 00:38:12,400 --> 00:38:13,380 It should be tightened up considerably. 803 00:38:14,180 --> 00:38:15,080 We don't have time. 804 00:38:16,500 --> 00:38:16,900 OK. 805 00:38:22,620 --> 00:38:23,020 Right. 806 00:38:26,340 --> 00:38:28,060 OK. So, I've, I've 807 00:38:28,560 --> 00:38:30,180 really, uh, run through, 808 00:38:30,260 --> 00:38:32,220 um, the, the hacking side of things. 809 00:38:32,400 --> 00:38:34,320 So, we've got a, a couple more minutes 810 00:38:34,320 --> 00:38:36,180 left, uh, for a wee bit 811 00:38:36,180 --> 00:38:36,880 of the forensic side. 812 00:38:37,500 --> 00:38:40,160 So, the database has been breached, and what do we do now? 813 00:38:40,400 --> 00:38:41,320 Where is the evidence? 814 00:38:42,400 --> 00:38:44,120 In Oracle, the evidence is everywhere. 815 00:38:44,420 --> 00:38:45,160 It's great. 816 00:38:45,420 --> 00:38:48,440 There's so much redundancy built into the Oracle database server. 817 00:38:48,600 --> 00:38:49,140 It's wonderful. 818 00:38:49,700 --> 00:38:51,580 Uh, security, 819 00:38:52,180 --> 00:38:52,960 not so wonderful. 820 00:38:53,280 --> 00:38:56,380 Uh, if we look at Microsoft SQL Server, 821 00:38:56,600 --> 00:38:58,240 SQL Server 2005, 822 00:38:58,400 --> 00:39:00,040 I think, has had three 823 00:39:00,040 --> 00:39:02,180 critical patches required since 824 00:39:02,180 --> 00:39:04,200 2005. So, what, that's pushing six 825 00:39:04,200 --> 00:39:06,160 years, and it's had three, 826 00:39:06,200 --> 00:39:07,740 uh, critical patches. 827 00:39:08,020 --> 00:39:10,220 Oracle, uh, Microsoft SQL Server 828 00:39:10,220 --> 00:39:12,360 2008, I think, 829 00:39:12,400 --> 00:39:14,560 has had zero. If we, uh, 830 00:39:14,580 --> 00:39:16,160 look at Oracle, you know, each, 831 00:39:16,280 --> 00:39:18,340 every three months, patches are coming out time 832 00:39:18,340 --> 00:39:20,280 and time again. As I said, sometimes they're 833 00:39:20,280 --> 00:39:22,500 patching up to 30, uh, 20 to 30 issues. 834 00:39:22,600 --> 00:39:24,200 Sometimes it's only five or six, but 835 00:39:24,200 --> 00:39:26,100 every three months, you have to worry about 836 00:39:26,100 --> 00:39:28,020 or, well, you have to worry about Oracle security 837 00:39:28,020 --> 00:39:30,240 all the time, but every three months 838 00:39:30,240 --> 00:39:32,200 it's, it's patch day. But, 839 00:39:32,680 --> 00:39:34,140 SQL Server's pretty crap 840 00:39:34,140 --> 00:39:36,400 when it comes to, you know, logging 841 00:39:36,400 --> 00:39:38,480 stuff that's 842 00:39:38,480 --> 00:39:40,260 useful to, uh, an investigator. Obviously, you've got 843 00:39:40,260 --> 00:39:42,280 the transaction log, and you've got the error log file 844 00:39:42,400 --> 00:39:44,180 but as far as that can, as 845 00:39:44,180 --> 00:39:46,260 far as, uh, you know, useful 846 00:39:46,260 --> 00:39:47,840 information goes, that's pretty much it. 847 00:39:48,320 --> 00:39:50,180 Oracle is, is great. It's, it's 848 00:39:50,180 --> 00:39:52,460 wonderful. Uh, so let's 849 00:39:52,460 --> 00:39:53,800 look at some of these, uh, locations. 850 00:39:54,040 --> 00:39:56,180 So, obviously the, the system metadata 851 00:39:56,180 --> 00:39:58,360 itself, the, the information that makes up 852 00:39:58,360 --> 00:40:00,100 the database server is a wonderful source of information. 853 00:40:00,640 --> 00:40:01,700 Uh, the data files, 854 00:40:01,960 --> 00:40:03,900 uh, when 855 00:40:03,900 --> 00:40:06,320 a, uh, a record 856 00:40:06,320 --> 00:40:08,320 is updated or deleted, the 857 00:40:09,800 --> 00:40:10,280 data 858 00:40:10,280 --> 00:40:11,160 is left intact. 859 00:40:12,400 --> 00:40:14,280 It's just, well, each row of data 860 00:40:14,280 --> 00:40:15,720 has a three-byte header. How we doing? 861 00:40:16,060 --> 00:40:18,320 Okay, good. Each row of data has a three-byte header. 862 00:40:18,420 --> 00:40:20,420 The first byte of that, 863 00:40:20,440 --> 00:40:21,640 uh, three-byte header 864 00:40:22,240 --> 00:40:24,220 has, uh, its flags, basically, and 865 00:40:24,220 --> 00:40:26,160 the, the fifth bit, if you flip that bit, 866 00:40:26,220 --> 00:40:28,320 it says it's deleted. If you flip it again, 867 00:40:28,380 --> 00:40:29,860 it says it's not deleted. Okay? 868 00:40:30,080 --> 00:40:32,100 So, we can very, very quickly 869 00:40:32,680 --> 00:40:34,180 find, uh, deleted data 870 00:40:34,180 --> 00:40:36,220 by looking at that first bit of 871 00:40:36,220 --> 00:40:38,380 the, the, the, the three-byte 872 00:40:38,380 --> 00:40:40,320 header to say, is the bit set or 873 00:40:40,320 --> 00:40:42,380 unset, and whether it's deleted or not. So, if you 874 00:40:42,400 --> 00:40:44,260 delete data, if you think, I'm 875 00:40:44,260 --> 00:40:46,340 hiding, you know, uh, my tracks, I've deleted 876 00:40:46,340 --> 00:40:47,780 all my stuff and everything like that, 877 00:40:48,340 --> 00:40:50,520 it's still in there, it's just that bit's been flipped. 878 00:40:50,740 --> 00:40:51,960 Or, if you update data, 879 00:40:52,200 --> 00:40:54,380 that bit is flipped and everything, and 880 00:40:54,380 --> 00:40:56,240 a new row, a new row is 881 00:40:56,240 --> 00:40:58,120 created, so, uh, 882 00:40:58,220 --> 00:41:00,100 it's, it's really useful in that information. Uh, 883 00:41:00,180 --> 00:41:01,920 it's really useful when it comes to that information. 884 00:41:02,540 --> 00:41:04,380 There's a thing called the active session history. 885 00:41:04,560 --> 00:41:06,380 Uh, I wrote a couple of papers on this, uh, 886 00:41:06,420 --> 00:41:08,180 a few years ago. So, what active session 887 00:41:08,180 --> 00:41:10,120 history is, when, 888 00:41:10,320 --> 00:41:12,280 uh, the, the Oracle, so, 889 00:41:12,400 --> 00:41:14,060 when the server's running, it, there's, uh, 890 00:41:14,080 --> 00:41:16,000 a sub-process running in the background, basically 891 00:41:16,000 --> 00:41:18,480 pulling the database server every three seconds 892 00:41:18,480 --> 00:41:20,280 to find out what's going on at that 893 00:41:20,280 --> 00:41:21,820 particular time. It takes a snapshot. 894 00:41:22,200 --> 00:41:24,220 These snapshots are recorded in memory. 895 00:41:24,400 --> 00:41:25,880 And then every half hour or so, 896 00:41:26,580 --> 00:41:28,520 one in ten of the snapshots 897 00:41:28,520 --> 00:41:29,840 are recorded in, in, 898 00:41:30,400 --> 00:41:31,840 uh, on disk, basically. 899 00:41:32,200 --> 00:41:34,380 So, if you have a query 900 00:41:34,380 --> 00:41:36,500 that lasts for, say, three seconds, 901 00:41:36,800 --> 00:41:38,500 you're gonna have a snapshot in it, 902 00:41:38,520 --> 00:41:39,900 definitely in memory somewhere. 903 00:41:40,240 --> 00:41:42,320 If the query lasts for more than 904 00:41:42,400 --> 00:41:44,400 30 seconds, chances are there's gonna 905 00:41:44,400 --> 00:41:46,500 be a snapshot written to the disk. 906 00:41:46,940 --> 00:41:48,240 So, this active session 907 00:41:48,240 --> 00:41:50,460 history becomes a really useful source of information 908 00:41:50,460 --> 00:41:52,340 for looking at 909 00:41:52,340 --> 00:41:54,300 select attacks. Select attacks 910 00:41:54,300 --> 00:41:55,920 obviously are just, uh, 911 00:41:56,160 --> 00:41:57,840 you know, getting access to data. 912 00:41:58,320 --> 00:42:00,420 So, if you're downloading a customer 913 00:42:00,420 --> 00:42:02,340 database that, say, has, uh, 914 00:42:02,460 --> 00:42:04,340 5 million records, that's gonna take 915 00:42:04,340 --> 00:42:06,280 longer than 30 seconds, probably. If you're 916 00:42:06,280 --> 00:42:08,000 using something like UTL HTTP 917 00:42:08,000 --> 00:42:10,240 or UTL Inidra to exfiltrate, 918 00:42:10,360 --> 00:42:12,200 uh, data over an out-of-band 919 00:42:12,400 --> 00:42:14,220 method across the network, that's gonna 920 00:42:14,220 --> 00:42:16,120 take a long time. And so, 921 00:42:16,160 --> 00:42:17,560 there will be calls to, 922 00:42:17,800 --> 00:42:20,080 uh, to, uh, these 923 00:42:20,080 --> 00:42:22,140 SQL statements will be logged in the active session history. 924 00:42:22,380 --> 00:42:23,920 And as a forensic investigator, 925 00:42:24,220 --> 00:42:26,280 we can go back and look for evidence of 926 00:42:26,280 --> 00:42:27,320 even select attacks. 927 00:42:28,440 --> 00:42:30,300 The transaction logs, you know, like the 928 00:42:30,300 --> 00:42:32,380 redo logs in Oracle, anything that requires 929 00:42:32,380 --> 00:42:34,460 a transaction is logged in the redo log. 930 00:42:34,560 --> 00:42:35,880 So, that's another great source of information. 931 00:42:36,160 --> 00:42:37,860 So, that's things like deletes, inserts, updates, 932 00:42:38,120 --> 00:42:40,340 uh, select for updates, any DDL 933 00:42:40,340 --> 00:42:42,060 like, uh, grant 934 00:42:42,400 --> 00:42:44,320 creates and drops and so on. All that 935 00:42:44,320 --> 00:42:46,360 information can be found in the transaction logs. 936 00:42:47,480 --> 00:42:48,260 Undo segments, 937 00:42:48,620 --> 00:42:50,360 uh, if you, if you make a change, 938 00:42:50,480 --> 00:42:52,300 an undo segment is created that 939 00:42:52,300 --> 00:42:53,920 has information pertaining to that change. 940 00:42:54,100 --> 00:42:55,300 So, again, we can query that. 941 00:42:55,980 --> 00:42:58,220 Uh, the memory itself, in a 942 00:42:58,220 --> 00:43:00,040 live response situation, we can 943 00:43:00,040 --> 00:43:02,160 start querying certain key 944 00:43:02,160 --> 00:43:04,260 tables for, uh, uh, 945 00:43:04,260 --> 00:43:06,200 key, uh, virtual 946 00:43:06,200 --> 00:43:08,240 views, rather, for information. So, 947 00:43:08,320 --> 00:43:10,320 one of them is VDOR SQL. It has about 948 00:43:10,320 --> 00:43:12,300 3,000 to 5,000 queries 949 00:43:12,400 --> 00:43:14,300 that have, the most recent ones that 950 00:43:14,300 --> 00:43:16,520 have been executed. So, if we can find 951 00:43:16,520 --> 00:43:18,360 an attack in progress, or an attack 952 00:43:18,360 --> 00:43:20,320 which happened just, uh, like half an hour 953 00:43:20,320 --> 00:43:22,300 ago, on a fairly quiet database server, 954 00:43:22,440 --> 00:43:24,100 there might be evidence of attacks in there. 955 00:43:25,360 --> 00:43:26,360 VDOR DB object 956 00:43:26,360 --> 00:43:27,980 cache is another great source of information. 957 00:43:28,380 --> 00:43:30,480 So, again, a couple of years ago, I wrote a paper 958 00:43:30,480 --> 00:43:32,440 on, uh, hacking, 959 00:43:32,640 --> 00:43:34,500 uh, the, the Java virtual machine, 960 00:43:34,700 --> 00:43:36,460 uh, built into Oracle. 961 00:43:36,940 --> 00:43:38,460 And, uh, looking 962 00:43:38,460 --> 00:43:40,020 through the source code of 963 00:43:40,020 --> 00:43:42,280 the, the default Java objects, there's this 964 00:43:42,780 --> 00:43:44,300 UTL wrapper that basically takes 965 00:43:44,300 --> 00:43:46,360 user input and, and passes it 966 00:43:46,360 --> 00:43:48,500 to, uh, you know, 967 00:43:48,500 --> 00:43:50,060 the system function, basically. So, 968 00:43:50,920 --> 00:43:52,240 if there is no 969 00:43:52,240 --> 00:43:53,900 reference to this UTL wrapper 970 00:43:53,900 --> 00:43:56,320 anywhere else in the Oracle code, 971 00:43:56,500 --> 00:43:58,280 and I think it's left over there from 972 00:43:58,280 --> 00:44:00,180 development days, so no, 973 00:44:00,340 --> 00:44:02,200 uh, no 974 00:44:02,200 --> 00:44:04,360 real-world code should be using it. So, if 975 00:44:04,360 --> 00:44:06,100 it's in, if it exists in this DB object 976 00:44:06,100 --> 00:44:08,080 cache, one can infer from that that 977 00:44:08,080 --> 00:44:09,960 an attack has probably taken place. 978 00:44:10,620 --> 00:44:12,380 So, again, there's the, the 979 00:44:12,400 --> 00:44:14,340 these, uh, virtual tables, uh, which are 980 00:44:14,340 --> 00:44:15,500 a wonderful source of information. 981 00:44:16,380 --> 00:44:18,280 And, obviously, the, the log files themselves, 982 00:44:18,420 --> 00:44:20,320 like the TNS listener log file, is the 983 00:44:20,320 --> 00:44:22,400 first port of call. Uh, any kind 984 00:44:22,400 --> 00:44:24,280 of connection is, is gonna be logged 985 00:44:24,280 --> 00:44:26,220 in there. Caveat emptor, though, 986 00:44:26,240 --> 00:44:27,920 when it comes to the TNS listener log files, 987 00:44:28,900 --> 00:44:30,160 when a, um, 988 00:44:30,240 --> 00:44:32,220 a client connects, they 989 00:44:32,220 --> 00:44:34,380 pass the program name and stuff like that, 990 00:44:34,460 --> 00:44:36,120 and that's all logged in the TNS listener. 991 00:44:36,240 --> 00:44:37,920 But because it's under the control of the client, 992 00:44:38,080 --> 00:44:40,260 they could say whatever they wanted. They could pretend to be a 993 00:44:40,260 --> 00:44:42,080 JDBC client, whereas, whereas 994 00:44:42,080 --> 00:44:44,100 in actual fact, they're a, a C hacking tool. 995 00:44:44,500 --> 00:44:45,160 Uh, so, 996 00:44:46,480 --> 00:44:48,120 don't fully trust the information 997 00:44:48,120 --> 00:44:50,020 in there. Uh, use it for, 998 00:44:50,040 --> 00:44:52,140 like, pattern recognition and so on, perhaps, 999 00:44:52,300 --> 00:44:54,140 but, uh, or, or another one. For 1000 00:44:54,140 --> 00:44:56,240 example, when, uh, 1001 00:44:56,400 --> 00:44:57,500 you authenticate to Oracle, 1002 00:44:58,400 --> 00:45:00,020 you, what happens is, you 1003 00:45:00,020 --> 00:45:02,040 connect to the TNS listener, the TNS 1004 00:45:02,040 --> 00:45:04,180 listener, okay, great, the TNS 1005 00:45:04,180 --> 00:45:06,180 listener, uh, then passes you off to the 1006 00:45:06,180 --> 00:45:08,440 Oracle process, and you authenticate, 1007 00:45:08,440 --> 00:45:10,200 or attempt to authenticate, and if 1008 00:45:10,260 --> 00:45:12,160 authentication, uh, fails, 1009 00:45:12,360 --> 00:45:14,240 the client tears down 1010 00:45:14,240 --> 00:45:16,060 the connection and you, you start the whole process 1011 00:45:16,060 --> 00:45:18,180 again, connect to the listener, the listener passes you off 1012 00:45:18,180 --> 00:45:19,680 to Oracle and so on. Uh, 1013 00:45:19,840 --> 00:45:20,300 now, 1014 00:45:21,820 --> 00:45:23,880 as a, as a consequence of the 1015 00:45:23,880 --> 00:45:26,160 client being the one responsible for 1016 00:45:26,160 --> 00:45:28,100 tearing down that session, if we don't choose 1017 00:45:28,100 --> 00:45:30,220 to, if we fail authentication and we don't choose to tear 1018 00:45:30,220 --> 00:45:32,040 down that session, we can continue 1019 00:45:32,040 --> 00:45:34,060 to authenticate once we've got that, 1020 00:45:34,060 --> 00:45:36,060 uh, connection to the Oracle process. 1021 00:45:36,480 --> 00:45:38,260 So we can make one connection 1022 00:45:38,260 --> 00:45:40,160 to the TNS listener which passes off to the Oracle 1023 00:45:40,260 --> 00:45:42,220 server, we then say to 1024 00:45:42,220 --> 00:45:44,140 the Oracle server, is the password 1025 00:45:44,140 --> 00:45:45,400 for sys this? 1026 00:45:45,840 --> 00:45:48,140 And if the Oracle server says no, no, uh, 1027 00:45:48,260 --> 00:45:50,280 that's not the password, we don't tear 1028 00:45:50,280 --> 00:45:52,200 down the connection, we just say to 1029 00:45:52,200 --> 00:45:54,260 it, well, how's this for a password for 1030 00:45:54,260 --> 00:45:55,800 sys? And we keep on firing, 1031 00:45:55,920 --> 00:45:58,140 uh, multiple, uh, attempts 1032 00:45:58,140 --> 00:46:00,120 down the, the same TCP pipe, 1033 00:46:00,180 --> 00:46:01,960 so we're not having to go through that whole 1034 00:46:01,960 --> 00:46:03,860 setting up the communication again. 1035 00:46:04,100 --> 00:46:06,340 So, what would take 1036 00:46:06,340 --> 00:46:07,760 typically, uh, 1037 00:46:08,240 --> 00:46:10,200 a minute to go through a 1038 00:46:10,260 --> 00:46:12,240 couple of hundred passwords, we can go 1039 00:46:12,240 --> 00:46:14,020 through a couple hundred passwords in a second, 1040 00:46:14,180 --> 00:46:15,840 so we speed up, uh, brute forcing. 1041 00:46:16,500 --> 00:46:17,900 Obviously later versions of Oracle, 1042 00:46:18,080 --> 00:46:20,240 uh, account locking is enabled by 1043 00:46:20,240 --> 00:46:22,000 default, so we would just go for the sys account 1044 00:46:22,000 --> 00:46:23,600 because you can't lock out that, uh, 1045 00:46:24,120 --> 00:46:26,220 account anyway. And obviously the trace 1046 00:46:26,220 --> 00:46:27,940 files, we looked at our debug earlier. 1047 00:46:28,520 --> 00:46:30,080 I'm not gonna have, uh, 1048 00:46:31,060 --> 00:46:32,140 time to show you any of the 1049 00:46:32,140 --> 00:46:34,180 tools and stuff. If you are interested in 1050 00:46:34,180 --> 00:46:35,860 the tools, it's, it's, they're free, 1051 00:46:35,960 --> 00:46:37,980 go to the Verity website, download 1052 00:46:37,980 --> 00:46:40,080 them, play with them, have fun and everything like that, 1053 00:46:40,260 --> 00:46:41,740 uh, so, 1054 00:46:42,220 --> 00:46:43,720 thanks for listening. Are there any questions 1055 00:46:44,300 --> 00:46:45,080 before I disappear? 1056 00:46:48,740 --> 00:46:50,060 I can barely see you, so 1057 00:46:50,060 --> 00:46:51,320 if you do have a question, shout out. 1058 00:46:52,880 --> 00:46:54,180 Okay, no questions then? 1059 00:46:54,240 --> 00:46:55,800 Great. Thank you very, very much for coming.