知识屋:更实用的电脑技术知识网站
所在位置:首页 > 操作系统 > linux

BT5下自动配置pgsql的脚本

发布时间:2014-09-05 16:10:20作者:知识屋

#!/bin/sh
 
## Kill database process
echo "Killing database process .."
kill $(pgrep postgres) > /dev/null 2>&1
 
## replace the md5 auth with trust for local ipv4 connections
echo "Allowing all local IPV4 connections .."
cp /opt/framework3/postgresql/data/pg_hba.conf /opt/framework3/postgresql/data/pg_hba.conf.bak
cat /opt/framework3/postgresql/data/pg_hba.conf | sed -e 's/host all all 127.0.0.1//32 md5/host all all 127.0.0.1//32 trust/' > /opt/framework3/postgresql/data/tmp.conf
mv /opt/framework3/postgresql/data/tmp.conf /opt/framework3/postgresql/data/pg_hba.conf
 
## restart postgres server (only necessary during this process, on reboot it will start automatically)
echo "Restarting postgres server (only necessary during this process, on reboot it will start automatically) .."
su postgres -c "/opt/framework3/postgresql/bin/postgres -D /opt/framework3/postgresql/data -p 7175 &"
# wait for server to start
sleep 5
 
## Now we can access via psql we can change user for database
echo "Changing postgres user postgres's password to 'postgres_password' .."
su postgres -c "psql -h 127.0.0.1 -p 7175 -c /"ALTER USER postgres WITH PASSWORD 'postgres_password'/";" > /dev/null 2>&1
 
## Create a database for usage with msf
echo "Creating database 'msf_db' for use with metasploit .."
su postgres -c "psql -h 127.0.0.1 -p 7175 -c /"CREATE DATABASE msf_db/";" > /dev/null 2>&1
 
## change back to md5 auth
echo "Changing back to md5 auth .."
cat /opt/framework3/postgresql/data/pg_hba.conf | sed -e 's/host all all 127.0.0.1//32 trust/host all all 127.0.0.1//32 md5/' > /opt/framework3/postgresql/data/tmp.conf
mv /opt/framework3/postgresql/data/tmp.conf /opt/framework3/postgresql/data/pg_hba.conf
 
###############################
 
## msfconsole
 
## change ruby version
echo "##################################"
echo "Changing Ruby version - please choose the '0' option .."
echo "##################################"
update-alternatives --config ruby
 
## install postgres gem
gem install postgres
 
# go into msfconsole and choose the db_driver
echo "Updating msf .."
/opt/framework3/msf3/msfupdate
 
echo
echo "################################################## ####################"
echo "starting msfconsole .."
echo "now enter 'db_driver postgresql' and then 'db_connect postgres:postgres_password@127.0.0.1:7175/msf_db'"
echo "################################################## ####################"
 
/opt/framework3/msf3/msfconsole
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