@@ -20,6 +20,11 @@ readonly myversion=98
2020
2121# Major Changes (for details, see Github):
2222#
23+ # - V99 (Freek)
24+ # - fixed some missing sudos
25+ # - adapted to support newest openSUSE
26+ # - added the https port 8443
27+ #
2328# - V98 (Johannes)
2429# - new web hpot (Mark Baggett)
2530# - installer no longer requires root / better priv separation
@@ -293,10 +298,11 @@ LOGFILE="${LOGDIR}/install_${INSTDATE}.log"
293298SSHHONEYPORT=2222
294299TELNETHONEYPORT=2223
295300WEBHONEYPORT=8000
301+ HTTPSHONEYPORT=8443
296302SSHREDIRECT=" 22"
297303TELNETREDIRECT=" 23 2323"
298304WEBREDIRECT=" 80 8080 7547 5555 9000"
299- HONEYPORTS=" ${SSHHONEYPORT} ${TELNETHONEYPORT} ${WEBHONEYPORT} "
305+ HONEYPORTS=" ${SSHHONEYPORT} ${TELNETHONEYPORT} ${WEBHONEYPORT} ${HTTPSHONYPORT} "
300306
301307# create and setup log directory
302308if [ ! -d ${LOGDIR} ]; then
@@ -771,10 +777,10 @@ if [ "$FAST" == "0" ]; then
771777 outlog " Updating your openSUSE Operating System will now be done."
772778 sudorun ' zypper --non-interactive dup --no-recommends'
773779 outlog " Installing additional packages"
774- sudorun ' zypper --non-interactive install --no-recommends cron gcc libffi-devel python311 -devel libopenssl-devel rsyslog dialog'
780+ sudorun ' zypper --non-interactive install --no-recommends cron gcc libffi-devel python3 -devel libopenssl-devel rsyslog dialog'
775781 sudorun ' zypper --non-interactive install --no-recommends perl-libwww-perl perl-Switch perl-LWP-Protocol-https python3-requests'
776- sudorun ' zypper --non-interactive install --no-recommends python3-pycryptodome python3-virtualenv'
777- sudorun ' zypper --non-interactive install --no-recommends python311 -pip rng-tools curl openssh unzip'
782+ sudorun ' zypper --non-interactive install --no-recommends python3-pycryptodome python3-virtualenv python3-dateutils '
783+ sudorun ' zypper --non-interactive install --no-recommends python3 -pip rng-tools curl openssh unzip'
778784 sudorun ' zypper --non-interactive install --no-recommends net-tools-deprecated patch logrotate'
779785 sudorun ' zypper --non-interactive install --no-recommends system-user-mail mariadb libmariadb-devel python3-PyMySQL jq'
780786 sudorun ' zypper --non-interactive install --no-recommends python3-python-snappy snappy-devel gcc-c++'
@@ -886,7 +892,7 @@ if [ -x /etc/init.d/cowrie ]; then
886892fi
887893# in case systemd is used
888894outlog " Stopping cowrie via systemd"
889- sudo systemctl stop cowrie
895+ [ " $( sudo systemcl is-active cowrie.service ) " = " active " ] && sudo systemctl stop cowrie
890896
891897if [ " $FAST " == " 0" ]; then
892898
980986 drun " cat /etc/modprobe.d/ipv6.conf.bak"
981987 drun " cat /etc/modprobe.d/ipv6.conf"
982988else # in openSUSE
983- run " grep -q 'ipv6.conf' /etc/sysctl.d/70-yast.conf"
984- # shellcheck disable=SC2181
985- if [ ${?} -ne 0 ]; then
986- dlog " Disabling IPv6 in /etc/sysctl.d/70-yast.conf"
987- dsudorun ' echo "net.ipv4.ip_forward = 0" >> /etc/sysctl.d/70-yast.conf'
988- dsudorun ' echo "net.ipv6.conf.all.forwarding = 0" >> /etc/sysctl.d/70-yast.conf'
989- dsudorun ' echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.d/70-yast.conf'
990- else
991- dlog " IPv6 already disabled in /etc/sysctl.d/70-yast.conf"
992- fi
989+ iface=$( ip -4 route show | grep ' ^default ' | head -1 | cut -f5 -d' ' )
990+ dsudorun " nmcli device modify $iface ipv6.method 'disabled'"
993991fi
994992
995993# ##########################################################
@@ -1001,7 +999,8 @@ if ! grep -qE '^webhpot' /etc/passwd; then
1001999 if [ " $ID " != " opensuse" ]; then
10021000 sudorun ' adduser --gecos "Honeypot,A113,555-1212,555-1212" --disabled-password --quiet --home /srv/web --no-create-home webhpot'
10031001 else
1004- sudorun ' useradd -c "Honeypot,A113,555-1212,555-1212" -M -U -d /srv/web webhpot'
1002+ sudorun ' useradd -c "Honeypot,A113,555-1212,555-1212" -M -U -d /srv/web webhpot'
1003+ sudorun ' passwd -d webhpot' # disable password
10051004 fi
10061005 outlog " Added user 'webhpot'"
10071006else
@@ -1778,7 +1777,7 @@ EOF
17781777
17791778else # use_iptables = False -> use nftables
17801779 dlog " using nftables, not iptables"
1781- cat > /etc/network /ruleset.nft << EOF
1780+ cat > ${TMPDIR} /ruleset.nft << EOF
17821781# NFT ruleset generated on $( date)
17831782add table ip filter
17841783add chain ip filter INPUT { type filter hook input priority 0; policy drop; }
@@ -1789,7 +1788,7 @@ add rule ip filter INPUT iifname "${interface}" ct state related,established co
17891788EOF
17901789
17911790 # allow pings from localnet
1792- echo " # allow ping from local network" >> /etc/network /ruleset.nft
1791+ echo " # allow ping from local network" >> ${TMPDIR} /ruleset.nft
17931792 echo " add rule ip filter INPUT iifname \" $interface \" ip saddr ${localnet} icmp type echo-request counter accept" >> " ${TMPDIR} " /ruleset.nft
17941793
17951794 # insert IPs and ports for which honeypot has to be disabled
@@ -1928,24 +1927,53 @@ fi
19281927if [ " $INTERACTIVE " == 1 ]; then
19291928 dlog " changing port for sshd"
19301929
1931- run " sed \" s/^[#\s]*Port 22\s*$/Port ${SSHDPORT} /\" < /etc/ssh/sshd_config > ${TMPDIR} /sshd_config"
1932- sudorun " mv ${TMPDIR} /sshd_config /etc/ssh/sshd_config"
1933-
1934- dlog " checking if modification was successful"
1935- if [ " $( grep -c " ^Port ${SSHDPORT} $" /etc/ssh/sshd_config) " -ne 1 ]; then
1936- dialog --title ' sshd port' --ok-label ' Understood.' --cr-wrap --msgbox " Congrats, you had already changed your sshd port to something other than 22.
1937-
1930+ if [ -f /etc/ssh/sshd_config ] ; then
1931+ run " sed \" s/^[#\s]*Port 22\s*$/Port ${SSHDPORT} /\" < /etc/ssh/sshd_config > ${TMPDIR} /sshd_config"
1932+ sudorun " mv ${TMPDIR} /sshd_config /etc/ssh/sshd_config"
1933+ dlog " checking if modification was successful"
1934+ if [ " $( grep -c " ^Port ${SSHDPORT} $" /etc/ssh/sshd_config) " -ne 1 ]; then
1935+ dialog --title ' sshd port' --ok-label ' Understood.' --cr-wrap --msgbox " Congrats, you had already changed your sshd port to something other than 22.
19381936Please clean up and either
19391937 - change the port manually to ${SSHDPORT}
19401938 in /etc/ssh/sshd_config OR
19411939 - clean up the firewall rules and
19421940 other stuff reflecting YOUR PORT" 13 50
1943- clear
1941+ clear
19441942
1945- dlog " check unsuccessful, port ${SSHDPORT} not found in sshd_config"
1946- drun ' cat /etc/ssh/sshd_config | grep -v "^\$" | grep -v "^#"'
1947- else
1948- dlog " check successful, port change to ${SSHDPORT} in sshd_config"
1943+ dlog " check unsuccessful, port ${SSHDPORT} not found in sshd_config"
1944+ drun ' cat /etc/ssh/sshd_config | grep -v "^\$" | grep -v "^#"'
1945+ else
1946+ dlog " check successful, port change to ${SSHDPORT} in sshd_config"
1947+ fi
1948+ else # when /etc/ssh/sshd_config does not exist
1949+ if [ " $( cat /etc/ssh/sshd_config.d/* .conf | grep -c " ^Port ${SSHDPORT} \$ " ) " -ne 0 ] ; then
1950+ dlog " check succesfull, port changed to ${SSHDPORT} in a file in /etc/ssh/sshd.config.d/"
1951+ else
1952+ if [ -n " $( cat /etc/ssh/sshd_config.d/* .conf) " ] && [ " $( cat /etc/ssh/sshd_config.d/* .conf | grep -c " ^Port " ) " -ge 1 ] ; then
1953+ dialog --title ' sshd port' --ok-label ' Understood.' --cr-wrap --msgbox " Congrats, you had already changed your sshd port to something other than 22.
1954+ Please clean up and either
1955+ - change the port manually to ${SSHDPORT}
1956+ in a file in /etc/ssh/sshd_config.d/*.conf OR
1957+ - clean up the firewall rules and
1958+ other stuff reflecting YOUR PORT" 13 50
1959+ clear
1960+ else # a file Port*.conf does not exist
1961+ echo " Port ${SSHDPORT} " > " ${TMPDIR} " /Port_${SSHDPORT} .conf
1962+ sudorun " mv ${TMPDIR} /Port_${SSHDPORT} .conf /etc/ssh/sshd_config.d/"
1963+ sudorun " chown root:root /etc/ssh/sshd_config.d/Port_${SSHDPORT} .conf"
1964+ if [ -x /usr/sbin/getenforce ] ; then
1965+ if [ " $( sudo /usr/sbin/getenforce) " = " Enforcing" ] ; then
1966+ if [ ! -x /usr/sbin/semanage ] ; then
1967+ sudorun " zypper --non-interactive in --no-recommends policycoreutils-python-utils"
1968+ else
1969+ echo " ERROR utility semanage needs to be installed, exiting!!"
1970+ exit 9
1971+ fi
1972+ fi
1973+ sudorun " semanage port -a -t ssh_port_t -p tcp ${SSHDPORT} "
1974+ fi
1975+ fi
1976+ fi
19491977 fi
19501978fi # interactive
19511979# ##########################################################
19641992
19651993
19661994
1967- dsudorun ' cat /etc/rsyslog.d/dshield.conf'
1995+ dsudorun ' cat /etc/rsyslog.d/10- dshield.conf'
19681996
19691997# ##########################################################
19701998# # Further copying / configuration
@@ -1987,7 +2015,8 @@ if ! grep -qE '^webhpot' /etc/passwd; then
19872015 if [ " $ID " != " opensuse" ]; then
19882016 sudorun ' adduser --gecos "Honeypot,A113,555-1212,555-1212" --disabled-password --quiet --home /srv/web --no-create-home webhpot'
19892017 else
1990- sudorun ' useradd -c "Honeypot,A113,555-1212,555-1212" -M -U -d /srv/web webhpot'
2018+ sudorun ' useradd -c "Honeypot,A113,555-1212,555-1212" -M -U -d /srv/web webhpot'
2019+ sudorun ' passwd -d webhpot' # disable password
19912020 fi
19922021 outlog " Added user 'webhpot'"
19932022else
@@ -2022,8 +2051,9 @@ if [ -f ${DSHIELDDIR}/updatehoneypotip.sh ]; then
20222051 run " rm ${DSHIELDDIR} /updatehoneypotip.sh"
20232052fi
20242053do_copy " $progdir " /updatehoneypotip.sh ${DSHIELDDIR} 700
2025- [ " $ID " = " opensuse" ] &&
2054+ if [ " $ID " = " opensuse" ]; then
20262055 run " patch ${DSHIELDDIR} /DShield.py $progdir /../srv/dshield/DShield.patch"
2056+ fi
20272057
20282058# check: automatic updates allowed?
20292059
@@ -2164,6 +2194,7 @@ if ! grep '^cowrie:' -q /etc/passwd; then
21642194 sudorun ' adduser --gecos "Honeypot,A113,555-1212,555-1212" --disabled-password --quiet --home /srv/cowrie --no-create-home cowrie'
21652195 else
21662196 sudorun ' useradd -c "Honeypot,A113,555-1212,555-1212" -M -U -d /srv/cowrie cowrie'
2197+ sudorun ' passwd -d cowrie' # disable password
21672198 fi
21682199 outlog " Added user 'cowrie'"
21692200else
@@ -2254,6 +2285,8 @@ if [ "$FAST" == "0" ]; then
22542285 run ' sg cowrie -c "pip3 install --require-virtualenv --upgrade bcrypt"'
22552286 run ' sg cowrie -c "pip3 install --require-virtualenv --upgrade requests"'
22562287 run ' sg cowrie -c "pip3 install --require-virtualenv -r requirements.txt"'
2288+ run ' sg cowrie -c "pip3 install --require-virtualenv dateutils"'
2289+ run ' sg cowrie -c "pip3 install --require-virtualenv -e ."'
22572290 # shellcheck disable=SC2181
22582291 if [ ${?} -ne 0 ]; then
22592292 outlog " Error installing dependencies from requirements.txt. See ${LOGFILE} for details."
@@ -2282,7 +2315,8 @@ outlog "Doing further cowrie configuration."
22822315
22832316# step 6 (Generate a DSA key)
22842317dlog " generating cowrie SSH host key"
2285- sudorun " ssh-keygen -t dsa -b 1024 -N '' -f ${COWRIEDIR} /var/lib/cowrie/ssh_host_dsa_key "
2318+ # dsa is too insecure and possibly not supported anymore in ssh-keygen; so use rsa
2319+ sudorun " ssh-keygen -t rsa -b 1024 -N '' -f ${COWRIEDIR} /var/lib/cowrie/ssh_host_rsa_key "
22862320
22872321# step 5 (Install configuration file)
22882322dlog " copying cowrie.cfg and adding entries"
@@ -2315,13 +2349,20 @@ dlog "creating output for text commands"
23152349
23162350sudorun " mkdir -p ${TXTCMDS} /bin"
23172351sudorun " mkdir -p ${TXTCMDS} /usr/bin"
2318- sudorun " df > ${TXTCMDS} /bin/df"
2319- sudorun " dmesg > ${TXTCMDS} /bin/dmesg"
2320- sudorun " mount > ${TXTCMDS} /bin/mount"
2321- sudorun " ulimit > ${TXTCMDS} /bin/ulimit"
2322- sudorun " lscpu > ${TXTCMDS} /usr/bin/lscpu"
2323- sudorun " echo '-bash: emacs: command not found' > ${TXTCMDS} /usr/bin/emacs"
2324- sudorun " echo '-bash: locate: command not found' > ${TXTCMDS} /usr/bin/locate"
2352+ sudorun " df > ${TMPDIR} /df"
2353+ sudorun " mv ${TMPDIR} /df ${TXTCMDS} /bin/df"
2354+ sudorun " dmesg > ${TMPDIR} /dmesg"
2355+ sudorun " mv ${TMPDIR} /dmesg ${TXTCMDS} /bin/dmesg"
2356+ sudorun " mount > ${TMPDIR} /mount"
2357+ sudorun " mv ${TMPDIR} /mount ${TXTCMDS} /bin/mount"
2358+ run " ulimit > ${TMPDIR} /ulimit"
2359+ sudorun " mv ${TMPDIR} /ulimit ${TXTCMDS} /bin/ulimit"
2360+ sudorun " lscpu > ${TMPDIR} /lscpu"
2361+ sudorun " mv ${TMPDIR} /lscpu ${TXTCMDS} /usr/bin/lscpu"
2362+ sudorun " echo '-bash: emacs: command not found' > ${TMPDIR} /emacs"
2363+ sudorun " mv ${TMPDIR} /emacs ${TXTCMDS} /usr/bin/emacs"
2364+ sudorun " echo '-bash: locate: command not found' > ${TMPDIR} /locate"
2365+ sudorun " mv ${TMPDIR} /locate ${TXTCMDS} /usr/bin/locate"
23252366
23262367sudorun " chown -R cowrie:cowrie ${COWRIEDIR} "
23272368
@@ -2330,7 +2371,17 @@ sudorun "chown -R cowrie:cowrie ${COWRIEDIR}"
23302371dlog " copying cowrie system files"
23312372
23322373sudo_copy " $progdir " /../lib/systemd/system/cowrie.service /lib/systemd/system/cowrie.service 644
2374+ # file copied/added from previous version of cowrie
2375+ sudo_copy " $progdir " /../srv/cowrie/bin/cowrie /srv/cowrie/bin/cowrie
2376+ sudorun chmod cowrie:cowrie /srv/cowrie/bin/cowrie
23332377sudo_copy " $progdir " /../etc/cron.hourly/cowrie /etc/cron.hourly 755
2378+ if [ " $ID " = opensuse ] ; then
2379+ # add some selinux policy rules to let cowrie.service succeed
2380+ sudo_copy " $progdir " /../etc/cowrie.pp /etc/ 644
2381+ sudo_copy " $progdir " /../etc/cowrie1.pp /etc/ 644
2382+ sudorun semodule -i /etc/cowrie.pp
2383+ sudorun semodule -i /etc/cowrie1.pp
2384+ fi
23342385
23352386# make sure to remove old cowrie start if they exist
23362387if [ -f /etc/init.d/cowrie ]; then
@@ -2347,7 +2398,8 @@ sudorun 'systemctl daemon-reload'
23472398sudorun ' systemctl enable cowrie.service'
23482399
23492400dlog ' deactivate cowrie venv'
2350- sudorun ' deactivate'
2401+ # sudorun 'deactivate'
2402+ run deactivate
23512403
23522404
23532405# ##########################################################
@@ -2372,7 +2424,9 @@ sudo -u webhpot find ./isc_agent -mindepth 1 -type d -exec rm -rf {} +
23722424sudo_copy " ${progdir} " /../srv/web/web-honeypot.service /etc/systemd/system/web-honeypot.service 644
23732425cd " ${WEBHPOTDIR} " || exit
23742426# disable old service in case it is still enabled
2375- sudorun " systemctl disable isc-agent.service"
2427+ if [ " $( sudo systemctl is-enabled isc-agent.service) " = " enabled" ] ; then
2428+ sudorun " systemctl disable isc-agent.service"
2429+ fi
23762430# enable new service
23772431sudorun " systemctl daemon-reload"
23782432sudorun " systemctl enable web-honeypot.service"
@@ -2542,7 +2596,7 @@ run 'mkdir -p /var/tmp/dshield'
25422596
25432597# rotate dshield firewall logs
25442598sudo_copy " $progdir " /../etc/logrotate.d/dshield /etc/logrotate.d 644
2545- [ " $ID " = " opensuse" ] && sed -e ' s/\/usr\/lib.*$/systemctl reload rsyslog/' -i /etc/logrotate.d/dshield
2599+ [ " $ID " = " opensuse" ] && sudo sed -e ' s/\/usr\/lib.*$/systemctl reload rsyslog/' -i /etc/logrotate.d/dshield
25462600if [ -f " /etc/cron.daily/logrotate" ]; then
25472601 sudorun " mv /etc/cron.daily/logrotate /etc/cron.hourly"
25482602fi
25682622# ##########################################################
25692623
25702624if [ -f /root/bin/postinstall.sh ]; then
2571- run " /root/bin/postinstall.sh"
2625+ sudorun " /root/bin/postinstall.sh"
25722626else
25732627 outlog
25742628 outlog
0 commit comments