Showing posts with label Barnyard2. Show all posts
Showing posts with label Barnyard2. Show all posts

Friday, May 24, 2013

Troubleshooting your Snort deployment

I recently had a discussion with a user new to snort and autosnort who wanted to know some troubleshooting techniques that can be done to see if snort is working and/or snorby or the web interface of your choosing is working. After thinking about it, I decided it might be a good idea to post my troubleshooting steps here to assist users of snort and snorby in general to determine if things are working okay.

Before we begin here, realize that there are a number of moving parts with any IDS/IPS deployment.  Understanding the basics of networking (OSI/TCPIP stacks, collision domains and/or broadcast domains) really help you in understanding why snort can or cannot see traffic for certain parts of your network. If you have no way of copying traffic from the network segment you want to protect, then snort will not be able to see anything.

Now that I got that part out of the way, there are a couple of basic components in any snort deployment:

1) the network

How busy is your network? If the network isn't particularly active, it may take a while before you see any sort of alerts from snort.

2) the method you are using to pass network traffic to snort

How are you copying traffic to snort's sniffing interface? Do you have an old hub? a professional grade network tap or hobbyist network tap? A switch that can do port mirroring/span ports? Is snort sitting in a VM? does that virtual machine have a way to sniff traffic off of the vswitch?

Any IDS/IPS deployment needs a reliable method to clone/copy traffic off of the network. If you plug snort into a regular switch port or SOHO router, you're usually only going to see broadcast traffic (usually UDP broadcasts, CDP broadcasts, Spanning tree traffic, and ARP requests) and will be absolutely useless to you.

You need to have the equipment or means to copy traffic to snort somehow.

3) Snort itself and how it's configured

If you have a light ruleset (say the balanced ruleset from pulledpork, or the connectivity over security ruleset), you won't be seeing very many alerts, unless those rules are a really big deal, like big enough to be included in those rulesets, and/or if your network is particularly infested with bad traffic.

4) Barnyard2, how it's configured and/or the database it is logging to

Autosnort is configured to use barnyard2 and log to a local database. normally this is the "snort" database, but some web interfaces require their own database (e.g. Aanval uses the aanval database and snort database, snorby uses the snorby database). Does barnyard2's database user have the right access to insert events to the database? does the database user have the right credentials?

For other barnyard2 logging options, such as syslog, is the remote host allowing connections from your sensor's management interface? is the SIEM solution configured to log syslog events properly?

So, to summarize IDS/IPS deployments have a number of parts that have to work together to provide you with a working solution: The network itself, the method you are using to copy network traffic to snort, snort or the IDS/IPS solution you are using and what its configured to alert on, and the method by which you are logging intrusion events (barnyard2/database/syslog).

Here are some basic troubleshooting methods I've devised:

Basic Steps:

1) are snort processes running? If you're using Snorby or another specialized logging interface, are the processes that interface relies on running?

ps -ef | grep snort
ps -ef | grep delayed

you are looking for this output from ps -ef | grep snort:

root      1853  1258  0 17:54 pts/0    00:00:00 grep snort
snort     1883     1  0 May18 ?        00:00:47 /usr/local/snort/bin/snort -D -u snort -g snort -c /usr/local/snort/etc/snort.conf -i br0
root      1912     1  0 May18 ?        00:00:53 /usr/local/bin/barnyard2 -c /usr/local/snort/etc/barnyard2.conf -d /var/log/snort -f snort.u2 -w /var/log/snort/barnyard2.waldo -D

you are looking for this output from ps -ef | grep delayed:

root      1869  1258  0 17:55 pts/0    00:00:00 grep delayed
root      2161     1  0 May18 ?        00:11:01 delayed_job
If snort and barnyard2 BOTH are not running, check /var/log/messages (cat /var/log/messages [or /var/log/syslog depending on your distro] | grep snort) to see if you can determine why. Look for error, critical or fatal messages as they indicate reasons why snort or barnyard2 refused to run. We'll talk about snorby's delayed_job process in a moment.

