#!/bin/sh
# ------------------------------------------------------------------------------
# stealth.sh:   Sets up a stealth environment for promiscous networking.
#
# Usage:        Must be called by root.
#
# Notes:        This script checks /etc/hosts.deny for the "ALL: ALL" line.
#               It is assumed that you do not have any other services allowed
#               within the file that may override. You should also be certain
#               that your /etc/hosts.allow does not override the deny file in
#               any way that may compromise your security.
#
#               Some services are shutdown manually when entering promiscous
#               mode because they are independant of the inetd or xinetd
#               daemon.
#
# Author:       Sean Blankenship <seanb/at/writeme/dot/com>.
# Modified:     12/11/2000.
# ------------------------------------------------------------------------------
stopservice() {
        ps -A | grep $1 >/dev/null 2>&1; TEST="$?"
        if [ $TEST = "0" ]; then
                /etc/rc.d/init.d/$1 stop
        fi
}
startservice() {
        ps -A | grep $1 >/dev/null 2>&1; TEST="$?"
        if [ $TEST = "1" ]; then
                /etc/rc.d/init.d/$1 start
        fi
}
case $1 in
        start)
                echo "Going into promiscous mode..."
                echo ""
                cat /etc/hosts.deny|grep "^ALL:.*ALL" >/dev/null 2>&1; TEST="$?"
                if [ $TEST = "1"  ]; then
                        echo "/etc/hosts.deny is open, add \"ALL: ALL\""
                fi
                stopservice sendmail
                stopservice httpd
                stopservice sshd
                ;;
        stop)
                echo "Leaving promiscous mode..."
                echo ""
                startservice sendmail
                startservice httpd
                startservice sshd
                ;;
        restart)
                echo "Not implemented..."
                echo ""
                exit 1
                ;;
        *)
                echo "Usage: $(basename $0) [start|stop|restart]"
                echo ""
                exit 1
esac
echo ""
exit 0