If you can see this check that

Main Page


Exploitation using the Metasploit Framework (MSF)

User:
Password:

Authors: Rich Macfarlane, Gordon Russell

This practical runs a Windows XP target, which we can then use to explore the many features of the Metasploit framework. Originally this was based on a pdf paper-based tutorial, but it has recently been integrated into linuxzoo.

Start your Kali Linux machine, and then you can boot the target below.

Topology
Figure 1: Lab Environment

To reset all the check buttons from a previous attempt click here

Question 1: Target 2 - Boot

Press this button to ready your machine for running with the virtual machine targets. If your machine is reset or you reboot then you may have to press this button again.

Note that this target can take (quite) a few minutes to boot, as it has many processes running many services.

Tests - not attempted
Script ready UNTESTED
Target 2 started UNTESTED

The machine can take a few minutes to warm up. Press the test button to see if it is running fully. So long as the network of the target is running, you can continue to the next question while you wait for the XP target.

Tests - not attempted
Target 2 started UNTESTED
Target 2 network running UNTESTED
Target 2 all services running UNTESTED

Question 2: Network Device

Target 1 lies somewhere in 192.168.1.1 - 192.168.1.254. This time use "ip route show" and find out the device name on your machine which would be used to handle packets going to target 1. You can identify it by looking at the output, finding the line involved with the target subnet, and looking for the "dev".

Target network device:

Tests - not attempted
Gateway IP UNTESTED

What is your machine's IP number on the target network?

Your IP:

Tests - not attempted
Local IP UNTESTED

Question 3: Network scanning with nmap

The target needs to be running before starting this question.

Use nmap to sweep the target network, and identify the IP address of target 1. Use the appropriate flags to keep this scan efficient.

Target IP:

Tests - not attempted
target ip UNTESTED

On the target machine, list the first 3 port numbers found in numerical order using a standard nmap portscan of the common ports open on the target.

Open port 1
Open port 2
Open port 3

Tests - not attempted
first port UNTESTED
second port UNTESTED
third port UNTESTED

Question 4: Metasploit Framework

Before we use the Metasploit Framework, lets check the MSF database is running, and start it if not. Start the MSF database:

sudo msfdb start

Tests - not attempted
metasploit db running UNTESTED

Start the Metasploit Framework console interface.

msfconsole

Tests - not attempted
metasploit console process UNTESTED

We would typically now perform a vulnerability scan against our target using a full blown scanner such as OpenVAS.

As Windows SMB services are running we could perform a quick assessment using the nmap NSE Scripts under the category vulns, which checks for some of the most well know vulnerabilities.

Note: Some of the scripts are marked as intrusive and unsafe, which means they could crash the target system, so would not be used in a production environment.

Documentation of the Nmap SMB Vulnerability scanning Scripts under vuln: https://nmap.org/nsedoc/categories/vuln.html

nmap --script vuln 192.168.1.x

Note if the target fails during the test, go to the bottom of the tutorial and click the button to stop the target, then go to the top of the tutorial and use the buttons to restart and test the target.

What CVE-rated issue was identified with a year of 2017?

Tests - not attempted
2017 CVE UNTESTED

Explore Metasploit via the File System

The various elements of the MetaSploit Framework (MSF) are stored under the directory /usr/share/metasploit-framework including the exploit and payload Ruby scripts themselves.

Change to this directory, and list the contents.

UserAssist Keys
Figure 2: metasploit directories

Which directory holds the built in vulnerability scanners?
/usr/share/metasploit-framework/

Tests - not attempted
Vulnerability directory UNTESTED

Change to the exploits directory and list the contents.

How are the exploits sorted?

Where might exploits which work on several different OS's be stored?

Tests - not attempted
Ordering UNTESTED
Generic UNTESTED

Change to the directory where the Windows exploits are, and list the contents.

How are the Windows exploits sorted?

Note : The exploits contained here are for the OS and applications which run on the OS.

Tests - not attempted
Window Exploits ordering UNTESTED

Change to the directory where the Windows Server Message Block (SMB) exploits are, and list the contents.

Edit one of the Ruby exploit scripts (or use less to view), for the well know vulnerability MS08_067.

What is the associated CVE for this exploit script? Use the format "CVE 2025-0001".

Tests - not attempted
CVE UNTESTED

Google for the CVE and check the mitre database (cve.mitre.org) - What date was the vulnerability entry first published? Use the format 2025-12-31.

Try to find the Exploit-Db entry(s). What is the lowest-numbered entry?

