<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Piece of Unix Hints &#187; NetBSD</title>
	<atom:link href="http://hints.jeb.be/category/netbsd/feed/" rel="self" type="application/rss+xml" />
	<link>http://hints.jeb.be</link>
	<description>hints.jeb.be</description>
	<lastBuildDate>Fri, 04 Dec 2009 20:35:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Booting NetBSD on Mac (iMac DV+)</title>
		<link>http://hints.jeb.be/2008/12/17/booting-netbsd-on-mac-imac-dv/</link>
		<comments>http://hints.jeb.be/2008/12/17/booting-netbsd-on-mac-imac-dv/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:48:40 +0000</pubDate>
		<dc:creator>Jeb</dc:creator>
				<category><![CDATA[NetBSD]]></category>
		<category><![CDATA[Boot]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://hints.jeb.be/?p=34</guid>
		<description><![CDATA[This is what to use to boot NetBSD MacPPC CD on an iMac DV+ (at least): boot cd:,ofwboot.xcf netbsd.macppc or boot cd:0,ofwboot.xcf netbsd.macppc You may not need to put netbsd.macppc depending of the CD To boot on HD try this: boot cd:,ofwboot.xcf hd:/nebtsd or boot cd:,ofwboot.xcf hd:13/nebtsd Where 13 is the number of the netbsd [...]]]></description>
			<content:encoded><![CDATA[<p>This is what to use to boot NetBSD MacPPC CD on an iMac DV+ (at least):</p>
<blockquote><p><code>boot cd:,ofwboot.xcf netbsd.macppc</code></p></blockquote>
<p>or</p>
<blockquote><p><code>boot cd:0,ofwboot.xcf netbsd.macppc</code></p></blockquote>
<p>You may not need to put netbsd.macppc depending of the CD</p>
<hr />
<p>To boot on HD try this:</p>
<blockquote><p><code>boot cd:,ofwboot.xcf hd:/nebtsd</code></p></blockquote>
<p>or</p>
<blockquote><p><code>boot cd:,ofwboot.xcf hd:13/nebtsd</code></p></blockquote>
<p>Where 13 is the number of the netbsd partition (usualy near 13)</p>
]]></content:encoded>
			<wfw:commentRss>http://hints.jeb.be/2008/12/17/booting-netbsd-on-mac-imac-dv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add IPF rule automatically from log files</title>
		<link>http://hints.jeb.be/2008/12/17/add-ipf-rule-automatically-from-log-files/</link>
		<comments>http://hints.jeb.be/2008/12/17/add-ipf-rule-automatically-from-log-files/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:30:14 +0000</pubDate>
		<dc:creator>Jeb</dc:creator>
				<category><![CDATA[NetBSD]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[IPF]]></category>
		<category><![CDATA[Log]]></category>

		<guid isPermaLink="false">http://hints.jeb.be/?p=16</guid>
		<description><![CDATA[Here is a very simple command to add a rule to your firewall (IPF in my example) when you match something in a log file (apache in this case) for item in `tail -n 150 access_log &#124; grep "c+dir" &#124; awk '{print $1}'` ; do echo "block in quick on ne0 proto ip from $item [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a very simple command to add a rule to your firewall (IPF in my example) when you match something in a log file (apache in this case)</p>
<div class="code">
<pre>for item in `tail -n 150 access_log | grep "c+dir" | awk '{print $1}'` ;
  do echo "block in quick on ne0 proto ip from $item to any" &gt;&gt; /etc/ipf.conf ;
done</pre>
</div>
<p>This read 150 last line of access_log using tail, use grep as matching operator, use awk to catch ip (note that you could do /c+dir/{print $1} in awk to don&#8217;t use grep) then add a blocking rule in /etc/ipf.conf</p>
<p>You may want to add a comment to the end of the blocking rule saying why it was blocked.</p>
<p>Don&#8217;t forget to reload the firewall, /sbin/ipf -Fa -f /etc/ipf.conf for ipf, from time to time with cron to active the rule.</p>
<p>You may reload the firewall each time with</p>
<div class="code">
<pre>for item in `tail -n 150 access_log | grep "c+dir" | awk '{print $1}'` ;
  do echo "block in quick on ne0 proto ip from $item to any" &gt;&gt; /etc/ipf.conf; /sbin/ipf -Fa -f /etc/ipf.conf ;
done</pre>
</div>
<p>This system has 2 problems:</p>
<ul>
<li>You must run tail from cron as -f can&#8217;t work with the for statement.</li>
<li>Rules are added at the end of ipf.conf, this is very useless if you have <tt>pass in quick proto ip any to any port 80</tt> before.</li>
</ul>
<p>So, here is a Perl script that will do a better job.</p>
<div class="code">
<pre>my $IPF_FILE="/etc/ipf.conf";
my $TMP_FILE="/tmp/ipf.new.rules";
my %h;
open (FILE,"tail -fn 1 /usr/local/apache/logs/access_log|") || die "can't open FILE: $!";
 while (&lt;FILE&gt;) {
  if ($_ =~ /^(.*)s-s-.*c+dir/) {
   if(exists($h{"$1"})) { $h{"$1"}++ }
   else {
    $h{"$1"} = 1;
    open(IPF, "&lt; $IPF_FILE") or die "can't open $IPF_FILE: $!";
    open(TMP, "&gt; $TMP_FILE") or die "can't open $TMP_FILE: $!";
    print TMP "block in log quick on ne0 from $1 to anyn" or die "can't write to $TMP_FILE: $!";
    while (&lt;IPF&gt;) { (print TMP $_) or die "can't write to $TMP_FILE: $!"; }
    close(IPF)                  or die "can't close $IPF_FILE: $!";
    close(TMP)                  or die "can't close $TMP_FILE: $!";
    rename("$TMP_FILE", "$IPF_FILE") or die "can't rename $TMP_FILE to $IPF_FILE: $!";
    system("ipf -Fa -f $IPF_FILE");
   }
  }
 }
close (FILE);
}</pre>
</div>
<p>Incrementation of $h{&#8220;$1&#8243;} is totally useless here but you may use it for something (like waiting more than one attemp of the IP before adding it to IPF). $h is used to don&#8217;t firewall two time the same IP.</p>
<p>You may think that $h is not usefull because as we have blocked the IP, we will not get any new request from it. Not really</p>
<ul>
<li>Tail is not working really in live, it check time to time for new line then print them, so between the first request of the IP and the reload of the firwall, you may have more than one request (don&#8217;t forget that reloading ipf take time also);</li>
<li>My IPF rule is very strict, you may only block port 80, so you can still get request on port 443, or things like that.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hints.jeb.be/2008/12/17/add-ipf-rule-automatically-from-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reminder to add an user on NetBSD</title>
		<link>http://hints.jeb.be/2008/12/17/reminder-to-add-an-user-on-netbsd/</link>
		<comments>http://hints.jeb.be/2008/12/17/reminder-to-add-an-user-on-netbsd/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:21:48 +0000</pubDate>
		<dc:creator>Jeb</dc:creator>
				<category><![CDATA[NetBSD]]></category>
		<category><![CDATA[User Management]]></category>

		<guid isPermaLink="false">http://hints.jeb.be/?p=9</guid>
		<description><![CDATA[This is just a little reminder about adding user on NetBSD. The basic way is to use : # useradd -G &#60;group_2&#62; -b /home -g &#60;group_1&#62; -k /etc/skel -m -s /usr/pkg/bin/bash -v &#60;user&#62; This add &#60;user&#62; in primary group &#60;group_1&#62; and secondary group &#60;group_2&#62;, create is home in /home/&#60;user&#62; using /etc/skel as skeleton. It also [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a little reminder about adding user on NetBSD.<br />
The basic way is to use :
</p>
<pre class="wiki"># useradd -G &lt;group_2&gt; -b /home -g &lt;group_1&gt; -k /etc/skel -m -s /usr/pkg/bin/bash -v &lt;user&gt;
</pre>
<p>
This add &lt;user&gt; in primary group &lt;group_1&gt; and secondary group &lt;group_2&gt;, create is home in /home/&lt;user&gt; using /etc/skel as skeleton. It also set the shell to bash.
</p>
<p>
N.B: in /etc/passwd you will see the primary group of each user.<br />In /etc/group you will find, for each group, the list of user that are inside the group as secondary group.<br />
N.B: You can also use id command to see all group of an user, it will display uid, gid (primary group) then all secondary group</p>
]]></content:encoded>
			<wfw:commentRss>http://hints.jeb.be/2008/12/17/reminder-to-add-an-user-on-netbsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Time Password authentication system</title>
		<link>http://hints.jeb.be/2008/12/17/one-time-password-authentication-system/</link>
		<comments>http://hints.jeb.be/2008/12/17/one-time-password-authentication-system/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:18:25 +0000</pubDate>
		<dc:creator>Jeb</dc:creator>
				<category><![CDATA[NetBSD]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[OTP]]></category>

		<guid isPermaLink="false">http://hints.jeb.be/?p=6</guid>
		<description><![CDATA[S/key is an one time password authentication (OTP) system that prevent you from sending password in clear. It&#8217;s especially useful with system like telnet. It&#8217;s quite easy to setup on NetBSD. To start, run # skeyinit -s &#60;user&#62; [Adding user] You need the 6 english words generated from the "skey" command. Enter sequence count from [...]]]></description>
			<content:encoded><![CDATA[<p>S/key is an one time password authentication (OTP) system that prevent you from sending password in clear.<br /> It&#8217;s especially useful with system like telnet.
</p>
<p>
It&#8217;s quite easy to setup on NetBSD. To start, run
</p>
<pre class="wiki"># skeyinit -s &lt;user&gt;
[Adding user]
You need the 6 english words generated from the "skey" command.
Enter sequence count from 1 to 10000: Enter anything you want
Enter new seed [default NetB14423]: Just press return or enter something else
otp-md4 &lt;sequence count&gt; &lt;seed&gt;
s/key access password: &lt;Follow instruction bellow&gt;
</pre>
<p>
To get the s/key access password, you have to run the following command but <strong>be careful to do not run it on the remote host through telnet</strong>, <span class="underline">run it locally</span> !
</p>
<pre class="wiki"># skey &lt;sequence count you entered for skeyinit&gt; &lt;seed you use in skeyinit&gt;
</pre>
<p>
This will ask you for a password (use a secure one) and give you 6 english word, use them to complete the &#8220;s/key access password:&#8221; question.
</p>
<p>
Your S/Key authentification is ready !
</p>
<hr />
<p>
Next time you do a telnet connexion to the host you will get this prompt
</p>
<pre class="wiki">login: &lt;put your username&gt;
Password [otp-md4 &lt;random number&gt; &lt;seed you use in skeyinit&gt;]:
</pre>
<p>
To know the 6 english word password to use, you have to run the following command (on you local computer for example)
</p>
<pre class="wiki"># skey &lt;random number&gt; &lt;seed you use in skeyinit&gt;
</pre>
<p>
In fact the random number will be incremented by one each time you log in. You can easily generate (in advance) all 6 english word password for number X to Z, with the following command (another time, run this locally) :
</p>
<pre class="wiki">skey -n (Z-X) Z &lt;seed you use in skeyinit&gt;
</pre>
<p>
Z-X is the number of password to generate. Z mean the last generated password is for random number Z
</p>
<p>
N.B: <strong>You clear password will still work if you use it.</strong>
</p>
<hr />
<p>
Related link: <a class="ext-link" href="http://en.wikipedia.org/wiki/S/Key" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/S/Key?referer=');"><span class="icon">S/Key on Wikipedia</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hints.jeb.be/2008/12/17/one-time-password-authentication-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
