Metasploit tips and tricks

Metasploit tips and tricks

msfcolsole, to access de metaexploit framework

db_status, to see the connection status to the database.

bundle install, to install ruby gems, or little codes to test vulnerabilities.

workspace -a HR, to create a workspace with configuration to test HR department.

workspace, to see which workspace is in used.

workspace HR, to change the workspace.

workspace -d, to delete a workspace.

————- Database Connection ————————–
You don’t need a database to run the Framework, but it’s pretty useful if you want to store and view the data you’ve collected. To set up a database, take a look at this awesome wiki created by the Fedora Project.

After you’ve set up the database, you need to connect to it. You will need to manually connect to the database each time you launch msfconsole.

To connect to the database, run the following command in msfconsole:

msf > db_connect your_msfdb_user:your_msfdb_pswd@127.0.0.1:5432/msf_database

If you configured your PostgreSQL database to run on a port other than 5432, or you have named your database something other than msf_database, you will need to replace those values in the previous command with the correct values.

To make sure that the database is connected, you can run the db_status command, which should return the following:

msf > db_status
[*] postgresql connected to msf_database

Now, you need to modify the database configuration file to store your database settings. To modify the database configuration file, you will need to edit database.yml, which is located in /path/to/framework/config. If you don’t have this file, you will need to modify database.yml.example and save it as database.yml.

Open a text editor, like vim, and enter the following:

$ vim /opt/framework/config/database.yml

When the editor appears, the following information needs to be added to the database configuration file:

development:
adapter: “postgresql”
database: “msf_database”
username: “msf_user”
password: “123456”
port: 5432
host: “localhost”
pool: 256
timeout: 5

production:
adapter: “postgresql”
database: “msf_database”
username: “msf_user”
password: “123456”
port: 5432
host: “localhost”
pool: 256
timeout: 5

The database, username, password, and port attributes need to be updated with the values you’ve chosen for your database.

Now, you can run the following command to start the database:

msf > db_connect -y /opt/metasploit/config/database.yml

Automatically Connecting to the Database

If you want the database to connect every time you launch msfconsole, you can copy the database configuration file and move it to the .msf4 directory. The .msf4 directory is a hidden folder in the home directory that is automatically created by the Metasploit installer. If you cloned Metasploit from GitHub, you will need to manually create the folder.

To copy database.yml to the .msf4 folder, run the following command:

cp /opt/framework/config/database.yml /root/.msf4/

Recreat the database automatically:

The best way yo create a database is usin msfdb init or msfdb reinit.

To delete a database just type msfdb delete.

To start metasploit the best way is:
1. Start postgresql.

2. Start de database connection to postgress with mfsdb start.

3. start the framework with mfsconsole.

Start to scanning:

To found the machines on the network you can use db_nmap, it save the result in the metasploit DB.
db_nmap -v -sV {host or network}

Use the command hosts to get access to the host saved in the db.

Hosts

To see the options that we have to scan:

search portscan

to use one of the use, for instace full tcp portscan then:
use auxiliary/scanner/portscan/tcp

after that you just have to add the machine to scan, and some parameters of the scanning method.
set rhost ipaddress

set threads 8

to see the parameter option to this type of scan just type:

options

To start running the scan jut type:

run

If you get an error like:uxiliary failed: RuntimeError enp0s25: You don’t have permission to capture on that device (socket: Operation not permitted).
just run:

“sudo setcap cap_net_raw,cap_net_bind_service=+eip /opt/metasploit-framework/embedded/bin/ruby” and “sudo setcap cap_net_raw,cap_net_bind_service=+eip /usr/bin/nmap”.

Leave a Reply