<?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>try all your chance</title>
	<atom:link href="http://blog.pclewis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pclewis.com</link>
	<description>nerdy stuff about computers and hacking</description>
	<lastBuildDate>Thu, 06 Dec 2012 05:43:46 +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>Groovy Gotchas</title>
		<link>http://blog.pclewis.com/2011/10/groovy-gotchas/</link>
		<comments>http://blog.pclewis.com/2011/10/groovy-gotchas/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 03:16:32 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=372</guid>
		<description><![CDATA[Map['key'] When calling putAt() on a Map with a String as a key, the Object version of putAt() is selected over the Map version. In other words, it will only call Map.put() if a property with the same name does not exist. However, calling getAt() on a Map will only call Map.get(), and will never [...]]]></description>
				<content:encoded><![CDATA[<h2>Map['key']</h2>
<p>When calling putAt() on a Map with a String as a key, the Object version of putAt() is selected over the Map version. In other words, it will only call Map.put() if a property with the same name does not exist. However, calling getAt() on a Map will only call Map.get(), and will never return an object property.</p>
<pre class="brush: groovy; title: ; notranslate">
class A extends HashMap { String y; } // any Map

a = new A();

a['x'] = 1;
a['x'];           // =&gt; 1
a.get('x');       // =&gt; 1
a.putAt('x', 2);
a.getAt('x');     // =&gt; 2

a['y'] = 1;
a['y'];           // =&gt; null
a.get('y');       // =&gt; null
a.putAt('y', 2);
a.getAt('y');     // =&gt; null
org.codehaus.groovy.runtime.DefaultGroovyMethods.putAt(a, 'y', 3)
a.getAt('y');     // =&gt; 3 !?

class B { String y = &quot;hi&quot;; }
(new B()).getAt('y');  // =&gt; &quot;hi&quot;
(new B())['y'];        // =&gt; &quot;hi&quot;

class C implements Map { String y; /* implement Map methods */ } 
(new C()).getAt('y');  // =&gt; null
(new C())['y'];        // =&gt; null
</pre>
<h2>Ranges</h2>
<p>The exclusive range operator (..<) generates a Range where the ending value is one step closer to the beginning value. The less-than symbol can be somewhat unintuitive for descending ranges.</p>
<pre class="brush: groovy; title: ; notranslate">
enum E { ONE, TWO, THREE, FOUR }
((E.ONE)..(E.THREE)).toList()  // [ONE, TWO, THREE]
((E.ONE)..&lt;(E.THREE)).toList() // [ONE, TWO]
((E.THREE)..(E.ONE)).toList()  // [THREE, TWO, ONE]
((E.THREE)..&lt;(E.ONE)).toList() // [THREE, TWO]
</pre>
<p>Indexing a List with a Range only considers <code>from</code> and <code>to</code> values <em>after</em> the above adjustment; the result of Range.toList() is irrelevant, and whether or not it was an exclusive range is not known. Three steps are performed to get the result:</p>
<ol>
<li>Negative values are normalized to positive values by adding them to List.size()</li>
<li>The result is generated from List.subList( min(from, to), max(from, to) )</li>
<li>If from > to, the result is reversed</li>
</ol>
<p>In Ruby, <code>a[0...-1]</code> means &#8220;From the 0th element up to and excluding the last element,&#8221; whereas the ostensibly equivalent construct in Groovy, <code>a[0..&lt;-1]</code>, means &#8220;From the 0th element to the 0th element.&#8221;</p>
<pre class="brush: groovy; title: ; notranslate">
a = [0,1,2,3,4]

a[0..-1]             // =&gt; [0, 1, 2, 3, 4]
a[0..-2]             // =&gt; [0, 1, 2, 3]
a[0..&lt;-1]            // =&gt; [0]
a[0..&lt;-2]            // =&gt; [0, 1, 2, 3, 4]

a[0..-2]             // =&gt; [0, 1, 2, 3]
a[-1..-2]            // =&gt; [5, 4]
a[-1..&lt;-2]           // =&gt; [5]
</pre>
<p>Compare to Ruby:</p>
<pre class="brush: ruby; title: ; notranslate">
a[0..-1]              # =&gt; [0, 1, 2, 3, 4]
a[0..-2]              # =&gt; [0, 1, 2, 3]
a[0...-1]             # =&gt; [0, 1, 2, 3]
a[0...-2]             # =&gt; [0, 1, 2]

a[0..-2]              # =&gt; [0, 1, 2, 3]
a[-1..-2]             # =&gt; []
a[-1...-2]            # =&gt; []
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2011/10/groovy-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TIP: Fixing author in git history</title>
		<link>http://blog.pclewis.com/2010/10/tip-fixing-author-in-git-history/</link>
		<comments>http://blog.pclewis.com/2010/10/tip-fixing-author-in-git-history/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 22:34:36 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=364</guid>
		<description><![CDATA[I always forget to set up my user info on git on new machines before I check stuff in. It&#8217;s pretty easy to fix if there&#8217;s nobody else in your repo: Source: serverfault]]></description>
				<content:encoded><![CDATA[<p>I always forget to set up my user info on git on new machines before I check stuff in. It&#8217;s pretty easy to fix if there&#8217;s nobody else in your repo:</p>
<pre class="brush: bash; title: ; notranslate">
git filter-branch --env-filter &quot;\
  export GIT_AUTHOR_NAME=Dade\ Murphy \
         GIT_AUTHOR_EMAIL=zer0cool@example.com \
         GIT_COMMITTER_NAME=Dade\ Murphy \
         GIT_COMMITTER_EMAIL=zer0cool@example.com &quot;
</pre>
<p>Source: <a href="http://serverfault.com/questions/12373/how-do-i-edit-gits-history-to-correct-an-incorrect-email-address-name">serverfault</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/10/tip-fixing-author-in-git-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starcraft vs Monty Hall</title>
		<link>http://blog.pclewis.com/2010/05/starcraft-vs-monty-hall/</link>
		<comments>http://blog.pclewis.com/2010/05/starcraft-vs-monty-hall/#comments</comments>
		<pubDate>Sun, 02 May 2010 21:46:11 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[starcraft]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=322</guid>
		<description><![CDATA[If you&#8217;re not familiar with the Monty Hall problem, it goes something like this: There are three doors, and one of them has a prize. You choose one of the doors, and Monty opens one of the others that is not a winner. Now you have the option to stick with your original choice, or [...]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re not familiar with the <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem">Monty Hall problem</a>, it goes something like this:</p>
<p>There are three doors, and one of them has a prize. You choose one of the doors, and Monty opens one of the others that is not a winner. Now you have the option to stick with your original choice, or switch to the remaining door. It might seem counter-intuitive, but switching doubles your odds of winning.</p>
<p>Some people have attempted to apply the same logic to scouting as <a href="http://starcraft.wikia.com/wiki/Zerg">Zerg</a> using an overlord and a drone in <a href="http://en.wikipedia.org/wiki/Starcraft">Starcraft</a>. Stated similarly, the problem goes like this:</p>
<p>There are three starting locations, and one of them has your enemy base. You send a drone to one location, and your overlord gets to one of the other locations and discovers no enemy base. Now you have the option to stick with your original choice, or send your drone to the remaining location.</p>
<p>Sounds the same, but in this case, switching has no effect on your odds of winning. It is the same as the &#8220;<a href="http://probability.ca/jeff/writing/montyfall.pdf">Monty Fall</a>&#8221; or &#8220;Ignorant Monty&#8221; variant of the Monty Hall problem, where Monty opens a door completely at random rather than one which is a non-winner.</p>
<p>The difference is because in the classic Monty Hall problem, you are initially choosing one door, which gives you 1/3 odds of your first choice being right. If you could choose to switch to <em>both</em> other doors, you&#8217;d obviously have a 2/3 chance of winning. In fact, this is <em>exactly</em> what you are doing when you switch, even after one of the doors has been revealed.</p>
<p>In the Starcraft problem, you are choosing <em>two</em> locations to begin with, which gives you a 2/3 chance of being right. If you choose to switch your drone to the remaining location at any point, the overlord still has a 1/3 chance and the drone still has a 1/3 chance. In the Monty Hall problem, you switch from only an unknown door (1/3), to the empty door and an unknown door (2/3). In the Starcraft problem, you switch from both an empty location and an unknown location (2/3), to the same empty location and a different unknown location (2/3).</p>
<p>To demonstrate this visually, I&#8217;ve made a <a href="http://blog.pclewis.com/scvsmh/">simulator</a> in Javascript.</p>
<p><b>Update (5/3):</b><br />
I added a &#8220;Monty Hall mode&#8221; to the simulator, the implementation of which may help make this even clearer. Normally, I choose two random locations from the possible enemy starting points, and send the overlord to the first and the drone to the second. This leads to 3 possibilities with an equal chance of occuring: the overlord finds the base, the drone finds the base, or neither finds the base. Only in the final case, which occurs 1/3 of the time, would it be correct to switch. In &#8220;Monty Hall mode,&#8221; the overlord is not allowed to find the base &#8211; so the 1/3 of the time where the overlord would normally have found the base, is now added to the 1/3 of the time when neither finds the base, making it correct to switch 2/3s of the time.</p>
<p>I also added a &#8220;Stupid Overlord mode&#8221; which demonstrates that the order is important. If the overlord chooses an empty base first, rather than the drone choosing first, the chances of the drone being correct are (obviously) 1/2.<br />
<span id="more-322"></span><br />
<iframe src="http://blog.pclewis.com/scvsmh/" width="550" height="550"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/05/starcraft-vs-monty-hall/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mixing Up Code and Data</title>
		<link>http://blog.pclewis.com/2010/05/mixing-up-code-and-data/</link>
		<comments>http://blog.pclewis.com/2010/05/mixing-up-code-and-data/#comments</comments>
		<pubDate>Sat, 01 May 2010 08:12:56 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[essays]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=305</guid>
		<description><![CDATA[From buffer overflows to cross-site scripting, decades of software security flaws can be traced back to a simple design problem: executable code (or otherwise specially meaningful data), and non-executable, black-box data are intermingled in the same channel. To execute arbitrary code, traditional buffer overflow exploits rely on non-executable data trampling execution state and eventually causing [...]]]></description>
				<content:encoded><![CDATA[<p>From buffer overflows to cross-site scripting, decades of software security flaws can be traced back to a simple design problem: executable code (or otherwise specially meaningful data), and non-executable, black-box data are intermingled in the same channel. To execute arbitrary code, traditional buffer overflow exploits rely on non-executable data trampling execution state and eventually causing data to be executed as code. Cross-site scripting exploits, and all traditional injection exploits, work when intermediary systems fail to identify the difference between code and data in exactly the same way as some other system.</p>
<p>To prevent these exploits, developers are generally advised to canonicalize input and encode data in output. While this is correct, I think it is important to also understand that <em>it shouldn&#8217;t be that way</em>. Developers should have to go an extra mile to cause data to be interpreted as code, not the other way around.<br />
<span id="more-305"></span><br />
Consider this common SQL injection scenario:</p>
<pre class="brush: php; light: true; title: ; notranslate">
$result = mysql_query( &quot;select id, name, pass from users where name='$name'&quot;, $db );
</pre>
<p>While it&#8217;s clear that $name is simply data to the developer, it&#8217;s being crammed into a string along with code and handed off to another system for re-interpretation. A common solution to prevent injection is something like this:</p>
<pre class="brush: php; light: true; title: ; notranslate">
$query = sprintf( &quot;select id, name, pass from users where name='%s' &quot;, mysql_real_escape_string($name) );
$result = mysql_query( $query, $db );
</pre>
<p>It&#8217;s true that this solution fixes the vulnerability in this instance, but it&#8217;s a heavy burden: always remember to add a whole bunch of code every time you perform this incredibly common task, or you will introduce one of the most serious vulnerabilities possible into your application. In my opinion, even though the code may be &#8220;secure,&#8221; it is still wrong. You are still mixing up code and data in the same place on the same channel. Here is a better solution:</p>
<pre class="brush: php; light: true; title: ; notranslate">
$stmt = $mysqli-&gt;prepare(&quot;select id, name, pass from users where name=?&quot;);
$stmt-&gt;bind_param(&quot;s&quot;, $name);
$stmt-&gt;execute();
</pre>
<p>This looks similar, but it&#8217;s important to understand how it works. The first line sends all of the code to be parsed and prepared by the server. Data to be filled in later is represented by question marks, which can only be used where data is expected. After this point, nothing is re-interpreted. When we send the data on the second line, the server is only reading data, and no special encoding is required to prevent it from being treated as code.</p>
<p>Even though it suffers the same criticism of being extra code every time you want to execute a SQL query, a developer used to coding this way is much less likely to make a mistake than a developer used to the previous example. The statements could also be prepared in an initializer somewhere completely different instead of right next to where data is being bound, to make it even harder to make a mistake.</p>
<p>Imagine if HTML/HTTP had something similar:</p>
<pre class="brush: xml; light: true; title: ; notranslate">
&lt;html&gt;
&lt;div class=&quot;title&quot;&gt;&amp;data[0,16];&lt;/div&gt;
&lt;div class=&quot;body&quot;&gt;&amp;data[17,256];&lt;/div&gt;
&lt;/html&gt;
Data until EOF. &lt;!-- &amp;amp; No possibility of being interpreted as html. &lt;script&gt;alert(1);&lt;/script&gt;
</pre>
<p>Note that the data part is a complete black box and terminated out-of-band (by closing the connection). There aren&#8217;t lengths or other special markers embedded in the data. I&#8217;m not suggesting this is a realistic possibility for HTML or any other established standard. I just want to make the point that a protocol which makes it impossible to confuse code and data is invulnerable to injection attacks by default.</p>
<p>A related idea is identifying the source of data. When an application includes user input in its own output, or in SQL statements, or anywhere else, it takes responsibility for it; to other applications, it&#8217;s data (or code) coming from the first application, not data coming from a user or third-party application somewhere else.</p>
<p>In cases where user input needs to be specially interpreted, especially by some other application &#8211; when you want to let people include a little HTML in a post, for example &#8211; then you have a more difficult problem which can&#8217;t be solved by shoving it all into a separate black box. But imagine how nice it would be if you could specify that some bit of HTML was from a user, or some other website (perhaps with digital signatures), or whatever, and the browser could handle sandboxing and cross-domain policies and everything else it already has the ability to do.</p>
<p>I think it is important to address this idea up front not just when designing a protocol or file format, but when designing APIs and internal interfaces to existing systems. Even if you have to output HTML or actual SQL statements, an interface to generate the output which cleanly separates code and data can relieve the burden from developers, isolate potential weaknesses in one place, and go a long way to improve the security of a system.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/05/mixing-up-code-and-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TIP: Using GDB as an Interactive C Shell</title>
		<link>http://blog.pclewis.com/2010/03/tip-using-gdb-as-an-interactive-c-shell/</link>
		<comments>http://blog.pclewis.com/2010/03/tip-using-gdb-as-an-interactive-c-shell/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 20:13:54 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=70</guid>
		<description><![CDATA[Many programming languages come with some way to run an interactive shell, or REPL (read-eval-print loop). This makes it extremely easy to test little bits of code and understand exactly what they do, and is invaluable when learning a new language or library. For example: What&#8217;s the result of (unsigned int)atoi("4294967295") in C? Even if [...]]]></description>
				<content:encoded><![CDATA[<p>Many programming languages come with some way to run an interactive shell, or <a href="http://en.wikipedia.org/wiki/REPL">REPL (read-eval-print loop)</a>. This makes it extremely easy to test little bits of code and understand exactly what they do, and is invaluable when learning a new language or library. For example:</p>
<p>What&#8217;s the result of <tt>(unsigned int)atoi("4294967295")</tt> in C?</p>
<p>Even if you know the answer, how quickly can you prove it? How concisely can you communicate the proof via IM or email? What if it&#8217;s a poorly documented third-party library function, and not a standard one?</p>
<p>For quick tasks, you can just use <a href="http://www.gnu.org/software/gdb/">gdb</a> which is probably already present on any system that has <a href="http://gcc.gnu.org/">gcc</a>. Just fire up gdb on any binary, set a breakpoint on main, and run. When it stops you will be able to call functions and examine their results, and many other common REPL tasks. The binary doesn&#8217;t matter much, but you should prefer ones with debugging symbols, and if you want to call functions in a particular library, you should use a binary that is linked to that library.</p>
<p>Example session:</p>
<pre class="brush: cpp; title: ; notranslate">
~% gdb ./test
(gdb) break main
Breakpoint 1 at 0x8048452
(gdb) run
Starting program: /home/pcl/sandbox/test
Breakpoint 1, 0x08048452 in main ()
(gdb) set $a = malloc(1234)
(gdb) call sprintf($a, &quot;Hello %d&quot;, 12345*12345*12345)
$1 = 15
(gdb) print (char*)$a
$2 = 0x96c6008 &quot;Hello 170287977&quot;
(gdb) print (unsigned int)atoi(&quot;-1&quot;)
$3 = 4294967295
(gdb) print (unsigned int)atoi(&quot;4294967295&quot;)
$4 = 2147483647
</pre>
<p>gdb lets you use arbitrarily-named, untyped convenience variables, as you can see in the example. The only practical difference between <tt>print $var = expr</tt>, <tt>call $var = expr</tt>, and <tt>set $var = expr</tt> seems to be that <tt>set</tt> does not additionally assign the result to a history variable. Obviously you also have the full debugging facilities of gdb available as well.</p>
<p>It is also possible to do this on stripped binaries with no &#8216;main&#8217; function, but there are many disadvantages:</p>
<pre class="brush: cpp; title: ; notranslate">
~% gdb `which echo`
(gdb) inf files
	Entry point: 0x8048be0	0x08048154 - 0x08048167 is .interp
(gdb) break *0x8048be0
Breakpoint 1 at 0x8048be0
</pre>
<p>For a fully featured REPL for C, check out <a href="http://neugierig.org/software/c-repl/">c-repl</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/03/tip-using-gdb-as-an-interactive-c-shell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Analysis of Gemini Cybernetics CDS</title>
		<link>http://blog.pclewis.com/2010/03/analysis-of-gemini-cybernetics-cds/</link>
		<comments>http://blog.pclewis.com/2010/03/analysis-of-gemini-cybernetics-cds/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 03:13:55 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[second life]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=260</guid>
		<description><![CDATA[There have been some rumors going around about a new third-party system for Second Life. The system attempts to detect avatars using third-party clients capable of duplicating objects without the creator&#8217;s permission, and the rumors are that it uses some kind of QuickTime exploit or other nefarious means to actually examine the contents of your [...]]]></description>
				<content:encoded><![CDATA[<p>There have been some rumors going around about a new third-party system for Second Life. The system attempts to detect avatars using third-party clients capable of duplicating objects without the creator&#8217;s permission, and the rumors are that it uses some kind of QuickTime exploit or other nefarious means to actually examine the contents of your hard drive or otherwise invade your privacy without permission. I decided to take a quick look to see what it&#8217;s all about.</p>
<p>The system in question is called <a href="https://www.xstreetsl.com/modules.php?name=Marketplace&amp;file=item&amp;ItemID=2138424">GEMINI CDS Ban Relay</a> and is advertised as a simple object which detects avatars entering your sim, and uses &#8220;a team of bots with special abilities&#8221; to determine if the avatar is &#8220;harmful.&#8221; If they are, it adds them to an external database, and can optionally ban or teleport them home. Entries in the database are permanent, so if an avatar has been considered harmful once, they are always considered harmful in the future. It claims to use several frequently updated methods to detect &#8220;illegitimate&#8221; clients.</p>
<p>The most obvious detection method, and the only one I discovered, is a script that triggers as soon as you enter a protected sim and <a href="http://wiki.secondlife.com/wiki/LlParcelMediaCommandList">tells your client</a> to load up a special media URL. Using a tool like <a href="http://www.wireshark.org/">Wireshark</a> or <a href="http://ngrep.sourceforge.net/">ngrep</a>, it is trivial to watch the HTTP request.</p>
<p><span id="more-260"></span></p>
<p><img class="size-medium wp-image-262 aligncenter" title="pcap1" src="http://blog.pclewis.com/wp-content/uploads/2010/03/pcap1-300x203.jpg" alt="Packet Capture" width="300" height="203" /></p>
<p>Broken down, the requested URL in my case was:</p>
<pre>http://media.syscast.net/youtube.php
  ? <strong>licensekey</strong> = KBVaQkxGH1lDVRdBWA1GVEdaTFpQF1ReWUcREU9YEFxBRgxE
  &amp; <strong>title</strong>      = BEYeQR8TAxxOLE8eBk0T
  &amp; <strong>licensedon</strong> = B1IAQhUG
  &amp; <strong>tvowner</strong>    = eBVbGUdLQFxeVA%3D%3D
  &amp; <strong>videoid</strong>    = eEJVE0xDHwxZAUQSWBJFARMJV1RTE19BWUETGBMNQg0%3D</pre>
<p>At a glance, the values are obviously all Base64 encoded &#8212; the trailing <tt>%3D</tt>s on the last two fields are a dead giveaway. Decoding them doesn&#8217;t produce anything human-readable, though; one online service gives me &#8220;(ZBLFYCUAXFTGZLZPT^YGOX\AFD&#8221; for the first field.</p>
<p>It&#8217;s easy to decode them in Ruby, where we can play with them a little more:</p>
<pre class="brush: ruby; light: true; title: ; notranslate">
irb(main):002:0&gt; CIPHERTEXT = Base64.decode64('KBVaQkxGH1lDVRdBWA1GVEdaTFpQF1ReWUcREU9YEFxBRgxE')
=&gt; &quot;(&#92;&#48;25ZBLF&#92;&#48;37YCU&#92;&#48;27AX\rFTGZLZP&#92;&#48;27T^YG&#92;&#48;21&#92;&#48;21OX&#92;&#48;20\\AF\fD&quot;

irb(main):003:0&gt; CIPHERTEXT.length
=&gt; 36
</pre>
<p>36 bytes is the same length as a <a href="http://en.wikipedia.org/wiki/UUID">UUID</a> in canonical form, so it&#8217;s a pretty reasonable guess that this is my avatar&#8217;s UUID encrypted somehow. The only real encryption facility LSL makes available is <a href="http://wiki.secondlife.com/wiki/LlXorBase64StringsCorrect">XORing Base64-encoded strings together</a>. <a href="http://en.wikipedia.org/wiki/Xor">XOR</a> has an interesting property: <tt>a ⊕ b = c</tt> ⇒ <tt>a ⊕ c = b</tt>; that is, if XORing some plaintext and some key produces some ciphertext, then XORing that ciphertext and the plaintext produces the key. Let&#8217;s give it a shot:</p>
<pre class="brush: ruby; light: true; title: ; notranslate">
irb(main):004:0&gt; PLAINTEXT = 'a27b84f0-2757-4176-9579-43a181d4a5a0'
=&gt; &quot;a27b84f0-2757-4176-9579-43a181d4a5a0&quot;

irb(main):007:0&gt; CIPHERTEXT.bytes.each_with_index {|v,i| key &lt;&lt; (v ^ PLAINTEXT[i])}; key
=&gt; &quot;I'm trying to replace msmtp with smt&quot;
</pre>
<p>That was easy enough. Using the key to decode the rest of the fields, we can see what is really being sent:</p>
<pre>http://media.syscast.net/youtube.php
  ? <strong>licensekey</strong> = a27b84f0-2757-4176-9579-43a181d4a5a0
  &amp; <strong>title</strong>      = Masakazu Kojima
  &amp; <strong>licensedon</strong> = Numbat
  &amp; <strong>tvowner</strong>    = 1269399503
  &amp; <strong>videoid</strong>    = 1e8381fe7fdf727dce67632245c8dd6e</pre>
<p>The second field (title) turns out to be my avatar name, followed by the sim name (licensedon), a UNIX time value (tvowner), and what looks like an MD5 hash (videoid). The time value is apparently used to prevent <a href="http://en.wikipedia.org/wiki/Replay_attack">replay attacks</a>: it is possible to immediately replay the request exactly and get a success response, but after about 30 seconds it causes an internal server error instead.</p>
<p>Visiting the parcel again to get another URL shows that only the time and MD5 hash change. Tampering with the values causes an immediate error redirect, which suggests that the MD5 hash is a signature to prevent forged messages. So, even though we could encrypt arbitrary values and send them, we&#8217;d need to know how the signature is generated for them to work.</p>
<p>The response from the server is innocent enough:</p>
<pre>&lt;!--
--&gt;
&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body bgcolor="#7f7f7f" leftmargin="0" topmargin="0"&gt;&lt;img src="video-background.gif" width="2000px" height="2000px" border="0px" /&gt;&lt;/body&gt;&lt;/html&gt;</pre>
<p>The video-background.gif file is just a transparent 1&#215;1 GIF image:</p>
<pre>00000000  47 49 46 38 39 61 01 00  01 00 80 00 00 7f 7f 7f  |GIF89a..........|
00000010  00 00 00 21 f9 04 00 00  00 00 00 2c 00 00 00 00  |...!.......,....|
00000020  01 00 01 00 00 02 02 44  01 00 3b                 |.......D..;|</pre>
<p>These are the only requests that are performed. Nothing nefarious appears to be taking place. There is no evidence of any kind of exploit, or the transmission of any kind of private information. So how does the service detect &#8220;illegitimate&#8221; clients?</p>
<p>The magic turns out to be in the &#8220;User-Agent&#8221; request header, which identifies the client. In my case: <tt>Mozilla/5.0 (Windows; U; Windows NT 6.0; chrome://navigator/locale/navigator.properties; rv:1.8.1.21) Gecko/20090305 SecondLife/Emerald Viewer (default skin)</tt></p>
<p>By using <a href="http://curl.haxx.se/">curl</a> to replay an old request, and simply replacing &#8220;Emerald Viewer&#8221; with the name of a random client from <a href="http://onyx.modularsystems.sl/viewer_reference.html">the Onyx project</a> (NeilLife), I was able to get the system to ban an alternate account I created. Note that this worked even though the time value was old, and the HTTP response status was a 500 error, so it would appear that the system to prevent replay attacks is broken. Looks like they&#8217;re up to at least 1 false positive, even if it&#8217;s a technicality. Also note that the actual response body did not change, so there doesn&#8217;t seem to be any kind of exploit that is only sent to users of &#8220;bad&#8221; clients.</p>
<p>Using the same IP address and computer, I was able to go back to the same parcel on my main account with no trouble.</p>
<h2>Conclusions</h2>
<p>Despite all the subterfuge, the Gemini CDS system seems to simply rely on &#8220;illegitimate&#8221; clients to identify themselves in an HTTP request. The message encryption is trivial to break, and it would seem that is only a matter of time before someone cares enough to figure out how to forge the message signature. It is trivial to avoid detection by this method, though the system may employ additional detection methods: the common way for third-party clients to identify each other is by the unique texture UUIDs they use for skin layer protection, which is passive and undetectable.</p>
<p>There is no evidence that the system uses any kind of exploit or other nefarious tactic. The system does not appear to record any data other than the avatar and client self-identification information.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/03/analysis-of-gemini-cybernetics-cds/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>Speaking at MBCSC2010</title>
		<link>http://blog.pclewis.com/2010/03/speaking-at-mbcsc2010/</link>
		<comments>http://blog.pclewis.com/2010/03/speaking-at-mbcsc2010/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 02:30:39 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=258</guid>
		<description><![CDATA[I will be speaking at the Myrtle Beach Computer Security Conference on April 15th. The title of my presentation is &#8220;Practical Web Application Security,&#8221; and will partially be a rehash of my post about shared hosting but with more focus on why the little things matter and less on shared environments.]]></description>
				<content:encoded><![CDATA[<p>I will be speaking at the <a href="http://www.computersecurityconference.com/">Myrtle Beach Computer Security Conference</a> on <a href="http://www.computersecurityconference.com/index.cfm?nextpage=ConferenceSchedule">April 15th</a>. The title of my presentation is &#8220;Practical Web Application Security,&#8221; and will partially be a rehash of my <a href="http://blog.pclewis.com/2010/01/the-dangers-of-shared-hosting/">post about shared hosting</a> but with more focus on why the little things matter and less on shared environments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/03/speaking-at-mbcsc2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TIP: Make bash tab completion ignore .svn directories</title>
		<link>http://blog.pclewis.com/2010/03/tip-make-bash-tab-completion-ignore-svn-directories/</link>
		<comments>http://blog.pclewis.com/2010/03/tip-make-bash-tab-completion-ignore-svn-directories/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 15:50:45 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=253</guid>
		<description><![CDATA[Having to tab through the fifty million otherwise empty &#8220;net/mycompany/project/unit/subunit&#8221; directories that the Java ecosystem necessitates has consistently driven me crazy because completion stops at each step to let me choose the .svn directory, and I have to look and type the first letter of the directory I actually want to make it continue. It&#8217;s [...]]]></description>
				<content:encoded><![CDATA[<p>Having to tab through the fifty million otherwise empty &#8220;net/mycompany/project/unit/subunit&#8221; directories that the Java ecosystem necessitates has consistently driven me crazy because completion stops at each step to let me choose the .svn directory, and I have to look and type the first letter of the directory I actually want to make it continue.</p>
<p>It&#8217;s actually really easy to fix this:</p>
<pre class="brush: bash; light: true; title: ; notranslate">export FIGNORE=.svn</pre>
<p><tt>$FIGNORE</tt> is just a colon-separated list of suffixes to ignore when doing tab completion.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/03/tip-make-bash-tab-completion-ignore-svn-directories/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Streaming Nokia N900 Camera to VLC</title>
		<link>http://blog.pclewis.com/2010/02/streaming-nokia-n900-camera-to-vlc/</link>
		<comments>http://blog.pclewis.com/2010/02/streaming-nokia-n900-camera-to-vlc/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 04:08:31 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[n900]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=244</guid>
		<description><![CDATA[I recently had need to look at the back of my own head, and using the camera on my phone seemed like the easiest way to do it. I found a guide on the Maemo wiki, but it was for the N800 and I didn&#8217;t have the hantro4200 encoder it was trying to use. After [...]]]></description>
				<content:encoded><![CDATA[<p>I recently had need to look at the back of my own head, and using the camera on my phone seemed like the easiest way to do it. I found <a href="http://wiki.maemo.org/Streaming_video_from_built-in_webcam">a guide</a> on the Maemo wiki, but it was for the N800 and I didn&#8217;t have the hantro4200 encoder it was trying to use. After learning more than I ever wanted to about gstreamer and sdp files, I came up with a way that works for me.</p>
<p>In my setup, my computer is 192.168.0.100 and the phone is 192.168.0.200. You will have to replace them with your own IP addresses.</p>
<p>Here is the command to start gstreamer on the phone. You will probably want to put it in a script:</p>
<pre class="brush: bash; title: ; notranslate">
gst-launch v4l2camsrc device=/dev/video0 ! \
           dsph264enc ! \
           rtph264pay ! \
           udpsink host=192.168.0.100 port=5434
</pre>
<p>If <tt>gst-launch</tt> is not found, you probably need to install the <tt>gstreamer-tools</tt> package:</p>
<pre class="brush: plain; light: true; title: ; notranslate">apt-get install gstreamer-tools</pre>
<p>To use the camera on the front of the phone, you can change the device to <tt>/dev/video1</tt>.</p>
<p>Here is the minimal sdp file I was able to use with VLC to get it to play. Using the &#8220;Open Network&#8221; dialog to try and play an RTP stream did not work.</p>
<pre class="brush: plain; title: ; notranslate">
v=0
m=video 5434 RTP/AVP 96
c=IN IP4 192.168.0.200
a=rtpmap:96 H264/90000
</pre>
<p>The second line (<tt>m=</tt>) contains the port, the third (<tt>c=</tt>) contains the IP address of the phone, and the fourth (<tt>a=</tt>) specifies the codec.</p>
<p>To use MP4 instead of H264, you can just change <tt>h264</tt> to <tt>mp4v</tt> everywhere. In the SDP file, it should be <tt>MP4V-ES</tt>, as in: <tt>a=rtpmap:96 MP4V-ES/90000</tt>. If you get errors in VLC like:</p>
<pre class="brush: plain; light: true; title: ; notranslate">avcodec warning: cannot decode one frame (14922 bytes)</pre>
<p>Then add <tt>send-config=true</tt> to the <tt>rtpmp4v</tt> part of the gstreamer pipeline, and make sure you start VLC before you start streaming:</p>
<pre class="brush: bash; title: ; notranslate">
gst-launch v4l2camsrc device=/dev/video0 ! \
           dspmp4venc ! \
           rtpmp4vpay send-config=true ! \
           udpsink host=192.168.0.100 port=5434
</pre>
<p>For H263, you can try <tt>dsph263enc</tt>, <tt>rtph263pay</tt> and <tt>H263-1998</tt> or <tt>H263-2000</tt>, but I couldn&#8217;t get it to work.</p>
<p>I don&#8217;t know if there&#8217;s a way to control the focus, white balance, etc, but I was able to use the flashlight-applet to turn on the camera LEDs while streaming after I downgraded to 0.2-0:</p>
<pre class="brush: plain; light: true; title: ; notranslate">apt-get install flashlight-applet=0.2-0</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/02/streaming-nokia-n900-camera-to-vlc/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Three Most Commonly Used Passwords</title>
		<link>http://blog.pclewis.com/2010/01/three-most-commonly-used-passwords/</link>
		<comments>http://blog.pclewis.com/2010/01/three-most-commonly-used-passwords/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 20:41:22 +0000</pubDate>
		<dc:creator>pcl</dc:creator>
				<category><![CDATA[links]]></category>
		<category><![CDATA[passwords]]></category>

		<guid isPermaLink="false">http://blog.pclewis.com/?p=234</guid>
		<description><![CDATA[PHREAK: Alright, what are the three most commonly used passwords? JOEY: love, secret, and uh, sex. But not in that order, necessarily, right? CEREAL: Yeah but don&#8217;t forget GOD. System operators love to use GOD. It&#8217;s that whole male ego thing. Analyses of various password leaks: 32 million RockYou passwords (December 2009) 47,380 phished MySpace [...]]]></description>
				<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://blog.pclewis.com/wp-content/uploads/2010/01/vlcsnap-2010-01-23-14h48m35s212.png"><img class="aligncenter size-medium wp-image-239" title="Hackers Passwords Scene" src="http://blog.pclewis.com/wp-content/uploads/2010/01/vlcsnap-2010-01-23-14h48m35s212-300x127.png" alt="Hackers movie screenshot" width="300" height="127" /></a></p>
<blockquote><p><strong>PHREAK</strong>: Alright, what are the three most commonly used passwords?<br />
<strong> JOEY</strong>: <tt>love</tt>, <tt>secret</tt>, and uh, <tt>sex</tt>.  But not in that order, necessarily, right?<br />
<strong> CEREAL</strong>: Yeah but don&#8217;t forget <tt>GOD</tt>. System operators love to use <tt>GOD</tt>. It&#8217;s that whole male ego thing.</p></blockquote>
<p>Analyses of various password leaks:</p>
<ul>
<li><a href="http://www.imperva.com/docs/WP_Consumer_Password_Worst_Practices.pdf">32 million RockYou passwords (December 2009)</a></li>
<li><a href="http://blog.jimmyr.com/Password_analysis_of_databases_that_were_hacked_28_2009.php">47,380 phished MySpace passwords (2006), 28,644 phpBB.com mailing list passwords (January 2009), and 40,758 singles.org passwords (February 2009)</a></li>
<li><a href="http://www.acunetix.com/blog/websecuritynews/statistics-from-10000-leaked-hotmail-passwords/">10,000 phished Hotmail passwords (October 2009)</a></li>
<li><a href="http://digg.com/security/Passwords_of_8000_Comcast_Customers_Exposed?t=24171960#c24171960">8,000 Comcast passwords (March 2009)</a></li>
</ul>
<p>I think it is interesting that as bad as the passwords in <a href="http://www.imdb.com/title/tt0113243/">Hackers</a> seem, the passwords people actually use are somehow even worse. Where it&#8217;s allowed, <tt>123456</tt> always takes the number one spot, usually by a huge margin; in the RockYou leak, <tt>123456</tt> was used 4x more than its closest competitor (<tt>12345</tt>). When purely numeric password are forbidden, <tt>password</tt> is the clear winner, and continues to take the number one spot as requirements are added.</p>
<p>Require a capital letter? <tt>Password</tt><br />
Number? <tt>password1</tt><br />
Both? <tt>Password1</tt></p>
<p>The top three I&#8217;d try, without knowing the requirements:</p>
<ol>
<li><tt>123456</tt></li>
<li><tt>password</tt></li>
<li><tt>password1</tt></li>
</ol>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.pclewis.com/2010/01/three-most-commonly-used-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
