Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, July 4, 2014

SSD tweaks under Ubuntu 14.04 LTS Server

Change IO Scheduler

"The scheduler helps organise reads and writes in the I/O queue to maximise performance. The default scheduler in the Linux kernel is CFQ (Completely Fair Queuing) which is designed with the rotational latencies of spinning platter drives in mind. So while it works well for standard hard drives it doesn’t work so well when it comes to SSDs." — http://apcmag.com/how-to-maximise-ssd-performance-with-linux.htm

Edit /etc/default/grub and add elevator=deadline to GRUB_CMDLINE_LINUX_DEFAULT:

#GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX_DEFAULT="elevator=deadline"

Update GRUB settings with update-grub2:

root@localhost:~# update-grub2
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.13.0-30-generic
Found initrd image: /boot/initrd.img-3.13.0-30-generic
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done

Verify deadline scheduler is in use:

root@localhost:~# cat /sys/block/sda/queue/scheduler 
noop [deadline] cfq 

/etc/fstab options

Add discard,noatime, and nodiratime options to all partitions on the SSD in the /etc/fstab file.

Descriptions of the options found in the mount man page:

discard/nodiscard
              Controls  whether ext4 should issue discard/TRIM commands to the underlying block device
              when blocks are freed.  This is useful for  SSD  devices  and  sparse/thinly-provisioned
              LUNs, but it is off by default until sufficient testing has been done.

noatime
              Do not update inode access times on this filesystem (e.g., for faster access on the news
              spool to speed up news servers).

nodiratime
              Do not update directory inode access times on this filesystem.

Backup /etc/fstab first:

root@localhost:~# cp -v /etc/fstab{,.bak}
‘/etc/fstab’ -> ‘/etc/fstab.bak’

Edit and add options in /etc/fstab:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/vg0-lv_root /       ext4    errors=remount-ro,discard,noatime,nodiratime    0       1

References

http://www.howtogeek.com/62761/how-to-tweak-your-ssd-in-ubuntu-for-better-performance/
http://apcmag.com/how-to-maximise-ssd-performance-with-linux.htm

Wednesday, July 2, 2014

Configuring OpenVPN and SELinux

up and down user scripts

OpenVPN supports custom user scripts to be run as the service is started or stopped — known as the --up and --down parameters in the man page. On CentOS or other Red Hat-based distributions, these scripts may not work correctly because SELinux is preventing them from executing, which results in the OpenVPN service failing to start.

[root@localhost ~]# service openvpn start
Starting openvpn:                                          [FAILED]

[root@localhost ~]# tail -15 /var/log/openvpn.log
Tue Jul  1 10:48:44 2014 TUN/TAP TX queue length set to 100
Tue Jul  1 10:48:44 2014 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Tue Jul  1 10:48:44 2014 /sbin/ip link set dev tun0 up mtu 1500
Tue Jul  1 10:48:44 2014 /sbin/ip addr add dev tun0 local 172.16.1.1 peer 172.16.1.2
Tue Jul  1 10:48:44 2014 PLUGIN_CALL: POST /usr/lib64/openvpn/plugins/openvpn-plugin-down-root.so/PLUGIN_UP status=0
Tue Jul  1 10:48:44 2014 /etc/openvpn/scripts/up.sh tun0 1500 1542 172.16.1.1 172.16.1.2 init
/etc/openvpn/scripts/up.sh: line 14: /sbin/iptables: Permission denied
/etc/openvpn/scripts/up.sh: line 15: /sbin/iptables: Permission denied
/etc/openvpn/scripts/up.sh: line 16: /sbin/iptables: Permission denied
/etc/openvpn/scripts/up.sh: line 17: /sbin/iptables: Permission denied
/etc/openvpn/scripts/up.sh: line 18: /sbin/iptables: Permission denied
/etc/openvpn/scripts/up.sh: line 19: /sbin/iptables: Permission denied
/etc/openvpn/scripts/up.sh: line 20: /proc/sys/net/ipv4/ip_forward: Permission denied
Tue Jul  1 10:48:44 2014 WARNING: Failed running command (--up/--down): external program exited with error status: 1
Tue Jul  1 10:48:44 2014 Exiting due to fatal error
  • OpenVPN fails to start with the service command.
  • Error messages in /var/log/openvpn.log show failed execution of commands regarding the up.sh script.

Also to further verify SELinux is causing this problem, error messages can be found in /var/log/audit/audit.log:

