<?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"
	>

<channel>
	<title>Foo Bar Quux</title>
	<atom:link href="http://fbq.hamal.nl/index.php/feed" rel="self" type="application/rss+xml" />
	<link>http://fbq.hamal.nl</link>
	<description>Just a *nix phreak blogging</description>
	<pubDate>Wed, 25 Nov 2009 06:29:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Free 2-factor authentication with RADIUS and HOTP</title>
		<link>http://fbq.hamal.nl/index.php/archives/8</link>
		<comments>http://fbq.hamal.nl/index.php/archives/8#comments</comments>
		<pubDate>Tue, 12 Feb 2008 16:49:20 +0000</pubDate>
		<dc:creator>rsw</dc:creator>
		
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fbq.hamal.nl/index.php/archives/8</guid>
		<description><![CDATA[HOTP is an internet standard that can be used for 2-factor authentication (i.e., something you know and something you have). This is an event-based One-Time Password protocol (i.e., the passwords are generated based on a counter i.o. the current time). This article is a description of how I used free tools to setup a complete [...]]]></description>
			<content:encoded><![CDATA[<p>HOTP is an <a href="http://www.faqs.org/rfcs/rfc4226.html">internet standard</a> that can be used for 2-factor authentication (i.e., something you know and something you have). This is an event-based One-Time Password protocol (i.e., the passwords are generated based on a counter i.o. the current time). This article is a description of how I used free tools to setup a complete environment for two-factor authentication on various servers. The article below is targetted to debian-based systems, but users of other Linux distributions (or other PAM enabled unices) should not have too great a difficulty to adept the description to their own environment.<br/><span id="more-8"></span></p>
<p>A free HOTP soft-token for J2ME based mobile phones and PDA's can be found on the <a href="http://www.dsssasia.com/token.html">Data Security Systems Solutions site</a> (or locally from <a href="/blobs/oathdsss.jar">here</a>, the manual (1.4MB) is <a href="/blobs/oathtoken_User_Guide_v1.0.pdf">here</a>). </p>
<p>On the server-side we use the OTP daemon from Tri-D systems (website no longer available). On that site you could find the source tarball for the HOTP daemon (<tt>otpd</tt>, now avalailable <a href="/blogs/otpd-3.0.0.tar.gz">locally</a>) which is prepared for the debian build tools (and rpm-based systems for that matter). Starting with version 3.0.0, the  local state manager daemon (<tt>lsmd</tt>) is integrated, but with earlier versions this should also be built.</p>
<h2>Building the OTP daemon</h2>
<p>Unpack the <tt>otpd</tt> tarball and change to the <tt>otpd-3.0.0</tt> directory. We need to make two minor changes, but the files lack the write-bit, so we can just make everything writable with "<strong><tt>chmod&nbsp;-R&nbsp;u+w&nbsp;.</tt></strong>" The two fixes that we apply are changing a small typo in the <tt>debian/changelog</tt> and add the install of the <tt>otppasswd</tt> manpage. Apply the following <a href="blobs/otpd.patch">patch</a>:</p>
<div class="igBar"><span id="ldiff-14"><a href="#" onclick="javascript:showPlainTxt('diff-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DIFF:</span>
<div id="diff-14">
<div class="diff">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--- otpd-<span style="color:#800000;">3</span>.<span style="color:#800000;">0</span>.<span style="color:#800000;">0</span>/debian/changelog <span style="color:#800000;">2008</span>-<span style="color:#800000;">01</span>-<span style="color:#800000;">31</span> <span style="color:#800000;">03</span>:<span style="color:#800000;">30</span>:<span style="color:#800000;">25</span>.<span style="color:#800000;">000000000</span> -<span style="color:#800000;">0500</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+++ otpd-<span style="color:#800000;">3</span>.<span style="color:#800000;">0</span>.<span style="color:#800000;">0</span>-<span style="color:#800000;">1</span>/debian/changelog&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;">2008</span>-<span style="color:#800000;">02</span>-<span style="color:#800000;">09</span> <span style="color:#800000;">19</span>:<span style="color:#800000;">45</span>:<span style="color:#800000;">20</span>.<span style="color:#800000;">000000000</span> -<span style="color:#800000;">0500</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">@@ -<span style="color:#800000;">2</span>,<span style="color:#800000;">7</span> +<span style="color:#800000;">2</span>,<span style="color:#800000;">7</span> @@</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;* New release</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #991111;">- -- Frank Cusack &lt;frank@tri-dsystems.com&gt;&nbsp; Thu Jan <span style="color:#800000;">31</span> <span style="color:#800000;">2008</span> <span style="color:#800000;">00</span>:<span style="color:#800000;">30</span>:<span style="color:#800000;">04</span> -<span style="color:#800000;">0700</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+ -- Frank Cusack &lt;frank@tri-dsystems.com&gt;&nbsp; Thu, <span style="color:#800000;">31</span> Jan <span style="color:#800000;">2008</span> <span style="color:#800000;">00</span>:<span style="color:#800000;">30</span>:<span style="color:#800000;">04</span> -<span style="color:#800000;">0700</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;otpd <span style="">&#40;</span><span style="color:#800000;">2</span>.<span style="color:#800000;">5</span>.<span style="color:#800000;">2</span>-<span style="color:#800000;">1</span><span style="">&#41;</span> dapper; urgency=low</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">diff -wurN otpd-<span style="color:#800000;">3</span>.<span style="color:#800000;">0</span>.<span style="color:#800000;">0</span>/Makefile.in otpd-<span style="color:#800000;">3</span>.<span style="color:#800000;">0</span>.<span style="color:#800000;">0</span>-<span style="color:#800000;">1</span>/Makefile.in</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #888822;">--- otpd-<span style="color:#800000;">3</span>.<span style="color:#800000;">0</span>.<span style="color:#800000;">0</span>/Makefile.in&nbsp; &nbsp; &nbsp; <span style="color:#800000;">2008</span>-<span style="color:#800000;">01</span>-<span style="color:#800000;">31</span> <span style="color:#800000;">01</span>:<span style="color:#800000;">32</span>:<span style="color:#800000;">33</span>.<span style="color:#800000;">000000000</span> -<span style="color:#800000;">0500</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+++ otpd-<span style="color:#800000;">3</span>.<span style="color:#800000;">0</span>.<span style="color:#800000;">0</span>-<span style="color:#800000;">1</span>/Makefile.in&nbsp; &nbsp; <span style="color:#800000;">2008</span>-<span style="color:#800000;">02</span>-<span style="color:#800000;">09</span> <span style="color:#800000;">19</span>:<span style="color:#800000;">49</span>:<span style="color:#800000;">38</span>.<span style="color:#800000;">000000000</span> -<span style="color:#800000;">0500</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">@@ -<span style="color:#800000;">73</span>,<span style="color:#800000;">6</span> +<span style="color:#800000;">73</span>,<span style="color:#800000;">8</span> @@</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;install-otpd: otpd</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="">&#40;</span>INSTALL<span style="">&#41;</span> -d $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>sbindir<span style="">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="">&#40;</span>INSTALL<span style="">&#41;</span> otpd $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>sbindir<span style="">&#41;</span>/otpd</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;$<span style="">&#40;</span>INSTALL<span style="">&#41;</span> -d $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>mandir<span style="">&#41;</span>/man5</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;$<span style="">&#40;</span>INSTALL_DATA<span style="">&#41;</span> otpd.<span style="color:#800000;">8</span> $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>mandir<span style="">&#41;</span>/man5/otppasswd.<span style="color:#800000;">5</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="">&#40;</span>INSTALL<span style="">&#41;</span> -d $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>mandir<span style="">&#41;</span>/man8</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="">&#40;</span>INSTALL_DATA<span style="">&#41;</span> otpd.<span style="color:#800000;">8</span> $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>mandir<span style="">&#41;</span>/man8/otpd.<span style="color:#800000;">8</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="">&#40;</span>INSTALL<span style="">&#41;</span> -d $<span style="">&#40;</span>DESTDIR<span style="">&#41;</span>$<span style="">&#40;</span>sysconfdir<span style="">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>After this, the package can be built with
<div class="igBar"><span id="lcode-15"><a href="#" onclick="javascript:showPlainTxt('code-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-15">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dpkg-buildpackage -rfakeroot -uc -us </div>
</li>
</ol>
</div>
</div>
</div>
<p> The pre-build package for the i386 architecture is available <a href="blobs/otpd_3.0.0-1_i386.deb">here</a>.</p>
<p>If all you want is to use the OTP daemon on a single server, you might install Tri-D's PAM module from their <a href="http://www.tri-dsystems.com/software/downloads.html">download page</a>. This too is prepared with the debian build files and a spec file for rpm-based systems. I opt for a central server with <tt>freeradius</tt> and <tt>otpd</tt> running and having a <a href="http://packages.debian.org/etch/libpam-radius-auth">RADIUS PAM module</a> on the separate systems.</p>
<h2>Building the <tt>freeradius</tt> package</h2>
<p>Version 3.0.0 of <tt>otpd</tt> requires at least version 1.1.7 of <tt>freeradius</tt>. The <tt>rlm_otp</tt> module is included, but the debian <tt>rules</tt> file excludes that module. So to build that we should get the source files from <em>testing</em>. Make sure your <tt>/etc/apt/sources.list</tt> contains a the line:<br />
<strong>
<pre>deb-src&nbsp;http://ftp.debian.nl/debian/&nbsp;testing&nbsp;main</pre>
<p></strong> then update the <em>apt</em> database and get the source files with
<div class="igBar"><span id="lcode-16"><a href="#" onclick="javascript:showPlainTxt('code-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-16">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">apt-get source freeradius </div>
</li>
</ol>
</div>
</div>
</div>
<p> Alternately, you can get the <tt>.orig.tar.gz</tt>, <tt>.diff</tt> and <tt>.dsc</tt> from the <a href="http://packages.debian.org/source/lenny/freeradius">debian packages repository</a> and unpack it with
<div class="igBar"><span id="lcode-17"><a href="#" onclick="javascript:showPlainTxt('code-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-17">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dpkg-source -x freeradius_1.<span style="color:#800000;color:#800000;">1</span>.<span style="color:#800000;color:#800000;">7</span>-<span style="color:#800000;color:#800000;">1</span>.<span style="">dsc</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p> Change to the <tt>freeradius-1.1.7</tt> directory and apply the following <a href="blobs/freeradius.patch">patch</a>:</p>
<div class="igBar"><span id="ldiff-18"><a href="#" onclick="javascript:showPlainTxt('diff-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DIFF:</span>
<div id="diff-18">
<div class="diff">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--- freeradius-<span style="color:#800000;">1</span>.<span style="color:#800000;">1</span>.<span style="color:#800000;">7</span>/debian/rules&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;">2008</span>-<span style="color:#800000;">01</span>-<span style="color:#800000;">31</span> <span style="color:#800000;">21</span>:<span style="color:#800000;">05</span>:<span style="color:#800000;">10</span>.<span style="color:#800000;">000000000</span> -<span style="color:#800000;">0500</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+++ freeradius-<span style="color:#800000;">1</span>.<span style="color:#800000;">1</span>.<span style="color:#800000;">7</span>-<span style="color:#800000;">1</span>/debian/rules&nbsp; &nbsp; &nbsp;<span style="color:#800000;">2008</span>-<span style="color:#800000;">02</span>-<span style="color:#800000;">09</span> <span style="color:#800000;">18</span>:<span style="color:#800000;">25</span>:<span style="color:#800000;">02</span>.<span style="color:#800000;">000000000</span> -<span style="color:#800000;">0500</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">@@ -<span style="color:#800000;">65</span>,<span style="color:#800000;">7</span> +<span style="color:#800000;">65</span>,<span style="color:#800000;">6</span> @@</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --without-rlm_eap_tls \</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --without-rlm_eap_ttls \</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --without-rlm_eap_peap \</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #991111;">-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--without-rlm_otp \</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --with-rlm_sql_postgresql_lib_dir=`pg_config --libdir` \</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --with-rlm_sql_postgresql_include_dir=`pg_config --includedir` \</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --without-openssl \ </div>
</li>
</ol>
</div>
</div>
</div>
<p>
and build the package. Aside from the package itself, various modules are built as separate packages . I only install the basic package (<tt><a href="blobs/freeradius_1.1.7-1_i386.deb">freeradius_1.1.7-1_i386.deb</a></tt>) since flat files are sufficient for my needs. </p>
<h2>Combining the two</h2>
<p>There was a minor problem I ran into when trying to have <tt>freeradius</tt> actually use the <tt>otpd</tt> for verifying the responses: file permissions. <tt>otpd</tt> has the option of running as a user other than <em>root</em> but then some files and directories have to be readable and/or writable by that user. If you install the package they are not. <tt>freeradius</tt> runs as user "<em>freerad</em>" by default, and this is the user that will access the socket file in <tt>/var/run/otpd</tt>. There are two solutions: have <tt>freeradius</tt> run as <em>root</em>, or have <tt>otpd</tt> run as <em>freerad</em> and change the file ownerships. I opted for the latter. For this reason I postponed configuring <tt>otpd</tt> until after I installed <tt>freeradius</tt>. I also ran into a small bug in the <tt>otpd</tt> package: the <tt>/etc/otpd.conf</tt> has an empty "state" section, which is considered a syntax error so the debian <tt>post-install</tt> script failed. I just unhashed the "mode = local" line and issued "<tt>dpkg&nbsp;--configure&nbsp;--pending</tt>" to make it happy.</p>
<h3>Configuring <tt>otpd</tt></h3>
<p>First, we stop both the <tt>freeradius</tt> and <tt>otpd</tt> daemons. Some files and directories need to be created and the correct permissions set. Execute the following commands:</p>
<div class="igBar"><span id="lcode-19"><a href="#" onclick="javascript:showPlainTxt('code-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-19">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir /etc/otpstate</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">touch /etc/otppasswd</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">chmod <span style="color:#800000;color:#800000;">600</span> /etc/otppasswd</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">chmod <span style="color:#800000;color:#800000;">700</span> /etc/otpstate</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">chown freerad:freerad /etc/otpd.<span style="">conf</span> /etc/otpstate/ /etc/otppasswd /var/run/otpd/ </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Generate a token on the J2ME client. The seedlength may be any value from 16 to 20 (I use the maximum), but the OTP length should be 6. This is because of a limitation of the "<tt>resynctool</tt>" that we will see later. After this the seed is displayed. Make sure you see the complete seed (i.e. opening and closing bracket should both be visible). I use a Windows Mobile based PDA and I need to use landscape mode to prevent the seed being truncated. The seed is displayed only once. Be cautious in copying it in the next step. After this, you are opted to place a PIN code on the token you just created. You might want to do that to have real 2-factor authentication.</p>
<p>Now create an entry in <tt>/etc/otppasswd</tt> with the following syntax:<br />
<strong>
<pre>user:hotp-d6:key</pre>
<p></strong> where "<em>user</em>" is the loginname of the user that will be authenticated via RADIUS, and "<em>key</em>" is the seed you just generated on the soft-token. So the line might look like this:</p>
<div class="igBar"><span id="lcode-20"><a href="#" onclick="javascript:showPlainTxt('code-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-20">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">foo:hotp-d6:3cd0f53cd4d94b08d249b1f861e655d774fcf0e5 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now we need a state file for this user. Calculate 2 consecutive passwords with the token, and use "<tt>resynctool</tt>" to generate state information like this:</p>
<div class="igBar"><span id="lcode-21"><a href="#" onclick="javascript:showPlainTxt('code-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-21">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">resynctool -<span style="color:#800000;color:#800000;">1</span> <span style="color:#800000;color:#800000;">990878</span> -<span style="color:#800000;color:#800000;">2</span> <span style="color:#800000;color:#800000;">457035</span> -u foo -k 3cd0f53cd4d94b08d249b1f861e655d774fcf0e5 </div>
</li>
</ol>
</div>
</div>
</div>
<p>
This results in output of the form:<br />
<strong>
<pre>5:foo:0000000000000002:::0:0:0:</pre>
<p></strong> Copy this into the file "<tt>/etc/otpstate/<em>user</em></tt>" where "<em>user</em>" is the same as the second field from the pasted text (in this case: "<em>foo</em>"). Make sure user <em>freerad</em> has read and write access to the file.</p>
<p>Now start the <tt>otpd</tt> daemon (<tt>/etc/init.d/otpd&nbsp;start</tt>) and test it with the "<tt>otpauth</tt>"  command:</p>
<div class="igBar"><span id="lcode-22"><a href="#" onclick="javascript:showPlainTxt('code-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-22">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">otpauth -u foo -p <span style="color:#800000;color:#800000;">123456</span> -s /var/run/otpd/socket </div>
</li>
</ol>
</div>
</div>
</div>
<p>
If you get the output "<strong><tt>5&nbsp;(service&nbsp;error)</tt></strong>", your configuration is still incorrect. Review <tt>/var/log/auth.log</tt> for clues what should be fixed. The error the we should expect here is "<strong><tt>3&nbsp;(authentication&nbsp;error)</tt></strong>". Try the same command with a newly generated password, and you should get "<strong><tt>0&nbsp;(ok)</tt></strong>".</p>
<h3>Configuring <tt>freeradius</tt></h3>
<p>We should enable the otp module in <tt>freeradius</tt>. That means removing the hash to include otp.conf and adding "otp" to both the authorize and authenticate modules of <tt>/etc/freeradius/radiusd.conf</tt> (or apply the following <a href="blobs/radiusd.conf.patch">patch</a>):</p>
<div class="igBar"><span id="ldiff-23"><a href="#" onclick="javascript:showPlainTxt('diff-23'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DIFF:</span>
<div id="diff-23">
<div class="diff">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--- /oldconf/freeradius/radiusd.conf&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#800000;">2008</span>-<span style="color:#800000;">02</span>-<span style="color:#800000;">10</span> <span style="color:#800000;">00</span>:<span style="color:#800000;">29</span>:<span style="color:#800000;">26</span>.<span style="color:#800000;">000000000</span> +<span style="color:#800000;">0100</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+++ /etc/freeradius/radiusd.conf&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#800000;">2008</span>-<span style="color:#800000;">02</span>-<span style="color:#800000;">11</span> <span style="color:#800000;">21</span>:<span style="color:#800000;">59</span>:<span style="color:#800000;">59</span>.<span style="color:#800000;">000000000</span> +<span style="color:#800000;">0100</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">@@ -<span style="color:#800000;">1730</span>,<span style="color:#800000;">7</span> +<span style="color:#800000;">1730</span>,<span style="color:#800000;">7</span> @@</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; # $INCLUDE&nbsp; $<span style="">&#123;</span>confdir<span style="">&#125;</span>/postgresqlippool.conf</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; # OTP token support.&nbsp; Not included by default.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #991111;">-&nbsp; &nbsp; &nbsp; &nbsp;# $INCLUDE&nbsp; $<span style="">&#123;</span>confdir<span style="">&#125;</span>/otp.conf</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;$INCLUDE&nbsp; $<span style="">&#123;</span>confdir<span style="">&#125;</span>/otp.conf</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">@@ -<span style="color:#800000;">1788</span>,<span style="color:#800000;">6</span> +<span style="color:#800000;">1788</span>,<span style="color:#800000;">8</span> @@</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;#&nbsp; need to setup hints for the remote radius server</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;authorize <span style="">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;otp</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; The preprocess module takes care of sanitizing some bizarre</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; attributes in the request, and turning them into attributes</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; which are more standard.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #440088;">@@ -<span style="color:#800000;">1906</span>,<span style="color:#800000;">6</span> +<span style="color:#800000;">1908</span>,<span style="color:#800000;">8</span> @@</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;#</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;authenticate <span style="">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;otp</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp;#</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; PAP authentication, when a back-end database listed</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; in the 'authorize' section supplies a password.&nbsp; The</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; password can be clear-text, or encrypted. </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now we can start the RADIUS daemon (<tt>/etc/init.d/freeradius&nbsp;start</tt>) and test if it works with the otp module:</p>
<div class="igBar"><span id="lcode-24"><a href="#" onclick="javascript:showPlainTxt('code-24'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-24">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">radtest foo <span style="color:#800000;color:#800000;">123456</span> localhost <span style="color:#800000;color:#800000;">10</span> testing123 </div>
</li>
</ol>
</div>
</div>
</div>
<p>
"testing123" is the default secret for localhost in <tt>/etc/freeradius/clients.conf</tt>. You should change that. We also don't use a NAS server so the NAS port (10) doesn't matter. We used a wrong password so the output looks like this:<br />
<strong>
<pre>Sending Access-Request of id 177 to 127.0.0.1 port 1812
        User-Name = "foo"
        User-Password = "123456"
        NAS-IP-Address = 255.255.255.255
        NAS-Port = 10
Re-sending Access-Request of id 177 to 127.0.0.1 port 1812
        User-Name = "foo"
        User-Password = "123456"
        NAS-IP-Address = 255.255.255.255
        NAS-Port = 10
rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=177, length=20</pre>
<p></strong></p>
<p>With a correct password we get the following output:<br />
<strong>
<pre>Sending Access-Request of id 172 to 127.0.0.1 port 1812
        User-Name = "foo"
        User-Password = "752230"
        NAS-IP-Address = 255.255.255.255
        NAS-Port = 10
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=172, length=20</pre>
<p></strong></p>
<p>Now we need to allow clients to connect to the RADIUS server. For that we edit <tt>/etc/freeradius/clients.conf</tt> and assign shared secrets to the various clients and/or networks that will be accessing the server. The pre-installed file has comments that should make the syntax clear. Reload the <tt>freeradius</tt> daemon after you finished editing <tt>clients.conf</tt>.</p>
<h3>Configuring the clients</h3>
<p>On each client, install libpam-radius-auth:</p>
<div class="igBar"><span id="lcode-25"><a href="#" onclick="javascript:showPlainTxt('code-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-25">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">apt-get install libpam-radius-auth </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Then edit <tt>/etc/pam_radius_auth.conf</tt> and add a line for the RADIUS server with the secret assigned to the specified client and a timeout value.</p>
<p>Now you need to edit those PAM files in <tt>/etc/pam.d</tt> where you want to allow RADIUS authentication. In debian, there is a single file (<tt>/etc/pam.d/common-auth</tt>) that is sourced by all modules that allow standard Unix authentication. I edited the file to allow both standard Unix authentication and RADIUS authentication. The file now reads:</p>
<div class="igBar"><span id="lcode-26"><a href="#" onclick="javascript:showPlainTxt('code-26'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-26">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">auth&nbsp; &nbsp; sufficient&nbsp; &nbsp; &nbsp; pam_unix.<span style="">so</span> nullok_secure</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">auth&nbsp; &nbsp; required&nbsp; &nbsp; &nbsp; &nbsp; pam_radius_auth.<span style="">so</span> try_first_pass </div>
</li>
</ol>
</div>
</div>
</div>
<p>
so I can choose my method of authentication depending on the circumstances.</p>
<h2>Caveat emptor</h2>
<p>First, the RADIUS daemon requires UDP port 1812 to be open. Make sure your firewall configuration allows that.<br />
Second, since the username used by the authentication module is specified on the RADIUS server, do note that there is a risk of clashing usernames. Either make sure that identical usernames on various clients belong to the same person or that different clients with the same usernames don't share access to the RADIUS server.<br />
Third, since the HOTP protocol is an event-based system, a brute force attack on a simple numerical 6-digit password is very possible! The reason for this is that wrong password probes or a timeslot don't invalidate the current password. Make sure that the service which you use HOTP for is not freely accessible from untrusted networks and/or use something like <a href="http://www.fail2ban.org/">fail2ban</a>. Also make sure that you do not generate many superfluous passwords with your token that are not communicated to the <tt>otpd</tt> daemon on the RADIUS server. The server will calculate 6 consecutive passwords and give up if none qualify. If this happens, you will should use "<tt>resynctool</tt>" to calculate a new content for the state file.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://fbq.hamal.nl/index.php/archives/8/feed</wfw:commentRss>
		</item>
		<item>
		<title>A Unix introductory document</title>
		<link>http://fbq.hamal.nl/index.php/archives/5</link>
		<comments>http://fbq.hamal.nl/index.php/archives/5#comments</comments>
		<pubDate>Tue, 20 Nov 2007 20:57:08 +0000</pubDate>
		<dc:creator>rsw</dc:creator>
		
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://fbq.hamal.nl/index.php/archives/5</guid>
		<description><![CDATA[Two years ago I created a Unix introductory document as part of a course manual for starting bio-informaticians. The document is written in OpenOffice.org (a requirement since I prefer LaTeX).
The document presents a general introduction to the Unix family of operating systems. It presents most examples using the Bourne shell (the shell that was delivered [...]]]></description>
			<content:encoded><![CDATA[<p>Two years ago I created a Unix introductory document as part of a course manual for starting bio-informaticians. The document is written in OpenOffice.org (a requirement since I prefer LaTeX).<br/><br />
The document presents a general introduction to the Unix family of operating systems. It presents most examples using the Bourne shell (the shell that was delivered with Unix Release 7 in 1979) but aims to be agnostic towards specific Unix brands.<br/><br />
I made the document available under the GNU Free Documentation License so feel free to copy and use it where applicable. You can download either the <a href="/blobs/unixstarter.odt">OpenOffice.org</a> format or the <a href="/blobs/unixstarter.pdf">PDF export</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fbq.hamal.nl/index.php/archives/5/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using LVM snapshots as backups</title>
		<link>http://fbq.hamal.nl/index.php/archives/4</link>
		<comments>http://fbq.hamal.nl/index.php/archives/4#comments</comments>
		<pubDate>Mon, 19 Nov 2007 18:26:46 +0000</pubDate>
		<dc:creator>rsw</dc:creator>
		
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://fbq.hamal.nl/index.php/archives/4</guid>
		<description><![CDATA[I've written a script to rotate multiple snapshots of a logical volume in Linux's LVM as a backup mechanism. The script is meant to be run via crond and (forcibly) removes the oldest snapshot and creates a new one. It can also monitor usage of the available snapshots. Call the script with the option --help [...]]]></description>
			<content:encoded><![CDATA[<p>I've written a script to rotate multiple snapshots of a logical volume in Linux's LVM as a backup mechanism. The script is meant to be run via crond and (forcibly) removes the oldest snapshot and creates a new one. It can also monitor usage of the available snapshots. Call the script with the option <b>--help</b> for the manpage. The script is available from <a href="/blobs/snaprotate.pl">this link</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fbq.hamal.nl/index.php/archives/4/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dipping my toes in the Xen pool</title>
		<link>http://fbq.hamal.nl/index.php/archives/3</link>
		<comments>http://fbq.hamal.nl/index.php/archives/3#comments</comments>
		<pubDate>Thu, 15 Nov 2007 21:42:07 +0000</pubDate>
		<dc:creator>rsw</dc:creator>
		
		<category><![CDATA[code]]></category>

		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://fbq.hamal.nl/index.php/archives/3</guid>
		<description><![CDATA[In my previous home setup I had two physical computers, one acting as my firewall and one acting as a DMZ system. Within the DMZ system there was no separation of functionalities and the need for slightly better hardware was starting to get apparent. Combine that with the need for consolidation to cut on electricity [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous home setup I had two physical computers, one acting as my firewall and one acting as a <a href="http://en.wikipedia.org/wiki/Demilitarized_zone_%28computing%29">DMZ</a> system. Within the DMZ system there was no separation of functionalities and the need for slightly better hardware was starting to get apparent. Combine that with the need for consolidation to cut on electricity costs and we enter the wonderful world of virtualization.<br/><span id="more-3"></span><br />
This is what the configuration looked like:<br />
<img src="/blobs/nettopo-old.png"><br/><br/></p>
<p>I first took a look at <a href="http://www.linux-vserver.org">vserver</a> but that was lacking a proper virtualization of the network. I like the idea of running a system on the host's kernel as a set of jailed processes, but since network security was the point of focus, the possibilities did not suffice. I read up on <a href="http://user-mode-linux.sourceforge.net/">UserMode Linux </a>and <a href="http://xen.org/">Xen</a> and settled for the latter because of better performance and better overall possibilities of separating the functionalities. The next image shows the final configuration (the VOIP part still needs to be done):<br />
<img src="/blobs/nettopo-new.png"><br/><br/></p>
<p>The purpose of this configuration is to create small and tightly locked DMZ systems that will host related network services and be disallowed to start any other network service. No internet initiated connection can get directly onto the firewall unless I temporarily allow that (see the later chapter on the Sesame web front-end). The DMZ systems are locked down with the <a href="http://packages.debian.org/etch/lcap">lcap</a> tool to prevent the possibility of adding modules to the system or changing critical files. The fact that the system disks are visible from the firewall (which is the Xen Dom0) enables periodical scans for malware that the DMZ hosts are completely unaware of.</p>
<h3>Hardware</h3>
<p>Not all that much actually. I have a dual P3/1GHz with 1.5 GiB memory, 2 160GB ATA disks in RAID1 all in a 4U rack-mountable that generates way too much noise. It does suffice nicely for the job, partly because of the efficiency of the Xen hypervisor on standard hardware.</p>
<h3>Xen configuration</h3>
<p>In this setup there was no need for multiple domU's to share the same virtual network, so I opted for routing i.o. bridging scripts in <strong>xend-config.sxp</strong>. I modified the vif script to assign a C-net to the various internal interfaces.  This is the "diff" with the vif-route script:<br/></p>
<div class="igBar"><span id="lcode-32"><a href="#" onclick="javascript:showPlainTxt('code-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-32">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">antares:/etc/xen% diff -wuN&nbsp; scripts/vif-<span style="color:#006600; font-weight:bold;">&#123;</span>route,custom<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">--- scripts/vif-route&nbsp; &nbsp;<span style="color:#800000;color:#800000;">2007</span>-<span style="color:#800000;color:#800000;">11</span>-<span style="color:#800000;color:#800000;">09</span> <span style="color:#800000;color:#800000;">14</span>:<span style="color:#800000;color:#800000;">58</span>:<span style="color:#800000;color:#800000;">32</span>.<span style="color:#800000;color:#800000;">000000000</span> +<span style="color:#800000;color:#800000;">0100</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+++ scripts/vif-custom&nbsp; <span style="color:#800000;color:#800000;">2007</span>-<span style="color:#800000;color:#800000;">11</span>-<span style="color:#800000;color:#800000;">09</span> <span style="color:#800000;color:#800000;">14</span>:<span style="color:#800000;color:#800000;">58</span>:<span style="color:#800000;color:#800000;">29</span>.<span style="color:#800000;color:#800000;">000000000</span> +<span style="color:#800000;color:#800000;">0100</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@@ -<span style="color:#800000;color:#800000;">23</span>,<span style="color:#800000;color:#800000;">11</span> +<span style="color:#800000;color:#800000;">23</span>,<span style="color:#800000;color:#800000;">17</span> @@</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;dir=$<span style="color:#006600; font-weight:bold;">&#40;</span>dirname <span style="color:#CC0000;">"$0"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;. <span style="color:#CC0000;">"$dir/vif-common.sh"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">-main_ip=$<span style="color:#006600; font-weight:bold;">&#40;</span>dom0_ip<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+if <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC0000;">"${ip}"</span> <span style="color:#006600; font-weight:bold;">&#93;</span> ; then</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; main_ip=<span style="color:#CC0000;">"${ip%.*}.24"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; netmask=<span style="color:#CC0000;">"255.255.255.0"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+else</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; main_ip=$<span style="color:#006600; font-weight:bold;">&#123;</span>main_ip:-$<span style="color:#006600; font-weight:bold;">&#40;</span>dom0_ip<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; netmask=<span style="color:#CC0000;">"255.255.255.255"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+fi</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;case <span style="color:#CC0000;">"$command"</span> in</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;online<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">-&nbsp; &nbsp; &nbsp; &nbsp; ifconfig $<span style="color:#006600; font-weight:bold;">&#123;</span>vif<span style="color:#006600; font-weight:bold;">&#125;</span> $<span style="color:#006600; font-weight:bold;">&#123;</span>main_ip<span style="color:#006600; font-weight:bold;">&#125;</span> netmask <span style="color:#800000;color:#800000;">255</span>.<span style="color:#800000;color:#800000;">255</span>.<span style="color:#800000;color:#800000;">255</span>.<span style="color:#800000;color:#800000;">255</span> up</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; &nbsp; &nbsp; &nbsp; ifconfig $<span style="color:#006600; font-weight:bold;">&#123;</span>vif<span style="color:#006600; font-weight:bold;">&#125;</span> $<span style="color:#006600; font-weight:bold;">&#123;</span>main_ip<span style="color:#006600; font-weight:bold;">&#125;</span> netmask $<span style="color:#006600; font-weight:bold;">&#123;</span>netmask<span style="color:#006600; font-weight:bold;">&#125;</span> up</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo <span style="color:#800000;color:#800000;">1</span>&gt;/proc/sys/net/ipv4/conf/$<span style="color:#006600; font-weight:bold;">&#123;</span>vif<span style="color:#006600; font-weight:bold;">&#125;</span>/proxy_arp</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ipcmd=<span style="color:#CC0000;">'add'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmdprefix=<span style="color:#CC0000;">''</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@@ -<span style="color:#800000;color:#800000;">39</span>,<span style="color:#800000;color:#800000;">13</span> +<span style="color:#800000;color:#800000;">45</span>,<span style="color:#800000;color:#800000;">13</span> @@</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;esac</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">-if <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC0000;">"${ip}"</span> <span style="color:#006600; font-weight:bold;">&#93;</span> ; then</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">-&nbsp; &nbsp; # If we<span style="color:#CC0000;">'ve been given a list of IP addresses, then add routes from dom0 to</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">-&nbsp; &nbsp; # the guest using those addresses.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">-&nbsp; &nbsp; for addr in ${ip} ; do</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">-&nbsp; &nbsp; &nbsp; ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">-&nbsp; &nbsp; done</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">-fi </span></div>
</li>
</ol>
</div>
</div>
</div>
<p><br/></p>
<p>The domU's each have two LVM volumes assigned as swap and as the main disk. Here's the configuration of elektra as an example:<br/></p>
<div class="igBar"><span id="lcode-33"><a href="#" onclick="javascript:showPlainTxt('code-33'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-33">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#&nbsp; Kernel + memory size</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">kernel&nbsp; = <span style="color:#CC0000;">'/boot/vmlinuz-2.6.18-4-xen-686'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ramdisk = <span style="color:#CC0000;">'/boot/initrd.img-2.6.18-4-xen-686'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">memory&nbsp; = <span style="color:#CC0000;">'256'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#&nbsp; Disk device<span style="color:#006600; font-weight:bold;">&#40;</span>s<span style="color:#006600; font-weight:bold;">&#41;</span>.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">root&nbsp; &nbsp; = <span style="color:#CC0000;">'/dev/sda1 ro'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">disk&nbsp; &nbsp; = <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC0000;">'phy:vg-ant/elektra-disk,sda1,w'</span>, <span style="color:#CC0000;">'phy:vg-ant/elektra-swap,sda2,w'</span> <span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#&nbsp; Hostname</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">name&nbsp; &nbsp; = <span style="color:#CC0000;">'elektra'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#&nbsp; Networking</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">vif&nbsp; = <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC0000;">'ip=xx.xx.xx.1, vifname=ueth0, mac=aa:26:26:f9:a4:f4'</span> <span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#&nbsp; Behaviour</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">on_poweroff = <span style="color:#CC0000;">'destroy'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">on_reboot&nbsp; &nbsp;= <span style="color:#CC0000;">'restart'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">on_crash&nbsp; &nbsp; = <span style="color:#CC0000;">'restart'</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p><br/></p>
<p>Each domU is "debootstrapped" with a minimal version of <a href="http://www.debian.org/News/2007/20070817">debian etch</a> and the packages specific for each domU are added. The firewall runs on dom0 (also debian etch). I actually planned to run the firewall in a domU but there is a hardcoded limit of 3 network devices per domU in xen 3.0.</p>
<h3>General concept of the firewall rules</h3>
<ul>
<li>The internal net is white-listed to allow a few protocols (like HTTP and FTP). A few trusted clients are completely white-listed.</li>
<li>The wireless net is <i>exclusively</i> allowed to start an <a href="http://openvpn.net/">OpenVPN</a> connection (this is actually the way I protect the wireless net, I don't do WEP or WPA). If an OpenVPN connection is established, that connection is treated like an internal net.</li>
<li>Internet-initiated connections that are allowed are send directly to the DMZ. With the exception of temporarily allowed connections (see the part on Sesame), no direct connections from the internet or the DMZ to the firewall are allowed (with the exception of UDP connections for OpenVPN sessions).</li>
<li>The DMZ hosts have varying rules (enforced via the FORWARD table):
<ul>
<li>All hosts can send NTP packets to the internet and send syslog packets to the firewall</li>
<li>The mailhost can receive IMAPS, and SMTP from anywhere and can send SMTP to the internet</li>
<li>The webhost can receive HTTP, HTTPS and DNS from anywhere and send DNS to the internet, and send a "sesame" string to the firewall.</li>
<li>The Proxy host can start any connection to the internet (for SOCKS purposes) and receive SOCKS connections from internal and VPN hosts and SQUID from internal, VPN and DMZ hosts.</li>
<li>The database server can receive mysql and LDAP connections from internal, VPN and DMZ hosts</li>
</li>
</ul>
<li>VOIP has not been configured yet, the interface is idle as of this writing.</li>
</ul>
<p>The firewall script can be found <a href="/blobs/fwrules">here</a>.<br/></p>
<h3>Sesame web-frontend</h3>
<p>There is a conflict of not allowing direct connections to the firewall and needing remote administration. I worked around this by creating a CGI page on the webserver that verifies a one-time password (<a href="http://www.inner.net/opie">OPIE</a>) and if the verification succeeds, send the originating IP address to a specific port on the firewall.</p>
<p>There are a few requirements on the webserver for this to work. At the very least, the <a href="http://packages.debian.org/etch/opie-server">opie-server</a> tools and the <a href="http://search.cpan.org/~eestabroo/Authen-OPIE-1.00/OPIE.pm">Authen::OPIE</a> perl module are required.  The latter is not packaged by default in debian, so this needs to be created with dh_perl (part of <a href="http://packages.debian.org/etch/debhelper">debhelper</a>). The opie libraries (package <a href="http://packages.debian.org/etch/libopie-dev">libopie-dev</a>) are required for making the package. My ready-built package is available <a href="/blobs/libauthen-opie-perl_1.00-1_i386.deb">here</a>. The CGI script also makes use of the <a href="http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm">HTML::Template</a> module (package <a href="http://packages.debian.org/etch/libhtml-template-perl">libhtml-template-perl</a>). I created a special user named <strong>opie</strong> and changes the ownership of <strong>/etc/opiekeys</strong> to that user. The CGI script runs at that user via the <a href="http://httpd.apache.org/docs/2.2/suexec.html">suexec</a> mechanism of Apache. Except the OPIE challenge response, the user can also override the IP address that should be added in the table. This is done to prevent the address of a proxy server to be added to the rules i.o. your own.  By default, the IP address of the connecting system is used.  This is the content of the CGI script:<br/></p>
<div class="igBar"><span id="lperl-34"><a href="#" onclick="javascript:showPlainTxt('perl-34'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PERL:</span>
<div id="perl-34">
<div class="perl">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl -w</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># vim:ai:filetype=perl:sta:sw=4:et:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># This CGI script will use the S/Key One-Time </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># Password mechanism for verification and if</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># sucessfull, will pass an IP address (default:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># $ENV{REMOTE_ADDR}) to a socket for inclusion</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># in a firewall rulebase</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> strict;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> CGI <a href="http://www.perldoc.com/perl5.6/pod/func/qw.html"><span style="color: #000066;">qw</span></a> /:standard/;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> CGI::<span style="color: #006600;">Carp</span> <span style="color: #ff0000;">'fatalsToBrowser'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> HTML::<span style="color: #006600;">Template</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> IO::<span style="color: #006600;">Socket</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> Authen::<span style="color: #006600;">OPIE</span> <a href="http://www.perldoc.com/perl5.6/pod/func/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>opie_challenge opie_verify<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># var declarations</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">our</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cgi</span>, <span style="color: #0000ff;">$template</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$opie_user</span>=<span style="color: #ff0000;">"opie"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$fwhost</span>=<span style="color: #ff0000;">"192.168.1.1"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$fwport</span>=<span style="color: #ff0000;">"54321"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$cgi</span>=CGI-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">header</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"login"</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"login"</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">"Open Sesame"</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># print challenge screen</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$opiechalstr</span>=&amp;opie_challenge<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$opie_user</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &amp;Barf2Browser<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Unknown OPIE user: $opie_user"</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$opiechalstr</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@opiechalarr</span>=<a href="http://www.perldoc.com/perl5.6/pod/func/split.html"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">&#40;</span>/ /, <span style="color: #0000ff;">$opiechalstr</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$opiechalarr</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#93;</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">"otp-md5"</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &amp;Barf2Browser<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Crazy challenge: $opiechalstr"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$response</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">textfield</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"response"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -value=&gt;<span style="color: #ff0000;">""</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -size=&gt;<span style="color: #cc66cc;color:#800000;">40</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ipaddr</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">textfield</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"ipaddr"</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -value=&gt;<span style="color: #ff0000;">""</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -size=&gt;<span style="color: #cc66cc;color:#800000;">16</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$submitbutton</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">submit</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"login"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -value=&gt;<span style="color: #ff0000;">"Open Sesame"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>=HTML::<span style="color: #006600;">Template</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span>filename =&gt;<span style="color: #ff0000;">"sesame.tmpl"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; path =&gt; <span style="color: #ff0000;">"/home/$opie_user/templates"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>chalbool =&gt; <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>formstart =&gt; <span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">start_form</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>sequence =&gt; <span style="color: #0000ff;">$opiechalarr</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>seed =&gt; <span style="color: #0000ff;">$opiechalarr</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>response =&gt; <span style="color: #0000ff;">$response</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>ipaddr =&gt; <span style="color: #0000ff;">$ipaddr</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>curraddr =&gt; <span style="color: #0000ff;">$ENV</span><span style="color: #66cc66;">&#123;</span>REMOTE_ADDR<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>submit =&gt; <span style="color: #0000ff;">$submitbutton</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">output</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Verify the challenge</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$response</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"response"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ipaddr</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"ipaddr"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &amp;Barf2Browser<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Empty response"</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$response</span> <span style="color: #b1b100;">or</span> <span style="color: #0000ff;">$response</span> eq <span style="color: #ff0000;">""</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$verifyval</span>=&amp;opie_verify<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$opie_user</span>,<span style="color: #0000ff;">$response</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$verifyval</span> <span style="color: #b1b100;">or</span> <span style="color: #0000ff;">$verifyval</span> != <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &amp;Barf2Browser<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"&lt;span class=red&gt;Athentication attempt FAILED&lt;/span&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># OTP challenge succeeded, send IP address to firewall</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$ipaddr</span>=<span style="color: #0000ff;">$ENV</span><span style="color: #66cc66;">&#123;</span>REMOTE_ADDR<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$ipaddr</span> <span style="color: #b1b100;">or</span> <span style="color: #0000ff;">$ipaddr</span> eq <span style="color: #ff0000;">""</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$socket</span>= <span style="color: #000000; font-weight: bold;">new</span> IO::<span style="color: #006600;">Socket</span>::<span style="color: #006600;">INET</span> <span style="color: #66cc66;">&#40;</span>PeerAddr =&gt; <span style="color: #0000ff;">$fwhost</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PeerPort =&gt; <span style="color: #0000ff;">$fwport</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Proto&nbsp; &nbsp; =&gt; <span style="color: #ff0000;">"tcp"</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Type&nbsp; &nbsp; &nbsp;=&gt; SOCK_STREAM<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> &amp;Barf2Browser<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Authentication succeeded but "</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #ff0000;">"&lt;span class=red&gt;network connection failed&lt;/span&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$socket</span> <span style="color: #ff0000;">"$ipaddr"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/close.html"><span style="color: #000066;">close</span></a> <span style="color: #0000ff;">$socket</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$submitbutton</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">submit</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"ok"</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -value=&gt;<span style="color: #ff0000;">"OK"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$template</span>=HTML::<span style="color: #006600;">Template</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span>filename =&gt;<span style="color: #ff0000;">"sesame.tmpl"</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path =&gt; <span style="color: #ff0000;">"/home/$opie_user/templates"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>msgbool =&gt; <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>formstart =&gt; <span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">start_form</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>msghdr =&gt; <span style="color: #ff0000;">"&lt;span class=blue&gt;Authentication succeeded!&lt;/span&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>message =&gt; <span style="color: #ff0000;">"Sent $ipaddr to the firewall"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>submit =&gt; <span style="color: #0000ff;">$submitbutton</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">output</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.perldoc.com/perl5.6/pod/func/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">sub</span> Barf2Browser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># output error</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>=<span style="color: #0000ff;">@_</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$submitbutton</span>=<span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">submit</span><span style="color: #66cc66;">&#40;</span>-name=&gt;<span style="color: #ff0000;">"ok"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -value=&gt;<span style="color: #ff0000;">"OK"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$string</span>=<span style="color: #ff0000;">"undefined"</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>=HTML::<span style="color: #006600;">Template</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span>filename =&gt;<span style="color: #ff0000;">"sesame.tmpl"</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; path =&gt; <span style="color: #ff0000;">"/home/$opie_user/templates"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>msgbool =&gt; <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>formstart =&gt; <span style="color: #0000ff;">$cgi</span>-&gt;<span style="color: #006600;">start_form</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>msghdr =&gt; <span style="color: #ff0000;">"Sesame error:"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>message =&gt; <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">param</span><span style="color: #66cc66;">&#40;</span>submit =&gt; <span style="color: #0000ff;">$submitbutton</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$template</span>-&gt;<span style="color: #006600;">output</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p><br/></p>
<p>The template file is very straight-forward:<br/></p>
<div class="igBar"><span id="lhtml-35"><a href="#" onclick="javascript:showPlainTxt('html-35'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-35">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00bbdd;">&lt;!DOCTYPE html</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html</span></a> xmlns=<span style="color: #ff0000;">"http://www.w3.org/1999/xhtml"</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">"en-US"</span> xml:<span style="color: #000066;">lang</span>=<span style="color: #ff0000;">"en-US"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">&lt;title&gt;</span></a></span>Sesame<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Content-Type"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"text/html; charset=iso-8859-1"</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">&lt;style</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/css"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">BODY {background-color: #b0c4ef; color: black}</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">A:link {color: #000040}</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">A:external {color: #000040}</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">A:active {color: #000040}</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">A:visited {color: #000040}</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SPAN.blue {color: #0000c0}</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SPAN.red {color: #c00000}</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"formstart"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">&lt;h1&gt;</span></a></span>Sesame Verifyer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;tmpl_if <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"chalbool"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">&lt;h3&gt;</span></a></span>Challenge:<span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"sequence"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> <span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"seed"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h3&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>Response:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"response"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">&lt;table&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Current IP address:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/tt.html"><span style="color: #000000; font-weight: bold;">&lt;tt&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span><span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"curraddr"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tt&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Optionally override with:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"ipaddr"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;">&lt;tmpl_else&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;">&lt;tmpl_if <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"msgbool"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">&lt;h3&gt;</span></a></span><span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=msghdr&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h3&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span><span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"message"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>/tmpl_if&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>/tmpl_if&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br</span></a>/<span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;">&lt;tmpl_var <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"submit"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p><br/></p>
<p>On the firewall end we have inetd listen to the specified port and send any incoming string to the script to add firewall rules. Because of the latter task this script needs to run as root. You can specify multiple tcp and/or udp ports in this script and for each of these, a firewall rule will be added to allow packets for that rule from the specified IP address, then the script will sleep for some time (default 5 minutes) and then all added rules are deleted again. Existing sessions stay active because of the stateful checks of iptables. The script:<br/></p>
<div class="igBar"><span id="lperl-36"><a href="#" onclick="javascript:showPlainTxt('perl-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PERL:</span>
<div id="perl-36">
<div class="perl">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># vim:ai:filetype=perl:sta:sw=4:et:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># This script will read a line from STDIN, expecting</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># expecting an IP address and will use that address</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># as a source for a firewall rule that temporarily</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># opens one or more ports in the INPUT chain</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># ports must be specified as /^[tu]\d+$/ (the first</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># character specifies the tcp or udp protocol</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> strict;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">use</span> Sys::<span style="color: #006600;">Syslog</span> <a href="http://www.perldoc.com/perl5.6/pod/func/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>:standard :macros<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">our</span> <span style="color: #0000ff;">@ports</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"t22"</span>,<span style="color: #ff0000;">"u5000"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$timeslot</span> = <span style="color: #cc66cc;color:#800000;">300</span>; <span style="color: #808080; font-style: italic;">#5 minutes</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$addr</span>=<span style="color: #009999;">&lt;STDIN&gt;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.perldoc.com/perl5.6/pod/func/chomp.html"><span style="color: #000066;">chomp</span></a> <span style="color: #0000ff;">$addr</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># check if we received a correct IP address</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$addr</span> !~ /^<span style="color: #66cc66;">&#40;</span>\d<span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;color:#800000;">1</span>,<span style="color: #cc66cc;color:#800000;">3</span><span style="color: #66cc66;">&#125;</span>\.<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color: #66cc66;">&#125;</span>\d<span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;color:#800000;">1</span>,<span style="color: #cc66cc;color:#800000;">3</span><span style="color: #66cc66;">&#125;</span>$/<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &amp;LogText<span style="color: #66cc66;">&#40;</span>LOG_WARNING, <span style="color: #ff0000;">"WARNING: someone tried something nasty!"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$port</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@ports</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &amp;IPTrule<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"-I"</span>,<span style="color: #0000ff;">$port</span>,<span style="color: #0000ff;">$addr</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.perldoc.com/perl5.6/pod/func/sleep.html"><span style="color: #000066;">sleep</span></a> <span style="color: #0000ff;">$timeslot</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$port</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@ports</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &amp;IPTrule<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"-D"</span>,<span style="color: #0000ff;">$port</span>,<span style="color: #0000ff;">$addr</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.perldoc.com/perl5.6/pod/func/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">sub</span> LogText<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$level</span>, <span style="color: #0000ff;">$text</span><span style="color: #66cc66;">&#41;</span>=<span style="color: #0000ff;">@_</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; openlog<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"sesamed"</span>,<span style="color: #ff0000;">"ndelay,pid"</span>,LOG_DAEMON<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; syslog<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$level</span>,<span style="color: #0000ff;">$text</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; closelog;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">sub</span> IPTrule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$act</span>,<span style="color: #0000ff;">$protoport</span>,<span style="color: #0000ff;">$addr</span><span style="color: #66cc66;">&#41;</span>=<span style="color: #0000ff;">@_</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$proto</span>,<span style="color: #0000ff;">$port</span><span style="color: #66cc66;">&#41;</span>=<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$protoport</span> =~ /^<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>tu<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>\d+<span style="color: #66cc66;">&#41;</span>$/<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$port</span>=$<span style="color: #cc66cc;color:#800000;">2</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$proto</span> = <span style="color: #66cc66;">&#40;</span>$<span style="color: #cc66cc;color:#800000;">1</span> eq <span style="color: #ff0000;">"t"</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">"tcp"</span> : <span style="color: #ff0000;">"udp"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <a href="http://www.perldoc.com/perl5.6/pod/func/defined.html"><span style="color: #000066;">defined</span></a> <span style="color: #0000ff;">$proto</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &amp;LogText<span style="color: #66cc66;">&#40;</span>LOG_NOTICE, <span style="color: #ff0000;">"BUG: wrong protoport specified"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/return.html"><span style="color: #000066;">return</span></a>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@cmdline</span>=<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"/sbin/iptables"</span>,<span style="color: #0000ff;">$act</span>,<span style="color: #ff0000;">"INPUT"</span>,<span style="color: #ff0000;">"-p"</span>,<span style="color: #0000ff;">$proto</span>,<span style="color: #ff0000;">"--dport"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@cmdline</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$port</span>,<span style="color: #ff0000;">"-s"</span>,<span style="color: #0000ff;">$addr</span>,<span style="color: #ff0000;">"-j"</span>,<span style="color: #ff0000;">"ACCEPT"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &amp;LogText<span style="color: #66cc66;">&#40;</span>LOG_INFO, <a href="http://www.perldoc.com/perl5.6/pod/func/join.html"><span style="color: #000066;">join</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">" "</span>, <span style="color: #0000ff;">@cmdline</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.perldoc.com/perl5.6/pod/func/system.html"><span style="color: #000066;">system</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@cmdline</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p><br/></p>
<h4>Security issues</h4>
<p>The <a href="http://www.faqs.org/rfcs/rfc2289.html">S/Key system</a> (which OPIE implements) is not terribly secure. It uses <a href="http://en.wikipedia.org/wiki/MD5">MD5 hashes</a> on top of each other and then splits the hash in two 64-bit parts and "xor"s the two parts together. Cracking the system means doing a preimage attack on 64 bits with the MD5 algorithm. If you are limited to brute-force, a modern server (2 quad-core CPUs with 5kMIPS per core) runs for 2500 years. This may sound as much but really isn't. Last I heard there was a less-than brute force system available for finding MD5 collisions (I'm not talking about a birthday attack here, just the algorithm) and using multiple parallel systems which could bring down the time quite a bit.</p>
<p>Personally, I don't think we need to resort to any paranoia in this particular case. Even if a hash collision is found, the only thing a black hat can gain is opening up ports where another level of authentication waits (or should wait).  The security can also be enhanced by having the HTTP traffic encrypted by SSL to prevent a black hat of sniffing the net. I wouldn't use S/Key for logging into a system on its own, but combined with a second authentication vector (e.g. using a challenge response sent via SMS to a cell phone) would create a nice 2-vector authentication mechanism (handy for situations like Internet Cafe's where you run the risk of being subjected to a key-logger).</p>
]]></content:encoded>
			<wfw:commentRss>http://fbq.hamal.nl/index.php/archives/3/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
