Okay. Hi. I'm Anthony Martinez. This is Thomas Bowen. We're here to talk about ToasterKit. It's a rootkit designed for NetBSD. And the reason we picked NetBSD is it's portable. It runs on everything from your desktop machine to big scary hardware like the VAX. To a toaster, little gum stick board, someone putting a toaster. There's new additions to the Unix ideas. And it's also fun. Messing with the kernel lets you control the machine. As for rootkits on NetBSD, there pretty much are none. There haven't been any that we've been able to find. And in addition, check rootkit hasn't been updated for NetBSD for a very, very, very long time. This is possibly the first rootkit for NetBSD. NetBSD architecture is . . . there's a lot of differences. Not all of them work. We're different things to it. There's one thing to it is that there's loadable kernel modules which allow you to, at runtime, add new system calls to kernel space. Also, there's a very good, very clean design in the code as well as very portable design. The way that they do portable design is just basically you have a lot of abstraction from the architecture so you abstract from the architecture so that you do not have to deal with... There's a lot of functions out there in kernel space that make it so you don't have to deal with any of the architecture-specific pieces of code. You just deal with generic functions and it's very easy to deal with. There's process security. If you've ever used the Windows security... Yeah. Tokens, privileges, Linux capabilities, it's a similar idea. We get away from the all or nothing or your root. They also let you load in different security models. We've got to take that into account when we're breaking the security. How we've broken the security, we do a few standard rootkit tricks, provide a system call to make whoever asks the root user. We hide processes like say you're running a password cracker. You don't want that to show up in the list. Say you're sending those cracked passwords home, we can hide the network socket and we can also hide the loadable modules that we're using so that it's not obvious is that there's a rootkit installed. So the code that we used, we just basically ended up using sample. There were a lot of sample code skeletons inside as part of the NetVSD kernel that gave you a lot of information on how to create system calls in loadable kernel modules. It was very simple to modify those so that we could, instead of adding a new system call, we could create system call hooks and things like that. It was very, very easy, just a few lines, just as much, as little as three lines of code modification to be able to make code that they already gave us into a system call hook. So that was very easy. So system call hooks, they basically, there's a master table inside, in the kernel space, which is called sysents. It's a sysents array. Basically, that table is a table mapping system call numbers to functions, to the system call functions in kernel space. So to create a system call function, you're going to need to create a system call function called hook. All you do is go through that table, find the number you want to modify, and change the function pointer in there, and ta-da, you have a system call hook. It's very, very easy. Now the modules that ship, they can do lots of neat stuff, load executable formats, load file system types, but we only concern ourselves with two kinds. A miscellaneous module, which doesn't do anything by itself. When it's loaded, we have to tell it what to do. And a system call module, those go through and pick the next unused system call, load ours in there. We get to be extra lazy, because the NetBSD people did all the work. We just, we use their functions. The module system's controlled through a file on the file system. It's their Unix everything's a file mentality kind of comes back later when we're dealing with hiding the modules. The first module we did goes through and gives you root. It doesn't give you root so much as it copies the credentials out of init. And since init has all sorts of responsibilities, it... It's the first, first process to start up, so it needs to do lots of things, so we use the interface provided by Kehoth to steal its credentials and plug them in to whoever asks. And once we get more complicated than that, we start running into some of the things we want to modify are locked. They can't be written to. quality owns partial structures. Theiron, trying to use the equal assignment operator in C. We just crashed the system. There's functions for the memory manager, uvm-map-protect, and it says that it goes through and it'll remove write protection, but it doesn't actually work against kernel memory. We went through the memory manager code, and it turns out that for supporting the debugger, they had a function that actually does what we want, so we just kind of copied it because we're lazy. Once we got that finished, we could hide modules. If we go through and type modstat and there's a bunch of modules labeled rootkit, that's a dead giveaway. The dev-lkm file, which is where module information comes from, is on the file system, and if we delete that, another dead giveaway. 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. system call, and when it's asked about modules whose name contains rootkit, it says they don't exist. Now we already have a module that will give you root, and we also have a module that will hide any modules you have in there. Another thing we may want to do is hide ports. Maybe we want to have something like OpenSSH running that we don't want anybody to know. We can hide that, but to be able to hide that, it turns out netstat uses a sysctl tree. sysctl is basically a tree structure in kernel space that all of the leaves contain information or configuration options for the kernel that you can modify. It also turns out that it contains all of the port information. Netstat looks through. To be able to hide ports from netstat, we had to hook a sysctl helper function, the TCP helper function. One notable thing about sysctl is the API really, really, really sucks. It was very difficult to get any information out of it to help us in messing with sysctl. The sysctl structure. Actually hiding the port, basically we needed to find the TCP helper function node inside the sysctl tree. As soon as we find that, we can modify that helper function, basically create a new hook, just like we would do for a system call hook. Once we traverse it and hook that function, Basically, our hook function will call the original helper function and modify the results that that function returns so that we're hiding certain ports that we don't want it to actually be displaying to netstat and then return back to netstat. Or anybody that's calling the function, it's basically just hiding it from anybody. And our next step was hiding some processes. We could do that with sysctl, but like we said, using the sysctl API kind of sucks. Instead, we go through, there's a master list of processes in memory that's pretty much only used by PS. And we go through, and when we're asked, we remove. We remove the process we want to hide from the list. And you would think that would be a bad idea because the process wouldn't continue to execute, but that's not actually the case. The scheduler doesn't work with processes anymore. It works on threads. We've got a quick demo cooked up. We did development. We worked on Intel i386 machines. We also worked on a PowerPC machine. And we tested it on a VAX. I could have brought some actual VAX hardware, but it's a little easier to use the emulated one, which is not working. Okay. Can we all see that? Okay, so as we can see, we're running NetBSD 4.0 on the VAX. We've got our main module, our port hiding module, and our process hiding module loaded. And later on, we'll load the VAC. the hiding and the detection modules. Currently, we're unprivileged, but we can change that. This is a little C program that just makes our system call and then runs ID. You could do that and then run a shell. Here's our current process list. One of them is SSHD. Thomas was saying... We can hide the SSHD socket. Currently, we only work on TCP4. It's not hiding the IPv6, but we can easily fix it so that it shows... It also hides the IPv6. Now we show that we don't see the SSHD anymore. It's out of the list, but it's still running. We'll log out of our unprivileged account. Come into root. Load the hiding module. Vaxes are a little slow. That's a bunch of garbage. The considering stuff is our debugging output, but it doesn't show any of the modules listed. Now we can show that we can detect our rootkit. Again, the Vax is not the speediest machine on the earth. There's a sys exit mismatch because we hook exit. These, getGID, getPID, and getUID, those system calls don't actually match up to their functions to begin with. There's a reason for that that I don't recall at the moment. Here we show that we are not showing the true module status because these functions differ. Then we return an error because we don't actually need a load permanently. We just go in to the kernel space to check. Then we return an error because we don't actually need a load permanently. We just go in to the kernel space to check. We don't hide files at the moment, but that's the next step. How do you do protection? Basically, you have to detect these hooks. Our current rootkit just does a lot of simple hooks. For the simple case, it's very easy to detect hooks like this because you're modifying some sort of table somewhere or a tree somewhere where there's basically a pointer in there which is supposed to be pointing to your actual system call or your helper function like in a CTL tree. While you're in kernel space, you can see both that table and your actual function. You can compare the memory addresses of those two, and if they're different, then that's how you detect hooks. However, it's an arms race with rootkits because they are now mostly starting to do a lot of hot patching in kernel. Basically, you strip out all of your code from the original function that you're hooking and move that somewhere else in memory and then replace it with your hook function and run it like that. That is a lot easier. It's a little bit more difficult to detect. Detecting kauth is pretty difficult because what we did with kauth is it's just doing a simple duplicate function that many other kernel functions use. An example is fork uses it very often. We're not doing anything special with it. We're just basically calling it down. We want to go a lot faster with our as if we were calling it normally, so it would be very difficult to be able to detect what we're doing with that because it just looks normal. Detecting memory unprotection is difficult as well because, at least on NetBSD currently, because there is no utilities to really do that because there are no rootkits that we've been able to find, public rootkits, for NetBSD, so there's just no need for the tools currently. And preventing this sort of attack is another arms race. The first step is don't build your kernel with modules available. Now, that works against a script kitty installing a rootkit on a machine because there's also tools to force in a module through directly writing a memory, and sometimes you've got to have a module for a hardware device or a file system that you can't build into the kernel. The other option is the security levels, which originated in BSD, but that messes with your ability to run X windows. It keeps you from, from being able to patch your system easily because you've got to take it all the way down to single user to get insecure again. And the popular architectures ship by default as insecure because it's a tradeoff between annoying your users and being able to use your machine. Plus there's always a point where the secure level is low enough at boot time, so someone can go in, modify your boot up scripts and load the modules in there. We ran really, really short. Any questions? Audience member 1 Audience member 2? Male Speaker 3 He's asking if we do anything to avoid things like top and free from seeing our hidden bought We we, he's asking if we do anything from seeing our hidden log into... to avoid things like top and free from seeing our, our hidden processes. Those also use the, if we do and we get it continuously. the all proc list that we modify. So yes, that works against those. We do not hide our network sockets from LSOF because what LSOF does is it goes through and actually reads kernel memory. They're trying to get away from processes reading kernel memory because then they are hard coded in and it's difficult to upgrade past that. I'm sorry? If you're on netstat, it will not show because we hide from netstat, but we do not hide from LSOF. No, the... Okay. Little stub functions that we wrote that actually make the system calls. Those are really short. It just makes system call and then runs ID. This is the one we use to hide a process. This is the one we use to hide network sockets. You just, you hand it the process name or the port number. I'm sorry? There you go. I see. I'm sorry? Not affiliated with the NetBSD project. This is a typical rootkit. There's nothing special we've done. There's lots of books about designing rootkits. The most innovative thing we've done, from what I can tell, is we messaged the CTL, which I haven't seen any other kit that deals with that. Any other questions? Okay. We've tried this on three architectures. The PPC, the Intel 386, and the VAX. . Yeah. . . . . . . . . . . . . . . . . . The code is going to be released in a Google Code project. The group name is Toaster Kit. This is the main module, the first one. It goes through, it finds init, copies the credentials in, and puts them in the current process. That was the easiest thing to do. This is the function that we pulled from the memory manager that it allows us to do two things, to unprotect the memory. It goes through various dances to find the physical addresses and forcibly put the protection in. This is possibly our worst module. This doesn't 100% work on the PowerPC for some reason. I am not entirely sure why that is. It started out with we make the original call, we check for some errors, and then we go through and copy the useful information back out and hide the port we are looking for. As released, it has a bunch of debugging information. It's not particularly stealthy. It's more of a proof of concept. It's all licensed under the BSD license, of course. This one goes through, looks at the process list. It leaves, removes it out of the list, simple linked list style. We could do some more thorough hiding later on, but proof of concept. The detection is sort of interesting. We generate at compile time we generate a C-file that includes, that we include in the module. The whole process is a clip of it. module, and it goes through, performs all the if checks, and warns on the errors. For the checking if we're hooking a module listing, we just do a single if check. For hiding the modules, it's the same sort of, we wrap the old function and we lie about the original data. Say it is not an entry, does not exist. Right. Not in the base system. He was asking if there's any tools that show the thread list. PS does not read the thread list. It reads the all proc list. Any further questions? If there's no further questions, I suppose we'll be in the Q and A room for track two. Thank you.