<?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; wifi</title>
	<atom:link href="http://smorgasbord.gavagai.nl/tags/wifi/feed/" rel="self" type="application/rss+xml" />
	<link>http://smorgasbord.gavagai.nl</link>
	<description>Ambachtelijk bereide beschouwingen.</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:17:45 +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>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[en_GB]]></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>
