kali linux 2017.1 中 Metasploit 连接 postgres 数据库
-
重启 postgres 数据库
root@attacker:~# systemctl restart postgresql.service
-
修改数据库用户账号(postgres)的密码
1. 以管理员身份登录数据库 postgres 用户 root@attacker:~# sudo -u postgres psql psql (9.6.3) Type "help" for help. 2. 修改数据库 postgres 用户的密码 postgres=# alter user postgres with password 'admin'; ALTER ROLE postgres=# \q (退出数据库)
-
修改 Linux 系统的 postgres 用户的密码(密码与数据库用户 postgres 的密码相同)
1. 修改 postgres 数据库用户的密码 root@attacker:~# passwd postgres Enter new UNIX password: admin Retype new UNIX password: admin passwd: password updated successfully
-
修改 PostgresSQL 数据库配置实现远程访问
1. 修改数据库监听地址 root@attacker:~# vim /etc/postgresql/9.6/main/postgresql.conf listen_addresses = '0.0.0.0' #59行 password_encryption = on #88行 2. pg_hba.conf是客户端认证配置文件,定义如何认证客户端 root@attacker:~# vim /etc/postgresql/9.6/main/pg_hba.conf host all all 0.0.0.0 md5 #93行 3. 重启 postgres 数据库服务 root@attacker:~# systemctl restart postgresql.service
-
管理PostgreSQL用户和数据库
1. 以管理员身份登录数据库 postgres 用户 root@attacker:~# psql -U postgres -h 127.0.0.1 Password for user postgres: admin psql (9.6.3) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. 2. 创建数据库用户及其密码 postgres=# create user msf with password 'admin'; CREATE ROLE 3. 修改数据库用户密码 postgres=# alter user postgres with password 'admin'; ALTER ROLE 4. 创建数据库及其属主 postgres=# create database msf with owner=msf; CREATE DATABASE 5. 退出数据库 postgres=# \q (退出数据库)
-
metasploit 配置连接
1. 切换渗透测试数据库 msf > db_status [*] postgresql connected to msf msf > db_disconnect msf > db_status [*] postgresql selected, no connection 2. 连接 postgres 数据库 msf > db_status [*] postgresql selected, no connection msf > db_connect [*] Usage: db_connect <user:pass>@<host:port>/<database> [*] OR: db_connect -y [path/to/database.yml] [*] Examples: [*] db_connect user@metasploit3 [*] db_connect user:pass@192.168.0.2/metasploit3 [*] db_connect user:pass@192.168.0.2:1500/metasploit3 msf > db_connect msf:admin@127.0.0.1/msf (数据库中的用户和密码) [*] Rebuilding the module cache in the background... msf > db_status [*] postgresql connected to msf
-
配置自动连接
1. 创建文件备份 root@attacker:/usr/share/metasploit-framework/config# cp database.yml database.yml.bak 2. 从样例复制文件 root@attacker:/usr/share/metasploit-framework/config# cp database.yml.example database.yml 3. 编辑文件 root@attacker:/usr/share/metasploit-framework/config# vim database.yml development: &pgsql adapter: postgresql database: msf #数据库名 username: msf #数据库用户名 password: admin #数据库用户密码 host: localhost port: 5432 pool: 200 timeout: 5
-
重新连接 msfconsole
root@attacker:~# msfconsole