7.3. Hiding ProcessesAdore is a popular LKM-based rootkit. Among its many features, it allows a user to hide processes by altering the /proc system's readdir handler. Download the Adore rootkit at http://packetstormsecurity.nl/groups/teso/. The /proc system stores a lot of system information, including process information. For example, let's assume sshd is running on our system. You can use the ps tool to obtain sshd's Process ID (PID): [notroot]$ ps x | grep sshd In our example, the sshd process's PID is 1431. Let's look in /proc/1431 to obtain more information about the sshd process: [notroot]$ ls -l /proc/1431/ As you can see, the /proc filesystem also stores process information. The ps tool uses the /proc system to enumerate the processes running on a system. In this section, we will use Adore's techniques to hide a given process with an LKM that we will call hidepid. For example, let's create a simple process we want to hide: [notroot]$ sleep 999999 & From the preceding sleep command, we know process 4781 will be available for 999,999 seconds, so we will attempt to hide this process. The hide_pid( ) function in hidepid.c expects a pointer to /proc's original readdir handler, as well as the new readdir handler. First, the function attempts to obtain a file descriptor by attempting to open /proc: if((filep = filp_open("/proc",O_RDONLY,0))==NULL) The pointer to /proc's readdir handler is stored so we can restore it before the LKM exits: if(orig_readdir) Next, /proc's readdir handler is set to new_readdir: filep->f_op->readdir=new_readdir; The hide_pid( ) function is invoked with the following parameters upon initialization: hide_pid(&orig_proc_readdir,my_proc_readdir); Because my_proc_readdir is passed as the second parameter to hide_pid( ), which corresponds with new_readdir, the LKM sets /proc's readdir handler to my_proc_readdir. The my_proc_readdir( ) function invokes the original_proc_readdir() function but with my_proc_filldir as the handler. The my_proc_filldir( ) function simply checks if the name of the PID being read from /proc is the same as the name of the PID we are trying to hide. If it is, the function simply returns. Otherwise, it calls the original filldir( ): if(adore_atoi(name)==HIDEPID) When the LKM is unloaded, restore( ) is invoked to reset /proc's readdir handler: if ((filep = filp_open("/proc", O_RDONLY, 0)) == NULL) 7.3.1. hidepid.cFollowing is the full source code of our hidepid LKM: /*Thanks to adore-ng from Stealth for the ideas used in this code*/ 7.3.2. Compiling and Testing hidepidTo test the module, use the following makefile: obj-m += hidepid.o Compile using the following make command: [notroot]$ make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules Test the module by executing ps to list the sleep process we initiated earlier: [notroot]$ ps a | grep 4781 Insert the module: [root]# insmod ./hidepid.ko Now, the sleep process is no longer visible: [notroot]$ ps a | grep 4781 Remember to remove the module when done: [root]# rmmod hidepid |