BT5下自动配置pgsql的脚本

来源:岁月联盟 编辑:exp 时间:2012-06-11
#!/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