From your research which versions of Windows XP Professional are vulnerable?

Tests - not attempted
When UNTESTED
Lowest UNTESTED
Versions UNTESTED

Change into the singles payload directory, and then into the windows payloads directory.

Which payload would be used to create a new user on the target machine?

Which payload would be used to create a TCP listener on a port on the target, and create and bind a command shell to it?

Tests - not attempted
Script.rb name UNTESTED
Script shell binding to tcp UNTESTED

Examine the newuser.rb script.

Which Windows command is executed on the target machine to create the new user?

Tests - not attempted
Command used UNTESTED

Examine the shell_bind_tcp.rb script and review the payload itself.

Approx. how many bytes of shellcode are in the payload?

Tests - not attempted
Bytes UNTESTED

Question 5: Framework

Now the Metasploit Framework services are running we can explore the various parts of the framework.

Metasploit Framework
Figure 3: Metasploit framework

There are several interfaces we can use to interact with the framework exploit/payload/auxiliary modules. MSF (MetaSploit Framework) including the msfcli, msfconsole, and a web-based interface.

You should have already started the metasploit console, but if not start the Metasploit MsfConsole interface from a terminal window. You should get a strange and fairly unique ascii graphic:

Metasploit Framework
Figure 4: Console

Which version of Metasploit is reported? It is in the form "v0.0.0" or "v0.0.0-string".

How many exploits does it contain?

How many payloads does it contain?

Tests - not attempted
Metasploit version UNTESTED
test UNTESTED
test UNTESTED

Use the show exploits command to list all available exploits. We can Mix and match Exploits and associated Payloads using MSF, as shown below:

Exploit modules
Figure 5: Exploit Modules

The search command can help us find useful exploits. Use search -h to check the help for the command.

Note: for older versions of MSF you may need to run db_rebuild_cache if MSF reports the cache isn't built or needs rebuilt.

Use the search type:exploit name:smb command to list only the windows smb exploits:

Search
Figure 6: Search

Use the search command to list the exploit modules have been added in 2020.
How many exploit modules were added?

What is the exploit module filename for this?

Which type of memory mgt exploit is this?

Is it a remote/client-side/local exploit?

Tests - not attempted
Number in 2020 UNTESTED
Exploit FILENAME UNTESTED
Exploit type UNTESTED
Exploit form UNTESTED

Each Exploit and Payload has information related to it stored in the framework. Select a payload name form the show command and use the following command to display details about the respective modules. View several to get a feel for the structure of information provided.

info <Name Of Payload/Exploit>

(Use the <TAB KEY> to auto complete commands and values, or cut and paste the full name)

Search for the windows smb netapi exploits. Find the netapi exploit name of the ms08_067 exploit, and copy it from the screen.

netapi module
Figure 6: netapi module

The MSF command use allows us to select an exploit module to use. Paste the exploit name onto the msfconsole command line:

use exploit/windows/smb/ms08_067_netapi

What has the msfconsole prompt changed to?

Tests - not attempted
Prompt UNTESTED

We now in exploit command mode. If you check the help now, you should see we have more commands. The info command gives details on this particular exploit.

The show options command can now be used to check the options for the selected exploit

show options
Figure 7: show options

From the file system, find the exploit module and review the contents.

show options
Figure 8: Module Review

Which CVE number is listed in the exploit module code, in the format CVE-xxxx-xxxx?

Look up the vulnerability on the NVD database online. Which CWE category is listed against the vulnerability, in the format CWE-xx?

Is it a remote/client-side/local exploit?

Tests - not attempted
CVE Code UNTESTED
CDE Category UNTESTED
Exploit type UNTESTED

This is a remote exploit for the vulnerability in the Windows SMB network server service.

SMB Layout
Figure 9: SMB Layout

Payloads and Options
To check the possible payloads compatible with this exploit module, use the show payloads command.

Possible Payloads
Figure 10: Possible Payloads

Try using the msf grep command to filter out bind shells

Grep for bind
Figure 11: Bind Grep

Note the msf grep command can take flags. You can check those out using "grep help".

How many bind shell payloads are compatible with the selected exploit?

Tests - not attempted
Grep count UNTESTED

The set command can be used to set the PAYLOAD option for our exploit.

Try typing set PAYLOAD <TAB KEY> <TAB KEY> and autocomplete should show all possible payloads and page nicely.

We can select a Bind Shell payload to add to our Exploit, which will start a listener on the target, allowing Metasploit to connect, and then the payload will spawn a shell and bind this shell to the connection.

