<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.offensivethinking.org/</id>
  <title>Offensive Thinking</title>
  <updated>2011-07-14T22:55:00Z</updated>
  <link href="http://www.offensivethinking.org/" rel="alternate"/>
  <link href="http://www.offensivethinking.org/atom.xml" rel="self"/>
  <author>
    <name>Patrick Hof</name>
    <uri>http://www.offensivethinking.org</uri>
  </author>
  <entry>
    <id>tag:www.offensivethinking.org,2011-07-14:/thoughts/2011/07/14/debian-chroot-eee-pad-transformer/</id>
    <title type="html">Installing a Debian chroot on the Asus Eee Pad Transformer</title>
    <published>2011-07-14T22:55:00Z</published>
    <updated>2011-07-14T22:55:00Z</updated>
    <link href="http://www.offensivethinking.org/thoughts/2011/07/14/debian-chroot-eee-pad-transformer/" rel="alternate"/>
    <content type="html">&lt;p style="text-align:justify;"&gt;I bought an Asus Eee Pad Transformer these days. It has a keyboard dock, so I could finally convince myself why I&amp;#8217;d need a tablet and that this one could also be used for creating stuff (like e.g. developing), not only consuming.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;Of course, having Android (Honeycomb 3.1) running on the tablet is nice for couch surfing, but not for creating anything useful. So before buying the tablet, I at least made sure that it is possible to run Linux in any form on it.&lt;/p&gt;
