Hopefully this will work. Okay, so what I'm going to talk about is rootkits and also ways to detect rootkits. I've developed a freeware tool called VICE that does that. So if you came to see a bunch of hookers taken away by some policemen, you're in the wrong room. I know, I know, the limo got broke down, you know, whatever. So as he said, my name is Foozanop. If you came to Black Hat, you know I'm also Jamie Butler. It's in your program. That's no secret. I'm at rootkit.com. Everything I discuss here you can download from rootkit.com. But wait until Monday or Tuesday of next week. The source code for all the rootkit stuff I will talk about is always rootkit.com. So you can have that and change it or whatever. VICE, the freeware tool, currently is downloadable in binary format. 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. Then we're going to talk about the tool VICE to detect it. Then we're going to talk about direct kernel object manipulation, which is incorporated into FU and a demonstration. Pardon my voice today. It's pretty dry. So just we'll cover a few general overview of an operating system. This talk applies mainly to Win32, but you could also apply all the rootkit technologies and concepts to a Linux or Spark or whatever. So in a Win32 type of environment, there's user land, and that's supported. It's supported by kernel32.dll and ntdll.dll. So whenever you write a program, that's the libraries you link to, and you use the functionalities exported by those DLLs. 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. The kernel is what implements the low-level functionality to allow these APIs to work. So it's the kernel doing all the work. And then the other thing I wanted to talk about is how the rootkit can be used to do things like basically just pass-through. So tax scenario. Rootkits are not about how to exploit a box. There's been other talks here, FX and Alvar and other talks at Black Hat, or experts at Shellcode and so forth. So I won't talk about how to gain access the first time. What a rootkit is for is to maintain access so hide your presence you want a remote command and control channel that is undetectable by IDS's and by the kernel itself and maybe intrusion provision. In the most part for the ones I write they'll exist in the kernel so they act as part of the kernel and we'll talk about why. Until recently most root kits were nothing more than a Trojan program this is probably like an 80s thing they would they would replace PS or LS or something but when an administrator would run the command they would get a Trojan version of the executable. Of course companies have come along and for the large part solve this problem and now root kits evolved to filter data by hooking functions in memory. This way they could achieve the same results. By hooking a function you can run a function in memory and it can run a function in memory. This way they could achieve the same results. By hooking a function you can change what that function returned. So for instance if it's you're asking for a list of processes on the machine by hooking you can filter out your your rogue process that you do not want displayed. Hooking can be done at many different places. The import address table is one and I think we'll have a diagram of that in a moment. You can hook the system call table you can hook the interrupt descriptor table. Really this is only a few places you could hook there's quite a multitude. So this is just a diagram I don't have a light pen so sorry I can't point out the relevant features on the slide but this is the green represents the big green box represents a program that's running and it needs functionality from another DLL. So it does it has stubs in its code called the import address table. When the loader loads the program into memory it will set the appropriate function address for these functions that are in other DLLs in this IAT table and that's a blow up there. They're either exported by function name or by ordinal and the one two one one two two three three four four represents the address in a different DLL that that function would actually be located at. So this is the normal control flow code and your program goes and the application goes through the IAT the IAT calls into some DLL such as kernel 32 etc. You can inject a DLL into another process through a couple different means we won't cover those but they're well documented and it's also rootkit.com there's at least three different rootkits that use DLL in general. to hook things. So in this case, the rootkit is changing the IET entry so that the program control flow changes to it instead of the original DLL. Now here's an example of a system call hook. So on the, I guess, my left, there's the system calls being made. That's an application asking the operating system to do something on its behalf. It passes through that magic barrier there. Now it's in kernel mode. In kernel mode, there's a function called, in the kernel, in TS kernel, there's a function called chaos system service. Chaos system service will resolve. The, the number of the function you're trying to call. So for instance, like, um, ZW create key for creating a registry key. Maybe that's function number 3B. It uses that as an index into the system service descriptor table, and that just contains function pointers. Each, there's a blowup, blowup of each table entry, and they're merely, um, functions. There are functions points that are indexed by call number. The function, uh, is represented here. So you go through the call table to the function that's in question with his control flow. Now if you have a rootkit, obviously you can divert that control flow to yourself. This is the same as a userlan IET hook more or less it's just a little bit more complicated because not as many people seem to know how to write that. kernel code and can get some things wrong this is an example of a more advanced technique where after going through the system call table it still goes to the correct function which is represented there at the top however the functions been hooked by immediate jump and the immediate jump jumps to the rootkit and then the rootkit has control once again this is a lot more advanced technique it's sometimes hard to get correct quick overview again in case this is an animated slide that represents it may be a little bit better so kernel32.dll runs for a while this function represents create file w to create a file in the file system it eventually calls into NT DLL calling the function NT create file that runs for a while and then it calls into the system so at each one of those places on the slide you could have hooked at the beginning of the function you could have hooked up where the function made the call you could hook the IETs etc once you're in the kernel or on Linux the the interrupt for requesting service of the kernel is interrupt80 on Windows it's int2e so if you hit int2e then that's when you'll jump to a system chaos system service which will resolve the number of the system call that you wanted and also where your user parameters are and so forth just for reference in the EAX register is the system call number in this case it would correspond to in this case it would correspond to ntcrate file and in EDX is a pointer to the user supply parameters so once in a system call table again it's just an address and it jumps off to the real function in question this slide is an anime but you could have hooked Nt create file by overriding push ebp movie SP into ebp and xor xor or you would have to at least overwrite that many, maybe the push also. Because a jump is a 5-byte instruction, it's at least 5 bytes, so you have to overwrite at least the first 5 bytes of the function. So, in rootkit.com, there's a whole lot of rootkits that are user-mode rootkits. And user-mode rootkits aren't the way to go if you want to write a rootkit, because they're fairly trivial to find. By hooking the IAT and so forth, they leave a really big footprint that you can look for, because you know the range of the DLL and so forth. So you can look for jumps outside of an acceptable range and then flag those. So vice was to take care of that. Also, hooking even in the curls, usually it's a little bit old school now. It's been around for at least... Six years, probably, in public source stuff. And maybe in the Linux world even longer than that. I'm not familiar with that. So, vice detects kernel hooks, 132 API hooks, and inline function patching. What I mean by that is when you would overwrite the first 5 bytes of a function, that's inline function patching. Also, the not only slide is if the device drivers in memory have a table of function pointers also. There's... Whenever you talk to a driver, you're talking through our request packet. So like when you use netstack to list all the available ports, you're talking actually under the hood to tcpip.sys. And you're passing it rp underscore mj underscore query. That's one of the ERPs you'll pass down to the driver. Well, there's a function pointer within the driver object that describes Well, there's a function pointer within the driver object that describes which function handles, or the address of the function that handles that particular ERP. So you can also hook there. However, I haven't currently come across any public rootkits that do that in the Windows world. And I'm doubting it's done much in the Linux world. I'm not sure of the format of the LKM structure. So I'll try to get to a vice demonstration now. And show you how it works. And... That you can use it when you go home. Okay, well... Let's run that key. I'll try to show it in a minute. If I have extra time. The key's not installed right now. So, to save the day, I have backup slides. So here's vice versus hacker defender. Hacker defender is a very good rootkit that's on rootkit.com. I believe it was written by Holy Father. And he's very knowledgeable. I've discussed rootkit stuff with him in email. Here's the vice output. I'm not sure if it's completely readable. But all these slides should be on your CD also. The things there with the embers glue. A little icon. You'll see it's hooking. There's something hooking kernel32.dll. And actually that turns out to be... In this case, way up top of the screen is NTDLL. So you might say, well, NTDLL is not a rootkit. That's correct. But the way it's used in the system... It actually hooks... It hooks other Windows API's occasionally. And so therefore it is a hook. And that's what vice catches. So, the thing with the Swiss Army knife. A little icon. That's all the functions that vice called hacker defender hooking. When possible, vice will output where on the file system you can find the hooking module in question. So that will allow you to go to the file system. And delete that bad DLL or whatever off of the system. In this case, it couldn't resolve hacker defender. Vice is, you know, a project still in the works. And maybe in the future we will be able to resolve that on the file system. So you can see it hooking things like create process and so on and so forth. It also gives you the address and memory. Vice does. So if you wanted to go and reverse engineer it yourself. And figure out exactly what their function is. You can do this. Here's vice versus vankwish. Vankwish is another popular rootkit at rootkit.com. And enough said about that. How many read KDM's paper on FRAC 62? Anyone? Okay, he stated that vice could not catch his rootkit called NT Illusion. Which is an entirely user land rootkit. This was correct at the time he tested. There was a bug in vice. And vice had not had any development on it since it was first written in mid-April. However, now that bug is fixed. And as you can see, it catches NT Illusion. What's noteworthy here is not only did it catch NT Illusion. It also lists where on the file system it is. So you can go delete it. So that was sort of the rootkit spin and hooking. We talked about how hooking is detectable. And now we're going to go into a little bit more of what consumers are currently doing in the world of trying to prevent viruses. Trying to prevent rootkits and so on and so forth. Everyone is running to third-party personal firewalls. And also host-based intrusion prevention systems. So what are HIDs? HIDs are host-based intrusion detection system. HIPs being host-based intrusion prevention system. What are they there for? They're there to detect what processes are running on the system. Maybe if a new process has started. Block access to things like netcat and so forth from running. What files are created or deleted or modified. That may be important to a HIPs. Like don't let anyone write to the WinMT or Windows system 32 directory. Because that's probably going to be a bad thing. HIPs also keep track of network connections made and possibly deny those connections. And they try to do a little bit with privilege escalation. And they look for buffer overflows and so forth. However for a lot of these different pieces of functionality. HIPs and the current security products rely on the operating system itself. So if you lie to the operating system. You lie to the HIPs. Here's some different functionality that's built into the operating systems today. That allow HIPs to work. If it allows the HIPs to work. It can also probably. You could use this as a starting point to where to look. To try to unlink a HIPs. For instance. In your kernel. So you can register OS provided callback functions. For instance. If you want to be notified every time a process is created. You can register an address to be called. In that case. And the kernel will do so. That works for threads also. Images loaded into memory. There's all these different pieces that HIPs use. To detect new things coming into the kernel. Or coming into the process. You can hook these. You could remove. These are nothing more than a linked list of functions to call. You could remove a HIPs product from that linked list probably. Without a whole lot of problems. Some HIPs actually hook the system call table. You have to do that. Especially on Windows. If you want to. If you want to filter on registry key access. Because there's no easily. There's a user land API that you can call for a callback. When a registry key changes. Or any of its children. But it doesn't provide you much useful details. It just says hey something changed. And you would have to reparse all the keys. To figure out exactly what it was that changed. And therefore you'd have to sort of keep state. Like before and after. That's not very useful. So HIPs for the most part just hook the system call table directly. HIPs can hook user land API functions. How many saw the FRAC article on bypassing third party Windows buffer overflow protection? Okay that was done by myself and two other anonymous co-authors. Who I'd like to thank. And they know who they are. So anyway. Some products were hooking the user land APIs. And we wrote some shellcode and so forth that totally bypassed. Their implementation of buffer overflow protection at the API level. And then you can query the kernel of course. So if you want to know what network connections are open. You can query the kernel and it will tell you. Well there's a problem with a lot of these HIPs designs. And it goes back to the FRAC article really. It requires that they be on the execution path of any malicious code. And they have to know where that execution path would be ahead of time. So there's no reason that we have to use the APIs in the kernel or even in user land. So the ones that we know that they're watching. We don't use those APIs. And I'll introduce DECOM in a second. Which uses absolutely no APIs to make its changes. It may use some APIs once in a while to gather information. But this is really benign information that would never be blocked anyway. So let's talk about operating system design quickly. Intel has four privilege levels. Or four rings as you see here demonstrated. However, Microsoft and other OS vendors do not use all four of these rings. They only use two. There's ring zero of course which is completely privilege code. Which is the kernel itself or device drivers or LKMs. Then there's ring three. Ring three is all applications. So when you're running in ring three. For instance, ring three is just ring three. Like the HIPs doesn't have any more privilege than you do at that point. If it's only implemented at ring three. Which is the case of some of these 132 buffer overflow protection mechanisms. Ring zero you have access to all of kernel memory. So everything that the kernel uses like objects to keep track. The kernel is more or less a big accounting arm. So it's keeping track of all the processes. All the ports and so forth. And it does this in structures that Microsoft calls objects. So these are kernel objects not to be confused with C++ objects. So once you have this no separation of powers. There's only two privilege levels. Every single device driver has access to all these accounting objects that the kernel has access to. Therefore you can modify it just as much as the kernel can. You just have to be very careful how you do so. You have to understand what the structures are. How to find them. What they do. And how the kernel expects them to look. So if you don't understand those important details. You may modify an object in memory and cause a blue screen. There are so many third party device drivers. I mean there's your printer drivers. Your fax drivers. All these different things. And there really should be different levels of protection between the two. Between the kernel and the drivers. So the next generation of rootkit technology is DECOM. It's a play on obviously Microsoft's terminology. But in this case direct kernel object manipulation. So what does it do? It modifies objects directly in memory. Never going through APIs. So there's well known APIs to for instance add a SID to a token in a Windows process. Well. First of all the kernel is going to see if you have the appropriate privilege to add that SID. And it may stop you there. Also the HIPS or other third parties may wrap around that function flow. The function control flow. And try to intercept that call. And limit you there. But if you write just directly to the memory. There's nothing to stop you. So you can use DECOM to hide a process. Add a privilege to a token. Add groups to tokens. Cool application is to fake out the Windows event viewer. So that if a user. I should say if a process spawns another process. Such as netcat. If the administrator has detailed process logging turned on. In the Windows event viewer. They will see. An event that says that administrator. Or whoever you're logged in as. You know just started. CMD or regedit32 or whatever. Well. If you change your token. To look like someone else's. Just by changing a couple bytes. Then the administrator will be thrown off. Because it'll look like. You can make it look like system did it. So system just spawned netcat. Now obviously that's going to be a red flag. To any halfway competent administrator. However it's not going to point at possibly. The user account that you subverted. It's going to be a red herring. That they're going to have to chase. For a couple weeks probably. Before they really figure out what happened. And maybe they'll never figure it out. So another thing of DECOM. You could use it to hide ports. Currently the FU rootkit does not hide ports. But you can do it. So obviously the implications of hidden processes. The hidden process can have. Potentially full control of the system. There's no accountability. It defeats the. Heads and hips type of paradigm. And it can skew the results of forensics. It all depends on how. How advanced your forensics are. But you only have to. Be overcome the slowest. Forensic tools. For the most case. So how would you go about. Hiding a process in the Windows kernel. Here's a. Here's a picture of how the objects look. In memory. The. The kernel has a. Processor control block. It's represented there at the top. Within there's three key pointers. One is to the current thread. One is to the next thread. And one is to the idle thread. So you need to find. Your current thread. Because that's going to lead you to your current process. So you go to the processor control block. Follow that pointer to the current thread. That's represented there by the E thread block. That's sort in the middle of the diagram. The E thread block. Or object contains a K thread object. Completely embedded within it. At the beginning of the E thread object. And that contains a pointer. That leads to. The E process block. Every process in a Windows. Operating system has to have at least one thread. And it has an E process block. So. These structures are. For the most part undocumented. Some of them now are becoming a little bit more documented. However they change a lot between versions of service packs. And also major versions of the operating system. So you have to do. At first when I did this. Two years ago. It was all reverse engineering. Now you can use Win debug. Load up the symbols appropriately. For whatever version of the kernel you're using. Type D T space M T. Bang. Underscore. Object name. And if you don't know what the object name is. You can wild card it. To try to narrow it down. I will tell you that not all the object numbers are documented. Like Microsoft may just say. Oh it's a. It's a P void. And so you don't know what. It actually leads to. And of course that takes a bit more time to figure out. So within the E process block. There's a. There's a list entry structure. It contains two pointers. The first one is called a flank. And the second one is called a blink. A flank is a forward link. And a blink is a backward link. So this list of E processes. If you would just keep following the flanks. It's completely circular. Also if you just keep following. Well you'd have to do like. D reference blink. And then add four. To get to the. Blink behind you. And keep following the chain. That way. You could go backwards through the list. Also. So if you want to hide a process. The kernel. Processor control block. Is located at a fixed address. Also if you don't trust that. Because I haven't verified that since 2000. Um. You can use the FS register. To always get the address of that kernel. Uh. Kernel processor control block. Also. Um. Within there. We talked about. That you can get the current thread running. And there's the assembly command. Well. Um. You would just move that into like. EAX. The FS colon. Um. Bracket. 124. And that would get you to an E thread. The E thread takes you to the K thread. And the K thread. Takes you to the E process block. So to hide a process. All you need to do. Is change the E process block. In front of you. To point to the E process block. Behind you. And the E process block. Behind you. To point to the E process block. In front of you. And I think. I have a demonstration of that. Or. Graphic. So here. Sorry. I don't have a. A pointer. But we're trying to hide. The current process. So. If you just. It's the. E process block. That's in the center. So you would want to modify. The flink. Behind us. To point. To the flink. In front of us. And that's represented there. Once you do that. Half the game's done. Now you have to change the. The blink. In front of us. To point. To the flink. Behind us. Like that. So you just tell your neighbors. Hey. You know. Point around us. So. Why does this continue to run? Well. It turns out. That the. The scheduler. In windows. Is extremely advanced. And. It's thread based. But. However. The reporting mechanisms. Are process based. So you can edit the. This. E process block. And. All your threads. Still get scheduled. Because. They're off. In their little threads. And. So they'll continue. To run. I'll just cover this. Really quickly. Because. Linux isn't my strong point. And. I haven't looked at it. Since it came out. With the new threading model. In. Linux 2.6. But. Within. The Linux kernel. You could do a similar thing. However. There's. Sort of. A gotcha. At the end. The Linux kernel. Contains. An array. Of task structs. So. Each task struct. Represents. Process. A task. Struct. Contains. A link. List. With. The pointers. Previous. Task. And. Next. Task. That. You. Can. Also. Follow. Around. The. Circle. And. It. Contains. Two. Other. Vital. Pointers. Which. Are. Previous. And. The. Task. Like. Demonstrated. In. The. E. Process. Block. Exact. Same. Concept. You. Leave. Next. Run. And. Previous. Run. Alone. Does. Anybody. Know. What. Happens. When. You. Run. What. Speak. Up. Okay. The. Whole. Process. Freezes. So. Nothing. Your. Process. Does. Not. Continue. To. Run. And. The. Reason. Being. Is. Because. The. Way. That. Processes. Get. Scheduled. Time. On. A. Linux. Two. Point. Four. Kernel. In. Which. Case. The. Scheduler. Walks. Around. The. Previous. Run. And. Next. Run. List. So. It. Follows. The. Next. Or. I'm. Sorry. Follows. The. Previous. Task. Or. The. Next. Task. List. Walks. Around. This. Link. List. Going. To. Each. Task. Structure. Within. Memory. Based. Upon. It. Calculates. A. Goodness. Value. The. Ordering. There. Well. If. You're. Never. In. The. In. The. Next. Task. Listing. Then. You'll. Never. Get. Your. Goodness. Value. Calculated. So. You'll. Never. Get. Scheduled. Again. Because. This. The. Scheduler. Can't. See. You. This. Is. Probably. All. Different. In. The. Two. Six. With. The. Threading. Model. There. Was. A. Root. Kid. On. After. I. Hit. This. Problem. There. Root. Kid. That. I. Found. Online. That. Was. Open. Source. Is. Fairness. More. Yeah. Believe. Is. The. Name. And. This. Person. Had. Come. Across. The. Exact. Same. Problem. I. Was. Having. And. They. Figured. Out. The. Only. Way. To. Fix. It. Was. The. They. Were. Fix. It. Was. To. Patch. The. Scheduler. So. What. But. The. Solution. Did. Was. The. Process. Is. Always. The. First. Process. That. Has. No. No. Parent. Process. So. The. Parent. Processor. Or. Parent. Process. In. The. Calculated. Goodness. Value. For. Them. But. If. You. Go. Through. All. That. Effort. They. Probably. Better. Ways. To. Hide. Your. Process. So. You. It. Be. Noted. That. You. Can. Use. So. You. Have. To. Use. Some. Kind. Of. Synchronization. Objects. To. Try. To. Get. Access. To. These. Lists. If. You. Want. To. Completely. Modify. Or. Modify. A. Safe. Manner. In. Windows. If. Want. To. Modify. The. List. Of. Active. Processes. There's. A. Non-Exported. Symbol. Called. PSP. Active. Process. New. Text. The. Kernel. Every. Services. I. These. Symbols. Are. Not. Exported. So. We. Have. To. Find. Another. Way. To. Come. Up. With. Synchronization. One. Way. You. Could. It. Is. You. Could. Hard. For. A. Known. Pattern. In. Memory. You. Know. That. There's. Going. To. Certain. Functions. Within. The. Kernel. That. Have. To. Access. These. New. Texts. In. Order. To. Operate. Safely. So. You. Could. Do. A. Certain. Way.