<?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>idlethreat &#187; Code</title>
	<atom:link href="http://idlethreat.com/site/index.php/archives/tag/code/feed" rel="self" type="application/rss+xml" />
	<link>http://idlethreat.com/site</link>
	<description>stupid is durable</description>
	<lastBuildDate>Fri, 03 Sep 2010 11:33:51 +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>Visualizing network connections using GraphViz and Afterglow</title>
		<link>http://idlethreat.com/site/index.php/archives/5</link>
		<comments>http://idlethreat.com/site/index.php/archives/5#comments</comments>
		<pubDate>Sun, 15 Mar 2009 16:53:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[GraphViz]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[After recovering from a particularly nasty crash and migrating my sites and data over to a new server, I became curious at the number of networking connections that it received, and what was going where. Sure, there&#8217;s a lot of tools out there to give me that sort of information, but sometimes you would really [...]]]></description>
			<content:encoded><![CDATA[<p>After recovering from a particularly nasty crash and migrating my sites and data over to a new server, I became curious at the number of networking connections that it received, and what was going where. Sure, there&#8217;s a lot of tools out there to give me that sort of information, but sometimes you would really just like a pretty (if informative) picture of information instead of dry old text scrolling across the screen.<br />
<span id="more-5"></span><br />
In this document I&#8217;ll assume the following:</p>
<p>You have access to a Linux / Unix server system and have administrative capabilities on it.</p>
<h2>tools I used</h2>
<p>Graphviz is an open source graph visualization software. It takes standard textual input and can automatically generate graphs depending on the input itself. It has its own graphing language, which is used to create all of this information for you.</p>
<p>Afterglow is a collection of scripts which assist in converting csv and other table data into information which can be pushed off to Graphviz to generate graphs with.</p>
<p>I also ended up with a &#8216;glue&#8217; shell script or two which assisted in gathering the information and pushing it off to Afterglow for processing.</p>
<h2>How To</h2>
<p>Download and install <a href="http://www.graphviz.org/">GraphViz</a> using your favorite package management system. Next, download and un-archive the <a href="http://afterglow.sourceforge.net/">Afterglow</a> package on the system. For myself, I placed all the Afterglow packages from afterglow/src/perl directory to a new /opt/afterglow directory.</p>
<p>After that has been set up, it&#8217;s time to get a tcpdump of your current connections. We&#8217;ll grab the first 10,000 packets and put it in the /opt/afterglow directory.</p>
<p><code class="prettyprint">tcpdump -vttttnneli eth0 -c10000 &gt; /opt/afterglow/eth0.dump</</code></p>
<p>Next, we'll parse it through Afterglow and let it do its magic. In this instance, we'll be looking at the source IP, destination IP, and finally the destination port. There's quite a number of possible fields to go by. Check out the source code from tcpdump2csv.pl for a full treatment of what is available.</p>
<p><code class="prettyprint">cat /opt/afterglow/eth0.dump | /opt/afterglow/parsers/tcpdump2csv.pl "sip dip dport" | /opt/afterglow/graph/afterglow.pl -c /opt/afterglow/parsers/color.properties -e 2 | neato -Tgif -o /opt/afterglow/eth0.gif</code>></p>
<p><img src="http://idlethreat.com/files/networking/fig1.gif" alt="" width="500" /></p>
<p>The initial run is interesting, but pretty cluttered. Looks more like a geek version of a fertilized-egg-and-sperm picture.</p>
<p>Since we're using three arguments (sip dip dport) as arguments, let's change the mode from the default (zero) up to three and then re-run the results.</p>
<p><code class="prettyprint">cat /opt/afterglow/eth0.dump | /opt/afterglow/parsers/tcpdump2csv.pl "sip dip dport" | /opt/afterglow/graph/afterglow.pl -p3 -c /opt/afterglow/parsers/color.properties -e 2 | neato -Tgif -o /opt/afterglow/eth0.gif</code></p>
<p><img src="http://idlethreat.com/files/networking/fig2.gif" alt="" width="500" /></p>
<p>This one is much more revealing and easy to read. You will notice by now that:</p>
<ul>
<li>Arrows show the direction of traffic</li>
<li>Red ovals will be an IP address which <strong>initiates</strong> a connection. A lot of the time this will be your own system. Other times it will be an external system sending in a request.</li>
<li>Red blocks will be an IP address which is <strong>processing</strong> a request. Again, your system will show up either as a processor of requests, or sending something out.</li>
<li>Light Blue Ovals will show which port this traffic is traveling across</li>
<li>Dark Blue Ovals will show up whenever communication is going across a 'named' port (below 1024). This is normally like port 80, 443, or 53 (DNS).</li>
</ul>
<p>Changing colors to fit your needs are relatively easy as well. I like a nice bright green to distinguish my system against all the other connections out there. To color your own "home" system as green, edit the /opt/afterglow/parsers/color.properties. At the top of the regex list, add in a line something like:</p>
<p><code class="prettyprint">color.source="green" if ($fields[0]=~/^your.ip.address.here/);</code></p>
<p>Save your changes and re-run the script to get an output where your IP address has a dinstinct color to it.</p>
<p><img src="files/networking/fig3.gif" alt="" width="500" /></p>
<p>Finally, if you would like to have a constantly refreshing view of your server traffic, then something like this should work out well for you:</p>
<p><code class="prettyprint"><br />
while true; do<br />
tcpdump -vttttnneli eth0 -c 2000 &gt; /opt/afterglow/current.dump<br />
cat current.dump |/opt/afterglow/parsers/tcpdump2csv.pl "sip dip dport" | /opt/afterglow/graph/afterglow.pl -p3 -c /opt/afterglow/parsers/color.properties -e 2 | neato -Tgif -o /var/www/yourwebsite.com/traffic.gif<br />
sleep 60<br />
done<br />
</code></p>
<p>Kick off the script, let it run once, and then hit <a title="http://yourwebsite.com/traffic.gif" href="http://yourwebsite.com/traffic.gif">http://yourwebsite.com/traffic.gif</a> for the story. It will refresh every 60 seconds.</p>
<h2>Summary</h2>
<p>Using Graphviz and Afterglow will give you a unique overview of your incoming and outgoing traffic and a much broader overview of what is coming in and out of your immediate network. This is a wonderful tool and one that deserves to be in every server geek's arsenal.</p>
<p>Enjoy!</p>
<p>tom</p>
]]></content:encoded>
			<wfw:commentRss>http://idlethreat.com/site/index.php/archives/5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
