Metasploit连接PostgreSQL
(1) 首先查看一下PostgreSQL数据库是否有在运行:netstat -tnpl | grep postgres,如果没有在运行就启动一下PostgreSQL服务:service postgresql start。
root@kali:~# netstat -tnpl | grep postgres
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 9867/postgres
tcp 0 0 127.0.0.1:5433 0.0.0.0:* LISTEN 9866/postgres
tcp6 0 0 ::1:5432 :::* LISTEN 9867/postgres
tcp600::1:5433:::*LISTEN9866/postgres
root@kali:~# service postgresql status //查看postgresql服务状态
root@kali:~#servicepostgresqlstart //启动postgresql服务
root@kali:~# service postgresql stop //停止postgresql服务
(2) 如果Metasploit的PostgreSQL数据库在连接报错或者没有连接上的情况下,我们就需要手动连接了,使用locate命令搜索找到database.yml数据库配置文件。
root@kali:~# locate database.yml
/usr/share/metasploit-framework/config/database.yml
/usr/share/metasploit-framework/config/database.yml.example
/usr/share/metasploit-framework/config/database.yml.travis
/usr/share/metasploit-framework/config/database.yml.vagrant
[...SNIP...]
(3) 使用PostgreSQL用户连接到PostgreSQL数据库,新建1个msf3的数据库和用户,密码为123456。
root@kali:~# sudo -u postgres psql postgres
psql (9.5.4, server 9.5.0)
Type "help" for help.
postgres=# create database msf3;
CREATE DATABASEpostgres=# create user msf3;
CREATE ROLE
postgres=# alter user msf3 with password '123456';
CREATE ROLE
(4) 使用db_connect -y命令连接已改好database.yml数据库配置文件即可,db_status查看连接状态。
msf > db_connect
[*] Usage: db_connect <user:pass>@<host:port>/<database>
[*] OR: db_connect -y [path/to/database.yml]
[...SNIP...]
msf > db_connect -y /usr/share/metasploit-framework/config/database.yml
[-] postgresql already connected to msf3
[-] Run db_disconnect first if you wish to connect to a different database
msf > db_status
[*] postgresql connected to msf3
(5) PostgreSQL数据库服务默认是没有开启自启动的,每次启动Metasploit时都需要手动连接数据库,可使用以下命令来设置PostgreSQL服务的自启动。
root@kali:~# update-rc.d postgresql enable
root@kali:~# update-rc.d postgresql disabled
常用PostgreSQL命令参数:
root@kali:~#sudopasswd-dpostgres //删除postgres用户的密码
root@kali:~#sudo-upostgrespasswd //设置postgres用户的密码
\? //帮助
\l //所有数据库
\du //所有用户名
\s //命令行记录
\q //退出命令行
\c //切换数据库
\d //列出当前数据库的数据表
\d tablename //列出指定表的字段
\d+ tablename //查看指定表的情况