Table of Contents
Metasploit is a widely used penetration testing tool that makes hacking way easier than it used to be. It has become an indispensable tool for both the red team and the blue team.
In this article, you are going to learn, how to use Metasploit, a penetration-testing platform for developing and launching exploits.
Metasploit gives you an awesome working environment. From web vulnerability plugins to network information gathering and from an extensive exploit development environment to commercial-grade exploits, you will hardly find any tool parallel to Metasploit.
Getting Metasploitable
Metasploit in Linux
Metasploit Framework comes preinstalled in Kali Linux.To launch Metasploit on Kali Linux Machine, navigate to Application Menu > Exploitation Tools > Metasploit-Framework.
Installing Metasploit on Windows
Metasploit Framework can be easily installed on a Windows-based operating system.
The following are the steps for the Metasploit Framework installation on Windows:
1. Download the latest Metasploit from Windows installer from GitHub.
2. Now click and the downloaded file:
3. Accept the license agreement:
4. Select the location where you wish to install the Metasploit Framework:
Why Windows XP?
As per my knowledge, Windows XP contains lots of vulnerabilities which means we will perform many attacks compared to today's Windows operating system.1. To launch, Metasploitable type the following commands:
Show <exploits | payloads>
Info <exploits | payloads> <name>
Use <exploits-name>
2. You’ll find all the other commands by typing “help” or “?”.
3. To lunch an MS08-067 exploit, we’ll first need to find The Metasploit name for this exploit. We can use the search command to do so.
Notice that the prompt changes to enter “exploit mode” when you use an exploit module. Any options or variables you set while configuring this exploit will be retained so that you don’t have to reset the options every time you run it. You can get back to the original lunch state at the main console by issuing the back command.
5. Different exploits have different options. Let’s see what options need to be set to make the MS08-067 exploit work:
6. This exploit requires a target address, the port number on which SMB (Server Message Block) listens, and the name of the pipe exposing this functionality:
set RHOSTS <the target IP address>
Set <OPTION-NAME> <option>
Note: Earlier versions of Metasploit were particular about the case of the option name and option, so examples in this chapter always use uppercase if the option is listed in uppercase.
7. With the exploit module set, we next need to set the payload. The payload is the action that happens after the vulnerability is exploited. It’s like choosing how you want to interact with the compromised machine if the vulnerability is triggered successfully.
For this first example, let’s use a payload that simply opens a command shell listing on a TCP port:
By default, this exploit will open a listener on the TCP port 4444, allowing us to connect for the command shell. Let’s attempt the exploit:
Notice that this is “session 2.” Press CTRL – Z to put this session in the background and go back Metasploit prompt. Then, issue the command sessions to list all active sessions:
13. It’s easy to bounce back and forth between these two sessions. Just use the sessions –i <session>. If you don’t get a prompt immediately, try pressing ENTER.
Exploiting Client-Side Vulnerabilities with Metasploit
A Windows XP workstation missing MS08-067 security update and available on the local subnet with no firewall protection is not common. The main purpose of this article is to preview, Client-Side vulnerabilities.
Have you ever seen this type of mail? If yes, then at the end of this article, you will find out how you can hack just through your browser.
The idea is to lure a victim to a malicious website or to trick him into opening a malicious file or e-mail. When the victim interacts with attacker-controlled content, the attacker presents data that triggers a vulnerability in the client-side application parsing the content. One nice thing (from an attacker’s point of view) is that connections are initiated by the victim and sail right through the firewall.
Metasploit includes many exploits for browser-based vulnerabilities and can act as a rogue webserver to host those vulnerabilities. In this video, we’ll use Metasploit to host an exploit for MS10_002.To know more about this read it from Microsoft's official website.
Exploit Windows XP using MS10_002
SRVHOST: Server IP addressSRVPORT: Server Port Address
A good link for that kind of attack might be http://<IP ADDRESS>/you_win.htm . In that case, you would want to set the URIPATH to you_win.htm. For this example, we will leave the URIPATH set to the default, “/”.7. Now run exploit:
I just send a spam mail to the victim. So I open my browser and open this site. From here I will send an e-mail to the victim.
When the victim found the mail and click that link. When The victim clicks the link, you got the session:
The usage of meterpreter is not similar to other payloads.
Penetration Testing with Metasploit's Meterpreter
Having a command prompt is great. However, often it would be
convenient to have more flexibility after you've compromised a host. And in
some situations, you need to be so sneaky that even creating a new process on a
host might be too much noise that's where the Meterpreter payload shines!
The Metasploit Meterpreter is a command interpreter payload
that is injected into the memory of the exploited process and provides
extensive and extendable features to the attacker. This payload never actually
hits the disk on the victim host everything is injected into process memory
with no additional process created It also provides a consistent feature set no
matter which platform is being exploited. The Meterpreter is even extensible,
allowing you to load new features on the fly by uploading DLLs to the target
system's memory.
To introduce the Meterpreter, we'll reuse the MS10-022
browser-based exploit with the Meterpreter payload rather than the reverse
shell payload.
The exploit worked again. Let's check our session listing.
We now have two command shells from previous examples and
one new Meterpreter session. Let's interact with the Meterpreter session.
The help command will list all the built-in Meterpreter
commands. The entire command list would fill several pages, but here are some
of the highlights.
Let's start with the ps and migrate commands Remember that
the Meterpreter payload typically runs within the process that has been
exploited (Meterpreter paired with the MS 10-002 is a bit of a special case) So
as soon as the user closes that web browser the session is gone in the case of
these client-side exploits especially, you'll want to move the Meterpreter out
of the client-side application's process space and into a process that will be
around longer A good target is the user's explorer.exe process. “Explorer.exe”
is the process that manages the desktop and shell, so as long as the user is
logged in explorer.exe should remain alive. In the following example, we'll use
the ps command to list all running processes and the migrate command to migrate
the Meterpreter over to “explorer.exe”.
Great, now our session is less likely to be terminated by a
suspicious user.
When pen-testing your goals will often be to elevate
privileges, establish a stronger foothold, and expand access to other machines.
In this demo example, so far we have a Meterpreter session running as TS-1B7F08B5B4BA
slash TS. This local workstation account is better than nothing, but it won't
allow us to expand access to other machines.
There are a few other ways to explore the meterpreter
session. Using meterpreter, you can log keystrokes, or run code as a different
logged-on user, or use Meterpreter’s hashdump command and Metasploit’s psexec
Command to Log In using a Shared password. I cannot explore all these here.
If you want to learn more about meterpreter, raise your hand and write me yes in
my comment section.
There is a tool called MSF venom, that is used to generate a
malicious application, that is used to exploit any device without having a
vulnerability.
Due to community guidelines, I cannot teach you on YouTube.
But don’t worry, I already have a tutorial for the usage of MSF Venom, find them
by visiting my website, the link is in my description.
Using these two videos you will learn how to build a
malicious application.
If you have any doubts or queries on my video write me
below in my comment section.
Automating and Scripting Metasploit
The examples we have shown so far have all required a human at the keyboard to launch the exploit and, similarly, a human typing in each post-exploitation command. On larger scale penetration test engagements, that would, at best, be monotonous or worse, cause you to miss exploitation opportunities, because you were not available to immediately type in the necessary commands to capture the session.Thankfully, Metasploit offers functionality to automate post-exploitation and even build your own scripts to run when on each compromised session. Let's start with an example of creating an automated script and running it.
From here we have to generate an automated script. So from here open a new terminal window. I want the script live on my desktop, so let me change the directory. Ok, next is to push the all used commands to gain access to the Windows XP. Now run nano along with the file name. Always remember the file name must be in “.rc” format.
To run the script use the resource command, and then paste the file.
As here you see it automatically runs each of the commands. Otherwise, you can run it directly from the new terminal window using the “MSF console hyphen r and the file”.
You can find all the available Meterpreter scripts in your Metasploit installation under user, share, Metasploit–framework, here click on scripts and then click on meterpreter. These all scripts are written in Ruby.
Let me open a script just to show you all, what is in a script.
Going Further with Metasploit
There are a few other ways to exploit a device. The simplest and easiest step is MSF Venom.Few other videos will explore the Metasploit Framework. Watch these videos from my blog, the link is in my description. It’s time to say goodbye. If you have any doubts or queries about my videos write me below in my comment section.