type=AVC msg=audit(1404247863.966:166): avc:  denied  { getattr } for  pid=2946 comm="up.sh" path="/sbin/iptables-multi-1.4.7" dev=sda1 ino=705 scontext=unconfined_u:system_r:openvpn_t:s0 tcontext=system_u:object_r:iptables_exec_t:s0 tclass=file

type=SYSCALL msg=audit(1404247863.966:166): arch=c000003e syscall=4 success=no exit=-13 a0=26c6890 a1=7fff1691d490 a2=7fff1691d490 a3=50 items=0 ppid=2939 pid=2946 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=2 comm="up.sh" exe="/bin/bash" subj=unconfined_u:system_r:openvpn_t:s0 key=(null)
  • Notice up.sh was trying to run shell commands and /bin/bash.

To allow custom scripts to be executed two things must be done:

  1. The up or down script must have the correct file contexts set.
  2. The correct SELinux boolean must be set to allow for unconfined scripts to be run by OpenVPN.

1. OpenVPN SELinux file contexts

Anytime the restorecon command is run, it reads the /etc/selinux/targeted/contexts/files/file_contexts file to know what file context to set on a regular file or directory. Therefore we can search through this file to find all the default file contexts for OpenVPN using grep -i openvpn /etc/selinux/targeted/contexts/files/file_contexts, see below.

[root@localhost ~]# grep -i openvpn /etc/selinux/targeted/contexts/files/file_contexts
/etc/openvpn(/.*)? system_u:object_r:openvpn_etc_t:s0
/var/log/openvpn.* system_u:object_r:openvpn_var_log_t:s0
/etc/openvpn/ipp.txt -- system_u:object_r:openvpn_etc_rw_t:s0
/var/lib/openvpn(/.*)? system_u:object_r:openvpn_var_lib_t:s0
/var/run/openvpn(/.*)? system_u:object_r:openvpn_var_run_t:s0
/etc/openvpn/scripts(/.*)? system_u:object_r:openvpn_unconfined_script_exec_t:s0
/usr/sbin/openvpn -- system_u:object_r:openvpn_exec_t:s0
/etc/rc\.d/init\.d/openvpn -- system_u:object_r:openvpn_initrc_exec_t:s0
/usr/share/munin/plugins/openvpn -- system_u:object_r:munin_services_plugin_exec_t:s0

Note all the different context types, though, the type we are most interested in is system_u:object_r:openvpn_unconfined_script_exec_t:s0 which applies to all files and directories under /etc/openvpn/scripts/, and the directory itself.

Create the /etc/openvpn/scripts directory, move your custom script to it, and run a recursive restorecon:

[root@localhost ~]# mkdir /etc/openvpn/scripts

[root@localhost ~]# ls -Zd /etc/openvpn/scripts/
drwx------. root root unconfined_u:object_r:openvpn_etc_t:s0 /etc/openvpn/scripts/

[root@localhost ~]# mv -v up.sh /etc/openvpn/scripts/
`up.sh' -> `/etc/openvpn/scripts/up.sh'

[root@localhost ~]# restorecon -Rv /etc/openvpn/scripts/
restorecon reset /etc/openvpn/scripts context unconfined_u:object_r:openvpn_etc_t:s0->unconfined_u:object_r:openvpn_unconfined_script_exec_t:s0
restorecon reset /etc/openvpn/scripts/roadwarrior context unconfined_u:object_r:openvpn_etc_t:s0->unconfined_u:object_r:openvpn_unconfined_script_exec_t:s0
restorecon reset /etc/openvpn/scripts/up.sh context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:openvpn_unconfined_script_exec_t:s0
  • Notice the file context type for the scripts/ directory and the scripts/up.sh switch from openvpn_etc_t to openvpn_unconfined_script_exec_t.

Verify the directory and files have the correct file contexts with ls -Z:

[root@localhost ~]# ls -Zd /etc/openvpn/scripts/
drwx------. root root unconfined_u:object_r:openvpn_unconfined_script_exec_t:s0 /etc/openvpn/scripts/

[root@localhost ~]# ls -Zl /etc/openvpn/scripts/
total 3
-rwxr-xr-x. 1 unconfined_u:object_r:openvpn_unconfined_script_exec_t:s0 root root    0 Jul  1 12:21 up.sh

2. OpenVPN SELinux booleans

Find the relevant SELinux booleans by listening them using getsebool -a:

