<?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>Mike Conley&#039;s Blog &#187; Security</title>
	<atom:link href="http://mikeconley.ca/blog/category/technology/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikeconley.ca/blog</link>
	<description>The personal blog of a Toronto based software developer, musician, sound designer, and theatre enthusiast.</description>
	<lastBuildDate>Tue, 10 Jan 2012 13:58:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A Sobering Post About Code Review From Microsoft</title>
		<link>http://mikeconley.ca/blog/2010/02/16/a-sobering-post-about-code-review-from-microsoft/</link>
		<comments>http://mikeconley.ca/blog/2010/02/16/a-sobering-post-about-code-review-from-microsoft/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 16:09:14 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Code Reviews]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[code review]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[shawn hernan]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=1034</guid>
		<description><![CDATA[It&#8217;s easy to get on the code review band-wagon, and tout it as the &#8220;silver bullet&#8221; for bugs, or the key to developing awesome, elegant software, etc.  It&#8217;s easy to get carried away, and forget that code review should probably be accompanied by rigorous testing, static analysis, and security integration from day one. While the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy to get on the code review band-wagon, and tout it as the &#8220;silver bullet&#8221; for bugs, or the key to developing awesome, elegant software, etc.  It&#8217;s easy to get carried away, and forget that code review should probably be accompanied by rigorous testing, static analysis, and security integration from day one.</p>
<p>While the purpose of <a href="http://blogs.msdn.com/shawnhernan/archive/2010/02/13/microsoft-s-many-eyeballs-and-the-security-development-lifecycle.aspx">this blog post</a> by <a href="http://blogs.msdn.com/user/Profile.aspx?UserID=56729">Shawn Hernan</a> from Microsoft may be to attack or question the merits of open source software, I see it as an interesting discussion on the role of code review in software engineering and how it relates to writing secure code.</p>
<p>Insert your own joke about Microsoft security here.  I, personally, think their IE team should read Shawn&#8217;s post.</p>
<p>Particularly interesting is one of the comments to the post by &#8220;danclarke_2000&#8243;:</p>
<blockquote><p>I think another point is diminishing returns of code review..  Each extra code review brings less value than the preeding; review comments can already be known and awaiting action, not important enough to change etc</p>
<p>having extra eyes reviewing code means generating extra code review output.  Here is the true cost, all the code review comments of the many eyes have to pass through the bottleneck of the few people who have authority to make changes.  As each extra review has less value, processing the extra reviews has a higher and higher opportunity cost.</p></blockquote>
<p><a href="http://mikeconley.ca/blog/2010/02/07/the-importance-of-first-impressions-how-theatre-criticism-migh-inform-peer-code-review/">Sound kind of familiar?</a></p>
<p>Anyhow, Hernan&#8217;s post is an interesting read.  <a href="http://blogs.msdn.com/shawnhernan/archive/2010/02/13/microsoft-s-many-eyeballs-and-the-security-development-lifecycle.aspx">Click here to check it out.</a></p>
<p>UPDATE:</p>
<p>Here&#8217;s a quote from Joshua Bloch of Google on a similar topic:</p>
<blockquote><p>&#8230;We programmers need all the help we can get, and we should never assume otherwise. Careful design is great. Testing is great. Formal methods are great. Code reviews are great. Static analysis is great. But none of these things alone are sufficient to eliminate bugs: They will always be with us. A bug can exist for half a century despite our best efforts to exterminate it. We must program carefully, defensively, and remain ever vigilant.</p></blockquote>
<p><a href="http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html">Read the entire post here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2010/02/16/a-sobering-post-about-code-review-from-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fiddling Around with Skype</title>
		<link>http://mikeconley.ca/blog/2009/12/01/fiddling-around-with-skyp/</link>
		<comments>http://mikeconley.ca/blog/2009/12/01/fiddling-around-with-skyp/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 02:38:55 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[fingerprint]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[networks]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[packets]]></category>
		<category><![CDATA[port scanning]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[scapy]]></category>
		<category><![CDATA[skype]]></category>
		<category><![CDATA[spoof]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[telnet]]></category>
		<category><![CDATA[udp]]></category>
		<category><![CDATA[wireshark]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=952</guid>
		<description><![CDATA[As I said last week, I&#8217;ve been working with a partner (Mohammad Jalali) on a project for our networks course. The idea:  given an arbitrary IP and port number, we want to find a way of determining whether or not there is an FTP server, an HTTP server, or a Skype node on the other [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikeconley.ca/blog/2009/11/24/playing-around-with-ftp/">As I said last week</a>, I&#8217;ve been working with a partner (<a href="http://www.mjalali.com/blog/">Mohammad Jalali</a>) on a project for our networks course.</p>
<p>The idea:  given an arbitrary IP and port number, we want to find a way of determining whether or not there is an FTP server, an HTTP server, or a Skype node on the other side.  <a href="http://mikeconley.ca/blog/2009/11/24/playing-around-with-ftp/">FTP</a> and HTTP are trivial &#8211; those protocols essentially announce themselves to the world.</p>
<p><a href="http://www.skype.com/">Skype</a> clients, on the other hand, act a little more strangely.  Skype goes out of its way to hide its traffic &#8211; from straight-up encryption, down to making their client executable really hard to reverse engineer.  Because of this, <a href="http://www.blackhat.com/presentations/bh-europe-06/bh-eu-06-biondi/bh-eu-06-biondi-up.pdf">Skype has been an interesting challenge to the hacker community.</a></p>
<p>Anyhow, my partner and I have learned a few interesting things about Skype &#8211; and in particular, we&#8217;ve found a reliable way to determine whether or not Skype is running behind an arbitrary IP and port.  Cool.</p>
<h3>Fact 1:  Skype pretends to be an HTTP server</h3>
<p>I&#8217;m serious, it does.  Using <a href="http://www.wireshark.org/">Wireshark</a>, we noticed that both UDP <em>and</em> TCP packets were being sent to one particular port.  Pretty funny behavior&#8230;so, we took a closer look.  And this is what we found.  Pop open your Skype client, connect to the network, then use nmap to find the ports that Skype is using:</p>
<p><code><br />
$&gt;nmap localhost -p10000-50000</code></p>
<p>Starting Nmap 5.00 ( http://nmap.org ) at 2009-12-01 20:33 EST<br />
Interesting ports on localhost (127.0.0.1):<br />
Not shown: 39999 closed ports<br />
PORT      STATE SERVICE<br />
48915/tcp open  unknown</p>
<p>Ok, cool &#8211; there&#8217;s something at 48915, and it looks like it accepts TCP connections.  Pop open Telnet, connect to it, and feed it an HTTP request:</p>
<p><code><br />
$&gt;telnet localhost 48915<br />
Trying 127.0.0.1...<br />
Connected to localhost.<br />
Escape character is '^]'.<br />
GET / HTTP/1.1<br />
HTTP/1.0 404 Not Found<br />
Connection closed by foreign host.<br />
</code><br />
Ok, we got an HTTP response &#8211; looks like there&#8217;s an HTTP server back there, right?</p>
<p>Wrong.  Reconnect, and send it some garbage:</p>
<p><code><br />
$&gt;telnet localhost 48915<br />
Trying 127.0.0.1...<br />
Connected to localhost.<br />
Escape character is '^]'.<br />
thisissomegarbagetextthatisnotanHTTPrequest<br />
��Nun��2�=���1��N$O/(����<br />
���u.)(yy�g��$<br />
ș�oT�b렑�-z#x�&amp;���[P���\��(yVO���<br />
</code></p>
<p>See all of those funny characters down at the bottom?  That&#8217;s what I got back.  In the words of Obi-Wan Kenobi&#8230;that&#8217;s no HTTP server&#8230;it&#8217;s a space station (Skype node).</p>
<p>So we&#8217;ve learned something here &#8211; Skype opens a port, and &#8220;spoofs&#8221; an HTTP server.  We can easily check for this &#8211; just write a script that connects to a port, spews some garbage, and check to see if we got binary garbage back.</p>
<p>It&#8217;s so easy, <em>that someone else has already done it</em>.  Remember that nmap tool we used earlier?  <a href="http://nmap.org/nsedoc/scripts/skypev2-version.html">Somebody over in that camp wrote a script for the Nmap Scripting Engine</a> that runs this exact analysis on some ip/port.  Don&#8217;t believe me?  <a href="http://nmap.org/book/nse-vscan.html">Read the script yourself!</a> We stumbled upon that script while trying to figure out what Skype was doing with the spoofed HTTP server.<br />
And sure enough:<br />
<code><br />
$&gt;nmap localhost -p48915 --script skype.nse<br />
Starting Nmap 5.00 ( http://nmap.org ) at 2009-12-01 20:45 EST<br />
Interesting ports on localhost (127.0.0.1):<br />
PORT      STATE SERVICE<br />
48915/tcp open  skype2</code></p>
<p>Nmap done: 1 IP address (1 host up) scanned in 0.14 seconds</p>
<p>Hmph.  So much for cutting edge, never-been-done research.  Go figure.</p>
<h3>Fact 2:  Given some UDP packets, Skype echos back a predictable pattern</h3>
<p>For this part, we&#8217;re pretty sure no one else has tried this.</p>
<p>While connected to Skype, we recorded some packets with tcpdump.  We wrote a script that loaded up those packets, and could &#8220;replay&#8221; the packet payloads to an arbitrary IP and port.</p>
<p>So, we played some packets against an IP/port with Skype behind it.  Most of the time, we got TCP packets with RST flags (which is TCP&#8217;s way of telling us to &#8220;shut yer trap&#8221;).  But wayyyy down in the middle, there was a section of UDP packets that actually got a response:</p>
<table style="width: auto;" border="0">
<tbody>
<tr>
<td><a href="http://picasaweb.google.com/lh/photo/Fs73oxvTCSJ--ZWG0blasw?feat=embedwebsite"><img src="http://lh6.ggpht.com/_Kib24bTtAAU/SxXKinoyE5I/AAAAAAAAA9Q/yd_K9mD355I/s144/Repeated%20UDPs.png" alt="" /></a></td>
</tr>
<tr>
<td style="font-family: arial,sans-serif; font-size: 11px; text-align: right;">From <a href="http://picasaweb.google.com/mike.d.conley/MiscBlogImages?feat=embedwebsite" target="_blank">Misc Blog Images</a></td>
</tr>
</tbody>
</table>
<p>192.168.0.19 was the computer we were playing the packets from, and 192.168.0.14 was the computer with Skype running on it.  See those UDP packets that are getting echoed back?  That&#8217;s the interesting part&#8230;instead of just shutting us down with RST&#8217;s, Skype appears to be saying something back.</p>
<p>So, is there a pattern in all of this?  Actually yes.  We isolated 4 of those UDP packets, and repeatedly fired them at the same IP/Port on the computer running Skype, and we found a pattern.</p>
<p>The pattern:  <em>the first two bytes that are sent in our UDP packets are echo&#8217;d back to us in the first two bytes of the UDP packets that come back. </em></p>
<p>So, for example,  one UDP payload we sent looked like this:<br />
<code><br />
92 40 02 a1 66 65 ea 0d 8c 82 c3 0c 27 cd c5 e7<br />
4e 78 fe a1 50 a6<br />
</code><br />
And we got back:<br />
<code><br />
92 40 17 c0 a8 00 13 74 a0 41 f0<br />
</code><br />
See that common 92 40?  Bingo.  <img src='http://mikeconley.ca/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>And it&#8217;s <em>pretty consistent</em> &#8211; if we repeat the same UDP packet, we get (almost) the same response.</p>
<p><code><br />
<strong>92 40</strong> 67 <strong>c0 a8</strong> <strong>00</strong> <strong>13</strong> 11 00 10 4f<br />
</code></p>
<p>And if we repeat again&#8230;</p>
<p><code><br />
<strong>92 40</strong> 37 <strong>c0 a8 00 13</strong> 68 08 43 3a<br />
</code></p>
<p>92, 40, and c0, a8, 00, 13.  Nice!  Looks like a fingerprint to me!</p>
<h3>Except&#8230;</h3>
<p>Except, remember, we already found a way of determining whether or not Skype was running behind a given IP/port.  This last finding was just bonus.  My partner and I aren&#8217;t sure if our instructor is going to let us stay with this topic, seeing as how it&#8217;s pretty much been solved by other people before.  We&#8217;ve only got 2 weeks before this project is due, so&#8230;if we get another project, let&#8217;s hope it&#8217;s relatively simple.  Push come to shove, we could always try to fingerprint a different protocol&#8230;maybe BitTorrent clients.</p>
<p>Either way, working on this stuff has been pretty cool&#8230;and it let me try out some pretty neat tools that are usually reserved for the people <a href="http://en.wikipedia.org/wiki/Black_hat">with</a> <a href="http://en.wikipedia.org/wiki/Grey_hat">coloured</a> <a href="http://en.wikipedia.org/wiki/White_hat">hats</a> (and no, I didn&#8217;t mean Red Hat):</p>
<ul>
<li><a href="http://nmap.org/">nmap:</a> port scanner that can also do service/os fingerprinting</li>
<li><a href="http://www.secdev.org/projects/scapy/">Scapy:</a> sculpt, gut, spoof, manipulate, and send packets &#8211; the power of C, with the simplicity of Python!  We used Scapy as a library while writing our scripts.  Lots of potential with this tool.  Feel like poisoning an ARP cache?  Scapy is for you!</li>
<li><a href="http://www.wireshark.org/">Wireshark:</a> a network student&#8217;s best friend.</li>
</ul>
<p><a href="http://www.mjalali.com/blog/?p=102">Click here to check out Mohammad&#8217;s blog post about this project.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/12/01/fiddling-around-with-skyp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>alertCheck on Mozilla Addons</title>
		<link>http://mikeconley.ca/blog/2009/08/22/alertcheck-on-mozilla-addons/</link>
		<comments>http://mikeconley.ca/blog/2009/08/22/alertcheck-on-mozilla-addons/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 17:15:28 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[modal]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[suppress]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=662</guid>
		<description><![CDATA[Remember alertCheck &#8211; that Firefox Extension I wrote a while back, that helped suppress annoying popups? I finally decided to post it on Mozilla Addons.  Now compatible with Firefox 3.5.*. Here you go.]]></description>
			<content:encoded><![CDATA[<p>Remember alertCheck &#8211; that Firefox Extension I wrote a while back, that helped suppress annoying popups?</p>
<p>I finally decided to post it on Mozilla Addons.  Now compatible with Firefox 3.5.*.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/13176">Here you go.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/08/22/alertcheck-on-mozilla-addons/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Overriding Firefox’s Window.Alert &#8211; Part 4</title>
		<link>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-4/</link>
		<comments>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-4/#comments</comments>
		<pubDate>Sun, 03 May 2009 21:42:12 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[content.alert]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[window.alert]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=392</guid>
		<description><![CDATA[So, I think I&#8217;m more or less done the extension. Someday, when I&#8217;ve got more extension development experience under my belt, I&#8217;ll probably come back to this and fix it up.  Until then, this will have to do. Click here to download. If you&#8217;re interested in looking at the source, just change the file extension [...]]]></description>
			<content:encoded><![CDATA[<p>So, I think I&#8217;m more or less done the extension.</p>
<p>Someday, when I&#8217;ve got more extension development experience under my belt, I&#8217;ll probably come back to this and fix it up.  Until then, this will have to do.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/13176">Click here to download.</a></p>
<p>If you&#8217;re interested in looking at the source, just change the file extension from &#8220;.xpi&#8221; to &#8220;.zip&#8221;, and decompress.  It&#8217;s all there.</p>
<p>There&#8217;s no license on this thing, no GPL, MIT, nothing.  Use it however you want.  <strong>If you find it useful though, I&#8217;d love to hear from you</strong> &#8211; send me email, post a comment, Facebook, Twitter, whichever.</p>
<p>Whew.  I think I&#8217;m going to reward myself with some orange sherbet.  Om nom nom&#8230;</p>
<p>Here&#8217;s a really annoying website to test the extension with.  <strong>I really don&#8217;t recommend that you visit it without my extension installed</strong>.</p>
<p>The window hops around a bit, so just double click on the location bar, and type in something like &#8220;http://www.google.ca&#8221;.  This will start up the flood of alerts, and (hopefully) you&#8217;ll be able to suppress them after the first one hits.</p>
<p><a href="http://www.bringvictory.com/">Here&#8217;s the site.  Visit at your own risk.</a></p>
<p><strong>UPDATE:</strong></p>
<p>I&#8217;ve <a href="https://addons.mozilla.org/en-US/firefox/addon/13176">moved the extension to Mozilla Addons</a>, and added Firefox 3.5 compatibility.</p>
<p>I&#8217;ve updated alertCheck.xpi so that it&#8217;ll play nice with Firefox 3.0b5, and hopefully Firefox 3.1.*.  Let me know if there are any behaviour foulups, and I&#8217;ll do my best to fix them.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-4/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Overriding Firefox’s Window.Alert &#8211; Part 3</title>
		<link>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-3/</link>
		<comments>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-3/#comments</comments>
		<pubDate>Sun, 03 May 2009 07:14:17 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[content.alert]]></category>
		<category><![CDATA[contentWindow]]></category>
		<category><![CDATA[DOMContentLoaded]]></category>
		<category><![CDATA[DOMWillOpenModalDialog]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[window.alert]]></category>
		<category><![CDATA[wrappedJSObject]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=387</guid>
		<description><![CDATA[Wow.  I think I got it.  I&#8217;ve got a Firefox plugin that can suppress all alert() dialogs on a page if the user checks a &#8220;suppress&#8221; box on the second alert() dialog. The trick, was not to rely on the DOMContentLoaded event to fire to do the override.  Instead, I used the DOMWillOpenModalDialog to detect [...]]]></description>
			<content:encoded><![CDATA[<p>Wow.  I think I got it.  I&#8217;ve got a Firefox plugin that can suppress all alert() dialogs on a page if the user checks a &#8220;suppress&#8221; box on the second alert() dialog.</p>
<p>The trick, was not to rely on the DOMContentLoaded event to fire to do the override.  Instead, I used the DOMWillOpenModalDialog to detect the first alert().  After detection, I overrode with an alertCheck which asked the user whether or not to &#8220;suppress more dialogs&#8221;.  If the user answers in the affirmative, alert() is simply overwritten with an empty function.</p>
<p>Piece of cake.</p>
<p>A couple of issues though&#8230;</p>
<h2>Security</h2>
<p>In order to override the alert() function, I have to write to document.getElementById(&#8216;content&#8217;).contentWindow.wrappedJSObject.alert.</p>
<p>Remember how I mentioned the <em>distance</em> between the Extension JavaScript, and the inline content JavaScript?  I said it felt like a security layer.</p>
<p>I was totally right.</p>
<p><a href="https://developer.mozilla.org/En/Working_with_windows_in_chrome_code#Accessing_content_documents">Check this out.</a> I&#8217;ll quote:</p>
<blockquote><p>You should be aware of <a rel="internal" href="https://developer.mozilla.org/en/XPCNativeWrapper">XPCNativeWrappers</a> when working with <a rel="internal" href="https://developer.mozilla.org/en/XPCNativeWrapper#What_is_a_trusted_window.3F">untrusted content</a>. With XPCNativeWrappers turned on (which is the default in Firefox 1.5+), your extension can safely access the DOM of the content document, but not the content JavaScript. Bypassing XPCNativeWrapper to work with content JavaScript directly can lead to security problems.</p></blockquote>
<p>Hrmph.  So I seem to be violating some security rules here.  So maybe my approach isn&#8217;t the greatest idea.  &#8220;Mook&#8221; from irc.mozilla.net #extdev suggested looking into commonDialog.xul&#8230;but I can&#8217;t seem to wrap my head around that just yet.</p>
<h2>Imperfections</h2>
<p>Not sure why yet, but while I can suppress dialog floods like this:</p>
<pre>for (i = 0; i &lt; 10; ++i) {
  alert(i);
}</pre>
<p>It seems to fail on this:</p>
<pre>for (i = 0; i &lt; 10; ++i) {
  alert(i);
  confirm(i);
}</pre>
<p>For some reason, regardless of whether or not I choose to suppress the dialogs, they just keep coming.  It works fine when I swap out the confirm() for a second alert().  Not exactly sure why.  Yet.</p>
<p>Ok, so I&#8217;m going to clean the code up, and post it soon.  I&#8217;ll also post a link to a real, brutally annoying website where you can test the alertCheck extension.  Just give me a bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overriding Firefox’s Window.Alert &#8211; Part 2</title>
		<link>http://mikeconley.ca/blog/2009/05/02/overriding-firefox%e2%80%99s-windowalert-part-2/</link>
		<comments>http://mikeconley.ca/blog/2009/05/02/overriding-firefox%e2%80%99s-windowalert-part-2/#comments</comments>
		<pubDate>Sat, 02 May 2009 23:19:04 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[commonDialog.xul]]></category>
		<category><![CDATA[content.alert]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[window.alert]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=381</guid>
		<description><![CDATA[Ok, so there have been some developments. Before I go into this though, I just want to make it clear that I have very little knowledge or experience working with XUL, or writing Firefox extensions in general.  I&#8217;ve dabbled, but I&#8217;m mostly ignorant.  So all you Firefox aficionados out there&#8230;go easy on me. So, developments: [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so there have been some developments.</p>
<p>Before I go into this though, I just want to make it clear that I have <em>very little </em>knowledge or experience working with XUL, or writing Firefox extensions in general.  I&#8217;ve dabbled, but I&#8217;m mostly ignorant.  So all you Firefox aficionados out there&#8230;go easy on me.</p>
<p>So, developments:</p>
<p>Using <a href="http://ted.mielczarek.org/code/mozilla/extensionwiz/">this site</a>, I created a skeleton for my extension, calling it &#8220;alertCheck&#8221;.</p>
<p>And then I hit a brick wall right away, trying to find the right &#8220;alert&#8221; to override.</p>
<p>Let me explain.  Mozilla extension development is strange for me because of all of the various layers to Firefox, and the <em>distance</em> between the JavaScript in the extension, and any page that is loaded in the browser.  It feels like a security layer &#8211; and it makes sense:  you <em>really</em> don&#8217;t want the Javascript on a website to monkey around with the internals of your browser.</p>
<p>Thankfully, <a href="http://forums.mozillazine.org/viewtopic.php?f=19&amp;t=326355&amp;p=1791443">this forum</a> and <a href="http://markmail.org/message/gsxdzrhddztbgtbc">this forum</a> provided some help.</p>
<p>Now, after the appcontent is loaded, I wait for the DOMContentLoaded event to fire, and then write my new alert function to here:</p>
<pre>document.getElementById('content').contentWindow.wrappedJSObject.alert</pre>
<p>The problem is, if I wait for the DOMContentLoaded event to fire, the alert override happens (obviously) <em>after </em>all of the DOM Content is loaded into the browser.  This is only useful if the alert&#8217;s that we want to capture are fired using &lt;body onLoad&gt; or some other function that detects when the DOM has been loaded.  It&#8217;s no good for inline Javascript alerts, since these commands are parsed and executed line by line as the HTML is processed.</p>
<p>Phew.  Big mouthful.</p>
<p>So, where does that leave me?  Well, I was just hanging out in irc.mozilla.net in the #extdev channel.  Here&#8217;s a chunk of what was said:</p>
<pre>&lt;mike_conley&gt; Hey all - I'm trying to write an extension to override window.alert, with an alertCheck that allows users to disable future alerts.
&lt;mike_conley&gt; So far, I'm able to override alert by writing to document.getElementById('content').contentWindow.wrappedJSObject.alert
&lt;mike_conley&gt; however, now it's a matter of timing - I'm doing the override after the DOMContentLoaded event is fired
&lt;mike_conley&gt; But this means that it doesn't catch alerts that are fired using inline javascript.
&lt;mike_conley&gt; So my question is, when should I do the override?
&lt;Mook&gt; I suspect just overriding commonDialog.xul is easier
&lt;Mook&gt; trying to poke the content JS's definition is going to be full of pain
&lt;mike_conley&gt; Cool, I'll look into that - thanks!
&lt;Mook&gt; (the content JS starts around http://mxr.mozilla.org/mozilla/source/dom/src/base/nsGlobalWindow.cpp#4022 and goes the the prompt service which pokes that xul)
&lt;mike_conley&gt; Excellent - I appreciate it.</pre>
<p>So maybe there&#8217;s another approach that I should be taking &#8211; I&#8217;m going to look into overriding commonDialog.xul&#8230; I&#8217;ll write more when I have it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/05/02/overriding-firefox%e2%80%99s-windowalert-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Overriding Firefox&#8217;s Window.Alert &#8211; Part 1</title>
		<link>http://mikeconley.ca/blog/2009/04/28/overriding-firefoxs-windowalert-chapter-1/</link>
		<comments>http://mikeconley.ca/blog/2009/04/28/overriding-firefoxs-windowalert-chapter-1/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 19:46:43 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[window.alert]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=377</guid>
		<description><![CDATA[Window.alert is a native function built into Firefox &#8211; but that doesn&#8217;t mean it can&#8217;t be overridden. Check this out: Open Firebug, and get to the console.  Then, click that little red arrow at the end of the input line so that you get the large box input on the right side of the screen. [...]]]></description>
			<content:encoded><![CDATA[<p>Window.alert is a native function built into Firefox &#8211; but that doesn&#8217;t mean it can&#8217;t be overridden.</p>
<p>Check this out:</p>
<p>Open <a href="http://getfirebug.com/">Firebug</a>, and get to the console.  Then, click that little red arrow at the end of the input line so that you get the large box input on the right side of the screen.</p>
<p>Type this into the input box:</p>
<pre>var alert_count = 0;
var old_alert = window.alert;
var alert_max = 5;
window.alert = function(alert_text) {
  if (alert_count &lt; alert_max) {
    ++alert_count;
    old_alert(alert_text);
  } else {
    console.log("Reached maximum alerts");
  }
}</pre>
<p>Now, hit &#8220;Run&#8221; at the bottom of that input window.  We&#8217;ve just overridden the window.alert function during runtime.</p>
<p>Hit &#8220;Clear&#8221; at the bottom of the input window, and type in:</p>
<pre>for (i = 0; i &lt; 10; ++i) {
  alert(i);
}</pre>
<p>Hit &#8220;Run&#8221;.  Click &#8220;OK&#8221; for the first 5 alert windows, and watch as the rest of them are spewed out to the console.  Nice.</p>
<p>So, I don&#8217;t think this helps me much in creating my plug-in, but it&#8217;s interesting to see how window.alert is malliable at run-time.</p>
<p><a href="https://developer.mozilla.org/en/NsIPromptService#alertCheck">This seems to be a more relevant discovery</a> &#8211; Mozilla&#8217;s Chrome lets me create an alert popup with a checkbox using alertCheck.  I think this is exactly what I&#8217;m looking for.</p>
<p>I&#8217;ll tinker with it over the next few days, and post some code.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/04/28/overriding-firefoxs-windowalert-chapter-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Summer Project:  Firefox Plugin to Override Window.Alert</title>
		<link>http://mikeconley.ca/blog/2009/04/27/summer-project-firefox-plugin-to-override-window-alert/</link>
		<comments>http://mikeconley.ca/blog/2009/04/27/summer-project-firefox-plugin-to-override-window-alert/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 00:15:18 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=374</guid>
		<description><![CDATA[When I don&#8217;t have work to do, I get antsy. And right now, I&#8217;ve got no work to do. So I&#8217;ve come up with a project for myself:  remember how I created a Firefox Plugin a few months back?  I&#8217;d like to make another one &#8211; but this one will actually serve a useful purpose. [...]]]></description>
			<content:encoded><![CDATA[<p>When I don&#8217;t have work to do, I get antsy.</p>
<p>And right now, I&#8217;ve got no work to do.</p>
<p>So I&#8217;ve come up with a project for myself:  <a href="http://mikeconley.ca/blog/2009/03/05/making-my-first-firefox-extension-before-5pm-today/">remember how I created a Firefox Plugin a few months back?</a>  I&#8217;d like to make another one &#8211; but this one will actually serve a useful purpose.</p>
<p>Have you ever been to a page that suddenly started spewing window.alert boxes at you?</p>
<p>If you haven&#8217;t, open up Firebug, and paste this into the console:</p>
<pre><span class="objectBox objectBox-text">for(i = 0; i &lt; 10; ++i){ alert(i); }</span></pre>
<p>Now imagine if instead of 10 alert boxes, it spewed hundreds&#8230;or thousands&#8230;.or god forbid, it uses a while(true) loop, and throws infinity alert boxes at you.</p>
<p>It totally cripples Firefox. It&#8217;s a super simple browser DoS attack.</p>
<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=59314">Mozilla knows this</a>, but so far, no solution except for killing the Firefox process, or disabling Javascript manually, or with <a href="http://noscript.net/">NoScript</a> (a plugin that I highly recommend).</p>
<p>Google Chrome has solved this problem by <a href="http://blog.spathare.com/2009/02/chrome-prevents-javascript-alert-loop/">providing a checkbox on alert dialogs that allow a user to disable future popups from the current site</a>.</p>
<p>Cool.  I want Firefox to have the same feature.</p>
<p>So, this summer, I&#8217;m going to <em>try </em>to build a Firefox Plugin that will override the standard window.alert function, with one that provides a checkbox, letting the user disable future alerts.</p>
<p>I don&#8217;t even know if this is possible, but I&#8217;m looking into it.</p>
<p>I&#8217;ll blog my research and progress as I go along, and share my code / final plugin when it&#8217;s all finished (or when I abandon it&#8230;hey, it happens).</p>
<p>So stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/04/27/summer-project-firefox-plugin-to-override-window-alert/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Injection Prevention in PHP &#8211; Tip 1</title>
		<link>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/</link>
		<comments>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 21:36:38 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=157</guid>
		<description><![CDATA[It&#8217;s amazing &#8211; I&#8217;ve been going around, Googling for anything with &#8220;index.php?id=&#8221;&#8230;and that&#8217;s really all it takes.  Now, granted, SQL Injection isn&#8217;t new, and a lot of the top hits have taken some steps to protect themselves, but if you go deep &#8211; like, Google search page 23 deep &#8211; you&#8217;ll find ones that break [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s amazing &#8211; I&#8217;ve been going around, Googling for anything with &#8220;index.php?id=&#8221;&#8230;and that&#8217;s really all it takes.  Now, granted, SQL Injection isn&#8217;t new, and a lot of the top hits have taken some steps to protect themselves, but if you go deep &#8211; like, Google search page 23 deep &#8211; you&#8217;ll find ones that break if you put a semi-colon after the id # &#8211; and if it breaks, it&#8217;s vulnerable.</p>
<p>So, here&#8217;s my first tip on preventing SQL Injection &#8211; when you&#8217;re asking for an ID number, make sure it&#8217;s a number, and nothing else.  Also consider using prepared statements &#8211; database wrappers like <a href="http://pear.php.net/package/MDB2">MDB2</a> for PHP make this easy.</p>
<p>Check this out &#8211; this might be how I would have done it 3 years ago:</p>
<pre>&lt;?php
  //Assume we're already connected to a MySQL database...
  $id = $_GET['id'];

  $result = mysql_query('SELECT * from pages where id='.$id);
  if (!$result) {
     die('Invalid query: ' . mysql_error());
  }
  ... //Code to print out my result to the page
?&gt;</pre>
<p>I&#8217;d do it this way now:</p>
<p><strong>Note:</strong> My use of MDB2 might be a little rusty &#8211; I haven&#8217;t tested this code, and I usually compose RowDataGateway objects with MDB2 to represent my data.  So pay more attention to the structure than the actual syntax.</p>
<pre>&lt;?php
  require 'View.php';
  require 'MDB2.php';  //An excellent DB layer from the PEAR libs

  //Code to set $mdb2 as our DB connection variable
  //See http://pear.php.net/package/MDB2 for details
  $id = $_GET['id'];

  try {
    if(!is_int($id)) {
      //ID wasn't an int, it's no good, let's bail
      throw new Exception('Could not recognize the id that you passed');
    }
    //ID was an int, let's see if we can find the record
    $sql = 'SELECT * from pages where id=:id";
    $statement = $mdb2-&gt;prepare($sql);
    $statement-&gt;bindParam('id', $id);
    $result = $statement-&gt;execute();
    if(PEAR::isError($result)) {
      //Uh oh - our result was an error on the PEAR library level
      throw new Exception('There was an error communicating with the database');
    }
    //Insert the database result into the view, render, and die.
    $content = new View('templates/page.tpl', array('page' =&gt; $result-&gt;fetchOne()));
    $content-&gt;render();
    die;
  }
  catch(Exception $e) {
    //We must have caught an exception - put this into our
    //error page template with the error message, render, die.
    $content = new View('templates/error.tpl', array('message' =&gt; $e-&gt;getMessage()));
    $content-&gt;render();
    die;
  }
?&gt;</pre>
<p>Yes, it&#8217;s quite a bit more code.  But I feel safer just looking at it.<br />
Did I miss anything on this?  Please post a comment if you  notice that I&#8217;ve left a gaping hole.  Learning is good.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing SQL Injection Attacks</title>
		<link>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/</link>
		<comments>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 18:48:04 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=125</guid>
		<description><![CDATA[Over the reading week, along with studying for various midterms and assignments, I&#8217;ve decided to brush up on preventing SQL Injection attacks in web applications. Pretty scary/awesome stuff out there on this stuff.  Here&#8217;s a great place to get some SQL Injection training, and here&#8217;s an excellent SQL Injection cheat sheet. I got hit with [...]]]></description>
			<content:encoded><![CDATA[<p>Over the reading week, along with studying for various midterms and assignments, I&#8217;ve decided to brush up on preventing SQL Injection attacks in web applications.</p>
<p>Pretty scary/awesome stuff out there on this stuff.  <a href="http://www.hackthissite.org" target="_self">Here&#8217;s a great place to get some SQL Injection training</a>, and <a href="http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/" target="_self">here&#8217;s an excellent SQL Injection cheat sheet</a>.</p>
<p>I got hit with a pretty bad SQL Injection attack last summer on an application I had written 3 years ago (before I had any clue that SQL Injection attacks were possible).</p>
<p>Here&#8217;s the take home message:  <strong>never trust user input.  Ever. </strong>If you&#8217;re expecting an int, make sure it&#8217;s an int.  <strong>Never insert user input directly into an SQL string.</strong> Use prepared statements instead, or stored procedures.</p>
<p>Luckily, I just did a quick survey of all of my running apps, and I seem to be OK in terms of SQL Injection.  Still, it&#8217;s a common attack vector &#8211; and the consequences of being lazy on user input can be pretty awful.</p>
<p><strong>Update: </strong> Want to see something awesome?  <a href="http://www.milw0rm.com/video/watch.php?id=92" target="_self">Check this out &#8211; a Debian box gets rooted through MySQL injection&#8230;killer soundtrack too.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