2) ifconfig -a

-- which interface is snort sniffing traffic on? is it in promiscuous mode?

You're looking for output that looks something like this on the interface that snort is sniffing traffic on, pay attention to the lines in bold face:

eth1      Link encap:Ethernet  HWaddr 00:0c:29:8b:bb:ca
          inet6 addr: fe80::20c:29ff:fe8b:bbca/64 Scope:Link
          UP BROADCAST RUNNING NOARP PROMISC  MTU:1500  Metric:1

The most important lines above are UP RUNNING PROMISC, because the interface must be up, must be running, and likely should be in promiscuous mode to pick up traffic. the NOARP line isn't entirely necessary, but it's there to ensure that the sniffing interface doesn't respond to arp queries in case attackers are probing the network to try and find your IDS installations.

3) How are you passing traffic to snort? is snort's sniffing interface attached to a switch span? a hub? a network tap? if it's a virtual machine on ESXi or something of that nature, is the vswitch snort is sniffing off of configured to allow promiscuous mode network cards?


If you're in a corporate environment, and are a proficient network administrator, I'm going to assume you know what a switch span port is. These are also referred to as mirror ports. Most professional grade switches have an option to copy ALL traffic seen on a switch to a single interface. You would plug snort's sniffing interface into this mirror interface for snort to see traffic for that entire network segment.

If you're a security reasearcher and don't have money for a procurve or cisco switch that does port mirroring, here's some awesome alternatives:

http://routerboard.com/RB260GS

This is a 5-port switch from microtik. Very very affordable and capable of port mirroring.

Alternatively, if you want a bigger name-brand switch, I personally use netgear's GS108T switch for my home network, since it was the cheapest switch I was aware at the time that allowed port mirroring:

http://www.newegg.com/Product/Product.aspx?Item=33-122-381&IsVirtualParent=1

An alternative to span/mirror ports are network taps. On the professional/corporate side, Net Optics, Gigamon and several other vendors offer network tap solutions. Often ridiculously priced, but without all of the possible problems that come with setting of span/mirror ports. These devices are solely dedicated to creating exact clones of network traffic passing over the wire and nothing else.

For those on the cheap side, there are several results via google on how to make your own network tap, but be aware that these sorts of taps are usually for 10/100 networks and usually do not support tapping gigabit networks.

Finally for vmware environments, I posted a specialized tutorial on how to "hack" vmware player on how to bridge traffic from one physical interface or another, using the vmnetconfig.exe from vmware workstation (check the pdf document available in my autosnort github if you're interested...)

But for professional deployments or network labs running vmware ESX/ESXi, it's pretty easy to configure a vswitch to allow promiscuous mode nics. That's really all you have to do is change vswitch security settings, allow promiscuous mode NICs and just configure the snort VM to sniff off of that vswitch.


4) run tcpdump on snort's sniffing interface:

tcpdump -i ethX not arp and not port 22

X is the ethernet interface number snort is sniffing traffic on. the "not arp and not port 22" is telling tcpdump to ignore ssh traffic and arp broadcasts.

while tcpdump is running, on another system on the network, try doing something to generate network traffic (ping google.com, go to a web page, etc.). did tcpdump see your traffic? If not, you may need to investigate how you're mirroring traffic to snort.

5) Check and see if the snort.u2 file is greater than 0 bytes:
ls -al /var/log/snort
check the output of the ls command. You're looking for the snort.u2 file, it should look something like this:

-rw-------  1 snort snort 67261 May 19 17:39 snort.u2.1368917933
the numbr "67261" in the middle is the file's size. If your snort.u2 file is 0 bytes, that means snort hasn't generated any alerts.
So those are the basic steps. You confirm that snort is running, confirm that the interface is in promisc mode, and confirm that mirroring device is actually pushing traffic to where snort can see it, and confirm snort is logging events.

Snorby-specific troubleshooting steps:
Here's a couple of things you can try to confirm that barnyard2 and snorby are working together:

