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

<channel>
	<title>acloudtree</title>
	<atom:link href="http://www.acloudtree.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acloudtree.com</link>
	<description>Programming, Computers, Writing, Economics, and Life</description>
	<lastBuildDate>Mon, 20 May 2013 15:58:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Lions, and Tigers, and OP Codes, OH MY! &#8211; Hacking Java Bytecode for Programmers (Part2)</title>
		<link>http://www.acloudtree.com/lions-and-tiger-and-op-codes-oh-my-hacking-java-bytecode-for-programmers-part2/</link>
		<comments>http://www.acloudtree.com/lions-and-tiger-and-op-codes-oh-my-hacking-java-bytecode-for-programmers-part2/#comments</comments>
		<pubDate>Fri, 17 May 2013 16:49:18 +0000</pubDate>
		<dc:creator>jared folkins</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bytecode]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[Hex]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=1610</guid>
		<description><![CDATA[AT THE END OF MAY I AM INVITED TO SPEAK AT A LOCAL USER GROUP ABOUT JAVA BYTECODE HACKING. I FIGURED IT WOULD BE BENEFICIAL TO GET MY THOUGHTS DOWN CONCERNING THIS TOPIC. THEREFORE, YOU MY FRIENDS, ARE MY GUINEA PIGS. YAY! IF YOU FIND A MISTAKE, EMAIL, COMMENT, WHATEVER,...<p style="text-align:center;"><a class="more-link" href="http://www.acloudtree.com/lions-and-tiger-and-op-codes-oh-my-hacking-java-bytecode-for-programmers-part2/">Click to Load</a></p>]]></description>
				<content:encoded><![CDATA[<div class="intro">AT THE END OF MAY I AM INVITED TO SPEAK AT A LOCAL USER GROUP ABOUT JAVA BYTECODE HACKING. I FIGURED IT WOULD BE BENEFICIAL TO GET MY THOUGHTS DOWN CONCERNING THIS TOPIC. THEREFORE, YOU MY FRIENDS, ARE MY GUINEA PIGS. YAY! IF YOU FIND A MISTAKE, EMAIL, COMMENT, WHATEVER, SO THAT I CAN IMPROVE THE FLOW. WERD.</div>
<h2>Index</h2>
<ol>
<li><span style="line-height: 15px;"><a href="http://www.acloudtree.com/the-birds-and-the-bees-of-hex-editing-hacking-java-bytecode-for-programmers-part1/">The Birds and the Bees of Hex Editing &#8211; Hacking Java Bytecode for Programmers (Part1)</a><br />
</span></li>
<li><a href="http://www.acloudtree.com/lions-and-tiger-and-op-codes-oh-my-hacking-java-bytecode-for-programmers-part2/">Lions, and Tigers, and OP Codes, OH MY! – Hacking Java Bytecode for Programmers (Part2)<br />
</a></li>
<li>Coming Soon</li>
</ol>
<p>In <a href="http://www.acloudtree.com/the-birds-and-the-bees-of-hex-editing-hacking-java-bytecode-for-programmers-part1/">Part 1</a>, I showed you the basics of Hexadecimal, Hex Editors, and Java Bytecode. Refer to that post if you need to catch up. The following will be a simple exercise showing you how to manipulate the Java Bytecode directly.</p>
<h2>GOAAAAAAAAAAAAAAAL!</h2>
<p>Lets set ourselves up with a goal for this exercise.</p>
<p>You should have the following <em><strong>User.java</strong></em> file on your system.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> status <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> setStatusTrue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">status</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hacking Java Bytecode!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Which we compiled using <em><strong>javac</strong></em>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>javac User.java</pre></td></tr></table></div>

<p>Thus, we should also have a <em><strong>User.class</strong> </em>file.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span><span style="color: #c20cb9; font-weight: bold;">ls</span>
User.class  User.java
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>At this point, lets pretend that we were never given the source file. So for clarity, rename the source file to <em><strong>User.java.del</strong></em>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span><span style="color: #c20cb9; font-weight: bold;">mv</span> User.java User.java.del
<span style="color: #666666;">thedude$ </span><span style="color: #c20cb9; font-weight: bold;">ls</span>
User.class  User.java.del</pre></td></tr></table></div>

<p>In this scenario, despite the fact that you do not have the source code, you still have the compiled class file that the JVM can execute. Lets run it now.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>java User 
Hacking Java Bytecode<span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p><span class="highlight"> Our goal will be to change the output from &#8220;<em>Hacking Java Bytecode!</em>&#8221; to &#8220;<em>l33t hax0r bro</em>&#8221; by modifying only the compiled source.</span></p>
<h2>Understanding Java Opcodes (Operation Codes)</h2>
<p>When we compiled our code using <em><strong>javac</strong></em>, it took the human readable goodness that we cooked up.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> status <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> setStatusTrue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">status</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hacking Java Bytecode!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And turned it into the computer digestible binary awesome-sauce that the JVM needs. Below seen in hexadecimal using xxd.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;">thedude<span style="color: pink;">@</span>thedude<span style="color: pink;">-</span>virtual<span style="color: pink;">-</span>machine:~<span style="color: pink;">/</span>hackingjavabytecode$ xxd User.class
0000000: cafe babe 0000 0033 0024 0a00 0700 <span style="color: #804000;">1509</span>  .......<span style="color: #804000;">3</span>.$......
0000010: 0006 0016 0900 <span style="color: #804000;">1700</span> <span style="color: #804000;">1808</span> 0019 0a00 1a00  ................
0000020: 1b07 001c 0700 1d01 0006 <span style="color: #804000;">7374</span> <span style="color: #804000;">6174</span> <span style="color: #804000;">7573</span>  ..........status
0000030: 0100 0149 0100 063c 696e <span style="color: #804000;">6974</span> 3e01 0003  ...I......
0000040: <span style="color: #804000;">2829</span> <span style="color: #804000;">5601</span> 0004 436f <span style="color: #804000;">6465</span> 0100 0f4c 696e  <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>V...Code...Lin
0000050: 654e 756d <span style="color: #804000;">6265</span> <span style="color: #804000;">7254</span> <span style="color: #804000;">6162</span> 6c65 0100 0d73  eNumberTable...s
0000060: <span style="color: #804000;">6574</span> <span style="color: #804000;">5374</span> <span style="color: #804000;">6174</span> <span style="color: #804000;">7573</span> <span style="color: #804000;">5472</span> <span style="color: #804000;">7565</span> 0100 0328  etStatusTrue...<span style="color: #000000;">&#40;</span>
0000070: 295a 0100 0d53 <span style="color: #804000;">7461</span> 636b 4d61 <span style="color: #804000;">7054</span> <span style="color: #804000;">6162</span>  <span style="color: #000000;">&#41;</span>Z...StackMapTab
0000080: 6c65 0100 046d <span style="color: #804000;">6169</span> 6e01 0016 285b 4c6a  le...main...<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Lj
0000090: <span style="color: #804000;">6176</span> 612f 6c61 6e67 2f53 <span style="color: #804000;">7472</span> 696e 673b  ava<span style="color: pink;">/</span>lang<span style="color: pink;">/</span>String;
00000a0: <span style="color: #804000;">2956</span> 0100 0a53 6f75 <span style="color: #804000;">7263</span> <span style="color: #804000;">6546</span> 696c <span style="color: #804000;">6501</span>  <span style="color: #000000;">&#41;</span>V...SourceFile.
00000b0: 0009 <span style="color: #804000;">5573</span> <span style="color: #804000;">6572</span> 2e6a <span style="color: #804000;">6176</span> 610c 000a 000b  ..User.java.....
00000c0: 0c00 0800 0907 001e 0c00 1f00 <span style="color: #804000;">2001</span> 0016  ............ ...
00000d0: <span style="color: #804000;">4861</span> 636b 696e <span style="color: #804000;">6720</span> 4a61 <span style="color: #804000;">7661</span> <span style="color: #804000;">2042</span> <span style="color: #804000;">7974</span>  Hacking Java Byt
00000e0: <span style="color: #804000;">6563</span> 6f64 <span style="color: #804000;">6521</span> 0700 210c 0022 0023 0100  ecode<span style="color: pink;">!</span>..<span style="color: pink;">!</span>..<span style="color: #800000;">&quot;.#..
00000f0: 0455 7365 7201 0010 6a61 7661 2f6c 616e  .User...java/lan
0000100: 672f 4f62 6a65 6374 0100 106a 6176 612f  g/Object...java/
0000110: 6c61 6e67 2f53 7973 7465 6d01 0003 6f75  lang/System...ou
0000120: 7401 0015 4c6a 6176 612f 696f 2f50 7269  t...Ljava/io/Pri
0000130: 6e74 5374 7265 616d 3b01 0013 6a61 7661  ntStream;...java
0000140: 2f69 6f2f 5072 696e 7453 7472 6561 6d01  /io/PrintStream.
0000150: 0007 7072 696e 746c 6e01 0015 284c 6a61  ..println...(Lja
0000160: 7661 2f6c 616e 672f 5374 7269 6e67 3b29  va/lang/String;)
0000170: 5600 2100 0600 0700 0000 0100 0400 0800  V.!.............
0000180: 0900 0000 0300 0100 0a00 0b00 0100 0c00  ................
0000190: 0000 2600 0200 0100 0000 0a2a b700 012a  ..&amp;........*...*
00001a0: 03b5 0002 b100 0000 0100 0d00 0000 0a00  ................
00001b0: 0200 0000 0100 0400 0300 0100 0e00 0f00  ................
00001c0: 0100 0c00 0000 3100 0200 0100 0000 0e2a  ......1........*
00001d0: b400 0204 a000 0704 a700 0403 ac00 0000  ................
00001e0: 0200 0d00 0000 0600 0100 0000 0600 1000  ................
00001f0: 0000 0500 020c 4001 0009 0011 0012 0001  ......@.........
0000200: 000c 0000 0025 0002 0001 0000 0009 b200  .....%..........
0000210: 0312 04b6 0005 b100 0000 0100 0d00 0000  ................
0000220: 0a00 0200 0000 0a00 0800 0b00 0100 1300  ................
0000230: 0000 0200 14</span></pre></td></tr></table></div>

<p>There are two primary things to know concerning compiled Java code.</p>
<p><span class="highlight">The first</span> is that Opcodes or &#8220;Operational Codes&#8221; created by the compiler are simply optimized and formatted instruction sets telling the JVM what to do. In programmer speak, they are <span style="text-decoration: underline;">reserved</span> words that <em>javac</em> created on compilation.</p>
<p>Just for example, lets randomly take a look at byte <em>0&#215;19 </em>found on offset line<em> 0&#215;10</em> when we dumped our <em>User.class </em>file with <em>xxd</em>.</p>
<p><code> 0000010: 0006 0016 0900 1700 1808 00<span style="color: #993366;">19</span> 0a00 1a00 ................<br />
</code></p>
<p>A logical question would be.</p>
<p>&#8220;Jared, how do we know that <em>0&#215;19</em> is an instruction Opcode and how do we know what it actually does? &#8221;</p>
<p>Lucky for us we can use a <a href="http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings">Java Bytecode Reference</a> which tells us that the <em>mnemonic</em> for <em>0&#215;19</em> is <em>aload.  </em></p>
<p>This could lead to the next question.</p>
<p>&#8220;What is a mnemonic?&#8221;</p>
<p>Mnemonics are simply a way of organization. It is the process of taking something hard to remember (<em>0&#215;19</em>) and associating it with something easier to remember (<em>aload</em>). You can think of mnemonics as a simple conversation.</p>
<p>You &#8220;What is the Opcode for <em>aload</em>?&#8221;</p>
<p>Me &#8220;<em>0&#215;19</em> is the Opcode you are looking for.&#8221;</p>
<p>Another way I visualize the functionality of a particular Opcode, is as a simple procedural function. Here is how it could look using Python.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> aload<span style="color: black;">&#40;</span>stack<span style="color: #66cc66;">,</span> pointer<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># load an object onto the stack</span>
    stack.<span style="color: black;">append</span><span style="color: black;">&#40;</span>pointer<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Object loaded!&quot;</span>
&nbsp;
stack <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
pointer <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot;A string pretending to be an object&quot;</span>
aload<span style="color: black;">&#40;</span>stack<span style="color: #66cc66;">,</span> pointer<span style="color: black;">&#41;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>python aload.py 
Object loaded<span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>For now, we are not going to focus on the the low level details of Opcodes. We just need to be aware at a high level, that the JVM creates them upon compilation, that they are super important, and that we don&#8217;t want to accidentally squish them when we attempt to hack on the ASCII text.</p>
<p><span class="highlight">The second</span><strong> </strong>is that we are accessing the binary data using a hexadecimal tool (xxd, Bless). Because of this, we need a comparison of <em>Hacking Java Bytecode! </em>in both ASCII and hexadecimal.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"> H  a  c  k  i  n  g \s  J  a  v  a \s  B  y  t  e  c  o  d  e  <span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #000000;">48</span> <span style="color: #000000;">61</span> <span style="color: #000000;">63</span> 6B <span style="color: #000000;">69</span> 6E <span style="color: #000000;">67</span> <span style="color: #000000;">20</span> 4A <span style="color: #000000;">61</span> <span style="color: #000000;">76</span> <span style="color: #000000;">61</span> <span style="color: #000000;">20</span> <span style="color: #000000;">42</span> <span style="color: #000000;">79</span> <span style="color: #000000;">74</span> <span style="color: #000000;">65</span> <span style="color: #000000;">63</span> 6F <span style="color: #000000;">64</span> <span style="color: #000000;">65</span> <span style="color: #000000;">21</span></pre></td></tr></table></div>

<p>Each hexadecimal number correspondes with the letter or special character in the example above. Also, an important tool you will rely on is a <a href="  http://www.ltg.ed.ac.uk/~richard/utf-8.cgi">good calculator</a> that easily converts ASCII, Binary, and Hexadecimal.</p>
<h2>Bring on the hack</h2>
<p>Now, even though the data is no longer ideal for human consumption or manipulation, this doesn&#8217;t mean we are actually prevented from hacking on it. It just means it will take a bit more work.</p>
<p>Take a look at these three lines from the <em><strong>xxd</strong></em> output of our User.class file.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">00000c0: 0c00 0800 0907 001e 0c00 1f00 <span style="color: #000000;">2001</span> 0016  ............ ...
00000d0: <span style="color: #000000;">4861</span> 636b 696e <span style="color: #000000;">6720</span> 4a61 <span style="color: #000000;">7661</span> <span style="color: #000000;">2042</span> <span style="color: #000000;">7974</span>  Hacking Java Byt
00000e0: <span style="color: #000000;">6563</span> 6f64 <span style="color: #000000;">6521</span> 0700 210c 0022 0023 0100  ecode<span style="color: #000000; font-weight: bold;">!</span>..<span style="color: #000000; font-weight: bold;">!</span>..<span style="color: #ff0000;">&quot;.#..</span></pre></td></tr></table></div>

<p>You&#8217;ll notice that ASCII has been printed on the right, showing us these lines contain the data we are trying to manipulate.</p>
<p>Lets open up the <em><strong>User.class</strong></em> file with Bless. I&#8217;ve taken the liberty of highlighting the lines of interest in Bless.</p>
<p><a href="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-15-at-11.22.56-AM.png"><img class="aligncenter size-full wp-image-1665" alt="User.class" src="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-15-at-11.22.56-AM.png" width="763" height="782" /></a></p>
<p>You can use a tool like the <a href="http://www.string-functions.com/string-hex.aspx">following</a> or hexdump from the command line to convert your string to hex.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;l33t hax0r bro&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">hexdump</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/1 &quot;%02X &quot;'</span> ; <span style="color: #7a0874; font-weight: bold;">echo</span>
6C <span style="color: #000000;">33</span> <span style="color: #000000;">33</span> <span style="color: #000000;">74</span> <span style="color: #000000;">20</span> <span style="color: #000000;">68</span> <span style="color: #000000;">61</span> <span style="color: #000000;">78</span> <span style="color: #000000;">30</span> <span style="color: #000000;">72</span> <span style="color: #000000;">20</span> <span style="color: #000000;">62</span> <span style="color: #000000;">72</span> 6F
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>This means we need to replace the hexadecimal for <strong><em>Hacking Java Bytecode!</em></strong>  (48 61 63 6B 69 6E 67 20 4A 61 76 61 20 42 79 74 65 63 6F 64 65 21) with the hexadecimal for <strong><em>l33t hax0r bro</em></strong> (6C 33 33 74 20 68 61 78 30 72 20 62 72 6F).</p>
<p>Go ahead and run the program again.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>java User 
Hacking Java Bytecode<span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>Now take the output of the previous hexdump from <em>l33t hax0r bro</em> and paste it over the hex for <em>Hacking Java Bytecode!</em> in Bless.</p>
<p><a href="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-8.52.14-AM.png"><img class="aligncenter size-full wp-image-1681" alt="User.class after hack" src="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-8.52.14-AM.png" width="762" height="784" /></a></p>
<p>Now run your program again.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>java User
Exception <span style="color: #000000; font-weight: bold;">in</span> thread <span style="color: #ff0000;">&quot;main&quot;</span> java.lang.ClassFormatError: Illegal UTF8 string <span style="color: #000000; font-weight: bold;">in</span> constant pool <span style="color: #000000; font-weight: bold;">in</span> class <span style="color: #c20cb9; font-weight: bold;">file</span> User
	at java.lang.ClassLoader.defineClass1<span style="color: #7a0874; font-weight: bold;">&#40;</span>Native Method<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.lang.ClassLoader.defineClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>ClassLoader.java:<span style="color: #000000;">787</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.security.SecureClassLoader.defineClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>SecureClassLoader.java:<span style="color: #000000;">142</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.net.URLClassLoader.defineClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>URLClassLoader.java:<span style="color: #000000;">447</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.net.URLClassLoader.access<span style="color: #007800;">$1</span>00<span style="color: #7a0874; font-weight: bold;">&#40;</span>URLClassLoader.java:<span style="color: #000000;">71</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.net.URLClassLoader<span style="color: #007800;">$1</span>.run<span style="color: #7a0874; font-weight: bold;">&#40;</span>URLClassLoader.java:<span style="color: #000000;">361</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.net.URLClassLoader<span style="color: #007800;">$1</span>.run<span style="color: #7a0874; font-weight: bold;">&#40;</span>URLClassLoader.java:<span style="color: #000000;">355</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.security.AccessController.doPrivileged<span style="color: #7a0874; font-weight: bold;">&#40;</span>Native Method<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.net.URLClassLoader.findClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>URLClassLoader.java:<span style="color: #000000;">354</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.lang.ClassLoader.loadClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>ClassLoader.java:<span style="color: #000000;">423</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at sun.misc.Launcher<span style="color: #007800;">$AppClassLoader</span>.loadClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>Launcher.java:<span style="color: #000000;">308</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at java.lang.ClassLoader.loadClass<span style="color: #7a0874; font-weight: bold;">&#40;</span>ClassLoader.java:<span style="color: #000000;">356</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	at sun.launcher.LauncherHelper.checkAndLoadMain<span style="color: #7a0874; font-weight: bold;">&#40;</span>LauncherHelper.java:<span style="color: #000000;">482</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>Doh! What happened?</p>
<p>It is rather simple. When you compiled <em><strong>User.class</strong></em> using <em><strong>javac</strong></em>, the compiler took a count of all the characters in that string and prepended a value in hexadecimal to help validate the strings length.</p>
<p>Let&#8217;s count the characters.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #000000;">1</span>  <span style="color: #000000;">2</span>  <span style="color: #000000;">3</span>  <span style="color: #000000;">4</span>  <span style="color: #000000;">5</span>  <span style="color: #000000;">6</span>  <span style="color: #000000;">7</span>  <span style="color: #000000;">8</span>  <span style="color: #000000;">9</span> <span style="color: #000000;">10</span> <span style="color: #000000;">11</span> <span style="color: #000000;">12</span> <span style="color: #000000;">13</span> <span style="color: #000000;">14</span> <span style="color: #000000;">15</span> <span style="color: #000000;">16</span> <span style="color: #000000;">17</span> <span style="color: #000000;">18</span> <span style="color: #000000;">19</span> <span style="color: #000000;">20</span> <span style="color: #000000;">21</span> <span style="color: #000000;">22</span>
 H  a  c  k  i  n  g \s  J  a  v  a \s  B  y  t  e  c  o  d  e  <span style="color: #000000; font-weight: bold;">!</span></pre></td></tr></table></div>

<p>This shows us that our original string has twenty-two characters and if we convert the number 22 to hexadecimal we get 0&#215;16. And if you look at the beginning of our line in Bless, you will see that exact value.</p>
<p><a href="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-9.31.45-AM.png"><img class="aligncenter size-full wp-image-1683" alt="Screen Shot 2013-05-17 at 9.31.45 AM" src="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-9.31.45-AM.png" width="763" height="781" /></a></p>
<p>The problem is that now we have changed that string. Which means we need to also change that character count to match the new string.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #000000;">1</span>  <span style="color: #000000;">2</span>  <span style="color: #000000;">3</span>  <span style="color: #000000;">4</span>  <span style="color: #000000;">5</span>  <span style="color: #000000;">6</span>  <span style="color: #000000;">7</span>  <span style="color: #000000;">8</span>  <span style="color: #000000;">9</span> <span style="color: #000000;">10</span> <span style="color: #000000;">11</span> <span style="color: #000000;">12</span> <span style="color: #000000;">13</span> <span style="color: #000000;">14</span>
 l  <span style="color: #000000;">3</span>  <span style="color: #000000;">3</span>  t \s  h  a  x  <span style="color: #000000;">0</span>  r \s  b  r  o</pre></td></tr></table></div>

<p>You can see that our new string has fourteen characters. So if we convert 14 to hexadecimal we get 0x0E. Now you just need to replace that <em><strong>0&#215;16</strong></em> byte with the <em><strong>0x0E</strong></em> byte and save the file.</p>
<p><a href="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-9.34.56-AM.png"><img class="aligncenter size-full wp-image-1684" alt="Screen Shot 2013-05-17 at 9.34.56 AM" src="http://www.acloudtree.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-9.34.56-AM.png" width="764" height="786" /></a></p>
<p>Run the command again!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>java User
l33t hax0r bro
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>Success!!!</p>
<h2>Conclusion</h2>
<p>You should now have a decent understanding of JavaBytecode, High Level comprehension concerning Java Opcodes, and the ability to manipulate basic strings inside of compiled source.</p>
<p>In our next installment we are going to talk about more advanced techniques in how to bypass certain code blocks by manipulating the Bytecode directly. We will also start discussing tools that will help us in our effort of reverse engineering.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/lions-and-tiger-and-op-codes-oh-my-hacking-java-bytecode-for-programmers-part2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The Birds and the Bees of Hex Editing &#8211; Hacking Java Bytecode for Programmers (Part1)</title>
		<link>http://www.acloudtree.com/the-birds-and-the-bees-of-hex-editing-hacking-java-bytecode-for-programmers-part1/</link>
		<comments>http://www.acloudtree.com/the-birds-and-the-bees-of-hex-editing-hacking-java-bytecode-for-programmers-part1/#comments</comments>
		<pubDate>Tue, 14 May 2013 17:24:17 +0000</pubDate>
		<dc:creator>jared folkins</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bytecode]]></category>
		<category><![CDATA[Editing]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[Hex]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=1471</guid>
		<description><![CDATA[At the end of May I am invited to speak at a local user group about Java bytecode hacking. I figured it would BE beneficial to get my thoughts down concerning this topic. Therefore, you my friends, are my guinea pigs. Yay! If you find a mistake, email, comment, whatever,...<p style="text-align:center;"><a class="more-link" href="http://www.acloudtree.com/the-birds-and-the-bees-of-hex-editing-hacking-java-bytecode-for-programmers-part1/">Click to Load</a></p>]]></description>
				<content:encoded><![CDATA[<div class="intro">At the end of May I am invited to speak at a local user group about Java bytecode hacking. I figured it would BE beneficial to get my thoughts down concerning this topic. Therefore, you my friends, are my guinea pigs. Yay! If you find a mistake, email, comment, whatever, so that I can improve the flow. Werd.</div>
<h2>Tools &amp; References</h2>
<ul>
<li>Ubuntu 12.10</li>
<li>Java 1.7.0_15</li>
<li>Python 2.7</li>
<li>xxd</li>
<li>Bless Hex Editor</li>
<li>Jd-gui</li>
<li>http://en.wikipedia.org/wiki/Java_bytecode</li>
<li>http://en.wikipedia.org/wiki/Hexadecimal</li>
<li>http://linuxcommand.org/man_pages/xxd1.html</li>
</ul>
<h2>Audience</h2>
<p>Required &#8211; You should be comfortable in Linux ( 1+ years )<br />
Required &#8211; You should be comfortable writing scripts ( 1+ years )<br />
Desired &#8211; You have written web, desktop, or mobile applications ( 1+ years )<br />
Desired &#8211; You have programmed in Java and Python ( 6 months )</p>
<h2>What is Hexadecimal?</h2>
<p>Computers execute binary code. But neck beards were fairly frustrated when editing a binary file and having to parse and edit huge number blocks of ones and zeros. The internet tells me that IBM came along and formalized a hexadecimal standard in the 1950s to pacify their geeks.</p>
<p>Wikipedia puts it nicely.</p>
<p><em><span style="display: inline !important;">&#8220;t</span></em><em><span style="display: inline !important;">he primary use of hexadecimal notation is a human-friendly representation of binary-coded values&#8221;</span></em></p>
<p>Essentially, hexadecimal makes it much easier to read and edit binary data.</p>
<h2>What is a Hex Editor?</h2>
<p>A Hex Editor is a handy program that makes editing binary data easier. We will use xxd from the command line. But later we will use Bless which is a GUI Hex editing program.</p>
<h2>What is Java Bytecode?</h2>
<p><span class="highlight">Bytecode is compiled Java code that the JVM (Java Virtual Machine) executes.</span></p>
<p>That simplistic syllabus doesn&#8217;t really tell you much so lets actually show you what is up.</p>
<p>Say you have a <strong><em>User.java</em> </strong>class file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> status <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> setStatusTrue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">status</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hacking Java Bytecode!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now lets compile it with the Java compiler <strong><em>javac</em></strong>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>javac User.java</pre></td></tr></table></div>

<p>This will create a compiled <strong><em>User.class</em></strong> file containing data.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span><span style="color: #c20cb9; font-weight: bold;">ls</span>
User.class  User.java
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>Now lets run the program.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>java User 
Hacking Java Bytecode<span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>But lets actually take a look at the <em><strong>User.class</strong></em> file by dumping it with <em><strong>cat</strong></em>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span><span style="color: #c20cb9; font-weight: bold;">cat</span> User.class 
����<span style="color: #000000;">3</span>$
		
StackMapTablemain<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Ljava<span style="color: #000000; font-weight: bold;">/</span>lang<span style="color: #000000; font-weight: bold;">/</span>String;<span style="color: #7a0874; font-weight: bold;">&#41;</span>VrTable
SourceFile	User.java
&nbsp;
	
          Hacking Java Bytecode<span style="color: #000000; font-weight: bold;">!!</span>
                                    <span style="color: #ff0000;">&quot;#Userjava/lang/Objectjava/lang/SystemoutLjava/io/PrintStream;java/io/PrintStreamprintln(Ljava/lang/String;)V!
&nbsp;

 &amp;amp;
*�*��

 1*����
     @	
           %	���

&nbsp;
thedude$</span></pre></td></tr></table></div>

<p>Well that sucks. What we need to do instead is dump the <strong><em>User.class</em></strong> file with the command line hexadecimal application <strong><em>xxd.</em></strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>xxd User.class 
0000000: cafe babe 0000 0033 0016 0a00 0400 <span style="color: #000000;">1209</span>  .......<span style="color: #000000;">3</span>........
0000010: 0003 0013 0700 <span style="color: #000000;">1407</span> 0015 0100 0673 <span style="color: #000000;">7461</span>  .............sta
0000020: <span style="color: #000000;">7475</span> <span style="color: #000000;">7301</span> 0001 <span style="color: #000000;">4901</span> 0006 3c69 6e69 743e  tus...I...
0000030: 0100 0328 <span style="color: #000000;">2956</span> 0100 0443 6f64 <span style="color: #000000;">6501</span> 000f  ...<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>V...Code...
0000040: 4c69 6e65 4e75 6d62 <span style="color: #000000;">6572</span> <span style="color: #000000;">5461</span> 626c <span style="color: #000000;">6501</span>  LineNumberTable.
0000050: 000d <span style="color: #000000;">7365</span> <span style="color: #000000;">7453</span> <span style="color: #000000;">7461</span> <span style="color: #000000;">7475</span> <span style="color: #000000;">7354</span> <span style="color: #000000;">7275</span> <span style="color: #000000;">6501</span>  ..setStatusTrue.
0000060: 0003 <span style="color: #000000;">2829</span> 5a01 000d <span style="color: #000000;">5374</span> <span style="color: #000000;">6163</span> 6b4d <span style="color: #000000;">6170</span>  ..<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>Z...StackMap
0000070: <span style="color: #000000;">5461</span> 626c <span style="color: #000000;">6501</span> 0004 6d61 696e 0100 <span style="color: #000000;">1628</span>  Table...main...<span style="color: #7a0874; font-weight: bold;">&#40;</span>
0000080: 5b4c 6a61 <span style="color: #000000;">7661</span> 2f6c 616e 672f <span style="color: #000000;">5374</span> <span style="color: #000000;">7269</span>  <span style="color: #7a0874; font-weight: bold;">&#91;</span>Ljava<span style="color: #000000; font-weight: bold;">/</span>lang<span style="color: #000000; font-weight: bold;">/</span>Stri
0000090: 6e67 3b29 <span style="color: #000000;">5601</span> 000a 536f <span style="color: #000000;">7572</span> <span style="color: #000000;">6365</span> <span style="color: #000000;">4669</span>  ng;<span style="color: #7a0874; font-weight: bold;">&#41;</span>V...SourceFi
00000a0: 6c65 0100 0955 <span style="color: #000000;">7365</span> 722e 6a61 <span style="color: #000000;">7661</span> 0c00  le...User.java..
00000b0: 0700 080c 0005 0006 0100 0455 <span style="color: #000000;">7365</span> <span style="color: #000000;">7201</span>  ...........User.
00000c0: 0010 6a61 <span style="color: #000000;">7661</span> 2f6c 616e 672f 4f62 6a65  ..java<span style="color: #000000; font-weight: bold;">/</span>lang<span style="color: #000000; font-weight: bold;">/</span>Obje
00000d0: <span style="color: #000000;">6374</span> 0021 0003 0004 0000 0001 0004 0005  ct.<span style="color: #000000; font-weight: bold;">!</span>............
00000e0: 0006 0000 0003 0001 0007 0008 0001 0009  ................
00000f0: 0000 0026 0002 0001 0000 000a 2ab7 0001  ...<span style="color: #000000; font-weight: bold;">&amp;</span>amp;........<span style="color: #000000; font-weight: bold;">*</span>...
0000100: 2a03 b500 02b1 0000 0001 000a 0000 000a  <span style="color: #000000; font-weight: bold;">*</span>...............
0000110: 0002 0000 0001 0004 0003 0001 000b 000c  ................
0000120: 0001 0009 0000 0031 0002 0001 0000 000e  .......<span style="color: #000000;">1</span>........
0000130: 2ab4 0002 04a0 0007 04a7 0004 03ac 0000  <span style="color: #000000; font-weight: bold;">*</span>...............
0000140: 0002 000a 0000 0006 0001 0000 0006 000d  ................
0000150: 0000 0005 0002 0c40 0100 0900 0e00 0f00  .......<span style="color: #000000; font-weight: bold;">@</span>........
0000160: 0100 0900 0000 <span style="color: #000000;">1900</span> 0000 0100 0000 01b1  ................
0000170: 0000 0001 000a 0000 0006 0001 0000 000b  ................
0000180: 0001 0010 0000 0002 0011                 ..........
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>Voila! Much better. A hex dump containing bytecode. Right?! RIGHT?!?</p>
<p>Well, kinda. If you are a newb (don&#8217;t worry, everyone is, we are all just faking it) then there are three distinct logical groupings to account for.</p>
<h1>Hexcode Viewer Breakdown</h1>
<p><strong><span style="color: #9f9f03;">The Offset</span></strong> is on the left and is not part of the file but rather derived from the Hex editing/dumping application. You can think of the offset as the <span style="text-decoration: underline;">line number</span> of a hex dump. Kind of like when you edit the source code of a file.</p>
<p>In the middle is the <span style="color: #800000;"><strong>Bytecode</strong></span> represented using Hexadecimal. This is the actual data of the file we are editing. Eventually this is the portion we will manipulate to change our application&#8217;s behavior.</p>
<p>Finally there is<span style="color: #0082a3;"><strong> the ASCII viewer</strong></span> on the right.The viewer tries its best to display ASCII when it detects and decodes the text in the file. When it can decode the ASCII text correctly, you wil find it displayed. At times though ASCII cannot be rendered. Here you&#8217;ll usually see a dot &#8220;.&#8221; indicating a special character.</p>
<p><a href="http://www.acloudtree.com/wp-content/uploads/2013/05/bytecode_highlights.png"><img class="aligncenter size-full wp-image-1498" alt="bytecode_highlights" src="http://www.acloudtree.com/wp-content/uploads/2013/05/bytecode_highlights.png" width="481" height="451" /></a></p>
<p>&nbsp;</p>
<h1>Hexcode Viewer Gotcha</h1>
<p>Unlike source code where the line number &#8220;1&#8243; is always going to be the line number &#8220;1&#8243;, you can <span style="text-decoration: underline;">change</span> the offset of your hex editor. Having the correct offset is critical. In my opinion, a problem with some GUI hex editors is that when you resize your editor window, most of them will automagically adjust the offset.</p>
<p>To illustrate this, here is the default <em><strong>xxd</strong></em> output of our<strong> <em>User.class</em></strong> file using 16 columns as well as the output of xxd using 10 columns. This should prove that nothing has fundamentally changed about the bytecode data stored in our file. The only thing that has changed is the way the data is being displayed.</p>
<p>(I&#8217;ve <strong>bolded</strong>, <em>italicized</em>, and highlighted the exact same byte in <span style="color: #00ccff;">blue</span>.)</p>
<p><code>thedude$ xxd User.class<br />
0000000: cafe babe 0000 0033 0016 0a00 0400 1209 .......3........<br />
0000010: 0003 0013 0700 1407 0015 0100 0673 7461 .............sta<br />
0000020: 7475 7301 0001 4901 0006 3c69 6e69 743e tus...I...<br />
<strong><em>0000030: 0100 0328 29<span style="color: #00ccff;">56</span> 0100 0443 6f64 6501 000f ...()V...Code...</em></strong><br />
0000040: 4c69 6e65 4e75 6d62 6572 5461 626c 6501 LineNumberTable.<br />
0000050: 000d 7365 7453 7461 7475 7354 7275 6501 ..setStatusTrue.<br />
0000060: 0003 2829 5a01 000d 5374 6163 6b4d 6170 ..()Z...StackMap<br />
0000070: 5461 626c 6501 0004 6d61 696e 0100 1628 Table...main...(<br />
0000080: 5b4c 6a61 7661 2f6c 616e 672f 5374 7269 [Ljava/lang/Stri<br />
0000090: 6e67 3b29 5601 000a 536f 7572 6365 4669 ng;)V...SourceFi<br />
00000a0: 6c65 0100 0955 7365 722e 6a61 7661 0c00 le...User.java..<br />
00000b0: 0700 080c 0005 0006 0100 0455 7365 7201 ...........User.<br />
00000c0: 0010 6a61 7661 2f6c 616e 672f 4f62 6a65 ..java/lang/Obje<br />
00000d0: 6374 0021 0003 0004 0000 0001 0004 0005 ct.!............<br />
00000e0: 0006 0000 0003 0001 0007 0008 0001 0009 ................<br />
00000f0: 0000 0026 0002 0001 0000 000a 2ab7 0001 ...&amp;........*...<br />
0000100: 2a03 b500 02b1 0000 0001 000a 0000 000a *...............<br />
0000110: 0002 0000 0001 0004 0003 0001 000b 000c ................<br />
0000120: 0001 0009 0000 0031 0002 0001 0000 000e .......1........<br />
0000130: 2ab4 0002 04a0 0007 04a7 0004 03ac 0000 *...............<br />
0000140: 0002 000a 0000 0006 0001 0000 0006 000d ................<br />
0000150: 0000 0005 0002 0c40 0100 0900 0e00 0f00 .......@........<br />
0000160: 0100 0900 0000 1900 0000 0100 0000 01b1 ................<br />
0000170: 0000 0001 000a 0000 0006 0001 0000 000b ................<br />
0000180: 0001 0010 0000 0002 0011 ..........<br />
thedude$</code></p>
<p><code>thedude$ xxd -c 10 User.class<br />
0000000: cafe babe 0000 0033 0016 .......3..<br />
000000a: 0a00 0400 1209 0003 0013 ..........<br />
0000014: 0700 1407 0015 0100 0673 .........s<br />
000001e: 7461 7475 7301 0001 4901 tatus...I.<br />
0000028: 0006 3c69 6e69 743e 0100 ....<br />
<strong><em>0000032: 0328 29<span style="color: #00ccff;">56</span> 0100 0443 6f64 .()V...Cod</em></strong><br />
000003c: 6501 000f 4c69 6e65 4e75 e...LineNu<br />
0000046: 6d62 6572 5461 626c 6501 mberTable.<br />
0000050: 000d 7365 7453 7461 7475 ..setStatu<br />
000005a: 7354 7275 6501 0003 2829 sTrue...()<br />
0000064: 5a01 000d 5374 6163 6b4d Z...StackM<br />
000006e: 6170 5461 626c 6501 0004 apTable...<br />
0000078: 6d61 696e 0100 1628 5b4c main...([L<br />
0000082: 6a61 7661 2f6c 616e 672f java/lang/<br />
000008c: 5374 7269 6e67 3b29 5601 String;)V.<br />
0000096: 000a 536f 7572 6365 4669 ..SourceFi<br />
00000a0: 6c65 0100 0955 7365 722e le...User.<br />
00000aa: 6a61 7661 0c00 0700 080c java......<br />
00000b4: 0005 0006 0100 0455 7365 .......Use<br />
00000be: 7201 0010 6a61 7661 2f6c r...java/l<br />
00000c8: 616e 672f 4f62 6a65 6374 ang/Object<br />
00000d2: 0021 0003 0004 0000 0001 .!........<br />
00000dc: 0004 0005 0006 0000 0003 ..........<br />
00000e6: 0001 0007 0008 0001 0009 ..........<br />
00000f0: 0000 0026 0002 0001 0000 ...&amp;......<br />
00000fa: 000a 2ab7 0001 2a03 b500 ..*...*...<br />
0000104: 02b1 0000 0001 000a 0000 ..........<br />
000010e: 000a 0002 0000 0001 0004 ..........<br />
0000118: 0003 0001 000b 000c 0001 ..........<br />
0000122: 0009 0000 0031 0002 0001 .....1....<br />
000012c: 0000 000e 2ab4 0002 04a0 ....*.....<br />
0000136: 0007 04a7 0004 03ac 0000 ..........<br />
0000140: 0002 000a 0000 0006 0001 ..........<br />
000014a: 0000 0006 000d 0000 0005 ..........<br />
0000154: 0002 0c40 0100 0900 0e00 ...@......<br />
000015e: 0f00 0100 0900 0000 1900 ..........<br />
0000168: 0000 0100 0000 01b1 0000 ..........<br />
0000172: 0001 000a 0000 0006 0001 ..........<br />
000017c: 0000 000b 0001 0010 0000 ..........<br />
0000186: 0002 0011 ....<br />
thedude$</code></p>
<h1>How I (a programmer) think about Bytecode</h1>
<p>How I like to think about Bytecode is usually in two ways.</p>
<h2>(1)</h2>
<p>If I&#8217;m operating in a Hex editing application I usually just think of the bytecode as a <em>multidimensional</em> array.</p>
<p>Lets take a look at the first two lines of our <strong><em>User.class</em></strong> dumped using 16 column formatting.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">0000000: cafe babe 0000 0033 0016 0a00 0400 <span style="color: #000000;">1209</span>  .......<span style="color: #000000;">3</span>........
0000010: 0003 0013 0700 <span style="color: #000000;">1407</span> 0015 0100 0673 <span style="color: #000000;">7461</span>  .............sta</pre></td></tr></table></div>

<p>Then lets strip out the <strong><span style="color: #989e04;">Offset</span></strong> and the <strong><span style="color: #0082a3;">ASCII</span></strong> text.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">cafe babe 0000 0033 0016 0a00 0400 <span style="color: #000000;">1209</span>
0003 0013 0700 <span style="color: #000000;">1407</span> 0015 0100 0673 <span style="color: #000000;">7461</span></pre></td></tr></table></div>

<p>And finally we take those bytes and create a multidimensional array using Python to illustrate this.</p>
<h4>Python</h4>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">bytecode_multi_array = <span style="color:#006600; font-weight:bold;">&#91;</span>
  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'ca'</span>,<span style="color:#996600;">'fe'</span>,<span style="color:#996600;">'ba'</span>,<span style="color:#996600;">'be'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'33'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'16'</span>,<span style="color:#996600;">'0a'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'04'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'12'</span>,<span style="color:#996600;">'09'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'00'</span>,<span style="color:#996600;">'03'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'13'</span>,<span style="color:#996600;">'07'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'14'</span>,<span style="color:#996600;">'07'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'15'</span>,<span style="color:#996600;">'01'</span>,<span style="color:#996600;">'00'</span>,<span style="color:#996600;">'06'</span>,<span style="color:#996600;">'73'</span>,<span style="color:#996600;">'74'</span>,<span style="color:#996600;">'61'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#008000; font-style:italic;"># print array 0 which is actually the first line of our bytecode dump </span>
<span style="color:#CC0066; font-weight:bold;">print</span> bytecode_multi_array<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<h2> (2)</h2>
<p>The other way is a bit more hardcore. I simply just visualize the bytecode stream.</p>
<p>Take this <em><strong>bytecode_stream.py</strong></em> script I wrote.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
_directory <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'./'</span>
_file <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'User.class'</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>_directory<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>_file<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;rb&quot;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> f:
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;read file: %s&quot;</span> % _file
                stream <span style="color: #66cc66;">=</span> f.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                f.<span style="color: black;">close</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;print the bytecode stream&quot;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> stream.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'hex'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>If you run it from the same directory that our<strong> <em>User.class</em></strong> file is stored in you&#8217;ll get the following.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">thedude$ </span>python bytecode_stream.py 
<span style="color: #c20cb9; font-weight: bold;">read</span> file: User.class
print the bytecode stream
cafebabe0000003300160a000400120900030013070014070015010006737461747573010001490100063c696e69743e010003282956010004436f646501000f4c696e654e756d6265725461626c6501000d7365745374617475735472756501000328295a01000d537461636b4d61705461626c650100046d61696e010016285b4c6a6176612f6c616e672f537472696e673b295601000a536f7572636546696c65010009557365722e6a6176610c000700080c00050006010004557365720100106a6176612f6c616e672f4f626a65637400210003000400000001000400050006000000030001000700080001000900000026000200010000000a2ab700012a03b50002b100000001000a0000000a000200000001000400030001000b000c0001000900000031000200010000000e2ab4000204a0000704a7000403ac00000002000a00000006000100000006000d0000000500020c40010009000e000f00010009000000190000000100000001b100000001000a0000000600010000000b00010010000000020011
<span style="color: #666666;">thedude$</span></pre></td></tr></table></div>

<p>Essentially the bytecode is just one long string.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">cafebabe0000003300160a000400120900030013070014070015010006737461747573010001490100063c696e69743e010003282956010004436f646501000f4c696e654e756d6265725461626c6501000d7365745374617475735472756501000328295a01000d537461636b4d61705461626c650100046d61696e010016285b4c6a6176612f6c616e672f537472696e673b295601000a536f7572636546696c65010009557365722e6a6176610c000700080c00050006010004557365720100106a6176612f6c616e672f4f626a65637400210003000400000001000400050006000000030001000700080001000900000026000200010000000a2ab700012a03b50002b100000001000a0000000a000200000001000400030001000b000c0001000900000031000200010000000e2ab4000204a0000704a7000403ac00000002000a00000006000100000006000d0000000500020c40010009000e000f00010009000000190000000100000001b100000001000a0000000600010000000b00010010000000020011</pre></td></tr></table></div>

<h1>Conclusion</h1>
<p>Hopefully you have a decent understanding on how to view compiled Java Bytecode using the hex dumping program <em><strong>xxd</strong></em>.</p>
<p>You also should understand how, when using Python, we opened the compiled Java Bytecode file and dumped it to screen in hex format. We will be using Python to do some hacking in the future.</p>
<p>In Part 2 we will take a look at Java Op codes and actually manipulating the compiled Bytecode by hand using a hex editor.</p>
<h2></h2>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/the-birds-and-the-bees-of-hex-editing-hacking-java-bytecode-for-programmers-part1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To: Remove index.php from owncloud url path</title>
		<link>http://www.acloudtree.com/how-to-remove-index-php-from-owncloud-url-path/</link>
		<comments>http://www.acloudtree.com/how-to-remove-index-php-from-owncloud-url-path/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 22:50:42 +0000</pubDate>
		<dc:creator>jared folkins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=1462</guid>
		<description><![CDATA[When installing owncloud on your own server, the path looks pretty crappy. I&#8217;d like to change it from this. https://example.com/owncloud/index.php/apps/files To this. https://example.com/owncloud/apps/files To do this, you need to make sure mod_rewrite is enabled and change the .htaccess in the ROOT directory (example: /var/www/html/owncloud/) Change it from this. ...snip... &#160;...<p style="text-align:center;"><a class="more-link" href="http://www.acloudtree.com/how-to-remove-index-php-from-owncloud-url-path/">Click to Load</a></p>]]></description>
				<content:encoded><![CDATA[<p>When installing owncloud on your own server, the path looks pretty crappy.</p>
<p>I&#8217;d like to change it from this.</p>
<h5>https://example.com/owncloud/index.php/apps/files</h5>
<p>To this.</p>
<h5>https://example.com/owncloud/apps/files</h5>
<p>To do this, you need to make sure mod_rewrite is enabled and change the .htaccess in the ROOT directory (example: /var/www/html/owncloud/)</p>
<p>Change it from this.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">...snip...
&nbsp;
RewriteEngine on
RewriteRule .<span style="color: #000000; font-weight: bold;">*</span> - <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">env</span>=HTTP_AUTHORIZATION:<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP:Authorization<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>host-meta <span style="color: #000000; font-weight: bold;">/</span>public.php?<span style="color: #007800;">service</span>=host-meta <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>host-meta.json <span style="color: #000000; font-weight: bold;">/</span>public.php?<span style="color: #007800;">service</span>=host-meta-json <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>carddav <span style="color: #000000; font-weight: bold;">/</span>remote.php<span style="color: #000000; font-weight: bold;">/</span>carddav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>R<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>caldav <span style="color: #000000; font-weight: bold;">/</span>remote.php<span style="color: #000000; font-weight: bold;">/</span>caldav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>R<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^apps<span style="color: #000000; font-weight: bold;">/</span>calendar<span style="color: #000000; font-weight: bold;">/</span>caldav.php remote.php<span style="color: #000000; font-weight: bold;">/</span>caldav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^apps<span style="color: #000000; font-weight: bold;">/</span>contacts<span style="color: #000000; font-weight: bold;">/</span>carddav.php remote.php<span style="color: #000000; font-weight: bold;">/</span>carddav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>^<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span>css<span style="color: #000000; font-weight: bold;">|</span>php<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>$ index.php?<span style="color: #007800;">app</span>=<span style="color: #007800;">$1</span><span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #007800;">getfile</span>=<span style="color: #007800;">$2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^remote<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> remote.php <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
...snip...</pre></td></tr></table></div>

<p>Add the one line.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">...snip...
&nbsp;
RewriteEngine on
RewriteRule .<span style="color: #000000; font-weight: bold;">*</span> - <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">env</span>=HTTP_AUTHORIZATION:<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>HTTP:Authorization<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>host-meta <span style="color: #000000; font-weight: bold;">/</span>public.php?<span style="color: #007800;">service</span>=host-meta <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>host-meta.json <span style="color: #000000; font-weight: bold;">/</span>public.php?<span style="color: #007800;">service</span>=host-meta-json <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>carddav <span style="color: #000000; font-weight: bold;">/</span>remote.php<span style="color: #000000; font-weight: bold;">/</span>carddav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>R<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^.well-known<span style="color: #000000; font-weight: bold;">/</span>caldav <span style="color: #000000; font-weight: bold;">/</span>remote.php<span style="color: #000000; font-weight: bold;">/</span>caldav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>R<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^apps<span style="color: #000000; font-weight: bold;">/</span>calendar<span style="color: #000000; font-weight: bold;">/</span>caldav.php remote.php<span style="color: #000000; font-weight: bold;">/</span>caldav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^apps<span style="color: #000000; font-weight: bold;">/</span>contacts<span style="color: #000000; font-weight: bold;">/</span>carddav.php remote.php<span style="color: #000000; font-weight: bold;">/</span>carddav<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>^<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span>css<span style="color: #000000; font-weight: bold;">|</span>php<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>$ index.php?<span style="color: #007800;">app</span>=<span style="color: #007800;">$1</span><span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #007800;">getfile</span>=<span style="color: #007800;">$2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
RewriteRule ^remote<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> remote.php <span style="color: #7a0874; font-weight: bold;">&#91;</span>QSA,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
RewriteRule ^index.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
...snip...</pre></td></tr></table></div>

<p>Then you will need to restart apache.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/how-to-remove-index-php-from-owncloud-url-path/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to: Configure Burp and Chrome for HTTPS (SSL) packet inspection and web site debugging on Mac OSX</title>
		<link>http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/</link>
		<comments>http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 00:49:49 +0000</pubDate>
		<dc:creator>jared folkins</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[burp]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[sniffing]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[traffic]]></category>

		<guid isPermaLink="false">http://www.acloudtree.com/?p=1330</guid>
		<description><![CDATA[Use Case You are troubleshooting a web application and want to see the data being sent. You think you can&#8217;t because it is encrypted with SSL. You totally can bro/bro-dette. You to-tal-ly can. Download BURP (the free edition is fine) http://www.portswigger.net/burp/download.html Using Chrome, install zx2c4&#8242;s quick and dirty proxy flipper...<p style="text-align:center;"><a class="more-link" href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/">Click to Load</a></p>]]></description>
				<content:encoded><![CDATA[<h3>Use Case</h3>
<p>You are troubleshooting a web application and want to see the data being sent. You think you can&#8217;t because it is encrypted with SSL. You totally can bro/bro-dette. You to-tal-ly can.</p>
<h3>Download BURP (the free edition is fine)</h3>
<p><a href="http://www.portswigger.net/burp/download.html">http://www.portswigger.net/burp/download.html</a></p>
<h3>Using Chrome, install zx2c4&#8242;s quick and dirty proxy flipper</h3>
<p><a href="https://chrome.google.com/webstore/detail/quick-dirty-proxy-flipper/lbhdjpmomigdcfkidmimojhnoacaffcg?hl=en">https://chrome.google.com/webstore/detail/quick-dirty-proxy-flipper/lbhdjpmomigdcfkidmimojhnoacaffcg?hl=en</a></p>
<h3>Run Burp</h3>
<p>When you run the Burp jar file, it will launch the gui along with a proxy running on port 8080. It will also create its own self signed certificate. Obviously this certificate has not been signed by any actual authority and will create issues for you. We are going to bypass this problem by essentially telling OSX to &#8220;TRUST&#8221; this self signed certificate.</p>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/burp_image_1/" rel="attachment wp-att-1331"><img class="size-large wp-image-1331 aligncenter" alt="burp_image_1" src="http://www.acloudtree.com/wp-content/uploads/2013/01/burp_image_1-1024x745.png" width="580" height="421" /></a></p>
<h3>Enable Quick And Dirty Proxy Flipper</h3>
<p>&nbsp;</p>
<p>Select the http://localhost:8080 radio button</p>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/quick_and_dirty_proxy_2/" rel="attachment wp-att-1335"><img class="size-full wp-image-1335 aligncenter" alt="quick_and_dirty_proxy_2" src="http://www.acloudtree.com/wp-content/uploads/2013/01/quick_and_dirty_proxy_2.png" width="225" height="215" /></a></p>
<h3>Access google.com</h3>
<p>With Burp running, access google.com using Chrome. You should get the following screen.</p>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/security_certificate_not_trusted_3/" rel="attachment wp-att-1336"><img class="size-full wp-image-1336 aligncenter" alt="security_certificate_not_trusted_3" src="http://www.acloudtree.com/wp-content/uploads/2013/01/security_certificate_not_trusted_3.png" width="827" height="417" /></a></p>
<p>&nbsp;</p>
<h3>WTH?</h3>
<p>Let me explain what is happening. You are using chrome to access the web site google.com. Because you enabled <strong><em><a href="http://zx2c4.com/">zx2c4</a></em></strong>&#8216;s quick and dirty proxy flipper. The chrome extension is proxying the request through Burp. Burp is then using its self signed certificate to encrypt the data. At this point, your chrome browser is freaking out because it doesn&#8217;t know who the heck you are. It thinks you are a regular old l33t h@x0r or something. Here is how to fix it.</p>
<h3>Click the lock icon with the red (x)</h3>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/click_lock_with_red_x_4/" rel="attachment wp-att-1338"><img class="size-full wp-image-1338 aligncenter" alt="click_lock_with_red_x_4" src="http://www.acloudtree.com/wp-content/uploads/2013/01/click_lock_with_red_x_4.png" width="225" height="105" /></a></p>
<p>&nbsp;</p>
<h3>Click the &#8220;certificate information&#8221; link</h3>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/click_certificate_information_5/" rel="attachment wp-att-1339"><img class="size-full wp-image-1339 aligncenter" alt="Click_certificate_information_5" src="http://www.acloudtree.com/wp-content/uploads/2013/01/Click_certificate_information_5.png" width="295" height="97" /></a></p>
<h3>Click on the PortSwigger CA line</h3>
<h2><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/6/" rel="attachment wp-att-1340"><img class="size-full wp-image-1340 aligncenter" alt="6" src="http://www.acloudtree.com/wp-content/uploads/2013/01/6.png" width="487" height="265" /></a></h2>
<h2></h2>
<h3>Click and Drag the Gold Certificate icon to your desktop</h3>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/7/" rel="attachment wp-att-1341"><img class="size-full wp-image-1341 aligncenter" alt="7" src="http://www.acloudtree.com/wp-content/uploads/2013/01/7.png" width="116" height="98" /></a></p>
<h3>(Image of certificate on your desktop)</h3>
<h2><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/8/" rel="attachment wp-att-1342"><img class="size-full wp-image-1342 aligncenter" alt="8" src="http://www.acloudtree.com/wp-content/uploads/2013/01/8.png" width="111" height="109" /></a></h2>
<p>&nbsp;</p>
<h3>Double click on the .cer file that you dragged to your desktop, this will open a popup window, make sure that &#8220;system&#8221; is set in the dropdown, then click the add button</h3>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/9/" rel="attachment wp-att-1343"><img class="size-full wp-image-1343 aligncenter" alt="9" src="http://www.acloudtree.com/wp-content/uploads/2013/01/9.png" width="535" height="303" /></a></p>
<h3>Type in your System password (you may have to do this several times)</h3>
<h2><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/10/" rel="attachment wp-att-1344"><img class="size-full wp-image-1344 aligncenter" alt="10" src="http://www.acloudtree.com/wp-content/uploads/2013/01/10.png" width="446" height="238" /></a></h2>
<p>&nbsp;</p>
<h3>Click &#8220;Always Trust&#8221; (you may have to enter your system level password)</h3>
<p style="text-align: center;"><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/11/" rel="attachment wp-att-1345"><img class="size-full wp-image-1345 aligncenter" alt="11" src="http://www.acloudtree.com/wp-content/uploads/2013/01/11.png" width="541" height="345" /></a></p>
<h3>You should see the following line in the Keychain Access application. The blue plus denotes that you select to &#8220;Trust&#8221; the certificate.</h3>
<h2><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/12/" rel="attachment wp-att-1346"><img class="size-full wp-image-1346 aligncenter" alt="12" src="http://www.acloudtree.com/wp-content/uploads/2013/01/12.png" width="770" height="18" /></a></h2>
<h2></h2>
<h3>Close Chrome, Open Chrome, Try accessing Google.com again, Success</h3>
<h2><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/14/" rel="attachment wp-att-1347"><img class="size-full wp-image-1347 aligncenter" alt="14" src="http://www.acloudtree.com/wp-content/uploads/2013/01/14.png" width="731" height="621" /></a></h2>
<h3>Now if you go back to Burp, you can click on the Proxy-&gt;History tab and see the traffic</h3>
<p>&nbsp;</p>
<h3><a href="http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/attachment/15/" rel="attachment wp-att-1362"><img class="size-full wp-image-1362 aligncenter" alt="15" src="http://www.acloudtree.com/wp-content/uploads/2013/01/15.png" width="1425" height="1036" /></a></h3>
<h3>Happy Sniffing!!!</h3>
<p>jared</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acloudtree.com/how-to-configure-burp-and-chrome-for-https-ssl-packet-inspection-and-web-site-debugging-on-mac-osx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
