Metasploit
Set up
Create and initialize MSF database:
sudo msfdb initEnable database service:
sudo systemctl enable postgresqlRun metasploit:
sudo msfconsoleVerify database connectivity
db_statusGet information about metasploit:
helpWorkspaces
Creation
Create new workspace:
workspace -a <name>Move to workspace:
Check workspace
Commands inside workspace
Nmap scan:
Get information about the hosts
Get information about the services
Show specific port
Get more commands:
Auxiliary Modules
Information Gathering, scanning, enumerating.
List all auxiliary modules:
Search in auxiliary:
Use auxiliary:
Information about the auxiliary:
Show options about the auxiliary:
Run auxiliary:
See if metasploit found any vulnerabilities:
Exploit modules
Search for exploits:
Show options:
Set payload:
Session and Jobs
Sessions are used to interact and manage access to successfully exploited targets. Jobs are used to run modules for features in the background.
Run attack in the background:
Sessions
List all active attacks:
Enter the session:
Delete the session:
Jobs
Run job:
Payloads
There are two types of payloads: staged and non-staged.
Staged - payload is sent alongside with exploit (more stable but has more size)
Non-staged - payload is sent in two parts - the first one connect back to us from the machine, the second one transfer larger payload with the rest of the shellcode and executes it.
Show available payloads:
Select payload:
Meterpreter
After succesfully getting the shell user is able to get all possible commands:
Most common commands
Get information about the system:
Get shell (you can background existing shell with Ctril + Z):
Get shell list:
Executable payloads (MSFVenom)
Search for payloads:
Create malicious exe file:
Set up listener with multi/handler:
Set payload:
Meterpreter Post Exploitation
Check idle time:
Migrate to the other process:
Escalate:
Get uid:
Pivoting
If you already have a shell type:
In order to pivot through our compromised server we have to set session as background:
Next, we add route in metasploit:
Check the route:
Automatic route add:
You can scan another host with:
Socks proxy:
You can also create port forwarding:
Metasploit automation
You can use multiple different scripts which can be useful while exploiting the machines here:
Execute the script in the following way:
Last updated