Bind Payload
Figure 12: Bind Payload

Select the name of a windows TCP Bind Shell payload shown below (copy+paste or use auto complete for the payload value – using TABs, or use the index from the search output):

TCP Bind Payload
Figure 13: Select the correct payload

Note: If you type set PAYLOAD windows/shell<TAB><TAB> MSF displays only the possible windows shell-based payloads for the exploit.

The payload we are using here is "windows/shell_bind_tcp", and not any other payload by a similar sounding name or in a different directory.

Which type of bind shell payload is this single/staged?

Tests - not attempted
Payload seems to be used UNTESTED
Payload type UNTESTED

The show options command can now be used to check the options for the selected exploit and payload modules selected:

Payload options
Figure 14: Payload Options

Note: the separate sections for the Exploit and Payload options.

Which option is mandatory and currently not set?

Tests - not attempted
Mandatory option UNTESTED

Set any mandatory options needed to run the exploit; in this case possibly the target host. (Check the Required col, and use the set msfconsole cmd)

Check the options have been set correctly using show options again (or use up arrow twice).

Which port is the Bind Shell payload going to start the listener on? Can you draw your own diagram with the smb service, bind shell listener, and network communications?

Tests - not attempted
RHOSTS plausable UNTESTED
Port of the listener UNTESTED

To send the exploit and payload to the target use the exploit command. (got to be the best cmd in any tool ever!)

You should see helpful debug messages until you get a message saying if the exploit was successful or not. If the exploit is successful, the payload should execute, and the action should be carried out.

If the exploit was successful you should get a cmd shell on the target!

Shell opened
Figure 15: Remote Shell Open

Did the exploit work, and has the shell payload been launched? Check using the Windows ipconfig command.
What is the IP Address of the target reported from the ipconfig command?

Tests - not attempted
Target 2 active UNTESTED
Target 2 session detected UNTESTED
Ip Discovered UNTESTED

In a Kali cmd shell, check the connection of our payload using

    ss -a |grep 4444
  

Use the Windows cd command to check the working directory, and the dir command to check the contents of the current directory.

What is the current working directory, using cd?

We can use environment variables to find out some useful information. Try set COMPUTERNAME, which is the local name for this machine.
What is the current COMPUTERNAME?

Tests - not attempted
cwd UNTESTED
PCNAME UNTESTED

From the Target machine shell, check the network services running and especially any established connections using netstat -an

It should look similar to the following:

netstat example
Figure 16: Netstat example

Identify the bind shell MSF payload connection?
What are the port numbers used in the connection?
Target end: msfconsole end:
Check the associated processes for the payload connection using the netstat command and adding the -o flag
Can you identify the process id (pid) for the bind shell MSF payload connection?

Review the running executables and the associated processes using the windows command tasklist
Can you identify the executable process the bind shell is attached to?

Tests - not attempted
msfconsole port UNTESTED
target port UNTESTED
target pid UNTESTED
Broken process name UNTESTED

Run tcpdump or Wireshark and filter for your Meterpreter connection. Check if you can view the commands and shell output in the connection.

What tcpdump command filters for the payload connection? Do it in ASCII, use the local bridge device, and select the known msf port number.
sudo tcpdump -ni port
Can the shell content be captured and understood?

Tests - not attempted
tcpdump dev UNTESTED
tcpdump ascii UNTESTED
tcpdump port UNTESTED
tcpdump readable UNTESTED

Question 6: VNC to Target 1

Let's logon to our target and check these things.

From Kali, open a new terminal windows and get a VNC remote desktop to the target, using the vncviewer tool. From the new terminal window type:

vncviewer :1

Validate the IP Address of the target and working directory from a Windows command window.

Command window in XP
Figure 18: Commands in target 1 using VNC

On the Target machine, again check the listening services and established connections using netstat -an

From Kali, check the listening services and connections using ss -ln and ss -an

Once the question is complete, exit from the remote shell inside msfconsole, using the exit command or CTRL C.

What is the IP number of the server (listener)?

Which is the IP number of the attacker?

Is the listener on the target or on the attacking machine?

Tests - not attempted
IP server UNTESTED
IP attacker UNTESTED
Listener end UNTESTED

Question 7: Reverse Shell Payload

Now we can try the same exploit with a different payload. Keep using the ms08_067_netapi exploit. This time we will use a Reverse Bind Shell payload. This creates a Listener (a Handler) on Kali, and the exploit connects back and binds a shell to the connection.

