<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>E4200v2 on bramp.net</title>
    <link>https://blog.bramp.net/</link>
    <description>Recent content in E4200v2 on bramp.net</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-GB</language>
    <lastBuildDate>Tue, 24 Jan 2012 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bramp.net/tags/e4200v2/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Hacking Linksys E4200v2 firmware</title>
      <link>https://blog.bramp.net/post/2012/01/24/hacking-linksys-e4200v2-firmware/</link>
      <pubDate>Tue, 24 Jan 2012 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2012/01/24/hacking-linksys-e4200v2-firmware/</guid>
      <description><p>In a previous post I <a href="/post/2012/01/22/obtaining-the-firmware-for-linksys-e4200v2/">obtained the Linksys E4200v2 firmware</a>, now I plan to break it apart and see what I can find.</p>
<p>I start off by simplying using “file” on the firmware:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ file FW_E4200_2.0.36.126507.SSA 
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">FW_E4200_2.0.36.126507.SSA: u-boot legacy uImage, Linux-2.6.35.8, Linux/ARM, OS Kernel Image <span class="o">(</span>Not compressed<span class="o">)</span>, <span class="m">2677476</span> bytes, Thu Dec <span class="m">22</span> 19:40:21 2011, Load Address: 0x00008000, Entry Point: 0x00008000, Header CRC: 0x6ADD9801, Data CRC: 0xB010442D
</span></span></code></pre></div><p>Well this is a great start. We know we are dealing with Linux, and that this is a normal uImage. I then move on to use a neat little tool called <a href="https://github.com/devttys0/binwalk">binwalk</a>. By using libmagic, binwalk tries to find interesting sections of the file.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ /usr/local/bin/binwalk FW_E4200_2.0.36.126507.SSA 
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">DECIMAL   	HEX       	DESCRIPTION
</span></span><span class="line"><span class="cl">-------------------------------------------------------------------------------------------------------
</span></span><span class="line"><span class="cl"><span class="m">0</span>         	0x0       	uImage header, header size: <span class="m">64</span> bytes, header CRC: 0x6ADD9801, created: Thu Dec <span class="m">22</span> 19:40:21 2011, image size: <span class="m">2677476</span> bytes, Data Address: 0x8000, Entry Point: 0x8000, data CRC: 0xB010442D, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: Linux-2.6.35.8
</span></span><span class="line"><span class="cl"><span class="m">1124</span>      	0x464     	LZMA compressed data, properties: 0x87, dictionary size: <span class="m">250216448</span> bytes, uncompressed size: <span class="m">14786800</span> bytes
</span></span><span class="line"><span class="cl"><span class="m">16636</span>     	0x40FC    	gzip compressed data, from Unix, last modified: Thu Dec <span class="m">22</span> 19:40:18 2011, max compression
</span></span><span class="line"><span class="cl"><span class="m">2752512</span>   	0x2A0000  	JFFS2 filesystem data little endian, JFFS node length: <span class="m">49</span>
</span></span><span class="line"><span class="cl">..A whole lot of JFFS2 sections..
</span></span><span class="line"><span class="cl"><span class="m">20974612</span>  	0x1400C14 	JFFS2 filesystem data little endian, JFFS node length: <span class="m">51</span>
</span></span><span class="line"><span class="cl"><span class="m">20974664</span>  	0x1400C48 	JFFS2 filesystem data little endian, JFFS node length: <span class="m">193</span>
</span></span></code></pre></div><p>We find a small LZMA section, and large gzip section, and lots of JFFS2 sections. JFFS2 is a popular embedded file system, so we can guess the bulk of the file system is here. Next we can extract each section using dd:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">dd <span class="nv">bs</span><span class="o">=</span><span class="m">1</span> <span class="nv">skip</span><span class="o">=</span><span class="m">1124</span>  <span class="nv">count</span><span class="o">=</span><span class="m">15512</span>   <span class="k">if</span><span class="o">=</span>FW_E4200_2.0.36.126507.SSA <span class="nv">of</span><span class="o">=</span>image-1.lzma
</span></span><span class="line"><span class="cl">dd <span class="nv">bs</span><span class="o">=</span><span class="m">1</span> <span class="nv">skip</span><span class="o">=</span><span class="m">16636</span> <span class="nv">count</span><span class="o">=</span><span class="m">2735876</span> <span class="k">if</span><span class="o">=</span>FW_E4200_2.0.36.126507.SSA <span class="nv">of</span><span class="o">=</span>image-2.gz
</span></span><span class="line"><span class="cl">dd <span class="nv">bs</span><span class="o">=</span><span class="m">1</span> <span class="nv">skip</span><span class="o">=</span><span class="m">2752512</span> <span class="k">if</span><span class="o">=</span>FW_E4200_2.0.36.126507.SSA <span class="nv">of</span><span class="o">=</span>image-3.jffs2
</span></span></code></pre></div><p>Notice we are using a block size of 1 (so we can count in bytes), and we skip the offset into the file. Then we manually work out the sizes for the lzma and gzip sections. They can be no larger than their start until the next section. If they don’t fill that full space, then not to worry as these tools will normally ignore trailing data.</p>
<p>As I’m interested to see what’s in the JFFS filesystem, we should mount it. You can’t mount JFFS like a normal loopback device, you have to create a fake flash device. The following set of command can solve that:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo modprobe mtdram <span class="nv">total_size</span><span class="o">=</span><span class="m">32768</span> <span class="nv">erase_size</span><span class="o">=</span><span class="m">256</span>
</span></span><span class="line"><span class="cl">sudo modprobe mtdblock
</span></span><span class="line"><span class="cl">sudo modprobe mtdchar
</span></span><span class="line"><span class="cl"><span class="c1"># sudo mknod /dev/mtdblock0 b 31 0</span>
</span></span><span class="line"><span class="cl">dd <span class="k">if</span><span class="o">=</span>image-3.jffs2 <span class="nv">of</span><span class="o">=</span>/dev/mtdblock0
</span></span><span class="line"><span class="cl">mount -t jffs2 /dev/mtdblock0 /mnt/disk
</span></span></code></pre></div><p>The mknod line is only needed if you don’t already have a /dev/mtdblock0. Also a /mnt/disk needs to be created ahead of time so the mounting works. Anyway once that was done, I cd /mnt/disk and found that it does appear to contain most of the file system. There are all the HTML pages, and binaries (for example busybox).</p>
<p>Now we should go back to image-1.lzma and image-2.gz. Well straight away trying to decompress image-1</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ lzma -dc image-1.lzma &gt; image-1
</span></span><span class="line"><span class="cl">lzma: Decoder error
</span></span></code></pre></div><p>results in a error. So we can assume that was a incorrectly detected by binwalk. Lets now try and decompress image-2.gz:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ gzip -dc image-2.gz &gt; image-2
</span></span><span class="line"><span class="cl">gzip: image-2.gz: decompression OK, trailing garbage ignored
</span></span></code></pre></div><p>So that does indeed produce a large image-2 file, so we can ignore the trailing garbage warning. A quick “file” on image-2 doesn’t reveal anything useful, so I run binwalk on it. This turns up a set of false positives. So I take a different approach. I run:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ strings image-2
</span></span></code></pre></div><p>This produces a whole host of valid looking strings. From the contents of the strings it makes me think it’s the actual kernel. A line like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Linux version 2.6.35.8 (root@ubuntu) (gcc version 4.2.0 20070413 (prerelease) (CodeSourcery Sourcery G++ Lite 2007q1-21)) #1 Thu Dec 22 16:40:10 PST 2011
</span></span></code></pre></div><p>helps me come to that conclusion.</p>
<p>I haven’t finished poking around image-2.gz, but I suspect the interesting parts are mostly in the JFFS2 filesystem. Hopefully this will lead to me getting ssh access to the router, and eventually being able to customise the firmware.</p>
</description>
    </item>
    
  </channel>
</rss>
