Last active
May 3, 2017 12:11
-
-
Save Creased/45be79fb059e9a60eb70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
### BEGIN INIT INFO | |
# Provides: honeyd | |
# Required-Start: | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Service to simulate hosts and networks | |
# Description: Daemon that provides a way to fully simulate | |
# virtual hosts on a network and any type of | |
# service running in those hosts. | |
### END INIT INFO | |
# | |
# /etc/init.d/honeyd | |
# | |
# Originally written by Miquel van Smoorenburg <[email protected]>. | |
# Modified for Debian GNU/Linux by Ian Murdock <[email protected]>. | |
# Modified for honeyd by Javier Fernandez-Sanguino <[email protected]> | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
# Daemon locations | |
DAEMON=/usr/bin/honeyd | |
# Daemon names | |
NAME=honeyd | |
# Pidfiles | |
PIDFILE=/var/run/honeyd.pid | |
# Labels | |
LABEL="Honeyd daemon" | |
DEFAULT=/etc/default/honeyd | |
LOGDIR="/var/log/honeyd" | |
DAEMONLOG="$LOGDIR/daemon.log" | |
# time to wait for daemons death, in seconds | |
DODTIME=5 | |
# Users to run the daemons as | |
DAEMONUSER=honeyd | |
# Defaults (should be changed in the | |
# /etc/default/honeyd file, not here) | |
RUN="no" | |
OPTIONS="" | |
INTERFACE="" | |
# Note: You should not need to modify anything below this. | |
test -x $DAEMON || exit 0 | |
. /lib/lsb/init-functions | |
if [ "$(id -u)" != "0" ] | |
then | |
echo "You must be root to start, stop or restart \"$LABEL\"." >&2 | |
exit 1 | |
fi | |
running_pid() { | |
# Check if a given process pid's cmdline matches a given name | |
pid=$1 | |
name=$2 | |
[ -z "$pid" ] && return 1 | |
[ ! -d /proc/$pid ] && return 1 | |
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1` | |
# Is this the expected server | |
[ "$cmd" != "$name" ] && return 1 | |
return 0 | |
} | |
running() { | |
# Check if the process is running looking at /proc | |
# (works for all users) | |
ret=1 | |
if [ -r "$PIDFILE" ] ; then | |
pid=`cat $PIDFILE` | |
running_pid $pid $DAEMON && ret=0 | |
else | |
# No pidfile (or not readable), probably no daemon present | |
procname=`/bin/ps h -C $DAEMON -U $DAEMONUSER` | |
[ -n "$procname" ] && ret=0 | |
fi | |
return $ret | |
} | |
not_configured () { | |
log_failure_msg "Not configured, will not be started" | |
if [ "$1" != "stop" ] | |
then | |
log_failure_msg "Please configure the daemon, edit $DEFAULT and set the \"RUN\" variable" | |
fi | |
log_end_msg 1 | |
exit 1 | |
} | |
# Read config (will override defaults) | |
# and check if it is configured | |
if [ -f "$DEFAULT" ] ; then | |
. $DEFAULT | |
fi | |
trap "" 1 | |
trap "" 15 | |
# This is the network in which honeyd will work | |
DAEMONOPTS="-f /usr/share/honeyd/honeyd.conf -l $LOGDIR/honeyd.log" | |
DAEMONOPTS="$DAEMONOPTS -p /usr/share/honeyd/nmap.prints" | |
DAEMONOPTS="$DAEMONOPTS -a /usr/share/honeyd/nmap.assoc" | |
DAEMONOPTS="$DAEMONOPTS -0 /usr/share/honeyd/pf.os" | |
DAEMONOPTS="$DAEMONOPTS -x /usr/share/honeyd/xprobe2.conf" | |
# Does the user exist? | |
if getent passwd | grep -q "^$DAEMONUSER:"; then | |
DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'` | |
DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'` | |
DAEMONOPTS="$DAEMONOPTS -u $DAEMONUID -g $DAEMONGID" | |
fi | |
if [ -z "$DAEMONUID" ] ; then | |
log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist." | |
exit 1 | |
fi | |
# Extra options (given by the user in /etc/default files) | |
DAEMONOPTS="$DAEMONOPTS $OPTIONS" | |
# Have we defined an interface? | |
if [ "x$INTERFACE" != "x" ]; | |
then | |
INTERFACE="-i $INTERFACE" | |
fi | |
start() | |
{ | |
if [ "x$RUN" != "xyes" ] ; then | |
not_configured | |
fi | |
date=`date -R` | |
echo "$date - Starting honeyd" >>$LOGDIR/daemon.log | |
start-stop-daemon --quiet --start --pidfile "$PIDFILE" \ | |
--exec $DAEMON --chdir /usr/share/honeyd/ \ | |
-- $DAEMONOPTS $INTERFACE $NETWORK >>$LOGDIR/daemon.log 2>&1 | |
} | |
stop() | |
{ | |
date=`date -R` | |
echo "$date - Stopping honeyd" >>$LOGDIR/daemon.log | |
start-stop-daemon --quiet --stop --pidfile $PIDFILE --oknodo \ | |
--exec $DAEMON >>$DAEMONLOG 2>&1 | |
} | |
case "$1" in | |
start) | |
log_daemon_msg "Starting $LABEL" "$NAME" | |
if running ; then | |
log_progress_msg "apparently already running" | |
log_end_msg 0 | |
exit 0 | |
else | |
start | |
if running ; then | |
log_end_msg 0 | |
else | |
log_failure_msg "ERROR while starting please check $DAEMONLOG" | |
log_end_msg 1 | |
fi | |
fi | |
;; | |
stop) | |
log_daemon_msg "Stopping $LABEL" "$NAME" | |
if running ; then | |
stop | |
log_end_msg $? | |
else | |
log_progress_msg "apparently not running" | |
log_end_msg 0 | |
exit 0 | |
fi | |
;; | |
restart) | |
log_daemon_msg "Restarting $LABEL" "$NAME" | |
if running ; then | |
stop | |
[ -n "$DODTIME" ] && sleep "$DODTIME"s | |
fi | |
if running ; then | |
log_failure_msg "Daemon did not stop (please check $DAEMONLOG)." | |
exit 1 | |
else | |
start | |
if running ; then | |
log_end_msg 0 | |
exit 0 | |
else | |
log_failure_msg "ERROR while starting please check $DAEMONLOG" | |
log_end_msg 1 | |
fi | |
fi | |
;; | |
status) | |
log_daemon_msg "Checking status of $LABEL" "$NAME" | |
if [ "x$RUN" != "xyes" ] ; then | |
log_progress_msg "not configured" | |
log_end_msg 1 | |
exit 1 | |
fi | |
if running ; then | |
log_end_msg 0 | |
else | |
log_progress_msg "apparently not running" | |
log_end_msg 1 | |
exit 1 | |
fi | |
;; | |
reload|force-reload) | |
log_daemon_msg "Reloading $LABEL" "$NAME" | |
if [ "x$RUN" != "xyes" ] ; then | |
not_configured | |
fi | |
if running ; then | |
start-stop-daemon --stop --pidfile $PIDFILE --signal 1 --exec $DAEMON | |
if running ; then | |
log_end_msg 0 | |
else | |
log_progress_msg "did not reload properly, check $ERRORLOG" | |
log_end_msg 1 | |
exit 1 | |
fi | |
else | |
log_progress_msg "Cannot reload as it is not running" | |
log_end_msg 1 | |
exit 1 | |
fi | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|reload|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment