Right. I've fixed the setup-unicornscan.sh script so that it works on my installation of Back|Track 5 R3 (and should be capable of being run multiple times, should the need arise). The whole script is too long to post here, but the following patch should be sufficient:
Code:
#*** setup-unicornscan.sh.orig 2013-01-09 17:03:59.141728098 +0000
--- setup-unicornscan.sh 2013-01-11 10:07:44.217956451 +0000
***************
*** 26,33 ****
use_existing_pgsql=1
psqlbin="/opt/metasploit/postgresql/bin"
! psqlcmd="psql.bin -h 127.0.0.1 -p 7175"
! createdbcmd="createdb.bin -h 127.0.0.1 -p 7175"
MSF3_PG_EXISTS=1
--- 26,37 ----
use_existing_pgsql=1
psqlbin="/opt/metasploit/postgresql/bin"
! psqldata="/opt/metasploit/postgresql/data"
! psqlscripts="/opt/metasploit/postgresql/scripts"
! postgres_port=7337
! psqlcmd="$psqlbin/psql -h 127.0.0.1 -p $postgres_port"
! createdbcmd="$psqlbin/createdb -h 127.0.0.1 -p $postgres_port"
! createusercmd="$psqlbin/createuser -h 127.0.0.1 -p $postgres_port"
MSF3_PG_EXISTS=1
***************
*** 43,79 ****
if [ $use_existing_pgsql -eq 1 ]; then
# patch pg_hba.conf to allow local connections to existing postgresql install
! cat > /opt/metasploit/postgresql/data/pg_hba.diff.patch <<"END-OF-FILE"
! *** pg_hba.conf.orig 2011-05-14 23:19:58.589122626 -0400
! --- pg_hba.conf 2011-05-14 23:50:08.059123544 -0400
***************
! *** 71,78 ****
! # TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
! ! local all all md5
# IPv4 local connections:
! ! host all all 127.0.0.1/32 md5
# IPv6 local connections:
! ! host all all ::1/128 md5
! --- 71,78 ----
! # TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
! ! local all all trust
# IPv4 local connections:
! ! host all all 127.0.0.1/32 trust
# IPv6 local connections:
! ! host all all ::1/128 trust
END-OF-FILE
! cd /opt/metasploit/postgresql/data/
if [ -f ./pg_hba.diff.patch ]; then
patch -c -b -p0 --posix -i pg_hba.diff.patch
chown postgres pg_hba.conf
! /opt/metasploit/postgresql/scripts/ctl.sh stop
sleep 5
! /opt/metasploit/postgresql/scripts/ctl.sh start
sleep 5
else
--- 47,90 ----
if [ $use_existing_pgsql -eq 1 ]; then
# patch pg_hba.conf to allow local connections to existing postgresql install
! cat > $psqldata/pg_hba.diff.patch <<"END-OF-FILE"
! --- pg_hba.conf.orig 2012-08-09 22:53:26.000000000 +0100
! *** pg_hba.conf 2013-01-10 16:07:52.416523319 +0000
***************
! *** 81,91 ****
! # TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
! ! local all all md5
# IPv4 local connections:
! ! host all all 127.0.0.1/32 md5
# IPv6 local connections:
! ! host all all ::1/128 md5
! # Allow replication connections from localhost, by a user with the
! # replication privilege.
! #local replication postgres md5
! --- 81,91 ----
! # TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
! ! local all all trust
# IPv4 local connections:
! ! host all all 127.0.0.1/32 trust
# IPv6 local connections:
! ! host all all ::1/128 trust
! # Allow replication connections from localhost, by a user with the
! # replication privilege.
! #local replication postgres md5
END-OF-FILE
! cd $psqldata/
if [ -f ./pg_hba.diff.patch ]; then
+ cp -p pg_hba.conf.orig pg_hba.conf
patch -c -b -p0 --posix -i pg_hba.diff.patch
chown postgres pg_hba.conf
! $psqlscripts/ctl.sh stop
sleep 5
! $psqlscripts/ctl.sh start
sleep 5
else
***************
*** 138,152 ****
func_getUniCreds
# add 'scan' user (default for unicornscan) with pw:scanit! (default) and create database
! sudo -u postgres $psqlbin/createuser -d -S -R $uni_user_esc
! sudo -u postgres $psqlbin/psql -c "alter user $uni_user_esc with password '$uni_pw_esc'"
# create system user 'scan' for the database using Ident auth
adduser --no-create-home --disabled-login --gecos '' $uni_user_esc
! sudo -u $uni_user_esc $psqlbin/$createdbcmd -O $uni_user_esc $uni_db_esc
! sudo -u $uni_user_esc $psqlbin/$psqlcmd -d $uni_db_esc < $SCRIPT_PATH/unicornscan/src/output_modules/database/sql/pgsql_schema.sql
! sudo -u $uni_user_esc $psqlbin/$psqlcmd -d $uni_db_esc < $SCRIPT_PATH/unicornscan/www-front-end/lib/session.sql
# copy GeoIP.dat file to unicornscan location
cp /usr/share/GeoIP/GeoIP.dat /usr/local/etc/unicornscan/
--- 149,167 ----
func_getUniCreds
+ # In case we're running it for a second time, drop the database and user
+ sudo -u postgres $psqlcmd -c "drop database $uni_db_esc"
+ sudo -u postgres $psqlcmd -c "drop role $uni_user_esc"
+
# add 'scan' user (default for unicornscan) with pw:scanit! (default) and create database
! sudo -u postgres $createusercmd -d -S -R $uni_user_esc
! sudo -u postgres $psqlcmd -c "alter user $uni_user_esc with password '$uni_pw'"
# create system user 'scan' for the database using Ident auth
adduser --no-create-home --disabled-login --gecos '' $uni_user_esc
! sudo -u $uni_user_esc $createdbcmd -O $uni_user_esc $uni_db_esc
! sudo -u $uni_user_esc $psqlcmd -d $uni_db_esc -U $uni_user_esc < $SCRIPT_PATH/unicornscan/src/output_modules/database/sql/pgsql_schema.sql
! sudo -u $uni_user_esc $psqlcmd -d $uni_db_esc -U $uni_user_esc < $SCRIPT_PATH/unicornscan/www-front-end/lib/session.sql
# copy GeoIP.dat file to unicornscan location
cp /usr/share/GeoIP/GeoIP.dat /usr/local/etc/unicornscan/
***************
*** 567,574 ****
# fix port setting if using existing postgresql install on port 7175
if [ $use_existing_pgsql -eq 1 ]; then
! sed -i -e 's/port="5432"/port="7175"/g' $WWW_ROOT/unicornscan/lib/pgsqldbclass.php
! sed -i -e 's/host=localhost/host=localhost port=7175/g' /usr/local/etc/unicornscan/modules.conf
fi
echo ""
--- 582,593 ----
# fix port setting if using existing postgresql install on port 7175
if [ $use_existing_pgsql -eq 1 ]; then
! sed -i -e 's/username="postgres"/username="'$uni_user'"/g' $WWW_ROOT/unicornscan/lib/pgsqldbclass.php
! sed -i -e 's/password=""/password="'$uni_pw'"/g' $WWW_ROOT/unicornscan/lib/pgsqldbclass.php
! sed -i -e 's/port="5432"/port="'$postgres_port'"/g' $WWW_ROOT/unicornscan/lib/pgsqldbclass.php
! sed -i -e 's/db="template1"/db="'$uni_db'"/g' $WWW_ROOT/unicornscan/lib/pgsqldbclass.php
! sed -i -e 's/host=localhost/host=localhost port='$postgres_port'/g' /usr/local/etc/unicornscan/modules.conf
! sed -i -e 's/port='$postgres_port' port='$postgres_port'/port='$postgres_port'/g' /usr/local/etc/unicornscan/modules.conf
fi
echo ""
***************
*** 596,606 ****
deluser $uni_user_esc
if [ $use_existing_pgsql -eq 1 ]; then
! cp /opt/metasploit/postgresql/data/pg_hba.conf /opt/metasploit/postgresql/data/pg_hba.conf.bak
! cp /opt/metasploit/postgresql/data/pg_hba.conf.orig /opt/metasploit/postgresql/data/pg_hba.conf
! /opt/metasploit/postgresql/scripts/ctl.sh stop
sleep 5
! /opt/metasploit/postgresql/scripts/ctl.sh start
fi
# if apache was running, try to restart it
--- 615,625 ----
deluser $uni_user_esc
if [ $use_existing_pgsql -eq 1 ]; then
! cp $psqldata/pg_hba.conf $psqldata/pg_hba.conf.bak
! cp $psqldata/pg_hba.conf.orig $psqldata/pg_hba.conf
! $psqlscripts/ctl.sh stop
sleep 5
! $psqlscripts/ctl.sh start
fi
# if apache was running, try to restart it
***************
*** 623,629 ****
sleep 2
clear
! echo "NOTE: unless custome values were specified, default values are:"
echo -e "(USER/DB/PW -> scan/scan/scanit!)"
echo -e "These credentials are found in the following files for unicornscan:"
echo -e " /usr/local/etc/unicornscan/modules.conf"
--- 642,648 ----
sleep 2
clear
! echo "NOTE: unless custom values were specified, default values are:"
echo -e "(USER/DB/PW -> scan/scan/scanit!)"
echo -e "These credentials are found in the following files for unicornscan:"
echo -e " /usr/local/etc/unicornscan/modules.conf"
You can apply the patch as "patch -c -b -p0 --posix -i setup-unicornscan.sh.diff.patch", assuming you've saved the patch as "setup-unicornscan.sh.diff.patch".