[Kali_Metasploit]db_connect建立鏈接時沒法鏈接的解決方案

問題1復現路徑:sql

  1. 終端輸入msfconsole,進入msf命令行模式,須要等待若干分鐘;數據庫

  2. 輸入db_status,查看鏈接狀態,兩種結果:一,默認鏈接msf3;二,沒有鏈接,顯示postgresql selected, no connectionpost

  3. 建立鏈接數據庫msfbook,輸入 db_connect postgres:toor@127.0.0.1/msfbook編碼

現象:命令行

  沒有顯示任何信息,輸入db_status查看,仍沒有鏈接postgresql

分析:it

  沒有相關帳號和密碼,因此沒法鏈接io

解決方案:console

  1. 在#命令行模式下,輸入sudo -u postgres psql postgres // 來建立帳號coding

  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 // 建立成功

相關文章
相關標籤/搜索