Repository navigation
Expand file tree
/
Copy pathhoneyd.init
More file actions
242 lines (220 loc) · 5.9 KB
/
Copy pathhoneyd.init
File metadata and controls
242 lines (220 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/sh -e
#
### BEGIN INIT INFO
# Provides: honeyd
# Required-Start:
# Required-Stop: $remote_fs $syslog
# Default-Start:
# Default-Stop:
# 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 <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for honeyd by Javier Fernandez-Sanguino <jfs@debian.org>
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/honeypot"
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 /etc/honeypot/honeyd.conf -l $LOGDIR/honeyd.log"
DAEMONOPTS="$DAEMONOPTS -p /etc/honeypot/nmap.prints"
DAEMONOPTS="$DAEMONOPTS -a /etc/honeypot/nmap.assoc"
DAEMONOPTS="$DAEMONOPTS -0 /etc/honeypot/pf.os"
DAEMONOPTS="$DAEMONOPTS -x /etc/honeypot/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
sta
8000
rt()
{
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