1) ps -ef | grep delayed
- You are looking for an entry that looks something like this:

root      2161     1  0 May18 ?        00:11:00 delayed_job
if the delayed_job process is NOT running, run this command:

cd /var/www/snorby && ruby script/delayed_job start
then run this command to see if the sensor_cache needs to be updated:

cd /var/www/snorby && rails runner 'Snorby::Jobs::SensorCacheJob.new(false).perform; Snorby::Jobs::DailyCacheJob.new(false).perform'
note: I do not know if you need root permission to run the commands above, but if the above commands fail without root privileges, run the command:
 sudo su -
to get a shell with root privileges and re-run those commands.

2) you'll want to check the contents of barnyard2.conf and snorby's database.yml to make sure they match:
cat /usr/local/snort/etc/barnyard2.conf
on the log mysql line, check these values and make sure they match:
log,mysql, user=snort password=[password you gave the snort database user] dbname=snorby host=localhost

cat /var/www/snorby/config/database.yml

verify these lines in database.yml:

snorby: &snorby
  adapter: mysql
  username: snort
  password: [same password in the barnyard2.conf file]
  host: localhost

development:
  database: snorby
  <<: *snorby

test:
  database: snorby
  <<: *snorby

production:
  database: snorby
  <<: *snorby

the most important lines to check are the dbname: and database: line under production are the same database, and that the password= and password: lines are the same to make sure that barnyard2 and snorby agree on the correct password to use to log to and read from that same database.

If the database lines and password lines match, at the very least, we know that barnyard2 and snorby are talking to the right database.

3) One last check you can perform is to verify that the snort user has the privileges to talk to the snorby database. run this command:

