Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Metasploit Penetration Testing Cookbook

You're reading from   Metasploit Penetration Testing Cookbook Evade antiviruses, bypass firewalls, and exploit complex environments with the most widely used penetration testing framework

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher
ISBN-13 9781788623179
Length 426 pages
Edition 3rd Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Monika Agarwal Monika Agarwal
Author Profile Icon Monika Agarwal
Monika Agarwal
Abhinav Singh Abhinav Singh
Author Profile Icon Abhinav Singh
Abhinav Singh
Nipun Jaswal Nipun Jaswal
Author Profile Icon Nipun Jaswal
Nipun Jaswal
Daniel Teixeira Daniel Teixeira
Author Profile Icon Daniel Teixeira
Daniel Teixeira
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Metasploit Quick Tips for Security Professionals FREE CHAPTER 2. Information Gathering and Scanning 3. Server-Side Exploitation 4. Meterpreter 5. Post-Exploitation 6. Using MSFvenom 7. Client-Side Exploitation and Antivirus Bypass 8. Social-Engineer Toolkit 9. Working with Modules for Penetration Testing 10. Exploring Exploits 11. Wireless Network Penetration Testing 12. Cloud Penetration Testing 13. Best Practices 14. Other Books You May Enjoy

Configuring PostgreSQL

An important feature of Metasploit is the backend database support for PostgreSQL, which you can use to store your penetration-testing results. Any penetration test consists of lots of information and can run for several days, so it becomes essential to store the intermediate results and findings, such as target host data, system logs, collected evidence, and report data. As a good penetration-testing tool, Metasploit has proper database integration to store the results quickly and efficiently. In this recipe, we will be dealing with the installation and configuration process of a database in Kali Linux.

Getting ready

To configure PostgreSQL, we will first start the service and then use the Metasploit msfdb command to initialize the database.

How to do it...

  1. To set up our Metasploit database, we first need to start up the PostgreSQL server, using the following command:
root@kali:~# systemctl start postgresql 
  1. Then we need to create and initialize the msf database with the msfdb command with the init option:
root@kali:~# msfdb init
Creating database user 'msf'
Enter password for new role:
Enter it again:
Creating databases 'msf' and 'msf_test'
Creating configuration file in /usr/share/metasploit-framework/config/database.yml
Creating initial database schema

The msfdb command allows you to manage the Metasploit Framework database, not just initialize the database. To display all the msfdb options, run the command as follows:

root@kali:~# msfdb

Manage a metasploit framework database

msfdb init # initialize the database
msfdb reinit # delete and reinitialize the database
msfdb delete # delete database and stop using it
msfdb start # start the database
msfdb stop # stop the database
  1. To modify the database configuration file, we can edit the database.yml file  located in /usr/share/metasploit-framework/config/database.yml:
root@kali:~# cat /usr/share/metasploit-framework/config/database.yml
development:
adapter: postgresql
database: msf
username: msf
password: 3HcNhAtdH6F9F2iGa4z3wJVoI7UK1Ot+MG1zuKjYzn4=
host: localhost
port: 5432
pool: 5
timeout: 5

production:
adapter: postgresql
database: msf
username: msf
password: 3HcNhAtdH6F9F2iGa4z3wJVoI7UK1Ot+MG1zuKjYzn4=
host: localhost
port: 5432
pool: 5
timeout: 5

test:
adapter: postgresql
database: msf_test
username: msf
password: 3HcNhAtdH6F9F2iGa4z3wJVoI7UK1Ot+MG1zuKjYzn4=
host: localhost
port: 5432
pool: 5
timeout: 5

Notice the default username, password, and default database that has been created. If necessary, you can also change these values according to your preference.

  1. Now, let's launch the msfconsole interface and confirm that Metasploit is successfully connected to the database using the db_status command:
msf > db_status
[*] postgresql connected to msf

There's more...

To connect to a database manually, you can use the db_connect command followed by the credentials, host, and database you want to connect to, using the following syntax:

db_connect <user:pass>@<host:port>/<database>

To test the db_connect command, we can use the values of the username, password, database name, and port number, from the database.yml file:

msf > db_disconnect 
msf > db_status
[*] postgresql selected, no connection
msf > db_connect msf:3HcNhAtdH6F9F2iGa4z3wJVoI7UK1Ot+MG1zuKjYzn4=@127.0.0.1/msf
[*] Rebuilding the module cache in the background...
msf > db_status
[*] postgresql connected to msf

We can also use db_connect with the -y option and the path to the database configuration file:

msf > db_disconnect 
msf > db_status
[*] postgresql selected, no connection
msf > db_connect -y /usr/share/metasploit-framework/config/database.yml
[*] Rebuilding the module cache in the background...
msf > db_status
[*] postgresql connected to msf

If you want the database to connect every time you launch msfconsole, copy the database configuration file to the .msf4 directory which was created in your home directory by the Metasploit installer.

You have been reading a chapter from
Metasploit Penetration Testing Cookbook - Third Edition
Published in: Feb 2018
Publisher:
ISBN-13: 9781788623179
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image