mirror of
https://github.com/ziirish/burp-ui.git
synced 2026-05-15 14:16:08 -06:00
158 lines
4.5 KiB
Bash
Executable file
158 lines
4.5 KiB
Bash
Executable file
#!/bin/bash
|
|
set -e
|
|
|
|
trap appStop SIGINT SIGTERM
|
|
|
|
appStart () {
|
|
|
|
BURPUI_CONFIG=${BURPUI_CONFIG:-/etc/burp/burpui.cfg}
|
|
BURPUI_CLIENT_NAME=${BURPUI_CLIENT_NAME:-bui}
|
|
BURPUI_VERBOSE=${BURPUI_VERBOSE:-0}
|
|
BURPUI_UID=${BURPUI_UID:-5337}
|
|
BURPUI_GID=${BURPUI_GID:-5337}
|
|
BURPUI_PLUGINS=${BURPUI_PLUGINS:-none}
|
|
BURP_CLIENT_CONFIG=${BURP_CLIENT_CONFIG:-/tmp/burp.conf}
|
|
BURP_SERVER_CONFIG=${BURP_SERVER_CONFIG:-/etc/burp/burp-server.conf}
|
|
BURP_SERVER_ADDR=${BURP_SERVER_ADDR:-auto}
|
|
REDIS_SERVER=${REDIS_SERVER:-redis:6379}
|
|
DATABASE_URL=${DATABASE_URL:-sqlite:////var/lib/burpui/store.db}
|
|
TIMEZONE=${TIMEZONE:-Europe/Paris}
|
|
|
|
[ -e /usr/share/zoneinfo/$TIMEZONE ] && {
|
|
cp /usr/share/zoneinfo/$TIMEZONE /etc/localtime
|
|
echo "$TIMEZONE" >/etc/timezone
|
|
}
|
|
|
|
# Create burp-ui User
|
|
getent group | grep -q burpui || groupadd -g $BURPUI_GID burpui
|
|
getent passwd | grep -q burpui || useradd -r -m -d /var/lib/burpui -c 'Burp-UI daemon user' -u $BURPUI_UID -g $BURPUI_GID burpui
|
|
chown -R burpui: /var/log/gunicorn
|
|
|
|
[ -e /etc/burp/this_is_a_decoy_file_to_know_if_we_can_chown ] && {
|
|
chown -R burpui: /etc/burp
|
|
rm /etc/burp/this_is_a_decoy_file_to_know_if_we_can_chown
|
|
}
|
|
|
|
[ "$BURP_SERVER_ADDR" == "auto" ] && {
|
|
BURP_SERVER_ADDR=$(ip route sh | grep default | awk '{print $3;}')
|
|
}
|
|
|
|
[ -e "$BURPUI_CONFIG" ] || {
|
|
cp /usr/local/share/burpui/etc/burpui.sample.cfg $BURPUI_CONFIG
|
|
chown burpui: $BURPUI_CONFIG
|
|
}
|
|
|
|
# wait for redis to be up
|
|
sleep 3
|
|
|
|
LOGFILE=$(mktemp)
|
|
bui-manage -c $BURPUI_CONFIG setup_burp -b $BURP_CLIENT_CONFIG \
|
|
-s $BURP_SERVER_CONFIG -h $BURP_SERVER_ADDR -c $BURPUI_CLIENT_NAME \
|
|
-r $REDIS_SERVER -d $DATABASE_URL -p $BURPUI_PLUGINS 2>&1 | tee $LOGFILE
|
|
|
|
CELERY="True"
|
|
grep -q "Unable to contact the redis server" $LOGFILE && CELERY=""
|
|
rm $LOGFILE
|
|
|
|
[ "$DATABASE_URL" != "none" ] && {
|
|
su -l burpui -c "/usr/local/bin/bui-manage -c $BURPUI_CONFIG db upgrade"
|
|
}
|
|
|
|
# You can change log verbosity at runtime
|
|
[ -e /etc/gunicorn.d/burp-ui.example ] || cp -a /etc/gunicorn.d/burp-ui /etc/gunicorn.d/burp-ui.example
|
|
perl -pe "s#\@BURPUI_CONFIG\@#$BURPUI_CONFIG#" /etc/gunicorn.d/burp-ui.example >/etc/gunicorn.d/burp-ui
|
|
perl -i -pe "s#\@BURPUI_VERBOSE\@#$BURPUI_VERBOSE#" /etc/gunicorn.d/burp-ui
|
|
|
|
ssl_cert_ca=$(grep -E "^\s*ssl_cert_ca\s*=" $BURP_CLIENT_CONFIG | cut -d= -f2 | sed -e "s/\s*//g")
|
|
ssl_cert=$(grep -E "^\s*ssl_cert\s*=" $BURP_CLIENT_CONFIG | cut -d= -f2 | sed -e "s/\s*//g")
|
|
ssl_key=$(grep -E "^\s*ssl_key\s*=" $BURP_CLIENT_CONFIG | cut -d= -f2 | sed -e "s/\s*//g")
|
|
|
|
[ -z "$ssl_cert_ca" ] && {
|
|
echo "Unable to locate ssl_cert_ca in $BURP_CLIENT_CONFIG"
|
|
exit 1
|
|
}
|
|
[ -z "$ssl_cert" ] && {
|
|
echo "Unable to locate ssl_cert in $BURP_CLIENT_CONFIG"
|
|
exit 1
|
|
}
|
|
[ -z "$ssl_key" ] && {
|
|
echo "Unable to locate ssl_key in $BURP_CLIENT_CONFIG"
|
|
exit 1
|
|
}
|
|
|
|
[ ! -e "$ssl_cert_ca" -a ! -e "$ssl_cert" -a ! -e "$ssl_key" ] && {
|
|
# pre-generate burp certs because of https://github.com/grke/burp/issues/512
|
|
TMPFILE=$(mktemp)
|
|
/usr/sbin/burp -c $BURP_CLIENT_CONFIG -a l 2>&1 >$TMPFILE
|
|
for file in $(grep "Could not find ssl" $TMPFILE | cut -d' ' -f8 | sed "s/:$//")
|
|
do
|
|
chgrp burpui $file
|
|
chmod g+rw $file
|
|
done
|
|
rm $TMPFILE
|
|
}
|
|
|
|
# start supervisord
|
|
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
|
|
|
|
echo "Starting crond..."
|
|
supervisorctl start cron >/dev/null
|
|
|
|
echo "Starting burp..."
|
|
supervisorctl start burp >/dev/null
|
|
|
|
[ -n "$CELERY" ] && {
|
|
echo "Starting bui-celery..."
|
|
supervisorctl start bui-celery >/dev/null
|
|
}
|
|
|
|
echo "Starting gunicorn..."
|
|
/etc/init.d/gunicorn restart >/dev/null
|
|
|
|
# wait a bit for the logs to be populated
|
|
sleep 2
|
|
|
|
# watch the access logs
|
|
tail -F /var/log/gunicorn/burp-ui_info.log
|
|
}
|
|
|
|
appStop() {
|
|
echo ""
|
|
echo "Stopping gunicorn..."
|
|
/etc/init.d/gunicorn stop >/dev/null
|
|
echo "Stopping burp..."
|
|
supervisorctl stop burp >/dev/null
|
|
echo "Stopping crond..."
|
|
supervisorctl stop cron >/dev/null
|
|
echo "Stopping supervisord..."
|
|
kill -15 $(cat /var/run/supervisord.pid)
|
|
exit
|
|
}
|
|
|
|
appHelp () {
|
|
echo "Available options:"
|
|
echo " app:start - Starts the burp-ui server (default)"
|
|
echo " app:help - Displays the help"
|
|
echo " [command] - Execute the specified linux command eg. bash."
|
|
}
|
|
|
|
case "$1" in
|
|
app:start)
|
|
appStart
|
|
;;
|
|
*)
|
|
if [ -x $1 ]; then
|
|
$1
|
|
else
|
|
prog=$(which $1)
|
|
if [ -n "${prog}" ] ; then
|
|
shift 1
|
|
su -l burpui -c "$prog $@"
|
|
else
|
|
appHelp
|
|
fi
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|