<?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>FILI&#039;S TECH THOUGHTS &#187; cron</title>
	<atom:link href="http://blog.fili.nl/tag/cron/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fili.nl</link>
	<description>-- All wiyht.  Rho sritched mg kegtops awound?</description>
	<lastBuildDate>Thu, 08 Jul 2010 15:45:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Audit your network using Nmap, Ndiff and cron</title>
		<link>http://blog.fili.nl/articles/audit-your-network-using-nmap-ndiff-and-cron/</link>
		<comments>http://blog.fili.nl/articles/audit-your-network-using-nmap-ndiff-and-cron/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 19:31:59 +0000</pubDate>
		<dc:creator>fili</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[audit]]></category>
		<category><![CDATA[auditing]]></category>
		<category><![CDATA[backdoors]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ndiff]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[rootkits]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[trojans]]></category>
		<category><![CDATA[virusses]]></category>
		<category><![CDATA[worms]]></category>

		<guid isPermaLink="false">http://blog.fili.nl/?p=185</guid>
		<description><![CDATA[To combat the ill effects of trojans, rootkits and worms (not to forget the new H1N1 virus) one "should" regularly scan their local network for changes, preferably on a daily basis. Then again, one "should" also preferably feed the dog, greet the neighbors and clean their teeth on a daily basis. Tell me, who has [...]]]></description>
			<content:encoded><![CDATA[<p>To combat the ill effects of trojans, rootkits and worms (not to forget the new H1N1 virus) one "should" regularly scan their local network for changes, preferably on a daily basis. Then again, one "should" also preferably feed the dog, greet the neighbors and clean their teeth on a daily basis. Tell me, who has time to do all that?</p>
<p>Network auditing is a tedious task and because it's not very stimulating work, you're likely more prone to error. I too, as your fellow computer enthusiast, like to automate just about anything (and as such my dog is never hungry, my teeth never dirty and my neighbor never under-greeted).<br />
So here's how I did it this time.</p>
<p><strong>1. Nmap 5 to the rescue!<br />
</strong>Nmap is a "<em>network exploration tool and security / port scanner"</em>, commonly used by sysadmins and unanimously considered  (by me) to be an indispensable tool. Nmap version 5 was recently  (july 16th, 2009) released - bringing some <a href="http://nmap.org/5/" target="_blank">exciting new features</a>. This article focuses on Ndiff, the scan comparison tool. It's the fruit of a Google Summer of Code project in 2008.</p>
<p>Your first task is to install Nmap 5. It happily runs on Windows, Linux, and Mac OS X, however this article is written with Linux in mind. Note: earlier releases won't do, on Debian Lenny I had to obtain version 5 through the <a href="http://backports.org/dokuwiki/doku.php" target="_blank">backports repository</a>.</p>
<p><strong>2. Next, install the script</strong><br />
Make a directory somewhere only accessible by root and put the following bash script in it:</p>
<pre class="brush: bash;">
#!/bin/bash
# Simple cron-based network auditing scanner
# Requires Nmap 5+
# Related article @ http://blog.fili.nl/articles/audit-your-network-using-nmap-ndiff-and-cron/

MAILOUT=your@email.com
NETWORK=10.0.0.0/24

CWD=`dirname $0`
NMAP=/usr/bin/nmap
NDIFF=/usr/bin/ndiff
MAIL=/usr/bin/mail

if [ -f &quot;$CWD/baseline.xml&quot; ]; then
    echo &quot;Scanning network $NETWORK...&quot;
    $NMAP -n -oX &quot;$CWD/current.xml&quot; $NETWORK &gt;/dev/null

    echo -n &quot;Comparing Nmap scans using Ndiff...&quot;
    $NDIFF $CWD/baseline.xml $CWD/current.xml &gt;$CWD/last-result

    if [ $(stat -c%s &quot;$CWD/last-result&quot;) -gt 70 ]; then
        echo &quot;Changed!&quot;; echo &quot;$MAILOUT has been notified.&quot;
        cat $CWD/last-result | mail -s &quot;Alert: Network $NETWORK changed&quot; $MAILOUT
        mv $CWD/current.xml $CWD/baseline.xml
    else
        echo &quot;Ok.&quot;
        rm -f $CWD/current.xml $CWD/last-result
    fi
else
    echo &quot;First scan, generating baseline...&quot;
    $NMAP -n -oX &quot;$CWD/baseline.xml&quot; $NETWORK &gt;/dev/null
fi
</pre>
<p>Download: <a href="http://fili.nl/naudit-cron/naudit-cron.sh" target="_blank">naudit-cron.sh</a></p>
<p>It's a quite straightforward script as you can see.<br />
Here's what it does:</p>
<ol>
<li>At the first run, it makes a baseline scan of your network to compare too.</li>
<li>At subsequent runs it makes a new scan and compares that to the baseline scan. When something differs in your network (like newly opened/closed ports or computers that have appeared/disappeared) it alerts an admin.</li>
<li>Finally it updates the baseline xml-file to reflect the change.</li>
</ol>
<p><strong>3. Configure the script<br />
</strong>There are few settings to adjust, but they are important. MAILOUT obviously declares where to send the notifications to. With NETWORK you can define what you want to scan, this could be an entire subnet (in <a href="http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" target="_blank">CIDR notation</a>) or a single ip.</p>
<pre class="brush: bash;">
MAILOUT=your@email.com
NETWORK=10.0.0.0/24
</pre>
<p>Make the file executable and run it (a couple of times) to generate the baseline xml-file and to verify that everything works as expected.</p>
<p><strong>4. Finally, cron it<br />
</strong>The only step left is to automatically execute this script on a hourly/daily/weekly basis. This is kind of OS specific, on most Linux distribution you'd create a new file in /etc/cron.d/ containing:</p>
<pre class="brush: plain;">
# minute - hour - monthday - month - weekday - command
0 1 * * * root /root/naudit-cron/naudit-cron.sh &gt;/dev/null
</pre>
<p>Tweak the cron settings and you're done!</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">As your fellow computer enthusiast,</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.fili.nl/articles/audit-your-network-using-nmap-ndiff-and-cron/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
