Metasploit for the Aspiring Ethical Hacker, Part 2

Part 1 is here: https://linuxsecurityblog.com/2016/03/01/metasploit-for-the-aspiring-ethical-hacker-part-1/

In this second tutorial, we will look at some of the basic commands we can use in Metasploit. Although the Metasploit framework can appear daunting to the uninitiated, it is actually a very simply framework for system exploitation. If you can learn a few keywords and techniques, you can use Metasploit to hack just about any system.

Linux Courses on sale NOW!!

Metasploit Keywords

Undersatnding and using a few keywords in Metasploit can help you navigate and operate this powerful piece of software. Let’s look a few of the most basic and necessary Metasploit commands. This is far from an exhaustive list of Metasploit keywords and commands, but it covers the basic commands you need to function in Metasploit until you gain more experience.

1 Show

“Show” is one of the most basic commands in Metasploit. It can be used to show modules, such as show payloads, show exploits, etc. But, it also can be used to show options once we have an exploit chosen.

The “show” command becomes context sensitive when we choose an exploit, so that if we type “show payloads” before selecting an exploit, it will show us ALL the payloads. If we type “show payloads” after selecting an exploit, it will only show us the payloads that will work with that exploit.

2 Help

The “help” command will give you a limited list of commands you can use in msfconsole. If you lose this guide, simply type “help” to get some basic commands.

3 Info

“Info” is another basic command in Metasploit that enables us to see all the basic information about an exploit. After selecting an exploit, we can then type “info” and it will display all of the options, targets, and a description for the exploit. I prefer to type “info” on any exploit I am using to find or remind myself of its features and requirements.

4 Set

“Set” is a basic and critical command/keyword in Metasploit. We can use it to set parameters and variables necessary to run the exploit. These variables can include the payload, the RHOST, the LHOST, the target, URIPATH, etc.

In the screenshot below from my tutorial on using psexec to hack a system, we set RHOST, LHOST, SMBUser, and the SMBPass to hack the system without leaving a trace.

5 Back

When we are done working with a particular module or we chose the wrong module, we can use the “back” command to return to the msfconsole prompt.

For instance, if we chose an exploit and then realized we chose the wrong one, we can simply type “back” and then use the “use” command (see next section) to select another module.

6 Use

When we have decided which exploit we want to use against our target system, we use the “use” command to load that exploit into memory and ready it to send to the target system. An example can be found in my tutorial on using the Heartbleed vulnerability to grab information in memory from systems running OpenSSL.

7 Exploit

After choosing our exploit, setting all of our variables, and choosing our payload, the last thing we do is to type the “exploit” command. This launches the exploit against the target machine with the payload and any variables we might have set.

8 Sessions

The “sessions” command is used to list or set a session. When used with the -l (list) switch, it will list all open sessions. When used with a number (“sessions -1”), it tells Metasploit to activate the first session.

Metasploit allows us to run multiple sessions on the same system or multiple sessions on multiple systems. Using the “sessions” command, we can find these open sessions and switch to or activate them.