metasploit所處位置:/usr/share/metasploit-framework
msf資料庫連線命令:db_connect msf:[email protected]/msf
1、啟動postgresql
service postgresql start/2、進入postgresql配置
2、進入postgresql配置
sudo -u postgres psql
alter user postgres with password 'kaliadmin';
注意1:’admin’ 這個是密碼。
注意2:分號!!!! 一定要帶上分號”;”。
注意3:\q:退出資料庫
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/13/main/postgresql.conf //由於我裝的是msf6,所以對應的資料庫版本是13.x
更改#listen_addresses = 'localhost'為listen_addresses = '*'
更改#password_encryption = on為password_encryption = on
root@kali:~# vi /etc/postgresql/13/main/pg_hba.conf
在文件末尾加上以下內容
# to allow your client visiting postgresql server
host all all 0.0.0.0/32 md5
root@kali:~# service postgresql restart //重啟資料庫
5、管理PostgresSQL使用者和資料庫
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 msf with password 'msfadmin' nocreatedb;
CREATE ROLE
postgres=# create database msf with owner=msf;
CREATE DATABASE
postgres=# \q
注意
1、還是要注意分號!!!沒有分號命令就無法執行。
2、注意複製的時候”“符號問題。
3、user後面是使用者名稱,password後面是使用者名稱對應的密碼。
4、命令執行後有返回結果才是執行成功了。
6、msf配置連線
root@kali:~# msfconsole
msf > db_status
[*] postgresql selected, no connection
msf > db_connect msf:[email protected]/msf
[*] Rebuilding the module cache in the background...
msf > db_status
[*] postgresql connected to msf
msf >
注意:
1:”msf:admin”這個是步驟5中的
“create user msf with password ‘admin’ nocreatedb;”所建立的。
“127.0.0.1”是指本機。
“msf”這個是庫名。
2:”[*] postgresql connected to msf”這個是說明以連結成功資料庫。
7、配置自動連線
自動連線可以通過配置檔案 /usr/share/metasploit-framework/config/database.yml
完成,內容可以通過複製database.yml.example
並修改內容來完成設定。
root@kali:/usr/share/metasploit-framework/config#cp database.yml.example database.yml
root@kali:/usr/share/metasploit-framework/config#vi database.yml
root@kali:/usr/share/metasploit-framework/config#cat database.yml
development: &pgsql
adapter: postgresql
database: msf
username: msf
password: msfadmin
host: localhost
port: 5432
pool: 5
timeout: 5
主要改database、password、host這三個值
8、提示
重新執行msfconsole即可直接連結資料庫