By Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
Book Price: $39.95 USD
£28.50 GBP
PDF Price: $31.99
Cover | Table of Contents | Colophon
http://sourceforge.org/projects/tripwire or
http://www.tripwire.org.# cd /etc/tripwire # ./twinstall.sh # tripwire --init # rm twcfg.txt twpol.txt
Helpful variables:
DIR=/etc/tripwire
SITE_KEY=$DIR/site.key
LOCAL_KEY=$DIR/`hostname`-local.key
Generate the site key:
# twadmin --generate-keys --site-keyfile $SITE_KEY
Generate the local key:
# twadmin --generate-keys --local-keyfile $LOCAL_KEY
Sign the configuration file:
# twadmin --create-cfgfile --cfgfile $DIR/tw.cfg \
--site-keyfile $SITE_KEY $DIR/twcfg.txt
Sign the policy file:
# twadmin --create-polfile --cfgfile $DIR/tw.cfg \
--site-keyfile $SITE_KEY $DIR/twpol.txt
Set appropriate permissions:
# cd $DIR
# chown root:root $SITE_KEY $LOCAL_KEY tw.cfg tw.pol
# chmod 600 $SITE_KEY $LOCAL_KEY tw.cfg tw.pol
# cd /etc/tripwire # twadmin --print-cfgfile > twcfg.txt
# cd /etc/tripwire # twadmin --print-polfile > twpol.txt
# cd /etc/tripwire # twadmin --print-polfile > twpol.txt # twadmin --print-cfgfile > twcfg.txt
# twadmin --create-cfgfile --cfgfile /etc/tripwire/tw.cfg \
--site-keyfile site_key etc/tripwire/twcfg.txt
# twadmin --create-polfile --cfgfile /etc/tripwire/tw.cfg \
--site-keyfile site_key etc/tripwire/twpol.txt
# tripwire --init # rm twcfg.txt twpol.txt
### Error: File could not be opened.
# tripwire --check
(
rulename = "My funky files",
severity = 50
)
{
/sbin/e2fsck -> $(SEC_CRIT) ;
/bin/cp -> $(SEC_CRIT) ;
/usr/tmp -> $(SEC_INVARIANT) ;
/etc/csh.cshrc -> $(SEC_CONFIG) ;
}
# tripwire --check /bin/cp /usr/tmp
# tripwire --check --rule-name "My funky files"
# tripwire --check --severity 40
$ tripwire --check --help
# mount /mnt/cdrom # ls -l /mnt/cdrom total 2564 -r--r----- 1 root root 931 Feb 21 12:20 site.key -r--r----- 1 root root 931 Feb 21 12:20 myhost-local.key -r-xr-xr-x 1 root root 2612200 Feb 21 12:19 tripwire
# DIR=/etc/tripwire # cd $DIR # twadmin --print-cfgfile > twcfg.txt
/etc/tripwire/twcfg.txt:
ROOT=/mnt/cdrom
SITEKEYFILE=/mnt/cdrom/site.key
LOCALKEYFILE=/mnt/cdrom/myhost-local.key
# SITE_KEY=/mnt/cdrom/site.key
# twadmin --create-cfgfile --cfgfile $DIR/tw.cfg \
--site-keyfile $SITE_KEY $DIR/twcfg.txt
# /mnt/cdrom/tripwire --init # umount /mnt/cdrom
# mount /mnt/cdrom # /mnt/cdrom/tripwire --check # umount /mnt/cdrom
#!/bin/sh
REMOTE_MACHINE=trippy
RSYNC='/usr/bin/rsync -a --progress --rsh=/usr/bin/ssh'
SAFE_DIR=/usr/local/tripwire/${REMOTE_MACHINE}
VITAL_FILES="/usr/sbin/tripwire
/etc/tripwire/site.key
/etc/tripwire/${REMOTE_MACHINE}-local.key"
mkdir $SAFE_DIR
for file in $VITAL_FILES
do
$RSYNC ${REMOTE_MACHINE}:$file $SAFE_DIR/
done
#!/bin/sh
cd $SAFE_DIR
rm -f log
for file in $VITAL_FILES
do
base=`basename $file`
$RSYNC -n ${REMOTE_MACHINE}:$file . | fgrep -x "$base" >> log
done
if [ -s log ] ; then
echo 'Security alert!'
else
ssh ${REMOTE_MACHINE} -l root /usr/sbin/tripwire --check
fi
root's crontab file:
0 3 * * * /usr/sbin/tripwire --check
Remote crontab entry on trusty:
0 3 * * * ssh -n -l root trippy /usr/sbin/tripwire --check
cron will send daily email
to root about a failed tripwire invocation.#!/bin/sh DIR=/var/lib/tripwire/report HOST=`hostname -s` LAST_REPORT=`ls -1t $DIR/$HOST-*.twr | head -1` twprint --print-report --twrfile "$LAST_REPORT"
REPORTFILE = /var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr
# twprint --print-dbfile --dbfile /var/lib/tripwire/`hostname -s`.twd
Tripwire(R) 2.3.0 Database
Database generated by: root
Database generated on: Mon Apr 1 22:33:52 2002
Database last updated on: Never
... contents follow ...
#!/bin/sh DIR=/var/lib/tripwire/report HOST=`hostname -s` LAST_REPORT=`ls -1t $DIR/$HOST-*.twr | head -1` tripwire --update --twrfile "$LAST_REPORT"
/bin/ls --> $(SEC_BIN) ;
/etc --> $(SEC_BIN) ;
/etc --> $(SEC_BIN) (recurse=1) ;
/etc --> $(SEC_BIN) (recurse=0);
filename -> rule ;
/bin/login -> +pisug ;
/etc -> rule
!/etc/not.me !/etc/not.me.either
!/etc/dirname
filename -> rule -i ;
/mnt/windows/system -> $(SEC_BIN) -i ;
# rpm -Va [packages]
$ rpm -Va SM5....T c /etc/syslog.conf .M...... /var/lib/games/trojka.scores missing /usr/lib/perl5/5.6.0/Net/Ping.pm ..?..... /usr/X11R6/bin/XFree86 .....U.. /dev/audio S.5....T /bin/ls
trusty# rsync -a -v --rsync-path=/mnt/cdrom/rsync --rsh=/usr/bin/ssh \
trippy:/ /data/trippy-backup
trusty# rsync -a -v -n --rsync-path=/mnt/cdrom/rsync --rsh=/usr/bin/ssh \
trippy:/ /data/trippy-backup
receiving file list ... done wrote 16 bytes read 7478 bytes 4996.00 bytes/sec total size is 3469510 speedup is 462.97
receiving file list ... done /bin/ls /usr/sbin/sshd wrote 24 bytes read 7486 bytes 5006.67 bytes/sec total size is 3469510 speedup is 461.99
#!/bin/sh
for file
do
date=`/usr/bin/stat "$file" | /bin/grep '^Modify:' | /usr/bin/cut -f2- -d' '`
sum=`/usr/bin/md5sum "$file" | /usr/bin/awk '{print $1}'`
inode=`/bin/ls -id "$file" | /usr/bin/awk '{print $1}'`
/bin/echo -e "$file\t$inode\t$sum\t$date"
done
# find /dir -xdev -type f -print0 | \ xargs -0 -r /usr/local/bin/idfile > /tmp/my_snapshot
/bin/arch 2222 7ba4330c353be9dd527e7eb46d27f923 Wed Aug 30 17:54:25 2000 /bin/ash 2194 cef0493419ea32a7e26eceff8e5dfa90 Wed Aug 30 17:40:11 2000 /bin/awk 2171 b5915e362f1a33b7ede6d7965a4611e4 Sat Feb 23 23:37:18 2002 ...
ipchains
and
iptables. ipchains models a
stateless
packet filter. Each packet reaching the firewall is evaluated against
a set of rules. Stateless means that the
decision to accept, reject, or forward a packet is not influenced by
previous packets.#!/bin/sh echo -n "Enabling source address verification..." echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter echo "done"
#!/bin/sh
CONF_DIR=/proc/sys/net/ipv4/conf
CONF_FILE=rp_filter
if [ -e ${CONF_DIR}/all/${CONF_FILE} ]; then
echo -n "Setting up IP spoofing protection..."
for f in ${CONF_DIR}/*/${CONF_FILE}; do
echo 1 > $f
done
echo "done"
fi
net.ipv4.conf.all.rp_filter = 1
# sysctl -p
http://www.linux.org/docs/ldp/howto/IPCHAINS-HOWTO-5.html#ss5.7.
iptables:# iptables -A INPUT -i external_interface -s your_IP_address -j REJECT
ipchains:# ipchains -A input -i external_interface -s your_IP_address -j REJECT
iptables:# iptables -A INPUT -i external_interface -s 192.168.0.0/24 -j REJECT
iptables:# iptables -F # iptables -A INPUT -j REJECT # iptables -A OUTPUT -j REJECT # iptables -A FORWARD -j REJECT
ipchains:# ipchains -F # ipchains -A input -j REJECT # ipchains -A output -j REJECT # ipchains -A forward -j REJECT
iptables
:# iptables -F INPUT # iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT # iptables -A INPUT -j REJECT
ipchains
:# ipchains -F input # ipchains -A input -i lo -j ACCEPT # ipchains -A input -p tcp --syn -j REJECT # ipchains -A input -p udp --dport 0:1023 -j REJECT
# ipchains -F input # ipchains -A input -j REJECT
# iptables -A INPUT -p tcp --syn -j REJECT
iptables
:# iptables -F OUTPUT # iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT # iptables -A OUTPUT -j REJECT
# ipchains -F output # ipchains -A output -p tcp ! --syn -j ACCEPT # ipchains -A output -j REJECT
iptables
:# iptables -A INPUT -p tcp --dport www -j REJECT
ipchains
:# ipchains -A input -p tcp --dport www -j REJECT
iptables
:# iptables -A INPUT -p tcp -i lo --dport www -j ACCEPT # iptables -A INPUT -p tcp --dport www -j REJECT
ipchains
:# ipchains -A input -p tcp -i lo --dport www -j ACCEPT # ipchains -A input -p tcp --dport www -j REJECT