1、postgresql启动。
service postgresql start
2、进入postgresql配置
1
2
sudo -u postgres psql
alter user postgres with password 'admin';
注意1:’admin’ 这个是密码。 注意2:分号!!!! 一定要带上分号”;”。 注意3:q:退出数据库
3、修改linux系统的postgres用户的密码(密码与数据库用户postgres的密码相同)
1
2
3
4
5
6
root@kali:~
passwd:密码过期信息已更改。
root# sudo -u postgres passwd
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码
4、修改PostgresSQL数据库配置实现远程访问
1
root# vi /etc/postgresql/9.4/main/postgresql.conf
更改#listen_addresses = 'localhost' 为listen_addresses = '*' 更改#password_encryption = on 为password_encryption = on
# vi /etc/postgresql/9.4/main/pg_hba.conf
在文档末尾加上以下内容
1
2
# to allow your client visiting postgresql server
host all all 0.0.0.0/32 md5
# service postgresql restart
注意1:”#”号,一定要把”#”删除掉。 注意2:在vi编辑模式下点击键盘字母a是进入编辑模式,编辑完成后点击“esc”退出编辑模式然后在最下方输入”:wq”保存并退出。
5、管理PostgreSQL用户和数据库
1
2
3
4
5
6
7
8
9
10
11
12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
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 'admin' nocreatedb;
CREATE ROLE postgres=# database msf with owner=msf;
CREATE DATABASE postgres=# q
注意1:还是要注意分号!!!没有分号命令就无法执行。 注意2:注意复制的时候”“符号问题。 注意3:user后面是用户名,password后面是用户名对应的密码。 注意4:命令执行后有返回结果才是执行成功了。
6、msf配置连接
1
2
3
4
5
6
7
8
root# msfconsole
msf > db_status
[*] postgresql selected,no connection
msf > db_connect msf:admin@127.0.1/msf
[*] Rebuilding the module cache in the background...
msf > db_status
[*] postgresql connected to msf
msf >
1
db_connect -y /usr/share/metasploit-framework/config/database.yml
在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 并修改内容来完成设置。
1
2
3
root:/usr/share/metasploit-framework/config
root#vi database.yml
root#cat database.yml
1
2
3
4
5
6
7
8
9
development: &pgsql
adapter: postgresql
database: msf
username: msf
password: admin
host: localhost
port: 5432
pool: 5
timeout: 5
主要改database 、password 、host 这三个值
重新执行msfconsole即可直接链接数据库 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|