1 00:00:00,380 --> 00:00:07,700 Okay. Hi. I'm Anthony Martinez. This is Thomas Bowen. We're here to talk about ToasterKit. 2 00:00:08,280 --> 00:00:19,140 It's a rootkit designed for NetBSD. And the reason we picked NetBSD is it's portable. 3 00:00:19,340 --> 00:00:25,920 It runs on everything from your desktop machine to big scary hardware like the VAX. 4 00:00:30,000 --> 00:00:34,480 To a toaster, little gum stick board, someone putting a toaster. 5 00:00:39,400 --> 00:00:55,560 There's new additions to the Unix ideas. And it's also fun. Messing with the kernel lets 6 00:00:55,560 --> 00:00:56,380 you control the machine. 7 00:00:58,940 --> 00:01:03,360 As for rootkits on NetBSD, there pretty much are none. 8 00:01:03,540 --> 00:01:06,300 There haven't been any that we've been able to find. 9 00:01:06,940 --> 00:01:12,300 And in addition, check rootkit hasn't been updated for NetBSD for a very, very, very 10 00:01:12,300 --> 00:01:18,400 long time. This is possibly the first rootkit for NetBSD. 11 00:01:23,200 --> 00:01:26,360 NetBSD architecture is . . . there's a lot of differences. Not all of them work. We're 12 00:01:26,360 --> 00:01:31,200 different things to it. There's one thing to it is that there's loadable kernel modules 13 00:01:31,880 --> 00:01:41,100 which allow you to, at runtime, add new system calls to kernel space. Also, there's a very 14 00:01:41,100 --> 00:01:47,220 good, very clean design in the code as well as very portable design. The way that they 15 00:01:47,220 --> 00:01:53,660 do portable design is just basically you have a lot of abstraction from the architecture 16 00:01:53,660 --> 00:01:58,100 so you abstract from the architecture so that you do not have to deal with... There's a 17 00:01:58,100 --> 00:02:03,100 lot of functions out there in kernel space that make it so you don't have to deal with 18 00:02:03,100 --> 00:02:08,740 any of the architecture-specific pieces of code. You just deal with generic functions 19 00:02:08,740 --> 00:02:20,200 and it's very easy to deal with. There's process security. If you've ever 20 00:02:20,200 --> 00:02:23,060 used the Windows security... 21 00:02:23,060 --> 00:02:23,640 Yeah. 22 00:02:24,920 --> 00:02:34,260 Tokens, privileges, Linux capabilities, it's a similar idea. We get away from the 23 00:02:34,260 --> 00:02:40,140 all or nothing or your root. They also let you load in different security models. We've 24 00:02:40,140 --> 00:02:53,040 got to take that into account when we're breaking the security. How we've broken the 25 00:02:53,040 --> 00:03:00,100 security, we do a few standard rootkit tricks, provide a system call to make whoever asks 26 00:03:01,000 --> 00:03:02,240 the root user. 27 00:03:03,540 --> 00:03:08,980 We hide processes like say you're running a password cracker. You don't want that to 28 00:03:08,980 --> 00:03:12,480 show up in the list. Say you're sending those cracked passwords home, we can hide the network 29 00:03:12,480 --> 00:03:22,460 socket and we can also hide the loadable modules that we're using so that it's not obvious 30 00:03:22,460 --> 00:03:23,400 is that there's a rootkit installed. 31 00:03:29,820 --> 00:03:35,940 So the code that we used, we just basically ended up using sample. There were a lot of 32 00:03:35,940 --> 00:03:46,260 sample code skeletons inside as part of the NetVSD kernel that gave you a lot of information 33 00:03:46,260 --> 00:03:52,640 on how to create system calls in loadable kernel modules. It was very simple to modify 34 00:03:52,640 --> 00:03:57,500 those so that we could, instead of adding a new system call, we could create system 35 00:03:57,500 --> 00:04:04,400 call hooks and things like that. It was very, very easy, just a few lines, just as much, 36 00:04:04,500 --> 00:04:10,420 as little as three lines of code modification to be able to make code that they already 37 00:04:10,420 --> 00:04:14,340 gave us into a system call hook. So that was very easy. 38 00:04:16,560 --> 00:04:23,720 So system call hooks, they basically, there's a master table inside, in the kernel space, 39 00:04:24,000 --> 00:04:32,320 which is called sysents. It's a sysents array. Basically, that table is a table mapping system 40 00:04:32,920 --> 00:04:41,160 call numbers to functions, to the system call functions in kernel space. 41 00:04:44,080 --> 00:04:46,240 So to create a system call function, you're going to need to create a system call function 42 00:04:46,240 --> 00:04:50,100 called hook. All you do is go through that table, find the number you want to modify, 43 00:04:50,300 --> 00:04:55,500 and change the function pointer in there, and ta-da, you have a system call hook. It's 44 00:04:55,500 --> 00:04:56,340 very, very easy. 45 00:05:00,140 --> 00:05:07,660 Now the modules that ship, they can do lots of neat stuff, load executable formats, load 46 00:05:08,700 --> 00:05:13,740 file system types, but we only concern ourselves with two kinds. A miscellaneous module, which 47 00:05:14,480 --> 00:05:18,820 doesn't do anything by itself. When it's loaded, we have to tell it what to do. And 48 00:05:18,820 --> 00:05:25,980 a system call module, those go through and pick the next unused system call, load ours 49 00:05:26,620 --> 00:05:34,800 in there. We get to be extra lazy, because the NetBSD people did all the work. We just, 50 00:05:34,880 --> 00:05:43,720 we use their functions. The module system's controlled through a file on the file system. 51 00:05:44,500 --> 00:05:53,200 It's their Unix everything's a file mentality kind of comes back later when we're dealing 52 00:05:53,200 --> 00:06:01,440 with hiding the modules. The first module we did goes through and gives you root. It 53 00:06:01,440 --> 00:06:09,860 doesn't give you root so much as it copies the credentials out of init. And since init 54 00:06:09,860 --> 00:06:12,220 has all sorts of responsibilities, it... 55 00:06:13,240 --> 00:06:19,180 It's the first, first process to start up, so it needs to do lots of things, so we use 56 00:06:21,220 --> 00:06:28,740 the interface provided by Kehoth to steal its credentials and plug them in to whoever 57 00:06:28,740 --> 00:06:29,040 asks. 58 00:06:30,920 --> 00:06:37,860 And once we get more complicated than that, we start running into some of the things we 59 00:06:37,860 --> 00:06:42,200 want to modify are locked. They can't be written to. quality owns partial structures. Theiron, 60 00:06:42,200 --> 00:06:48,740 trying to use the equal assignment operator in C. We just crashed the system. 61 00:06:52,420 --> 00:07:00,160 There's functions for the memory manager, uvm-map-protect, and it says that it goes 62 00:07:00,160 --> 00:07:04,080 through and it'll remove write protection, but it doesn't actually work against kernel 63 00:07:04,980 --> 00:07:11,460 memory. We went through the memory manager code, and 64 00:07:11,460 --> 00:07:18,520 it turns out that for supporting the debugger, they had a function that actually does what 65 00:07:18,520 --> 00:07:23,280 we want, so we just kind of copied it because we're lazy. 66 00:07:36,440 --> 00:07:39,640 Once we got that finished, we could hide modules. 67 00:07:41,460 --> 00:07:48,600 If we go through and type modstat and there's a bunch of modules labeled rootkit, that's 68 00:07:48,600 --> 00:07:54,100 a dead giveaway. The dev-lkm file, which is where module information 69 00:07:54,100 --> 00:08:02,820 comes from, is on the file system, and if we delete that, another dead giveaway. 70 00:08:03,780 --> 00:08:11,440 We go through and there's a function that provides the information and we just hook it in a similar way to doing this simple way. 71 00:08:11,460 --> 00:08:19,980 system call, and when it's asked about modules whose name contains rootkit, it says they 72 00:08:19,980 --> 00:08:20,420 don't exist. 73 00:08:27,540 --> 00:08:32,700 Now we already have a module that will give you root, and we also have a module 74 00:08:32,700 --> 00:08:37,000 that will hide any modules you have in there. Another thing we may want to do is hide ports. 75 00:08:37,000 --> 00:08:43,760 Maybe we want to have something like OpenSSH running that we don't want anybody to know. 76 00:08:44,120 --> 00:08:51,360 We can hide that, but to be able to hide that, it turns out netstat uses a sysctl tree. sysctl 77 00:08:51,360 --> 00:08:56,420 is basically a tree structure in kernel space that all of the leaves contain information 78 00:08:56,420 --> 00:09:02,560 or configuration options for the kernel that you can modify. It also turns out that it 79 00:09:02,560 --> 00:09:05,200 contains all of the port information. 80 00:09:07,000 --> 00:09:15,960 Netstat looks through. To be able to hide ports from netstat, we had to hook a sysctl 81 00:09:18,720 --> 00:09:27,740 helper function, the TCP helper function. One notable thing about sysctl is the API 82 00:09:27,740 --> 00:09:33,600 really, really, really sucks. It was very difficult to get any information out of it 83 00:09:33,600 --> 00:09:36,980 to help us in messing with sysctl. 84 00:09:36,980 --> 00:09:45,240 The sysctl structure. Actually hiding the port, basically we needed 85 00:09:45,240 --> 00:09:51,740 to find the TCP helper function node inside the sysctl tree. As soon as we find that, 86 00:09:51,880 --> 00:09:58,520 we can modify that helper function, basically create a new hook, just like we would do for 87 00:09:58,520 --> 00:10:06,460 a system call hook. Once we traverse it and hook that function, 88 00:10:06,980 --> 00:10:12,360 Basically, our hook function will call the original helper function 89 00:10:12,360 --> 00:10:17,520 and modify the results that that function returns 90 00:10:17,520 --> 00:10:22,920 so that we're hiding certain ports that we don't want it to actually be displaying to netstat 91 00:10:22,920 --> 00:10:24,600 and then return back to netstat. 92 00:10:24,800 --> 00:10:31,180 Or anybody that's calling the function, it's basically just hiding it from anybody. 93 00:10:36,980 --> 00:10:39,320 And our next step was hiding some processes. 94 00:10:43,040 --> 00:10:51,740 We could do that with sysctl, but like we said, using the sysctl API kind of sucks. 95 00:10:55,040 --> 00:10:58,780 Instead, we go through, there's a master list of processes in memory 96 00:10:58,780 --> 00:11:00,960 that's pretty much only used by PS. 97 00:11:02,540 --> 00:11:06,720 And we go through, and when we're asked, we remove. 98 00:11:06,980 --> 00:11:11,280 We remove the process we want to hide from the list. 99 00:11:12,680 --> 00:11:14,740 And you would think that would be a bad idea 100 00:11:14,740 --> 00:11:18,420 because the process wouldn't continue to execute, 101 00:11:18,660 --> 00:11:20,700 but that's not actually the case. 102 00:11:20,860 --> 00:11:25,460 The scheduler doesn't work with processes anymore. 103 00:11:25,780 --> 00:11:26,840 It works on threads. 104 00:11:30,260 --> 00:11:31,940 We've got a quick demo cooked up. 105 00:11:33,580 --> 00:11:36,620 We did development. 106 00:11:36,980 --> 00:11:40,160 We worked on Intel i386 machines. 107 00:11:40,820 --> 00:11:44,140 We also worked on a PowerPC machine. 108 00:11:45,300 --> 00:11:47,760 And we tested it on a VAX. 109 00:11:48,260 --> 00:11:50,300 I could have brought some actual VAX hardware, 110 00:11:50,540 --> 00:11:57,100 but it's a little easier to use the emulated one, 111 00:11:58,820 --> 00:12:01,760 which is not working. 112 00:12:02,160 --> 00:12:02,720 Okay. 113 00:12:07,840 --> 00:12:09,140 Can we all see that? 114 00:12:21,420 --> 00:12:25,400 Okay, so as we can see, we're running NetBSD 4.0 on the VAX. 115 00:12:26,860 --> 00:12:31,780 We've got our main module, our port hiding module, 116 00:12:31,880 --> 00:12:33,160 and our process hiding module loaded. 117 00:12:33,540 --> 00:12:34,620 And later on, 118 00:12:36,100 --> 00:12:36,960 we'll load the VAC. 119 00:12:36,980 --> 00:12:53,060 the hiding and the detection modules. Currently, we're unprivileged, but we can change that. 120 00:12:54,120 --> 00:13:02,640 This is a little C program that just makes our system call and then runs ID. You could 121 00:13:02,640 --> 00:13:19,820 do that and then run a shell. Here's our current process list. One of them is SSHD. 122 00:13:29,380 --> 00:13:31,420 Thomas was saying... 123 00:13:32,980 --> 00:13:48,940 We can hide the SSHD socket. Currently, we only work on TCP4. It's not hiding the IPv6, 124 00:13:50,560 --> 00:14:01,780 but we can easily fix it so that it shows... 125 00:14:01,780 --> 00:14:16,720 It also hides the IPv6. Now we show that we don't see the SSHD anymore. It's out of 126 00:14:16,720 --> 00:14:31,560 the list, but it's still running. We'll log out of our unprivileged account. 127 00:14:31,780 --> 00:14:40,920 Come into root. Load the hiding module. 128 00:14:51,340 --> 00:14:57,720 Vaxes are a little slow. That's a bunch of garbage. 129 00:14:57,720 --> 00:15:05,580 The considering stuff is our debugging output, but it doesn't show any of the modules listed. 130 00:15:10,880 --> 00:15:15,580 Now we can show that we can detect our rootkit. 131 00:15:32,340 --> 00:15:35,300 Again, the Vax is not the speediest machine on the earth. 132 00:15:40,960 --> 00:15:44,100 There's a sys exit mismatch because we hook exit. 133 00:15:46,700 --> 00:15:52,840 These, getGID, getPID, and getUID, those system calls don't actually match up to their 134 00:15:52,840 --> 00:15:53,900 functions to begin with. 135 00:15:58,460 --> 00:16:02,860 There's a reason for that that I don't recall at the moment. 136 00:16:04,580 --> 00:16:13,000 Here we show that we are not showing the true module status because these functions differ. 137 00:16:13,340 --> 00:16:18,680 Then we return an error because we don't actually need a load permanently. We just 138 00:16:20,520 --> 00:16:22,560 go in to the kernel space to check. 139 00:16:23,400 --> 00:16:23,880 Then we return an error because we don't actually need a load permanently. We just go in to the kernel space to check. 140 00:16:27,600 --> 00:16:33,000 We don't hide files at the moment, but that's the next step. 141 00:16:40,420 --> 00:16:50,460 How do you do protection? Basically, you have to detect these hooks. Our current rootkit 142 00:16:50,460 --> 00:16:56,100 just does a lot of simple hooks. For the simple case, it's very easy to detect 143 00:16:56,100 --> 00:17:02,340 hooks like this because you're modifying some sort of table somewhere or a tree somewhere 144 00:17:02,340 --> 00:17:07,520 where there's basically a pointer in there which is supposed to be pointing to your actual 145 00:17:07,520 --> 00:17:13,960 system call or your helper function like in a CTL tree. While you're in kernel space, 146 00:17:14,080 --> 00:17:20,240 you can see both that table and your actual function. You can compare the memory addresses 147 00:17:20,240 --> 00:17:23,900 of those two, and if they're different, then that's how you detect hooks. 148 00:17:24,320 --> 00:17:31,940 However, it's an arms race with rootkits because they are now mostly starting to do a lot of 149 00:17:31,940 --> 00:17:37,440 hot patching in kernel. Basically, you strip out all of your code from the original function 150 00:17:37,440 --> 00:17:43,120 that you're hooking and move that somewhere else in memory and then replace it with your 151 00:17:43,120 --> 00:17:50,220 hook function and run it like that. That is a lot easier. 152 00:17:50,240 --> 00:18:01,460 It's a little bit more difficult to detect. Detecting kauth is pretty difficult because 153 00:18:03,110 --> 00:18:09,200 what we did with kauth is it's just doing a simple duplicate function that many other 154 00:18:09,990 --> 00:18:18,040 kernel functions use. An example is fork uses it very often. We're not doing anything 155 00:18:18,040 --> 00:18:20,220 special with it. We're just basically calling it down. We want to go a lot faster with our 156 00:18:20,240 --> 00:18:25,320 as if we were calling it normally, so it would be very difficult to be able to detect what 157 00:18:25,320 --> 00:18:32,140 we're doing with that because it just looks normal. Detecting memory unprotection is difficult 158 00:18:32,140 --> 00:18:37,640 as well because, at least on NetBSD currently, because there is no utilities to really do 159 00:18:37,640 --> 00:18:43,600 that because there are no rootkits that we've been able to find, public rootkits, for NetBSD, 160 00:18:43,600 --> 00:18:46,100 so there's just no need for the tools currently. 161 00:18:52,440 --> 00:19:02,340 And preventing this sort of attack is another arms race. The first step is don't build your 162 00:19:02,340 --> 00:19:12,720 kernel with modules available. Now, that works against a script kitty installing a rootkit 163 00:19:13,820 --> 00:19:21,520 on a machine because there's also tools to force in a module through directly writing 164 00:19:21,520 --> 00:19:29,940 a memory, and sometimes you've got to have a module for a hardware device or a file system 165 00:19:29,940 --> 00:19:35,320 that you can't build into the kernel. The other option is the security levels, which 166 00:19:36,180 --> 00:19:43,040 originated in BSD, but that messes with your ability to run X windows. It keeps you from, 167 00:19:43,040 --> 00:19:46,320 from being able to patch your system easily because you've got to take it all the way 168 00:19:46,320 --> 00:19:56,640 down to single user to get insecure again. And the popular architectures ship by default 169 00:19:57,000 --> 00:20:03,360 as insecure because it's a tradeoff between annoying your users and being able to use 170 00:20:03,360 --> 00:20:12,500 your machine. Plus there's always a point where the secure level is low enough at boot 171 00:20:12,500 --> 00:20:20,800 time, so someone can go in, modify your boot up scripts and load the modules in there. 172 00:20:24,840 --> 00:20:28,040 We ran really, really short. Any questions? 173 00:20:31,780 --> 00:20:32,260 Audience member 1 174 00:20:32,260 --> 00:20:32,880 Audience member 2? 175 00:20:39,480 --> 00:20:40,680 Male Speaker 3 176 00:20:40,680 --> 00:20:43,040 He's asking if we do anything to avoid things like top and free from seeing our hidden bought 177 00:20:43,040 --> 00:20:50,960 We we, he's asking if we do anything from seeing our hidden log into... 178 00:20:50,960 --> 00:21:00,080 to avoid things like top and free from seeing our, our hidden processes. Those also use 179 00:21:00,080 --> 00:21:02,860 the, if we do and we get it continuously. 180 00:21:02,860 --> 00:21:08,780 the all proc list that we modify. So yes, that works against those. 181 00:21:08,960 --> 00:21:15,360 We do not hide our network sockets from LSOF because what LSOF does is it goes through 182 00:21:15,360 --> 00:21:20,000 and actually reads kernel memory. They're trying to get away from processes reading 183 00:21:20,000 --> 00:21:30,240 kernel memory because then they are hard coded in and it's difficult to upgrade past that. 184 00:21:36,780 --> 00:21:45,700 I'm sorry? If you're on netstat, it will not show because we hide from netstat, but 185 00:21:45,700 --> 00:21:46,980 we do not hide from LSOF. 186 00:22:00,080 --> 00:22:01,260 No, the... 187 00:22:02,240 --> 00:22:02,840 Okay. 188 00:22:02,860 --> 00:22:10,280 Little stub functions that we wrote that actually make the system calls. Those are really short. 189 00:22:16,680 --> 00:22:28,260 It just makes system call and then runs ID. This is the one we use to hide a process. 190 00:22:33,360 --> 00:22:39,080 This is the one we use to hide network sockets. You just, you hand it the process name or the port number. 191 00:22:53,820 --> 00:22:54,380 I'm sorry? 192 00:22:55,040 --> 00:22:55,620 There you go. 193 00:22:57,540 --> 00:22:58,060 I see. 194 00:22:58,060 --> 00:22:58,120 I'm sorry? 195 00:22:58,240 --> 00:23:13,080 Not affiliated with the NetBSD project. This is a typical rootkit. There's nothing 196 00:23:13,080 --> 00:23:20,480 special we've done. There's lots of books about designing rootkits. 197 00:23:20,480 --> 00:23:29,080 The most innovative thing we've done, from what I can tell, is we messaged the CTL, which 198 00:23:30,420 --> 00:23:37,660 I haven't seen any other kit that deals with that. 199 00:23:47,580 --> 00:23:49,020 Any other questions? 200 00:23:49,240 --> 00:23:49,800 Okay. 201 00:23:59,820 --> 00:24:09,200 We've tried this on three architectures. The PPC, the Intel 386, and the VAX. 202 00:24:16,080 --> 00:24:16,780 . 203 00:24:22,460 --> 00:24:23,860 Yeah. 204 00:24:24,720 --> 00:24:26,120 . 205 00:24:26,120 --> 00:24:28,720 . 206 00:24:28,720 --> 00:24:29,040 . 207 00:24:29,040 --> 00:24:29,420 . 208 00:24:42,840 --> 00:24:43,120 . 209 00:24:44,840 --> 00:24:45,120 . 210 00:24:45,120 --> 00:24:45,320 . 211 00:24:45,320 --> 00:24:45,400 . 212 00:24:45,400 --> 00:24:45,520 . 213 00:24:45,520 --> 00:24:45,660 . 214 00:24:46,720 --> 00:24:47,000 . 215 00:24:47,000 --> 00:24:47,080 . 216 00:24:48,560 --> 00:24:48,840 . 217 00:24:48,840 --> 00:24:48,860 . 218 00:24:48,860 --> 00:24:48,880 . 219 00:25:05,020 --> 00:25:07,820 . . 220 00:25:07,820 --> 00:25:16,020 The code is going to be released in a Google Code project. The group name is Toaster Kit. 221 00:25:20,620 --> 00:25:33,560 This is the main module, the first one. It goes through, it finds init, copies the credentials 222 00:25:33,560 --> 00:25:45,560 in, and puts them in the current process. That was the easiest thing to do. 223 00:25:52,340 --> 00:26:03,540 This is the function that we pulled from the memory manager that it allows us to do two 224 00:26:03,560 --> 00:26:11,220 things, to unprotect the memory. It goes through various dances to find the physical 225 00:26:11,220 --> 00:26:13,700 addresses and forcibly put the protection in. 226 00:26:58,000 --> 00:26:59,980 This is possibly our worst module. 227 00:26:59,980 --> 00:27:08,660 This doesn't 100% work on the PowerPC for some reason. I am not entirely sure why that 228 00:27:08,660 --> 00:27:16,220 is. It started out with we make the original call, 229 00:27:19,500 --> 00:27:29,240 we check for some errors, and then we go through and copy the useful information back out and 230 00:27:29,240 --> 00:27:31,560 hide the port we are looking for. 231 00:27:36,500 --> 00:27:44,180 As released, it has a bunch of debugging information. It's not particularly stealthy. It's more 232 00:27:44,180 --> 00:27:45,000 of a proof of concept. 233 00:27:57,980 --> 00:28:00,360 It's all licensed under the BSD license, of course. 234 00:28:06,700 --> 00:28:11,660 This one goes through, looks at the process list. 235 00:28:16,340 --> 00:28:24,800 It leaves, removes it out of the list, simple linked list style. We could do some more 236 00:28:24,800 --> 00:28:31,760 thorough hiding later on, but proof of concept. 237 00:28:41,220 --> 00:28:58,300 The detection is sort of interesting. We generate at compile time we generate a C-file 238 00:28:58,300 --> 00:29:01,740 that includes, that we include in the module. The whole process is a clip of it. 239 00:29:01,740 --> 00:29:08,540 module, and it goes through, performs all the if checks, and warns on the errors. 240 00:29:09,340 --> 00:29:18,500 For the checking if we're hooking a module listing, we just do a single if check. 241 00:29:31,940 --> 00:29:44,980 For hiding the modules, it's the same sort of, we wrap the old function and we 242 00:29:44,980 --> 00:29:53,120 lie about the original data. Say it is not an entry, does not exist. 243 00:30:12,360 --> 00:30:22,120 Right. Not in the base system. He was asking if there's any tools that show the thread 244 00:30:22,120 --> 00:30:29,060 list. PS does not read the thread list. It reads the all proc list. 245 00:30:39,700 --> 00:30:49,320 Any further questions? If there's no further questions, I suppose we'll be in the Q and 246 00:30:49,320 --> 00:30:58,440 A room for track two. Thank you.