Backtrack5的Postpresql的使用

Backtrack5的Postpresql的使用

在使用Backtrack5的Postpresql时发现没法正常连接进去,出现如下错误

-----------------------------------------------------------------------------------------------------

 

msf > db_connect postgres:[email protected]/msfbook

[-] Error while running command db_connect: Failed to connect to the database: could not connect to server: Connection refused

Is the server running on host "127.0.0.1" and accepting

TCP/IP connections on port 5432?

-----------------------------------------------------------------------------------------------------

从这里我们看出

 db_connect命令

默认去连接

5432接口,而我们可以通过多种方式看到开启的端口其实是

7337

 

【1】

 

root@bt:~# ps -ef|grep post

 

 

 

root      3554     1  0 19:50 tty1     00:00:13 gedit /opt/metasploit/postgresql/data/pg_hba.conf

postgres  4980     1  0 21:11 pts/2    00:00:00 /opt/metasploit/postgresql/bin/postgres.bin -D /opt/metasploit/postgresql/data -p 7337

【2】/opt/metasploit/postgresql/data/postgresql.conf文件里有

 

# CONNECTIONS AND AUTHENTICATION

#------------------------------------------------------------------------------

 

# - Connection Settings -

 

listen_addresses = '*'# what IP address(es) to listen on;

# comma-separated list of addresses;

# defaults to 'localhost', '*' = all

# (change requires restart)

#port = 7377# (change requires restart)

max_connections = 100# (change requires restart)

【3】/etc/init.d/metasploit-postgres restart

 

LOG:  received smart shutdown request

LOG:  autovacuum launcher shutting down

LOG:  shutting down

LOG:  database system is shut down

/opt/metasploit/postgresql/scripts/ctl.sh : postgresql stopped

LOG:  database system was shut down at 2013-03-02 20:45:52 CST

LOG:  database system is ready to accept connections

LOG:  autovacuum launcher started

/opt/metasploit/postgresql/scripts/ctl.sh : postgresql  started at port 7337

 

------------------------------------------------------------------------------

接着用psql连接去连接发现

root@bt:~# psql

程序“psql”尚未安装。  您可以使用以下命令安装:

-----------------------------------------------------------------------------

然后安装

root@bt:~# apt-get install postgresql-client-common

----------------------------------------------------------------------------

安装完后发现还是有问题

Error: You must install at least one postgresql-client-<version> package.

奇怪了,这个时候去查看安装的依赖包关系

root@bt:~# apt-get install postgresql libpq-dev

下列软件包有未满足的依赖关系:

  libpq-dev: 依赖: libpq5 (= 8.4.8-0ubuntu0.10.04) 但是 8.4.12-0ubuntu10.04 正要被安装

被打败了。。。。。果断执行

root@bt:~# sudo apt-get install postgresql-8.4 postgresql-client-8.4

--------------------------------------------------------------------------------

这个时候发现其实已经重装好了postgresql了,版本是8.4

用命令重新启动:/etc/init.d/postgresql-8.4 restart

 

 

root@bt:/etc/init.d# sudo su postgres -c psql
psql (8.4.8)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'Test12345';
ALTER ROLE

postgres-# \q
could not save history to file "/home/postgres/.psql_history": No such file or directory
root@bt:/etc/init.d# sudo passwd -d postgres
passwd: password expiry information changed.
root@bt:/etc/init.d# sudo su postgres -c passwd
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

----------------------------------------------------------------------------------------------------------

root@bt:/etc/init.d# update-alternatives --config ruby
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/ruby1.8     500       auto mode
  1            /usr/bin/ruby1.8     500       manual mode
* 2            /usr/bin/ruby1.9.2   400       manual mode

Press enter to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/bin/ruby1.8 to provide /usr/bin/ruby (ruby) in auto mode.


root@bt:/etc/init.d# gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0... 
-----------------------------------------------------------
最后一步,连接注意是
msf > db_connect postgres:"test12345"@127.0.0.1/postgres

 

你可能感兴趣的:(Backtrack5的Postpresql的使用)