1 00:00:08,200 --> 00:00:09,340 Hopefully this will work. 2 00:00:16,860 --> 00:00:22,420 Okay, so what I'm going to talk about is root kits and also ways to detect root kits. 3 00:00:22,720 --> 00:00:26,240 I've developed a freeware tool called VICE that does that. 4 00:00:26,240 --> 00:00:32,760 So if you came to see a bunch of hookers taken away by some policemen, you're in the wrong room. 5 00:00:34,480 --> 00:00:37,780 I know, I know, the limo got broke down, you know, whatever. 6 00:00:40,140 --> 00:00:41,960 So as he said, my name is Fusinop. 7 00:00:42,680 --> 00:00:45,160 If you came to Black Hat, you know I'm also Jamie Butler. 8 00:00:45,720 --> 00:00:46,720 It's in your program. 9 00:00:47,320 --> 00:00:48,220 That's no secret. 10 00:00:48,440 --> 00:00:49,560 I'm at rootkit.com. 11 00:00:50,040 --> 00:00:52,960 Everything I discuss here you can download from rootkit.com. 12 00:00:54,040 --> 00:00:56,180 But wait until Monday or Tuesday. 13 00:00:56,240 --> 00:00:56,920 Tuesday of next week. 14 00:00:58,860 --> 00:01:03,520 The source code for all the rootkit stuff I will talk about is on rootkit.com. 15 00:01:04,040 --> 00:01:06,260 So you can have that and change it or whatever. 16 00:01:06,960 --> 00:01:11,260 VICE, the freeware tool, currently is downloadable in binary format. 17 00:01:13,580 --> 00:01:21,280 So what we're going to do, we're going to talk about hooking and how a lot of really lame rootkits hook and user land and so forth. 18 00:01:22,740 --> 00:01:25,740 Then we're going to talk about the tool VICE to detect it. 19 00:01:26,240 --> 00:01:32,920 Then we're going to talk about direct kernel object manipulation, which is incorporated into FU and a demonstration. 20 00:01:34,340 --> 00:01:35,620 Pardon my voice today. 21 00:01:35,720 --> 00:01:37,980 It's pretty dry. 22 00:01:40,040 --> 00:01:44,140 So just we'll cover a few general overview of an operating system. 23 00:01:44,380 --> 00:01:53,920 This talk applies mainly to Win32, but you could also apply all the rootkit technologies and concepts to a Linux or Spark or whatever. 24 00:01:54,380 --> 00:01:56,220 So in Win32... 25 00:01:56,240 --> 00:02:04,460 In a Win32 type of environment, there's user land, and that's supported by kernel32.dll and ntdll.dll. 26 00:02:04,860 --> 00:02:13,960 So whenever you write a program, that's the libraries you link to, and you use the functionalities exported by those DLLs. 27 00:02:15,000 --> 00:02:21,880 Once those DLLs get a hold of your request, they eventually call down to the kernel through some means we'll talk about in a moment. 28 00:02:22,380 --> 00:02:25,180 The kernel is what implements the low-level functionality. 29 00:02:28,240 --> 00:02:34,120 So it's the kernel doing all the work, kernel32 and everything is just basically a pass-through. 30 00:02:36,360 --> 00:02:37,800 So, tax scenario. 31 00:02:38,980 --> 00:02:42,540 Rootkits are not about how to exploit a box. 32 00:02:43,520 --> 00:02:54,020 There's been other talks here, FX and Alvar, and other talks, Black Hat, experts at Shellcode and so forth. 33 00:02:54,200 --> 00:02:56,220 So I won't talk about how to gain access. 34 00:02:56,240 --> 00:02:57,120 I'll talk about how to get access the first time. 35 00:02:58,180 --> 00:03:00,740 What a rootkit is for is to maintain access. 36 00:03:01,260 --> 00:03:02,800 So you want to hide your presence. 37 00:03:03,140 --> 00:03:13,420 You want a remote command and control channel that is undetectable by IDSs and by the kernel itself, and maybe intrusion prevention systems. 38 00:03:14,880 --> 00:03:19,960 Rootkits will, in the most part, for the ones I write, they'll exist in the kernel. 39 00:03:20,700 --> 00:03:22,960 So they act as part of the kernel. 40 00:03:24,720 --> 00:03:26,160 And we'll talk about why. 41 00:03:26,240 --> 00:03:28,840 And all device drivers acting as kernel can be really bad. 42 00:03:29,660 --> 00:03:33,500 Until recently, most rootkits were nothing more than a Trojan program. 43 00:03:34,420 --> 00:03:36,220 This is probably like an 80s thing. 44 00:03:36,640 --> 00:03:42,720 They would replace PS or LS or some of the other commands on the file system, 45 00:03:42,880 --> 00:03:49,560 so that when an administrator would run the command, they would get a Trojan version of the executable. 46 00:03:51,560 --> 00:03:56,220 Of course, companies would come along and, for the large part, solve this problem. 47 00:03:56,240 --> 00:04:03,880 And now, rootkits evolved to filter data by hooking functions in memory. 48 00:04:04,920 --> 00:04:07,040 This way, they could achieve the same results. 49 00:04:07,320 --> 00:04:11,240 By hooking a function, you can change what that function returned. 50 00:04:11,960 --> 00:04:16,980 So, for instance, if you're asking for a list of processes on the machine, 51 00:04:17,240 --> 00:04:22,660 by hooking, you can filter out your rogue process that you do not want displayed. 52 00:04:25,200 --> 00:04:26,220 Hooking can be done in multiple ways. 53 00:04:26,220 --> 00:04:27,100 There aren't many different places. 54 00:04:27,600 --> 00:04:29,320 The import address table is one. 55 00:04:30,280 --> 00:04:32,360 And I think we'll have a diagram of that in a moment. 56 00:04:32,740 --> 00:04:34,280 You can hook the system call table. 57 00:04:34,460 --> 00:04:35,840 You can hook the scripted table. 58 00:04:38,420 --> 00:04:40,620 Really, this is only a few places you could hook. 59 00:04:40,640 --> 00:04:42,140 There's quite a multitude. 60 00:04:44,280 --> 00:04:45,780 So, this is just a diagram. 61 00:04:46,000 --> 00:04:48,280 I don't have a light pen, so sorry. 62 00:04:48,720 --> 00:04:51,800 I can't point out the relevant features on the slide. 63 00:04:52,120 --> 00:04:53,080 But this is... 64 00:04:53,080 --> 00:04:54,840 The green represents... 65 00:04:54,840 --> 00:04:57,120 The big green box represents a program that's running. 66 00:04:58,020 --> 00:05:00,600 And it needs functionality from another DLL. 67 00:05:00,820 --> 00:05:06,360 So, it has stubs in its code called the import address table. 68 00:05:06,840 --> 00:05:09,420 When the loader loads the program into memory, 69 00:05:09,620 --> 00:05:18,020 it will set the appropriate function address for these functions that are in other DLLs in this IAT table. 70 00:05:18,240 --> 00:05:19,440 And that's a blow-up there. 71 00:05:19,520 --> 00:05:21,820 They're either exported by function name or by ordinal. 72 00:05:21,820 --> 00:05:32,120 And the 1-1-2-2-3-3-4-4 represents the address in a different DLL that that function would actually be located at. 73 00:05:34,880 --> 00:05:37,500 So, this is the normal control flow. 74 00:05:38,200 --> 00:05:40,260 Code in your program goes... 75 00:05:40,260 --> 00:05:43,100 And the application goes through the IAT. 76 00:05:43,360 --> 00:05:49,440 The IAT calls into some DLL, such as kernel 32, etc. 77 00:05:50,820 --> 00:05:51,680 You can... 78 00:05:51,680 --> 00:05:54,020 You can inject, though, a DLL into another process. 79 00:05:55,360 --> 00:05:56,740 There are a couple different means. 80 00:05:56,940 --> 00:05:57,660 We won't cover those. 81 00:05:58,100 --> 00:05:59,780 But they're well documented. 82 00:06:00,560 --> 00:06:02,300 And it's also rootkit.com. 83 00:06:02,380 --> 00:06:06,680 There's at least three different rootkits that use DLL injection to hook things. 84 00:06:08,720 --> 00:06:13,680 So, in this case, the rootkit is changing the IAT entry 85 00:06:13,680 --> 00:06:19,720 so that the program control flow changes to it instead of the original DLL. 86 00:06:22,160 --> 00:06:24,960 Now, here's an example of a system call hook. 87 00:06:25,780 --> 00:06:27,380 So, on the... 88 00:06:28,480 --> 00:06:30,520 I guess, my left... 89 00:06:32,460 --> 00:06:34,580 There's the system calls being made. 90 00:06:34,780 --> 00:06:39,980 That's an application asking the operating system to do something on its behalf. 91 00:06:40,480 --> 00:06:43,720 It passes through that magic barrier there. 92 00:06:43,860 --> 00:06:45,160 Now, it's in kernel mode. 93 00:06:45,900 --> 00:06:48,480 In kernel mode, there's a function called... 94 00:06:48,480 --> 00:06:49,520 In the kernel... 95 00:06:49,520 --> 00:06:51,200 In TS kernel, there's a function called... 96 00:06:51,200 --> 00:06:52,600 Chaos system service. 97 00:06:52,840 --> 00:06:58,760 Chaos system service will resolve the number of the function you're trying to call. 98 00:06:59,340 --> 00:07:00,700 So, for instance, like... 99 00:07:01,540 --> 00:07:04,480 ZW create key for creating a registry key. 100 00:07:04,720 --> 00:07:07,460 Maybe that's function number 3B. 101 00:07:08,720 --> 00:07:13,040 It uses that as an index into the system service descriptor table. 102 00:07:13,700 --> 00:07:16,900 And that just contains function pointers. 103 00:07:18,100 --> 00:07:18,760 Each... 104 00:07:18,760 --> 00:07:19,620 There's a blowup... 105 00:07:19,620 --> 00:07:21,400 Blowup of each table entry. 106 00:07:21,980 --> 00:07:26,400 And they're merely function pointers that are indexed by call number. 107 00:07:28,720 --> 00:07:32,000 The function is represented here. 108 00:07:33,240 --> 00:07:38,840 So, you go through the call table to the function in question with this control flow. 109 00:07:40,100 --> 00:07:45,260 Now, if you have a rootkit, obviously, you can divert that control flow to yourself. 110 00:07:45,840 --> 00:07:49,360 This is the same as a userland IAT hook. 111 00:07:49,620 --> 00:07:51,780 More or less, it's just a little bit more complicated. 112 00:07:52,300 --> 00:07:55,480 Because not as many people seem to know how to write kernel code. 113 00:07:56,100 --> 00:07:57,700 And can get some things wrong. 114 00:07:59,920 --> 00:08:03,860 This is an example of a more advanced technique where... 115 00:08:04,660 --> 00:08:09,080 After going through the system call table, it still goes to the correct function. 116 00:08:09,580 --> 00:08:11,260 Which is represented there at the top. 117 00:08:11,840 --> 00:08:15,660 However, the function's been hooked by an immediate jump. 118 00:08:16,400 --> 00:08:18,840 And the immediate jump jumps to the rootkit. 119 00:08:19,620 --> 00:08:21,700 And then the rootkit has control once again. 120 00:08:23,520 --> 00:08:25,800 This is a lot more advanced technique. 121 00:08:26,460 --> 00:08:28,540 It's sometimes hard to get correct. 122 00:08:32,380 --> 00:08:33,960 Quick overview again in case... 123 00:08:34,540 --> 00:08:37,960 This is an animated slide that represents it maybe a little bit better. 124 00:08:38,360 --> 00:08:40,900 So, kernel32.dll runs for a while. 125 00:08:41,140 --> 00:08:43,420 This function represents create file w. 126 00:08:44,040 --> 00:08:45,740 To create a file in the file system. 127 00:08:46,280 --> 00:08:48,820 It eventually calls into ntdll. 128 00:08:48,820 --> 00:08:51,380 Calling the function ntcreatefile. 129 00:08:52,400 --> 00:08:53,820 That runs for a while. 130 00:08:54,000 --> 00:08:55,980 And then it calls into the system. 131 00:08:56,580 --> 00:08:59,620 So, at each one of those places on the slide. 132 00:08:59,700 --> 00:09:01,120 You could have hooked at the beginning of the function. 133 00:09:01,480 --> 00:09:03,660 You could have hooked at where the function made the call. 134 00:09:04,260 --> 00:09:07,560 You could hook the IATs, etc. 135 00:09:09,140 --> 00:09:10,200 Once you're in the kernel. 136 00:09:11,260 --> 00:09:16,720 On Linux, the interrupt for requesting service of the kernel. 137 00:09:16,980 --> 00:09:18,060 Is an interrupt baby. 138 00:09:18,060 --> 00:09:20,820 On Windows, it's nt2e. 139 00:09:25,580 --> 00:09:27,880 So, if you hit nt2e. 140 00:09:27,980 --> 00:09:31,700 Then that's when you'll jump to a chaos system service. 141 00:09:31,900 --> 00:09:35,300 Which will resolve the number of the system call that you wanted. 142 00:09:35,800 --> 00:09:38,860 And also where your user parameters are and so forth. 143 00:09:41,160 --> 00:09:42,360 Just for reference. 144 00:09:43,040 --> 00:09:46,140 In the EAX register is the system call number. 145 00:09:48,500 --> 00:09:52,040 In this case, it would correspond to ntcreatefile. 146 00:09:52,800 --> 00:09:57,980 And in EDX is a pointer to the user supplied parameters. 147 00:09:59,840 --> 00:10:01,320 So, once in the system call table. 148 00:10:01,540 --> 00:10:02,700 Again, it's just an address. 149 00:10:03,600 --> 00:10:06,500 And it jumps off to the real function in question. 150 00:10:07,700 --> 00:10:08,960 This slide is an anime. 151 00:10:09,080 --> 00:10:11,800 But you could have hooked ntcreatefile. 152 00:10:12,040 --> 00:10:13,880 By overwriting push EBP. 153 00:10:14,140 --> 00:10:15,860 Move ESP into EBP. 154 00:10:17,240 --> 00:10:18,040 And XOR. 155 00:10:18,900 --> 00:10:20,680 You would have to at least overwrite that many. 156 00:10:20,760 --> 00:10:23,100 Maybe the push also. 157 00:10:23,860 --> 00:10:26,260 Because a jump is a 5 byte instruction. 158 00:10:26,860 --> 00:10:28,020 It's at least 5 bytes. 159 00:10:28,880 --> 00:10:31,560 So, you have to overwrite at least the first 5 bytes of the function. 160 00:10:34,800 --> 00:10:37,560 So, on rootkit.com there's a whole lot of rootkits. 161 00:10:37,760 --> 00:10:39,860 That are user mode rootkits. 162 00:10:40,860 --> 00:10:44,520 And user mode rootkits aren't the way to go if you want to write a rootkit. 163 00:10:44,520 --> 00:10:47,600 Because they're fairly trivial to find. 164 00:10:48,540 --> 00:10:51,000 By hooking the IET and so forth. 165 00:10:51,140 --> 00:10:55,160 They leave a really big footprint that you can look for. 166 00:10:55,880 --> 00:10:58,780 Because you know the range of the DLL and so forth. 167 00:10:59,040 --> 00:11:02,800 So, you can look for jumps outside of an acceptable range. 168 00:11:03,000 --> 00:11:04,420 And then flag those. 169 00:11:07,300 --> 00:11:08,920 So, vice was to take care of that. 170 00:11:10,880 --> 00:11:12,760 Also, hooking even in the curls. 171 00:11:12,760 --> 00:11:15,900 Usually it's a little bit old school now. 172 00:11:16,000 --> 00:11:18,400 It's been around for at least 6 years. 173 00:11:18,500 --> 00:11:19,920 Probably in public source stuff. 174 00:11:20,380 --> 00:11:22,920 And maybe in the Linux world even longer than that. 175 00:11:22,960 --> 00:11:23,920 I'm not familiar with that. 176 00:11:25,680 --> 00:11:27,760 So, vice detects kernel hooks. 177 00:11:28,460 --> 00:11:29,620 132 API hooks. 178 00:11:29,740 --> 00:11:31,140 And inline function patching. 179 00:11:31,560 --> 00:11:35,840 What I mean by that is when you would overwrite the first 5 bytes of a function. 180 00:11:36,260 --> 00:11:37,800 That's inline function patching. 181 00:11:38,860 --> 00:11:40,520 Also, the not only slide is. 182 00:11:40,520 --> 00:11:42,300 If the driver. 183 00:11:42,580 --> 00:11:46,540 Device drivers in memory have a table of function pointers also. 184 00:11:47,240 --> 00:11:48,460 So, there's. 185 00:11:49,140 --> 00:11:50,920 Whenever you talk to a driver. 186 00:11:51,060 --> 00:11:54,060 You're talking through our request packet. 187 00:11:54,460 --> 00:11:58,200 So, like when you use netstat to list all the available ports. 188 00:11:58,680 --> 00:12:03,440 You're talking actually under the hood to tcpip.sys. 189 00:12:03,620 --> 00:12:09,480 And you're passing it rp underscore mj underscore query. 190 00:12:10,260 --> 00:12:13,120 That's one of the ERPs you'll pass down to the driver. 191 00:12:13,500 --> 00:12:16,340 Well, there's a function pointer within the driver object. 192 00:12:16,680 --> 00:12:18,900 That describes which function handles. 193 00:12:19,020 --> 00:12:22,020 Or the address of the function that handles that particular ERP. 194 00:12:22,680 --> 00:12:24,780 See, you can also hook there. 195 00:12:25,160 --> 00:12:28,560 However, I haven't currently come across any public root kits. 196 00:12:28,920 --> 00:12:30,840 That do that in the Windows world. 197 00:12:30,940 --> 00:12:35,080 And I'm doubting it's done much in the Linux world. 198 00:12:35,140 --> 00:12:36,480 I'm not sure of the format. 199 00:12:36,560 --> 00:12:37,480 The LKM structure. 200 00:12:37,800 --> 00:12:37,980 Okay. 201 00:12:41,860 --> 00:12:44,700 So, I'll try to get to a device demonstration now. 202 00:12:45,120 --> 00:12:46,960 And show you how it works. 203 00:12:47,020 --> 00:12:49,240 And that you can use it when you go home. 204 00:13:13,980 --> 00:13:16,100 Okay, well, it's on my key. 205 00:13:16,180 --> 00:13:18,040 I'll try to show it in a minute if I have extra time. 206 00:13:18,560 --> 00:13:20,040 The key's not installed right now. 207 00:13:20,400 --> 00:13:24,740 So, to save the day, I have backup slides. 208 00:13:27,020 --> 00:13:29,300 So, here's Vice versus Hacker Defender. 209 00:13:30,020 --> 00:13:34,500 Hacker Defender is a very good root kit that's on rootkit.com. 210 00:13:34,860 --> 00:13:37,000 I believe it was written by Holy Father. 211 00:13:37,660 --> 00:13:39,460 And he's very good. 212 00:13:39,460 --> 00:13:39,920 He's very knowledgeable. 213 00:13:39,920 --> 00:13:43,080 I've discussed rootkit stuff with him in email. 214 00:13:45,200 --> 00:13:46,220 Here's the vice output. 215 00:13:46,900 --> 00:13:48,880 I'm not sure if it's completely readable. 216 00:13:49,060 --> 00:13:50,800 But all these slides should be on your CD also. 217 00:13:51,900 --> 00:13:54,180 The things there with the embers glue. 218 00:13:54,840 --> 00:13:55,760 Little icon. 219 00:13:56,100 --> 00:13:57,000 You'll see it's hooking. 220 00:13:57,360 --> 00:13:59,640 There's something hooking kernel32.dll. 221 00:14:00,460 --> 00:14:06,980 And actually, that turns out to be, in this case, way up top of the screen, is NTDLL. 222 00:14:07,440 --> 00:14:08,620 So, you might say. 223 00:14:08,620 --> 00:14:10,120 Well, NTDLL is not a rootkit. 224 00:14:10,320 --> 00:14:11,240 That's correct. 225 00:14:11,440 --> 00:14:19,620 But the way it's used in the system, it actually hooks other Windows APIs occasionally. 226 00:14:20,180 --> 00:14:22,500 And so, therefore, it is a hook. 227 00:14:22,760 --> 00:14:25,360 And that's what vice catches. 228 00:14:26,350 --> 00:14:28,700 So, the thing with the Swiss Army knife. 229 00:14:28,920 --> 00:14:30,140 A little icon. 230 00:14:30,500 --> 00:14:35,160 That's all the functions that vice called Hacker Defender hooking. 231 00:14:35,360 --> 00:14:36,400 When possible, 232 00:14:36,400 --> 00:14:43,580 vice will output where on the file system you can find the hooking module in question. 233 00:14:44,000 --> 00:14:50,660 So, that will allow you to go to the file system and delete that bad DLL or whatever off of the system. 234 00:14:51,260 --> 00:14:54,500 In this case, it couldn't resolve Hacker Defender. 235 00:14:54,620 --> 00:14:57,480 Vice is, you know, a project still in the works. 236 00:14:57,700 --> 00:15:01,820 And maybe in the future, we will be able to resolve that on the file system. 237 00:15:02,860 --> 00:15:06,220 So, you can see it hooking things like create processes. 238 00:15:06,400 --> 00:15:07,060 And so on and so forth. 239 00:15:07,800 --> 00:15:10,460 It also gives you the address and memory. 240 00:15:11,000 --> 00:15:11,720 Vice does. 241 00:15:11,800 --> 00:15:13,900 So, if you wanted to go and reverse engineer it yourself. 242 00:15:14,260 --> 00:15:16,760 And figure out exactly what their function does. 243 00:15:17,120 --> 00:15:18,060 You can do this. 244 00:15:20,280 --> 00:15:21,920 Here's vice versus vinequish. 245 00:15:22,460 --> 00:15:26,280 Vinequish is another popular rootkit at rootkit.com. 246 00:15:28,060 --> 00:15:29,700 And, enough said about that. 247 00:15:30,740 --> 00:15:33,600 How many read KDM's paper on FRAC 62? 248 00:15:34,800 --> 00:15:35,280 Anyone? 249 00:15:36,840 --> 00:15:37,440 Okay. 250 00:15:37,560 --> 00:15:41,820 He stated that vice could not catch his rootkit called MT Illusion. 251 00:15:42,020 --> 00:15:45,900 Which is an entirely userland rootkit. 252 00:15:46,600 --> 00:15:48,800 This was correct at the time he tested. 253 00:15:49,240 --> 00:15:51,440 There was a bug in vice. 254 00:15:51,440 --> 00:15:57,340 And vice had not had any development on it since it was first written in mid-April. 255 00:15:57,820 --> 00:15:59,680 However, now that bug is fixed. 256 00:16:00,740 --> 00:16:03,720 And as you can see, it catches MT Illusion. 257 00:16:05,860 --> 00:16:09,260 What's noteworthy here is not only did it catch MT Illusion. 258 00:16:09,600 --> 00:16:12,280 It also lists where on the file system it is. 259 00:16:12,700 --> 00:16:14,000 So you can go delete it. 260 00:16:18,340 --> 00:16:22,480 So that was sort of the rootkit spin and hooking. 261 00:16:23,080 --> 00:16:25,600 We talked about how hooking is detectable. 262 00:16:26,340 --> 00:16:32,180 And now we're going to go into a little bit more of what consumers are currently doing. 263 00:16:32,180 --> 00:16:35,580 In the world of, you know, trying to prevent viruses. 264 00:16:35,600 --> 00:16:38,500 Trying to prevent rootkits and so on and so forth. 265 00:16:39,340 --> 00:16:42,200 Everyone's running to third party personal firewalls. 266 00:16:42,300 --> 00:16:45,260 And also host-based intrusion prevention systems. 267 00:16:52,740 --> 00:16:54,140 So what are HIDS? 268 00:16:54,140 --> 00:16:56,620 HIDS are host-based intrusion detection system. 269 00:16:57,000 --> 00:16:59,240 HIP's being host-based intrusion prevention system. 270 00:17:00,240 --> 00:17:01,440 What are they there for? 271 00:17:01,980 --> 00:17:05,120 They're there to detect what processes are running on the system. 272 00:17:05,340 --> 00:17:07,180 Maybe if a new process is started. 273 00:17:07,760 --> 00:17:11,260 Block access, you know, to things like netcat and so forth from running. 274 00:17:12,260 --> 00:17:14,520 What files are created or deleted or modified. 275 00:17:14,740 --> 00:17:16,520 That may be important to a HIP's. 276 00:17:16,760 --> 00:17:22,080 Like don't let anyone write to the WinMT or Windows system 32 directory. 277 00:17:22,560 --> 00:17:24,880 Because that's probably going to be a bad thing. 278 00:17:26,440 --> 00:17:30,140 HIP's also keep track of network connections made. 279 00:17:30,140 --> 00:17:32,100 And possibly deny those connections. 280 00:17:32,560 --> 00:17:36,160 And they try to do a little bit with privilege escalation. 281 00:17:37,540 --> 00:17:39,660 And they look for buffer overflows and so forth. 282 00:17:40,800 --> 00:17:43,680 However, for a lot of these different pieces of functionality. 283 00:17:44,460 --> 00:17:48,820 HIP's and the current security products rely on the operating system itself. 284 00:17:49,480 --> 00:17:53,640 So if you lie to the operating system, you lie to the HIP's. 285 00:17:56,120 --> 00:18:00,120 Here's some different functionality that's built into the operating system itself. 286 00:18:00,120 --> 00:18:01,940 For instance, today they allow HIP's to work. 287 00:18:03,880 --> 00:18:06,840 If it allows the HIP's to work, it can also probably... 288 00:18:06,840 --> 00:18:12,220 You could use this as a starting point to where to look to try to unlink a HIP's. 289 00:18:12,460 --> 00:18:14,020 For instance, in your kernel. 290 00:18:14,620 --> 00:18:18,520 So you can register OS provided callback functions. 291 00:18:19,000 --> 00:18:23,940 For instance, if you want to be notified every time a process is created. 292 00:18:24,340 --> 00:18:28,820 You can register an address to be called in that case. 293 00:18:28,820 --> 00:18:29,840 And the kernel will do so. 294 00:18:30,500 --> 00:18:32,200 That works for threads also. 295 00:18:33,360 --> 00:18:34,780 Images loaded into memory. 296 00:18:35,100 --> 00:18:40,800 There's all these different pieces that HIP's use to detect new things coming into the kernel. 297 00:18:40,880 --> 00:18:43,000 Or coming into the process listing. 298 00:18:43,920 --> 00:18:45,780 You can hook these... 299 00:18:45,780 --> 00:18:47,600 You could remove... 300 00:18:47,600 --> 00:18:51,060 These are nothing more than a linked list of functions to call. 301 00:18:51,380 --> 00:18:55,800 You could remove a HIP's product from that linked list probably. 302 00:18:56,140 --> 00:18:57,600 Without a whole lot of problems. 303 00:19:02,160 --> 00:19:04,900 Some HIP's actually hook the system call table. 304 00:19:05,680 --> 00:19:08,820 You have to do that especially on Windows if you want to... 305 00:19:09,660 --> 00:19:12,300 If you want to filter on registry key access. 306 00:19:12,800 --> 00:19:15,480 Because there's no easily... 307 00:19:16,240 --> 00:19:20,340 There's a userland API that you can call for a callback when a registry key changes. 308 00:19:20,500 --> 00:19:21,680 Or any of its children. 309 00:19:22,220 --> 00:19:24,580 But it doesn't provide you much useful details. 310 00:19:24,720 --> 00:19:26,160 It just says, hey, something changed. 311 00:19:26,960 --> 00:19:27,480 And... 312 00:19:27,480 --> 00:19:31,820 You would have to reparse all the keys to figure out exactly what it was that changed. 313 00:19:32,240 --> 00:19:35,660 And therefore you'd have to sort of keep state like before and after. 314 00:19:36,680 --> 00:19:37,820 That's not very useful. 315 00:19:38,180 --> 00:19:42,220 So HIP's for the most part just hook the system call table directly. 316 00:19:44,260 --> 00:19:47,380 HIP's can hook userland API functions. 317 00:19:48,340 --> 00:19:55,920 How many saw the FRAC article on bypassing third party Windows buffer overflow protection? 318 00:19:55,920 --> 00:20:01,160 Okay, that was done by myself and two other anonymous co-authors. 319 00:20:01,940 --> 00:20:03,140 Who I'd like to thank. 320 00:20:04,280 --> 00:20:05,680 And they know who they are. 321 00:20:07,460 --> 00:20:08,540 So anyway... 322 00:20:09,280 --> 00:20:11,800 Some products were hooking the userland APIs. 323 00:20:12,420 --> 00:20:20,800 And we wrote some shellcode and so forth that totally bypassed their implementation of buffer overflow protection at the API level. 324 00:20:21,380 --> 00:20:23,500 And then you can query the kernel of course. 325 00:20:23,760 --> 00:20:25,220 So if you want to... 326 00:20:26,660 --> 00:20:31,000 Know what network connections are open, you can query the kernel and it'll tell you. 327 00:20:33,520 --> 00:20:36,620 Well, there's a problem with a lot of these HIP's designs. 328 00:20:37,080 --> 00:20:40,880 And it goes back to the FRAC article really. 329 00:20:41,000 --> 00:20:45,040 It requires that they be on the execution path of any malicious code. 330 00:20:45,380 --> 00:20:48,240 And they have to know where that execution path would be ahead of time. 331 00:20:49,320 --> 00:20:49,760 So... 332 00:20:51,200 --> 00:20:52,920 There's no reason that... 333 00:20:52,920 --> 00:20:58,600 We have to use the APIs in the kernel or even in userland. 334 00:20:58,800 --> 00:21:02,360 So the ones that we know that they're watching, we don't use those APIs. 335 00:21:02,860 --> 00:21:10,860 And I'll introduce Deacom in a second, which uses absolutely no APIs to make its changes. 336 00:21:11,380 --> 00:21:16,560 It may use some APIs once in a while to gather information, but... 337 00:21:17,180 --> 00:21:20,440 This is really benign information that would never be blocked anyway. 338 00:21:21,820 --> 00:21:22,900 So let's talk about... 339 00:21:22,920 --> 00:21:24,260 Operating system design quickly. 340 00:21:26,880 --> 00:21:31,740 Intel has four privilege levels, or four rings as you see here demonstrated. 341 00:21:33,440 --> 00:21:38,660 However, Microsoft and other OS vendors do not use all four of these rings. 342 00:21:38,820 --> 00:21:39,640 They only use two. 343 00:21:39,980 --> 00:21:43,040 There's ring zero of course, which is completely privilege code. 344 00:21:43,640 --> 00:21:47,100 Which is the kernel itself for device drivers or LKMs. 345 00:21:47,680 --> 00:21:49,020 Then there's ring three. 346 00:21:49,560 --> 00:21:51,520 Ring three is all applications. 347 00:21:53,560 --> 00:21:55,880 So when you're running in ring three... 348 00:21:57,600 --> 00:21:58,640 For instance... 349 00:22:00,000 --> 00:22:01,440 Ring three is just ring three. 350 00:22:01,500 --> 00:22:05,560 Like the HIPS doesn't have any more privilege than you do at that point. 351 00:22:05,800 --> 00:22:08,080 If it's only implemented at ring three. 352 00:22:08,340 --> 00:22:13,340 Which is the case of some of these 132 buffer overflow protection mechanisms. 353 00:22:14,240 --> 00:22:18,200 Ring zero, you have access to all of kernel memory. 354 00:22:18,820 --> 00:22:20,920 So everything that the kernel uses... 355 00:22:20,920 --> 00:22:22,780 Like objects to keep track. 356 00:22:23,000 --> 00:22:24,200 The kernel is more or less a... 357 00:22:24,200 --> 00:22:25,940 You know, it's a big accounting arm. 358 00:22:26,200 --> 00:22:28,180 So it's keeping track of all the processes. 359 00:22:28,540 --> 00:22:30,620 All the ports and so forth. 360 00:22:30,860 --> 00:22:33,960 And it does this in structures that it calls... 361 00:22:33,960 --> 00:22:35,540 That Microsoft calls objects. 362 00:22:35,920 --> 00:22:40,440 So these are kernel objects, not to be confused with C++ objects. 363 00:22:42,620 --> 00:22:46,340 So once you have this low separation of powers... 364 00:22:46,340 --> 00:22:47,460 There's only two privilege levels. 365 00:22:48,180 --> 00:22:50,300 Every single device driver... 366 00:22:50,300 --> 00:22:53,380 Has access to all of these accounting objects... 367 00:22:53,380 --> 00:22:54,660 That the kernel has access to. 368 00:22:56,300 --> 00:22:59,240 Therefore, you can modify it just as much as the kernel can. 369 00:22:59,600 --> 00:23:02,160 You just have to be very careful how you do so. 370 00:23:02,420 --> 00:23:04,260 You have to understand what the structures are. 371 00:23:04,860 --> 00:23:06,020 How to find them. 372 00:23:06,080 --> 00:23:06,760 What they do. 373 00:23:07,200 --> 00:23:09,400 And how the kernel expects them to look. 374 00:23:10,300 --> 00:23:12,960 So if you don't understand those important details... 375 00:23:12,960 --> 00:23:16,120 You may modify an object in memory and cause a blue screen. 376 00:23:18,320 --> 00:23:19,420 There are so many... 377 00:23:20,300 --> 00:23:21,140 There are third-party device drivers. 378 00:23:21,360 --> 00:23:23,120 I mean, there's your printer drivers. 379 00:23:23,280 --> 00:23:24,220 Your fax drivers. 380 00:23:24,420 --> 00:23:25,260 All these different things. 381 00:23:27,780 --> 00:23:31,380 And there really should be different levels of protection between the two. 382 00:23:31,700 --> 00:23:33,320 Between the kernel and the drivers. 383 00:23:34,880 --> 00:23:37,940 So the next generation of rootkit technology... 384 00:23:37,940 --> 00:23:39,280 Is DCOM. 385 00:23:39,500 --> 00:23:42,040 It's a play on, obviously, Microsoft's terminology. 386 00:23:42,600 --> 00:23:45,100 But in this case, direct kernel object manipulation. 387 00:23:46,100 --> 00:23:47,320 So what does it do? 388 00:23:48,000 --> 00:23:50,040 It modifies objects... 389 00:23:50,300 --> 00:23:51,340 Directly in memory. 390 00:23:51,880 --> 00:23:53,460 Never going through APIs. 391 00:23:54,100 --> 00:23:56,320 So there's well-known APIs to... 392 00:23:57,140 --> 00:24:01,740 For instance, add a SID to a token in a Windows process. 393 00:24:03,160 --> 00:24:09,240 Well, first of all, the kernel is going to see if you have the appropriate privilege to add that SID. 394 00:24:09,420 --> 00:24:10,900 And it may stop you there. 395 00:24:11,500 --> 00:24:18,720 Also, the HIPs or other third-parties may wrap around that function flow. 396 00:24:18,940 --> 00:24:20,100 The function control flow. 397 00:24:20,300 --> 00:24:22,140 And try to intercept that call. 398 00:24:22,520 --> 00:24:23,800 And limit you there. 399 00:24:24,520 --> 00:24:28,020 But if you write just directly to the memory, there's nothing to stop you. 400 00:24:31,660 --> 00:24:34,980 So you can use DCOM to hide a process. 401 00:24:35,240 --> 00:24:36,340 Add a privilege to a token. 402 00:24:36,640 --> 00:24:37,980 Add groups to tokens. 403 00:24:38,540 --> 00:24:42,360 A cool application is to fake out the Windows Event Viewer. 404 00:24:42,740 --> 00:24:45,820 So that if a user... 405 00:24:46,580 --> 00:24:49,440 I should say, if a process spawns another process... 406 00:24:49,440 --> 00:24:50,660 Such as Netcat. 407 00:24:51,100 --> 00:24:55,800 If the administrator has detailed process logging turned on... 408 00:24:56,130 --> 00:24:58,580 In the Windows Event Viewer, they will see... 409 00:24:59,440 --> 00:25:02,400 An event that says that administrator... 410 00:25:02,400 --> 00:25:04,500 Or whoever you're logged in as... 411 00:25:04,500 --> 00:25:05,900 You know, just started... 412 00:25:06,390 --> 00:25:08,200 CMD or RegEdit32 or whatever. 413 00:25:09,840 --> 00:25:10,620 Well... 414 00:25:11,410 --> 00:25:13,140 If you change your token... 415 00:25:13,140 --> 00:25:15,580 To look like someone else's... 416 00:25:15,580 --> 00:25:17,620 Just by changing a couple bytes... 417 00:25:17,620 --> 00:25:18,520 Then... 418 00:25:18,520 --> 00:25:20,240 The administrator will be thrown off. 419 00:25:20,580 --> 00:25:21,800 Because it'll look like... 420 00:25:21,800 --> 00:25:23,320 You can make it look like system did it. 421 00:25:23,720 --> 00:25:25,800 So system just spawned Netcat. 422 00:25:26,360 --> 00:25:29,080 Now obviously that's going to be a red flag to any... 423 00:25:29,920 --> 00:25:31,080 Halfway competent administrator. 424 00:25:32,120 --> 00:25:34,660 However, it's not going to point at possibly... 425 00:25:34,660 --> 00:25:36,960 The user account that you subverted. 426 00:25:37,380 --> 00:25:40,260 It's going to be a red herring that they're going to have to chase... 427 00:25:40,260 --> 00:25:43,520 For a couple weeks probably before they really figure out what happened. 428 00:25:44,120 --> 00:25:45,800 And maybe they'll never figure it out. 429 00:25:46,940 --> 00:25:47,380 So... 430 00:25:47,380 --> 00:25:48,260 Another thing of... 431 00:25:48,260 --> 00:25:49,840 Decon, you could use it to hide ports. 432 00:25:50,380 --> 00:25:51,340 Currently the... 433 00:25:51,340 --> 00:25:53,260 FU rootkit does not hide ports. 434 00:25:53,740 --> 00:25:55,040 But you can do it. 435 00:25:57,900 --> 00:25:58,460 So... 436 00:25:58,460 --> 00:26:00,400 Obviously the implications of hidden processes. 437 00:26:00,920 --> 00:26:02,720 The hidden process can have... 438 00:26:03,300 --> 00:26:04,640 Potentially full control of the system. 439 00:26:04,840 --> 00:26:05,840 There's no accountability. 440 00:26:06,700 --> 00:26:07,820 It defeats... 441 00:26:08,380 --> 00:26:08,800 The... 442 00:26:09,380 --> 00:26:11,060 Heads and hips type of paradigm. 443 00:26:11,760 --> 00:26:12,320 And... 444 00:26:12,320 --> 00:26:14,340 It can skew the results of forensics. 445 00:26:14,780 --> 00:26:16,360 It all depends on how... 446 00:26:17,380 --> 00:26:18,500 How advanced your forensics are. 447 00:26:18,800 --> 00:26:20,140 But you only have to... 448 00:26:20,780 --> 00:26:21,240 Be... 449 00:26:21,240 --> 00:26:22,940 Overcome the slowest... 450 00:26:24,300 --> 00:26:25,000 Forensic tools. 451 00:26:25,200 --> 00:26:26,200 For the most case. 452 00:26:28,560 --> 00:26:31,080 So how would you go about hiding a process in the Windows kernel? 453 00:26:31,660 --> 00:26:32,260 Here's a... 454 00:26:33,460 --> 00:26:35,400 Here's a picture of how the objects look. 455 00:26:35,660 --> 00:26:36,400 In memory. 456 00:26:41,680 --> 00:26:42,140 The... 457 00:26:42,140 --> 00:26:43,880 The kernel has a... 458 00:26:44,460 --> 00:26:45,540 Processor control block. 459 00:26:47,580 --> 00:26:49,220 It's represented there at the top. 460 00:26:49,560 --> 00:26:51,720 Within there is three key pointers. 461 00:26:52,260 --> 00:26:53,620 One is to the current thread. 462 00:26:53,700 --> 00:26:54,560 One is to the next thread. 463 00:26:54,660 --> 00:26:55,560 And one is to the idle thread. 464 00:26:56,200 --> 00:26:58,020 So you need to find... 465 00:26:58,020 --> 00:26:59,260 Your current thread. 466 00:26:59,400 --> 00:27:01,380 Because that's going to lead you to your current process. 467 00:27:02,500 --> 00:27:04,500 So you go to the processor control block. 468 00:27:04,680 --> 00:27:06,260 Follow that pointer to the current thread. 469 00:27:06,900 --> 00:27:09,000 That's represented there by the E-thread block. 470 00:27:09,120 --> 00:27:10,420 That's sort of in the middle of the diagram. 471 00:27:11,280 --> 00:27:12,640 The E-thread block... 472 00:27:12,640 --> 00:27:12,980 Or... 473 00:27:12,980 --> 00:27:14,880 Object contains a K-thread object. 474 00:27:15,900 --> 00:27:17,360 Completely embedded within it. 475 00:27:17,380 --> 00:27:19,040 At the beginning of the E-thread object. 476 00:27:19,480 --> 00:27:20,940 And that contains a pointer. 477 00:27:21,460 --> 00:27:23,940 That leads to the E-process block. 478 00:27:24,620 --> 00:27:26,720 Every process in a Windows... 479 00:27:26,720 --> 00:27:29,520 Operating system has to have at least one thread. 480 00:27:30,100 --> 00:27:32,240 And it has an E-process block. 481 00:27:33,280 --> 00:27:33,820 So... 482 00:27:34,380 --> 00:27:35,680 These structures are... 483 00:27:35,680 --> 00:27:36,880 For the most part undocumented. 484 00:27:37,960 --> 00:27:40,560 Some of them now are becoming a little bit more documented. 485 00:27:41,020 --> 00:27:43,900 However they change a lot between versions of service packs. 486 00:27:45,600 --> 00:27:47,360 And also major versions of the object. 487 00:27:47,360 --> 00:27:47,760 In the operating system. 488 00:27:49,300 --> 00:27:50,740 So you have to do... 489 00:27:50,740 --> 00:27:52,400 At first when I did this... 490 00:27:52,400 --> 00:27:53,600 Two years ago. 491 00:27:53,700 --> 00:27:54,600 It was all reverse engineering. 492 00:27:55,280 --> 00:27:56,780 Now you can use WinDebug. 493 00:27:57,580 --> 00:27:59,180 Load up the symbols appropriately. 494 00:27:59,420 --> 00:28:01,140 For whatever version of the kernel you're using. 495 00:28:01,660 --> 00:28:02,140 Type... 496 00:28:02,140 --> 00:28:02,800 DT... 497 00:28:02,800 --> 00:28:03,320 Space... 498 00:28:03,320 --> 00:28:04,020 MT... 499 00:28:04,780 --> 00:28:05,260 Bang... 500 00:28:05,840 --> 00:28:06,320 Underscore... 501 00:28:06,320 --> 00:28:07,380 Object name. 502 00:28:08,320 --> 00:28:10,320 And if you don't know what the object name is. 503 00:28:10,380 --> 00:28:11,520 You can wildcard it. 504 00:28:11,620 --> 00:28:13,000 To try to narrow it down. 505 00:28:13,500 --> 00:28:16,680 I will tell you that not all the object numbers are documented. 506 00:28:16,680 --> 00:28:18,760 Like Microsoft may just say. 507 00:28:18,900 --> 00:28:19,600 Oh it's a... 508 00:28:19,600 --> 00:28:20,920 It's a P void. 509 00:28:21,620 --> 00:28:24,720 And so you don't know what it actually leads to. 510 00:28:24,980 --> 00:28:27,380 And of course that takes a bit more time to figure out. 511 00:28:28,120 --> 00:28:29,640 So within the E-process block. 512 00:28:30,760 --> 00:28:31,640 There's a... 513 00:28:33,120 --> 00:28:35,240 There's a list entry structure. 514 00:28:35,640 --> 00:28:37,100 It contains two pointers. 515 00:28:37,440 --> 00:28:39,000 The first one is called a Flink. 516 00:28:39,380 --> 00:28:41,480 And the second one is called a Blink. 517 00:28:41,740 --> 00:28:43,480 A Flink is a forward link. 518 00:28:43,780 --> 00:28:45,560 And a Blink is a backward link. 519 00:28:45,560 --> 00:28:48,600 So this list of E-processes. 520 00:28:48,820 --> 00:28:50,860 If you would just keep following the Flinks. 521 00:28:51,180 --> 00:28:52,400 It's completely circular. 522 00:28:53,200 --> 00:28:55,140 Also if you just keep following. 523 00:28:55,900 --> 00:28:57,400 Well you'd have to do like. 524 00:28:58,160 --> 00:28:59,080 Dereference Blink. 525 00:28:59,080 --> 00:29:00,060 And then add four. 526 00:29:00,520 --> 00:29:02,960 To get to the link behind you. 527 00:29:03,120 --> 00:29:04,460 And keep following the chain. 528 00:29:04,540 --> 00:29:04,860 That way. 529 00:29:05,120 --> 00:29:07,380 You could go backwards through the list also. 530 00:29:08,860 --> 00:29:10,240 So if you want to know how to process. 531 00:29:10,780 --> 00:29:13,200 The kernel processor control block. 532 00:29:13,520 --> 00:29:15,180 Is located at a fixed address. 533 00:29:15,560 --> 00:29:17,220 Also if you don't trust that. 534 00:29:17,280 --> 00:29:18,980 Because I haven't verified that since 2000. 535 00:29:20,060 --> 00:29:21,580 You can use the FS register. 536 00:29:22,020 --> 00:29:23,720 To always get the address. 537 00:29:23,800 --> 00:29:24,480 Of that kernel. 538 00:29:26,200 --> 00:29:27,860 Kernel processor control block. 539 00:29:28,780 --> 00:29:29,300 Also. 540 00:29:29,820 --> 00:29:31,400 Within there we talked about. 541 00:29:31,660 --> 00:29:33,680 That you can get the current thread running. 542 00:29:34,240 --> 00:29:36,000 And there's the assembly command. 543 00:29:36,560 --> 00:29:37,080 Well. 544 00:29:37,280 --> 00:29:39,160 You would just move that into like. 545 00:29:39,180 --> 00:29:40,600 EAX the FS colon. 546 00:29:41,980 --> 00:29:43,020 Bracket 124. 547 00:29:43,780 --> 00:29:45,140 And that would get you to. 548 00:29:45,560 --> 00:29:45,960 The E thread. 549 00:29:46,320 --> 00:29:48,280 The E thread takes you to the K thread. 550 00:29:48,780 --> 00:29:51,100 And the K thread takes you to the E process block. 551 00:29:56,040 --> 00:29:57,200 So to hide a process. 552 00:29:57,640 --> 00:29:58,940 All you need to do is. 553 00:29:59,000 --> 00:30:01,000 Change the E process block in front of you. 554 00:30:01,340 --> 00:30:03,600 To point to the E process block behind you. 555 00:30:03,920 --> 00:30:05,920 And the E process block behind you. 556 00:30:06,140 --> 00:30:08,320 To point to the E process block in front of you. 557 00:30:09,940 --> 00:30:10,800 And I think. 558 00:30:10,820 --> 00:30:12,000 I have a demonstration of that. 559 00:30:12,160 --> 00:30:12,900 Or a graphic. 560 00:30:13,660 --> 00:30:14,400 So here. 561 00:30:15,560 --> 00:30:16,500 We don't have a pointer. 562 00:30:17,120 --> 00:30:19,540 But we're trying to hide the current process. 563 00:30:20,220 --> 00:30:21,300 So if you just. 564 00:30:21,620 --> 00:30:23,480 It's the E process block. 565 00:30:23,560 --> 00:30:24,240 That's in the center. 566 00:30:25,180 --> 00:30:27,160 So you would want to modify the flink. 567 00:30:27,580 --> 00:30:28,580 Behind us. 568 00:30:28,700 --> 00:30:31,480 To point to the flink in front of us. 569 00:30:31,980 --> 00:30:33,420 And that's represented there. 570 00:30:34,680 --> 00:30:35,700 Once you do that. 571 00:30:35,760 --> 00:30:36,840 Half the game is done. 572 00:30:37,120 --> 00:30:38,740 Now you have to change the. 573 00:30:39,120 --> 00:30:40,820 The blink in front of us. 574 00:30:41,040 --> 00:30:43,680 To point to the flink behind us. 575 00:30:44,600 --> 00:30:45,280 Like that. 576 00:30:46,180 --> 00:30:47,780 So you just tell your neighbors. 577 00:30:47,960 --> 00:30:48,340 Hey. 578 00:30:49,160 --> 00:30:49,840 You know. 579 00:30:49,880 --> 00:30:50,460 Point around us. 580 00:30:52,220 --> 00:30:54,000 So why does this continue to run? 581 00:30:56,100 --> 00:30:57,280 Well it turns out. 582 00:30:57,320 --> 00:30:57,840 That the. 583 00:30:58,700 --> 00:31:01,360 The scheduler in Windows is extremely advanced. 584 00:31:02,080 --> 00:31:02,620 And. 585 00:31:04,280 --> 00:31:05,440 It's thread based. 586 00:31:06,520 --> 00:31:07,360 But however. 587 00:31:07,520 --> 00:31:08,840 The reporting mechanisms. 588 00:31:08,960 --> 00:31:10,060 Are process based. 589 00:31:10,660 --> 00:31:13,200 So you can edit this E process block. 590 00:31:13,700 --> 00:31:15,220 And all your threads. 591 00:31:15,560 --> 00:31:16,040 Will get scheduled. 592 00:31:16,180 --> 00:31:18,980 Because they're off in their little thread queues. 593 00:31:19,420 --> 00:31:20,740 And so they'll continue. 594 00:31:21,120 --> 00:31:21,800 To run. 595 00:31:26,460 --> 00:31:27,480 I'll just cover this. 596 00:31:27,540 --> 00:31:28,280 Really quickly. 597 00:31:28,420 --> 00:31:30,420 Because Linux isn't my strong point. 598 00:31:30,500 --> 00:31:31,860 And I haven't looked at it since it came out. 599 00:31:31,900 --> 00:31:32,860 With the new threading model. 600 00:31:33,360 --> 00:31:35,000 In Linux 2.6. 601 00:31:36,260 --> 00:31:37,940 But within the Linux kernel. 602 00:31:38,260 --> 00:31:39,580 You could do a similar thing. 603 00:31:39,700 --> 00:31:41,460 However there's sort of a gotcha at the end. 604 00:31:42,340 --> 00:31:43,640 The Linux kernel contains. 605 00:31:45,680 --> 00:31:48,020 So each task struct represents a process. 606 00:31:48,520 --> 00:31:50,000 A task struct contains. 607 00:31:50,340 --> 00:31:51,480 A linked list. 608 00:31:52,380 --> 00:31:53,580 With the pointers. 609 00:31:53,660 --> 00:31:55,180 Previous task and next task. 610 00:31:55,560 --> 00:31:57,820 That you can also follow around the circle. 611 00:31:59,040 --> 00:32:00,180 And it contains. 612 00:32:00,600 --> 00:32:02,080 Two other vital pointers. 613 00:32:02,400 --> 00:32:03,720 Which are previous run. 614 00:32:03,820 --> 00:32:04,440 And next run. 615 00:32:04,800 --> 00:32:06,720 To determine the list. 616 00:32:07,460 --> 00:32:09,940 Or the ordering of when to schedule a process. 617 00:32:12,240 --> 00:32:12,800 So. 618 00:32:14,400 --> 00:32:15,460 How to process. 619 00:32:15,460 --> 00:32:16,280 You just remove. 620 00:32:16,640 --> 00:32:18,080 It from the previous task. 621 00:32:18,320 --> 00:32:19,160 And the next task. 622 00:32:19,740 --> 00:32:21,660 Like demonstrated in the e-process block. 623 00:32:22,360 --> 00:32:23,460 Exact same concept. 624 00:32:23,920 --> 00:32:25,780 You leave next run and previous run alone. 625 00:32:27,800 --> 00:32:29,240 Does anybody know what happens. 626 00:32:29,300 --> 00:32:30,180 When you get this far? 627 00:32:33,580 --> 00:32:34,060 What? 628 00:32:35,580 --> 00:32:36,220 Speak up. 629 00:32:38,340 --> 00:32:38,820 Okay. 630 00:32:38,860 --> 00:32:39,980 The whole process freezes. 631 00:32:40,860 --> 00:32:41,340 So. 632 00:32:41,380 --> 00:32:41,840 Nothing. 633 00:32:41,840 --> 00:32:44,640 Your process does not continue to run. 634 00:32:45,000 --> 00:32:46,440 And the reason being. 635 00:32:46,500 --> 00:32:47,200 Is because. 636 00:32:47,680 --> 00:32:48,980 The way that. 637 00:32:49,920 --> 00:32:51,300 Processes get scheduled time. 638 00:32:51,420 --> 00:32:52,840 On a Linux 2.4 kernel. 639 00:32:53,280 --> 00:32:54,380 In which case. 640 00:32:54,420 --> 00:32:55,480 The scheduler. 641 00:32:55,840 --> 00:32:58,260 Walks around the previous run and next run. 642 00:32:59,480 --> 00:33:00,040 List. 643 00:33:00,420 --> 00:33:01,800 So it follows the next. 644 00:33:02,120 --> 00:33:02,880 I'm sorry. 645 00:33:03,100 --> 00:33:04,880 Follows the previous task. 646 00:33:04,940 --> 00:33:06,140 Or the next task list. 647 00:33:07,020 --> 00:33:08,540 Walks around this linked list. 648 00:33:12,240 --> 00:33:13,320 Based upon. 649 00:33:13,680 --> 00:33:15,520 It calculates a goodness value. 650 00:33:15,880 --> 00:33:17,040 For the process. 651 00:33:17,480 --> 00:33:19,300 And based upon the goodness value. 652 00:33:19,640 --> 00:33:21,320 It assigns it an order. 653 00:33:21,760 --> 00:33:24,280 Or the number of jiffies and so forth. 654 00:33:24,480 --> 00:33:25,520 In which to run. 655 00:33:25,780 --> 00:33:27,540 Or to get CPU scheduling. 656 00:33:27,980 --> 00:33:29,440 So that's. 657 00:33:29,440 --> 00:33:31,940 When it puts it into previous run and next run. 658 00:33:32,620 --> 00:33:33,860 The ordering there. 659 00:33:34,100 --> 00:33:35,760 Well if you're never in the. 660 00:33:36,180 --> 00:33:37,980 In the next task listing. 661 00:33:38,400 --> 00:33:39,760 Then you'll never get your. 662 00:33:39,800 --> 00:33:40,720 Goodness value calculated. 663 00:33:41,840 --> 00:33:42,780 You'll never get scheduled again. 664 00:33:43,620 --> 00:33:44,100 Because. 665 00:33:44,840 --> 00:33:46,360 The scheduler can't see you. 666 00:33:47,220 --> 00:33:49,520 This is probably all different in the 2.6. 667 00:33:49,640 --> 00:33:50,640 With the threading model. 668 00:33:53,600 --> 00:33:55,120 There was a root kit on. 669 00:33:55,600 --> 00:33:56,740 After I hit this problem. 670 00:33:56,860 --> 00:33:57,520 There was a root kit. 671 00:33:57,900 --> 00:33:59,080 That I found online. 672 00:33:59,340 --> 00:34:00,200 That was open source. 673 00:34:00,680 --> 00:34:02,340 It was famous morgy. 674 00:34:02,420 --> 00:34:03,240 I believe is the name. 675 00:34:03,980 --> 00:34:06,340 And this person had come across. 676 00:34:06,740 --> 00:34:08,600 The exact same problem I was having. 677 00:34:11,840 --> 00:34:12,740 And the way they were going to fix it. 678 00:34:12,840 --> 00:34:15,320 Was to patch the scheduler. 679 00:34:16,240 --> 00:34:17,260 So what this. 680 00:34:18,460 --> 00:34:19,140 But the. 681 00:34:19,600 --> 00:34:20,780 Solution did was. 682 00:34:21,260 --> 00:34:23,280 The inert process is always. 683 00:34:23,460 --> 00:34:25,340 The first process that has no. 684 00:34:26,060 --> 00:34:27,280 No parent process. 685 00:34:27,920 --> 00:34:29,520 So the parent processor. 686 00:34:29,800 --> 00:34:31,500 Or pointer parent process. 687 00:34:31,840 --> 00:34:33,700 In the task struct is null. 688 00:34:34,020 --> 00:34:35,380 Well they modified that. 689 00:34:35,400 --> 00:34:36,980 To point to the hidden task struct. 690 00:34:37,560 --> 00:34:39,780 That way they modify their scheduler. 691 00:34:39,820 --> 00:34:41,140 To always go there. 692 00:34:41,840 --> 00:34:42,060 And look. 693 00:34:42,420 --> 00:34:44,600 At these hidden task structs. 694 00:34:44,660 --> 00:34:46,600 And calculate a goodness value for them. 695 00:34:49,200 --> 00:34:50,880 But if you're going through all that effort. 696 00:34:51,000 --> 00:34:51,820 There would probably be better ways. 697 00:34:51,880 --> 00:34:53,040 To hide your process. 698 00:34:59,020 --> 00:35:00,400 It should be noted. 699 00:35:00,520 --> 00:35:02,360 That you can't just change these listings. 700 00:35:03,540 --> 00:35:04,020 Arbitrarily. 701 00:35:04,140 --> 00:35:05,260 And not expect some problems. 702 00:35:06,480 --> 00:35:07,740 These lists especially. 703 00:35:08,280 --> 00:35:09,680 In a multi threaded environment. 704 00:35:11,840 --> 00:35:12,780 In a CPU especially environment. 705 00:35:13,260 --> 00:35:15,380 These lists are shared resources. 706 00:35:16,060 --> 00:35:17,600 So you have to. 707 00:35:18,760 --> 00:35:19,920 Use some kind of. 708 00:35:20,100 --> 00:35:21,360 Synchronization objects. 709 00:35:21,720 --> 00:35:23,700 To try to get access to these lists. 710 00:35:23,800 --> 00:35:26,280 If you want to completely modify them. 711 00:35:26,280 --> 00:35:28,040 Or modify them in a completely safe manner. 712 00:35:29,420 --> 00:35:30,360 In Windows. 713 00:35:30,420 --> 00:35:32,220 If you want to modify the list of. 714 00:35:32,480 --> 00:35:33,420 Active processes. 715 00:35:33,520 --> 00:35:35,180 There's a non exported symbol. 716 00:35:35,680 --> 00:35:37,960 Called PSP active process mutex. 717 00:35:38,440 --> 00:35:39,740 The kernel every time. 718 00:35:39,800 --> 00:35:40,920 Grabs that mutex. 719 00:35:41,840 --> 00:35:42,980 And once it has it. 720 00:35:43,040 --> 00:35:44,200 Then it can modify the list. 721 00:35:44,660 --> 00:35:46,200 PS loaded module resource. 722 00:35:46,660 --> 00:35:49,320 Is to guard the list of device drivers. 723 00:35:52,720 --> 00:35:54,320 Problem is obviously as I said. 724 00:35:54,400 --> 00:35:55,600 These symbols are not exported. 725 00:35:55,920 --> 00:35:57,400 So we have to find another way. 726 00:35:57,480 --> 00:35:58,660 To come up with the synchronization. 727 00:35:59,440 --> 00:36:00,640 One way you could do it. 728 00:36:00,700 --> 00:36:03,560 Is you could hard code these addresses. 729 00:36:03,700 --> 00:36:04,620 Of these mutexes. 730 00:36:06,060 --> 00:36:08,020 And that would vary a lot. 731 00:36:08,020 --> 00:36:10,040 Between each version of the OS. 732 00:36:11,100 --> 00:36:11,960 And maybe. 733 00:36:12,160 --> 00:36:13,820 Potentially each reboot. 734 00:36:14,380 --> 00:36:15,280 Could also. 735 00:36:15,400 --> 00:36:16,620 Have an effect here. 736 00:36:18,160 --> 00:36:20,240 This isn't probably the best solution. 737 00:36:20,780 --> 00:36:22,500 Another way you could go about it. 738 00:36:22,580 --> 00:36:23,480 Is to try to search. 739 00:36:23,740 --> 00:36:25,540 For a known pattern in memory. 740 00:36:26,040 --> 00:36:27,620 You know that there's going to be. 741 00:36:27,640 --> 00:36:28,960 Certain functions within the kernel. 742 00:36:29,200 --> 00:36:31,420 That have to access these mutexes. 743 00:36:31,740 --> 00:36:33,800 In order to operate safely. 744 00:36:34,180 --> 00:36:35,680 So you could do a search. 745 00:36:36,400 --> 00:36:36,940 And. 746 00:36:39,140 --> 00:36:40,180 Sherry Sparks. 747 00:36:40,200 --> 00:36:42,660 From the University of Central Florida. 748 00:36:42,720 --> 00:36:43,880 Has worked with me on this. 749 00:36:44,020 --> 00:36:46,260 She wrote all the code to search for the. 750 00:36:46,920 --> 00:36:48,180 Pattern matches in memory. 751 00:36:48,640 --> 00:36:50,500 In order to gain synchronization. 752 00:36:51,060 --> 00:36:52,040 Another technique. 753 00:36:52,080 --> 00:36:53,320 That we're playing around with. 754 00:36:53,700 --> 00:36:55,660 Is trying to raise every. 755 00:36:56,000 --> 00:36:57,460 You can raise your. 756 00:36:58,600 --> 00:36:59,800 The dispatch level. 757 00:36:59,920 --> 00:37:00,740 On the processor. 758 00:37:01,000 --> 00:37:02,440 Or the IRQ. 759 00:37:03,140 --> 00:37:04,340 Level on the processor. 760 00:37:04,500 --> 00:37:06,040 To dispatch level. 761 00:37:08,080 --> 00:37:10,100 Then you can never get swapped out. 762 00:37:10,620 --> 00:37:11,740 You'll continue to run. 763 00:37:11,860 --> 00:37:12,840 Until you give up control. 764 00:37:13,680 --> 00:37:15,220 Because you run at the same. 765 00:37:16,440 --> 00:37:17,400 Priority more or less. 766 00:37:17,420 --> 00:37:18,100 Or the same level. 767 00:37:18,200 --> 00:37:19,860 As the actual scheduler itself. 768 00:37:20,600 --> 00:37:22,160 However you can only raise. 769 00:37:23,160 --> 00:37:24,640 One call to this function. 770 00:37:24,880 --> 00:37:26,860 Only raises it for that particular CPU. 771 00:37:29,080 --> 00:37:30,180 So you would have to. 772 00:37:30,200 --> 00:37:30,900 Find another way. 773 00:37:31,280 --> 00:37:33,580 To raise it on every single CPU. 774 00:37:34,240 --> 00:37:35,720 And we think we may have. 775 00:37:35,780 --> 00:37:36,480 A solution for that. 776 00:37:38,020 --> 00:37:38,640 But we haven't coded it up. 777 00:37:38,740 --> 00:37:39,260 To test it yet. 778 00:37:41,360 --> 00:37:42,880 So on to token manipulation. 779 00:37:44,540 --> 00:37:45,460 I have the privilege. 780 00:37:45,600 --> 00:37:46,160 Of some process. 781 00:37:46,540 --> 00:37:48,280 You can go and manipulate the token. 782 00:37:48,580 --> 00:37:50,800 Would be something like SE debug privilege. 783 00:37:51,200 --> 00:37:52,360 Or SE shutdown. 784 00:37:54,040 --> 00:37:55,580 Or SE load driver. 785 00:37:55,700 --> 00:37:56,140 For instance. 786 00:37:56,540 --> 00:37:58,800 You can also add groups to a token. 787 00:37:59,200 --> 00:38:01,260 The groups represent the SIDs. 788 00:38:01,280 --> 00:38:03,420 That that process belongs to. 789 00:38:05,120 --> 00:38:05,640 Also. 790 00:38:05,700 --> 00:38:06,880 The first SID. 791 00:38:08,020 --> 00:38:08,220 That token. 792 00:38:08,260 --> 00:38:10,580 Is the owner of the process. 793 00:38:11,460 --> 00:38:12,180 That's important. 794 00:38:12,580 --> 00:38:13,620 And we'll talk about it in a moment. 795 00:38:15,140 --> 00:38:16,960 And by altering some of these fields. 796 00:38:17,140 --> 00:38:18,980 You can make it process. 797 00:38:19,580 --> 00:38:21,560 Look like someone else launched it. 798 00:38:24,060 --> 00:38:25,340 So how is this possible? 799 00:38:26,080 --> 00:38:27,600 You have to understand the structure. 800 00:38:27,620 --> 00:38:28,360 Of the tokens a bit. 801 00:38:28,740 --> 00:38:29,920 There's a static portion. 802 00:38:31,860 --> 00:38:33,440 And there's a variable length portion. 803 00:38:33,700 --> 00:38:34,920 Within the static portion. 804 00:38:35,060 --> 00:38:36,100 Obviously it's a fixed size. 805 00:38:38,020 --> 00:38:39,460 There's important things such as session ID. 806 00:38:39,800 --> 00:38:41,460 There's a pointer to user and groups. 807 00:38:42,100 --> 00:38:43,720 There's a pointer to the privileges. 808 00:38:44,020 --> 00:38:46,040 And there's the number of privileges. 809 00:38:46,100 --> 00:38:46,920 And groups. 810 00:38:47,560 --> 00:38:49,620 So we'll need to modify these things. 811 00:38:50,080 --> 00:38:52,220 And also alter the variable length. 812 00:38:53,520 --> 00:38:55,140 Within the variable length portion. 813 00:38:55,520 --> 00:38:57,240 Because a token can have. 814 00:38:58,040 --> 00:38:59,880 Different numbers of privileges. 815 00:38:59,980 --> 00:39:00,600 And so forth. 816 00:39:00,680 --> 00:39:02,700 It may not be the same for every token. 817 00:39:03,660 --> 00:39:05,480 They're put in the variable length portion. 818 00:39:06,460 --> 00:39:08,000 The same for users and groups. 819 00:39:08,020 --> 00:39:09,320 And restricted SIDs. 820 00:39:09,580 --> 00:39:11,940 I won't cover restricted SIDs. 821 00:39:11,980 --> 00:39:14,220 It was something that was added in the Windows 2000. 822 00:39:15,220 --> 00:39:16,080 Kernel I believe. 823 00:39:16,180 --> 00:39:18,080 And I haven't seen much use of it. 824 00:39:18,300 --> 00:39:19,880 But you could restrict certain. 825 00:39:20,300 --> 00:39:22,660 Certain users from performing certain actions. 826 00:39:23,200 --> 00:39:24,600 With restricted SIDs. 827 00:39:28,140 --> 00:39:29,820 So one of the problems I ran into. 828 00:39:30,140 --> 00:39:31,800 In the FURootkit was. 829 00:39:32,300 --> 00:39:35,020 You cannot just grow a token in memory. 830 00:39:35,340 --> 00:39:36,120 In other words. 831 00:39:36,140 --> 00:39:37,720 You cannot just write to the end of it. 832 00:39:38,020 --> 00:39:40,060 Because you don't know what's below your token. 833 00:39:40,820 --> 00:39:41,760 There could be. 834 00:39:43,440 --> 00:39:44,820 Especially for FU. 835 00:39:44,860 --> 00:39:45,740 It doesn't take into account. 836 00:39:45,840 --> 00:39:46,820 The restricted SIDs. 837 00:39:47,200 --> 00:39:49,800 So you would sort of just write over the restricted SIDs. 838 00:39:49,820 --> 00:39:50,820 Which probably isn't a good idea. 839 00:39:51,460 --> 00:39:53,740 Also you don't know what's at the end. 840 00:39:53,800 --> 00:39:55,240 There could be another process token. 841 00:39:56,100 --> 00:39:57,100 So on and so forth. 842 00:39:57,640 --> 00:39:59,220 The memory may not be valid. 843 00:39:59,460 --> 00:40:00,600 You could cause a page fault. 844 00:40:00,740 --> 00:40:01,740 Or potentially a blue screen. 845 00:40:03,980 --> 00:40:05,860 And so I went about this. 846 00:40:06,140 --> 00:40:07,280 Or a way to solve this. 847 00:40:08,020 --> 00:40:08,440 Was to allocate memory. 848 00:40:09,560 --> 00:40:11,880 And that turned out not to work. 849 00:40:12,180 --> 00:40:13,720 But I did was allocate enough memory. 850 00:40:13,820 --> 00:40:14,880 To put the new privileges. 851 00:40:15,100 --> 00:40:16,540 And the new SIDs in. 852 00:40:16,740 --> 00:40:18,380 And then I just changed the pointers. 853 00:40:18,460 --> 00:40:19,720 And the static portion of the token. 854 00:40:19,960 --> 00:40:21,940 To point to that region of memory. 855 00:40:22,740 --> 00:40:25,540 And that worked for the current process. 856 00:40:25,980 --> 00:40:28,140 But if that process ever spawns. 857 00:40:28,140 --> 00:40:28,860 A child process. 858 00:40:29,720 --> 00:40:32,560 The way that SEP duplicate token works. 859 00:40:33,400 --> 00:40:34,780 It tries to create. 860 00:40:35,480 --> 00:40:37,720 It takes the parent process. 861 00:40:37,780 --> 00:40:38,000 As well as the child process. 862 00:40:38,020 --> 00:40:38,200 As a token. 863 00:40:38,480 --> 00:40:40,980 And tries to create that in the child process. 864 00:40:41,400 --> 00:40:42,500 So it's an inheritance. 865 00:40:43,680 --> 00:40:44,680 But the way it works. 866 00:40:45,240 --> 00:40:47,700 It actually has a subtraction in there. 867 00:40:48,040 --> 00:40:49,180 That I can't figure out. 868 00:40:49,280 --> 00:40:50,660 They assume they know. 869 00:40:51,420 --> 00:40:52,980 Where the token is in memory. 870 00:40:53,080 --> 00:40:54,240 Or what's right below it. 871 00:40:54,720 --> 00:40:55,680 And so on and so forth. 872 00:40:55,880 --> 00:40:58,660 So they know some things about the token structure. 873 00:40:58,820 --> 00:40:59,420 That I don't. 874 00:40:59,660 --> 00:41:03,360 And that prevented this mallocking from working. 875 00:41:03,960 --> 00:41:05,680 If they would have just followed the pointers. 876 00:41:06,160 --> 00:41:07,740 Which seemed like the obvious way. 877 00:41:08,020 --> 00:41:08,940 For me to do it. 878 00:41:09,620 --> 00:41:10,740 They wouldn't have had any. 879 00:41:10,820 --> 00:41:12,120 Or I wouldn't have had any trouble. 880 00:41:12,220 --> 00:41:13,740 When I tried to do it using that method. 881 00:41:18,000 --> 00:41:18,820 So the way. 882 00:41:20,580 --> 00:41:21,900 The way I went about this. 883 00:41:21,960 --> 00:41:22,760 Was to try to. 884 00:41:23,780 --> 00:41:25,560 There's a lot of privileges within a token. 885 00:41:25,900 --> 00:41:26,760 That are disabled. 886 00:41:27,560 --> 00:41:28,360 By default. 887 00:41:28,620 --> 00:41:31,020 And so if they're not even turned on. 888 00:41:31,600 --> 00:41:33,020 Then I probably don't need them. 889 00:41:33,100 --> 00:41:34,700 So let's just throw them away. 890 00:41:35,600 --> 00:41:36,960 And I used this method. 891 00:41:38,540 --> 00:41:40,140 Just to free up some. 892 00:41:40,480 --> 00:41:42,000 Slack space within the token. 893 00:41:42,200 --> 00:41:44,480 So I can write some valuable information there.