Search icon CANCEL
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 Over 70 recipes to master the most widely used penetration testing framework with this book and ebook.

Arrow left icon
Product type Paperback
Published in Jun 2012
Publisher Packt
ISBN-13 9781849517423
Length 268 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Abhinav Singh Abhinav Singh
Author Profile Icon Abhinav Singh
Abhinav Singh
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Metasploit Penetration Testing Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Metasploit Quick Tips for Security Professionals 2. Information Gathering and Scanning FREE CHAPTER 3. Operating System-based Vulnerability Assessment and Exploitation 4. Client-side Exploitation and Antivirus Bypass 5. Using Meterpreter to Explore the Compromised Target 6. Advanced Meterpreter Scripting 7. Working with Modules for Penetration Testing 8. Working with Exploits 9. Working with Armitage 10. Social Engineer Toolkit Index

Setting up the database in Metasploit


An important feature of Metasploit is the presence of databases 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. So a good penetration testing tool should have proper database integration to store the results quickly and efficiently.

Getting ready

Metasploit comes with PostgreSQL as the default database. For the BackTrack machine, we have one more option—MySQL. You can use either of the two databases. Let us first check out the default settings of the PostgreSQL database. We will have to navigate to database.yml located under opt/framework3/config. To do this, run the following command:

root@bt:~# cd /opt/framework3/config
root@bt:/opt/framework3/config# cat database.yml
production:
adapter: postgresql
database: msf3
username: msf3
password: 8b826ac0
host: 127.0.0.1
port: 7175
pool: 75
timeout: 5

Notice the default username, password, and default database that has been created. Note down these values as they will be required further. You can also change these values according to your choice as well.

How to do it...

Now our job is to connect the database and start using it. Let us launch the msfconsole and see how we can set up the databases and store our results.

Let us first check the available database drivers.

msf > db_driver
[*]Active Driver: postgresql
[*]Available: postgresql, mysql

PostgreSQL is set as the default database. If you want to change the database driver then you can execute the following command:

Msf> db_driver mysql
[*]Active Driver: Mysql

This will change the active driver to MySQL. In this book, we will primarily be using PostgreSQL for demonstrations.

Note

Rapid7 has dropped the support for MySQL database in the recent versions of Metasploit so the db_driver command may not work. The only default driver supported with the framework in that case will be PostgreSQL.

How it works...

To connect the driver to msfconsle we will be using the db_connect command. This command will be executed using the following syntax:

db_connect username:password@hostIP:port number/database_name

Here we will use the same default values of username, password, database name, and port number which we just noted down from the database.yml file:

msf > db_connect msf3:8b826ac0@127.0.0.1:7175/msf3

On successful execution of the command, our database is fully configured.

There's more...

Let us discuss some more important facts related to setting up the database.

Getting an error while connecting the database

There are chances of an error while trying to establish the connection. There are two things to keep in mind if any error arises:

  • Check the db_driver and db_connect commands and make sure that you are using the correct combination of the database.

  • Use start/etc/init.d to start the database service and then try connecting it.

If the error still prevails then we can re-install the database and associated libraries using the following commands:

msf> gem install postgres
msf> apt-get install libpq-dev

Deleting the database

At any time, you can drop the database created and start again to store fresh results. The following command can be executed for deleting the database:

msf> db_destroy msf3:8b826ac0@127.0.0.1:7175/msf3
Database "msf3" dropped.
msf>
lock icon The rest of the chapter is locked
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 €18.99/month. Cancel anytime