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

<channel>
	<title>Crowdway</title>
	<atom:link href="http://blog.crowdway.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crowdway.com</link>
	<description>Snippets of madness with a dash of salt</description>
	<pubDate>Wed, 16 Sep 2009 15:48:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Expanding a leading tilde in C/C++</title>
		<link>http://blog.crowdway.com/2009/09/16/expanding-a-leading-tilde-in-cc/</link>
		<comments>http://blog.crowdway.com/2009/09/16/expanding-a-leading-tilde-in-cc/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 13:33:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Code Poetry]]></category>

		<category><![CDATA[How To]]></category>

		<category><![CDATA[C/C++]]></category>

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

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

		<guid isPermaLink="false">http://blog.crowdway.com/?p=289</guid>
		<description><![CDATA[If you&#8217;re writing an app that accepts a path to a filename as user-input or in config-files, you&#8217;ll have to be able to parse the famous leading tilde and expand it to the correct home directory of the correct user. For example, if I enter &#8220;~/.vimrc&#8221; it needs to be expanded to the file in [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re writing an app that accepts a path to a filename as user-input or in config-files, you&#8217;ll have to be able to parse the famous leading tilde and expand it to the correct home directory of the correct user. For example, if I enter <strong>&#8220;~/.vimrc&#8221;</strong> it needs to be expanded to the file in my userdir <strong>&#8220;/home/david/.vimrc&#8221;</strong> before you can do anything with it. You can use &#8220;word expand&#8221; or wordexp to accomplish this.</p>
<p>Here&#8217;s a sample application showing how:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;wordexp.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> argv<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	wordexp_t exp_result<span style="color: #008080;">;</span>
	wordexp<span style="color: #008000;">&#40;</span>arv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>exp_result, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span>exp_result.<span style="color: #007788;">we_wordv</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>That should pretty much tell you everything you need to know. Here are some of the results output by this app:</p>
<p><strong>~/.vimrc</strong> becomes <strong>/home/david/.vimrc</strong><br />
<strong>.vimrc</strong> becomes <strong>.vimrc</strong><br />
<strong>~.vimrc</strong> becomes <strong>~.vimrc</strong><br />
<strong>~blacky/.vimrc</strong> becomes <strong>/home/admin/blacky/.vimrc</strong>  (blacky&#8217;s homedir is /home/admin/blacky)</p>
<p>As you can see, it handles pretty much every situation correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/09/16/expanding-a-leading-tilde-in-cc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Gmail Carbon Copy</title>
		<link>http://blog.crowdway.com/2009/08/26/gmail-carbon-copy/</link>
		<comments>http://blog.crowdway.com/2009/08/26/gmail-carbon-copy/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 12:38:04 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Code Poetry]]></category>

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

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

		<guid isPermaLink="false">http://blog.crowdway.com/?p=293</guid>
		<description><![CDATA[Today I&#8217;d like to introduce Gmail Carbon Copy, an application I&#8217;ve coded during the last couple of months. The latest version is stable and works, so I&#8217;m deeming it fit for public consumption.
Gmail Carbon Copy, or Gmailcc simply creates a back-up of your Gmail. It differs from existing alternatives because of two clever tricks: each [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;d like to introduce <strong><a href="http://gmailcc.crowdway.com">Gmail Carbon Copy</a></strong>, an application I&#8217;ve coded during the last couple of months. The latest version is stable and works, so I&#8217;m deeming it fit for public consumption.</p>
<p>Gmail Carbon Copy, or Gmailcc simply creates a back-up of your Gmail. It differs from <a href="http://www.gmail-backup.com/">existing</a> <a href="http://www.mattcutts.com/blog/backup-gmail-in-linux-with-getmail/">alternatives</a> because of two clever tricks: each mail is downloaded <em>only once</em> instead of once for every label while still saving the labels, and they&#8217;re stored in an actually usable, <em>sparse Maildir</em> format.</p>
<p>Gmail&#8217;s IMAP implementation is unique in that it maps labels to folders. The same mail will appear in different folders for every label attached to it. Regular IMAP clients like Thunderbird or getmail think each copy of the mail in a different folder is a new mail, and will download it again, even though it might just be a copy of a mail it downloaded earlier. Gmailcc detects &#8220;doubles&#8221; and will download each mail just once. Backups, especially the initial one, will finish much faster because of this and will take far less traffic.</p>
<p>Saving it in a usable Maildir format has the advantage that any regular mailserver like Courier can access your backup. It&#8217;s very practical: I&#8217;m using Gmailcc and Roundcube to access my mails on a webinterface if Gmail is down. It&#8217;s sparse because every mail is saved only once, while for every label a sizeless link is created instead of a true copy. This minimizes the space used to store the backup.</p>
<p>There are still some <a href="http://code.crowdway.com/projects/gmailcc/issues">issues</a> but it shouldn&#8217;t make your PC explode or kill your Gmail account. If you encounter bugs or would like to have features added, I encourage you to <a href="http://code.crowdway.com/account/register">sign up</a> and add a ticket.</p>
<p>Gmail Carbon Copy is open source (C++), licensed under the MIT license and works only on Linux at this time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/08/26/gmail-carbon-copy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Munin and Apache: Can&#8217;t locate object method</title>
		<link>http://blog.crowdway.com/2009/07/08/munin-and-apache-cant-locate-object-method/</link>
		<comments>http://blog.crowdway.com/2009/07/08/munin-and-apache-cant-locate-object-method/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 15:10:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Linux]]></category>

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

		<guid isPermaLink="false">http://blog.crowdway.com/?p=254</guid>
		<description><![CDATA[If you&#8217;re using Munin to track statistics on your server and you&#8217;re trying to use any of the Apache plugins, you might have some trouble getting it working. If Munin won&#8217;t display any statistics on Apache, and the munin-node.log logfile is filled with lines like these:
Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_processes line [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using <a href="http://munin.projects.linpro.no/">Munin</a> to track statistics on your server and you&#8217;re trying to use any of the Apache plugins, you might have some trouble getting it working. If Munin won&#8217;t display any statistics on Apache, and the munin-node.log logfile is filled with lines like these:</p>
<pre><code>Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_processes line 152.
2009/07/08-17:00:02 Plugin "apache_processes" exited with status 512. ----
Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_accesses line 130.
2009/07/08-17:00:03 Plugin "apache_accesses" exited with status 512. ----
Can't locate object method "new" via package "LWP::UserAgent"
at /etc/munin/plugins/apache_volume line 130.
2009/07/08-17:00:03 Plugin "apache_volume" exited with status 512. ----</code></pre>
<p>then the solution is to install the package <strong>libwww-perl</strong> which includes the required <em>LWP:UserAgent</em> package.</p>
<p>Make sure to restart munin-node afterwards:</p>
<pre><code>$ /etc/init.d/munin-node restart</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/07/08/munin-and-apache-cant-locate-object-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>On the Redundancy of the Password Inputbox</title>
		<link>http://blog.crowdway.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/</link>
		<comments>http://blog.crowdway.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/#comments</comments>
		<pubDate>Thu, 28 May 2009 18:21:24 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=216</guid>
		<description><![CDATA[We all know and love the password inputbox. It hides all the characters you type with stars, and encrypts the contents stored in memory. It&#8217;s about the only constant in the potpourri of user registration pages. It&#8217;s the part no site ever gets wrong â€” use a password inputbox when asking the user for their [...]]]></description>
			<content:encoded><![CDATA[<p>We all know and love the password inputbox. It hides all the characters you type with stars, and encrypts the contents stored in memory. It&#8217;s about the only constant in the potpourri of user registration pages. It&#8217;s the part no site ever gets wrong â€” use a password inputbox when asking the user for their password. But what function does it serve? It&#8217;s simple:</p>
<p><strong>To hide your password from bystanders</strong>, innocent or otherwise.</p>
<p>That&#8217;s the one and only reason why we obscure the characters with stars. That co-worker sitting next to you, or the coffee-lady casually walking by, if it weren&#8217;t for the trusty password field they could have spotted and accidentally memorized your password while you&#8217;re entering it. It&#8217;s a great solution to a very real problem.</p>
<div id="attachment_238" class="wp-caption alignright" style="width: 210px"><img class="size-full wp-image-238" title="Redundancy @ WordPress.com" src="http://blog.crowdway.com/wp-content/uploads/2009/05/password-screen-wordpresscom1.png" alt="Redundancy @ WordPress.com" width="200" height="180" /><p class="wp-caption-text">Redundancy at WordPress.com</p></div>
<p>All this is common knowledge, of course. So why am I repeating it? Because surprisingly, for most sites it&#8217;s redundant. All the websites out there that send your password by email, or show it when you&#8217;ve clicked the &#8220;activate account&#8221;-link are nullifying the sole reason of existence for the password field.</p>
<p>Since the user&#8217;s password is displayed on the screen in an e-mail, that coffee-lady can look at the password anyway. Worse: oft-times the user doesn&#8217;t know what&#8217;s coming when opening the mail or clicking the activation-link. He can&#8217;t pre-emptively check if anyone is in his vicinity before unknowingly revealing the password on his screen, which <em>is</em> an option when entering the password in a regular inputbox.</p>
<p>The conclusion is simple: if you think you can send the user his password by mail or show it in clear text on his profile, stop using the password inputbox. <strong>It won&#8217;t increase the level of security</strong>. By then, it only serves to annoy the user who has to enter his password blindly, twice even, possibly making an error along the way and having to try again. It&#8217;ll also tell the user the real degree of security you&#8217;re using, instead of fooling him with the asterisks.</p>
<p><span style="font-size: smaller">(The real conclusion is of course to never show the password in cleartext, anywhere)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/05/28/on-the-redundancy-of-the-password-inputbox/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hide Data in Bad Blocks</title>
		<link>http://blog.crowdway.com/2009/04/22/hide-data-in-bad-blocks/</link>
		<comments>http://blog.crowdway.com/2009/04/22/hide-data-in-bad-blocks/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 15:51:51 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[How To]]></category>

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

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

		<category><![CDATA[Hide Data]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=81</guid>
		<description><![CDATA[This is part 3 in a series on how to hide your data.
First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell thereâ€™s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is part 3 in a <a href="/tag/hide-data/">series on how to hide your data</a>.</em></p>
<p><em>First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell thereâ€™s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. <a href="http://www.truecrypt.org/">TrueCrypt</a> is an excellent way to do this.</em></p>
<h3>Introduction</h3>
<p>When a sector on a disk gets damaged, it becomes unusable.Â  Modern disks have spare sectors that are used to replace these bad sectors, so they&#8217;re handled and fixed automatically. If you&#8217;re young enough, you might never have witnessed these bad sectors, because modern hardware handles them transparently.</p>
<p>When the disk runs out of spare sectors, or never had any in the first place (like 3.5&#8243; disks, or very old hard disks), the filesystem is the second line of defense. Inside the filesystem a list of known bad blocksâ€”<em>blocks on bad sectors</em>â€”is stored. The filesystem takes care not to use these blocks and just skips them.</p>
<p>We can&#8217;t force the disk to remap certain blocks to spare sectors, but we <em>can</em> tell the filesystem which blocks have (supposedly) gone bad. If the blocks aren&#8217;t really damaged, any data we put there will never be touched, because the filesystem thinks it&#8217;s garbage anyway. That, is exactly what we&#8217;re going to do.</p>
<h3>Practical</h3>
<p>To keep it simple and fast, we&#8217;ll hide a whole partition inside a burst of bad blocks. The partition we&#8217;ll create has to be small and reside somewhere in the middle of the disk. We can&#8217;t put the partition at the beginning or the end of the disk, because most likely the filesystem requires an intact header at the start and end of the partition.</p>
<p><img class="aligncenter size-full wp-image-182" title="Partition inside Bad Blocks" src="http://blog.crowdway.com/wp-content/uploads/2009/04/bad_blocks.png" alt="Partition inside Bad Blocks" width="490" height="280" /></p>
<p>The partition has to be small enough to be able to fit inside the non-secret partition while not arousing suspicion. Some operating systems mark bad blocks as used blocks, which means if we put a 100MB partition inside bad blocks, the &#8220;parent&#8221; filesystem will always have at least 100MB in use. This could arouse suspicion when there aren&#8217;t any files on it.</p>
<p>I&#8217;ll be using my trusty 256MB Compactflash card for this, which is excellent for illustratory purposes.</p>
<p>Here&#8217;s what sfdisk has to say about it:</p>
<pre><code>$ sudo sfdisk -l /dev/sde

Disk /dev/sde: 1009 cylinders, 9 heads, 56 sectors/track
Units = cylinders of 258048 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sde1          0       -       0          0    0  Empty
/dev/sde2          0       -       0          0    0  Empty
/dev/sde3          0       -       0          0    0  Empty
/dev/sde4          0       -       0          0    0  Empty
</code></pre>
<p>We can see the card is comprised of 1009 cylinders. I want to create a partition of about 20MB, which is about 82 cylinders on this disk (see the second line of <em>sfdisk -l</em>). Because we can&#8217;t create the partition at the start of the disk, let&#8217;s put it 214 cylinders in:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
214,82,6
EOF
</code></pre>
<p>Just like before, put FAT16 on it and transfer your secret data.</p>
<pre><code>$ sudo mkfs.vfat -F16 /dev/sde1
mkfs.vfat 2.11 (12 Mar 2005)
</code></pre>
<p>If you want, you can copy the current partition table to the back of the disk for easy restoring, just like in the <a href="/2009/04/20/hide-data-in-invisible-partitions/">previous article</a>.</p>
<p>Unmount it, and remove the partition:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
0,0,0
EOF
</code></pre>
<p>Now create the parent partition. This should at least encompass the whole secret partition. If you&#8217;ve copied the partition table to the back of the disk, make sure to leave at least the last cylinder free.</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
,,6
EOF
</code></pre>
<h3>Creating Bad Blocks</h3>
<p>We need to calculate what blocks our secret partition resides on so we can mark them as <em>bad</em>. We know it starts at cylinder 214 and is 82 cylinders in size. Since on this disk, a cylinder is 258048 bytes big, the secret partition starts at byte 55222272. Divide this by the size of one block, which is 1024 bytes, and we get block 53928. Do the same for the size of the partition, and we find that 82 cylinders equal 20664 blocks. Now we know our partition starts at block 53928 and ends at block 74592. We&#8217;ll use a margin of 10 blocks on each side just in case our calculations aren&#8217;t precise.</p>
<p>Since we&#8217;re putting a FAT16 filesystem on it, we need to tell <em>mkfs.vfat</em> what blocks have supposedly gone bad. This is done by using a <strong>bad blocks file</strong>, which is a text-file with the address of each bad block on a new line. Let&#8217;s create our bad blocks file:</p>
<pre><code>$ seq 53918 74602 > /tmp/badblocks
</code></pre>
<p>If you open /tmp/badblocks, you should see something like this:</p>
<pre><code>53918
53919
53920
53921
...
</code></pre>
<p>To create the filesystem, we pass the bad blocks file using the <strong>-l</strong> parameter:</p>
<pre><code>$ sudo mkfs.vfat -n "Camera" -l /tmp/badblocks /dev/sde1
mkdosfs 2.11 (12 Mar 2005)
20685 bad blocks
</code></pre>
<p>That&#8217;s it! You can now use your disk to your heart&#8217;s delight, nothing will touch your secret partition. One awesome way is to put the card in your camera and take some pictures with it. Your data will remain safe, and there&#8217;ll be nothing suspicious about a 4GB card &#8220;missing&#8221; some megabytes.</p>
<h3>Revert</h3>
<p>If you&#8217;ve smuggled your secret data across state borders, you&#8217;re ready to recover the secret partition. Just recreate the partition table to contain the secret partition:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
214,82,6
EOF
</code></pre>
<p>That&#8217;s it! You can even reuse the setup: by switching partition tables you&#8217;re effectively changing which partition is &#8220;active&#8221; on your card, and changing data in either partition won&#8217;t affect the other.</p>
<h4>Advantages</h4>
<ul>
<li>Pretty much <strong>undetectable</strong></li>
<li>Infinitely <strong>reusable</strong></li>
<li><strong>Bad blocks</strong> are less suspicious than unallocated space</li>
</ul>
<h4>Disadvantages</h4>
<ul>
<li>Quite <strong>complex</strong> to set up</li>
<li>Possibly suspicious <strong>size discrepancy</strong> in empty filesystems</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/04/22/hide-data-in-bad-blocks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hide Data in Invisible Partitions</title>
		<link>http://blog.crowdway.com/2009/04/20/hide-data-in-invisible-partitions/</link>
		<comments>http://blog.crowdway.com/2009/04/20/hide-data-in-invisible-partitions/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 09:00:36 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[How To]]></category>

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

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

		<category><![CDATA[Hide Data]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=130</guid>
		<description><![CDATA[This is part 2 in a series on how to hide your data.
First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell thereâ€™s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is part 2 in a <a href="/tag/hide-data/">series on how to hide your data</a>.</em></p>
<p><em>First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell thereâ€™s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. <a href="http://www.truecrypt.org/">TrueCrypt</a> is an excellent way to do this.</em></p>
<h3>Introduction</h3>
<p>In the first article we learned about the Partition Table and how it identifies the partitions on our storage device. We also saw how to hide a partition using the standard method of flipping the 5th bit of the partition ID. From this moment on we&#8217;re stepping off the tracks and will use the tools at our disposal for things other than they were intended. </p>
<h3>The Partition Table, Redux</h3>
<p>Clever readers will have seen it coming when they read about the partition table in the previous article. Without those 64 bytes at the beginning of the disk, no one would know what partitions exist and where they are located. So that&#8217;s exactly what we&#8217;re going to fiddle with.</p>
<p>If we change the Partition Table, we don&#8217;t actually touch any of the real data on the disk. It&#8217;s the same thing with books: even if you remove the table of contents, you can still read the book, it&#8217;ll just be harder to find one specific chapter. If we remove the entry of a partition in the partition table, we&#8217;re not actually removing the partition, but just the info needed to know where it is. If you memorize this info, which are only 3 numbers, you can later add it back to the table, and access your data again.</p>
<h3>Practical</h3>
<p>A card with no partitions at all is suspicious, so we&#8217;ll create two partitions, and hide one of them afterwards.</p>
<p>Once again, we&#8217;re using sfdisk:</p>
<pre><code>$ sudo sfdisk /dev/sde &lt;&lt; EOF
&gt; 0,500,6
&gt; ,508,6
&gt; EOF
</code></pre>
<p>This is the result:</p>
<pre><code>david@Seven:~$ sudo sfdisk -l /dev/sde

Disk /dev/sde: 1009 cylinders, 4 heads, 62 sectors/track
Units = cylinders of 126976 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sde1          0+    499     500-     61999+   6  FAT16
/dev/sde2        500    1007     508      62992    6  FAT16
/dev/sde3          0       -       0          0    0  Empty
/dev/sde4          0       -       0          0    0  Empty
</code></pre>
<p>Put a FAT16 filesystem on the second partition&#8230;</p>
<pre><code>$ sudo mkfs.vfat -F16 /dev/sde2
mkfs.vfat 2.11 (12 Mar 2005)
</code></pre>
<p>&#8230;mount it, and save your secret data on it.</p>
<p>Hang tight, here comes the dirty bit.</p>
<p>We know our secret partition starts right after the first partition, and is exactly <strong>508</strong> cylinders in size, with <strong>0&#215;6</strong> as ID. You can memorize this data, or just copy the whole partition table to the end of the drive:</p>
<pre><code>$ sudo dd bs=1 count=64 skip=446 seek=128118720 \
&gt; if=/dev/sde of=/dev/sde
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.0282496 s, 2.3 kB/s
</code></pre>
<p>The Partition Table always starts at byte 446, so we skip those first few bytes. Byte 128118720 is the start of the last 64 bytes on my drive. You can calculate this by multiplying the size of a cylinder times the amount of cylindersâ€”both can be found using the output of <em>sfdisk -l</em> â€”and subtracting 64. Note that we made sure our two partitions don&#8217;t fully utilize the disk, but leave 1 cylinder free, so that the last 126KB at the end of the drive are free for us to use.</p>
<p>Now let&#8217;s remove the partition from the partition table:</p>
<pre><code>$ sudo sfdisk /dev/sde -N2 &lt;&lt; EOF
&gt; 0,0,0
&gt; EOF</code></pre>
<p>Our partition has magically disappeared. No operating system will be able to find the missing partition, but there exist special tools to recover the partition table. They do this by scanning the whole drive and looking for patterns that look like the beginning of a partition.</p>
<p>The one visible partition will obviously be of a smaller size than the whole drive. If for example you&#8217;re using a 2GB SD-card and want to avoid suspicion, replace the label with one from a 1GB SD-card, and make sure the visible partition is 1GB in size. This way, the only way to notice something is amiss is to run a partition editor and notice there&#8217;s a large chunk of unallocated space at the end of your drive.</p>
<p><img class="size-full wp-image-159" title="The Invisible Partition" src="http://blog.crowdway.com/wp-content/uploads/2009/04/gparted-invisible-partition.png" alt="The Invisible Partition in GParted, not quite invisible." width="488" height="301" /></p>
<h3>Revert</h3>
<p>When you want to access your data again, you can just use sfdisk to recreate exactly the same partition using the numbers you memorized:</p>
<pre><code>$ sudo sfdisk /dev/sde -N2 &lt;&lt; EOF
&gt; ,508,6
&gt; EOF
</code></pre>
<p>Or overwrite the partition table with the copy we made at the end of the drive:</p>
<pre><code>$ sudo dd bs=1 count=64 skip=128118720 seek=446 \
&gt; if=/dev/sde of=/dev/sde
</code></pre>
<p>Both methods don&#8217;t touch any of the data on the actual partitions, so are pretty safe to use, as long as you remember where your partition is located, and not format the partition afterwards.</p>
<h4>Advantages</h4>
<ul>
<li>Almost <strong>undetectable</strong></li>
<li><strong>Not accessible</strong> without changing the partition table (i.e. doing pretty advanced stuff)</li>
</ul>
<h4>Disadvantages</h4>
<ul>
<li>Possibly suspicious <strong>size discrepancy</strong></li>
<li>Detectable using <strong>partition editor</strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/04/20/hide-data-in-invisible-partitions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hide Data in Hidden Partitions</title>
		<link>http://blog.crowdway.com/2009/04/15/hide-data-in-hidden-partitions/</link>
		<comments>http://blog.crowdway.com/2009/04/15/hide-data-in-hidden-partitions/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 21:55:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[How To]]></category>

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

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

		<category><![CDATA[Hide Data]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=82</guid>
		<description><![CDATA[This is part 1 in a series on how to hide your data.
Introduction
First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell there&#8217;s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is part 1 in a <a href="/tag/hide-data/">series on how to hide your data</a>.</em></p>
<h3>Introduction</h3>
<p>First of all, the methods explained in this series are not secure. Anyone with some low-level knowledge of filesystems can tell there&#8217;s hidden data when looking at a raw image of your disk. Always complement these methods using encryption and plausible deniability methods. <a href="http://www.truecrypt.org/">TrueCrypt</a> is an excellent way to do this.</p>
<p>Second, these methods will destroy your data if you&#8217;re not careful. Use them at your own risk, and only on data you have backed up very well. These methods shouldn&#8217;t destroy your disk or memory card, since we&#8217;re purely toggling bits. However, I guarantee nothing.  These methods should work on any general data storage device, be it hard disks, usb keys, or flash cards.</p>
<h3>The Partition Table</h3>
<p>The first sector on every disk contains the partition table. These are 64 bytes divided in 4 records of 16 bytes, one for each primary partition. This explains the mystery of why you can only create 4 primary partitions on a disk. Like most arbitrary limitations this is a remnant of history.</p>
<p>Next to parameters like the start and the size of the partition, these records also contain the <em>partition-type descriptor</em>, which is an 8 bit ID identifying the filesystem on the partition. We&#8217;ll call it the partition ID or ID from here on. In hexadecimal, the ID for FAT12 is <strong>0&#215;01</strong>. For ext2, reiserfs, and various other linux filesystems the ID is <strong>0&#215;83</strong>. Here&#8217;s <a href="http://www.win.tue.nl/~aeb/partitions/partition_types-1.html">a list of all the partition ID&#8217;s</a>. Note that these are not regulated, and that the filesystem creators can decide for themselves what ID their system has. The partition ID is used by the OS to check if it can mount the specific filesystem on that partition or not, before actually trying to mount it.</p>
<p>Using <strong>sfdisk</strong> we can check out the partition table:</p>
<pre><code>$ sudo sfdisk -l /dev/sdd

Disk /dev/sdd: 1009 cylinders, 9 heads, 56 sectors/track
Units = cylinders of 258048 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sdd1          0+   1008    1009-    254267+   6  FAT16
/dev/sdd2          0       -       0          0    0  Empty
/dev/sdd3          0       -       0          0    0  Empty
/dev/sdd4          0       -       0          0    0  Empty</code></pre>
<p>This partition table comes from a 256MB compactflash card (on my PC, device <strong>/dev/sdd</strong>). As you can see, it only has one partition, encompassing all 1009 cylinders (minus 1 sector, see the addition and subtraction signs), and having ID <strong>0&#215;6</strong>, which is the standard for FAT16.  This doesn&#8217;t mean that there&#8217;s a FAT16 filesystem on that partition, though. It just means that there&#8217;s <em>probably</em> a FAT16 filesystem on there.</p>
<h3>The Standard Method</h3>
<p>As weird as it sounds, there&#8217;s actually some kind of &#8220;standard&#8221; on hidden partitions. Using this method you&#8217;re not really hiding the data as much as putting it in a corner where no one can see it unless they turn their heads. Every operating system and partition manager will recognize it as a &#8216;hidden partition&#8217;, and thus, it&#8217;s not really hidden. It even gets mounted by default in certain Linux distributions.</p>
<p>Why use this then? It&#8217;s useful when you need to install multiple legacy operating systems that don&#8217;t like to work together (<em>Windows</em>, I&#8217;m looking at you here). Grub, a linux bootloader, actually has the commands <em>hide</em> and <em>unhide</em>, which implement this method. It&#8217;s also a quick and easy, non-desctructable method to make sure the data can&#8217;t be accessed without doing <em>some</em> effort. Useful to hide data from a layperson.</p>
<p>The method is simple: flip the 5th least significant bit of the partition ID.  The <strong>0&#215;6</strong> (binary 00000110) for FAT16 becomes <strong>0&#215;16</strong> (000010110). The <strong>0&#215;83</strong> for Linux partitions becomes <strong>0&#215;93</strong>.  Let&#8217;s say we want to hide the partition on my compactflash card:</p>
<pre><code>$ sudo sfdisk --change-id /dev/sdd 1 16</code></pre>
<p>Ta-da! You&#8217;ve now officially hidden your partition. The &#8220;1&#8243;-parameter is the number of the partition on the specified disk you want to change. Change it to 2 if you want to change the second partition, etc.</p>
<p>Here&#8217;s how the table looks like now:</p>
<pre><code>$ sudo sfdisk -l /dev/sdd

Disk /dev/sdd: 1009 cylinders, 9 heads, 56 sectors/track
Units = cylinders of 258048 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sdd1          0+   1008    1009-    254267+  16  Hidden FAT16
/dev/sdd2          0       -       0          0    0  Empty
/dev/sdd3          0       -       0          0    0  Empty
/dev/sdd4          0       -       0          0    0  Empty</code></pre>
<p>As you can see: hidden, but they still know it&#8217;s there.</p>
<h4>Advantages</h4>
<ul>
<li><strong>Standard</strong>, supported by many OS&#8217;s and applications</li>
<li><strong>Easy and fast</strong> to hide and unhide</li>
</ul>
<h4>Disadvantages</h4>
<ul>
<li><strong>Standard</strong>, thus easily detected</li>
<li><strong>Mounted by default</strong> in linux, which easily defeats the purpose</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/04/15/hide-data-in-hidden-partitions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IRC Quote (2)</title>
		<link>http://blog.crowdway.com/2009/03/06/irc-quote-2/</link>
		<comments>http://blog.crowdway.com/2009/03/06/irc-quote-2/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 23:45:49 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://blog.crowdway.com/?p=49</guid>
		<description><![CDATA[Zeus WPI has an IRC channel which at any one time contains two dozen geeks discussing a myriad of topics ranging from the latest XKCD to the physics behind not being able to reach absolute zero.
Such a cornucopia of madness wouldn&#8217;t be complete without a bot for certain administrative tasks such as keeping stats on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://zeus.ugent.be">Zeus WPI</a> has an IRC channel which at any one time contains two dozen geeks discussing a myriad of topics ranging from the <a href="http://www.xkcd.com">latest XKCD</a> to the physics behind not being able to reach absolute zero.</p>
<p>Such a cornucopia of madness wouldn&#8217;t be complete without a bot for certain administrative tasks such as keeping stats on each user.</p>
<p>The &#8220;<a title="IRC Quote (1)" href="http://blog.crowdway.com/2008/02/03/irc-quote-1/">riddle</a>&#8221; I posted last year is a question we pondered about for a few days back then:</p>
<blockquote><p><em><strong>We keep a log-file of all that is said on our IRC channel. What&#8217;s the fastest way to extract one random line said by a specified person from that file, with every line having equal chance of being picked.</strong></em></p></blockquote>
<p>This we would use to implement a &#8220;quote&#8221;-command in our custom-made bot<a href="http://zeus.ugent.be/chasca"></a>, which returns a quote for the named person.</p>
<p>To keep the problem interesting, no &#8220;persistent&#8221; data can be kept in memory over multiple queries, such as an index or a counter.</p>
<p>Adhemar was the only person to <a href="http://blog.crowdway.com/2008/02/03/irc-quote-1/">propose a solution</a>, but we also asked our professor for Datastructures &amp; Algorithms, <em>Gunnar Brinkman</em>. As it turns out Adhemar&#8217;s solution was very close to the one Prof. Brinkmann suggested.</p>
<h3>Brinkmann&#8217;s Algorithm</h3>
<p>This is the algorithm we were using:</p>
<pre>totallines = 1
while not eof(logfile) do
   currentline = readline(logfile)
   if (rand() mod totallines) == 0 then
      currentqoute = currentline
   totallines++
done</pre>
<p>In plain English:</p>
<blockquote><p><strong><em>For every line i, pick that line with chance 1/i.</em></strong></p></blockquote>
<h3>Adhemar&#8217;s Algorithm</h3>
<p>Adhemar&#8217;s solution however, is a tad faster on a real-life system because it does not need the relatively expensive mod-operation for every line:</p>
<pre>currenthighest = 0
while not eof(logfile) do
   currentline = readline(logfile)
   currentrand = rand()
   if (currentrand &gt;= currenthighest)
      currentquote = currentline
      currenthighest = currentrand
done</pre>
<p>Or:</p>
<blockquote><p><em><strong>The player who rolls the highest dice gets picked.</strong></em></p></blockquote>
<p>Emperical data suggests the second algorithm is about 1% faster than the first. It&#8217;s obvious that this problem is an I/O-limited one, so these algorithms are probably as good as it gets without storing any data in memory.</p>
<p>Although the problem is relatively simple, the interesting thing to remember here is how to randomly pick an item from a set with an unknown amount of items.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2009/03/06/irc-quote-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zenity and rsync</title>
		<link>http://blog.crowdway.com/2008/12/24/zenity-rsync-and-awk/</link>
		<comments>http://blog.crowdway.com/2008/12/24/zenity-rsync-and-awk/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 10:18:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Linux]]></category>

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

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

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

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

		<guid isPermaLink="false">http://blog.crowdway.com/?p=102</guid>
		<description><![CDATA[Zenity is a neat little tool to create simple GUI&#8217;s for your shellscripts. One of its most useful features is the progress dialog, which allows one to show the progress of a command using the all-familiar GTK progress bar.

Zenity uses pipes to send commands to the dialogs. Any number sent to the Zenity instance while [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://freshmeat.net/projects/zenity">Zenity</a> is a neat little tool to create simple GUI&#8217;s for your shellscripts. One of its most useful features is the <strong>progress dialog</strong>, which allows one to show the progress of a command using the all-familiar GTK progress bar.</p>
<p><img src="http://blog.crowdway.com/wp-content/uploads/2008/12/rsynczenity.png" alt="Zenity and rsync" title="Zenity and rsync" width="490" height="177" class="aligncenter size-full wp-image-103" /></p>
<p>Zenity uses pipes to send commands to the dialogs. Any <em>number</em> sent to the Zenity instance while in <em>progress</em> mode will make the progress bar move to that number as the percentage completed. Any <em>text</em> that starts with <strong>#</strong> is set as the label above the progress bar.</p>
<p>Here&#8217;s an example shamelessly stolen and abbreviated from the <a href="http://library.gnome.org/users/zenity/stable/zenity-progress-options.html.en">manual</a>:</p>
<pre><code>        #!/bin/sh
        (
        echo "10" ; sleep 1
        echo "# Updating mail logs" ; sleep 1
        echo "20" ; sleep 1
        echo "# Resetting cron jobs" ; sleep 1
        echo "75" ; sleep 1
        echo "# Rebooting system" ; sleep 1
        echo "100" ; sleep 1
        ) |
        zenity --progress \
          --title="Update System Logs" \
          --text="Scanning mail logs..." \
          --percentage=0
</code></pre>
<p>To shape the output of a real application into data fit for Zenity mostly requires some creative <em>awk</em>ing. I couldn&#8217;t find an example to parse rsync output, so I made this awk-script to show the progress of an rsync operation:</p>
<pre><code>{
   if (index($0, "to-check=") > 0)
   {
	split($0, pieces, "to-check=");
	term = substr(pieces[2], 0, length(pieces[2])-1);
	split(term, division, "/");
	print (1-(division[1]/division[2]))*100"%"
   }
   else
   {
	print "#"$0;
   }
   fflush();
}</code></pre>
<p>Use it like this.</p>
<pre><code>$ rsync -av --progress /media/disk/ ~/backup/usbstick/ |
   awk -f rsync.awk |
   zenity --progress --title "Backing up USB-Stick" \
      --text="Scanning..." --percentage=0
</code></pre>
<p>rsync.awk contains the awk-script above. Mind how we use the parameter <strong>progress</strong> to tell how far we&#8217;ve progressed. This results in the dialog shown above.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2008/12/24/zenity-rsync-and-awk/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Autographed</title>
		<link>http://blog.crowdway.com/2008/12/22/autographed/</link>
		<comments>http://blog.crowdway.com/2008/12/22/autographed/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 08:13:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
		
		<category><![CDATA[Books]]></category>

		<guid isPermaLink="false">http://blog.crowdway.com/?p=98</guid>
		<description><![CDATA[Last Thursday I went on my annual visit to the Bookfestival in Expo, Ghent. While my dad was disappointed by the lack of good comic books this year, I was delighted being able to pick up Stephenson&#8217;s Confusion, Morrow&#8217;s The Last Witchfinder, Simmons&#8217; Olympos and a boxed edition of Clarke&#8217;s Jonathan Strange &#38; Mr. Norrell [...]]]></description>
			<content:encoded><![CDATA[<p>Last Thursday I went on my annual visit to the <a href="http://www.boekenfestijn.com/en/index.html">Bookfestival</a> in Expo, Ghent. While my dad was disappointed by the lack of good comic books this year, I was delighted being able to pick up Stephenson&#8217;s <a href="http://www.amazon.com/Confusion-Baroque-Cycle-Vol/dp/0060523867">Confusion</a>, Morrow&#8217;s <a href="http://www.amazon.com/Last-Witchfinder-Novel-James-Morrow/dp/0060821795">The Last Witchfinder</a>, Simmons&#8217; <a href="http://www.amazon.com/Olympos-Dan-Simmons/dp/0380978946/ref=ed_oe_h">Olympos</a> and a boxed edition of Clarke&#8217;s <a href="http://www.amazon.com/Jonathan-Strange-Mr-Norrell-Novel/dp/1582344167">Jonathan Strange &amp; Mr. Norrell</a> for less than â‚¬19. A steal!<br />
<img class="aligncenter size-full wp-image-99" title="Jonathan Strange &amp; Mr. Norrell" src="http://blog.crowdway.com/wp-content/uploads/2008/12/img_5271.jpg" alt="Jonathan Strange &amp; Mr. Norrell" width="200" height="233" /></p>
<p>I got even more excited when back home I turned the first page of Volume 1 of <em>Jonathan Strange &amp; Mr. Norrell</em>: The signature of Susanna Clarke!<br />
<img class="aligncenter size-full wp-image-100" title="Susanna Clarke\'s Signature" src="http://blog.crowdway.com/wp-content/uploads/2008/12/img_5270.jpg" alt="Susanna Clarke\'s Signature" width="490" height="242" /><br />
I have no idea if it&#8217;s real or pressed on. There&#8217;s no impression of the pen, but it is in blue ink. Nonetheless, a pleasant surprise.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crowdway.com/2008/12/22/autographed/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