&lt;h2&gt;Debian chroot&lt;/h2&gt;
&lt;p style="text-align:justify;"&gt;Fortunately, it is possible to run Linux (e.g. Debian) in a chroot environment. There&amp;#8217;s also people working (and succeeding) in running Linux natively over at &lt;a href="http://forum.xda-developers.com/showthread.php?t=1147062"&gt;xda-developers&lt;/a&gt;, but that&amp;#8217;s for another post if I ever go for the dual boot option (and those guys get all the kinks worked out).&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;This blog post will therefore describe how I run Debian in a chroot on my Transformer. I do own the keyboard dock, so if you want to follow this using only the tablet, I recommend installing &lt;a href="https://market.android.com/details?id=org.pocketworkstation.pckeyboard"&gt;Hacker&amp;#8217;s Keyboard&lt;/a&gt;. Also, this is written for people with a modicum of Linux knowledge, so don&amp;#8217;t expect me to explain what a chroot is.&lt;/p&gt;
&lt;h3&gt;Root your device&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;For the chroot to work, you first have to root your Transformer. I&amp;#8217;m not going to describe this, as others have already done so, have a look at the &lt;a href="http://forum.xda-developers.com/forumdisplay.php?f=1107"&gt;xda-developer pages&lt;/a&gt;. I did it by first downgrading to a vulnerable Android 3.0 version and then using gingerbreak. After that, I upgraded to 3.1 and later flashed &lt;a href="http://forum.xda-developers.com/showthread.php?t=1052380"&gt;Prime! 1.5&lt;/a&gt;. &lt;span class="caps"&gt;YMMV&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;Install a Terminal Emulator&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;This is easy. I&amp;#8217;m using &lt;a href="https://market.android.com/details?id=jackpal.androidterm"&gt;Terminal Emulator&lt;/a&gt;, but you may also try e.g. &lt;a href="https://market.android.com/details?id=org.connectbot"&gt;ConnectBot&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;Optional: Map the dock&amp;#8217;s &amp;#8220;Back&amp;#8221; key to Escape&lt;/h4&gt;
&lt;p style="text-align:justify;"&gt;This is not a requirement, but for me as a vi(m) user it&amp;#8217;s an absolute must: The Transformer&amp;#8217;s keyboard dock is not a full keyboard as on your normal netbook, but specifically designed for Android. Fortunately, &lt;a href="http://forum.xda-developers.com/showthread.php?t=1144204"&gt;this post&lt;/a&gt; describes how to remap the keys on the dock, so you can have the &amp;#8220;back&amp;#8221; key on the dock remapped to good ol&amp;#8217; &amp;#8220;Escape&amp;#8221;:&lt;/p&gt;
&lt;p&gt;1. Open the Terminal Emulator&lt;br /&gt;
2. Become root by typing &amp;#8220;su&amp;#8221;&lt;br /&gt;
3. Remount the read-only filesystem to be writable:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
mount -o rw,remount -t yaffs2 \
      /dev/block/mtdblock3 /system
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;4. Edit the file with the dock&amp;#8217;s keymappings:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
vi /system/usr/keylayout/asusec.kl
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;5. Search for &amp;#8220;&lt;span class="caps"&gt;BACK&lt;/span&gt;&amp;#8221; and change it to &amp;#8220;&lt;span class="caps"&gt;ESCAPE&lt;/span&gt;&amp;#8221; (should be key 158)&lt;/p&gt;
&lt;h3&gt;Add a script to start your chroot environment&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;This is where all the neat stuff happens. I&amp;#8217;ve based my script on the one that comes with &lt;a href="http://wiki.gitbrew.org/index.php?title=Android:Debdroid&amp;amp;oldid=268"&gt;Debdroid&lt;/a&gt;, as I originally tinkered with it. No need for all the additional stuff that comes with Debdroid though, and on the Transformer, their scripts do not work out of the box, so I had to rewrite them quite a bit to suit me.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;Long story short, you can download &lt;a href="/data/transformer/debdroid"&gt;the full script here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;1. Put it under /system/bin/ to have it in your path. See the optional section about mapping Escape above on how to make the system partition writable.&lt;br /&gt;
2. Set the permissions:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
chmod 700 /system/bin/debdroid
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;You also need the Debian image to mount. I just took one from the &lt;a href="http://wiki.gitbrew.org/index.php?title=Android:Debdroid&amp;amp;oldid=268#Distro_Images"&gt;Debdroid website&lt;/a&gt;, but can of course use any other image prepared for being used in a chroot, or you can even prepare your own. In its default state, the script mounts it from /sdcard/debian/debian.img. Edit the config variables at the beginning to whatever you need.&lt;/p&gt;
&lt;h3&gt;First run of the chroot&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;Now it&amp;#8217;s time to run the script for the first time. It will complain about the script &amp;#8216;mnt_home&amp;#8217; which it can&amp;#8217;t find, but that&amp;#8217;s ok for now. If everything went well, you&amp;#8217;ll now have a root bash prompt before you. Welcome to your new Debian chroot :).&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;Next, we want to add a new user, as it is dangerous to always work as root, don&amp;#8217;t we all know it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
adduser username
addgroup --gid 3003 inet
usermod -G inet -a username
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;Why the new group? Well, Android seems to allow socket access only to users in the inet (gid 3003) group. As we don&amp;#8217;t have that group in our chroot yet, we have to add it manually. Then we need to add our user to it. &lt;span class="caps"&gt;ICMP&lt;/span&gt; (i.e., ping) will still not work, as you need raw sockets for that. But normal &lt;span class="caps"&gt;TCP&lt;/span&gt; connections should work now. I found out about this by reading &lt;a href="http://tosh-ac100.wetpaint.com/page/Chrooted+Ubuntu"&gt;this blog post&lt;/a&gt;. Root will of course still be able to do everything.&lt;/p&gt;
&lt;h3&gt;Optional but recommended: Encrypted home for your user&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;Honeycomb allows you to encrypt your tablet (see Settings &amp;#8594; Location and security &amp;#8594; Encrypt tablet). That functionality is currently broken, but as it uses dm-crypt, the kernel modules are there and fortunately functional. As I did not want my &lt;span class="caps"&gt;GPG&lt;/span&gt; and &lt;span class="caps"&gt;SSH&lt;/span&gt; keys I&amp;#8217;m using in my chroot to lie around on an unencrypted hard drive, I worked around it by mounting an encrypted file as my home directory. Not very good performance-wise, but I gladly accept that for the added security.&lt;/p&gt;
&lt;h4&gt;Creating the encrypted file&lt;/h4&gt;
&lt;p style="text-align:justify;"&gt;First, we need a file that will hold the home dir. We start by creating a new file with dd. I recommend creating the file on another system, as it seems awfully slow on the Transformer, especially if you want to create a file not only containing zeroes, but with arbitrary content from /dev/urandom (for the really paranoid):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
dd if=/dev/zero of=/home/home.img bs=1M count=500
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;The command above will create a 500MB file containing only zeroes under /home. Put the file where you want to, I think /home is fitting. Next, we mount this file to a loopback device:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
mknod /dev/loop21 b 7 21
losetup /dev/loop21 /home/home.img
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;We need to create the loopback device first with &amp;#8220;mknod&amp;#8221;. Choose whatever number you want to, it doesn&amp;#8217;t have to be 21. Just don&amp;#8217;t try to recreate 255, that&amp;#8217;s what we already use for the Debian image. Now we want to create a new crypted device with cryptsetup. First, install cryptsetup:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
aptitude install cryptsetup
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;Let&amp;#8217;s format our new device:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
cryptsetup luksFormat /dev/loop21
cryptsetup luksOpen /dev/loop21 home-crypto
mkfs.ext4 /dev/mapper/home-crypto
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;Now you should have a new crypted device that you can mount on /home/username. My script &lt;a href="/data/transformer/mnt_home"&gt;mnt_home&lt;/a&gt; can do that for you automatically. Put it under /usr/local/bin to work out of the box with the debdroid-script from earlier (this is what caused the error message in the beginning, as we didn&amp;#8217;t have that script yet). It&amp;#8217;ll also unmount your home directory when you exit the chroot. Please edit the variables at the top of the script to suit your needs.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;You should now be able to exit the chroot with everything being cleanly unmounted, and to enter it again by opening your terminal emulator and running &amp;#8220;debdroid&amp;#8221;. To use your new user, just do a &amp;#8220;su username&amp;#8221;.&lt;/p&gt;
&lt;h3&gt;Optional: Install tmux and tweak its config to allow usage of normal user&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;I&amp;#8217;m a huge &lt;a href="http://tmux.sourceforge.net"&gt;tmux&lt;/a&gt; fan, so I use it in my chroot. The only problem is, once I su to my new user, tmux won&amp;#8217;t start in the su environment. There may be a better solution to this, but my current workaround is to start tmux as root and use the following extra directive in my .tmux.conf:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
set -g default-command "su username"
&lt;/code&gt;&lt;/pre&gt;&lt;p style="text-align:justify;"&gt;This&amp;#8217;ll automatically su to my user in every new window I create. Please contact me if you have a better way and I&amp;#8217;ll add it to this blog post.&lt;/p&gt;
&lt;h3&gt;Optional: Add inputrc&lt;/h3&gt;
&lt;p style="text-align:justify;"&gt;I also had the very odd bug that after su&amp;#8217;ing to my user, I couldn&amp;#8217;t type the numbers &amp;#8216;2&amp;#8217; and &amp;#8216;0&amp;#8217; anymore. What fixed the problem was to add my favourite .inputrc (see the &lt;a href="/projects/dotfiles/"&gt;dotfiles section&lt;/a&gt;. Don&amp;#8217;t ask me why, but it helped.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p style="text-align:justify;"&gt;I hope the instructions I gave helped you to set up your own chroot environment. If you find any mistakes, please contact me so I can fix them.&lt;/p&gt;</content>
    <summary type="html">My Debian chroot setup explained</summary>
  </entry>
  <entry>
    <id>tag:www.offensivethinking.org,2011-06-06:/thoughts/2011/06/06/minor-site-cleanups/</id>
    <title type="html">Minor site cleanups</title>
    <published>2011-06-06T15:13:11Z</published>
    <updated>2011-06-06T15:13:11Z</updated>
    <link href="http://www.offensivethinking.org/thoughts/2011/06/06/minor-site-cleanups/" rel="alternate"/>
    <content type="html">&lt;p style="text-align:justify;"&gt;I finally did some minor cleanups on the site. The following things&lt;br /&gt;
changed:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;As I use &lt;a href="http://tmux.sourceforge.net"&gt;tmux&lt;/a&gt; now instead of &lt;a href="http://www.gnu.org/software/screen/"&gt;screen&lt;/a&gt; wherever possible, I&amp;#8217;ve added my &lt;a href="/data/dotfiles/tmux.conf"&gt;tmux.conf&lt;/a&gt; to the &lt;a href="/projects/dotfiles/"&gt;dotfiles&lt;/a&gt; section.&lt;/li&gt;
	&lt;li&gt;I orphaned all my &lt;a href="/projects/discontinued/aur/"&gt;&lt;span class="caps"&gt;AUR&lt;/span&gt; packages&lt;/a&gt; due to lack of time. So there&amp;#8217;s a new project category now, &lt;a href="/projects/discontinued/"&gt;Discontinued&lt;/a&gt;, for all the projects I might abandon at some point.&lt;/li&gt;
	&lt;li&gt;There&amp;#8217;s a new project, &lt;a href="/projects/rem2jorte/"&gt;rem2jorte&lt;/a&gt;. Please see the project page for further details.&lt;/li&gt;
	&lt;li&gt;Removed the &lt;a href="http://identi.ca/courts"&gt;identi.ca link&lt;/a&gt; because I don&amp;#8217;t really use it.  &lt;a href="http://twitter.com/__courts__"&gt;Twitter&lt;/a&gt; has won. Instead, I added my &lt;a href="http://github.com/courts"&gt;github page&lt;/a&gt; where all my public projects reside.&lt;/li&gt;
&lt;/ul&gt;</content>
    <summary type="html">Moved some files, added rem2jorte project and tmux config</summary>
  </entry>
  <entry>
    <id>tag:www.offensivethinking.org,2011-04-17:/thoughts/2011/04/17/remparser/</id>
    <title type="html">New project: remparser</title>
    <published>2011-04-17T16:43:57Z</published>
    <updated>2011-04-17T16:43:57Z</updated>
    <link href="http://www.offensivethinking.org/thoughts/2011/04/17/remparser/" rel="alternate"/>
    <content type="html">&lt;p style="text-align:justify;"&gt;Without further ado: a new project on &lt;a href="http://github.com"&gt;github&lt;/a&gt;, &lt;a href="http://github.com/courts/remparser"&gt;remparser&lt;/a&gt;.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;The &lt;em&gt;remparser&lt;/em&gt; &lt;a href="http://treetop.rubyforge.org/"&gt;Treetop&lt;/a&gt; parser parses the output of &lt;a href="http://www.roaringpenguin.com/products/remind"&gt;remind -s&lt;/a&gt; into a (hopefully useful) data structure. An example script outputting &lt;span class="caps"&gt;YAML&lt;/span&gt; code is included.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;Some more details are in the &lt;a href="/projects/remparser/"&gt;&lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;</content>
    <summary type="html">remparser is a parser written with Treetop to parse the output of 'remind -s'</summary>
  </entry>
  <entry>
    <id>tag:www.offensivethinking.org,2010-08-08:/thoughts/2010/08/08/website-updates/</id>
    <title type="html">Website Updates</title>
    <published>2010-08-08T16:25:38Z</published>
    <updated>2010-08-08T16:25:38Z</updated>
    <link href="http://www.offensivethinking.org/thoughts/2010/08/08/website-updates/" rel="alternate"/>
    <content type="html">&lt;p style="text-align:justify;"&gt;It&amp;#8217;s been a while, I know. Busy as ever. So to prove that I&amp;#8217;ve not entirely dismissed this website, some minor updates in &lt;a href="/projects"&gt;Projects&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;I&amp;#8217;ve updated some &lt;a href="/projects/dotfiles"&gt;dotfiles&lt;/a&gt; and added two new: My elinks.conf for &lt;a href="http://elinks.or.cz"&gt;elinks&lt;/a&gt; and taskrc for &lt;a href="http://taskwarrior.org"&gt;task&lt;/a&gt;.&lt;/li&gt;
	&lt;li&gt;The &lt;a href="/projects/various"&gt;Various&lt;/a&gt; section now mentions the &lt;a href="http://www.metasploit.com"&gt;Metasploit&lt;/a&gt; JBoss AS exploit modules I contributed and updated recently.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="text-align:justify;"&gt;The JBoss modules would&amp;#8217;ve been worth their own blog post I guess, but I was too busy. I&amp;#8217;ve mentioned them in this &lt;a href="http://blogs.23.nu/RedTeam/2010/06/new-whitepaper-jboss-as-deploying-wars-with-the-deploymentfilerepository-mbean/"&gt;RedTeam blog post&lt;/a&gt; where I announced a new JBoss paper.  They are in the official main branch now, so you if you have a recent revision, they should be available. I&amp;#8217;ll give a &lt;a href="http://2010.brucon.org/index.php/Lightning_Talks"&gt;lightning talk&lt;/a&gt; at &lt;a href="http://www.brucon.org"&gt;BruCON&lt;/a&gt; about some of the ideas behind them.&lt;/p&gt;</content>
    <summary type="html">Minor updates in Projects section</summary>
  </entry>
  <entry>
    <id>tag:www.offensivethinking.org,2010-05-20:/thoughts/2010/05/20/new-project-http2code/</id>
    <title type="html">New project: http2code</title>
    <published>2010-05-20T19:44:09Z</published>
    <updated>2010-05-20T19:44:09Z</updated>
    <link href="http://www.offensivethinking.org/thoughts/2010/05/20/new-project-http2code/" rel="alternate"/>
    <content type="html">&lt;p style="text-align:justify;"&gt;A new repository has been added to my github account: &lt;a href="http://courts.github.com/http2code"&gt;http2code&lt;/a&gt;.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;It was inspired by &lt;a href="http://w3af.sourceforge.net/"&gt;w3af&amp;#8217;s&lt;/a&gt; ability to export a raw request to a template source code file for different languages (as a matter of fact, I once wrote the &lt;a href="http://w3af.svn.sourceforge.net/viewvc/w3af/trunk/core/data/export/ruby_export.py?view=markup"&gt;Ruby export&lt;/a&gt;).  The idea is simple: I have a raw &lt;span class="caps"&gt;HTTP&lt;/span&gt; &lt;span class="caps"&gt;GET&lt;/span&gt; or &lt;span class="caps"&gt;POST&lt;/span&gt; request, e.g. from my favourite &lt;span class="caps"&gt;HTTP&lt;/span&gt; (attack) proxy. Now quite often, I want to write a little script revolving around that request, for example for fuzzing. Previously, I always manually added the request&amp;#8217;s content to some template code for the &lt;span class="caps"&gt;HTTP&lt;/span&gt; library du jour I hopefully still found lying around somewhere on my hard drive. Then, I started to adapt the code to my liking.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;The whole &amp;#8220;copy the raw request, insert it into source code template (if any) and reformat until it fits into what the &lt;span class="caps"&gt;HTTP&lt;/span&gt; library expects (like parsing the raw body of a &lt;span class="caps"&gt;POST&lt;/span&gt; into an associative array, for example)&amp;#8221; is a rather dull and repetitive task better done by a script. w3af already does it quite nicely, but I wanted a simple command line tool for this.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;So I wrote http2code:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
Usage: http2code [options]
 -n, --newlines            Use \n as line delimiter when parsing the
                           POST request instead of \r\n
 -t, --template TEMPLATE   Use template TEMPLATE
 -b, --header-blacklist    Use header blacklist to automatically
                           remove common headers not needed
 -h, --help                Show this help

Available Templates:
--------------------
typhoeus.rb
&lt;/code&gt;
&lt;/pre&gt;
&lt;p style="text-align:justify;"&gt;It takes a raw request from stdin and parses it into &lt;span class="caps"&gt;JSON&lt;/span&gt; data structures for headers, body and the first line containing the &lt;span class="caps"&gt;HTTP&lt;/span&gt; verb and &lt;span class="caps"&gt;URL&lt;/span&gt;. If you supply a template name, it&amp;#8217;ll just put the &lt;span class="caps"&gt;JSON&lt;/span&gt; data into the template where some placeholders are defined. Then it writes the result to stdout. Pretty simple, but it saves me a lot of time. You will still have to manually adapt the code though, it may not work right out of the box.&lt;/p&gt;
&lt;p style="text-align:justify;"&gt;At the moment there&amp;#8217;s only a &lt;a href="http://github.com/pauldix/typhoeus"&gt;typhoeus&lt;/a&gt; template, I plan on adding them as I need / write them.&lt;/p&gt;</content>
    <summary type="html">Parse HTTP requests to JSON and optionally put them into template source code</summary>
  </entry>
</feed>

