MetaSploit tutorial for beginners

This (updated for 2020) MetaSploit tutorial for beginners is meant to be a starting guide on how to use MetaSploit if you have never used it before. It assumes that you already have MetaSploit installed and that it works, or that you are running Kali / other pen testing distro of linux (eg Parrot or BlackArch).

The basic concept you need to use in order to know how to use MetaSploit is pretty easy when you have used the tool a few times and is as follows:
– Run msfconsole in your terminal
– Identify a remote host and add to the metasploit database
– Identify a vulnerability in the remote host that you wish to exploit
– Configure the payload to exploit the vulnerability in the remote host
– Execute the payload against the remote host

Once you have practiced and mastered this pattern, you can perform most of the tasks within Metasploit. As this is a MetaSploit tutorial for beginners, I’ll walk you through the steps you need to know to scan your first machine.

If you enjoyed this tutorial, please check out my metasploit tutorials below

Start the database service

In your favourite Kali Linux Terminal (I recommend terminator), run the following command to start up a database server on your machine. This database is used to store all your results (so that you can come back to them later on, or share the database with others if working on a team)

service postgresql start

If this is the first time you are running metasploit, then you will need to run the following command to create a database schema

msfdb init

You can now start metasploit using the msfconsole command from the terminal

msfconsole

or using the kali linux menu system you will find it under:

Exploitation tools > Metasploit

Once Metasploit has loaded you will meet with the following prompt in your terminal – the splash screens are random, so don’t worry if yours looks different:

MetaSploit tutorial for beginners - msfconsole
MetaSploit tutorial for beginners

This is msfconsole. Msfconsole is the main command line interface to MetaSploit. There are other interfaces available – GUI interfaces (armitage), and a web interface too (websploit). With msfconsole you can launch exploits, create listeners, configure payloads etc.

Getting help in metasploit

MetaSploit has lots of great documentation built in. You can access this documentation if you type help to get a basic list of commands.

help show

help show will give you the help section for the show command.

help search

help search will give you the help section for the search command.

If you get the error ‘Database not connected or cache not built’ use ‘db_status’ to see if the metasploit database connected. if the database is not connected then you need to start the postgresql database (instructions above) and re-start msfconsole. If ‘db_status’ reports ‘connected’ then you need to run the ‘db_rebuild_cache’ command to rebuild your metasploit database cache. Once you do this you will be able to run metasploit as normal.

#rebuild the database caches
db_rebuild_cache

Identify a remote host

You can now run an nmap scan from inside msfconsole and save the output into the MetaSploit database.

db_nmap -v -sV host_or_network_to_scan[eg 192.168.0.0/24]
MetaSploit tutorial for beginners
MetaSploit tutorial for beginners

This is a handy way to get an initial list of remote hosts on your network. I have some other tips in this linux commands for networking article.
To show a list of all available port scanners:

search port-scan

More examples of port-scanning remote machines and saving the output into the metasploit database are here:

To list all the remote hosts found by your nmap scan:

hosts

To add these hosts to your list of remote targets

hosts -R

MetaSploit tutorial for beginners – Pick a vulnerability and use an exploit

Once you have performed an operating system fingerprint (or you have identified the application running on the remote host, eg by imporing nessus results into metasploit) and know what your remote hosts operating system is (using nmap, lynix, maltego, wp-scan, etc) you can pick an exploit to test. rapid7 have an easy way to find exploits. There is also a way to search within msfconsole for various exploits:

search type:exploit
search CVE-XXXX-XXXX
search cve:2014
search name:wordpress

See metasploit unleashed for more examples of the search command

metasploit tutorial for beginners
MetaSploit tutorial for beginners

Once you have found a suitable exploit to use against the vulnerability in the remote host, issue the following command into msfconsole:

use exploit/path/to/exploit_name

eg: use exploit/unix/webapp/php_wordpress_total_cache

From this point on, the available options change based on the exploit you are using, but you can get a list of the available options with:

show payloads

For a list of the available targets:

show targets
Picking an exploit in metasploit
Picking an exploit in metasploit

MetaSploit tutorial for beginners – Configure the exploit

In MetaSploit each exploit has a set of options to configure for your remote host:

show options

This gives a list. You need to set the options with ‘yes’ next to them.

set RHOST 192.168.0.15

If you issue the ‘hosts -R’ command then you will see that the remote hosts parameters are already filled in for you.

Execute the exploit against the remote host

run

or

exploit

If metasploit is successful in exploiting the vulnerability, you will know – most likely it will pop a shell for you. If you don’t get a shell, then your exploit may not have worked – you may have to try a different exploit for the same vulnerability, or you may have to gain better information on your targets – perhaps you wrongly identified the version of the service.

Thats the very basics of using metasploit covered! I hope you enjoyed my basic metasploit tutorial for beginners.

If you enjoyed this tutorial, please check out my metasploit tutorials below

References which I used to make this guide:
Kali Metasploit Guide
hackthis – a beginners guide to metasploit
offensive security – metasploit unleashed – using exploits
offensive security – metasploit unleashed – msfconsole commands


10 Comments

nutesh · January 27, 2016 at 5:59 pm

what if no hosts are detected???

    312. · December 4, 2019 at 1:20 pm

    Then nobody to run anything against to.

siddhesh jadhav · January 28, 2016 at 7:23 pm

hey i am using kali 2.0 , I would like to use msf over wan or public domain . will you please suggest or make good article on it . thanks in advance

Anthony · March 29, 2016 at 11:46 pm

ok thank you so much for the help i just have one question how do i find the rports

Rio · December 3, 2016 at 2:06 am

how do i know which exploit to grab?

NE0 · July 26, 2018 at 11:47 am

typo on database start command, should be

service postgresql start

Mas Baz · May 6, 2019 at 10:21 pm

for how to install metasploit in the windows check here how to install metasploit on windows OS for how to install metasploit in the windows check here https://www.fhxploit.com/2018/05/cara-memasang-metasploitframework-di.html