首页 > 技术文章 > [Kali_Metasploit]db_connect创建连接时无法连接的解决方案

webapplee 2014-11-04 08:34 原文

问题1复现路径:

  1. 终端输入msfconsole,进入msf命令行模式,需要等待若干分钟;

  2. 输入db_status,查看连接状态,两种结果:一,默认连接msf3;二,没有连接,显示postgresql selected, no connection

  3. 创建连接数据库msfbook,输入 db_connect postgres:toor@127.0.0.1/msfbook

现象:

  没有显示任何信息,输入db_status查看,仍没有连接

分析:

  没有相关账号和密码,所以无法连接

解决方案:

  1. 在#命令行模式下,输入sudo -u postgres psql postgres // 来创建账号

  2. 就会进入到postgres=#模式下,在msfconsole模式下输入 alter user postgres with password 'toor'; // 来修改密码

  3. 显示ALTER ROLE // 修改生效

  4. 退出postgres=#模式,重新输入db_connect postgres:toor@127.0.0.1/msfbook,就会出现一堆冗长的信息,这是创建连接数据表的过程,这只有在第一次创建postgres的msfbook库时出现冗长信息,以后就没有了,直接回到msf终端提示符。

提示:

  记得开始进入msfconsole前,启动postgresql和metasploit服务,命令如下:

    1. service postgresql start

    2. service metasploit start

 

问题2现象:

  根据以上的步骤进行创建连接数据库后,msf中会提示,创建时数据库编码错误,"Error while running command db_connect: Failed to connect to the database: PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template.: CREATE DATABASE "msfbook" ENCODING = 'utf8' Call stack:......"

分析:

  默认数据库编码问题

解决方案:

  1. sudo -u postgres psql postgres // 进入postgres用户PostgreSQL数据库模式中

  2. 输入 create database msfbook with encoding='SQL_ASCII';

  3. 显示 CREATE DATABASE // 创建成功

 

推荐阅读