![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Ubuntu 9.10 is out!!!
When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu. The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely. |
|
Security Discussions Discuss security flaws/updates/notices in the various Ubuntu releases. |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Ubuntu Guru
![]() |
Intrusion Detection
Ubuntu Intrusion Detection ![]() Quote : “Paranoia will get you through times of no enemies better than enemies will get you through times of no paranoia” ~ Pete Granger Contents
This how to was written as an extension to Ubuntu Security and is intended as an introduction to intrusion detection, Ubuntu Style. This post is quite long, and for what I hope is greater readability, I have broken it into separate posts. Here is a very nice link that reviews IDS : Security Focus ~ An Introduction to Intrusion Detection Systems And for the impatient, the readers digest version : There are two "arms" of intrusion detection: HIDS and NIDS. HIDS = Host-based Intrusion Detection System. NIDS = Network-based Intrusion Detection System. In a nut-shell, HIDS monitors you system files for unauthorized changes. Examples of this type of monitoring methodology might include techniques such as scanning for viruses, tripwire, Tiger, rkhunter, and chkrootkit. Similarly, NIDS monitors your network traffic for DOS attacks, port scans, or other suspicious network activity. Examples include watching your firewall in Windows for alerts, snort, or Wireshark. Although there are other options, both for applications and configuration, in this tutorial I will show you how to install ossec-hids and snort: NIDS = snort HIDS = ossec Snort : Snort will monitor your network traffic by checking packets against "rules". We will configure snort to log "alerts" to a mysql database. We will then use base to display this information in a web browser (Firefox). Although seemingly foreign at first, base is a very nice web based gui front end for snort. Base is basically point and click and contains numerous links to help interpret alerts. Quote:
OSSEC-HIDS : OSSEC-HIDS will monitor your log files, monitor the integrity of system files, check for root kits, and perform active response. Active response means ossec will blacklist (block connections) from potential crackers "automagically". Quote:
Note : There are of course other options for HIDS, NIDS, as well as alternate configuration options for both snort and ossec. You should be familiar with : 1. Installing from source (don't worry I will walk you through it). 2. Your ip address, both on your private LAN and public IP address. 3. Your netmask
4. If you wish to access base and the OSSEC web interface outside your LAN you will need to know how to configure your router (you do have a router don't you?). In addition be sure to understand the security implications of running LAMP. In addition you may wish to use ,htaccess or ssl. Reference: community/ApacheMySQLPHP 5. Installing and configuring snort will take some time, give yourself a few hours. We will be running all commands in this tutorial as root So either add "sudo" in front of these commands or open a terminal and obtain a root shell: Code:
sudo -i
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; September 28th, 2008 at 07:35 PM.. |
||
|
|
|
|
|
#2 |
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
How to install snort + mysql + base
As has been pointed out by Sarmacid you can install snort from the Ubuntu repositories. In the repos snort is on version 2.7 where from source we are on snort 2.8. To use the repos use "sudo apt-get install snort-mysql".You will need to download a set of rules for snort. The downloads page is here : http://www.snort.org/pub-bin/downloads.cgi 1. prep ~ Install the various tools and dependencies for Snort and OSSEC. You wee need the Universe repository enabled. If you need assistance enabling your repositories, see : /community/Repositories/Ubuntu Code:
apt-get -y install build-essential libpcap0.8-dev libmysqlclient15-dev mysql-client-5.0 mysql-server-5.0 bison flex apache2 libapache2-mod-php5 php5-gd php5-mysql libphp-adodb php-pear libc6-dev g++ gcc pcregrep libpcre3-dev For reference : /community/Repositories/ApacheMySQLPHP During the installation of these applications, make note of (write down) your mysql root password. 2. Obtain snort source code ~ be sure to check the snort home page for updated versions of snort. Although snort is in the repositories you will need to compile snort yourself. This is because the binary in Ubuntu does not have support for snort logging to a mysql database enabled. This procedure has been tested (and is working) on both 32 bit 64 bit arch. Code:
cd /usr/src wget http://www.snort.org/dl/current/snort-2.8.3.tar.gz tar zxvf snort-2.8.3.tar.gz In order to get a set of rules you have a set of options listed on the snort rules page The "Community Rules", at the bottom of the page, are available without any further registration. For a more "up to date" set of rules you must either register or subscribe. (continuing in the /usr/src directory) Code:
wget http://www.snort.org/the_rules_you_wish_to_use cd snort-2.8.3 tar zxvf ../snortrules* Bleeding Edge Threats The snort rule sets are here : http://doc.bleedingthreats.net/bin/v...in/AllRulesets I downloaded the bleeding-all.rules You may also be interested in : http://www.emergingthreats.net You can keep your rules up to date with oinkmaster. Oinkmaster is in the reops. If you use oinkmaster, be sure to READ THE DOCUMENTATION. Code:
cd /usr/src/snort-2.8.3/rules wget http://www.bleedingthreats.net/rules/bleeding-all.rules Code:
cd /usr/src/snort-2.8.3 ./configure -enable-dynamicplugin --with-mysql make make install If, however, you do get errors when compiling snort, see This thread 5. You can remove snort with : Code:
make uninstall
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; March 9th, 2009 at 02:22 AM.. |
|
|
|
|
|
#3 | |
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
Configure snort
Configure mysql Next we need to configure a mysql database for snort to use for alerts. Code:
mysql -u root -p You will get a mysql prompt "mysql>". I will use this prompt to indicate commands entered in mysql (as opposed to the command line) you do not need to enter the "mysql >". Quote:
Now, back at the command line, import the snort database scheme Code:
mysql -D snort -u snort -p < /usr/src/snort-2.8.3/schemas/create_mysql We need to configure snort and write a start script, and add a cron job. If things are too quiet, and snort goes a few hours without logging an alert to mysql, snort loses the connection with mysql. You then need to restart snort to re-establish a connection with the mysql database. First lets create a user for snort. Again change the user name if you wish. Code:
adduser snort Code:
chsh snort Last, lock the account. Code:
passwd snort -l Code:
cd /usr/src/snort-2.8.3 mkdir -p /etc/snort/rules /var/log/snort chown -R root.snort /var/log/snort chmod -R 770 /var/log/snort cp etc/* /etc/snort/ cp rules/* /etc/snort/rules Using any editor, open /etc/snort/snort.conf and make the following changes :
Write a script to start snort : The only "problem" with installing snort from source is that we now need a script to start snort. The other issue is that if there are no alerts, snort will lose it's connection with the mysql database. To solve this, I wrote a script to start / restart snort. The script is attached to this post and is called "ubuntu.snort.init.txt" Copy this file to your computer and copy/move it to /etc/init.d/snort Now lets look at the code. You need to look at two lines.
Now that you are done editing the file, set ownership and permissions : Code:
chown root.root /etc/init.d/snort chmod 500 /etc/init.d/snort My script has a 20 second sleep built in (sometimes when you start snort it will fail after a 10-15 second delay). To avoid adding a 20 second longer boot time, use the "boot" option. With this factoid in mind, edit /etc/rc.local and add : Code:
exec /etc/init.d/snort boot Restarting snort with a cron job Did I mention, Snort may lose the connection to the mysql data base if no alerts are received for several hours (which can happen once we eliminate false positives and install OSSEC-HIDS)? In addition if you clear your data in base you may need to re-start snort. To restart snort with my script : Code:
/etc/init.d/snort restart To restart snort every 6 hours, use crontab (as root) Code:
crontab -e Code:
0 0,6,12,18 * * * /etc/init.d/snort restart >/dev/null 2>&1 Back to top
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; January 4th, 2009 at 12:27 AM.. |
|
|
|
|
|
|
#4 |
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
Install base
Base is a web interface for snort and the snort alerts. See the "using base" section for a brief introduction. Code:
cd wget http://easynews.dl.sourceforge.net/sourceforge/secureideas/base-1.3.9.tar.gz Code:
cd /var/www tar zvxf ~/base-1.3.9.tar.gz mv base-1.3.9 base cd base cp -R /usr/src/snort-2.8.3/doc/signatures . cd .. chown -R www-data.www-data base Code:
pear install Image_Color Image_Canvas-alpha Image_Graph-alpha Code:
nano /etc/apache2/apache2.conf Code:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml Code:
/etc/init.d/apache2 restart You must accept cookies from base Click continue on the first page. Step 1 of 5: Enter the path to ADODB. This is /usr/share/php/adodb.
Step 2 of 5: Database type = MySQL, Database name = snort, Database Host = localhost, Database username = snort, Database Password = snort_password
Step 3 of 5: If you want to use authentication (used to log into the web interface) enter a username and password here and check the box. Step 4 of 5: Click on Create BASE AG. Step 5 of 5: once step 4 is done at the bottom click on Now continue to step 5 and log in. Congratulations ! You should now see something that looks like this : Click to enlarge pictureYou can password protect the base directory with .htaccess and/or use ssl. Back to top
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; September 15th, 2008 at 08:57 PM.. |
|
|
|
|
|
#5 | |||
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
Using snort / base
Although seemingly foreign, everything in base is point and click. Click on your alerts for example and they will be listed. Click on various links and you will be brought to web pages(s) where the alert is explained in more detail. For example, here is a screen shot showing us some alerts. Click to enlarge pictureClilck on the blue "19" by "Total Number of Alerts" and base will show you ... Click to enlarge pictureAlerts : Quote:
click on the ip address (74.6.17.188) to take you to a page where you can select a link to look up the offending ip. On this second page, click on ARIN (or any other) which will take us to a page where we can see this ip address belongs to Yahoo.com =============== Another example, from a local port scan : Quote:
http://www.snort.org/pub-bin/sigs.cgi?sid=119:14 This alert was generated by my portscan to show the active response of ossec (see below). Basic alert management First, when you first install snort, you will likely get a large number of alerts. Most of these are legitimate traffic (false positives). YOU WILL NEED TO RESEARCH EACH ALERT AND DETERMINE IF YOU ARE VULNERABLE. IF SO, FIX YOUR VULNERABILITY. For "false positives, once you have confirmed an alert is indeed either a false positive or legitimate traffic, either modify or comment out the rule (writing snort rules is beyond this tutorial, see How to snort rules). For the example here, robots.txt : Note: There are better ways of managing robots.txt, see the snort links and apache documentation, I am using this only as an example of editing snort rules. grep is our friend here, so find the alert with : Code:
grep robots.txt /etc/snort/rules/* Quote:
Code:
sudo nano -w /etc/snort/rules/web-misc.rules When you find the appropriate line (the one that starts with a "alert"), add a # to the front of the line. Re-start snort. Once you have managed the false positives, watch for repeat offenders. If I see an IP address persistently triggering snort, I black list it in iptables. If you do not know how to do this, see here : Uncomplicated_Firewall_ufw Specifically : https://help.ubuntu.com/community/Un...ocking%20Rules Hint: EDIT /etc/ufw/before.rules Back to top
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; September 15th, 2008 at 04:48 PM.. |
|||
|
|
|
|
|
#6 | |
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
OSSEC-HIDS
OSSEC-HIDS is much easier to install. Basically it is downloading and then running a script. Go to the ossec download page and download the most recent version : http://www.ossec.net/main/downloads/ Code:
wget http://www.ossec.net/files/ossec-hids-1.6.tar.gz tar xzvf ossec-hids-1.6.tar.gz Code:
cd ossec-hids-1.6 ./install.sh When you get to the question : Quote:
There is a very nice post on the Ubuntu forums here : Howto setup OSSEC-HIDS on your ubuntu box ~ Thanks RShadow The only "problem" is that the post is a little outdated. The information about running the install script is accurate, but you DO NOT need to write an init script. ossec 1.6 will install a script for you into /etc/init.d/ossec Start / Stop OSSEC with : Code:
sudo /etc/init.d/ossec start|stop Not much needs to be done. HOWEVER I would caution you that OSSEC has an active response to threats. If OSSEC detects a bad ip address, it will block that ip address using iptables. This means that if your snort rules are giving you false alerts legitimate traffic to your server will be blocked. This also means you can lose access to your server as well. Fortunately this is a temporary ban. It is more than sufficient to deter the script kiddies and if your access is blocked, access is restored in a few minutes. This means , however, you need to monitor snort (base) and fine tune your rules so you are not blocking legitimate traffic. Again, if there are repeat offending IP addresses, black list them in iptables (See the using snort/base post for how to do this). Additional configuration of OSSEC is is done by editing /var/ossec/etc/ossec.conf This configuration file is well commented and you will see a white list section where you may white list additional ip addresses if needed. Back to top
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; September 15th, 2008 at 04:56 PM.. |
|
|
|
|
|
|
#7 |
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
Web access to ossec
Download the web interface from http://www.ossec.net/main/downloads/ Code:
cd wget http://www.ossec.net/files/ui/ossec-wui-0.3.tar.gz cd /var/www tar xzvf ~/ossec-wui-0.3.tar.gz mv ossec-wui* ossec cd ossec ./setup.sh When the script is finished running, change ownership of the directory and add www-data to the ossec group Code:
cd /var/www chown -R www-data.www-data ossec usermod -G ossec -a www-data Code:
/etc/init.d/apache2 restart From the web interface you can see any changes to system files and alerts. Back to top
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; September 16th, 2008 at 07:05 PM.. |
|
|
|
|
|
#8 | |
|
Ubuntu Guru
![]() |
Re: Intrusion Detection
Using ossec :
Once you log into the web interface you will have a number of tabs. Main ~ This is where you will see alerts. Integrity checking ~ Will show you recent changes to system files. Understanding and modifying rules Listing of rules (it is incomplete): http://www.ossec.net/wiki/index.php/Rule Modifying rules : http://www.ossec.net/wiki/index.php/...w:Ignore_Rules I did find this wiki page on integrating base + ossec, but I have not tried it. ossec + base : http://www.ossec.net/wiki/index.php/OSSEC_&_BASE Example of ossec active response : Quote:
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999 ![]() Last edited by bodhi.zazen; September 18th, 2008 at 11:19 PM.. |
|
|
|
|
|
|
#9 |
|
Twilight Master Bumper
![]() Join Date: May 2007
Location: New Jersey
Beans: 6,281
Ubuntu Development Release
|
Re: Intrusion Detection
The Ubuntu Guru strikes again! Thanks bodhi, this thread is great, I think it's your best so far.
Now for a short little addendum to the main guide, for those interested in low system impact. Intrusion Detection using a Virtual Machine If you would like to take this guide for a run without heavily messing with their current system configuration, you can still get the full effect by setting up Ubuntu in a Virtual Machine (VM) and following the guide from there. The concepts here apply to whatever virtualization software you prefer, I just use vbox as an example since that is what I used. The only work that needs to be done on your host machine (not the VM) is to setup a network bridge so that your VM will have an IP assigned by your network's DHCP server (in a home network, this is usually the central router). You can also opt set a static IP that is recognized by the rest of the network. With this network IP, you can then actually see what is happening on the network, unlike with the default private IP that VMs normally get assigned. Example: Normal Private IP: 10.0.2.15(Note: Yes, yes, 192.168.xxx.yyy is also in the private IP range, but this is what is generally seen on a home network, and I therefore refer to as the network IP.) General Directions for using VirtualBox: Setup your virtual machine with an Ubuntu installation - there are many guides out there on how to do this (ex: community/VirtualBox). Don't forget to install LAMP and the build-essential metapackage which are needed for the above tutorial. Now create a network bridge on your host machine by following the directions at community/VirtualBox#Networking. Our guru, bodhi.zazen, also suggested the following link which will also work for vbox - community/KVM#Creating a network bridge on the host. I found it helps to first set your host to DHCP temporarily if you are using a static IP so that you can easily configure the bridge. Then you can setup your static IP after your bridge is successfully created and tested. The VM won't know the difference, other than it will get an IP immediately compatible with your network. Also, don't forget to create the scripts to bring the bridge up and down as described in the VirtualBox wiki link. Here is my /etc/network/interfaces file, with static IP on the host, for your reference (yours will vary). I have edited out my username, and I am using a Linksys WRT54G router: Code:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). auto eth0 iface eth0 inet manual address 0.0.0.0 auto br0 iface br0 inet static bridge_ports eth0 address 192.168.1.201 netmask 255.255.255.0 gateway 192.168.1.1 auto lo iface lo inet loopback auto tap1 iface tap1 inet manual up ifconfig $iface 0.0.0.0 up down ifconfig $iface down tunctl_user username If you're in to using static IPs, you can now set a static IP on your VM as well. This makes it convenient to access the web service interfaces for BASE and OSSEC from another system (like the host). Enjoy!
__________________
Beginners Guide to Filing Bug Reports | Ubuntu Security | Grub2 Troubleshooting Suspend/Resume: Remotely Backtrace X The Bump Thread - as pointless as it sounds. Last edited by Rocket2DMn; September 26th, 2008 at 02:23 PM.. Reason: set eth0 static ip |
|
|
|
|
|
#10 |
|
Fresh Brewed Ubuntu
![]() Join Date: Oct 2007
Location: ISS
Beans: 1,429
|
Re: Intrusion Detection
Thanks mate. This thread is indeed great.
__________________
CLI | Installation_Problems | DocIndex | tldp.org | GNUphil | Criticism_Microsoft |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|