Kali 2016.2 版本上metasploit和较早的版本有所不同,启动Metasploit 使用命令msfconsole.
启动后,使用命令db_status可以查看是否数据库已连接。
1、如果没有连接,可能postgresql本身没有启动。所以需要启动。
service postgresql start 如果启动了仍然没有连接,需要使用命令db_connect进行连接, 命令格式db_connect user:pass@ip:port/database, 用户名和密码可以参看配置文件:database.yml, 值得注意的是该文件位置已经不是大多数参考资料中给出的路径, 使用find / -maxdepth 20 -name "database.yml", 可以知道,文件位置:/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/metasploit-credential-2.0.3/spec/dummy/config/database.yml。
如果还是不能连接,使用以下方法:
2、通过命令进入配置
注意1:‘123456’这个是密码。
注意2:分号!!!!一定要带上分号“;”。
注意3:\q:退出数据库
sudo -u postgres psql ALTER USER postgres WITH PASSWORD ‘123456’;
3、修改linux系统的postgres用户的密码(密码与数据库用户postgres的密码相同)
root@kali:~# sudo passwd -d postgres passwd:密码过期信息已更改。 root@kali:~# sudo -u postgres passwd 输入新的 UNIX 密码: 重新输入新的 UNIX 密码: passwd:已成功更新密码
4、修改PostgresSQL数据库配置实现远程访问
root@kali:~# vi /etc/postgresql/9.5/main/postgresql.conf 更改#listen_addresses = ‘localhost’为 listen_addresses = ‘*’ 更改#password_encryption = on为password_encryption = on root@kali:~# vi /etc/postgresql/9.4/main/pg_hba.conf 在文档末尾加上以下内容: # to allow your client visiting postgresql server host all all 0.0.0.0 0.0.0.0 md5 root@kali:~# service postgresql restart
5、管理PostgreSQL用户和数据库
root@kali:~# psql -U postgres -h 127.0.0.1 用户 postgres 的口令: psql (9.4.6) SSL连接 (协议: TLSv1.2, 加密:ECDHE-RSA-AES256-GCM-SHA384,二进制位: 256, 压缩比: 关闭) 输入 "help" 来获取帮助信息. postgres=# create user "msf123" with password '123456' nocreatedb; CREATE ROLE postgres=# create database “msf1” with owner=”msf123”; ERROR: role "”msf123”" does not exist postgres=# create database "msf1" with owner="msf123"; CREATE DATABASE postgres=# \q
6、msf配置连接
root@kali:~# msfconsole msf > db_status [*] postgresql selected, no connection msf > db_connect msf123:123456@127.0.0.1/msf1 [*] Rebuilding the module cache in the background... msf > db_status [*] postgresql connected to msf1 msf >
















