1. Pre-tasks.
Uncomment the line beginning with: deb cdrom
This will configure the dpkg package system to NOT look for packages on the cdrom.
Then we want to update our sources and upgrade our binaries to the latest:
# apt-get update # apt-get upgrade
# apt-get install ssh
# apt-get -s install mysql-client libnet1 libnet1-dev libpcre3 libpcre3-dev libmysqlclient15-dev \ autoconf automake1.9 libpcap libpcap-dev libpcap0.8 libpcap0.8-dev libpcre-dev libmysqlclient15-dev gcc \ make libtool libssl-dev gcc-4.1 g++ libpcap-dev build-essential
# apt-get install mysql-client libnet1 libnet1-dev libpcre3 libpcre3-dev libmysqlclient15-dev \ autoconf automake1.9 libpcap libpcap-dev libpcap0.8 libpcap0.8-dev libpcre-dev libmysqlclient15-dev gcc \ make libtool libssl-dev gcc-4.1 g++ libpcap-dev build-essential
2. Compile & install Snort, then add the snort user & group.
This step involves installing snort, adding the snort user & group, then installing the detection rules.
We're installing the latest snort as found on the snort site.
# cd /usr/local/src
# wget http://snort.org/dl/snort-2.8.3.2.tar.gz
# tar xvzf snort-2.8.3.2.tar.gz
# cd snort-2.8.3.2 (take the time to read the doc/INSTALL file)
# ./configure --with-mysql --enable-dynamicplugin
# make
# make install
# ln -s /usr/local/src/snort-2.8.3.2 ./snort
# mkdir /etc/snort # mkdir /var/log/snort # groupadd snort # useradd -g snort -d /etc/snort snort # chown snort:snort /var/log/snort ; chown snort:snort /etc/snort
# ldd /usr/local/bin/snort
root@client: bin# ldd snort linux-gate.so.1 => (0xb7f50000) libmysqlclient.so.15 => not found libpthread.so.0 => /lib/libpthread.so.0 (0xb7f32000) libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7f04000) libz.so.1 => /usr/lib/libz.so.1 (0xb7eef000) libpcre.so.3 => /usr/lib/libpcre.so.3 (0xb7ec8000) libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0xb7e9d000) libm.so.6 => /lib/libm.so.6 (0xb7e78000) libnsl.so.1 => /lib/libnsl.so.1 (0xb7e61000) libdl.so.2 => /lib/libdl.so.2 (0xb7e5d000) libc.so.6 => /lib/libc.so.6 (0xb7d29000) /lib/ld-linux.so.2 (0xb7f51000)
3. Get initial set of rules.
Note: central repository for rules is on server.
# cd /etc/snort # scp -r root@server:/etc/snort/rules ./rules
4. Configure and start the Snort program.
# cp /usr/local/src/snort/etc/*.conf* . # cp /usr/local/src/snort/etc/*.map .
First, we need to edit the main configuration file:
# pico -w /etc/snort/snort.conf
var RULE_PATH /etc/snort/rules var HOME_NET 192.168.1.0/24 var EXTERNAL_NET !$HOME_NET
portvar SSH_PORTS 22
config disable_decode_alerts config disable_tcpopt_experimental_alerts config disable_tcpopt_obsolete_alerts config disable_tcpopt_ttcp_alerts config disable_tcpopt_alerts config disable_ipopt_alerts
Let's see if snort works by editing local rules:
# pico -w /etc/snort/rules/local.rules
alert icmp any any -> $HOME_NET any (msg:"ICMP test"; \
dsize:8; itype:8; sid:10000001;)
alert tcp any any -> any any (msg:"test"; sid:1000002;)
# /usr/local/bin/snort -Dq -u snort -g snort -c /etc/snort/snort.conf
snort[12991]: Snort initialization completed successfully (pid=12991)
# ifconfig eth1 up
5. Set up remote logging.
Check if snort user via the remote client can connect to the snort database on central snort server.
# mysql -h server -u snort -p -D snort
Uncomment and edit this line:
output database: log, mysql, user=snort password=password dbname=snort host=localhost sensor_name=ww.xx.yy.zz
output database: log, mysql, user=snort password=supersecretpassword dbname=snort host=server sensor_name=client
10. Keep rules up to date with Oinkmaster.
# cd /usr/local/src # wget http://internap.dl.sourceforge.net/sourceforge/oinkmaster/oinkmaster-2.0.tar.gz # tar xvzf oinkmaster-2.0.tar.gz # ln -s /usr/local/src/oinkmaster-2.0 ./oinkmaster # cd oinkmaster-2.0 # cp oinkmaster.pl /usr/local/bin # mkdir /usr/local/etc # cp oinkmaster.conf /usr/local/etc # ln -s /usr/local/etc/oinkmaster.conf /etc/oinkmaster.conf # mkdir /etc/snort/rules.hold ; mkdir /etc/snort/backup # mkdir /var/run/oinkmaster ; chmod 775 /var/run/oinkmaster
# pico -w /usr/local/etc/oinkmaster.conf
url = dir:///etc/snort/rules.hold
tmpdir = /tmp
# groupadd oinkmaster # useradd -d /opt/oinkmaster -g oinkmaster -G snort -s /bin/bash oinkmaster # mkdir /opt/oinkmaster ; chown oinkmaster:oinkmaster /opt/oinkmaster # chown oinkmaster:snort /etc/snort/rules.hold # su - oinkmaster ~ ssh-keygen -t rsa -b 2048
note: Double-check if oinkmaster is permitted to ssh into the system:
# less /etc/ssh/sshd_config AllowUsers root oinkmaster
As oinkmaster user on client:
~ ssh -l root server "sudo bash -c \"cat /opt/oinkmaster/.ssh/id_rsa.pub\"" > \
/opt/oinkmaster/.ssh/authorized_keys2
oinkmaster@server:~$ ssh oinkmaster@client
The authenticity of host 'client' can't be established.
RSA key fingerprint is bb:e4:31:de:9a:04:0a:1d:56:2b:62:c5:dd:4d:72:18.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'client' (RSA) to the list of known hosts.
oinkmaster@client:~$
# su - oinkmaster ~ pico -w /opt/oinkmaster/scripts/pushsnortrules-test.sh
rsync -c --delete -r -H -p -z -o -g -t -e 'ssh -i /opt/oinkmaster/.ssh/id_rsa' \ /etc/snort/rules client:/etc/snort/rules.hold
Run pushsnortrules-test.sh on the repository as oinkmaster:
~ ./opt/oinkmaster/scripts/pushsnortrules-test.sh
# mkdir /tmp/oinktest # /usr/local/bin/oinkmaster.pl -o /tmp/oinktest
# ls -lah /tmp/oinktest/
Note: The -o switch tells oinkmaster to override the output directory in the configuration file; the -b switch will make oinkmaster back up the current rules in the location before doing the actual update; play with this is so desired; the /etc/snort/backup directory is created for this purpose.
11. Set up configuration files and init scripts.
On repository, there are init scripts and configuration files. scp them over to client sensor and place thusly:
/etc/snort/snort.scripts/oinkoink.sh -> /root/scripts/oinkoink.sh /etc/snort/snort.scripts/snort.debian.conf -> /etc/snort/snort.debian.conf /etc/snort/snort.scripts/snort.default -> /etc/default/snort /etc/snort/snort.scripts/snort.initd -> /etc/init.d/snort
The above should be configured to match specific sensor environment. The /etc/default/snort file works will with the init.d script and will override settings in /etc/snort/snort.conf ; snort.debian.conf is good for determining specifying the interface and settings debian specific. Please be reminded to check the path for the snort binary in the init.d script.
After chmod +x /etc/init.d/snort
Make init script an init script, do:
# update-rc.d snort defaults 95
12. Set up cron jobs for oinkmaster running & auto email.
Set up favorite email daemon to send mail, then, in /etc/crontab add the following (if mail isn't set up, set it up):
# snort 49 5 * * * root /root/scripts/oinkoink.sh 50 5 * * * root /usr/local/bin/oinkmaster.pl -C /etc/oinkmaster.conf -o \ /etc/snort/rules | mail -s "oinkmaster client" youyesyou@somewherenothere.com 10 6 * * * root /etc/init.d/snort restart >> /dev/null 2>&1
echo testing | mail -s testorama youyesyou@somewherenothere.com
13. Start snort daemon
You're ready to start IDSing. Or something. On the client, execute:
# /etc/init.d/snort start
To watch snort start, stare at the appropriate syslog:
# tail -n 30 -f /var/log/syslog
No comments:
Post a Comment