[DE] Raspi als Honeypot preparieren

 Wenn ihr auch eine  Raspi im lokalen Netzwerk angeschlossen habt und außerdem nicht sicher seit was die anderen Geräte wie TV oder Xbox in eurem Netzwerk so machen, könnt ihr dem Raspi noch eine Zusatzfunktion verleihen. Installiert einen Honeypot auf dem Gerät.


Ein Honeypot ist im Grunde ein Dienst, den keiner braucht und deshalb nicht nutzt. Fängt ein Angreifer an das Netzwerk auszuspähen, trifft er zwangsläufig auf die vom Honeypot bereitgestellten Dienste und versucht diese zu inspizieren.

Nun gibt sich der Honeypot wie ein echter Dienst aus und protokoliert die Aktivitäten. Eine Benachrichtigung, z.B. via Email informiert den Administrator über ein potentielles Problem.

Wie also den Raspi zu einem Honeypot machen. Die Software tiny-honeypot bietet, was wir benötigen. Dazu muss vorerst git und xinetd installiert werden.

apt update
apt install git xinetd

nun kann das Projekt abgeholt werden und in das System integriert werden

git clone https://github.com/tiny-honeypot/thp.git
cd thp/
chmod a+x logthis
cp xinetd.d/* /etc/xinetd.d/
cd ..
mv thp /usr/local/
mkdir /var/log/hpot
chown nobody -R /var/log/hpot

Editiert die Dateien thp-* unter /etc/xinetd.d/ und setzt jeweils disabled = no und setzt die Ports für http auf 80 und für ftp auf 21. Es können auch weitere Dateien angelegt werden, z.B. für die Ports 8080 und 443.

In der Konfigurationsdatei des xinetd muss noch das Logging umgestellt werden /etc/xinetd.conf:

defaults
{
 log_type        = FILE /var/log/xinetdlog
 log_on_success  = HOST
 log_on_failure  = HOST
 cps             = 25 30
}

Starten von xinetd:

service xinetd start
update-rc.d xinetd defaults

Nun ist der Honeypot schon fertig. Aber wir werden noch nicht informiert, wenn ein Aufruf registriert wurde. Dazu senden wir eine Email wie hier beschrieben.

apt-get install sendemail libio-socket-ssl-perl libnet-ssleay-perl
vi /usr/local/bin/mailnotify.sh

Inhalt:

# Sender of the mail
SENDER="absender@domain.de"

# Recipient of the mail
RECIPIENT="empfaenger@domain.de"

# SMTP server
SMTPSERVER="smtp.domain.de"

# User name on the SMTP server
SMTPUSERNAME="MeinMailAccount"

# Password on the SMTP server
SMTPPASSWORD="MeinMailPasswort"

# Enable TLS for the SMTP connection
USETLS=1

###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################

# Use first argument as mail subject
if [ -n "$1" ]; then
  SUBJECT="$1"
else
  # No subject specified
  SUBJECT=""
fi

# Use second argument as mail body
if [ -n "$2" ]; then
  BODY="$2"
else
  # No mail body specified
  BODY=""
fi

# Generate the options list for sendEmail
OPTIONS=""

if [ -n "${SMTPSERVER}" ]; then
  OPTIONS="${OPTIONS} -s ${SMTPSERVER}"
fi

if [ -n "${SMTPUSERNAME}" ]; then
  OPTIONS="${OPTIONS} -xu ${SMTPUSERNAME}"
fi

if [ -n "${SMTPPASSWORD}" ]; then
  OPTIONS="${OPTIONS} -xp ${SMTPPASSWORD}"
fi

if [ -n "${USETLS}" ]; then
  if [ ${USETLS} == 1 ]; then
    OPTIONS="${OPTIONS} -o tls=yes"
  else
    OPTIONS="${OPTIONS} -o tls=no"
  fi
fi

# Send the mail with sendEmail
sendEmail -f ${SENDER} -t ${RECIPIENT} -u "${SUBJECT}" -m "${BODY}" ${OPTIONS}

exit 0

Execute nicht vergessen:

chmod +x /usr/local/bin/mailnotify.sh

Und nun noch ein kleines Script, das die Logs verschickt und löscht:

vi honeymail.sh

Inhalt:

#!/bin/bash

. /etc/profile

if test -e /var/log/hpot/captures
then
  tail -vn +1 /var/log/xinetdlog /var/log/hpot/* | mailnotify.sh "Honeypot $HOSTNAME"
  rm /var/log/hpot/*
  rm /var/log/xinetdlog 
  service xinetd restart
fi

Und dieses Script per Cron-Job jede Stunde anstarten

crontab -e

0 * * * * /root/honeymail.sh >/dev/null 2>&1





Comments

Popular posts from this blog

Sonatype Nexus fails with random "peer not authenticated" errors behind ingress

Creating a flux sync configuration referring a config map for substitution

[mhus lib] Reorg in generation 7 nearly finished