配置PostgreSQL数据库

Metasploit的一个重要特性是支持PostgreSQL数据库,使用它来存储渗透测试结果和漏洞信息。

准备工作

启动服务,然后使用 Metasploit msfdb 初始化数据库

作者:

锦凡歆在酷狗直播唱歌最好听

怎么做

1、启动数据库

  1. root@osboxes:~# systemctl start postgresql

2、初始化数据库

  1. ~# msfdb init
  2. Creating database user 'msf'
  3. Enter password for new role:
  4. Enter it again:
  5. Creating databases 'msf' and 'msf_test'
  6. Creating configuration file in /usr/share/metasploit-framework/config/database.yml
  7. Creating initial database schema

msfdb 还可以用来管理Metasploit Framework数据库

  1. root@osboxes:~# msfdb                                              
  2. Manage the metasploit framework database                          
  3.  msfdb init     # start and initialize the database              
  4.  msfdb reinit   # delete and reinitialize the database            
  5.  msfdb delete   # delete database and stop using it              
  6.  msfdb start    # start the database                              
  7.  msfdb stop     # stop the database                              
  8.  msfdb status   # check service status                            
  9.  msfdb run      # start the database and run msfconsole          

3、修改数据库配置文件

我们可以直接编辑 database.yml文件,文件位于/usr/share/metasploit-framework/config/database.yml

  1. root@osboxes:~# cat /usr/share/metasploit-framework/config/database.yml  
  2. development:                                                             
  3.   adapter: postgresql                                                    
  4.   database: msf                                                          
  5.   username: msf                                                          
  6.   password: 9JHbuu/CdoGT0kvBiSXf+VLDRQ9dKKpMYyWKY6Ui2jc=                 
  7.   host: localhost                                                        
  8.   port: 5432                                                             
  9.   pool: 5                                                                
  10.   timeout: 5                                                             
  11. production:                                                              
  12.   adapter: postgresql                                                    
  13.   database: msf                                                          
  14.   username: msf                                                          
  15.   password: 9JHbuu/CdoGT0kvBiSXf+VLDRQ9dKKpMYyWKY6Ui2jc=                 
  16.   host: localhost                                                        
  17.   port: 5432                                                             
  18.   pool: 5                                                                
  19.   timeout: 5                                                             
  20. test:                                                                    
  21.   adapter: postgresql                                                    
  22.   database: msf_test                                                     
  23.   username: msf                                                          
  24.   password: 9JHbuu/CdoGT0kvBiSXf+VLDRQ9dKKpMYyWKY6Ui2jc=                 
  25.   host: localhost                                                        
  26.   port: 5432                                                             
  27.   pool: 5                                                                
  28.   timeout: 5                                                             

里面的usrname和password是默认配置的,你可以根据自己的喜好进行更改

4、确定是否连接到数据库

启动msfconsole,然后执行db_status,检查数据库连接情况。

  1. msf > db_status
  2. [*] postgresql connected to msf
  3. msf >

更多

如果要手动连接到数据库,可以使用如下命令:

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

我们可以使用databse.yml文件测试db_connect命令

  1. msf > db_disconnect //断开连接
  2. msf > db_status //查看连接状态
  3. [*] postgresql selected, no connection
  4. msf > db_connect
  5. [*]    Usage: db_connect <user:pass>@<host:port>/<database>
  6. [*]       OR: db_connect -y [path/to/database.yml]
  7. [*] Examples:
  8. [*]        db_connect user@metasploit3
  9. [*]        db_connect user:[email protected]/metasploit3
  10. [*]        db_connect user:[email protected]:1500/metasploit3
  11. msf > db_connect -y /usr/share/metasploit-framework/config/database.yml //连接数据库
  12. [*] Rebuilding the module cache in the background...
  13. msf > db_status //查看连接状态
  14. [*] postgresql connected to msf
  15. msf >

猜你喜欢

转载自blog.csdn.net/hyg1165269653/article/details/89544402