[root@localhost ~]# getsebool -a | grep -i openvpn
openvpn_enable_homedirs --> on
openvpn_run_unconfined --> off

Change the openvpn_run_unconfined boolean to on with the setsebool command and verify:

[root@localhost ~]# setsebool openvpn_run_unconfined on
[root@localhost ~]# getsebool -a | grep -i openvpn
openvpn_enable_homedirs --> on
openvpn_run_unconfined --> on

Now the OpenVPN service should be able to start without any errors relating to the execution of --up or --down scripts:

[root@localhost ~]# service openvpn start
Starting openvpn:                                          [  OK  ]

[root@localhost ~]# tail -15 /var/log/openvpn.log 
Tue Jul  1 12:33:45 2014 TUN/TAP TX queue length set to 100
Tue Jul  1 12:33:45 2014 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Tue Jul  1 12:33:45 2014 /sbin/ip link set dev tun0 up mtu 1500
Tue Jul  1 12:33:45 2014 /sbin/ip addr add dev tun0 local 172.16.1.1 peer 172.16.1.2
Tue Jul  1 12:33:45 2014 PLUGIN_CALL: POST /usr/lib64/openvpn/plugins/openvpn-plugin-down-root.so/PLUGIN_UP status=0
Tue Jul  1 12:33:45 2014 /etc/openvpn/scripts/up.sh tun0 1500 1542 172.16.1.1 172.16.1.2 init
Tue Jul  1 12:33:46 2014 /sbin/ip route add 172.16.1.0/24 via 172.16.1.2
Tue Jul  1 12:33:46 2014 GID set to nobody
Tue Jul  1 12:33:46 2014 UID set to nobody
Tue Jul  1 12:33:46 2014 UDPv4 link local (bound): [undef]
Tue Jul  1 12:33:46 2014 UDPv4 link remote: [undef]
Tue Jul  1 12:33:46 2014 MULTI: multi_init called, r=256 v=256
Tue Jul  1 12:33:46 2014 IFCONFIG POOL: base=172.16.1.4 size=62, ipv6=0
Tue Jul  1 12:33:46 2014 IFCONFIG POOL LIST
Tue Jul  1 12:33:46 2014 Initialization Sequence Completed

Custom OpenVPN listening port

The default listening port for OpenVPN is UDP port 1194. If you decide to use another port, SELinux settings must be updated using semanage to reflect the newly assigned port.

List SELinux port information and find port contexts matching OpenVPN with semanage port -l | grep -i openvpn:

[root@localhost ~]# semanage port -l | grep -i openvpn
openvpn_port_t                 tcp      1194
openvpn_port_t                 udp      1194

If we decide to use UDP port 2194 instead, use the following semanage command:

[root@localhost ~]# semanage port -a -t openvpn_port_t -p udp 2194

Optionally you can swap udp with tcp if you are using OpenVPN in TCP mode.

Verify SELinux port contexts are updated:

[root@localhost ~]# semanage port -l | grep -i openvpn
openvpn_port_t                 tcp      1194
openvpn_port_t                 udp      2194, 1194

References

http://sysadmin-notepad.blogspot.com/2013/05/custom-openvpn-port-with-selinux-enabled.html
http://www.mankier.com/8/openvpn_unconfined_script_selinux

Thursday, September 15, 2011

Snort 2.9.1 on CentOS 6.0

This tutorial demonstrates a Snort 2.9.1 installation on CentOS 6.0 32-bit using Emerging Threats community rules. These rules will be automatically configured and updated by Oinkmaster.

It is important to note that Snort will be installed from RPMs, and not from source. There are also many tutorials on the web that cover a Snort installation from source in addition to MySQL, Apache2, and Barnyard to support the BASE front-end. This can be a very daunting and discouraging task to first-time Snort users. This tutorial, however, is not another one of those.

I try to reduce the overall complexity of learning Snort by showing a very simple setup to help those first-time Snort users get "their feet wet".

Bridging interfaces

In this setup Snort will be placed inline between a cable modem and home router.

To use Snort inline, two separate interfaces (eth0 and eth1) will need to be bridged as a single interface (br0). Using a bridge interface will allow Snort to transparently inspect all traffic passing in and out of the network.

Configure /etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0
BRIDGE=br0
NM_CONTROLLED=no
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

Configure /etc/sysconfig/network-scripts/ifcfg-eth1:

DEVICE=eth1
BRIDGE=br0
NM_CONTROLLED=no
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