mysql -usnort -p[snort database user's password, no spaces] snorby -e "show tables;"

your output should look like this:

+-------------------+
| Tables_in_snorby  |
+-------------------+
| agent_asset_names |
| aggregated_events |
| asset_names       |
| caches            |
| classifications   |
| data              |
| delayed_jobs      |
| detail            |
| encoding          |
| event             |
| events_with_join  |
| favorites         |
| icmphdr           |
| iphdr             |
| lookups           |
| notes             |
| notifications     |
| opt               |
| reference         |
| reference_system  |
| schema            |
| search            |
| sensor            |
| settings          |
| severities        |
| sig_class         |
| sig_reference     |
| signature         |
| tcphdr            |
| udphdr            |
| users             |
+-------------------+
This confirms that the snorby database exists and that the schema was configured properly during installation.

4) If the snort.u2 file in /var/log/snort is NOT 0 bytes, and you confirmed the snort database user was able to see the tables in the snorby database, there's one last set of commands you can run:
mysql -usnort -p[snort database user's password] snorby -e "select * from event\G;"
if you get "empty set" as the return value from that command, snorby doesn't have anything. If you get a bunch of data from this command, snorby should have events in the "events" tab on the web interface.
you can also run this command:
mysql -usnort -p[snort database user's password] snorby -e "select count(*) from event;"
you should get something like this:

+----------+
| count(*) |
+----------+
|     5284 |
+----------+
I have a boatload of events, because I have a testing suite that causes snort to trigger alerts like crazy, but basically, you're looking for the count number to NOT be 0. If the count is 0 there's no events for snorby to report on.


Hope this helps you all out

Cheers,

DA_667

Sunday, April 21, 2013

Sometimes the old ways are the best ways (support for BASE and Syslog_Full output)

Hello AS/snort users,

Got two new features in this latest build of autosnort.

First and foremost is support for the BASE web interface. BASE is by and far one of the older and more well-known web interfaces for snort alerting. While the interface isn't going to win for prettiest interface, it is by and far very functional. Some of the cool things include the ability to download alerts as pcap and actual tshark/pcap parsed output for each alert.

This has been added as an installation option in the interface selection menu. The installation is painless and straight forward. After the system reboots, just point your browser to http://[your ip]/base.

The web page initial setup will check for all of the required pre-requisite settings on the first page. On the second page, it will ask you where adodb, a pre-requisite package, is installed. Autosnort and most linux distros install adodb to /usr/share/php/adodb (put that in for the path to adodb). It will also, of course ask you for database information and credentials:
database name: snort
database host: localhost
database port: 3306 (can leave blank if you'd like)
database username: snort
password: (the snort database user's password)

Unless you have an archive database configured, leave that part blank.
On the last page, it will ask if you want to set up auth to get into the web page to review events. That is entirely up to you.

After that, you should be all set to get events to the BASE web interface.

The next feature I have to announce is support for syslog output as another output interface choice. I've added a child script that configures barnyard2 to output to syslog_full format to port 514/udp. I have not FULLY tested this feature, but preliminary tests show that splunk picks up and parses the events with no issues whatsoever. A couple of troubleshooting recommendations:

-Ensure that the sensor's management interface, if it is firewalled, has port 514/udp open and allowed outbound.
-Conversely, ensure that your SIEM or syslog aggregator has port 514/udp open inbound to accept events -- I hosted splunk on a CentOS box and was puzzled why tcpdump says we were sending events out, but they were never making it to be indexed by splunk. I ran system-config-firewall-tui and added a rule for 514/udp inbound (and port 8000/tcp inbound for the actual web UI), and everything was fine.

The child scripts have been made available to Debian, Ubuntu and CentOS.

One last thing:

I've made some minor changes to the script at the recommendation of maintainer of the barnyard2 project. Instead of using sed to modify the copy of barnyard2.conf included with the barnyard2 source, I'm making the script generate a barnyard.conf on-the-fly.

- the script keeps a copy of the original barnyard2.conf in /usr/local/snort/etc/ named barnyard2.conf.origin
- the script generates a barnyard2.conf with only the directives necessary to run barnyard2 (e.g. where are the reference and classification config files, the gen/sid-msg.map files, input format to accept, output format to output to, etc.)
- if you choose to configure output to syslog format, the child script disables output to the database automatically.

As always, the scripts are up on github, along with updated READMEs. Previous versions are available in the Previous_Rel directory as well.

Happy Hunting..

DA_667

Saturday, April 13, 2013

New AS release, New init scripts, bug fixes and more!

Hello AS users,

Got a lot to talk about today, so let's get down to business:

First and foremost I've finally gotten around to writing half-decent documentation for autosnort. I've pushed a pdf file to github featuring documentation with screenshots on how to install Autosnort via vmware player, including an interesting hack on how to get bridging to work on multiple interfaces on vmware player 5.

I chose CentOS as the vmware player operating system, but the instructions should be easy to follow for Debian Ubuntu or Backtrack. Any major differences were noted. All said and done it was about 23 pages of documentation with screenshots peppered in.

I focused on using VMware player this time around, and generally speaking the VMware player guidance can be used just as well for VMware Fusion or Workstation. I may do an alternate document for ESXi and/or Virtualbox in the near future.

I've also included general troubleshooting steps and things you *should* see after running autosnort.

Next in line is an update to the autosnort script for Debian, Ubuntu, and CentOS. Banyard2.13 BETA2 has changed how barnyard2 behaves. As a result of this, I had to change how arguments are passed to barnyard2 in Autosnort. The details are available for each operating system's readme files. Suffice to say, everything works fine now.

Finally, I've gotten around to testing and posting init scripts for Ubuntu and Debian to control snort and barnyard2. The Ubuntu and Debian init scripts support start, stop and restart functions and are pretty easy to implement. Implemtation details are also available via the Readme files for Ubuntu and Debian Autosnort scripts, but suffice to say, its incredibly easy.

I may release a modification to the init script that detects if you installed aanval and automatically start/stop the BPUs along with snort and barnyard2, but that will come a little later.

The documentation, new scripts, readmes and init scripts should all be available via github as of now.

Cheers,

DA