Reverse Shell
Figure: Reverse Shell

From Kali, we can use the same exploit, but this time let's swap the payload for a TCP Reverse Bind Shell payload, and set the PORT for the listener to 777.

Setting the payload
Figure: Setting the payload

Check the options with show options

Why do you have to set a listener port?

Which type of shell payload is this single/staged?

Tests - not attempted
Confirmed lhost with show options UNTESTED
Why LHOST UNTESTED
Is it staged UNTESTED
Setting the options needed
Figure: Options Needed

Set the options needed and run the exploit against the target XP machine.

Did the exploit work, and has the reverse shell payload been launched? Check using ipconfig command

From Kali, check the listening services and connections using ss -ln and ss -an

On the target server and check the listeners and connections using netstat -na

Which machine is the client and which is the server (handler) for this payload?
Kali machine is and Windows machine is the

Sessions
Sessions are the currently connected payloads. To keep the reverse shell payload session and work on another, we can put the connection into the background with <CTRL+Z> from the shell we have.

Putting a session into the background
Figure: Background Session

To interact with the session again we can use sessions -i sessionnumber

Join a session
Figure: Rejoin a session

To kill a session again we can use sessions -k sessionnumber.

Note: The back command can be used to exit out of the exploit command mode, if you want to change to a different exploit.

Tests - not attempted
Target 2 active UNTESTED
Which end is what? UNTESTED
Target 2 session detected UNTESTED
Looks like 777 reverse UNTESTED

Question 8: Meterpreter Shell Payload

The Meterpreter or "MetaSploit Interpreter" shell payload is the most powerful MSF payload, and improves on a target cmd.exe shell. It is a staged payload and implemented as DLLs which is injected into the exploited processes memory (so has no footprint on the target disk).

Shell Payload
Figure: Shell payload

Review the various Meterpreter payloads using:

set PAYLOAD windows/met <TAB><TAB>
  
Payload options
Figure: Payload Options

Use a Reverse TCP Meterpreter Shell payload, and check the options needed.

MAKE SURE to change the listening port. Set the listening port to be 799.

Which machine will run the listener (the reverse handler) on the specified port?

Tests - not attempted
Which is the listener UNTESTED

Before running the exploit, in your other terminal window, check the listening ports on Kali using ss –ln

Run the exploit, delivering the Meterpreter payload.

run the exploit
Figure: Run the exploit

From Kali, check the services running and established connections using ss –an.

On the Target machine, check the listening services running and connections using netstat –an

Should be similar to the below:

netstat output
Figure: netstat output

Which port is the listener for this payload?

Which port is used on the target?

Tests - not attempted
Looks like 799 reversei is open UNTESTED
Listener port UNTESTED
target port UNTESTED

In the Meterpreter shell, we have a range of Meterpreter commands for Windows target post exploitation. The UPARROW key and TAB key work. Check the Meterpreter shell help using the Meterpreter command?

Note: Use the lecture notes as reference, and most commands have help via -h

Which Meterpreter command gets information about the target system?

Which Build of XP is reported by the command?

Tests - not attempted
System Info command UNTESTED
Ran the command UNTESTED
Build reported UNTESTED
Session contains the build info UNTESTED

Check the network address of the target with the Meterpreter ipconfig command

ipconfig output
Figure: ipconfig output

What is the MAC Address of the target systems Ethernet interface?

Tests - not attempted
test UNTESTED

Run tcpdump or Wireshark and filter for your Meterpreter connection. Check if you can view the commands and shell output in the connection.

What tcpdump command filters for the payload connection? Do it in ASCII, use the local bridge device, and select the known msf port number.
sudo tcpdump -ni port
Can the shell content be captured and understood?

Tests - not attempted
tcpdump dev UNTESTED
tcpdump ascii UNTESTED
tcpdump port UNTESTED
tcpdump readable UNTESTED

Check the username we are running as on the target using the Meterpreter command getuid

What is the user we have inherited on the target? Use the form DOMAIN\USERNAME

Why is this?

Tests - not attempted
Ran getuid UNTESTED
Server Username UNTESTED
Why UNTESTED

From the Meterpreter shell, check the running processes on the target using getpid and ps

Find the process id of the exploited process which Meterpreter is running inside.

What is the process id which Meterpreter is running in?

What is the name of the process?

Tests - not attempted
Current PID UNTESTED
Process Name UNTESTED

If we had exploited a process which may have crashed, or the user might close, Meterpreter facilities moving processes. We would typically migrate to a process which will not terminate.

