1 00:00:00,620 --> 00:00:03,940 I'm going to talk a little bit about anti-reverse engineering techniques. 2 00:00:05,160 --> 00:00:07,700 My name is Jan Nugent. I'm from Germany. 3 00:00:09,220 --> 00:00:13,280 So what's a little bit special about this talk is the fact that 4 00:00:13,280 --> 00:00:18,820 the techniques I'm going to present here have been taken from a real-world DRAM system. 5 00:00:19,400 --> 00:00:23,220 So I was running into some legal issues with that, 6 00:00:23,300 --> 00:00:27,460 so I need to actually strip some details out of the talk. 7 00:00:28,920 --> 00:00:33,980 But I have also a few slides on that later, so let's just have a look at the outline. 8 00:00:35,040 --> 00:00:39,020 We start pretty smooth with a short introduction on DRAMs in general. 9 00:00:39,940 --> 00:00:44,020 And as I said, I will have a few slides on the legal issues with that. 10 00:00:47,460 --> 00:00:50,200 Chapter 2, actually this is the correct slide. 11 00:00:50,440 --> 00:00:52,520 Chapter 2 is a little bit more technical. 12 00:00:53,640 --> 00:00:57,320 We'll see some details on exceptions. 13 00:00:57,460 --> 00:01:00,300 We have a little bit more information handling on the Windows on operating system level. 14 00:01:00,560 --> 00:01:06,800 And we need this background knowledge in order to understand all the techniques I'm going to present in Chapter 3. 15 00:01:07,760 --> 00:01:11,740 And Chapter 3 actually is probably the main part of the talk 16 00:01:11,740 --> 00:01:16,820 and deals with various anti-reverse engineering techniques and how to overcome them. 17 00:01:17,820 --> 00:01:21,640 And finally, we have a demo, and that's it. 18 00:01:25,180 --> 00:01:27,160 So, obviously, there... 19 00:01:27,460 --> 00:01:30,480 There are some legal issues with this talk, and that's due to the fact that 20 00:01:31,300 --> 00:01:36,420 publishing DRAM research is probably pretty dangerous and considered to be illegal in most countries. 21 00:01:37,560 --> 00:01:41,500 At least, there's a huge legal uncertainty. 22 00:01:42,840 --> 00:01:44,440 So I went through the EFF, 23 00:01:45,860 --> 00:01:51,960 and especially Jennifer Granig, who gives me some very good insights and some very good advice. 24 00:01:52,100 --> 00:01:53,460 Thanks, Jennifer, if you see this. 25 00:01:55,180 --> 00:01:57,440 So we were discussing how we could... 26 00:01:57,460 --> 00:02:01,060 how we could modify the talk in order to lower the overall risk for me. 27 00:02:01,640 --> 00:02:06,100 And Jennifer actually told me that there's some kind of loophole in the DMCA, 28 00:02:06,840 --> 00:02:13,480 which allows you to publish your DRAM research if you do so-called encryption research, 29 00:02:14,160 --> 00:02:19,680 though there have to be fulfilled some additional issues with that. 30 00:02:19,740 --> 00:02:25,120 But this is still too dangerous for me, so I decided to go for another solution. 31 00:02:25,460 --> 00:02:26,860 And we discussed... 32 00:02:27,460 --> 00:02:30,200 the various solutions which would be fitted here. 33 00:02:31,080 --> 00:02:34,880 And as a consequence, I modified the talk in a way that, 34 00:02:35,460 --> 00:02:39,680 I skipped all the details about this key setup of the decryption algorithm. 35 00:02:40,460 --> 00:02:45,120 And additionally, I also won't reveal the very identity after the DRAM encryption. 36 00:02:45,400 --> 00:02:47,820 So this is kind of a black... black box talk. 37 00:02:51,320 --> 00:02:56,520 So, what this is about, it's about showing some not so common and reverse engineering techniques 38 00:02:56,520 --> 00:02:58,180 techniques from a real-world example, 39 00:02:58,920 --> 00:03:01,800 and I'm also going to show how to defeat these techniques. 40 00:03:02,620 --> 00:03:05,040 And it's obviously not on how to hack, 41 00:03:05,160 --> 00:03:07,020 insert your DRM here, or, 42 00:03:07,680 --> 00:03:10,000 it's also not about writing decryption tools. 43 00:03:11,620 --> 00:03:12,900 So, what's a DRM anyway? 44 00:03:14,460 --> 00:03:16,660 DRM means digital restriction, no. 45 00:03:16,840 --> 00:03:18,360 DRM means digital rights management. 46 00:03:18,540 --> 00:03:20,780 Some people say it means digital restriction management. 47 00:03:21,500 --> 00:03:24,460 So, what it actually does is it restricts the user 48 00:03:24,460 --> 00:03:25,960 in accessing the content, 49 00:03:26,620 --> 00:03:30,180 and this is achieved by encrypting the content. 50 00:03:30,400 --> 00:03:34,080 So, the DRM actually controls access to the key, 51 00:03:35,520 --> 00:03:37,840 and whenever you access the content, 52 00:03:38,040 --> 00:03:40,620 it's being decrypted online by the DRM system. 53 00:03:42,060 --> 00:03:45,040 The key is often bound to the user or hardware 54 00:03:45,040 --> 00:03:48,100 in order to prevent copying of content 55 00:03:48,100 --> 00:03:49,180 between different users. 56 00:03:50,520 --> 00:03:52,080 So, whenever you change your hardware, 57 00:03:52,220 --> 00:03:54,220 it's very likely that you need 58 00:03:54,220 --> 00:03:55,340 to acquire a new license. 59 00:03:57,080 --> 00:03:58,480 And, depending on the implementation, 60 00:03:58,880 --> 00:04:01,580 there might be various types of keys, 61 00:04:01,720 --> 00:04:04,360 such as media keys, hardware keys, player keys, and so on. 62 00:04:05,460 --> 00:04:08,160 And, just an obvious, pretty obvious side note is that 63 00:04:08,840 --> 00:04:12,580 every mainly software-driven DRM actually can be broken. 64 00:04:15,220 --> 00:04:17,660 So, let's define our strategy 65 00:04:17,660 --> 00:04:20,100 we would use to attack such a system. 66 00:04:22,120 --> 00:04:24,200 It's pretty obvious that the ultimate key, DRM, is really up to the user. 67 00:04:24,220 --> 00:04:31,280 goal is to find the decryption algorithm and the associated key setup. And if you can understand 68 00:04:31,280 --> 00:04:35,400 these, then obviously you have a technique to decrypt any content. 69 00:04:37,140 --> 00:04:43,600 So the obvious approach probably would be to, from a debugger perspective, would be 70 00:04:43,600 --> 00:04:49,860 to set some breakpoints on common system I.O.L. APIs like, under Windows, like create file, 71 00:04:49,860 --> 00:04:57,140 read file, or memory map files. And then you would probably set a breakpoint 72 00:04:57,140 --> 00:05:03,240 on memory access on the file buffer. And whenever this breakpoint would trigger, this 73 00:05:03,240 --> 00:05:08,960 would mean that it's either a copy operation or you're probably very near to the actual 74 00:05:08,960 --> 00:05:09,800 decryption algorithm. 75 00:05:12,220 --> 00:05:19,080 Okay so, since this talk would be over at this time if the DRAM system would allow this, 76 00:05:19,860 --> 00:05:24,560 we see that the DRAM system actually prevents this strategy by blocking the debug registers. 77 00:05:24,900 --> 00:05:31,980 So we need to, we need to carry out some fancy strategies in order to still be sufficient. 78 00:05:34,560 --> 00:05:41,940 Okay, a probably, a likely strategy would be to use code coverage. Code coverage in 79 00:05:41,940 --> 00:05:49,840 this sense means that you let the program run online while recording execution of base 80 00:05:49,860 --> 00:05:52,420 basic blocks or functions, and you recall all these 81 00:05:53,100 --> 00:05:56,540 break point hits and do some calculations 82 00:05:56,960 --> 00:06:00,500 with the sets of hits, so you would ultimately 83 00:06:01,220 --> 00:06:06,180 find, pretty easily find DRM-related code. 84 00:06:07,500 --> 00:06:10,260 Due to a few anti-reverse engineering techniques, 85 00:06:10,440 --> 00:06:12,800 code coverage is not possible in this case, 86 00:06:12,940 --> 00:06:15,640 but on the other hand, it gives some good starting points. 87 00:06:17,260 --> 00:06:22,440 Okay, so summing up, our strategy is to use code coverage 88 00:06:22,860 --> 00:06:27,560 and apply the debug registers and the hardware break points 89 00:06:27,560 --> 00:06:29,140 to find the decryption code. 90 00:06:32,380 --> 00:06:35,820 Okay, so exception handling under Windows, namely SEH, 91 00:06:37,040 --> 00:06:39,080 works on a per-thread basis. 92 00:06:39,220 --> 00:06:42,360 This means every thread actually has a list of 93 00:06:43,160 --> 00:06:45,420 registered exception handlers, which is pointed to 94 00:06:45,420 --> 00:06:45,620 by the user. 95 00:06:45,620 --> 00:06:49,160 This is our FS0, and whenever there's an exception 96 00:06:49,160 --> 00:06:51,460 triggered in the current running thread, 97 00:06:51,700 --> 00:06:57,440 the operating system walks this list and calls every thread 98 00:06:57,820 --> 00:07:00,660 until it finds one which responds to be able 99 00:07:00,660 --> 00:07:01,700 to handle the exception. 100 00:07:02,600 --> 00:07:06,220 So, as we see, an exception handler basically 101 00:07:06,220 --> 00:07:07,200 has two choices. 102 00:07:08,060 --> 00:07:11,180 On the one hand, it can say, okay, I'll handle the exception 103 00:07:12,020 --> 00:07:15,520 and return to the operating system, and in this 104 00:07:15,520 --> 00:07:17,840 moment, the operating system will stop list walking 105 00:07:18,210 --> 00:07:19,680 and schedule the thread again. 106 00:07:20,570 --> 00:07:23,300 On the other hand, the thread can decide to refuse 107 00:07:23,300 --> 00:07:25,340 to handle the exception, and in this case, 108 00:07:25,460 --> 00:07:29,080 the operating system will continue to walk the list 109 00:07:29,080 --> 00:07:30,000 of exception handlers. 110 00:07:33,140 --> 00:07:36,840 Okay, so what we see here is the signature of an 111 00:07:36,840 --> 00:07:41,040 exception handler, and probably the most important 112 00:07:41,040 --> 00:07:44,920 parameters are the exception record as well as the context. 113 00:07:46,920 --> 00:07:48,360 So, what does this mean? 114 00:07:48,480 --> 00:07:50,840 The exception record actually contains information 115 00:07:50,840 --> 00:07:54,980 on the exception itself, like the exception code, 116 00:07:56,230 --> 00:07:59,720 whereas the context is a pointer to the thread's context 117 00:07:59,720 --> 00:08:02,700 of the faulting thread, so the handler actually has 118 00:08:02,700 --> 00:08:07,320 the possibility to modify the context in a way such as 119 00:08:07,320 --> 00:08:10,580 that it fixes what caused the exception in the first place. 120 00:08:12,180 --> 00:08:14,640 And the list structure is depicted by the image. 121 00:08:15,520 --> 00:08:19,340 In the end of the list, you have always the operating 122 00:08:19,340 --> 00:08:23,180 system handler, which jumps in if there's no handler 123 00:08:23,700 --> 00:08:26,960 which could handle the exception, and this usually means 124 00:08:26,960 --> 00:08:30,640 that the process is terminated and Dr. Watson shows up 125 00:08:30,640 --> 00:08:31,060 or whatever. 126 00:08:33,000 --> 00:08:36,300 Okay, so the SEH in a more detailed version, 127 00:08:37,940 --> 00:08:40,080 whenever there's an exception triggered, 128 00:08:40,340 --> 00:08:43,340 the operating system actually dispatches into kernel mode, 129 00:08:45,520 --> 00:08:49,240 and the interrupt descriptor table is used to carry out 130 00:08:49,240 --> 00:08:54,140 all the program logic which clumps together the exception record 131 00:08:54,460 --> 00:08:59,080 and the context pointer, and this information is then 132 00:08:59,080 --> 00:09:02,760 passed down to user mode again, and the first code being 133 00:09:02,760 --> 00:09:05,620 executed in user mode actually is inside NTDLL, 134 00:09:05,820 --> 00:09:10,200 and the very procedure is a user exception dispatcher. 135 00:09:11,520 --> 00:09:15,260 And from this procedure, all the SEH list walking, 136 00:09:15,520 --> 00:09:17,800 logic, as previously outlined, is triggered. 137 00:09:19,250 --> 00:09:24,580 And in this case, handler one would be able to fix 138 00:09:25,540 --> 00:09:28,900 the exception and return to the NTDLL procedure, 139 00:09:29,670 --> 00:09:33,060 which would finally use NT-continue, which applies 140 00:09:33,060 --> 00:09:37,220 the possibly modified context to the thread. 141 00:09:40,440 --> 00:09:44,380 Okay, in this view, it was pretty much simplified, 142 00:09:45,520 --> 00:09:50,600 but it's sufficient for our analysis because we don't need 143 00:09:50,600 --> 00:09:53,780 concepts like stack unwinding, collided unwinds, and so on. 144 00:09:54,740 --> 00:09:57,500 And important to note, a handler can also decide 145 00:09:57,500 --> 00:10:00,460 not to return, for example, in C++, it's pretty common 146 00:10:00,460 --> 00:10:02,680 that the context is actually modified. 147 00:10:06,340 --> 00:10:10,720 Okay, so the DRAM protection actually deals with two major 148 00:10:11,440 --> 00:10:15,100 techniques to scare off reverse engineers. 149 00:10:15,100 --> 00:10:15,500 Okay, so the DRAM protection actually deals with two major techniques to scare off reverse engineers. 150 00:10:15,520 --> 00:10:18,040 It's control flow obfuscation on the one hand, 151 00:10:18,040 --> 00:10:20,180 and on the other hand, it's anti-debugging tricks. 152 00:10:21,280 --> 00:10:25,680 For control flow obfuscation, the DRAM system uses 153 00:10:25,680 --> 00:10:30,440 a vast amount of fake exceptions to interrupt control flow 154 00:10:30,440 --> 00:10:35,520 at runtime, and these handlers, the exception handlers, 155 00:10:35,560 --> 00:10:41,940 which react on these fake exceptions actually use logic 156 00:10:41,940 --> 00:10:44,220 to change the thread context. 157 00:10:46,460 --> 00:10:49,560 So, what you have is an exception handler, 158 00:10:49,720 --> 00:10:51,800 since it's able to modify the thread context, 159 00:10:52,100 --> 00:10:54,940 it can, for example, change the instruction pointer 160 00:10:54,940 --> 00:10:58,060 and the program resumes at a totally different location. 161 00:11:00,200 --> 00:11:03,140 Additionally, there are many, there are many call tables 162 00:11:03,140 --> 00:11:07,720 in order to stop disassemblers from successfully 163 00:11:08,280 --> 00:11:14,060 performing cross-referencing, and there are two major 164 00:11:14,060 --> 00:11:15,500 And there are two major, and two reversing techniques that we can use to stop disassemblers from successfully performing cross-referencing. 165 00:11:15,500 --> 00:11:17,200 For reverse engineering techniques, on the one hand, 166 00:11:17,200 --> 00:11:20,080 it's tremble lines, which I have a few slides on, 167 00:11:20,720 --> 00:11:24,000 and it's the P-code machine, which is used to carry out 168 00:11:24,000 --> 00:11:25,780 the actual decryption algorithm. 169 00:11:27,640 --> 00:11:31,180 Okay, for anti-debugging, we have some very basic checks. 170 00:11:32,200 --> 00:11:35,020 That is, the very common PEB flag check, 171 00:11:35,120 --> 00:11:39,400 or scanning APIs for interrupt-free opcodes. 172 00:11:41,120 --> 00:11:45,180 And in addition, you have special files containing 173 00:11:45,500 --> 00:11:46,980 code which is uncompressed at runtime, 174 00:11:47,220 --> 00:11:49,420 and this, again, is nothing very fancy, 175 00:11:50,040 --> 00:11:51,760 because this has been around for some years. 176 00:11:52,660 --> 00:11:55,500 But on the other hand, the usage of debug registers 177 00:11:56,880 --> 00:11:59,880 actually is a little bit harder to overcome, 178 00:12:00,500 --> 00:12:01,880 which we will see in a few seconds. 179 00:12:03,520 --> 00:12:06,460 And finally, the system also uses fake exceptions 180 00:12:06,460 --> 00:12:09,000 to detect a possibly attached debugger. 181 00:12:11,260 --> 00:12:15,480 Okay, so tremble lines are, in this case, is called, 182 00:12:15,480 --> 00:12:18,440 is code which is copied at runtime to a randomized location, 183 00:12:19,420 --> 00:12:24,500 and AudiTSC is used as a seed for a random number generator 184 00:12:25,120 --> 00:12:27,900 to place the destination of the tremble line. 185 00:12:28,360 --> 00:12:30,760 And when the tremble line has been copied, 186 00:12:30,980 --> 00:12:33,240 execution is resumed from the destination. 187 00:12:36,560 --> 00:12:40,060 Okay, so the actual control flow, 188 00:12:40,300 --> 00:12:44,540 which is changed via fake exceptions, in this case, 189 00:12:45,480 --> 00:12:46,460 since it's a fake exception, 190 00:12:46,740 --> 00:12:49,600 we need to have some unique exception identifier, 191 00:12:50,760 --> 00:12:53,080 and in this case, it's a single-step exception, 192 00:12:53,200 --> 00:12:56,620 and this also possibly interferes with an attached debugger. 193 00:12:58,020 --> 00:13:01,760 And the exception handler actually modifies 194 00:13:01,760 --> 00:13:05,880 the instruction pointer based on some debug register values, 195 00:13:06,220 --> 00:13:10,820 and this is exactly the reason why the debug registers have been blocked. 196 00:13:11,060 --> 00:13:15,280 So, because instruction pointer, the instruction pointer, 197 00:13:15,280 --> 00:13:15,460 and the instruction pointer, have been blocked, 198 00:13:15,460 --> 00:13:18,260 actually depends on values of the debug registers. 199 00:13:19,780 --> 00:13:23,160 So you cannot easily use BPMs in your debugger 200 00:13:23,160 --> 00:13:25,140 because that would interfere with the DRAM system. 201 00:13:27,420 --> 00:13:30,680 Okay, so let's see some details 202 00:13:30,680 --> 00:13:32,960 about the Trample Line control flow. 203 00:13:33,420 --> 00:13:36,860 In this situation, Trample Line A wants to initiate 204 00:13:36,860 --> 00:13:39,280 a control flow change to Trample Line B. 205 00:13:40,900 --> 00:13:43,940 And it's important to note that the control flow 206 00:13:43,940 --> 00:13:47,320 entirely depends on jumps and exceptions. 207 00:13:47,540 --> 00:13:51,080 That means there's no such thing like a call 208 00:13:51,080 --> 00:13:55,220 to a Trample Line because everything goes through exceptions. 209 00:13:56,900 --> 00:14:00,620 That means there's really no direct control flow 210 00:14:00,620 --> 00:14:03,240 between A and B because everything goes 211 00:14:03,240 --> 00:14:04,800 through the exception handlers. 212 00:14:05,060 --> 00:14:08,280 And therefore, we have a call hierarchy emulation 213 00:14:08,840 --> 00:14:11,540 because if you only jump to a Trample Line, 214 00:14:11,680 --> 00:14:13,840 you cannot, the Trample Line, 215 00:14:13,840 --> 00:14:15,340 being jumped to cannot just return 216 00:14:15,340 --> 00:14:17,460 because there's no return address on the stack. 217 00:14:21,080 --> 00:14:26,380 So Trample Line A copies the Trample Line 0 and jumps to it. 218 00:14:26,460 --> 00:14:29,760 Trample Line 0 is just a immediate Trample Line 219 00:14:29,760 --> 00:14:33,320 which is used to put the destination Trample Line, 220 00:14:33,520 --> 00:14:34,780 in this case, Trample Line B, 221 00:14:35,260 --> 00:14:37,340 on an internal call stack emulation. 222 00:14:39,020 --> 00:14:41,520 And this is, as I said, this is needed 223 00:14:41,520 --> 00:14:43,820 because there is no direct call between A and B. 224 00:14:43,820 --> 00:14:46,360 A and B, so you have to kind of emulate 225 00:14:46,360 --> 00:14:48,840 this nested calls and return operations. 226 00:14:51,140 --> 00:14:54,060 Okay, and Trampl.0 actually, sorry, 227 00:14:54,100 --> 00:14:57,960 Trampl.0 actually pushes the destination Trampl.1 228 00:14:57,960 --> 00:15:02,400 on the internal stack, and after this, 229 00:15:02,500 --> 00:15:05,740 it copies the next Trampl.1 again to a random location, 230 00:15:06,540 --> 00:15:08,420 and Trampl.1, in this case, 231 00:15:10,680 --> 00:15:12,060 installs an SEH frame, 232 00:15:12,280 --> 00:15:17,020 which is used to handle a fake exception, 233 00:15:17,300 --> 00:15:20,380 which is waste by this common code. 234 00:15:21,820 --> 00:15:25,180 First of all, the E-flex register is pushed to the stack, 235 00:15:25,680 --> 00:15:29,720 and the trap flag is owed in, 236 00:15:30,040 --> 00:15:33,400 and finally it's applied, so upon the next instruction, 237 00:15:33,660 --> 00:15:35,960 a single step exception is triggered, 238 00:15:37,240 --> 00:15:37,960 and the, 239 00:15:38,420 --> 00:15:42,620 the aforementioned SEH handler is invocated 240 00:15:42,620 --> 00:15:43,760 by the operating system, 241 00:15:45,120 --> 00:15:48,860 and so the exception handler now carries out all the logic, 242 00:15:49,320 --> 00:15:51,400 which is involved in, 243 00:15:52,320 --> 00:15:54,820 in the return and call emulation. 244 00:15:55,120 --> 00:15:57,180 So what it basically does is it changes 245 00:15:57,180 --> 00:15:59,840 the instruction pointer based on the debug register values, 246 00:16:00,540 --> 00:16:02,800 and again, it clears the trap flag bit, 247 00:16:02,900 --> 00:16:05,620 removes the SEH frame, and cleans up the stack. 248 00:16:07,140 --> 00:16:11,380 And finally, execution resumes at Trampl.1, too, 249 00:16:11,480 --> 00:16:15,440 which in turn copies the destination Trampl.1 250 00:16:15,440 --> 00:16:16,160 and jumps to it. 251 00:16:16,300 --> 00:16:20,320 So, what we saw here is this is the mechanism 252 00:16:20,320 --> 00:16:24,660 which is used to emulate a call between A and B. 253 00:16:27,500 --> 00:16:31,360 The return, so whenever Trampl.1 B wants to return again 254 00:16:31,360 --> 00:16:35,020 to Trampl.1 A, it would do this in a similar way. 255 00:16:35,620 --> 00:16:37,640 That is, again, use Trampl.0, 1, 256 00:16:37,780 --> 00:16:39,420 and trigger some fake exception, 257 00:16:39,720 --> 00:16:41,340 and the handler would then modify 258 00:16:42,220 --> 00:16:43,380 the internal stack representation, 259 00:16:44,140 --> 00:16:46,960 clean up the stack, and return to the middle of Trampl.1 A. 260 00:16:50,680 --> 00:16:53,680 Okay, so the debug registers are used in a special way, 261 00:16:54,360 --> 00:16:58,460 whereas debug register 0 and 6 are zeroed out, 262 00:16:58,540 --> 00:16:59,940 because they aren't used at all. 263 00:17:01,280 --> 00:17:04,900 Debug register 1 contains a pointer to a shared stack area, 264 00:17:05,040 --> 00:17:05,600 but it's not used at all. 265 00:17:05,620 --> 00:17:08,760 Which is used to pass data between Trampl.1s. 266 00:17:08,820 --> 00:17:12,680 In this case, that would mean DL1 points to a location 267 00:17:13,240 --> 00:17:17,200 which is used to exchange data between Trampl.1 A and B. 268 00:17:17,360 --> 00:17:20,760 So, therefore, you have some kind of parameter emulation. 269 00:17:24,820 --> 00:17:27,660 DL2 actually holds the Trampl.1 address 270 00:17:27,660 --> 00:17:30,460 used to perform the return emulation, 271 00:17:31,240 --> 00:17:34,360 and DL3 holds the address of the starting Trampl.1, 272 00:17:34,380 --> 00:17:35,100 that is Trampl.0. 273 00:17:36,000 --> 00:17:40,280 And, to confuse a possibly attached debugger, 274 00:17:40,400 --> 00:17:43,660 DR7 is used to turn hardware breakpoints 275 00:17:43,660 --> 00:17:44,940 on and off very frequently. 276 00:17:47,590 --> 00:17:49,460 So, what's the impact on reverse engineering? 277 00:17:50,950 --> 00:17:54,600 It's pretty annoying to debug such a concept, 278 00:17:54,740 --> 00:17:58,020 because Trampl.1s always jitter around in memory, 279 00:17:58,650 --> 00:18:03,220 and it's pretty hard to actually recognize 280 00:18:03,220 --> 00:18:04,720 repeating code patterns, 281 00:18:04,880 --> 00:18:07,600 because everything is copied at random addresses, 282 00:18:07,900 --> 00:18:11,440 and your disassembler or debugger has, 283 00:18:11,880 --> 00:18:14,420 it's difficult for the debugger or the disassembler 284 00:18:14,420 --> 00:18:16,500 to recognize function boundaries. 285 00:18:19,200 --> 00:18:22,140 So, as I said, since the control flow 286 00:18:22,140 --> 00:18:24,840 actually depends on the debug registers, 287 00:18:25,060 --> 00:18:29,940 we don't have a possibility to use our BPM or BPX strategy, 288 00:18:30,140 --> 00:18:32,220 as I pointed in the first part. 289 00:18:34,020 --> 00:18:36,480 On the other hand, we have also no call stack, 290 00:18:36,700 --> 00:18:38,700 as I said, due to the call emulation. 291 00:18:39,100 --> 00:18:43,620 So, it's pretty hard to kind of backtracing 292 00:18:43,620 --> 00:18:45,240 from a nested procedure call, 293 00:18:45,880 --> 00:18:47,220 and also we cannot, 294 00:18:48,340 --> 00:18:51,460 it's not so easy for the disassembler to say, 295 00:18:52,160 --> 00:18:54,480 OK, procedure A calls procedure B, 296 00:18:54,560 --> 00:18:56,020 because there are no call instructions 297 00:18:56,380 --> 00:18:57,480 which are directly used. 298 00:18:57,700 --> 00:19:02,540 And this means we have really very few cross-referencing, 299 00:19:02,540 --> 00:19:02,900 information. 300 00:19:02,900 --> 00:19:09,960 formation. And additionally, finally, absence of return instruction confuses a disassembler 301 00:19:09,960 --> 00:19:18,700 because it's hard to guess function boundaries. Okay, on the other hand, once we understood 302 00:19:18,700 --> 00:19:26,180 this call emulation mechanism, we get a perfect call stack, which is good because usually 303 00:19:26,180 --> 00:19:30,660 when debugging without debugging symbols, we don't get a perfect call stack. 304 00:19:32,900 --> 00:19:39,980 Okay, so how can we actually ease the impact of the trample on mechanism? An idea would be to 305 00:19:39,980 --> 00:19:46,940 actually fix the trample on addresses in memory. And we can do this by writing a kernel mode driver. 306 00:19:48,240 --> 00:19:54,740 And this driver then would actually turn our DTSC instruction into a privilege instruction 307 00:19:54,740 --> 00:20:01,900 by setting the timestamp disable flag in 0.4. And this means whenever this instruction is 308 00:20:01,900 --> 00:20:02,880 executed in use case, it will be executed in use case. And this means whenever this instruction 309 00:20:02,900 --> 00:20:09,860 is executed in user mode, a general protection fault is waste. And again, then all these 310 00:20:09,860 --> 00:20:17,540 exception handling, which outlines in the second chapter, jumps in. And as I said, the 311 00:20:17,540 --> 00:20:23,820 control flow upon this general protection fault would then jump to the interrupt descriptor 312 00:20:23,820 --> 00:20:30,440 table, which we would hook. So whenever the RDTSC instruction would be executed, we would 313 00:20:30,440 --> 00:20:32,100 gain control in our driver. 314 00:20:33,340 --> 00:20:42,740 And what we could do is we could just disable the randomization by just returning 0 if we 315 00:20:42,740 --> 00:20:48,220 come from user mode and if the instruction actually was RDTSC. So we need to disassemble 316 00:20:48,220 --> 00:20:56,520 the memory where the instruction would cause the general protection fault. In all other 317 00:20:56,520 --> 00:20:58,680 cases, we just jump to the original handler. 318 00:21:01,160 --> 00:21:02,880 Okay, so and this actually works. 319 00:21:03,800 --> 00:21:09,540 But by using this technique, we can fix the trample lines and this makes it a lot more 320 00:21:09,540 --> 00:21:16,820 easy to understand the trample line mechanism because you have, it's easier for the reverse 321 00:21:16,820 --> 00:21:22,120 engineer then to see repeating code patterns because everything doesn't jitter around anymore. 322 00:21:23,800 --> 00:21:29,780 Okay, some words on the debug registers. The debug registers are used by the DRM system, 323 00:21:29,900 --> 00:21:31,820 as I said, for various storage. 324 00:21:31,820 --> 00:21:42,320 And so the debugger cannot use the hardware breakpoints anymore. In addition, the context 325 00:21:42,620 --> 00:21:51,440 is actually set by our Windows API, set flat context. Okay, so obviously, since we said 326 00:21:51,440 --> 00:21:59,200 we wanted to have BPMs for our strategy, we need to solve this in a way. Okay, what 327 00:21:59,200 --> 00:22:01,720 we can do is we can use APIs. 328 00:22:01,720 --> 00:22:07,780 We can use a set API hooking in user land space to hook into the set or get the context APIs 329 00:22:07,780 --> 00:22:15,740 in order to redirect any modification attempts, read attempt to our internal storage and fake 330 00:22:15,740 --> 00:22:20,480 all the values the DRM system actually expects to see. 331 00:22:22,560 --> 00:22:28,580 As a consequence, the DRM system would then not be able anymore to modify the debug registers. 332 00:22:28,900 --> 00:22:30,200 And this is good. 333 00:22:30,200 --> 00:22:32,480 because that's what we ultimately want to achieve. 334 00:22:35,180 --> 00:22:36,600 So there's a problem with this 335 00:22:36,600 --> 00:22:39,520 because hardware breakpoints still won't work. 336 00:22:40,120 --> 00:22:43,700 And the reason for this is that we actually have 337 00:22:44,080 --> 00:22:45,500 two different thread contexts. 338 00:22:46,900 --> 00:22:49,820 On the one hand, we have the kernel mode thread context, 339 00:22:49,860 --> 00:22:51,780 which is maintained by the operating system. 340 00:22:52,360 --> 00:22:55,540 And on the other hand, we have, in this situation, 341 00:22:55,540 --> 00:22:59,460 we would have our internal storage of context records. 342 00:23:03,100 --> 00:23:04,440 So how can we solve this? 343 00:23:04,840 --> 00:23:09,340 We could, for example, hook KAU, the exception dispatcher. 344 00:23:09,380 --> 00:23:12,780 If you might recall, KAU, the exception dispatcher, 345 00:23:12,800 --> 00:23:16,420 actually is the first code being executed in user mode. 346 00:23:18,560 --> 00:23:23,600 So a reimplemented version would actually check 347 00:23:24,060 --> 00:23:25,440 if the current exception 348 00:23:25,540 --> 00:23:27,960 is a fake exception, 349 00:23:28,220 --> 00:23:30,580 that is, if it's of type single step. 350 00:23:31,800 --> 00:23:33,040 And if that's the case, 351 00:23:33,760 --> 00:23:35,360 it would pass a fake context 352 00:23:36,080 --> 00:23:37,940 with the fake debug register values 353 00:23:37,940 --> 00:23:43,340 previously set by the thread context API to the handler. 354 00:23:45,560 --> 00:23:47,320 So the handler would actually see 355 00:23:47,920 --> 00:23:50,140 the correct values it expects. 356 00:23:51,620 --> 00:23:55,260 And on return, that is when the handler returns 357 00:23:55,540 --> 00:24:00,120 to our KAU, the exception dispatcher, reimplementation, 358 00:24:00,790 --> 00:24:05,080 we would need to merge the modifications 359 00:24:05,570 --> 00:24:11,980 made by the handler into the real context back. 360 00:24:12,710 --> 00:24:17,120 And after this, we would then apply the final context again 361 00:24:17,120 --> 00:24:19,400 via NT-continue, as the original 362 00:24:20,170 --> 00:24:22,040 KAU, the exception dispatcher does. 363 00:24:24,350 --> 00:24:24,760 Okay. 364 00:24:24,760 --> 00:24:26,340 So here are a few more details. 365 00:24:26,600 --> 00:24:27,680 How does this work? 366 00:24:29,300 --> 00:24:33,440 In the upper image, you see the real context in kernel mode, 367 00:24:33,540 --> 00:24:35,200 which is maintained by the operating system. 368 00:24:35,840 --> 00:24:40,160 And in the lower part, there's our hooked version, 369 00:24:41,380 --> 00:24:42,600 our MGLT thread context. 370 00:24:43,420 --> 00:24:46,200 And at one, you see that the DRM system 371 00:24:46,980 --> 00:24:50,280 frequently uses set and get thread context API calls 372 00:24:50,820 --> 00:24:52,520 in order to modify the context. 373 00:24:52,640 --> 00:24:54,740 And all of these are redirected, and they're all connected. 374 00:24:54,740 --> 00:24:56,160 To our emulated context. 375 00:24:58,770 --> 00:25:01,040 So upon triggering an exception, 376 00:25:01,400 --> 00:25:04,700 the operating system would again call 377 00:25:05,970 --> 00:25:08,820 our KAU, the exception dispatcher, because we hooked it. 378 00:25:10,570 --> 00:25:12,020 And what we would do then is, 379 00:25:12,450 --> 00:25:15,640 we would plug in the fake debug register values, 380 00:25:16,570 --> 00:25:21,220 which are green, and merge them with the original values 381 00:25:21,630 --> 00:25:24,540 passed down from kernel mode by the operating system. 382 00:25:27,000 --> 00:25:30,340 So, we would then call the exception handler 383 00:25:30,340 --> 00:25:32,200 and passing our fake context, 384 00:25:33,100 --> 00:25:35,920 and the exception handler would then do all the fancy stuff 385 00:25:35,920 --> 00:25:40,400 and return, and the exception handler actually modifies 386 00:25:40,400 --> 00:25:44,020 some of the general purpose registers like the ESP, 387 00:25:44,140 --> 00:25:47,220 because it's cleaning up the stack, and some other stuff. 388 00:25:47,340 --> 00:25:49,940 Especially of course, the instruction pointers. 389 00:25:50,060 --> 00:25:54,540 So, we need to merge those two versions and sync them back, 390 00:25:54,740 --> 00:25:57,260 And finally, let the operating system 391 00:25:57,260 --> 00:25:59,040 apply this modified context. 392 00:26:01,900 --> 00:26:04,700 So, the summary after these countermeasures is 393 00:26:04,700 --> 00:26:07,800 the DRAM system actually cannot modify 394 00:26:07,800 --> 00:26:11,300 our debug registers anymore, which is due to our API hook. 395 00:26:12,420 --> 00:26:16,160 And in addition, the exception handler of the DRAM system 396 00:26:16,160 --> 00:26:19,440 gets its expected values because they are fed 397 00:26:19,440 --> 00:26:20,580 from our internal storage. 398 00:26:21,600 --> 00:26:25,020 So, this means we can really now use 399 00:26:25,020 --> 00:26:27,240 the hardware breakpoints for our analysis. 400 00:26:28,540 --> 00:26:31,680 I made the implementation available as an IDA plug-in. 401 00:26:31,920 --> 00:26:33,560 Maybe you would want to check it out. 402 00:26:35,700 --> 00:26:39,920 Okay, so the final protection mechanism, 403 00:26:40,320 --> 00:26:43,520 which seems to be probably the hardest one, 404 00:26:43,600 --> 00:26:45,040 is the use of a P-code machine. 405 00:26:47,000 --> 00:26:48,340 So, what's a P-code machine? 406 00:26:48,620 --> 00:26:50,560 A P-code machine is... 407 00:26:50,580 --> 00:26:52,640 some kind of virtual machine 408 00:26:52,640 --> 00:26:54,900 which is embedded inside the DRAM system. 409 00:26:55,820 --> 00:27:00,840 And in this case, this virtual machine is stack-based, 410 00:27:01,020 --> 00:27:04,460 which means that all parameters are pushed 411 00:27:04,460 --> 00:27:07,380 on a virtualized stack, 412 00:27:07,520 --> 00:27:09,660 which is maintained by the P-code machine. 413 00:27:11,280 --> 00:27:16,560 And you have roughly 256 opcodes, 414 00:27:17,160 --> 00:27:20,560 and the data are represented as ASMPs, 415 00:27:20,580 --> 00:27:22,300 which is an ASN1, an ASN1 format. 416 00:27:23,520 --> 00:27:28,580 And the P-code machine actually allows programs running inside it 417 00:27:28,580 --> 00:27:30,700 to allocate memory from the host machine, 418 00:27:30,940 --> 00:27:32,820 whereas the host machine in this case 419 00:27:32,820 --> 00:27:36,900 is just the program where the P-code machine is embedded in. 420 00:27:38,920 --> 00:27:44,760 Actually, the opcode set is split in two sets. 421 00:27:45,440 --> 00:27:48,080 On the one hand, you have the high-level opcodes, 422 00:27:48,940 --> 00:27:50,560 and these are used to... 423 00:27:50,580 --> 00:27:51,800 for example, 424 00:27:52,620 --> 00:27:54,360 loads opcode files. 425 00:27:54,720 --> 00:27:56,680 The DRAM system actually has files 426 00:27:56,680 --> 00:27:59,620 which nearly only contain opcodes. 427 00:27:59,840 --> 00:28:02,520 So, you have opcodes to reload 428 00:28:03,360 --> 00:28:06,040 additional functionality in opcode files. 429 00:28:06,760 --> 00:28:10,480 And you can also call into these opcode modules. 430 00:28:12,040 --> 00:28:13,700 And it's interesting to note that 431 00:28:13,700 --> 00:28:16,520 the music decoding actually is handled by this way. 432 00:28:18,100 --> 00:28:19,340 The other part of the set 433 00:28:19,340 --> 00:28:20,560 actually contains a lot of opcodes. 434 00:28:20,580 --> 00:28:22,680 It contains low-level opcodes, 435 00:28:22,880 --> 00:28:28,440 which means it's emulated the virtual CPU. 436 00:28:28,660 --> 00:28:32,000 That is, you have simple arithmetic instructions 437 00:28:32,000 --> 00:28:34,000 like add, subtract, and so on, 438 00:28:34,080 --> 00:28:36,400 and also instructions to handle 439 00:28:36,400 --> 00:28:38,980 the internal virtual machine call stack. 440 00:28:41,340 --> 00:28:43,820 Okay, a few words on the opcode module files. 441 00:28:44,700 --> 00:28:48,820 These are special files which contain opcodes 442 00:28:48,820 --> 00:28:50,200 for the P-code machine. 443 00:28:51,100 --> 00:28:53,940 Some of them have a mixed... 444 00:28:53,940 --> 00:28:55,980 have some amount of mixed code 445 00:28:55,980 --> 00:28:57,860 that is native and opcodes. 446 00:28:59,140 --> 00:29:01,640 And these files are actually decompressed at one time 447 00:29:01,640 --> 00:29:04,280 by using, I guess it was Gzip. 448 00:29:06,180 --> 00:29:09,360 On the other hand, these files are rather plain 449 00:29:09,360 --> 00:29:11,300 because there are no PE files, 450 00:29:11,460 --> 00:29:13,620 so there's no import address table, 451 00:29:13,720 --> 00:29:15,140 no sections, and so on. 452 00:29:16,700 --> 00:29:19,400 But, there's a relocation table because 453 00:29:20,580 --> 00:29:24,080 these opcode modules might call into some... 454 00:29:24,080 --> 00:29:26,480 into a fixed amount of imports, 455 00:29:26,860 --> 00:29:30,180 like, for example, ms-visual-c++ one time. 456 00:29:31,380 --> 00:29:33,820 So, there needs to be some relocation information 457 00:29:33,820 --> 00:29:34,980 in these opcode files. 458 00:29:38,520 --> 00:29:40,700 Okay, so now, how are the opcodes executed? 459 00:29:42,420 --> 00:29:45,720 Every module actually has a random pool, 460 00:29:46,200 --> 00:29:50,220 which is used to randomize the assignment between... 461 00:29:50,220 --> 00:29:52,600 between opcode and associated handler. 462 00:29:52,980 --> 00:29:56,280 And, this just means that every opcode file 463 00:29:56,280 --> 00:29:58,320 has a totally different opcode. 464 00:29:58,440 --> 00:30:01,500 For example, say, Edition or DecryptMusic. 465 00:30:02,260 --> 00:30:05,540 And it's just to further increase the protection. 466 00:30:07,940 --> 00:30:11,760 So, as I said, the machine actually 467 00:30:11,760 --> 00:30:13,980 has a built-in pseudorandom number generator. 468 00:30:14,820 --> 00:30:19,940 And, additionally, the data intel leaf, 469 00:30:20,080 --> 00:30:20,200 the time that the machine'sğin... 470 00:30:20,200 --> 00:30:22,660 with the opcodes, which are just there to 471 00:30:23,420 --> 00:30:25,100 confuse the reverse engineer. 472 00:30:25,240 --> 00:30:27,880 It's just garbage data inserted between opcodes. 473 00:30:28,060 --> 00:30:30,980 And this data is actually parsed via ASN1. 474 00:30:33,580 --> 00:30:36,620 So, the impact on reverse engineering, 475 00:30:36,940 --> 00:30:38,180 why is this difficult? 476 00:30:38,360 --> 00:30:42,180 Because you need to understand the machine itself 477 00:30:42,660 --> 00:30:46,420 before you can even start to understand the opcodes, 478 00:30:46,560 --> 00:30:48,960 which are contained in the files of the main program. 479 00:30:50,280 --> 00:30:52,140 And as I said, due to the randomization, 480 00:30:52,420 --> 00:30:54,740 we have a different meaning for each opcode 481 00:30:54,740 --> 00:30:57,960 on a per-module basing, on a per-module basis. 482 00:30:59,320 --> 00:31:02,440 And due to ASN1 parsing, which is quite complex, 483 00:31:02,660 --> 00:31:04,980 this still even more increases. 484 00:31:06,920 --> 00:31:09,500 So, debugging is difficult because you have, 485 00:31:09,540 --> 00:31:13,200 and so to say, you have a low signal-to-noise ratio 486 00:31:13,200 --> 00:31:17,100 because a PCOD machine actually looks like 487 00:31:17,100 --> 00:31:19,300 a very big loop, which has 488 00:31:20,200 --> 00:31:23,060 a very large switch statement inside a loop,, 489 00:31:24,200 --> 00:31:27,100 and this is even lower due to our opcode 490 00:31:27,100 --> 00:31:28,540 scrambling with the randomization. 491 00:31:29,960 --> 00:31:32,880 And this is actually the graph in IDAR 492 00:31:33,220 --> 00:31:35,600 of the PCOD machine, and on the lower left, 493 00:31:35,680 --> 00:31:38,560 you see the entry point, and in the middle, 494 00:31:38,660 --> 00:31:40,700 there are the sixth, the blue lines. 495 00:31:40,920 --> 00:31:43,880 These are all the opcode handlers. 496 00:31:47,320 --> 00:31:50,180 Okay, so what strategies could be developed for you? 497 00:31:50,180 --> 00:31:52,260 to attack such a system. 498 00:31:53,080 --> 00:31:56,400 Probably the most expensive strategy would be 499 00:31:56,400 --> 00:31:58,660 to just what a custom disassembler. 500 00:31:59,600 --> 00:32:02,080 But the problem with this is that we have 501 00:32:02,080 --> 00:32:05,340 really many handlers, in this case it was 256. 502 00:32:07,460 --> 00:32:11,220 And also you have mixed handlers, as I said, 503 00:32:11,280 --> 00:32:14,080 those two sets with the native and the opcode handlers. 504 00:32:14,220 --> 00:32:17,680 So you would have to analyze all the complex 505 00:32:17,680 --> 00:32:19,820 high-level handlers up front in order to 506 00:32:20,220 --> 00:32:21,960 make a meaningful disassembly. 507 00:32:24,240 --> 00:32:27,020 Okay, and for the disassembler to work, 508 00:32:27,220 --> 00:32:30,300 we would also need to reassemble randomization, 509 00:32:30,640 --> 00:32:33,440 the descrambling of opcodes, the garbage instruction, 510 00:32:33,900 --> 00:32:37,520 and ASN1 pausing, so that's really kind of expensive. 511 00:32:40,700 --> 00:32:43,720 Another strategy, which I would call the brute force strategy 512 00:32:44,500 --> 00:32:47,080 would be to just let the debugger 513 00:32:47,080 --> 00:32:49,040 single-step via a debugger script 514 00:32:49,040 --> 00:32:52,580 until the key is actually written to memory. 515 00:32:53,860 --> 00:32:57,940 This is pretty slow because single-stepping 516 00:32:57,940 --> 00:32:59,380 is a pretty expensive operation 517 00:32:59,380 --> 00:33:01,420 because you have so many context switches. 518 00:33:02,660 --> 00:33:05,060 But on the other hand, you will definitely reach 519 00:33:05,060 --> 00:33:08,180 the code which writes the key to the memory, 520 00:33:09,100 --> 00:33:11,560 but it's not so cool because it doesn't seem 521 00:33:11,560 --> 00:33:12,300 to be very clever. 522 00:33:13,940 --> 00:33:15,940 So what's the cool strategy? 523 00:33:15,940 --> 00:33:18,140 The cool strategy, that would be probably to use 524 00:33:18,140 --> 00:33:23,600 a CPU emulation like PyEMU or x86EMU for IDA 525 00:33:23,600 --> 00:33:29,920 to emulate all the instructions involved in the PCOD machine. 526 00:33:30,140 --> 00:33:34,740 So essentially, you would kind of defeat virtualization 527 00:33:34,740 --> 00:33:36,040 with virtualization. 528 00:33:37,520 --> 00:33:39,820 And this is also a very fast and flexible solution 529 00:33:39,820 --> 00:33:43,240 because obviously you can control every aspect 530 00:33:43,520 --> 00:33:45,380 due to the emulation. 531 00:33:47,440 --> 00:33:51,480 Okay, and the final strategy I've been using in this is, 532 00:33:51,700 --> 00:33:53,960 well, it's pretty lazy because we use 533 00:33:53,960 --> 00:33:54,840 what we already have. 534 00:33:55,720 --> 00:33:59,960 And the trick here is that, as I previously outlined, 535 00:34:00,120 --> 00:34:04,900 the machine actually has a mechanism allowing programs 536 00:34:04,900 --> 00:34:09,280 running inside it to allocate memory in the host machine. 537 00:34:10,540 --> 00:34:15,920 So what we can do is we know that due to our breakpoint, 538 00:34:15,940 --> 00:34:18,240 on memory access, for example, we might know 539 00:34:18,240 --> 00:34:22,540 that it's a DES algorithm, and since the key schedule size 540 00:34:23,040 --> 00:34:26,840 of DES is 80 hex, we can just pass, 541 00:34:27,120 --> 00:34:30,140 we could just set a breakpoint, a conditional breakpoint, 542 00:34:30,320 --> 00:34:33,740 in the memory allocation routine, which would fire 543 00:34:34,120 --> 00:34:36,740 whenever there's an allocation of size 80. 544 00:34:39,440 --> 00:34:44,200 Okay, and so whenever we reach this point, 545 00:34:44,200 --> 00:34:46,980 we could then use our reclined debug registers 546 00:34:47,980 --> 00:34:50,320 to set a breakpoint on memory access 547 00:34:51,160 --> 00:34:54,120 in the allocated memory, and whenever this memory 548 00:34:54,120 --> 00:34:55,760 has been written, we know, okay, 549 00:34:55,880 --> 00:34:59,640 there would be one break in the key setup algorithm. 550 00:35:00,760 --> 00:35:03,040 And from there, we could, under the assumption 551 00:35:03,040 --> 00:35:06,900 that the decryption algorithm is pretty close, 552 00:35:07,060 --> 00:35:10,420 we could backtrace from there and have everything. 553 00:35:12,800 --> 00:35:15,800 So, pretty disappointing in this case, 554 00:35:15,900 --> 00:35:18,320 was that the decryption and the key setup 555 00:35:18,320 --> 00:35:21,600 are contained in native code, that is, 556 00:35:21,600 --> 00:35:25,620 some of the high-level handlers actually contained the code 557 00:35:25,620 --> 00:35:32,100 to decrypt and calculate the key to decrypt the content. 558 00:35:35,980 --> 00:35:39,280 Okay, so the key setup algorithm, here it is. 559 00:35:40,420 --> 00:35:43,140 So, a little bit obfuscated due to some legal issues. 560 00:35:44,600 --> 00:35:47,580 It basically works by hashing some files 561 00:35:48,100 --> 00:35:51,680 using different hash algorithms, and finally, 562 00:35:51,780 --> 00:35:54,980 the encryption key is then made of some XO operation. 563 00:35:56,120 --> 00:36:00,780 It turns out that the key is different for every music file. 564 00:36:02,500 --> 00:36:04,680 Okay, and as I said, it's a DES algorithm, 565 00:36:05,240 --> 00:36:07,260 and the interrupt, no, not interrupt, 566 00:36:07,420 --> 00:36:10,000 the initialization vector comes from the DRM file. 567 00:36:12,320 --> 00:36:14,180 So, now we're going to see a demo. 568 00:36:16,320 --> 00:36:16,800 Nope. 569 00:36:19,040 --> 00:36:19,520 Okay. 570 00:36:21,660 --> 00:36:24,100 So, maybe I'll say a few quick words on the demo. 571 00:36:24,280 --> 00:36:25,320 Since I need to, 572 00:36:27,500 --> 00:36:31,160 I cannot actually reveal the identity of the very DRM, 573 00:36:31,300 --> 00:36:35,180 so I need to do some kind of black box demo. 574 00:36:37,660 --> 00:36:40,400 I can show you how a decryption, 575 00:36:40,400 --> 00:36:40,780 I can show you how a decryption works. 576 00:36:42,680 --> 00:36:46,340 But I cannot show you how the encryption process works, 577 00:36:46,440 --> 00:36:49,020 because that would obviously reveal 578 00:36:49,020 --> 00:36:51,300 the very identity of the DRM. 579 00:36:51,880 --> 00:36:55,540 So, I prepared a DRM-protected file. 580 00:36:59,220 --> 00:37:01,020 And I can encrypt it. 581 00:37:05,980 --> 00:37:06,300 Okay. 582 00:37:08,240 --> 00:37:10,380 And due to the fact that the DRM system is not working, 583 00:37:10,380 --> 00:37:13,780 actually registers direct show filters, 584 00:37:14,810 --> 00:37:19,800 I can use any player to play back 585 00:37:19,800 --> 00:37:21,400 the unprotected content. 586 00:37:21,680 --> 00:37:24,320 So by using the Windows Media Player, 587 00:37:24,540 --> 00:37:25,700 I don't reveal the identity. 588 00:37:27,540 --> 00:37:28,160 So. 589 00:37:31,940 --> 00:37:34,220 Okay, so I placed. 590 00:37:45,560 --> 00:37:48,920 So, to give you a good indication 591 00:37:49,280 --> 00:37:51,720 why this is, that this is not a fake, 592 00:37:53,200 --> 00:37:56,480 I started MATLAB with the script, 593 00:37:56,620 --> 00:38:00,040 and it just reads in both files as a vector, 594 00:38:00,160 --> 00:38:02,300 and puts the histogram on screen. 595 00:38:02,460 --> 00:38:04,320 So what you see on the left is the DRM file, 596 00:38:04,460 --> 00:38:06,660 which is pretty much equally distributed, 597 00:38:07,260 --> 00:38:09,240 and this is a pretty hard indication 598 00:38:09,240 --> 00:38:11,380 for the file content being encrypted. 599 00:38:12,210 --> 00:38:14,580 And on the right side, you see the plain file, 600 00:38:15,290 --> 00:38:16,400 which has been decrypted, 601 00:38:16,480 --> 00:38:19,580 so it's absolutely not equally distributed anymore. 602 00:38:20,640 --> 00:38:23,740 Okay, so I'm well aware that this could still be fake, 603 00:38:25,040 --> 00:38:27,580 but I can't give you a real proof, 604 00:38:27,880 --> 00:38:30,400 because it's just too dangerous. 605 00:38:33,720 --> 00:38:35,500 Okay, so the conclusion is, 606 00:38:35,620 --> 00:38:37,740 overall it's a pretty good protection, 607 00:38:37,960 --> 00:38:39,220 but it has a lot of problems. 608 00:38:39,220 --> 00:38:42,740 There's some major design issues associated with it, 609 00:38:42,820 --> 00:38:47,140 because we could bypass the whole p-code machine 610 00:38:47,140 --> 00:38:51,580 by just reacquiring our breakpoints on memory access. 611 00:38:53,000 --> 00:38:54,780 And there are also some other weaknesses, 612 00:38:56,020 --> 00:38:58,960 like for example, the very weak anti-debugging mechanisms. 613 00:39:00,680 --> 00:39:03,380 And of course, there's much room for improvements. 614 00:39:04,580 --> 00:39:06,860 The most obvious one would probably be 615 00:39:06,860 --> 00:39:09,080 to transform more native code to the p-code, 616 00:39:09,080 --> 00:39:13,740 so to avoid that the actual decryption process 617 00:39:14,190 --> 00:39:16,800 is a high-level handler, which is pretty useless. 618 00:39:18,540 --> 00:39:21,980 And you could also make the p-code machine more complex. 619 00:39:22,200 --> 00:39:23,740 You could do some nesting. 620 00:39:23,780 --> 00:39:26,780 You could have a p-code machine inside a p-code machine, 621 00:39:26,960 --> 00:39:27,900 inside, and so on. 622 00:39:29,070 --> 00:39:31,740 Or you could also have polymorphic handlers, 623 00:39:31,780 --> 00:39:33,560 a self-modifying machine, 624 00:39:33,740 --> 00:39:35,580 so the sky really is the limit. 625 00:39:37,410 --> 00:39:38,540 And well, as I said, 626 00:39:38,540 --> 00:39:40,860 the debugger detection is very weak 627 00:39:40,860 --> 00:39:43,180 and just uses some old techniques. 628 00:39:45,060 --> 00:39:50,320 Another one which could be used to improve the protection 629 00:39:50,320 --> 00:39:55,280 would be to use debug registers actually for their purpose. 630 00:39:55,940 --> 00:39:59,700 That is, the system could just let controls 631 00:39:59,700 --> 00:40:02,120 all depend on BPMs. 632 00:40:02,160 --> 00:40:04,680 So, in this way, we would have no chance 633 00:40:04,680 --> 00:40:06,860 of emulating any debug registers, 634 00:40:07,000 --> 00:40:08,060 because they would be used, 635 00:40:08,060 --> 00:40:09,140 but the protection itself. 636 00:40:09,640 --> 00:40:11,800 And well, I don't know why the guys 637 00:40:11,800 --> 00:40:13,680 developing this protection didn't do this. 638 00:40:14,700 --> 00:40:15,400 I don't know. 639 00:40:16,640 --> 00:40:18,400 Okay, so that's pretty much it. 640 00:40:19,400 --> 00:40:21,460 Thanks for your attention, and bye.