购买
下载掌阅APP,畅读海量书库
立即打开
畅读海量书库
扫码下载掌阅APP

1.3.1 配置PostgreSQL

Metasploit支持使用PostgreSQL数据库来存储数据,我们可以将扫描过程中产生的数据保存在数据库。这一点非常重要,要知道一场大型的渗透测试过程往往会产生大量的主机数据、系统日志、搜集的信息和报告数据等,我们需要将它们保存起来,而数据库则是一个很好的解决方案。

下面以Kali Linux 2操作系统为例来介绍如何配置Metasploit与PostgreSQL协同工作。我们需要先启动PostgreSQL,具体命令如下。

┌──(kali@kali)-[~]
└─$ systemctl start postgresql

然后创建并初始化数据库。这里使用的命令如下。

┌──(kali@kali)-[~]
└─$ sudo msfdb init

除了创建并初始化数据库之外,还可以使用msfdb命令对Metasploit Framwork数据库进行控制,这个控制是通过参数实现的。直接输入msfdb命令可以查看msfdb命令的参数的使用方法与意义。具体命令如下。

┌──(kali@kali)-[~]
└─$ msfdb     
Manage the metasploit framework database
You can use an specific port number for the PostgreSQL connection setting the PGPORT variable in the current shell.
Example: PGPORT=5433 msfdb init
msfdb init     # start and 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
msfdb status   # check service status
msfdb run      # start the database and run msfconsole

数据库的配置文件database.yml位于/usr/share/metasploit-framework/config/,我们可以使用vim命令查看其中的内容,具体命令如下。

┌──(kali㉿kali)-[~]
└─$ sudo vim /usr/share/metasploit-framework/config/database.yml

database.yml的内容如下。

development:
  adapter: postgresql
  database: msf
  username: msf
  password: Dxi3fXKC7ZWBeiuaYa+JB3X7lUD9Gi/v902PM/qg/Dk=
  host: localhost
  port: 5432
  pool: 5
  timeout: 5

production:
  adapter: postgresql
  database: msf
  username: msf
  password: Dxi3fXKC7ZWBeiuaYa+JB3X7lUD9Gi/v902PM/qg/Dk=
  host: localhost
  port: 5432
  pool: 5
  timeout: 5

test:
  adapter: postgresql
  database: msf_test
  username: msf
  password: Dxi3fXKC7ZWBeiuaYa+JB3X7lUD9Gi/v902PM/qg/Dk=
  host: localhost
  port: 5432
  pool: 5
  timeout: 5

配置文件database.yml包含数据库、用户名、主机等信息,你可以根据自己的需要修改其中的内容。到此为止,我们已经了解了如何配置PostgreSQL。

接下来我们查看Metasploit与数据库连接的状态,具体命令如下。

msf6 > db_status
[*] Connected to msf. Connection type: postgresql.

如果想要断开与当前数据库的连接,可以使用db_disconnect命令。

msf6 > db_disconnect
Successfully disconnected from the data service: local_db_service.

如果想要再次建立与数据库的连接,可以使用db_connect命令。该命令的完整用法如下。

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

例如要连接到数据库msf_test,可以使用如图1-9所示的命令。

图1-9 连接到数据库msf_test的命令

另外,你也可以使用参数-y通过配置文件来连接数据库,具体过程如下。

msf6 > db_connect -y /usr/share/metasploit-framework/config/database.yml
Connected to the database specified in the YAML file.
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.

如果之前已经成功配置过数据库,下次可以使用命令msfdb run启动数据库。 OjuiTNP8JqgJwgBoP7nDxH23rrwbk5K9b7PiGZ4M7GBQqWeB8W+8XVB7zDqLlAwe

点击中间区域
呼出菜单
上一章
目录
下一章
×