












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Group Number: _______________ Member Names: _________________________ _________________________ Date Assigned: September 21, 2004 Date Due: September 28, 2004 Last Edited: November 12, 2004, 2004 Please read the entire lab and any extra materials carefully before starting. Be sure to start early enough so that you will have time to complete the lab. Answer ALL questions and be sure you turn in ALL materials listed in the Turn-in Checklist ON or BEFORE the Date Due.
computer by someone who has already gained access and wishes to keep it and perform other tasks while remaining hidden.
and one for Windows. The first one is a traditional rootkit named lrk4, which is one of the most popular and stable rootkits available for use. The second one is a kernel level rootkit named Knark. We will also look at four ways of seeing if a rootkit is installed, by using kern_check, chkrootkit, strace and Rootkit Hunter. For Windows XP we will use a rootkit called Hacker Defender. This rootkit allows us to hide files and processes and creates a backdoor on the machine that has it.
would be difficult and time intensive, today there are dozens and dozens of common rootkits that are posted online for anyone to use. Using them just becomes a matter of reading and understanding the README file. In this way, all sorts of people have access to rootkits and discovering them on a system becomes a huge task in itself. We will see both how some rootkits are discovered and how some can go hidden if proper precautions are not taken or ineffective software is used.
and Windows XP Virtual Machine. It is assumed for this lab that we have already gained root access to our victim machine, though in reality this would have been an extra process, but for this lab we just want to focus on rootkits.
First, we make a backup of the Linux 7.2 virtual machine by going to the /root directory in the Linux 8.0 machine and typing (assuming RedHat7.2.2 is the name of your folder): #cp –r RedHat7.2.2 RedHat7.2.2.bak
The lrk4 rootkit exploits several different binaries and allows a hacker to gain access to a machine using a hacker password and also allows the hacker to hide what he or she is doing. All of the files you need can be found on the NAS, in the folder “Lab5”. You can access the NAS as you did in previous labs, by mounting it just like a floopy or CDROM. On your RedHat 7.2 virtual machine, Copy the lrk4.unshad.tar.gz and chkrootkit-0.39a.tar.gz file to the /home directory. Copy the two files from the “rpms” folder to /home/tools. At this time, also copy knark-2.4.3.tgz into the /home directory and kern_check.c into /home/tools directory, these will be used later. You will want to run the rest of the lab in runlevel 3 of linux, so that you are not in startx. To do this, in a terminal type: #init 3 Give it a few seconds. Log back in as root and create a user account called “user1” with the following command: #useradd user Then select a password for this user with the following command: #passwd user When prompted for a password, type one in and then re-type it at the next prompt. Now, type exit at the prompt and you should be returned to the login screen. Log in as user1; once you have logged in, type “ whoami ”. Q1.1: What do you see? Type exit again, and now try logging on as root, but use a wrong password and notice the error messages you get. Also notice that with an incorrect login, you still get the original login prompt. Keep this in mind. Go ahead and log in properly now. Q1.2: Check the date and the size of the login file and record it(use ls –l /bin/login ). Unzip the lrk4.unshad.tar.gz file to the /home directory. Unzip the file using the following command: #tar xvfz lrk4.unshad.tar.gz Now, before we can use the rootkit, we need to install a couple of libraries. Go into the “ tools ” directory and install the two library rpms using the following commands: #rpm –i ld.so-1.9.5-13.i386.rpm #rpm –i libc-5.3.12-31.i386.rpm
he/she will only have the privileges of that user. You can’t log on using a username that doesn’t exist. You can try this by typing “exit” and then trying to log on using the username “user2” and the hacker password; this will give you an error. Now, type the username “rewt” and password “satori” to log onto the system. Once you have logged on, type “whoami”. Q1.7: What permission level do you have now? So you can see how a hacker can get easy access to a machine using the “rewt” username and “satori” password. Summarize the differences between the normal and corrupted logins (messages, displays, etc.) on the separate page and turn that page in with the lab. But how does a hacker hide the corrupted login file? By using the “touch” program included as part of the linux. Touch will overwrite the date of a file with a new date. In this case, we want to use the date of the original login, so type: #touch –r /bin/backup/login /bin/login Now, go into the /bin directory and type ls –l login* and see what the output is. Q1.8: Record the output and what you think has happened. You should see that the date of the trojaned login file has been changed to that of the original login file. Q1.9: However, how do you know that the current /bin/login file is actually the corrupted login file? Q1.10: Also, type exit and try logging on as “rewt”. Can you log on? Attachment 1: Write up a summary that details how an administrator would know that a system had been exploited, i.e. file sizes, differing messages during login process, etc. There are several different programs available to check whether a system has been exploited or not. One of these is a tool called chkrootkit. The version we will be using in lab is 0.39a. Unzip the file chkrootkit-0.39a.tar.gz , and it should create a directory named chkrootkit- 0.39a. Go into this directory and type make sense. This will compile all the auxiliary files that chkrootkit will use. Before you start using chkrootkit , copy the original login file from the /bin/backup folder to the / bin folder. Now, go into the chkrootkit-0.39a folder and type the following command: #./chkrootkit login This will run chkrootkit on the login file to check if it’s infected. You could just run chkrootkit without any options, but then the output would be very long and searching for the output from the login file would take some time. Since we know that no other binaries on the system are corrupted, we can just run chkrootkit on the login file. Note that the output you get should show that the login file is not infected.
Now, copy the corrupted login file ( /home/lrk4/bin/login ) to the /bin folder, overwriting the original login file. Run the above chkrootkit command again. You should now see that the login is listed as infected. Chkrootkit simply checks the login file for the occurrence of the string “root”. Since the original login file doesn’t have the string “root” in it but the corrupted login file does, this alerts chkrootkit as to whether a file is infected or not. Ls Now we are going to overwrite the ls command, also in /bin, with rootkit’s ls command. Doing this we will be able to hide any folders and files that would appear during an ls command. Again, copy the original ls to the backup folder: #cp /bin/ls /bin/backup Now, in the lrk4 directory, go to fileutils-3.13/src. You should see more precompiled files, including ls and dir. We will only be using ls , but obviously a real hacker would put on all these if they wanted to hide something. Copy the ls file to the /bin directory. The corrupted ls is designed to hide files and folders listed in a specific data file, /dev/ptyr (dev is chosen because it is a large directory that has many files of similar names, so it is hard to notice one new one). No such file currently exists, so this ls command works just like the original. Now, create the /dev/ ptyr file with any text program and put in the following: lrk file.hide Now, go to the /home directory and create the file, file.hide , just an empty text file is fine. Use the dir command. Now, use the ls command. Q1.11: What is different about the two outputs? Notice that you can still cd into the lrk4 directory and open the file.hide. This corrupted ls command does not affect the files at all, it just accesses the ptyr file and suppresses anything in there, feel free to try other folders and files. The hacker can now leave a folder full of rootkit tools, such as packet sniffers and the files of data collected and without knowing specifically what to look for, the administrator would not see them. The ls command works separately from the login command, so either can be installed without the other, and the ls command would also need to be “fixed” to cover its tracks more. Another drawback to the trojaned ls is that is uses different system calls, which can be seen by using the built in function, strace. With the corrupted ls program in place, in the /home directory, type: #strace –c ls Q1.12: The –c counts the total number of system calls, what is the total number? Now, copy the original ls from the backup folder, again in the /home directory use strace on ls. Q1.13: What is the number of system calls now? Make sure that you copy your original ls and login commands back.
Chkrootkit uses some tricks when detecting rootkits because it knows the default behavior. Q2.3: What trick could chkrootkit use to detect Knark, and how could this be avoided by Knark? The README file in the knark-2.4.3-release folder gives information on some of the programs knark has. We will be looking at the hidef and ered programs specifically. The hidef program is used to hide files and folders. To use, type (in the folder where knark is insalled): _#./hidef _ Hide lrk4 and file.hide with this function, then, in the /home directory, try ls and dir. Q2.4: Do either show the file? To see which folders and files are hidden, you can always type: #cat /proc/knark/files To unhide the files, in the knark directory, type: _#./unhidef _ What is powerful about a kernel rootkit is that the ls and dir binaries are not changed, you can confirm this by looking at the size and date of each, the LKM just redirects the system calls used, so even a clean ls or dir running off a floppy would not show the hidden files. Q2.5: Again in the /home directory, use strace to count the number of system calls, is this a useful way of trying to detect a kernel rootkit? Why or why not? The program ./ered redirects execution of a command from one file to another. This means that instead of copying our trojaned login from lrk4, we can leave the original login in place and run the corrupted login by typing: #./ered /bin/login /home/lrk4/bin/login Q2.6: The login now works the same as in the first part of the lab (including the error where our root password does not work), but what is the date and filesize of /bin/login? Your redirections can be seen by typing: #cat /proc/knark/redirects And can be cleared by: #./ered –c Q2.7: Pick another Knark function and explain how it is used and what it would be good for (think of hiding what the hacker has done/is doing, use the README file). Include an example usage and screenshots if necessary.
At this point, you probably feel confident that rootkit detectors can adequately protect a system. Well, let’s see if that is really the case. Can we always trust that such tools will do an adequate and reliable job in detecting and identifying rootkits on our machine? Go to this website: http://www.rootkit.nl/. We think this website has a nice layout. Go ahead click on the “projects” link then the “Rootkit Hunter.” Notice the statement, “Rootkit scanner is scanning tool to ensure you for about 99.9% you're clean of nasty tools.” 99.9% is a pretty bold claim. If you look on this webpage further, you will notice that it says it can detect LKMs and suspicious binaries. So let’s test its ability to do so. Go ahead and copy the rkhunter-1.00RC3.tar.gz for the NAS to your /home directory in your RedHat 7.2 virtual machine and go ahead and do the following commands. #tar zxvf rkhunter-1.00RC3.tar.gz #cd rkhunter #./installer.sh This will install the Rootkit Hunter tool. Make sure you have the Knark LKM installed, and also go ahead replace the login binary program from the lrk4 rootkit like you did earlier in this lab (make sure to back up your valid login program). We are going to see first if it can detect these anomalies like it advertised. Run the rkhunter program by executing this command. #rkhunter --checkall --createlogfile Some nice color text output will start scrolling on the screen. Hit the enter key until you reach a screen that looks like Figure 1.
Figure 2. A False Positive on the BeastKit rootkit. So what is going on here? It was rather easy to fool this rootkit detector. Let’s open the log file rkhunter wrote by executing this command: #gedit /var/log/rkhunter.log Scroll down the text file a little bit and you should see the warning of finding the arobia file like in Figure 3.
Figure 3. Rkhunter log showing that it found the arobia file. Attachment 2: Go ahead and print out this log and include it with everything else you have to turn in. If you scroll through the rest of the log, you will notice that all this program does is just scan through certain directories and looks for a name match on a file. All that a savvy hacker has to do is rename his rootkit files and this “detector” will not detect the danger. You might as well remove the /usr/sbin/arobia harmless text file. We do not want to set off more false alarms. Also, replace the /bin/login binary file with the real, correct login file. The point of this exercise is to realize that implementing security requires good investigation in the tools that are relied on. As we have found out here, it is clear that not all rootkits are equal nor do they always do what they claim. Rootkit Hunter could easily create trouble for an inexperienced administrator. An experienced hacker, knowing this detector was on a system, can create a false positive and put in rootkits that this detector could not detect. Hence, the administrator’s attention will be incorrectly placed. Good information security not only requires vigilance over one’s systems but also vigilance over the systems’ security tools. You can now remove Knark from your system. Knark should remove itself when you reboot the computer. Check this with kern_check. If it does not, or if you have lost your original login or ls file, you can reset your virtual machine to what it was before you started the lab by going to your Linux 8.0 machine and in the /root directory typing:
#cp –r winXPPro winXPPro.bak (assuming winXPPro is the name of your folder) Now start you Windows XP Virtual Machine. The remainder of the lab will be done on this machine. This rootkit rewrites memory segments in all running processes to change their behavior. It has been available for about a year and would be detected by almost any antivirus program. For more on the program and its usage than what is in this lab, see the readme file (readmeen.txt) or go to the website. Copy all the Lab5/Windows folder files from the NAS to a new folder on your Desktop named “hacker”. This rootkit is run by typing the executable, hxdef100.exe, and specifying a .ini file to use. The .ini file has information on what files, processes or ports to hide, as well as information on the backdoor it creates on the system. We will be using kitfile.ini for this lab, you can double click on it and it will open in Notepad. There are 9 headings required, though we will only be looking at a few in this lab. The first heading, [Hidden Table], is the list that tells the program what files, directories and processes to hide. Right now it has root* and rcmd.exe as the only entries. This means that it will hide any file, folder or process that starts with root and the rcmd.exe process. The next heading, [Root Processes], is a list of programs that will be “immune” to the infection, meaning they will still be able to see hidden files and processes. [Hidden Services] is a list of services that will be hidden from the database of installed programs. In [Settings], the last heading, is information on backdoors as well as how things are run, we will not be modifying this part at all, but make note of the Password. For more information on what all these do, again, see the readme file. Create a folder on your desktop called “roottest”. Go to StartRuncmd. cd to the “hacker” folder with the rootkit files. Type: hxdef100.exe kitfile.ini You have just installed and run the rootkit. On your desktop, Right Click and go to Refresh. Q5.1: Can you still see the folder you just created? Now hold ALT + CNTRL + DELETE and click on the processes tab to see what is running. Q5.2: How do we know that Hacker Defender is running on our machine? Now it is time to hide the Hacker Defender process. Open up kitfile.ini and add the following line under [Hidden Table]: hxdef* Save the file.
Q5.3: Again look at what processes you are “running,” are you still able see that Hacker Defender is running? You can do this with any process, i.e. IE (Internet Explorer) but you would need to be careful hiding some system process that would stop you computer from functioning properly. Just for fun I added * to [Hidden Table] and hid all files and processes, of course, I was not able to run anything after that and could not even stop Hacker Defender from running, luckily I had backed up my Virtual Machine image and did not lose everything. Now we will use the backdoor feature of the rootkit. Once the rootkit is installed, all TCP ports become potential backdoors. This includes port 80, used for web servers. One of the web servers on the network has been infected with this kit, using a .ini file similar to yours, so the backdoor has the same settings. The server is http://57.35.5.16, which is the StorageRus Webserver. You can see the home page by typing the IP address into a web browser. The file bdcli100.exe will let us remotely connect to this server, through port 80, with administrator privileges. Again in your cmd window, type: #bdcli100.exe 57.35.5.16 80 hxdef-rulez This is the host, port and password to use when connecting. Because we have hidden Hacker Defender processes and rcmd.exe, there is no simple way of seeing that we have connected. Also, it was shown in tests that IIS does not log any of this connection. Once you have logged on through the backdoor, you might as well have some fun. In c:\ Inetpub\wwwroot is a file called default.htm. This is the homepage for the web server. You can edit a file by typing: _#edit _ Do this with default.htm and add your group number, names and a brief message in the body so it shows up on the homepage. Pressing ALT brings you to the menu options on the top of the screen, save your file and exit. Now type: #exit You have just terminated your backdoor connection. On your own machine type: #net stop HackerDefender Make sure the hidden files are revealed. This ends this portion of the lab. Again, if something was lost or damaged, you can delete this Virtual Machine folder and use the backup you made at the beginning of this section with: #rm –rf winXPPro #mv winXPPro.bak winXPPro
Q6.2: Does the rootkit detection software find any evidence of sucKIT? If so, what does the warning look like? Run the following command in the chkroot directory: ./chkproc -v Q6.3: Record the output you see on the screen. What information alerts you to a possible infection? To uninstall the rootkit, type:
Answer Sheet Lab 5 Group Number: _______________ Member Names: _________________________ _________________________
Q1.1: After logging in as user1, what do you see? Q1.2: Check the date and the size of the login file and record it (use ls –l /bin/login). Q1.3: (In /home/lrk4/bin) What is the size and date of this login file? Q1.4: (After logging in as root with password “satori”) Once you have logged in, type “whoami”. What is displayed? Q1.5: Type “exit” and log in as user1 with the password you chose. Type “whoami” and record what is displayed (your password still works here). Q1.6: Type “exit” and now try logging in with username “user1” and password “satori”. Can you log in? If you can, run “whoami” and record what you see. Q1.7: Now, type the username “rewt” and password “satori” to log onto the system. Once you have logged on, type “whoami”. What permission level do you have now?
Q2.3: What trick could chkrootkit use to detect Knark, and how could this be avoided by Knark? Q2.4: Do either show the file? Q2.5: Again the /home directory, use the strace to count the number of system call, is this a useful way of trying to detect a kernel rootkit? Why or why not? Q2.6: The login now works the same as in the first part of the lab (including the error where our roott password does not work), but what is the date and filesize of /bin/login? Q2.7 Pick another Knark function and explain how it is used and what it would be good for (think of hiding what the hacker has done/is doing). Include an example usage and screenshots if necessary.
Q4.1: On your desktop, Right Click and go to Refresh. Can you still see the folder you just created? Q4.2: How do we know that Hacker Defender is running on our machine?
Q4.3: Again look at what processes you are “running” are you still able see that Hacker Defender is running? How long did it take you to complete this lab? Was it an appropriate length lab? What corrections and or improvements do you suggest for this lab? Please be very specific and if you add new material give the exact wording and instructions you would give to future students in the new lab handout. You may cross out and edit the text of the lab on previous pages to make corrections. What corrections and or improvements do you suggest for this lab? Please be very specific and if you add new material give the exact wording and instructions you would give to future students in the new lab handout. You need to be very specific and provide details. You need to actually do the suggested additions in the lab and provide solutions to your suggested additions. Caution as usual: only extract and use the tools you downloaded in the safe and approved environment of the network security laboratory.