Skip to content

Commit cd8073d

Browse files
author
root
committed
modified: bin/updatehoneypotip.sh
- fixed egrep to grep -E and /etc/dshield.ini new files: - etc/cowrie.pp - etc/cowrie1.pp - srv/cowrie/bin/cowrie
1 parent a5fb0d0 commit cd8073d

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed

bin/updatehoneypotip.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ fi
1515
honeypotip=$(curl -s https://www4.dshield.org/api/myip?json | jq .ip | tr -d '"')
1616
if echo -n $honeypotip | grep -E -q '^[0-9\.]+$'; then
1717
sed -i "s/^honeypotip=.*/honeypotip=$honeypotip/" /etc/dshield.ini
18+
if ! grep -q '^piid=' /etc/dshield.ini; then
19+
piid=$(openssl rand -hex 10)
20+
sed -i "^apikey/a piid=$piid" /etc/dshield.ini
21+
fi
22+
cp /etc/dshield.ini /srv/dshield/etc/
1823
else
1924
echo "Bad IP address"
2025
exit 9

etc/cowrie.pp

1.16 KB
Binary file not shown.

etc/cowrie1.pp

1.18 KB
Binary file not shown.

srv/cowrie/bin/cowrie

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
#!/bin/bash
2+
################################################################################
3+
# Don't edit this file
4+
#
5+
# Environment variables can be passed to change how this script runs.
6+
#
7+
# Set `COWRIE_VIRTUAL_ENV=my-env` to use a particular virtual environment.
8+
# By default Cowrie will look for `cowrie-env` in the current or parent
9+
# directory.
10+
#
11+
# Set `COWRIE_STDOUT=yes` to run in foreground mode and send logs to stdout
12+
#
13+
# Pass any other config variable as well, to further setup your environment!
14+
# For example: `COWRIE_TELNET_ENABLED=yes`
15+
################################################################################
16+
17+
DEFAULT_VIRTUAL_ENV=cowrie-env
18+
19+
first_time_use() {
20+
echo
21+
echo "Join the Cowrie community at: https://www.cowrie.org/slack/"
22+
echo
23+
}
24+
25+
python_version_warning() {
26+
if python -V 2>&1 | grep -q '^Python 2.'; then
27+
echo
28+
echo "DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020."
29+
echo "Cowrie has dropped support for Python 2.7."
30+
echo
31+
fi
32+
if python -V 2>&1 | grep -q '^Python 3.5'; then
33+
echo
34+
echo "DEPRECATION: Python 3.5 is no longer supported by Cowrie."
35+
echo
36+
fi
37+
}
38+
39+
find_cowrie_directory() {
40+
# Determine Cowrie directory
41+
if [[ "$0" = /* ]]
42+
then
43+
COWRIEDIR=$(dirname $0)/..
44+
else
45+
COWRIEDIR=$(dirname $PWD/$0)/..
46+
fi
47+
COWRIEDIR=$(cd ${COWRIEDIR} && pwd -P 2>/dev/null || pwd)
48+
}
49+
50+
activate_venv() {
51+
# Activate Python virtual environment
52+
VENV="$1"
53+
if [ ! -f "$VENV/bin/activate" ]
54+
then
55+
return 1
56+
fi
57+
. $VENV/bin/activate
58+
return 0
59+
}
60+
61+
cowrie_status() {
62+
# Print status
63+
PID=$(cat ${PIDFILE} 2>/dev/null || echo "")
64+
if [ -n "$PID" ]; then
65+
if ps -p "$PID" 2>&1 >/dev/null; then
66+
echo "cowrie is running (PID: ${PID})."
67+
else
68+
echo "cowrie is not running (PID: ${PID})."
69+
echo "Removing stale PID file ${PIDFILE}"
70+
rm -f ${PIDFILE}
71+
fi
72+
else
73+
echo "cowrie is not running."
74+
fi
75+
}
76+
77+
cowrie_start() {
78+
# Start Cowrie
79+
COWRIEARGS="$*"
80+
TWISTEDARGS="${XARGS} --umask=0022 --pidfile=${PIDFILE}"
81+
82+
# Run foreground or background. Foreground has no file log.
83+
if [ "$COWRIE_STDOUT" = "yes" ]; then
84+
TWISTEDARGS="${TWISTEDARGS} -n -l -"
85+
else
86+
TWISTEDARGS="${TWISTEDARGS} --logger cowrie.python.logfile.logger"
87+
fi
88+
89+
# 1. Check if any virtual environment is active
90+
# 2. Try COWRIE_VIRTUAL_ENV if defined
91+
# 3. Try DEFAULT_VIRTUAL_ENV
92+
# 4. Try ../DEFAULT_VIRTUAL_ENV
93+
# 5. Try without virtual environment
94+
95+
if [ ! -z "$VIRTUAL_ENV" ]; then
96+
echo 2>&1 "Using activated Python virtual environment \"$VIRTUAL_ENV\""
97+
elif activate_venv "$COWRIE_VIRTUAL_ENV"; then
98+
echo 2>&1 "Using custom Python virtual environment \"$VIRTUAL_ENV\""
99+
elif activate_venv "$DEFAULT_VIRTUAL_ENV"; then
100+
echo 2>&1 "Using default Python virtual environment \"$VIRTUAL_ENV\""
101+
# Look one directory higher for the virtual env to not pollute the Cowrie dir
102+
elif activate_venv "../$DEFAULT_VIRTUAL_ENV"; then
103+
echo 2>&1 "Using default Python virtual environment \"../$VIRTUAL_ENV\""
104+
else
105+
echo 2>&1 "Not using Python virtual environment"
106+
fi
107+
108+
python_version_warning
109+
110+
# Automatically check if the authbind is enabled or not
111+
authfile="/etc/authbind/byport/22"
112+
if [ -z ${AUTHBIND_ENABLED} ] && [ -x "$authfile" ] && command -v authbind >/dev/null; then
113+
AUTHBIND_ENABLED=yes
114+
else
115+
AUTHBIND_ENABLED=no
116+
fi
117+
118+
echo "Starting cowrie: [twistd ${TWISTEDARGS} cowrie ${COWRIEARGS}]..."
119+
if [ "$AUTHBIND_ENABLED" = "no" ]
120+
then
121+
exec twistd ${TWISTEDARGS} ${COWRIEARGS} cowrie
122+
else
123+
exec authbind --deep twistd ${TWISTEDARGS} ${COWRIEARGS} cowrie
124+
fi
125+
}
126+
127+
cowrie_stop () {
128+
# Stop Cowrie
129+
PID=$(cat ${PIDFILE} 2>/dev/null || echo "")
130+
if [ -n "$PID" ]; then
131+
echo "Stopping cowrie..."
132+
if kill -TERM $PID; then
133+
echo -n
134+
else
135+
echo "Removing stale PID file ${PIDFILE}"
136+
rm -f ${PIDFILE}
137+
fi
138+
else
139+
echo "cowrie is not running."
140+
fi
141+
}
142+
143+
cowrie_force_stop () {
144+
# Force Stop Cowrie
145+
PID=$(cat ${PIDFILE} 2>/dev/null || echo -n "")
146+
if [ -n "$PID" ]; then
147+
echo -n "Stopping cowrie..."
148+
if kill -TERM $PID; then
149+
((t = 60))
150+
while ((t > 1)); do
151+
sleep 1
152+
echo -n .
153+
if kill -0 $PID 2>/dev/null; then
154+
((t -= 1))
155+
else
156+
echo "terminated."
157+
return
158+
fi
159+
done
160+
kill -KILL $PID
161+
echo "killed."
162+
else
163+
echo "Removing stale PID file ${PIDFILE}"
164+
rm -f ${PIDFILE}
165+
fi
166+
else
167+
echo "cowrie is not running."
168+
fi
169+
}
170+
171+
cowrie_usage() {
172+
echo "usage: $0 <start|stop|force-stop|restart|status|shell>"
173+
}
174+
175+
# Mostly for Docker use, to quickly get a shell in the container
176+
cowrie_shell() {
177+
$SHELL
178+
}
179+
180+
################################################################################
181+
## Main script
182+
################################################################################
183+
184+
if [ "$#" = 0 ]
185+
then
186+
cowrie_usage
187+
exit 1
188+
fi
189+
190+
find_cowrie_directory $0
191+
cd ${COWRIEDIR}
192+
export PYTHONPATH=${PYTHONPATH}:${COWRIEDIR}/src
193+
194+
set -e
195+
196+
# Don't store pidfile on Docker persistent volume
197+
if [ "${COWRIE_STDOUT}" = "yes" ]; then
198+
PIDFILE=""
199+
else
200+
PIDFILE=var/run/cowrie.pid
201+
fi
202+
203+
if [ ! -f ${COWRIEDIR}/var/log/cowrie/cowrie.log ]
204+
then
205+
first_time_use
206+
fi
207+
208+
key=$1
209+
shift 1
210+
case $key in
211+
stop)
212+
cowrie_stop $*
213+
;;
214+
force-stop)
215+
cowrie_force_stop $*
216+
;;
217+
start)
218+
cowrie_start $*
219+
;;
220+
restart)
221+
cowrie_stop $*
222+
cowrie_start $*
223+
;;
224+
status)
225+
cowrie_status $*
226+
;;
227+
bash)
228+
cowrie_shell $*
229+
;;
230+
sh)
231+
cowrie_shell $*
232+
;;
233+
shell)
234+
cowrie_shell $*
235+
;;
236+
*)
237+
cowrie_usage
238+
exit 1
239+
;;
240+
esac

0 commit comments

Comments
 (0)