Now create /etc/sysconfig/network-scripts/ifcfg-br0:

DEVICE=br0
TYPE=Bridge
NM_CONTROLLED=no
USERCTL=no
ONBOOT=yes
BOOTPROTO=none
DELAY=0

Restart the networking service:

# service networking restart

Installing Snort

Download the snort-2.9.1-1.F13.i386.rpm RPM from the Vincent Cojot unofficial Snort repository:

# wget http://vscojot.free.fr/dist/snort/snort-2.9.1/RHEL6/i386/snort-2.9.1-14.el6.i686.rpm


Download and install the following dependencies needed by Snort 2.9.1 from the Vincent Cojot repository:
  • libdnet
  • libpcap library version 1.1.1
  • Data Acquisiion Library

# wget http://vscojot.free.fr/dist/snort/snort-2.9.1/RHEL6/i386/libdnet-1.12-7.el6.i686.rpm
# wget http://vscojot.free.fr/dist/snort/snort-2.9.1/RHEL6/i386/libpcap1-1.1.1-10.el6.i686.rpm
# wget http://vscojot.free.fr/dist/snort/snort-2.9.1/RHEL6/i386/daq-0.6.1-10.el6.i686.rpm
# rpm -Uvh libdnet-1.12-7.el6.i686.rpm libpcap1-1.1.1-10.el6.i686.rpm daq-0.6.1-10.el6.i686.rpm

After all dependency packages have been installed, install the Snort RPM:

# rpm -Uvh snort-2.9.1-14.el6.i686.rpm

  • This will automatically create the Snort user and group, startup scripts, and setup the correct directories and paths.

Edit /etc/snort/snort.conf:

  • Configure the HOME_NET variable with your public IP address. If using Snort behind a router, configure HOME_NET with your internal network address, e.g. 192.168.1.0/24.
  • Define the RULE_PATH. The SO_RULE_PATH and PREPROC_RULE_PATH can be safely commented out as they are not used by the Emerging Threat rulesets.
  • Configure the unified2 output, change the filename from merged.log to snort.log and remove the additional options.

# Setup the network addresses you are protecting
#ipvar HOME_NET any
ipvar HOME_NET 1.2.3.4/32

# Path to your rules files (this can be a relative path)
# Note for Windows users: You are advised to make this an absolute path,
# such as: c:\snort\rules
#var RULE_PATH ../rules
#var SO_RULE_PATH ../so_rules
#var PREPROC_RULE_PATH ../preproc_rules
var RULE_PATH /etc/snort/rules

# output unified2: filename merged.log, limit 128, nostamp, mpls_event_types, vlan_event_types
output unified2: filename snort.log, limit 128

Verify that Snort will start with the following command:

# snort -c /etc/snort/snort.conf -i br0

  • -c denotes the configuration file.
  • -i denotes the interface to listen on.

Although no rules have been loaded yet, Snort should display a similar message if everything is configured correctly so far:

        --== Initialization Complete ==--

