<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bhaviksBlog &#187; Security</title>
	<atom:link href="http://bhaviksblog.com/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://bhaviksblog.com</link>
	<description></description>
	<lastBuildDate>Fri, 06 Nov 2009 20:25:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Snort Log Parser</title>
		<link>http://bhaviksblog.com/01/snort-log-parser/</link>
		<comments>http://bhaviksblog.com/01/snort-log-parser/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 16:39:41 +0000</pubDate>
		<dc:creator>Bhavik</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[snort]]></category>

		<guid isPermaLink="false">http://bhaviksblog.com/?p=80</guid>
		<description><![CDATA[This is a snort log parsing script. It goes through the snort event logs and sends you an email with the most occuring signatures. Easy to setup and simple to use. ]]></description>
			<content:encoded><![CDATA[<p>Hey guys, I&#8217;d like to share a script I wrote to make reporting simpler for Snort. <a href="http://www.snort.org" target="_new">Snort</a> is an open source intrusion detection / prevention system. It blocks or detects packets based on rules. Its an awesome security tool to see exactly what is going  on in your network and offers great protection if you decide to put it in prevention mode. And its all free!</p>
<p>I installed it on my very old compaq computer which runs Ubuntu server edition. Didn&#8217;t really have a reason, just wanted to see how it works&#8230;will be getting rid of it soon since it slows down the network (Counter Strike and Snort don&#8217;t mix). </p>
<p>Anyway, to check the logs I had to ssh to the compaq (that computer has no monitor) and manually go through the logs. Usually the same event would&#8217;ve tripped 400 times in a row. Scrolling through all of this and logging into the compaq everytime was a pain. So I wrote a bash script that bundled the same events together, output the number of times they occured and emailed this information to me everyday. Now all I had to do was check my email. I also added a threshold so it would only email rules that tripped at least 20 times.</p>
<p>I&#8217;m sure this method isn&#8217;t as efficient as some of the other parsers that are out there&#8230;but this one&#8217;s awesome since I made it! Here it is&#8230;</p>
<p><span id="more-80"></span></p>
<p>Note:  The snort log output method has to be &#8220;Fast&#8221;, more on that in a bit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Author: Bhavik from www.bhaviksblog.com</span>
<span style="color: #666666; font-style: italic;">#Script is free! Do whatever you want with it!                                                                                            </span>
<span style="color: #666666; font-style: italic;">#Date created : 11/06/08                                  </span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Automatically emails listed recipient all alerts that                            </span>
<span style="color: #666666; font-style: italic;">#occur in the log file more than 20 times                                           </span>
<span style="color: #666666; font-style: italic;">#Script will be added to cron to execute everyday      </span>
<span style="color: #666666; font-style: italic;">#email_alerts.txt contains the latest events that         </span>
<span style="color: #666666; font-style: italic;">#occured more than 20 times                                </span>
&nbsp;
<span style="color: #007800;">email</span>=<span style="color: #ff0000;">&quot;your email here&quot;</span>
<span style="color: #007800;">lines_in_file</span>=<span style="color: #000000;">5000</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> $<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">then</span> 
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The logfile must be supplied as an argument&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-e</span> $<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The file you supplied does not exist&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$lines_in_file</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-k</span> <span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-s</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-d</span>  
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'$1 &gt; 20 {print $0,&quot;n&quot;}'</span> <span style="color: #000000; font-weight: bold;">|</span> 
<span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> email_alerts_output.txt
mail <span style="color: #660033;">-v</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Snort Sensor Alerts&quot;</span> <span style="color: #007800;">$email</span> <span style="color: #000000; font-weight: bold;">&lt;</span> email_alerts_output.txt
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Logs Sent.&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>There are two variables at the top that you should set. The email is obviously the email address of where the logs should go. The lines_in_file is a variable since the logfile is constantly growing (if theres traffic on the network). I needed to see approximately how many lines get added to the file every 24 hours. I checked by doing a wc -l at 12pm on the log file to see the number of lines it had. 12 hours later I did the same thing. </p>
<p>The file grew about 2000 lines. I padded another 500 to be safe and doubled it to 5000 for the 24 hour period. The threshold determines how many times a rule has to trip before you get emailed about it. Above it is set to 20 (in the awk statement), you can change it there.</p>
<p>Now you need to make the script a cron job so you get emailed everyday. You can use crontab to do this.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-l</span>       <span style="color: #666666; font-style: italic;"># lets you see what is currently listed under cron</span>
crontab <span style="color: #660033;">-r</span>      <span style="color: #666666; font-style: italic;"># deletes your current cron</span>
crontab <span style="color: #660033;">-e</span>     <span style="color: #666666; font-style: italic;"># lets you edit the current cron</span></pre></div></div>

<p>Crontab uses 5 fields to determine the time (military time) your command runs. Here are a couple examples.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">01 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Runs a minute after every hour&quot;</span>
<span style="color: #000000;">45</span> <span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Runs everyday at 10:45 am&quot;</span>
00 <span style="color: #000000;">8</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Runs at 8 am every Sunday&quot;</span></pre></div></div>

<p>Heres what my cron looks like for this script.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">00 <span style="color: #000000;">8</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>snort<span style="color: #000000; font-weight: bold;">/</span>log_parser.sh <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>snort<span style="color: #000000; font-weight: bold;">/</span>alert
<span style="color: #666666; font-style: italic;">#sh /var/log/snort/log_parser.sh is the command to call the script</span>
<span style="color: #666666; font-style: italic;">#/var/log/snort/alert is the snort log file (im using full paths)</span></pre></div></div>

<p>Another important thing is to make sure that your method of logging is set to &#8220;Fast&#8221;.  The output of your logfile  should be in this format.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">01<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">28</span>-00:<span style="color: #000000;">14</span>:<span style="color: #000000;">17.600025</span>  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">**</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span>:<span style="color: #000000;">2469</span>:<span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> NETBIOS SMB-DS D$ unicode share access <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">**</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Classification: Generic Protocol Command Decode<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Priority: <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>TCP<span style="color: #7a0874; font-weight: bold;">&#125;</span> 10.xx.xx.xx:<span style="color: #000000;">2327</span> -<span style="color: #000000; font-weight: bold;">&gt;</span> 10.xx.xx.xx:<span style="color: #000000;">445</span></pre></div></div>

<p>You can set it to this output method when you call the command to start snort. This is what my command looks like.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">snort <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>snort<span style="color: #000000; font-weight: bold;">/</span>snort.conf <span style="color: #660033;">-A</span> fast <span style="color: #660033;">-I</span> eth2 <span style="color: #660033;">-D</span>
<span style="color: #666666; font-style: italic;"># -c is the config file for additional configuration</span>
<span style="color: #666666; font-style: italic;"># -A is where you set the logging method. We want Fast</span>
<span style="color: #666666; font-style: italic;"># -I is the interface</span>
<span style="color: #666666; font-style: italic;"># -D is to make it a Daemon which keeps it running</span></pre></div></div>

<p>If everything is setup correctly you should get an email at the specified time in cron. For the mail command to work you need a mail server setup on whichever box snort is running. Its a pretty simple script, no confusing configuration&#8230;.Hope it helps! Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://bhaviksblog.com/01/snort-log-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
