The Metasploitable virtual machine is an intentionally vulnerable version of Ubuntu Linux designed for testing security tools and demonstrating common vulnerabilities. First download metasploitable2 VM from here :
https://sourceforge.net/projects/metasploitable/files/Metasploitable2/
then extract the files from zip archive.
Now start the Virtualbox Application and click on 'NEW'
and put Name: Metasploitable2, Type:Linux, version: Ubuntu(64-bit) and then click on 'Next'
in 'Memory size' set it on 512 MB and click 'Next'
Now at that point just go to the extracted VM files folder and copy the
"Metasploitable.vmdk" file to Metasploitable2 folder which exists in "Your_User_Directory/Virtualbox VMs/"
now copy the "Metasploitable.vmdk" to 'Metasploitable2' folder
Now come back again in Virtualbox application and in 'Hard disk' Choose the third option 'use an existing viirtual hard disk file' and then select the "Metasploitable.vmdk" file in "Your_User_Directory/Virtualbox VMs/Metasploitable2" directory and click on 'Create' button.
now at Virtualbox click on File menu then Preferences
now at Preferences click on the Network tab and then Host-only Networks tab
now click on the green '+' sign on the right side of the box to add new host-only network
then click on the third screw driver button 'edit selected host only network' option
then click on the 'DHCP Server' tab and check 'Enable Server' option and fill-up the below information
Server Address : 192.168.56.1
Server Mask : 255.255.255.0
lower Address Bound : 192.168.56.101
Upper Address Bound : 192.168.56.254
then click OK and again click OK on 'Preferences'. Now on VirtualBox select Metasploitable2 and click on 'Settings'
then click on Network tab and 'set Attached to :' to Host-only Adaptor and then click OK.
Now on VirtualBox select Metasploitable2 and click on 'Start' button.
then wait for the startup of Metasploitable2
now put login user : msfadmin , password : msfadmin
now at terminal prompt type command 'ifconfig eth0' and in command output the address appeared in front of 'inet addr' is IP address of Metasploitable2 VM.
Now to access the Metasploitable2 Apps open Your Web Browser and type 'http://Metasploitable_IP_Address' and in my case it is http://192.168.56.101
and Thats it, Metasploitable2 up and running. now in order to set this ip address static for Metasploitable2 follow the below steps. type the below commands
sudo su
now it will ask the root password, just type msfadmin, then open a file /etc/network/interfaces with nano editor
nano /etc/network/interfaces
and erase the last two lines of opened file which is
auto eth0
iface eth0 inet dhcp
and put the following content
auto eth0
iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.1
broadcast 192.168.56.255
gateway 192.168.56.1
dns-nameservers 192.168.56.1
Now to save the file type Control + O and then type Control + X to exit to text editor. then edit another file called resolv.conf with the following commandnano /etc/resolv.conf
then change the 'nameserver 10.0.2.3' to 'nameserver 192.168.56.1' and again type Control + O and then type Control + X to exit to text editor. Then just reboot the metasploitable2 with 'reboot' command and we are done.
Note : If the Metasploitable2 hung up at reboot then you can forcefully restart the VM by going "Machine > Reset" option at menubar.