,,_ -*> Snort! <*-
o" )~ Version 2.9.1 IPv6 GRE (Build 71)
'''' By Martin Roesch & The Snort Team: http://www.snort.org/snort/snort-team
Copyright (C) 1998-2011 Sourcefire, Inc., et al.
Using libpcap version 1.1.1
Using PCRE version: 7.8 2008-09-05
Using ZLIB version: 1.2.3

Rules Engine: SF_SNORT_DETECTION_ENGINE Version 1.15
Preprocessor Object: SF_SIP (IPV6) Version 1.1
Preprocessor Object: SF_FTPTELNET (IPV6) Version 1.2
Preprocessor Object: SF_DCERPC2 (IPV6) Version 1.0
Preprocessor Object: SF_DNS (IPV6) Version 1.1
Preprocessor Object: SF_SDF (IPV6) Version 1.1
Preprocessor Object: SF_SMTP (IPV6) Version 1.1
Preprocessor Object: SF_REPUTATION (IPV6) Version 1.1
Preprocessor Object: SF_IMAP (IPV6) Version 1.0
Preprocessor Object: SF_SSH (IPV6) Version 1.1
Preprocessor Object: SF_POP (IPV6) Version 1.0
Preprocessor Object: SF_SSLPP (IPV6) Version 1.1
Commencing packet processing (pid=10957)

Oinkmaster and Emerging Threats rules

Emerging Threats is a fantastic community-driven project that provides free Snort rules for both personal and commercial use. They update their rulesets on a daily basis and even provide a commercial subscription with support, known as Emerging Threats Pro. See also ruleset comparison.

Oinkmaster is a simple perl script with accompanying .conf file that allows for that automatic configuration and management of Snort rules.

In a real-production network, not all Snort rules will be used, and certain rules may be disabled. When manually downloading and updating the newest rules, rules that have been disabled may be re-enabled again during the manual update process. Oinkmaster simplifies management of rules by allowing an administrator to keep track of which rules are disabled or enabled by default during an update as well as any other additional files to ignore.

Download the Oinkmaster tar archive from http://oinkmaster.sourceforge.net/download.shtml and extract:

# gunzip oinkmaster-2.0.tar.gz
# tar xvf oinkmaster-2.0.tar

The following files will be extracted to the current working directory:

oinkmaster-2.0
oinkmaster-2.0/README.templates
oinkmaster-2.0/oinkmaster.pl
oinkmaster-2.0/FAQ
oinkmaster-2.0/UPGRADING
oinkmaster-2.0/README
oinkmaster-2.0/README.win32
oinkmaster-2.0/README.gui
oinkmaster-2.0/LICENSE
oinkmaster-2.0/INSTALL
oinkmaster-2.0/ChangeLog
oinkmaster-2.0/oinkmaster.1
oinkmaster-2.0/template-examples.conf
oinkmaster-2.0/oinkmaster.conf
oinkmaster-2.0/contrib
oinkmaster-2.0/contrib/create-sidmap.pl
oinkmaster-2.0/contrib/addsid.pl
oinkmaster-2.0/contrib/makesidex.pl
oinkmaster-2.0/contrib/addmsg.pl
oinkmaster-2.0/contrib/README.contrib
oinkmaster-2.0/contrib/oinkgui.pl

Change into the oinkmaster-2.0/ directory and edit the oinkmaster.conf file.

Edit oinkmaster-2.0/oinkmaster.conf:

  • Add the url to the Emerging Threat rules Snort 2.9.0 rules. (2.9.0 rules are compatible with 2.9.1)
  • Set the tmpdir to /tmp.

# Example for Community rules
# url = http://www.snort.org/pub-bin/downloads.cgi/Download/comm_rules/Community-Rules.tar.gz

# Example for rules from the Bleeding Snort project
# url = http://www.bleedingsnort.com/bleeding.rules.tar.gz

# Emerging Threats
url = http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz

# Example for UNIX.
# tmpdir = /home/oinkmaster/tmp/
tmpdir = /tmp

Create a directory to backup old rules when Oinkmaster updates rules:

# mkdir /tmp/rules.old

Run the Oinkmaster perl script for the first time:

# oinkmaster.pl -o /etc/snort/rules/ -b /tmp/rules.old -C oinkmaster.conf

  • -o outputs the downloaded rules to the specified directory
  • -b defines where to backup old rules
  • -C defines which configuration file to use.
  • NOTE: oinkmaster.pl uses the wget utility, install it if it is not present on the system.

Output from above command:

# ./oinkmaster.pl -o /etc/snort/rules/ -b /tmp/rules.old -C oinkmaster.conf
Loading /root/oinkmaster-2.0/oinkmaster.conf
Downloading file from http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz... done.
Archive successfully downloaded, unpacking... done.
Setting up rules structures... done.
Processing downloaded rules... disabled 0, enabled 0, modified 0, total=15999
Setting up rules structures... done.
Comparing new files to the old ones... done.
Updating local rules files... done.

[***] Results from Oinkmaster started 20110915 20:06:35 [***]

[*] Rules modifications: [*]
None.

[*] Non-rule line modifications: [*]
None.

[+] Added files (consider updating your snort.conf to include them if needed): [+]

-> BSD-License.txt
-> classification.config
-> compromised-ips.txt
-> emerging.conf
-> emerging-activex.rules
-> emerging-attack_response.rules
-> emerging-botcc.rules
-> emerging-chat.rules
-> emerging-ciarmy.rules
-> emerging-compromised.rules
-> emerging-current_events.rules
-> emerging-deleted.rules
-> emerging-dns.rules
-> emerging-dos.rules
-> emerging-drop.rules
-> emerging-dshield.rules
-> emerging-exploit.rules
-> emerging-ftp.rules
-> emerging-games.rules
-> emerging-icmp.rules
-> emerging-icmp_info.rules
-> emerging-imap.rules
-> emerging-inappropriate.rules
-> emerging-malware.rules
-> emerging-misc.rules
-> emerging-mobile_malware.rules
-> emerging-netbios.rules
-> emerging-p2p.rules
-> emerging-policy.rules
-> emerging-pop3.rules
-> emerging-rbn-malvertisers.rules
-> emerging-rbn.rules
-> emerging-rpc.rules
-> emerging-scada.rules
-> emerging-scan.rules
-> emerging-shellcode.rules
-> emerging-smtp.rules
-> emerging-snmp.rules
-> emerging-sql.rules
-> emerging-telnet.rules
-> emerging-tftp.rules
-> emerging-tor.rules
-> emerging-trojan.rules
-> emerging-user_agents.rules
-> emerging-virus.rules
-> emerging-voip.rules
-> emerging-web_client.rules
-> emerging-web_server.rules
-> emerging-web_specific_apps.rules
-> emerging-worm.rules
-> gen-msg.map
-> gpl-2.0.txt
-> rbn-ips.txt
-> rbn-malvertisers-ips.txt
-> reference.config
-> sid-msg.map
-> snort-2.9.0-open.txt
-> unicode.map

Edit /etc/snort/snort.conf:

  • Now add the emerging.conf configuration file as an include.

###################################################
# Step #7: Customize your rule set
# For more information, see Snort Manual, Writing Snort Rules
#
# NOTE: All categories are enabled in this conf file
###################################################

# Emerging Threats rules
include $RULE_PATH/emerging.conf

By default /etc/snort/rules/emerging.conf has all rule groups commented out, and they must be enabled manually.

Edit /etc/snort/rules/emerging.conf to enable specific Emerging Threats rules:

  • Ensure classification.config and reference.config are uncommented!
  • Note do not enable all rules, you should enable rules relevant to your environment.
  • As an example I enabled the rules shown below.

include $RULE_PATH/classification.config
include $RULE_PATH/reference.config

include $RULE_PATH/emerging-policy.rules
include $RULE_PATH/emerging-games.rules
include $RULE_PATH/emerging-virus.rules
include $RULE_PATH/emerging-attack_response.rules
include $RULE_PATH/emerging-icmp.rules
include $RULE_PATH/emerging-scan.rules
include $RULE_PATH/emerging-chat.rulesles
include $RULE_PATH/emerging-shellcode.rules
include $RULE_PATH/emerging-current_events.rules
include $RULE_PATH/emerging-malware.rules
include $RULE_PATH/emerging-worm.rules
include $RULE_PATH/emerging-misc.rules
include $RULE_PATH/emerging-exploit.rules
include $RULE_PATH/emerging-p2p.rules
include $RULE_PATH/emerging-mobile_malware.rules

include $RULE_PATH/emerging-botcc.rules
include $RULE_PATH/emerging-compromised.ruless
include $RULE_PATH/emerging-drop.rulesK.rules
include $RULE_PATH/emerging-dshield.rules
include $RULE_PATH/emerging-rbn.rules
include $RULE_PATH/emerging-rbn-malvertisers.rules

Take time to go through each file to determine whether or not to use the rulesets provided by Emerging Threats. Again, not all will be relevant to your environment.

Because we edited /etc/snort/rules/emerging.conf, we need to ensure that it is not accidentally "updated" or overwritten by Oinkmaster. Remember, Oinkmaster outputs to and updates the /etc/snort/rules directory.

Edit oinkmaster-2.0/oinkmaster.conf again:

#######################################################################
# Files to totally skip (i.e. never update or check for changes) #
# #
# Syntax: skipfile filename #
# or: skipfile filename1, filename2, filename3, ... #
#######################################################################

# Do not modify or update emerging.conf
skipfile emerging.conf

NOTE: You can optionally ignore the rulesets that are commented out as well, i.e. skipfile emerging-tor.rules,emerging-sql etc.

Now anytime you need to update your Snort rules, simply run the ./oinkmaster.pl -o /etc/snort/rules/ -b /tmp/rules.old -C oinkmaster.conf command. It is recommended to put this command in a daily cron job, as Emerging Threats updates their rules on a daily basis.

Running Snort

Finally, run Snort in the foreground with the following command:

# snort -c /etc/snort/snort.conf -A fast -b -i br0

  • -A specifies the alert mode.
  • -b will log packets that were alerted on in tcpdump format.
  • -i specifies what interface to listen on.

Alerts will be logged to /var/log/snort/alert, if using the fast alert mode, alerts will appear as a single line.

Example output of /var/log/snort/alert using Snort alert-mode fast:

09/15-20:55:08.642022  [**] [1:2012141:2] ET POLICY Protocol 41 IPv6 encapsulation potential 6in4 IPv6 tunnel active [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {IPV6-ICMP} fe80:0000:0000:0000:0000:5efe:c0a8:0bf1 -> fe80:0000:0000:0000:0000:5efe:181c:c109
09/15-21:01:55.234549 [**] [1:2003089:4] ET GAMES STEAM Connection (v2) [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 1.2.3.4:49158 -> 68.142.72.250:27031
09/15-21:02:22.628590 [**] [1:2012170:2] ET GAMES Blizzard Web Downloader Install Detected [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 1.2.3.4:49196 -> 12.129.206.133:1119

I recommend running Snort for at least a day or two, you are guaranteed to see several alerts especially if your sensor is facing an external public network.

Tuning alerts

After running Snort for a period of time, even for a day or two as previously mentioned, you can quickly get a baseline of the alerts on your network. Some of these alerts can occur quite frequently and may unnecessarily flood your log file. Ideally you want to reduce the amount of "noise" in the alert log file. Tuning your alerts either by disabling the rule signature entirely, or suppressing them using the threshold.conf file is one of the many best practices in maintaining and optimizing Snort.

Disabling an alert

For example, on my development sensor I saw several of the following alerts:

09/16-17:39:08.567824  [**] [1:2012170:2] ET GAMES Blizzard Web Downloader Install Detected [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 1.2.3.4:54741 -> 173.223.52.219:80
09/16-17:39:08.677677 [**] [1:2012170:2] ET GAMES Blizzard Web Downloader Install Detected [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 1.2.3.4:54741 -> 173.223.52.219:80
09/16-17:39:13.197098 [**] [1:2012170:2] ET GAMES Blizzard Web Downloader Install Detected [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 1.2.3.4:54742 -> 12.129.242.21:80

As seen above, Snort detected a Blizzard Web Downloader which was triggered from a desktop running World of Warcraft within my network. If this were a corporate network, company policy would likely dictate that employees should not be playing games during work. However, because this development Snort sensor is on my home network, this alert is completely harmless and therefore can simply be disabled.

The signature or rule ID that triggered the above alert is 2012170. The 2 denotes that this is the second revision of the rule.

Using grep to search for 2012170 within the /etc/snort/rules directory, the file that contains the rule can be found:

# cd /etc/snort/rules
# grep -n 2012170 *

emerging-games.rules:326:alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"ET GAMES Blizzard Web Downloader Install Detected"; flow: established,to_server; content: "User-Agent|3a| Blizzard Web Client"; nocase; classtype:policy-violation; sid:2012170; rev:2;)
sid-msg.map:11036:2012170 || ET GAMES Blizzard Web Downloader Install Detected

The command found the rule in emerging-games.rules on line 326. To disable the rule, simply comment it out with #, like so:

#emerging-games.rules:326:alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"ET GAMES Blizzard Web Downloader Install Detected"; flow: established,to_server; content: "User-Agent|3a| Blizzard Web Client"; nocase; classtype:policy-violation; sid:2012170; rev:2;)

Restart Snort and the rule ID will no longer trigger an alert to the /var/log/snort/alert log file.

IMPORTANT: The oinkmaster.conf still needs to be configured to ensure that the above rule we disabled stays disabled during an update.

Edit your oinkmaster.conf:

  • Use a disablesid statement to disable the rule.

########################################################################
# SIDs to comment out, i.e. disable, after each update by placing a #
# '#' in front of the rule (if it's a multi-line rule, it will be put #
# in front of all lines). #
# #
# Syntax: disablesid SID #
# or: disablesid SID1, SID2, SID3, ... #
########################################################################

disablesid 2012170 # ET GAMES Blizzard Web Downloader Install Detected

The configuration file allows for comments to be appended to the disablesid parameter. For reference, putting the description of the rule, or why the rule is being disabled is strongly recommended.

Now, during an Oinkmaster update the above signature will stay disabled.

Suppressing an alert

There may be scenarios, where you do not want to disable a rule entirely, but rather configure it so that it does not alert on specific factors, such as source or destination IP addresses.

Take for instance the following alerts that were lightly flooding my alert file:

09/16-12:20:43.317651  [**] [1:1390:6] GPL SHELLCODE x86 inc ebx NOOP [**] [Classification: Executable Code was Detected] [Priority: 1] {TCP} 74.125.239.6:80 -> 1.2.3.4:54066
09/16-12:20:43.329227 [**] [1:1390:6] GPL SHELLCODE x86 inc ebx NOOP [**] [Classification: Executable Code was Detected] [Priority: 1] {TCP} 74.125.239.9:80 -> 1.2.3.4:54229
09/16-12:20:43.365007 [**] [1:1390:6] GPL SHELLCODE x86 inc ebx NOOP [**] [Classification: Executable Code was Detected] [Priority: 1] {TCP} 74.125.224.170:80 -> 1.2.3.4:54222

Resolving the above IP addresses shows that they actually belong to Google:

# for i in 74.125.239.6 74.125.239.9 74.125.224.170; do whois -h asn.shadowserver.org origin $i; done
[Querying asn.shadowserver.org]
[asn.shadowserver.org]
15169 | 74.125.239.0/24 | GOOGLE | US | GOOGLE.COM | GOOGLE INC
[Querying asn.shadowserver.org]
[asn.shadowserver.org]
15169 | 74.125.239.0/24 | GOOGLE | US | GOOGLE.COM | GOOGLE INC
[Querying asn.shadowserver.org]
[asn.shadowserver.org]
15169 | 74.125.224.0/24 | GOOGLE | US | GOOGLE.COM | GOOGLE INC

After further investigation it is safe to assume that the alerts were false positives. Optionally the triggering rule can be disabled, as shown in the previous example above, however, doing so would allow any IP address meeting the requirements to alert signature ID 1390 to pass through the network undetected. The correct way to tune the alert is to ignore only if it originates from Google, which can be done using the /etc/snort/threshold.conf file.

Configure /etc/snort/threshold.conf to ignore alerts from signature ID 1390 if it originates from Google's networks:

# Suppression:
#
# Suppression commands are standalone commands that reference generators and
# sids and IP addresses via a CIDR block (or IP list). This allows a rule to be
# completely suppressed, or suppressed when the causitive traffic is going to
# or comming from a specific IP or group of IP addresses.
#
# Suppress this event completely:
#
# suppress gen_id 1, sig_id 1852
#
# Suppress this event from this IP:
#
# suppress gen_id 1, sig_id 1852, track by_src, ip 10.1.1.54
#
# Suppress this event to this CIDR block:
#
# suppress gen_id 1, sig_id 1852, track by_dst, ip 10.1.1.0/24
#

# Suppress [1:1390:6] GPL SHELLCODE x86 inc ebx NOOP [**] if originating from Google's networks.
suppress gen_id 1, sig_id 1390, track by_src, ip 74.125.0.0/16

The Snort developers were kind enough to provide different examples in thethreshold.conf file.

Lastly, restart Snort and the the signature ID will only alert on non-Google networks.

Nothing needs to be changed on the Oinkmaster side, as no rule was explicitly being disabled or enabled. Suppression is handled by threshold.conf which is outside of the /etc/snort/rules directory that Oinkmaster "tracks".

Resources

Snort Official Documention: http://www.snort.org/docs
Emerging Threats Rule Documentation Wiki: http://doc.emergingthreats.net/

Saturday, November 28, 2009

How-to get rid of the netbook remix interface in Ubuntu Netbook Remix 9.10 (Karmic)

This is quick work around to get rid of the netbook remix interface under Karmic Koala by creating a new user with the default GNOME desktop configuration settings.

On your current user remove the ubuntu-netbook-remix-default-settings package, this will remove the main package as well:
sudo aptitude purge ubuntu-netbook-remix-default-settings
Create a new user using the GUI: System > Administration > Users and Groups > Add User

Switch User (DO NOT Log Out) to the new user that was just created. The default Gnome desktop should now be loaded.

Certain startup applications need to be disabled. Go to System > Preferences > Startup Applications, uncheck 'Maximus Windows Management' and 'Netbook Launcher'

Switch User again to your original user and reinstall the ubuntu-netbook-remix-default-settings package to preserve the netbook interface.
sudo aptitude install ubuntu-netbook-remix-default-settings
Now you can use the original user for the netbook remix interface, or switch to the new user that was created to use the original Gnome desktop.