算命縖子
生命不息,折腾不止。
© 算命縖子
All Rights Reserved.

msf(Metasploit)数据库连接失败的问题

我的msf有卸载重装过,所以不知道啥原因导致连接不上数据库。然后我也把数据库卸载了重新安装过。

blob

db_connect msf:123456@127.0.0.1/msf_db
[-] Error while running command db_connect: Failed to connect to the Postgres data service: FATAL:  Ident authentication failed for user "msf"


Call stack:
/opt/metasploit-framework/embedded/framework/lib/msf/ui/console/command_dispatcher/db.rb:2069:in `db_connect_postgresql'
/opt/metasploit-framework/embedded/framework/lib/msf/ui/console/command_dispatcher/db.rb:1837:in `cmd_db_connect'
/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:523:in `run_command'
/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:474:in `block in run_single'
/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `each'
/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `run_single'
/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/shell.rb:151:in `run'
/opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/console.rb:48:in `start'
/opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/base.rb:82:in `start'
/opt/metasploit-framework/bin/../embedded/framework/msfconsole:49:in `<main>'

安装PostgreSQL 9.6
yum install postgresql96-server postgresql96-contrib

blob

初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb

设置开机自启动
systemctl enable postgresql-9.6.service

启动服务
systemctl start postgresql-9.5.service

进入postgresql
sudo -u postgres psql

postgres权限太高,新建一个用户和数据库来连接metasploit

CREATE USER 用户名 WITH PASSWORD 密码 NOCREATEDB;

postgres=# CREATE USER msf WITH PASSWORD '123456' NOCREATEDB;

给新建的用户新建一个数据库

CREATE DATABASE 数据库名 OWNER 用户名;

postgres=# CREATE DATABASE msf_db OWNER msf;

查看数据库

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 msf       | msf_db   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

以上步骤完成后,去msf里面,如果能连接上最好了。

db_connect 用户名:密码@127.0.0.1/数据库 

db_connect msf:123456@127.0.0.1/msf_db 
[*] Rebuilding the module cache in the background... 

db_status 
[*] postgresql connected to msf_db

如果连接不上像我这样。可能还需要继续!

你可以试试能不能搜索到pg_hab.conf这个文件的存在,但是我这居然找不到
find / -name 'pg_hab.conf'

blob

blob

如果你也找不到的话,继续跟上步骤。

去到下面这个目录
cd /var/lib/pgsql/9.6/data/

我尝试用vi去创建一个这样的文件,但是神奇的事情发生了。
vi pg_hba.conf

blob

那个文件是存在的,只是我找不到他,他可能隐藏起来了。
拉到下面,把原本的METHOD的ident修改为md5

blob

重启一下
systemctl restart postgresql-9.6.service

blob


备注:
查看数据库
postgres=# \l

信息查看
postgres=# \du

退出
postgres=# \q

2019-11-08
33 views
暂无评论

发表评论