freedomboneeee/src/freedombone-base-tripwire

190 lines
7.6 KiB
Plaintext
Raw Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Intrusion detection application
#
# License
# =======
#
2016-10-31 17:24:49 +01:00
# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
2016-07-03 17:13:34 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-07-06 21:39:47 +02:00
function backup_local_tripwire {
echo -n ''
}
function backup_remote_tripwire {
echo -n ''
2016-07-04 22:02:22 +02:00
}
2016-07-05 21:07:43 +02:00
function remove_tripwire {
2016-10-08 20:32:04 +02:00
if ! grep -Fxq "tripwire" $COMPLETION_FILE; then
return
fi
2016-10-23 20:38:14 +02:00
apt-get -yq remove --purge tripwire
2016-10-08 20:32:04 +02:00
if [ -d /etc/tripwire ]; then
rm -rf /etc/tripwire
fi
rm /usr/bin/reset-tripwire
sed -i '/tripwire/d' $COMPLETION_FILE
2016-07-03 22:49:38 +02:00
}
2016-07-05 21:07:43 +02:00
function install_tripwire {
2016-10-16 20:50:56 +02:00
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
2016-10-08 20:32:04 +02:00
return
fi
2017-07-14 23:42:31 +02:00
echo '*** Installing intrusion detection ***'
debconf-set-selections <<< "tripwire tripwire/use-sitekey boolean false"
debconf-set-selections <<< "tripwire tripwire/use-localkey boolean false"
2017-08-05 14:15:35 +02:00
apt-get -yq install tripwire qrencode
2016-10-23 20:38:14 +02:00
apt-get -yq autoremove
2016-10-08 20:32:04 +02:00
cd /etc/tripwire
2017-07-14 23:42:31 +02:00
echo 'ROOT =/usr/sbin' > /etc/tripwire/twcfg.txt
echo 'POLFILE =/etc/tripwire/tw.pol' >> /etc/tripwire/twcfg.txt
echo 'DBFILE =/var/lib/tripwire/$(HOSTNAME).twd' >> /etc/tripwire/twcfg.txt
echo 'REPORTFILE =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr' >> /etc/tripwire/twcfg.txt
echo 'SITEKEYFILE =/etc/tripwire/$(HOSTNAME)-site.key' >> /etc/tripwire/twcfg.txt
echo 'LOCALKEYFILE =/etc/tripwire/$(HOSTNAME)-local.key' >> /etc/tripwire/twcfg.txt
echo 'EDITOR =/usr/bin/editor' >> /etc/tripwire/twcfg.txt
echo 'LATEPROMPTING =false' >> /etc/tripwire/twcfg.txt
echo 'LOOSEDIRECTORYCHECKING =false' >> /etc/tripwire/twcfg.txt
echo 'MAILNOVIOLATIONS =false' >> /etc/tripwire/twcfg.txt
echo 'EMAILREPORTLEVEL =3' >> /etc/tripwire/twcfg.txt
echo 'REPORTLEVEL =3' >> /etc/tripwire/twcfg.txt
echo 'SYSLOGREPORTING =false' >> /etc/tripwire/twcfg.txt
2017-08-04 19:12:01 +02:00
echo 'MAILMETHOD =SENDMAIL' >> /etc/tripwire/twcfg.txt
echo 'MAILPROGRAM =/usr/lib/sendmail -oi -t' >> /etc/tripwire/twcfg.txt
2017-07-14 23:42:31 +02:00
echo 'SMTPHOST =localhost' >> /etc/tripwire/twcfg.txt
echo 'SMTPPORT =25' >> /etc/tripwire/twcfg.txt
echo 'TEMPDIRECTORY =/tmp' >> /etc/tripwire/twcfg.txt
2017-08-04 19:12:01 +02:00
echo 'MAILFROMADDRESS =tripwire@$(HOSTNAME)' >> /etc/tripwire/twcfg.txt
2017-07-14 23:42:31 +02:00
echo '
' | twadmin --generate-keys -L /etc/tripwire/${HOSTNAME}-local.key -S /etc/tripwire/${HOSTNAME}-site.key
2016-10-08 20:32:04 +02:00
echo '
2016-07-03 17:13:34 +02:00
2017-07-14 23:42:31 +02:00
' | twadmin --create-cfgfile -S /etc/tripwire/${HOSTNAME}-site.key /etc/tripwire/twcfg.txt
2016-07-03 17:13:34 +02:00
2016-10-08 20:32:04 +02:00
# make a script for easy resetting of the tripwire
echo '#!/bin/sh' > /usr/bin/reset-tripwire
2017-08-03 22:32:18 +02:00
echo 'tripwire -m i' >> /usr/bin/reset-tripwire
2016-10-08 20:32:04 +02:00
chmod +x /usr/bin/reset-tripwire
2016-07-03 17:13:34 +02:00
2016-10-08 20:32:04 +02:00
sed -i '/# These files change the behavior of the root account/,/}/ s/.*//g' /etc/tripwire/twpol.txt
sed -i 's|/etc/rc.boot.*||g' /etc/tripwire/twpol.txt
# Don't show any changes to /proc
sed -i 's|/proc.*||g' /etc/tripwire/twpol.txt
# Don't report log changes
sed -i 's|/var/log.*||g' /etc/tripwire/twpol.txt
# Ignore /etc/tripwire
if ! grep -q '!/etc/tripwire' /etc/tripwire/twpol.txt; then
sed -i '\|/etc\t\t->.*|a\ !/etc/tripwire ;' /etc/tripwire/twpol.txt
fi
# Ignore /etc/freedombone
2017-08-05 15:27:41 +02:00
if ! grep -q '!/etc/freedombone' /etc/tripwire/twpol.txt; then
sed -i '\|/etc\t\t->.*|a\ !/etc/freedombone ;' /etc/tripwire/twpol.txt
fi
# Ignore /etc/pihole
2017-01-15 15:50:42 +01:00
if ! grep -q '!/etc/pihole' /etc/tripwire/twpol.txt; then
sed -i '\|/etc\t\t->.*|a\ !/etc/pihole ;' /etc/tripwire/twpol.txt
fi
2016-10-08 20:32:04 +02:00
# ignore tt-rss cache
if ! grep -q '!/etc/share/tt-rss/cache' /etc/tripwire/twpol.txt; then
sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/cache ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/etc/share/tt-rss/lock' /etc/tripwire/twpol.txt; then
sed -i '\|/etc\t\t->.*|a\ !/etc/share/tt-rss/lock ;' /etc/tripwire/twpol.txt
fi
# Ignore additional install files
if ! grep -q '!/usr/local/bin/freedombone' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/freedombone* ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!=/usr/local/bin' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !=/usr/local/bin ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/addremove' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/addremove ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/backup' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/backup ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/backup2friends' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/backup2friends ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/batman' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/batman ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/control' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/control ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/controluser' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/controluser ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/cronic' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/cronic ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/meshavahi' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/meshavahi ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/restore' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/restore ;' /etc/tripwire/twpol.txt
fi
if ! grep -q '!/usr/local/bin/restorefromfriend' /etc/tripwire/twpol.txt; then
2017-08-05 15:21:35 +02:00
sed -i '\|/usr/local/sbin.*|a\ !/usr/local/bin/restorefromfriend ;' /etc/tripwire/twpol.txt
fi
2016-10-08 20:32:04 +02:00
# Avoid logging the changed database
sed -i 's|$(TWETC)/tw.pol.*||g' /etc/tripwire/twpol.txt
2017-07-15 12:37:41 +02:00
# site key name
sed -i 's|$(TWETC)/site.key|$(TWETC)/$(HOSTNAME)-site.key|g' /etc/tripwire/twpol.txt
2017-08-04 19:12:01 +02:00
2017-07-14 23:42:31 +02:00
# create the policy
echo '
' | twadmin --create-polfile -S /etc/tripwire/${HOSTNAME}-site.key /etc/tripwire/twpol.txt
# create the database
2016-10-08 20:32:04 +02:00
echo '
2016-07-03 17:13:34 +02:00
2017-07-14 23:42:31 +02:00
' | tripwire --init --cfgfile /etc/tripwire/tw.cfg --polfile /etc/tripwire/tw.pol --dbfile /var/lib/tripwire/${HOSTNAME}.twd
2017-07-15 00:42:04 +02:00
if [ ! -f /var/lib/tripwire/${HOSTNAME}.twd ]; then
2017-07-14 23:42:31 +02:00
echo $'tripwire database was not created'
exit 72925
fi
# recreate the configuration
2016-10-08 20:32:04 +02:00
echo '
2016-07-03 17:13:34 +02:00
2016-10-08 20:32:04 +02:00
' | reset-tripwire
2016-07-03 17:13:34 +02:00
2016-10-16 20:50:56 +02:00
mark_completed $FUNCNAME
2016-07-03 17:13:34 +02:00
}
# NOTE: deliberately no exit 0