What is the process id of the winlogon.exe process?

Tests - not attempted
PID of winlogin UNTESTED

From the Meterpreter shell use the migrate command to move processes to the winlogon.exe process.

What is the process id which Meterpreter is now running in? Verify this using getpid.

What is the name of the process?

Tests - not attempted
Current PID UNTESTED
PID is winlogin UNTESTED
Check name UNTESTED

Check the current working directory with the Meterpreter command pwd

What is the current working dir?

Tests - not attempted
CWD UNTESTED

Create a directory c:\test on the target machine using the Meterpreter command mkdir. Check it has been created using cd and ls.

Note it is easier to cd and mkdir, then ls. In the metasploit shell, it uses unix-like slashes, rather than window-like slashes, so it is "cd c:/" not "c:\". Confusing!

cd and ls
Figure: cd and ls
Tests - not attempted
C:\test checked using ls UNTESTED

Downloading Files
Use Meterpreter command lcd to change to /home/kali user's home directory on the Kali machine. Then change to the Windows directory on the target box. Download the winnt.bmp file from the target using the command download

What size is the downloaded file in bytes?

Tests - not attempted
Download detected UNTESTED
Size right UNTESTED

The search command can be useful in finding files on the target. Locate all the ntuser.dat.log files.

Which common directory are all these files under? Include the drive letter and the trailing slash, using Windows slashes. It is case sensitive, and the volume is returned in lower case.

Tests - not attempted
Directory in common UNTESTED

Uploading Tools
Kali provides us with many useful tools which we can upload to a target. From Kali, change to the /usr/share/windows-binaries directory and list the contents. In the Meterpreter shell, change to the c:\test dir on the target machine. Use the upload command to upload the nc.exe Windows netcat executable to the target machine.

upload example
Figure: upload example

We could now use this to port scan an internal network... only if that was part of the penetration testing rules of engagement/scope of agreed testing!

Tests - not attempted
Upload logged UNTESTED

Windows Shell
We can also spawn a cmd.exe shell on our target. This extra layer of shell can be useful as if the cmd.exe crashes or exits for some reason, we still have out Meterpreter shell and can create another shell.

Try the shell command:

running shell
Figure: running the shell

Now from the new shell, use the Windows tasklist command to display the running processes on the target.

What is the process id of this cmd.exe shell?

Does the cmd cls clear the screen as it is meant to? Why not?

Tests - not attempted
Shell started UNTESTED
Shell pid UNTESTED
Cls not working UNTESTED

Windows Command Line Fun
Check the user accounts on the target with:

net user

As we have SYSTEM privileges lets add a user to the target machine for future use. This type of activity would have to be within your rules of engagement and perhaps discussed with the customer!

  net user username userpasswd /add
  
user add example
Figure: user add example

Add a new user called "rich" with password "richpass". Verify this using "net user".

Tests - not attempted
net user used UNTESTED
check user added example
Figure: check user added example

Check the user accounts which are in the local administrator group on the target with:

net localgroup administrators

This could be interesting as often the same local admin accounts are duplicated across different systems in a domain. Lets upgrade our new user account, and add it to the local administrator group:

net localgroup administrators username /add
  
admin change example
Figure: changing a user to an admin

We can use the windows shell to review machines the target has been in contact with, which could be interesting to check if they are in the scope of the penetration test. For example by dumping the target's ARP cache:

arp -a

What mac address has been learned? Use the lowercase format with "-" between the groups.

Tests - not attempted
net admin used UNTESTED
arp cache entry UNTESTED

If we only have a Windows cmd line, we can use the dir cmd to do searches on the filesystem. Make sure your current directory is C:\

Try searching for all pdf file with:

dir "\*.pdf" /s

Can you produce a cmd to search for all log files in a similar way? What is the filename of the last log file found using this technique

Can you find any files ending in ".pif"? What is the filename called?

Tests - not attempted
Last logfile found UNTESTED
pif file found UNTESTED

Question 9: Target 2 - Shutdown

THIS BUTTON IS ONLY NEEDED IF TARGET MACHINE IS RUNNING BUT BECOMES UNRESPONSIVE OR DAMAGED. That is rare. You can also use this button if you are finished with the tutorial and simply want to shutdown all the targets.

Tests - not attempted
Script ready UNTESTED
Power Off Target Machines UNTESTED


Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
Caine 13.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Registry | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Kali 2024-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2025 Edinburgh Napier University