<?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>david mccuskey.com &#187; Python</title>
	<atom:link href="http://davidmccuskey.com/category/programming/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidmccuskey.com</link>
	<description>my slice of the Internet</description>
	<lastBuildDate>Thu, 22 Jul 2010 16:58:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Generating Random Session IDs</title>
		<link>http://davidmccuskey.com/2009/09/generating-random-session-ids/</link>
		<comments>http://davidmccuskey.com/2009/09/generating-random-session-ids/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 21:03:36 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.mccuskey.com/?p=578</guid>
		<description><![CDATA[For any online service you must login so you can gain access to your stuff. So that you only have to put in your password once, the website must maintain a special unique character sequence called a session key to know that you have already authenticated. There is a problem with these keys, however, if [...]]]></description>
			<content:encoded><![CDATA[<p>For any online service you must login so you can gain access to your stuff.  So that you only have to put in your password once, the website must maintain a special unique character sequence called a <em>session key</em> to know that you have already authenticated.</p>

<p>There is a problem with these keys, however, if they are not truly random. This is detailed in a paper I stumbled upon entitled &#8220;Brute-Force Exploitation of Web Application Session IDs&#8221; by David Endler. It covers ways in which these keys can be &#8220;hacked&#8221; because they are not unique, but rather follow some sequence which can be guessed. He lists some major websites which he was able to get access to information that should have been private.</p>

<p>The paper got me thinking about how to generate random session keys, so I created some quick Python scripts using Twisted which demonstrates my solution. (This was my first time using Twisted, so it&#8217;s very possible that there is a better way to structure the code).</p>

<h4>Solution</h4>

<p>The character buffer in the server is used to generate new keys.</p>

<p>To fill the buffer:</p>

<p>0. Create a list of websites which themselves deliver random web pages (eg, wikipedia)<br />
1. Select a website from random and ask for a random page<br />
2. Grab the data within the <span class="caps">HTML </span><em>body</em> tags and put that string in the character buffer<br />
3. When the buffer needs more data, go back to 1.</p>

<p>To generate X number of keys:</p>

<p>0. Grab two random lengths of the character buffer. Use one to re-seed the random generator and the other as the basis for the new session key. Create the session key using <span class="caps">MD5 </span>and the key seed<br />
1. Update() the current <span class="caps">MD5 </span>session key using a generated random character / string<br />
2. Add that key to the buffer.<br />
3. When the key buffer needs more keys, go back to Step 1. For every Y number of keys generated, go back to Step 0.</p>


<h4>Notes</h4>

<p>We don&#8217;t use a a new seed for each <span class="caps">MD5 </span>session key because the buffer will be emptied too quickly. Of course, the settings for the buffer size, etc could be tweaked.</p>

<h4>Performance</h4>

<p>Running the server code on my Mac Mini (2.16GHz Dual Core) and 5 clients on another machine, I was able to service ~8000 keys/sec (~750 million keys/day).</p>

<h4>Conclusion</h4>

<p>My experiment satisfied my curiosity and answered the questions from my own project.</p>

<p>There are, of course, many tweaks that can be made. Send me the code changes to your favorites and I&#8217;ll include them.</p>

<p><a href="/downloads/code/HTTP-Session-Key.zip">Click to download the client server files.</a></p>

<h3>Resources</h3>


<ul>
<li><a href="http://www.cgisecurity.com/lib/SessionIDs.pdf">Brute-Force Exploitation fo Web Application Session IDs</a> (PDF)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2009/09/generating-random-session-ids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting journal entries from Outlook to MacJournal</title>
		<link>http://davidmccuskey.com/2007/06/converting-journal-entries-from-outlook-to-macjournal/</link>
		<comments>http://davidmccuskey.com/2007/06/converting-journal-entries-from-outlook-to-macjournal/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 05:26:49 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/converting-journal-entries-from-outlook-to-macjournal.html#unique-entry-id-22</guid>
		<description><![CDATA[I wrote a Python script to convert a journal file export from Microsoft Outlook to one which can be read by MacJournal. It requires the Python module csv (included with Python 2.3 or later) Run the script like so: ./outlook2macjournal.py [input_file] [output_file] If no input or output files are listed, it will use the following [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a Python script to convert a journal file export from Microsoft Outlook to one which can be read by MacJournal.</p>

<p>It requires the Python module csv (included with Python 2.3 or later)</p>

<p>Run the script like so:</p>


<pre>./outlook2macjournal.py [input_file] [output_file]</pre>


<p>If no input or output files are listed, it will use the following defaults:</p>

<p>Outlook (input): <code>exchange_export.csv</code><br />
MacJournal (output): <code>macjournal_import.txt</code></p>

<p>You can <a href="/wp-content/uploads/2010/07/outlook2macjournal.py_.zip" title="outlook2macjournal.py.zip"> click here to download the Outlook to MacJournal Python script</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2007/06/converting-journal-entries-from-outlook-to-macjournal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing Python-style imports in JavaScript</title>
		<link>http://davidmccuskey.com/2006/03/doing-python-style-imports-in-javascript/</link>
		<comments>http://davidmccuskey.com/2006/03/doing-python-style-imports-in-javascript/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 02:53:57 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/doing-python-style-imports-in-javascript.html#unique-entry-id-7</guid>
		<description><![CDATA[Lately at work I&#8217;ve been doing a lot of programming in JavaScript. Among other things, I have been learning about using the prototype object to do object oriented programming. One thing that I missed was the feature in Python used to import modules directly into other code. For example: from glorp import blah import foo [...]]]></description>
			<content:encoded><![CDATA[<p>Lately at work I&#8217;ve been doing a lot of programming in JavaScript. Among other things, I have been learning about using the prototype object to do object oriented programming. One thing that I missed was the feature in Python used to import modules directly into other code. For example:</p>


<pre>from glorp import blah
import foo</pre>


<p>I was happy to have found an open-source project which emulates that functionality in JavaScript! I haven&#8217;t been able to do more than skim the web site, but it looks promising.</p>

<h3>Resources</h3>


<ul>
<li><a rel="external" href="http://ajile.sourceforge.net/">http://ajile.sourceforge.net/</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2006/03/doing-python-style-imports-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

