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:[email protected]/msf1 [*] Rebuilding the module cache in the background... msf > db_status [*] postgresql connected to msf1 msf >