<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Breaking Code</title>
	<atom:link href="http://breakingcode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://breakingcode.wordpress.com</link>
	<description>When a meth lab&#039;s not an option, get into infosec instead.</description>
	<lastBuildDate>Sun, 19 May 2013 10:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='breakingcode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Breaking Code</title>
		<link>http://breakingcode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://breakingcode.wordpress.com/osd.xml" title="Breaking Code" />
	<atom:link rel='hub' href='http://breakingcode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A Python example on finding connected components in a graph</title>
		<link>http://breakingcode.wordpress.com/2013/04/08/finding-connected-components-in-a-graph/</link>
		<comments>http://breakingcode.wordpress.com/2013/04/08/finding-connected-components-in-a-graph/#comments</comments>
		<pubDate>Mon, 08 Apr 2013 21:30:26 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=778</guid>
		<description><![CDATA[This is a simple Python example of a non-recursive connected components finding algorithm.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=778&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">Today I&#8217;ve been coding a solution for a problem we&#8217;ve encountered with <a href="https://twitter.com/ggdaniel">@ggdaniel (cr0hn)</a> during the development of <a href="https://code.google.com/p/golismero/">GoLismero 2.0</a>. It called for an implementation of an algorithm to find <strong>connected components</strong> in an <strong>undirected graph</strong>. You can find the source code at the bottom of this post.</span></p>
<p><span style="font-size:120%;"><br />
<h2>A graph algorithm a day keeps the CS doctor away&#8230;</h2>
<p></span></p>
<p><span style="font-size:120%;">Suppose we have an <strong>undirected graph</strong> (connected by lines rather than arrows) in which we can find one or more &#8220;islands&#8221; of nodes that form connections to each other, but not to nodes in other &#8220;islands&#8221;. In graph theory, these &#8220;islands&#8221; are called <strong>connected components</strong>. In the image below, we see a graph with three connected components:</p>
<p><a href="https://en.wikipedia.org/wiki/File:Pseudoforest.svg"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Pseudoforest.svg/400px-Pseudoforest.svg.png" alt="Example graph with three connected components. Image from Wikipedia." class="aligncenter" /></a></p>
<p><span style="font-size:120%;">Now, suppose we have a set containing all nodes, and we can visit each node to know what are its <strong>neighbors</strong>, that is, the other nodes it&#8217;s connected to. We want to find all the connected components and put their nodes into separate sets. How would we do that?</span></p>
<p><span id="more-778"></span></p>
<p><span style="font-size:120%;">Luckily, <a href="https://en.wikipedia.org/wiki/Connected_component_(graph_theory)">according to the Internet</a> (what would I do without it! get a &#8220;proper&#8221; job I guess) there&#8217;s a well known algorithm to solve this problem. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and it would go more or less like this. Grab a random node from the graph, and add it to a new set. Now get all the neighbors of this node, <em>discard the ones we already visited</em> (so we don&#8217;t get stuck in an infinite loop), add them to the set, and keep doing the same thing from the beginning with each neighbor, recursively. When we&#8217;re done visiting neighbors, that means we finished finding one of the connected components &#8211; we can start over with a new random node <em>we haven&#8217;t visited yet</em> to find the next connected component, and so on until we visited all the nodes.</span></p>
<p><span style="font-size:120%;">Confused? Let&#8217;s start over, this time with an example.</span></p>
<p><img src="http://breakingcode.files.wordpress.com/2013/04/connected-components-1.png?w=481&#038;h=301" alt="connected-components-1" width="481" height="301" class="aligncenter size-full wp-image-793" /></p>
<p><span style="font-size:120%;">In the above example we&#8217;d start with a set containing 5 nodes (<b>A</b> through <b>E</b>), where <b>B</b> is connected to <b>A</b> and <b>D</b>, and <b>C</b> is connected to <b>E</b>. So let&#8217;s pick a random node, say <b>C</b>. We paint <b>C</b> in blue and get the neighbors, in this case it&#8217;s just <b>E</b>. Now we visit <b>E</b>, so we paint it blue and get the neighbors, now it&#8217;s <b>C</b> again. Since we already visited <b>C</b> (we know because it&#8217;s already painted blue) we discard it. Now we have no more nodes to visit, so we&#8217;re finished getting the first connected component.</span></p>
<p><img src="http://breakingcode.files.wordpress.com/2013/04/connected-components-2.png?w=481&#038;h=301" alt="connected-components-2" width="481" height="301" class="aligncenter size-full wp-image-792" /></p>
<p><span style="font-size:120%;">But that was the easy one, and we&#8217;ve still got 3 more nodes to go. Let&#8217;s pick a random one from the ones we didn&#8217;t visit yet, that is, the nodes that remain gray (<b>A</b>, <b>B</b> and <b>D</b>), for example <b>A</b>. We paint it green and get the neighbors, which is just <b>B</b>. Now we visit <b>B</b>, paint it green and get the neighbors, <b>A</b> and <b>D</b>. But <b>A</b> was already visited (it&#8217;s green already) so we discard it, leaving only <b>D</b>. Finally we visit <b>D</b>, paint it green, and get its neighbor <b>B</b>. Since <b>B</b> was already visited we discard it. This leaves no more nodes to visit, and we&#8217;re finished.</span></p>
<p><img src="http://breakingcode.files.wordpress.com/2013/04/connected-components-3.png?w=481&#038;h=301" alt="connected-components-3" width="481" height="301" class="aligncenter size-full wp-image-794" /></p>
<p><span style="font-size:120%;"><br />
<h2>But what was the problem I was trying to solve?</h2>
<p></span></p>
<p><span style="font-size:120%;">If you came here only looking for the graph theory bit then you can safely skip this part <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  but if I can interest you with some tidbits on the internals of GoLismero, here&#8217;s a summary:</span></p>
<p><span style="font-size:120%;">During the execution of the program, we have a given number of plugins all running concurrently, and a series of messages with data that are sent to each plugin for processing. Each plugin may also create new data objects and send them to the main process, who in turn re-sends it to the rest of the plugins. For example, the <em>Web Spider</em> plugin would crawl a website and create URL objects for each link it finds, and HTML objects for each page it downloads; then those objects are sent to other plugins that would analyze the URLs and the HTML pages looking for vulnerabilities, and creating Vulnerability objects describing each vulnerability they find. Another plugin may receive a vulnerability and exploit it -for example, an URL disclosure vulnerability- creating new URL objects, which in turn get sent to the <em>Web Spider</em> for crawling, and so on.</span></p>
<p><span style="font-size:120%;">The data objects also contain references to each other &#8212; for example, if a data object contains an HTML page, it&#8217;ll also have a reference to another data object with the URL where it was found, and vice versa. If a vulnerability is found in that page, another data object will be generated with the description of the vulnerability, and it will also reference the URL where the vulnerability was found. The URL, in turn, will reference the vulnerability that was found on it.</span></p>
<p><span style="font-size:120%;">More generally, this leaves us with an <strong>undirected graph</strong> of data objects, since any data object can reference any other data object, but references always go back and forth. Also, we store every data object in a database, where they can be consulted at any time by a plugin.</span></p>
<p><span style="font-size:120%;">Now, this would be the problem: before we can send any data object to a running plugin, we have to make sure all other data objects it references are already stored in the database &#8212; otherwise, we might run into a <strong>race condition</strong> between the time the data object is sent to the plugins and the objects it references are stored in the database. If we fail to solve this, a plugin would occasionally find a data object references another object that can&#8217;t be found in the database.</span></p>
<p><span style="font-size:120%;">To prevent this, a simple algorithm was needed to find clusters of objects that reference each other (a <strong>connected component</strong>). So as plugins send messages to the main process, the main process holds them until it can be sure it has a group of objects that aren&#8217;t referencing any data that hasn&#8217;t yet arrived. When the whole cluster is complete, it&#8217;s stored in the database and sent to the rest of the plugins.</span></p>
<p><span style="font-size:120%;"><br />
<h2>Enough of this nonsense already, where&#8217;s the example code?!</h2>
<p></span></p>
<p><span style="font-size:120%;">Behold! Here it is, in all of its syntax-colored glory. (?)</span></p>
<p><span style="font-size:120%;">Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </span></p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/example-connected-components.py">example-connected-components.py</a></h3>
</p>
<div class="highlight" style="background:#f8f8f8;">
<pre style="line-height:125%;">
    <span style="color:#408080;font-style:italic;">#!/usr/bin/env python</span>
    
    <span style="color:#408080;font-style:italic;"># Finding connected components in a bidirectional graph.</span>
    <span style="color:#408080;font-style:italic;"># By Mario Vilas (mvilas at gmail dot com)</span>
    
    <span style="color:#408080;font-style:italic;"># The graph nodes.</span>
    <span style="color:#008000;font-weight:bold;">class</span> <span style="color:#0000FF;font-weight:bold;">Data</span>(<span style="color:#008000;">object</span>):
        <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">__init__</span>(<span style="color:#008000;">self</span>, name):
            <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__name  <span style="color:#666666;">=</span> name
            <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__links <span style="color:#666666;">=</span> <span style="color:#008000;">set</span>()
    
        <span style="color:#AA22FF;">@property</span>
        <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">name</span>(<span style="color:#008000;">self</span>):
            <span style="color:#008000;font-weight:bold;">return</span> <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__name
    
        <span style="color:#AA22FF;">@property</span>
        <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">links</span>(<span style="color:#008000;">self</span>):
            <span style="color:#008000;font-weight:bold;">return</span> <span style="color:#008000;">set</span>(<span style="color:#008000;">self</span><span style="color:#666666;">.</span>__links)
    
        <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">add_link</span>(<span style="color:#008000;">self</span>, other):
            <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__links<span style="color:#666666;">.</span>add(other)
            other<span style="color:#666666;">.</span>__links<span style="color:#666666;">.</span>add(<span style="color:#008000;">self</span>)
    
    <span style="color:#408080;font-style:italic;"># The function to look for connected components.</span>
    <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">connected_components</span>(nodes):
    
        <span style="color:#408080;font-style:italic;"># List of connected components found. The order is random.</span>
        result <span style="color:#666666;">=</span> []
    
        <span style="color:#408080;font-style:italic;"># Make a copy of the set, so we can modify it.</span>
        nodes <span style="color:#666666;">=</span> <span style="color:#008000;">set</span>(nodes)
    
        <span style="color:#408080;font-style:italic;"># Iterate while we still have nodes to process.</span>
        <span style="color:#008000;font-weight:bold;">while</span> nodes:
    
            <span style="color:#408080;font-style:italic;"># Get a random node and remove it from the global set.</span>
            n <span style="color:#666666;">=</span> nodes<span style="color:#666666;">.</span>pop()
    
            <span style="color:#408080;font-style:italic;"># This set will contain the next group of nodes connected to each other.</span>
            group <span style="color:#666666;">=</span> {n}
    
            <span style="color:#408080;font-style:italic;"># Build a queue with this node in it.</span>
            queue <span style="color:#666666;">=</span> [n]
    
            <span style="color:#408080;font-style:italic;"># Iterate the queue.</span>
            <span style="color:#408080;font-style:italic;"># When it&#039;s empty, we finished visiting a group of connected nodes.</span>
            <span style="color:#008000;font-weight:bold;">while</span> queue:
    
                <span style="color:#408080;font-style:italic;"># Consume the next item from the queue.</span>
                n <span style="color:#666666;">=</span> queue<span style="color:#666666;">.</span>pop(<span style="color:#666666;">0</span>)
    
                <span style="color:#408080;font-style:italic;"># Fetch the neighbors.</span>
                neighbors <span style="color:#666666;">=</span> n<span style="color:#666666;">.</span>links
    
                <span style="color:#408080;font-style:italic;"># Remove the neighbors we already visited.</span>
                neighbors<span style="color:#666666;">.</span>difference_update(group)
    
                <span style="color:#408080;font-style:italic;"># Remove the remaining nodes from the global set.</span>
                nodes<span style="color:#666666;">.</span>difference_update(neighbors)
    
                <span style="color:#408080;font-style:italic;"># Add them to the group of connected nodes.</span>
                group<span style="color:#666666;">.</span>update(neighbors)
    
                <span style="color:#408080;font-style:italic;"># Add them to the queue, so we visit them in the next iterations.</span>
                queue<span style="color:#666666;">.</span>extend(neighbors)
    
            <span style="color:#408080;font-style:italic;"># Add the group to the list of groups.</span>
            result<span style="color:#666666;">.</span>append(group)
    
        <span style="color:#408080;font-style:italic;"># Return the list of groups.</span>
        <span style="color:#008000;font-weight:bold;">return</span> result
    
    <span style="color:#408080;font-style:italic;"># The test code...</span>
    <span style="color:#008000;font-weight:bold;">if</span> __name__ <span style="color:#666666;">==</span> <span style="color:#BA2121;">&quot;__main__&quot;</span>:
    
        <span style="color:#408080;font-style:italic;"># The first group, let&#039;s make a tree.</span>
        a <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;a&quot;</span>)
        b <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;b&quot;</span>)
        c <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;c&quot;</span>)
        d <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;d&quot;</span>)
        e <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;e&quot;</span>)
        f <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;f&quot;</span>)
        a<span style="color:#666666;">.</span>add_link(b)    <span style="color:#408080;font-style:italic;">#      a</span>
        a<span style="color:#666666;">.</span>add_link(c)    <span style="color:#408080;font-style:italic;">#     / \</span>
        b<span style="color:#666666;">.</span>add_link(d)    <span style="color:#408080;font-style:italic;">#    b   c</span>
        c<span style="color:#666666;">.</span>add_link(e)    <span style="color:#408080;font-style:italic;">#   /   / \</span>
        c<span style="color:#666666;">.</span>add_link(f)    <span style="color:#408080;font-style:italic;">#  d   e   f</span>
    
        <span style="color:#408080;font-style:italic;"># The second group, let&#039;s leave a single, isolated node.</span>
        g <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;g&quot;</span>)
    
        <span style="color:#408080;font-style:italic;"># The third group, let&#039;s make a cycle.</span>
        h <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;h&quot;</span>)
        i <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;i&quot;</span>)
        j <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;j&quot;</span>)
        k <span style="color:#666666;">=</span> Data(<span style="color:#BA2121;">&quot;k&quot;</span>)
        h<span style="color:#666666;">.</span>add_link(i)    <span style="color:#408080;font-style:italic;">#    h----i</span>
        i<span style="color:#666666;">.</span>add_link(j)    <span style="color:#408080;font-style:italic;">#    |    |</span>
        j<span style="color:#666666;">.</span>add_link(k)    <span style="color:#408080;font-style:italic;">#    |    |</span>
        k<span style="color:#666666;">.</span>add_link(h)    <span style="color:#408080;font-style:italic;">#    k----j</span>
    
        <span style="color:#408080;font-style:italic;"># Put all the nodes together in one big set.</span>
        nodes <span style="color:#666666;">=</span> {a, b, c, d, e, f, g, h, i, j, k}
    
        <span style="color:#408080;font-style:italic;"># Find all the connected components.</span>
        number <span style="color:#666666;">=</span> <span style="color:#666666;">1</span>
        <span style="color:#008000;font-weight:bold;">for</span> components <span style="color:#AA22FF;font-weight:bold;">in</span> connected_components(nodes):
            names <span style="color:#666666;">=</span> <span style="color:#008000;">sorted</span>(node<span style="color:#666666;">.</span>name <span style="color:#008000;font-weight:bold;">for</span> node <span style="color:#AA22FF;font-weight:bold;">in</span> components)
            names <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;, &quot;</span><span style="color:#666666;">.</span>join(names)
            <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;Group #</span><span style="color:#BB6688;font-weight:bold;">%i</span><span style="color:#BA2121;">: </span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;">&quot;</span> <span style="color:#666666;">%</span> (number, names)
            number <span style="color:#666666;">+=</span> <span style="color:#666666;">1</span>
    
        <span style="color:#408080;font-style:italic;"># You should now see the following output:</span>
        <span style="color:#408080;font-style:italic;"># Group #1: a, b, c, d, e, f</span>
        <span style="color:#408080;font-style:italic;"># Group #2: g</span>
        <span style="color:#408080;font-style:italic;"># Group #3: h, i, j, k</span>
</pre>
</div>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/algorithms/'>algorithms</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/778/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=778&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2013/04/08/finding-connected-components-in-a-graph/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Pseudoforest.svg/400px-Pseudoforest.svg.png" medium="image">
			<media:title type="html">Example graph with three connected components. Image from Wikipedia.</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2013/04/connected-components-1.png" medium="image">
			<media:title type="html">connected-components-1</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2013/04/connected-components-2.png" medium="image">
			<media:title type="html">connected-components-2</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2013/04/connected-components-3.png" medium="image">
			<media:title type="html">connected-components-3</media:title>
		</media:content>
	</item>
		<item>
		<title>An example dependency resolution algorithm in Python</title>
		<link>http://breakingcode.wordpress.com/2013/03/11/an-example-dependency-resolution-algorithm-in-python/</link>
		<comments>http://breakingcode.wordpress.com/2013/03/11/an-example-dependency-resolution-algorithm-in-python/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 13:36:12 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=754</guid>
		<description><![CDATA[This is a simple Python example of a non-recursive dependency resolving algorithm.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=754&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">I&#8217;ve been toying with dependency resolution a bit today, since it&#8217;s one of the features we plan to add to <a href="https://code.google.com/p/golismero/">GoLismero 2.0</a> plugins with <a href="https://twitter.com/ggdaniel">@ggdaniel (cr0hn)</a>. So I came up with this short example that&#8217;s reasonably fast and doesn&#8217;t use recursion at all, unlike many of the examples that I found on the net.</span></p>
<p><span style="font-size:120%;">The basic idea is this: given a set of tasks (nodes) and the tasks that need to be performed before them, build a dependency graph and find the sets of tasks that can be run concurrently while satisfying the dependencies. For example, suppose we have tasks <strong>A</strong>, <strong>B</strong>, <strong>C</strong> and <strong>D</strong>. Task <strong>A</strong> can be run directly, it has no dependencies. Tasks <strong>B</strong> and <strong>C</strong> must be run only after <strong>A</strong> has completed, so we say <strong>B</strong> and <strong>C</strong> depend on <strong>A</strong>. Then task <strong>D</strong> depends on <strong>B</strong> and <strong>C</strong>, which in turn depend on <strong>A</strong>.</span></p>
<div id="attachment_756" class="wp-caption aligncenter" style="width: 431px"><img src="http://breakingcode.files.wordpress.com/2013/03/dependency-example.png?w=421&#038;h=423" alt="Dependency graph example" width="421" height="423" class="size-full wp-image-756" /><p class="wp-caption-text">Dependency graph example</p></div>
<p><span style="font-size:120%;">What the algorithm does, instead of traversing the graph recursively, is iteratively finding and removing from the graph all nodes that have no dependencies &#8211; that is, no arrows coming out of them. In our example, the first iteration removes node <strong>A</strong>, the second iteration removes nodes <strong>B</strong> and <strong>C</strong>, and the last iteration removes node <strong>D</strong>. And these are precisely the three batches of tasks that can run concurrently &#8211; first task <strong>A</strong> runs, on completion tasks <strong>B</strong> and <strong>C</strong> can run in parallel, and once both are finished task <strong>D</strong> can be started.</span></p>
<p><span style="font-size:120%;">If at some point there are still nodes in the graph but we can&#8217;t find any nodes without dependencies, that means we have a circular dependency.</span></p>
<div id="attachment_758" class="wp-caption aligncenter" style="width: 330px"><img src="http://breakingcode.files.wordpress.com/2013/03/circular-dependency-example.png?w=320&#038;h=119" alt="Circular dependency graph example" width="320" height="119" class="size-full wp-image-758" /><p class="wp-caption-text">Circular dependency graph example</p></div>
<p><span id="more-754"></span></p>
<p><span style="font-size:120%;">Here&#8217;s an example of solving a larger graph, and detecting a circular dependency:</span></p>
<pre>
        $ ./example-dependencies.py
        A working dependency graph example:
        c -&gt; a
        e -&gt; c
        e -&gt; d
        d -&gt; b
        g -&gt; e
        g -&gt; f
        f -&gt; a
        f -&gt; b
        i -&gt; a
        h -&gt; g
        j -&gt; b

        Batches:
        b, a
        i, d, c, f, j
        e
        g
        h

        A broken dependency graph example:
        a -&gt; i
        c -&gt; a
        e -&gt; c
        e -&gt; d
        d -&gt; b
        g -&gt; e
        g -&gt; f
        f -&gt; a
        f -&gt; b
        i -&gt; a
        h -&gt; g
        j -&gt; b

        Trying to resolve the dependencies will raise an exception:

        Traceback (most recent call last):
          File "example-dependencies.py", line 108, in 
            get_task_batches(nodes)
          File "example-dependencies.py", line 42, in get_task_batches
            raise ValueError(msg)
        ValueError: Circular dependencies found!
        a -&gt; i
        c -&gt; a
        e -&gt; c
        g -&gt; e
        g -&gt; f
        f -&gt; a
        i -&gt; a
        h -&gt; g
        $
</pre>
<p>
<h2>Download</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/example-dependencies.py">example-dependencies.py</a></h3>
</p>
<p>
<h2>Source code</h2>
</p>
<div class="highlight" style="background:#f8f8f8;">
<pre style="line-height:125%;"><span style="color:#408080;font-style:italic;">#!/usr/bin/env python</span>

<span style="color:#408080;font-style:italic;"># Dependency resolution example in Python</span>
<span style="color:#408080;font-style:italic;"># By Mario Vilas (mvilas at gmail dot com)</span>

<span style="color:#408080;font-style:italic;"># The graph nodes</span>
<span style="color:#008000;font-weight:bold;">class</span> <span style="color:#0000FF;font-weight:bold;">Task</span>(<span style="color:#008000;">object</span>):
    <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">__init__</span>(<span style="color:#008000;">self</span>, name, <span style="color:#666666;">*</span>depends):
        <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__name    <span style="color:#666666;">=</span> name
        <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__depends <span style="color:#666666;">=</span> <span style="color:#008000;">set</span>(depends)

    <span style="color:#AA22FF;">@property</span>
    <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">name</span>(<span style="color:#008000;">self</span>):
        <span style="color:#008000;font-weight:bold;">return</span> <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__name

    <span style="color:#AA22FF;">@property</span>
    <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">depends</span>(<span style="color:#008000;">self</span>):
        <span style="color:#008000;font-weight:bold;">return</span> <span style="color:#008000;">self</span><span style="color:#666666;">.</span>__depends

<span style="color:#408080;font-style:italic;"># &quot;Batches&quot; are sets of tasks that can be run together</span>
<span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">get_task_batches</span>(nodes):

    <span style="color:#408080;font-style:italic;"># Build a map of node names to node instances</span>
    name_to_instance <span style="color:#666666;">=</span> <span style="color:#008000;">dict</span>( (n<span style="color:#666666;">.</span>name, n) <span style="color:#008000;font-weight:bold;">for</span> n <span style="color:#AA22FF;font-weight:bold;">in</span> nodes )

    <span style="color:#408080;font-style:italic;"># Build a map of node names to dependency names</span>
    name_to_deps <span style="color:#666666;">=</span> <span style="color:#008000;">dict</span>( (n<span style="color:#666666;">.</span>name, <span style="color:#008000;">set</span>(n<span style="color:#666666;">.</span>depends)) <span style="color:#008000;font-weight:bold;">for</span> n <span style="color:#AA22FF;font-weight:bold;">in</span> nodes )

    <span style="color:#408080;font-style:italic;"># This is where we&#039;ll store the batches</span>
    batches <span style="color:#666666;">=</span> []

    <span style="color:#408080;font-style:italic;"># While there are dependencies to solve...</span>
    <span style="color:#008000;font-weight:bold;">while</span> name_to_deps:

        <span style="color:#408080;font-style:italic;"># Get all nodes with no dependencies</span>
        ready <span style="color:#666666;">=</span> {name <span style="color:#008000;font-weight:bold;">for</span> name, deps <span style="color:#AA22FF;font-weight:bold;">in</span> name_to_deps<span style="color:#666666;">.</span>iteritems() <span style="color:#008000;font-weight:bold;">if</span> <span style="color:#AA22FF;font-weight:bold;">not</span> deps}

        <span style="color:#408080;font-style:italic;"># If there aren&#039;t any, we have a loop in the graph</span>
        <span style="color:#008000;font-weight:bold;">if</span> <span style="color:#AA22FF;font-weight:bold;">not</span> ready:
            msg  <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;Circular dependencies found!</span><span style="color:#BB6622;font-weight:bold;">\n</span><span style="color:#BA2121;">&quot;</span>
            msg <span style="color:#666666;">+=</span> format_dependencies(name_to_deps)
            <span style="color:#008000;font-weight:bold;">raise</span> <span style="color:#D2413A;font-weight:bold;">ValueError</span>(msg)

        <span style="color:#408080;font-style:italic;"># Remove them from the dependency graph</span>
        <span style="color:#008000;font-weight:bold;">for</span> name <span style="color:#AA22FF;font-weight:bold;">in</span> ready:
            <span style="color:#008000;font-weight:bold;">del</span> name_to_deps[name]
        <span style="color:#008000;font-weight:bold;">for</span> deps <span style="color:#AA22FF;font-weight:bold;">in</span> name_to_deps<span style="color:#666666;">.</span>itervalues():
            deps<span style="color:#666666;">.</span>difference_update(ready)

        <span style="color:#408080;font-style:italic;"># Add the batch to the list</span>
        batches<span style="color:#666666;">.</span>append( {name_to_instance[name] <span style="color:#008000;font-weight:bold;">for</span> name <span style="color:#AA22FF;font-weight:bold;">in</span> ready} )

    <span style="color:#408080;font-style:italic;"># Return the list of batches</span>
    <span style="color:#008000;font-weight:bold;">return</span> batches

<span style="color:#408080;font-style:italic;"># Format a dependency graph for printing</span>
<span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">format_dependencies</span>(name_to_deps):
    msg <span style="color:#666666;">=</span> []
    <span style="color:#008000;font-weight:bold;">for</span> name, deps <span style="color:#AA22FF;font-weight:bold;">in</span> name_to_deps<span style="color:#666666;">.</span>iteritems():
        <span style="color:#008000;font-weight:bold;">for</span> parent <span style="color:#AA22FF;font-weight:bold;">in</span> deps:
            msg<span style="color:#666666;">.</span>append(<span style="color:#BA2121;">&quot;</span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;"> -&gt; </span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;">&quot;</span> <span style="color:#666666;">%</span> (name, parent))
    <span style="color:#008000;font-weight:bold;">return</span> <span style="color:#BA2121;">&quot;</span><span style="color:#BB6622;font-weight:bold;">\n</span><span style="color:#BA2121;">&quot;</span><span style="color:#666666;">.</span>join(msg)

<span style="color:#408080;font-style:italic;"># Create and format a dependency graph for printing</span>
<span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">format_nodes</span>(nodes):
    <span style="color:#008000;font-weight:bold;">return</span> format_dependencies(<span style="color:#008000;">dict</span>( (n<span style="color:#666666;">.</span>name, n<span style="color:#666666;">.</span>depends) <span style="color:#008000;font-weight:bold;">for</span> n <span style="color:#AA22FF;font-weight:bold;">in</span> nodes ))

<span style="color:#408080;font-style:italic;"># The test code</span>
<span style="color:#008000;font-weight:bold;">if</span> __name__ <span style="color:#666666;">==</span> <span style="color:#BA2121;">&quot;__main__&quot;</span>:

    <span style="color:#408080;font-style:italic;"># An example, working dependency graph</span>
    a <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;a&quot;</span>)
    b <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;b&quot;</span>)
    c <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;c&quot;</span>, <span style="color:#BA2121;">&quot;a&quot;</span>)
    d <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;d&quot;</span>, <span style="color:#BA2121;">&quot;b&quot;</span>)
    e <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;e&quot;</span>, <span style="color:#BA2121;">&quot;c&quot;</span>, <span style="color:#BA2121;">&quot;d&quot;</span>)
    f <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;f&quot;</span>, <span style="color:#BA2121;">&quot;a&quot;</span>, <span style="color:#BA2121;">&quot;b&quot;</span>)
    g <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;g&quot;</span>, <span style="color:#BA2121;">&quot;e&quot;</span>, <span style="color:#BA2121;">&quot;f&quot;</span>)
    h <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;h&quot;</span>, <span style="color:#BA2121;">&quot;g&quot;</span>)
    i <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;i&quot;</span>, <span style="color:#BA2121;">&quot;a&quot;</span>)
    j <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;j&quot;</span>, <span style="color:#BA2121;">&quot;b&quot;</span>)
    k <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;k&quot;</span>)
    nodes <span style="color:#666666;">=</span> (a, b, c, d, e, f, g, h, i, j)

    <span style="color:#408080;font-style:italic;"># Show it on screen</span>
    <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;A working dependency graph example:&quot;</span>
    <span style="color:#008000;font-weight:bold;">print</span> format_nodes(nodes)
    <span style="color:#008000;font-weight:bold;">print</span>

    <span style="color:#408080;font-style:italic;"># Show the batches on screen</span>
    <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;Batches:&quot;</span>
    <span style="color:#008000;font-weight:bold;">for</span> bundle <span style="color:#AA22FF;font-weight:bold;">in</span> get_task_batches(nodes):
        <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;, &quot;</span><span style="color:#666666;">.</span>join(node<span style="color:#666666;">.</span>name <span style="color:#008000;font-weight:bold;">for</span> node <span style="color:#AA22FF;font-weight:bold;">in</span> bundle)
    <span style="color:#008000;font-weight:bold;">print</span>

    <span style="color:#408080;font-style:italic;"># An example, *broken* dependency graph</span>
    a <span style="color:#666666;">=</span> Task(<span style="color:#BA2121;">&quot;a&quot;</span>, <span style="color:#BA2121;">&quot;i&quot;</span>)
    nodes <span style="color:#666666;">=</span> (a, b, c, d, e, f, g, h, i, j)

    <span style="color:#408080;font-style:italic;"># Show it on screen</span>
    <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;A broken dependency graph example:&quot;</span>
    <span style="color:#008000;font-weight:bold;">print</span> format_nodes(nodes)
    <span style="color:#008000;font-weight:bold;">print</span>

    <span style="color:#408080;font-style:italic;"># This should raise an exception and show the current state of the graph</span>
    <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;Trying to resolve the dependencies will raise an exception:&quot;</span>
    <span style="color:#008000;font-weight:bold;">print</span>
    get_task_batches(nodes)
</pre>
</div>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/algorithms/'>algorithms</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/754/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=754&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2013/03/11/an-example-dependency-resolution-algorithm-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2013/03/dependency-example.png" medium="image">
			<media:title type="html">Dependency graph example</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2013/03/circular-dependency-example.png" medium="image">
			<media:title type="html">Circular dependency graph example</media:title>
		</media:content>
	</item>
		<item>
		<title>Navaja Negra (Black Razor) Conference</title>
		<link>http://breakingcode.wordpress.com/2012/12/02/black-razor/</link>
		<comments>http://breakingcode.wordpress.com/2012/12/02/black-razor/#comments</comments>
		<pubDate>Sun, 02 Dec 2012 17:39:05 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[LinkedIn]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=725</guid>
		<description><![CDATA[Aladdin Gurbanov (@SeTx[X]) and I gave a presentation called "Take a walk on the wild side", an introduction to the world of e-crime on the Internet, at the Navaja Negra (Black Razor) Conference in Albacete, Spain.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=725&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">Just came back today from the <a href="http://navajanegra.com/" target="_blank">Navaja Negra</a> (Black Razor) Conference in Albacete, Spain. Had a great time there, seen lots of old and new faces (they literally filled the room!) and after the talks had a taste of the Albacete nightlife, and a fantastic dinner where I left my mobile phone on the table unattended, and my fellow speakers kindly <a href="https://twitter.com/MarioVilas/status/274671448914808836" title="Well played, well played." target="_blank">reminded</a> me in a polite and civilized manner of the importance of locking one&#8217;s phone.</span></p>
<p><span style="font-size:120%;">This time my friend Aladdin Gurbanov (<a href="https://twitter.com/SeTx_X" title="@SeTx[X]" target="_blank">@SeTx[X]</a>) and I gave a presentation called &#8220;Take a walk on the wild side&#8221;, an introduction to the world of e-crime on the Internet. I&#8217;ll update this post when the slides and the video are online. They&#8217;ll be in Spanish only, sorry! Think of it a chance to practice what you learned in Spanish class. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;"><i><b>Update</b>: Unfortunately not all videos are available! A fragment of our talk is available at <a href="http://ustre.am/RjWO">Ustream</a>.</i></span></p>
<p><span><div id="attachment_726" class="wp-caption aligncenter" style="width: 810px"><img src="http://breakingcode.files.wordpress.com/2012/12/navaja_negra_800.jpg?w=800&#038;h=285" alt="Yup, that&#039;s my new knife! }:D" width="800" height="285" class="size-full wp-image-726" /><p class="wp-caption-text">The organization had a really original gift for the speakers this year: a traditional Albacetean <em>Teja</em> black razor.</p></div></span></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/conferences/'>Conferences</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/725/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=725&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/12/02/black-razor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2012/12/navaja_negra_800.jpg" medium="image">
			<media:title type="html">Yup, that&#039;s my new knife! }:D</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickpost: Cheating on XKCD</title>
		<link>http://breakingcode.wordpress.com/2012/09/19/quickpost-cheating-on-xkcd/</link>
		<comments>http://breakingcode.wordpress.com/2012/09/19/quickpost-cheating-on-xkcd/#comments</comments>
		<pubDate>Wed, 19 Sep 2012 14:23:38 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Just for fun]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=694</guid>
		<description><![CDATA[A quick and dirty Python script to download the XKCD strip "Click and Drag".<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=694&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">In case you missed it, today&#8217;s XKCD comic titled <a href="http://xkcd.com/1110/">Click and Drag</a> is simply amazing! Go check it out first, spend a few hours lost in it, and come back only when you&#8217;re done having fun. I&#8217;ll wait here. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">&#8230;</span></p>
<p><span style="font-size:120%;">Ok, you&#8217;re back. Naturally you&#8217;ll want to cheat on it at some point, to make sure you didn&#8217;t miss out on any hidden easter eggs! So let&#8217;s take a look at the web page.</span></p>
<p><span style="font-size:120%;">The easiest route is loading the comic on Google Chrome, or Chromium. Just right click on the image and select &#8220;inspect element&#8221;. This quickly reveals how the neat trick works.</span></p>
<div id="attachment_696" class="wp-caption aligncenter" style="width: 924px"><a href="http://breakingcode.files.wordpress.com/2012/09/click-and-drag-how-it-works.png"><img src="http://breakingcode.files.wordpress.com/2012/09/click-and-drag-how-it-works.png?w=914&#038;h=438" alt="Taking a peek under the hood..." title="click-and-drag-how-it-works" width="914" height="438" class="size-full wp-image-696" /></a><p class="wp-caption-text">Taking a peek under the hood&#8230;</p></div>
<p><span style="font-size:120%;">The &#8220;world&#8221; is divided into tiles of fixed size, and at all times the page loads the tile you&#8217;re currently viewing and the surrounding ones, in order to seamlessly stitch them together when scrolling. The clickable area is a map and the coordinates are used to build the URL to the images, which always follows the same pattern (north, south, and east and west coordinates). Trying out a few numbers reveals the &#8220;north&#8221; coordinate goes from 1 to 5, the &#8220;east&#8221; coordinate goes from 1 to 48 and the &#8220;west&#8221; coordinate goes from 1 to 33. Not all coordinates seem to work around the edges of the world (north 2 west 5 doesn&#8217;t work for example) and I couldn&#8217;t get south to work with manual tries. I suppose a couple empty images are used for those (one for black and one for white) but I didn&#8217;t confirm it.</span></p>
<p><span style="font-size:120%;">The first thing I tried was just accesing the parent directory to see if directory indexing was enabled, but no such luck. Instead, I wrote <a href="http://winappdbg.sourceforge.net/blog/xkcd-click-drag.py">this quick and dirty script</a> in Python to download all images, using urllib to download them and shutil to write them to disk. Missing tiles are simply skipped.</span></p>
<p><span style="font-size:120%;">This should be enough to check for easter eggs, but it&#8217;d be interesting of someone assembles a big image containing all the tiles. Let me know if you do! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;"><b>Update 1:</b> I originally missed the east coordinate, so the script was updated to try and bruteforce in all directions 1 to 10 north and south, and 1 to 50 east and west. This means a lot more HTTP requests, so I also added a pause between them as good netizens should.</span></p>
<p><span style="font-size:120%;"><b>Update 2:</b> This seems to be the <a href="http://winappdbg.sourceforge.net/blog/xkcd-click-drag.txt">complete list</a> of valid image URLs.</span></p>
<p><span style="font-size:120%;"><b>Update 3:</b> A commenter pointed out somebody did assemble the entire world image! <a href="http://kittenofdiscord.blogspot.de/2012/09/xkcd-click-and-drag-without-drag.html">Check it out here</a>.</span></p>
<p><span style="font-size:120%;"><b>Update 4:</b> <a href="https://twitter.com/prigazzi">@prigazzi</a> on Twitter pointed out <del datetime="2012-12-30T21:31:35+00:00"><a href="http://198.71.94.49/xkcd/">this fully navegable map</a></del> as well, based on Google Maps. Check it out! It&#8217;s IMHO the best one yet. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;"><b>Update 5:</b> The previous link no longer works, but this works pretty much the same way: <a href="http://xkcd-map.rent-a-geek.de/" title="xkcd-map.rent-a-geek.de">xkcd-map.rent-a-geek.de</a></span></p>
<p><span id="more-694"></span></p>
<p>
<h2>Source code:</h2>
</p>
<pre><font face="Lucida,Courier New"><font color="#008000">#!/usr/bin/env python</font>

<font color="#C00000">from</font> <font color="#000000">__future__</font> <font color="#C00000">import</font> <font color="#000000">with_statement</font>

<font color="#C00000">import</font> <font color="#000000">time</font>
<font color="#C00000">import</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font>
<font color="#C00000">import</font> <font color="#000000">shutil</font>
<font color="#C00000">import</font> <font color="#000000">urllib2</font>

<font color="#C00000">def</font> <font color="#000000">download</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">url</font> <font color="#0000C0">=</font> <font color="#004080">"http://imgs.xkcd.com/clickdrag/"</font> <font color="#0000C0">+</font> <font color="#000000">filename</font>
        <font color="#C00000">print</font> <font color="#000000">url</font>
        <font color="#C00000">try</font><font color="#0000C0">:</font>
            <font color="#000000">fsrc</font> <font color="#0000C0">=</font> <font color="#000000">urllib2</font><font color="#0000C0">.</font><font color="#000000">urlopen</font><font color="#0000C0">(</font><font color="#000000">url</font><font color="#0000C0">)</font>
            <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">,</font> <font color="#004080">"wb"</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">fdst</font><font color="#0000C0">:</font>
                <font color="#000000">shutil</font><font color="#0000C0">.</font><font color="#000000">copyfileobj</font><font color="#0000C0">(</font><font color="#000000">fsrc</font><font color="#0000C0">,</font> <font color="#000000">fdst</font><font color="#0000C0">)</font>
            <font color="#C00000">print</font> <font color="#004080">"=&gt;"</font><font color="#0000C0">,</font> <font color="#000000">filename</font>
        <font color="#C00000">except</font> <font color="#000000">urllib2</font><font color="#0000C0">.</font><font color="#000000">HTTPError</font><font color="#0000C0">,</font> <font color="#000000">e</font><font color="#0000C0">:</font>
            <font color="#C00000">print</font> <font color="#004080">"=&gt;"</font><font color="#0000C0">,</font> <font color="#004080">"%s: %s"</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">e</font><font color="#0000C0">.</font><font color="#000000">code</font><font color="#0000C0">,</font> <font color="#000000">e</font><font color="#0000C0">.</font><font color="#000000">msg</font><font color="#0000C0">)</font>
        <font color="#C00000">print</font>
        <font color="#000000">time</font><font color="#0000C0">.</font><font color="#000000">sleep</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">)</font>

<font color="#C00000">for</font> <font color="#000000">north</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#C00000">for</font> <font color="#000000">west</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">filename</font> <font color="#0000C0">=</font> <font color="#004080">"%dn%dw.png"</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">north</font><font color="#0000C0">,</font> <font color="#000000">west</font><font color="#0000C0">)</font>
        <font color="#000000">download</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">)</font>
    <font color="#C00000">for</font> <font color="#000000">east</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">filename</font> <font color="#0000C0">=</font> <font color="#004080">"%dn%de.png"</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">north</font><font color="#0000C0">,</font> <font color="#000000">east</font><font color="#0000C0">)</font>
        <font color="#000000">download</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">)</font>
<font color="#C00000">for</font> <font color="#000000">south</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#C00000">for</font> <font color="#000000">west</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">filename</font> <font color="#0000C0">=</font> <font color="#004080">"%ds%dw.png"</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">south</font><font color="#0000C0">,</font> <font color="#000000">west</font><font color="#0000C0">)</font>
        <font color="#000000">download</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">)</font>
    <font color="#C00000">for</font> <font color="#000000">east</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">filename</font> <font color="#0000C0">=</font> <font color="#004080">"%ds%de.png"</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">south</font><font color="#0000C0">,</font> <font color="#000000">east</font><font color="#0000C0">)</font>
        <font color="#000000">download</font><font color="#0000C0">(</font><font color="#000000">filename</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/just-for-fun/'>Just for fun</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/web/'>web</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/694/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/694/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=694&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/09/19/quickpost-cheating-on-xkcd/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>

		<media:content url="http://breakingcode.files.wordpress.com/2012/09/click-and-drag-how-it-works.png" medium="image">
			<media:title type="html">click-and-drag-how-it-works</media:title>
		</media:content>
	</item>
		<item>
		<title>[Quickpost] Updated Impacket/Pcapy installers for Python 2.5, 2.6 &amp; 2.7</title>
		<link>http://breakingcode.wordpress.com/2012/07/16/quickpost-updated-impacketpcapy-installers-for-python-2-5-2-6-2-7/</link>
		<comments>http://breakingcode.wordpress.com/2012/07/16/quickpost-updated-impacketpcapy-installers-for-python-2-5-2-6-2-7/#comments</comments>
		<pubDate>Mon, 16 Jul 2012 15:10:51 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[fuzzer]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[recon]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[SMB]]></category>
		<category><![CDATA[sniffer]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[vulnerability research]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=678</guid>
		<description><![CDATA[Updated installers for Impacket and Pcapy built against WinPcap 4.1.2. Working for Python versions 2.5 through 2.7.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=678&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">Hi folks! In a <a href="http://breakingcode.wordpress.com/2010/04/02/using-impacketpcapy-with-python-2-6-on-windows/">previous post</a> I talked about using Impacket and Pcapy on Python 2.6. Since those installers are now out of date, here are fresh ones for various versions of Pcapy and Python, built against WinPcap 4.1.2. There&#8217;s also a new Impacket MSI installer that works against all Python versions.</span></p>
<p><span style="font-size:120%;">Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;"><em>Edited 6-May-2013: updated Impacket to version 0.9.10</em></span></p>
<p>
<h2>Download Impacket 0.9.10</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/impacket-0.9.10.win32.msi">impacket-0.9.10.win32.msi</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/impacket-0.9.10.win-amd64.msi">impacket-0.9.10.win-amd64.msi</a></h3>
</p>
<p>
<h2>Download Pcapy 0.10.5</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win32-py2.5-winpcap4.1.2.msi">pcapy-0.10.5.win32-py2.5-winpcap4.1.2.msi</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win32-py2.6-winpcap4.1.2.exe">pcapy-0.10.5.win32-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win32-py2.7-winpcap4.1.2.exe">pcapy-0.10.5.win32-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win-amd64-py2.6-winpcap4.1.2.exe">pcapy-0.10.5.win-amd64-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win-amd64-py2.7-winpcap4.1.2.exe">pcapy-0.10.5.win-amd64-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p><span id="more-678"></span></p>
<p>
<h2>Download Pcapy 0.10.4</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.4.win32-py2.5-winpcap4.1.2.msi">pcapy-0.10.4.win32-py2.5-winpcap4.1.2.msi</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.4.win32-py2.6-winpcap4.1.2.exe">pcapy-0.10.4.win32-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.4.win32-py2.7-winpcap4.1.2.exe">pcapy-0.10.4.win32-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.4.win-amd64-py2.6-winpcap4.1.2.exe">pcapy-0.10.4.win-amd64-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.4.win-amd64-py2.7-winpcap4.1.2.exe">pcapy-0.10.4.win-amd64-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h2>Download Pcapy 0.10.3</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.3.win32-py2.5-winpcap4.1.2.msi">pcapy-0.10.3.win32-py2.5-winpcap4.1.2.msi</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.3.win32-py2.6-winpcap4.1.2.exe">pcapy-0.10.3.win32-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.3.win32-py2.7-winpcap4.1.2.exe">pcapy-0.10.3.win32-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.3.win-amd64-py2.6-winpcap4.1.2.exe">pcapy-0.10.3.win-amd64-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.3.win-amd64-py2.7-winpcap4.1.2.exe">pcapy-0.10.3.win-amd64-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h2>Download Pcapy 0.10.2</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.2.win32-py2.5-winpcap4.1.2.msi">pcapy-0.10.2.win32-py2.5-winpcap4.1.2.msi</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.2.win32-py2.6-winpcap4.1.2.exe">pcapy-0.10.2.win32-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.2.win32-py2.7-winpcap4.1.2.exe">pcapy-0.10.2.win32-py2.7-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.2.win-amd64-py2.6-winpcap4.1.2.exe">pcapy-0.10.2.win-amd64-py2.6-winpcap4.1.2.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.2.win-amd64-py2.7-winpcap4.1.2.exe">pcapy-0.10.2.win-amd64-py2.7-winpcap4.1.2.exe</a></h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/fuzzer/'>fuzzer</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/network/'>network</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/recon/'>recon</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/smb/'>SMB</a>, <a href='http://breakingcode.wordpress.com/tag/sniffer/'>sniffer</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/vulnerability-research/'>vulnerability research</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/678/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/678/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=678&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/07/16/quickpost-updated-impacketpcapy-installers-for-python-2-5-2-6-2-7/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Hackito Ergo Sum 2012</title>
		<link>http://breakingcode.wordpress.com/2012/04/20/hackito-ergo-sum-2012/</link>
		<comments>http://breakingcode.wordpress.com/2012/04/20/hackito-ergo-sum-2012/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 22:27:19 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[credit cards]]></category>
		<category><![CDATA[IDA]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[PCI]]></category>
		<category><![CDATA[pentest]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[RFID]]></category>
		<category><![CDATA[social engineering]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=542</guid>
		<description><![CDATA[Last week I've attended Hackito Ergo Sum 2012. This post won't be a detailed review of each talk, but rather an account of what I personally found more interesting.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=542&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">Hi everyone. Last week I&#8217;ve attended <a href="http://2012.hackitoergosum.org/blog/pages/234" title="It's spelled ROMANES EUNT DOMUS! Now go write it a hundred times." target="_blank">Hackito Ergo Sum 2012</a>, and I wanted to share with you some of the things that I found most interesting during the talks. This won&#8217;t be a detailed review of each talk, but rather an account of a few details on the talks that I personally found more interesting, in no particular order. If you&#8217;re looking for a detailed review of each talk check out <a href="http://www.devoteamblog.com/all-categories/hackito-ergo-sum-2012-jour-1" title="Now we can all pretend to be polyglots and read blogs in any language thanks to Google Translate." target="_blank">this blog</a>.</span></p>
<p><span style="font-size:120%;">Oh, by the way. I totally made up the names of the talks. I think it&#8217;s more fun that way. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">The event took place at the headquarters of the <a href="http://www.paris-meconnu.com/themes/architecture/lieux/siege-parti-communiste-francais-1.htm" title="Espace Niemeyer" target="_blank">French Communist Party</a>, and I have to say the conference room was quite impressive. It was an underground dome all covered with white metallic plates and lamps behind, giving a peculiar visual effect.</span></p>
<table align="center">
<tr>
<td><a href="https://breakingcode.files.wordpress.com/2012/04/img_2438.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2438.jpg?w=400&#038;h=300" alt="" title="Underground domes. Great for a hacker conference. Or a supervillain secret hideout." width="400" height="300" class="alignnone size-medium wp-image-545" /></a></td>
<td><a href="https://breakingcode.files.wordpress.com/2012/04/img_2446.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2446.jpg?w=400&#038;h=300" alt="" title="Beautiful and deadly, like a flock of laser-armed swans." width="400" height="300" class="alignnone size-medium wp-image-544" /></a></td>
</tr>
<tr>
<td><a href="https://breakingcode.files.wordpress.com/2012/04/img_2513.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2513.jpg?w=400&#038;h=300" alt="" title="I also liked to pretend I was inside a spaceship." width="400" height="300" class="alignnone size-medium wp-image-550" /></a></td>
<td><a href="https://breakingcode.files.wordpress.com/2012/04/img_2540.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2540.jpg?w=300&#038;h=400" alt="" title="You gotta take the power back! \m/(*~*)\m/" width="300" height="400" class="alignnone size-medium wp-image-551" /></a></td>
</tr>
</table>
<p><span style="font-size:120%;">An additional advantage of this place is that some security agencies can&#8217;t send their spooks there. Hurray to the ridiculously outdated cold war laws! <img src='http://s2.wp.com/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">One thing I didn&#8217;t like though, was that the slides were projected in a sort of tilted curved screen, making it a bit difficult to read the slides unless you were sitting in the middle. I don&#8217;t think I was the only one with this problem because I saw a lot of heads tilted sideways&#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<p><span id="more-542"></span></p>
<p><span style="font-size:120%;"><br />
<h2>IDA Toolbag: &#8220;How many of you use IDA? And how many of you like it?&#8221;</h2>
<p></span></p>
<p><a href="http://thunkers.net/~deft/code/toolbag/docs.html#Usage"><img alt="" src="http://thunkers.net/~deft/code/toolbag/img/ss/history_add_lots.png" title="Yo, Dawg! Hackers using pretty windows? No way!" class="alignleft" width="400" height="438" /></a></p>
<p><span style="font-size:120%;">I can assure you there were much fewer hands raised for the second question. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">This talk was about a new tool called &#8220;<a href="http://thunkers.net/~deft/code/toolbag/" title="I couldn't think of a funny mouseover text to put here. I am very sorry. I made a mistake and it won't happen again. No, wait, that's what I had to say if I ever went elephant hunting... never mind then." target="_blank">IDA Toolbag</a>&#8220;, by <a href="https://twitter.com/aaronportnoy" title="@aaronportnoy" target="_blank">Aaron Portnoy</a> and <a href="https://twitter.com/drraid" title="@drraid" target="_blank">Brandon Edwards</a>. In a nutshell, it&#8217;s a combination of a lot of ideas that were already present but not quite integrated before: a collaboration plugin, path finding and process stalking, plus some improvements on the code searching, all tied together and with (finally!) a properly designed GUI. The authors understandably put a lot more emphasis on the collaboration features of the plugin, which are much more advanced than any other public plugin that I know of, and I have to say it seems quite powerful.</span></p>
<p><span style="font-size:120%;">However what drew my attention the most was the care they took in thinking of usability from step one and modeling the GUI after common reversing tasks with IDA. Most hackers seem to believe usability and graphic interfases in general are not important at all, if not downright useless. But you know, consoles with green letters are cool and all (I&#8217;m looking at you, <a href="http://twitter.com/trufae" title="Es un trolleo, si, pero va con afecto! ;)" target="_blank">Pancake</a> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) but the fact is, the more time you spend mastering the use of a tool, the more time could have been spent on actually <em>using</em> the tool.</span></p>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/img_2553.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2553.jpg?w=300&#038;h=187" alt="" title="Totally heroic pose, envisioning a future where hackers dare to use pretty windows with many colors. Or maybe he was just pointing at the wall. But I like the first explanation better." width="300" height="187" class="alignright size-medium wp-image-600" /></a></p>
<p><span style="font-size:120%;">Properly designed GUIs may not give you &#8220;h4xx0r cred&#8221; but they help you work faster, thinking more about the problems you want to solve and less about how to use the tools to solve them. And for one, I&#8217;m happy to see when a reversing tool doesn&#8217;t get in the way of your reversing.</span></p>
<p><span style="font-size:120%;">Ok, I&#8217;ll stop my rant now, don&#8217;t worry. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Back on the tool. Basically you use it like this: after opening or creating the IDB, load the plugin by running the Python command &#8220;import toolbag&#8221;. This causes a parallel database to be created and stored embedded into a new section of the binary in the IDB file. It&#8217;s done like this due to some limitations on the IDA API to store arbitrary data in the IDB. The biggest advantage of this is since the plugin is using SQLite underneath you can simply query this new database using SQL queries or from Python code.</span></p>
<p><span style="font-size:120%;">The plugin also adds a new detachable window with some tabs inside, each tab provides a piece of the plugin functionality. There are enhancements to the IDA code search and a new improved mini graph window. Most notably the viewing history is now kept in a tree rather than the usual &#8220;breadcrumbs&#8221; pattern used by IDA, making it impossible to get lost when examining the code. Makes sense: the breadcrumbs pattern is suitable for linear tasks, and when you&#8217;re examining a disassembled binary you never do it linearly &#8211; what you really do is traverse the call graph, following code or data references.</span></p>
<p><span style="font-size:120%;">Inside this new database there&#8217;s a virtual filesystem. Pretty much everything you do can be stored as files here, and sent to other people through the network. That&#8217;s very useful for collaboration &#8211; you can send your source code comments, viewing history, etc. to other people so they can import it into their own IDB files. This importing/exporting process can be quite selective, so you don&#8217;t run into the risk of overwriting your own changes with someone else&#8217;s, and you don&#8217;t share more than you wanted to.</span></p>
<p><span style="font-size:120%;">A caveat I see right now is the fact that the plugin uses the pickle module to marshall data. Although it&#8217;s wrapped with a custom marshalling module to prevent attacks, and the GUI shows you what it is you&#8217;re about to unmarshall, just in case I still wouldn&#8217;t accept collaboration data from strangers. (Then again I wouldn&#8217;t accept IDB files from strangers either!). The authors also warn you about the <a href="http://thunkers.net/~deft/code/toolbag/docs.html#Queues" title="Yeah, maybe opening that IDB emailed to Full-Disclosure wasn't such a great idea after all." target="_blank">security implications</a> of this. Bad stuff may also happen if the binary you&#8217;re analyzing already contains the magic extra section where the database is stored &#8211; but if you&#8217;re blindly opening malware with IDA without checking for this kind of stuff you kinda deserve to be pwned, I guess. In any case the magic section name is configurable, just pick something nobody else would guess and you&#8217;re safe. One more thing: the network queues are not encrypted, so always use a VPN.</span></p>
<p><span style="font-size:120%;">The plugin also allows remote debugging using <a href="https://code.google.com/p/vtrace-mirror/" title="VTrace is the new black." target="_blank">Kenshoto&#8217;s VTrace</a>. The marshalling module described above is also used to send Python code to a listener process, so this feature is more generic than it may seem at first. You can code your own custom modules to be executed remotely, do your stuff asynchronously, collect information and incorporate it to the local database. I can think of a lot of uses for this and I&#8217;m sure you do too. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">Another thing I liked is how customizable everything is. Pretty much everything is configurable by editing the config.py file. All of IDA&#8217;s functionality can be replaced with a custom wrapper so it may be used outside of IDA. And I haven&#8217;t checked yet but I guess VTrace could also be replaced with <a href="https://github.com/OpenRCE/pydbg" title="A classic!" target="_blank">PyDbg</a>, <a href="http://winappdbg.sourceforge.net" title="Ask me about Loom... erhm, I mean WinAppDbg!" target="_blank">WinAppDbg</a> or <a href="https://pykd.codeplex.com/" title="This one really deserves more attention guys, check it out!" target="_blank">PyKd</a> should the need arise.</span></p>
<p><span style="font-size:120%;">the slides for this talk are not yet available, but the documentation in the webpage is pretty extensive and the video is online here: <a href="http://www.ustream.tv/recorded/21835515" target="_blank">http://www.ustream.tv/recorded/21835515</a></span></p>
<p><span style="font-size:120%;"><br />
<h2>Turning weird Windows kernel bugs into easy exploits</h2>
<p></span></p>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/img_2541.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2541.jpg?w=246&#038;h=512" alt="" title="You can tell I didn&#039;t get a good sit for this one. :(" width="246" height="512" class="alignright size-large wp-image-592" /></a></p>
<p><span style="font-size:120%;">In this talk <a href="https://twitter.com/#!/cesarcer" title="@cesarcer" target="_blank">Cesar Cerrudo</a> showed three quite useful tricks to exploit vulnerabilities in kernel land on Windows. The twist is these tricks allow you to take vulnerabilities that are tipically seen as very difficult to exploit, and turn them quickly into weaponized exploits without even needing to run kernel land shellcode.</span></p>
<p><span style="font-size:120%;">The key idea here is that we often think of running shellcode as the goal, when it&#8217;s only a means to an end. The real end in privilege escalation exploits is to, well, escalate privileges. So if it&#8217;s possible to do so without arbitrary code execution, all the better! This basic idea is also present in Gera&#8217;s <a href="http://community.corest.com/~gera/InsecureProgramming/" title="Tried abo2 on Windows already? It's a bitch!" target="_blank">Insecure Programming</a> challenges and the Shellcoder&#8217;s Handbook chapter on alternative payloads.</span></p>
<p><span style="font-size:120%;">In this case, the focus is on manipulating the process tokens to gain system privileges. This allows for very quick and stable local exploits with no kernel payload. In order to obtain the memory addresses of various kernel structures, we have a handy undocumented API call in ntdll.dll called NtQuerySystemInformation() that returns, among other information, the kernel pointer to the structures associated with the given handle value. By passing it a process handle we can obtain the pointer to the KPROCESS structure, and knowing the exact Windows version we can find the pointer to the primary token. This is based on <a href="https://twitter.com/j00ru" target="_blank">@j00ru</a>&#8216;s call gate exploitation paper: <a href="http://vexillium.org/dl.php?call_gate_exploitation.pdf" title="http://vexillium.org/dl.php?call_gate_exploitation.pdf" target="_blank">call_gate_exploitation.pdf</a>.</span></p>
<p><span style="font-size:120%;">Armed with this knowledge, we have three useful tricks we can play. The simplest is to just write a NULL pointer in SecurityDescriptor field of the structure. This effectively removes all ACLs from the handle, and now we can do whatever we want with it. With this we can exploit any vulnerability that allows us to write a NULL pointer in an attacker controlled address.</span></p>
<p><span style="font-size:120%;">The second trick then is to manipulate the tokens themselves to add more privileges. In Windows Vista and above tokens are represented by a _TOKEN structure with three UINT64 fields called &#8220;Present&#8221;, &#8220;Enabled&#8221; and &#8220;EnabledByDefault&#8221;. Each field contains a bitmask of privileges. Interestingly, we only need to set the corresponding bit in the &#8220;Enabled&#8221; field to effectively acquire a privilege. So if our vuln allows us to write arbitrary values we can simply write all 1&#8242;s here&#8230; but what if we have something trickier, like DEC instruction pointing to a user controlled address? What Cesar proposes is this: disable all your privileges using the Win32 APIs except for the one that corresponds to the highest bit of the bitmask (which happened to be a pretty harmless privilege that came by default, called &#8220;SeChangeNotifyPrivilege&#8221;). When you trigger the bug and decrement this value, the result will have all bits set BUT the highest one &#8211; so you gained all privileges but one. (If you have an INC instruction instead, your only choice will be to read your current privileges using the Win32 APIs to find out the value of this field, and trigger the bug multiple times to increment the value to the one you need).</span></p>
<p><span style="font-size:120%;">Before Vista things were different, though. What you have instead is a pointer to a list of tokens identified by numeric values (the _LUID_AND_ATTRIBUTES structure). The trick here is to get the address of the process primary token instead (using the NtQuerySystemInformation() API again) and modify this numeric values to match other, more interesting privileges. For example with a DEC you can change privilege 0&#215;15 (I don&#8217;t recall what that was, but it came by default) into 0&#215;14 (the debug privilege) to be able to debug any process you want. From then you can just inject your userland shellcode into any privileged process (LSASS.EXE to grab all the passwords, for example).</span></p>
<p><span style="font-size:120%;">And finally the last technique requires a vulnerability that can write an attacker controlled value into an attacker controlled address. The idea here is to copy a the System user&#8217;s identity token into the process primary token to escalate privileges. This token can&#8217;t be obtained directly though. In order to get it, Cesar hooked the NtOpenThreadToken() function and called MsiInstallProduct(). Any other API that uses the System identity token will do, this is just the one he used for the demo. Once you have the token handle you have to duplicate it (ntdll closes the handle when it&#8217;s done with it). Then you can call NtQuerySystemInformation() as usual to get the pointer to it. One important detail: to prevent the reference counter from going haywire, make sure to duplicate this handle a couple times in some other process that never dies (like our old friend LSASS.EXE).</span></p>
<p><span style="font-size:120%;"><br />
<h2>NFC credit cards: &#8220;We haven&#8217;t broken any security or tried to, because there is none!&#8221;</h2>
<p></span></p>
<p><a href="http://troll.me/2012/04/12/the-most-interesting-man-in-the-world/i-dont-always-secure-nfc-credit-cards-but-when-i-do-so-i-use-highly-secure-dynamic-cryptograms/"><img src="https://breakingcode.files.wordpress.com/2012/04/i-dont-always-secure-nfc-credit-cards-but-when-i-do-so-i-use-highly-secure-dynamic-cryptograms.jpg?w=200&#038;h=230" alt="" title="Whoever designed this standard must have been drunk, stoned, or both." width="200" height="230" class="alignleft size-thumbnail wp-image-563" /></a></p>
<p><span style="font-size:120%;">The talk on NFC credit card security by <a href="http://2012.hackitoergosum.org/blog/schedule/speakers#RenaudLifchitz" target="_blank">Renaud Lifchitz</a> was both surprisingly simple and scary.</span></p>
<p><span style="font-size:120%;">It turns out contactless credit cards just spit out all their info on the radio waves in plaintext to whoever wants to listen, and the closest thing to a &#8220;protection&#8221; is the required physical distance to receive the signal (3cm to 5cm). And using the proper equipment it can be boosted to 1.5m for active reading and 15m for passive sniffing, so much for THAT.</span></p>
<p><span style="font-size:120%;">The stupidest thing about it is the standard for contactless cards was made by the same credit card companies that sponsor PCI&#8230; but the cards themselves are a far cry from being PCI compliant. But don&#8217;t worry, because the vendors say the NFC cards use &#8220;highly secure dynamic cryptograms&#8221;&#8230; <img src='http://s2.wp.com/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' />  EPIC FAIL!</span></p>
<p><span style="font-size:120%;">In conclusion: don&#8217;t get yourself an NFC credit card. Hell, don&#8217;t get a credit card at all if you ask me! But if you absolutely must have one, get yourself an RFID wallet to carry it.</span></p>
<p><span style="font-size:120%;">The slides can be downloaded from here: <a href="http://2012.hackitoergosum.org/blog/wp-content/uploads/2012/04/HES-2012-rlifchitz-contactless-payments-insecurity.pdf" title="[Hacking the NFC credit cards for fun and debit ; )] by Renaud Lifchitz" target="_blank">HES-2012-rlifchitz-contactless-payments-insecurity.pdf</a>. There&#8217;s also a <a href="https://code.google.com/p/readnfccc/" target="_blank">Google Code project</a> with the command line tool shown during the talk.</span></p>
<p><span style="font-size:120%;"><br />
<h2>Android exploitation: pwning the heap like it&#8217;s 1999</h2>
<p></span></p>
<p><span style="font-size:120%;">This talk by <a href="https://twitter.com/ochsff" title="@ochsff" target="_blank">Georg Wicherski</a> was about Webkit exploitation. To sum it up, instead of exploiting the libc heap implementation you can target another allocator called RenderArena, built on top of the libc allocator, that can only allocate RenderObject objects. The advantage of this is that the RenderArena allocator is extremely predictable, and RenderObject objects have a vtable that get overwritten with the pointer to the next heap block on double frees. This talk gives two exploitation techniques (dubbed &#8220;The Wicherski&#8221; and &#8220;The Refined Aubizziere&#8221;) specific to the RenderArena allocator for use-after-free and type confusion bugs in Webkit. I won&#8217;t go into the details because the <a href="http://2012.hackitoergosum.org/blog/wp-content/uploads/2012/04/HES2012-gwicherski-exploiting-a-coalmine.pdf" title="Yeah, I got lazy at this point. But hey! it's probably my longest blog post to date! ;)" target="_blank">slides</a> explain all this better than me <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  but here are a few selected slides, to give the general idea:</span></p>
<table align="center">
<tr>
<td>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/slide1.png"><img src="https://breakingcode.files.wordpress.com/2012/04/slide1.png?w=500&#038;h=269" alt="" title="1" width="500" height="269" class="alignnone size-medium wp-image-634" /></a></p>
</td>
<td>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/slide2.png"><img src="https://breakingcode.files.wordpress.com/2012/04/slide2.png?w=500&#038;h=269" alt="" title="2" width="500" height="269" class="alignnone size-medium wp-image-635" /></a></p>
</td>
</tr>
<tr>
<td>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/slide3.png"><img src="https://breakingcode.files.wordpress.com/2012/04/slide3.png?w=500&#038;h=269" alt="" title="3" width="500" height="269" class="alignnone size-medium wp-image-636" /></a></p>
</td>
<td>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/slide4.png"><img src="https://breakingcode.files.wordpress.com/2012/04/slide4.png?w=500&#038;h=269" alt="" title="4" width="500" height="269" class="alignnone size-medium wp-image-637" /></a></p>
</td>
</tr>
</table>
<p><span style="font-size:120%;">You can download the slides from here: <a href="http://2012.hackitoergosum.org/blog/wp-content/uploads/2012/04/HES2012-gwicherski-exploiting-a-coalmine.pdf" target="_blank">HES2012-gwicherski-exploiting-a-coalmine.pdf</a></span></p>
<p><span style="font-size:120%;"><br />
<h2>Social engineering: &#8220;Advertising and religion are forms of social engineering too&#8221;</h2>
<p></span></p>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/img_2519.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2519.jpg?w=300&#038;h=224" alt="" title="So many times I&#039;ve wished for the exact same thing... *sigh*" width="300" height="224" class="alignright size-medium wp-image-644" /></a></p>
<p><span style="font-size:120%;">I&#8217;m usually quite partial to technical talks, especially when they&#8217;re about exploitation. But I still liked this one a lot. <a href="https://twitter.com/FreedomCoder" title="@FreedomCoder" target="_blank">Matias Brutti</a> painted a good picture of what the real social engineering practice is during a pentest, and did so with plenty of humor (giving religion as an example of pre-technology social engineering cracked me up) and with none of the self-important bullshit that usually plagues this topic. There was also no <a href="https://en.wikipedia.org/wiki/Neuro-linguistic_programming#Criticism_and_controversy" title="As crackpot pseudosciences go I prefer phrenology." target="_blank">NLP</a> nonsense at all, I liked that too.</span></p>
<p><span style="font-size:120%;">He also gave some practical examples of ruses that can be used to lure unsuspecting vict&#8230; ahem, I mean targets of your pentest to open a backdoored Office document. My favorite was the following: create a fake Excel spreadsheet with the salaries of all the bosses in the company, then send a spoofed email to a few non-technical folks complaining about how much does that damn pointy-haired boss earn compared to regular employees. Instant success! You don&#8217;t even need to mass mail it, the employees themselves will spread your backdoor much better than you would. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">But be careful of what ruse you use. You might be <em>a little too successful</em> and end up pwning people outside the scope of your pentest (or even outside the company entirely!) and that would get you into a lot of trouble. Also make sure the topic of your ruse is something you can show later in your report&#8230; sex sells, but it makes you look bad when you have to show it to the CEO. (I once heard of a really <em>nasty</em> example of this. Legend has it some pentesting team once used <a href="http://www.nmr.nl/nmr/binary/retrieveFile?instanceid=16&amp;itemid=2574" title="Sadistic homosexual necrophiliac ducks. Beat THAT, 4chan!" target="_blank">this PDF file</a> for a social engineering engagement. I&#8217;ll leave it to the readers to imagine the consequences! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )</span></p>
<p><span style="font-size:120%;">The talk ended with a set of free social engineering automation tools written by Matias himself. They help when gathering information for your targets and mass mail them, among other tasks. You can get the source code from Github: <a href="https://github.com/FreedomCoder" target="_blank">https://github.com/FreedomCoder</a></span></p>
<p><span style="font-size:120%;"><br />
<h2>Autopwn with steroids: how math geeks can improve your pwnage</h2>
<p></span></p>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/img_2537.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2537.jpg?w=250&#038;h=190" alt="" title="So I was like &quot;yeeeeeeeeah... I need another beer&quot;" width="250" height="190" class="alignleft size-medium wp-image-652" /></a></p>
<p><span style="font-size:120%;">This talk was about how to mathematically plan a complete network infrastructure pentest from top to bottom, using whatever information is available at the time (target machines involved, software installed on them, vulnerable versions, open ports, etc.). The algorithm can also accept input during the execution of the plan and correct it to incorporate the new information, and the math is also backed by statistical information gathered from over 700 machines with different combinations of operating systems, hardware, etc.</span></p>
<p><span style="font-size:120%;">I&#8217;m sure <a href="http://corelabs.coresecurity.com/index.php?action=view&amp;type=researcher&amp;name=Carlos_Sarraute" title="a.k.a. &quot;Charles&quot;" target="_blank">Carlos Sarraute</a> gave a superb talk a usual, he really knows his stuff and already published some previous work on the same topic. But&#8230; unfortunately I arrived late <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  so he was already past the introduction and knee-deep into the heavy math behind his work. (Suffice to say it involved statistics in four dimensional metaplanes to understand why I gave up almost instantly. I felt back in college, folks!)</span></p>
<p><span style="font-size:120%;">Sorry to disappoint you all! I&#8217;m sure I can get him to explain it to me while drinking some beers another day&#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </span></p>
<p><span style="font-size:120%;">The slides are not yet available, but in the meantime you can read Carlos&#8217; related past works a the <a href="http://corelabs.coresecurity.com/index.php?action=view&amp;type=researcher&amp;name=Carlos_Sarraute" title="a.k.a. Evil Mathematicians Headquarters" target="_blank">Core Security website</a>.</span></p>
<p><span style="font-size:120%;"><br />
<h2>Detecting crypto: that awkward moment when a typo in Wikipedia ruins your TEA</h2>
<p></span></p>
<p><a href="https://breakingcode.files.wordpress.com/2012/04/img_2455.jpg"><img src="https://breakingcode.files.wordpress.com/2012/04/img_2455.jpg?w=300&#038;h=199" alt="" title="It came from outer space! No, wait, that&#039;s another movie." width="300" height="199" class="alignright size-medium wp-image-658" /></a></p>
<p><span style="font-size:120%;"><a href="http://2012.hackitoergosum.org/blog/schedule/speakers#JoanCalvet" target="_blank">Joan Calvet</a> presents a proof-of-concept tool to automatically detect crypto code in malware and identify the algorithm being used. The task is divided in three parts: the first is detecting the cryptographic functions by analyzing an execution trace of the binary, the second is to find the inputs and outputs of said code during the execution, and the third is to detect the algorithm being used.</span></p>
<p><span style="font-size:120%;">The first part is possibly the hardest. Some shortcuts are taken to make it easier: a potential crypto function consists of one or more chained loops, for a particular definition of &#8220;loop&#8221;. This allows for a quick and easy detection method that works in many cases, but of course not in all. In particular, state machines are discarded as potential crypto code. However, unrolled loops are successfully detected, because the tool compares the instructions being executed rather than the memory addresses where they happen to be. I&#8217;m not sure what would happen if loops were transformed into recursive function calls, but most malware authors won&#8217;t alter crypto code much anyway (more on that later).</span></p>
<p><span style="font-size:120%;">The second part is about determining what are the inputs and outputs. In principle this is easier since all it has to do is track memory reads to addresses in areas where no writes happen and visceversa. The tricky part is finding out where the different arguments are. Just taking consecutive memory addresses won&#8217;t do, since that&#8217;s bound to happen all the time in the stack. The author&#8217;s solution is to separate the arguments based on what instructions are used to access them.</span></p>
<p><span style="font-size:120%;">The third part is the simplest: the tool has reference implementations of all the supported algorithms, and they are all tested in all possible combinations of parameters. This brute force solution works well even for algorithms like AES, provided you consider the S-boxes as part of the input. This is also the part I find severely lacking: it&#8217;s trivial to alter the crypto algorithm to defeat this. A simple XOR against a hardcoded constant will change the output enough so you can&#8217;t find it by comparing against the reference implementation, and you won&#8217;t lose any of its security. Joan seemed quite aware of this, and even showed a funny example on how it can fail.</span></p>
<p><span style="font-size:120%;">He was testing the tool against some malware samples that were supposed to be using TEA. The tool failed, and manual analysis revealed the algorithm was TEA alright&#8230; but on closer inspection there was a subtle difference of implementation: a pair of parenthesis was misplaced in the original source code! The strangest part was this exact same bug was present in other malware families as well. After some googling, the mistery was solved. All of these bugged malwares came from Russia, and the Russian version of Wikipedia contained a faulty reference implementation, that was copied and pasted into the malware code. To me, that says a lot on how malware is developed&#8230; and it also teaches to distrust code randomly found on the Internet. Maybe I&#8217;m being paranoid, but&#8230; who&#8217;s to say the bug wasn&#8217;t intentional?</span></p>
<p><span style="font-size:120%;"><br />
<h2>&#8230;And thanks for all the fish!</h2>
<p></span></p>
<p><span style="font-size:120%;">There were a lot more talks I&#8217;m completely and unfairly skipping here: Travis Goodspeed&#8217;s talk on pwning radio devices, Daniel Mende and Enno Rey messing with Cisco VoIP phones, Ralf Philipp Weinmann&#8217;s on baseband reverse engineering, just to name a few. The level of all the talks was excellent but I&#8217;ve really spent a lot more time on this blog post than I originally intended <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  plus I&#8217;m not confident enough with some topics to be talking about them, so I&#8217;ll leave it to you all to go to the <a href="http://2012.hackitoergosum.org/blog/schedule/talks" target="_blank">HES website</a> and read the slides. You can also <a href="http://www.ustream.tv/channel/hackito-ergo-sum-2012" target="_blank">check out the videos</a> at ustream.</span></p>
<p><span style="font-size:120%;">Many thanks as well to Phillipe Langlois, Jonathan Brossard, Malard Arnaud, Matthieu Suiche and the rest of the team, you guys really know how to throw a geek party! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/conferences/'>Conferences</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/conference/'>conference</a>, <a href='http://breakingcode.wordpress.com/tag/credit-cards/'>credit cards</a>, <a href='http://breakingcode.wordpress.com/tag/ida/'>IDA</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/math/'>math</a>, <a href='http://breakingcode.wordpress.com/tag/pci/'>PCI</a>, <a href='http://breakingcode.wordpress.com/tag/pentest/'>pentest</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/rfid/'>RFID</a>, <a href='http://breakingcode.wordpress.com/tag/social-engineering/'>social engineering</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/542/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=542&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/04/20/hackito-ergo-sum-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2438.jpg?w=400" medium="image">
			<media:title type="html">Underground domes. Great for a hacker conference. Or a supervillain secret hideout.</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2446.jpg?w=400" medium="image">
			<media:title type="html">Beautiful and deadly, like a flock of laser-armed swans.</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2513.jpg?w=400" medium="image">
			<media:title type="html">I also liked to pretend I was inside a spaceship.</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2540.jpg?w=300" medium="image">
			<media:title type="html">You gotta take the power back! \m/(*~*)\m/</media:title>
		</media:content>

		<media:content url="http://thunkers.net/~deft/code/toolbag/img/ss/history_add_lots.png" medium="image">
			<media:title type="html">Yo, Dawg! Hackers using pretty windows? No way!</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2553.jpg?w=300" medium="image">
			<media:title type="html">Totally heroic pose, envisioning a future where hackers dare to use pretty windows with many colors. Or maybe he was just pointing at the wall. But I like the first explanation better.</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2541.jpg?w=246" medium="image">
			<media:title type="html">You can tell I didn&#039;t get a good sit for this one. :(</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/i-dont-always-secure-nfc-credit-cards-but-when-i-do-so-i-use-highly-secure-dynamic-cryptograms.jpg?w=200" medium="image">
			<media:title type="html">Whoever designed this standard must have been drunk, stoned, or both.</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/slide1.png?w=500" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/slide2.png?w=500" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/slide3.png?w=500" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/slide4.png?w=500" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2519.jpg?w=300" medium="image">
			<media:title type="html">So many times I&#039;ve wished for the exact same thing... *sigh*</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2537.jpg?w=200" medium="image">
			<media:title type="html">So I was like &#34;yeeeeeeeeah... I need another beer&#34;</media:title>
		</media:content>

		<media:content url="https://breakingcode.files.wordpress.com/2012/04/img_2455.jpg?w=300" medium="image">
			<media:title type="html">It came from outer space! No, wait, that&#039;s another movie.</media:title>
		</media:content>
	</item>
		<item>
		<title>MSDN Help Plugin for OllyDbg / Immunity Debugger</title>
		<link>http://breakingcode.wordpress.com/2012/04/09/msdn-help-plugin-for-ollydbg-immunity-debugger/</link>
		<comments>http://breakingcode.wordpress.com/2012/04/09/msdn-help-plugin-for-ollydbg-immunity-debugger/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 15:49:49 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=514</guid>
		<description><![CDATA[A plugin for OllyDBG 1.x / Immunity Debugger to use the online MSDN help instead of the good old WIN32.HLP help file. Download: http://winappdbg.sourceforge.net/blog/OllyMSDN.zip<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=514&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">Hi everyone! I just wrote a quick <a href="http://www.ollydbg.de/" title="OllyDbg" target="_blank">OllyDbg 1.x</a> plugin and I wanted to share it. If you don&#8217;t know what that means, read my other article instead at the <a href="http://blog.buguroo.com/?p=4071" title="Buguroo Blog" target="_blank">Buguroo Blog</a> which has a more detailed explanation on what it is and how to use it. This post is more about why I wrote it and how it works.</span></p>
<p><span style="font-size:120%;">Anyway. After a conversation on Twitter about how it&#8217;s becoming increasingly harder to find the venerable <a href="http://www.winasm.net/win32hlp.html" title="Win32.hlp at the WinAsm IDE forum" target="_blank">WIN32.HLP</a> file &#8211; and how it was becoming ever more outdated, I came to realize I didn&#8217;t know of any OllyDbg plugin to use the more modern and up to date MSDN documentation. I asked around and no one else seems to have written such a plugin, so I wrote my own.</span></p>
<p><span style="font-size:120%;">It&#8217;s sort of a dirty hack &#8211; in general there&#8217;s no easy way of overriding existing features in Olly, the plugin API is rather meant to add new functionality. So after messing about with it for a while I came up with an easy hack &#8211; the plugin just hooks the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762267(v=vs.85).aspx" title="WinHelp function" target="_blank">WinHelp()</a> API call to detect when WIN32.HLP is about to be opened, and launches the default web browser instead. Any other help file is launched normally.</span></p>
<p><span style="font-size:120%;">The next step would be to search the MSDN looking for the API call the user requested. Then again, a quick hack came to the rescue <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  since instead of figuring out how to perform MSDN searches it was much easier to just use a Google search with the &#8220;I Feel Lucky&#8221; button. You can find out more <a href="http://jwebnet.net/advancedgooglesearch.html" title="Unofficial Google Advanced Search" target="_blank">here</a> about the unofficial Google Search API.</span></p>
<p><span style="font-size:120%;">The plugin is also compatible with the newer <a href="http://www.immunitysec.com/products-immdbg.shtml" title="Immunity Debugger" target="_blank">Immunity Debugger</a> which is based in OllyDbg, and was tested on both.</span></p>
<p><span style="font-size:120%;">To install, just copy the DLL file in the plugins folder (by default is the same where the main EXE lives). You do need to have set the win32.hlp file in the configuration at some point (so Olly actually tries to open it, otherwise the plugin never finds out). It doesn&#8217;t need to be the real file though, any file named &#8220;win32.hlp&#8221; will do the trick, even if it&#8217;s 0 bytes long. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </span></p>
<p><span style="font-size:120%;">Enjoy!</span></p>
<h2>Download</h2>
<h3><a href="http://winappdbg.sourceforge.net/blog/OllyMSDN.zip">OllyMSDN.zip</a></h3>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/api/'>API</a>, <a href='http://breakingcode.wordpress.com/tag/debugger/'>debugger</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/win32/'>win32</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/514/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=514&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/04/09/msdn-help-plugin-for-ollydbg-immunity-debugger/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickpost: Installers for BeaEnginePython, Pymsasid, PyDasm and Libdisassemble</title>
		<link>http://breakingcode.wordpress.com/2012/04/08/quickpost-installer-for-beaenginepython/</link>
		<comments>http://breakingcode.wordpress.com/2012/04/08/quickpost-installer-for-beaenginepython/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 18:25:59 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[BeaEngine]]></category>
		<category><![CDATA[disassembler]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[WinAppDbg]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=536</guid>
		<description><![CDATA[I've packaged the BeaEngine disassembler along with its Python bindings into a no-frills Windows installer. Certainly easier than manual install, and it really helps me when installing it on virtual machines. :)

Downloads:
http://winappdbg.sourceforge.net/blog/BeaEnginePython-3.1.0.win32.exe
http://winappdbg.sourceforge.net/blog/BeaEnginePython-3.1.0.win-amd64.exe
http://winappdbg.sourceforge.net/blog/BeaEnginePython-3.1.0.zip
<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=536&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">I&#8217;ve packaged the <a href="http://beatrix2004.free.fr/BeaEngine/index1.php" title="BeaEngine Disassembler" target="_blank">BeaEngine Disassembler</a> along with its Python bindings into a no-frills Windows installer. Certainly easier than manual install, and it really helps me when installing it on virtual machines. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">Enjoy!</span></p>
<p><span style="font-size:120%;"><strong>Update</strong>: Just added another disassembler package, <a href="http://pypi.python.org/pypi/pymsasid/0.3.1">Pymsasid</a>.</span></p>
<p><span style="font-size:120%;"><strong>Update</strong>: Added precompiled Windows binaries for PyDasm on Python 2.6 and 2.7.</span></p>
<p><span style="font-size:120%;"><strong>Update</strong>: My installers were added to the <a href="http://dsecrg.com/files/pub/pdf/Python%20arsenal%20for%20RE%201.1.pdf" title="Python Arsenal for RE" target="_blank">Python Arsenal for RE</a>. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;"><strong>Update</strong>: The Pymsasid package was updated with a small change, so the importation works just the same as loading the .py files from the current directory (it&#8217;s just an &#8220;import *&#8221; in __init__.py)</span></p>
<p><span style="font-size:120%;"><strong>Update</strong>: Added a simple setup script for Libdisassemble 2.0. Since I had to put the sources inside a package the import statement in your scripts will have to be adjusted if using this version. With a simple try/except block you can make scripts compatible with both versions as well, if you need to.</span></p>
<p>
<h2>Downloads</h2>
</p>
<p>
<h3>BeaEngine win32 installer: <a href="http://winappdbg.sourceforge.net/blog/BeaEnginePython-3.1.0.win32.exe">BeaEnginePython-3.1.0.win32.exe</a></h3>
</p>
<p>
<h3>BeaEngine win64 installer: <a href="http://winappdbg.sourceforge.net/blog/BeaEnginePython-3.1.0.win-amd64.exe">BeaEnginePython-3.1.0.win-amd64.exe</a></h3>
</p>
<p>
<h3>BeaEngine source installer: <a href="http://winappdbg.sourceforge.net/blog/BeaEnginePython-3.1.0.zip">BeaEnginePython-3.1.0.zip</a> (run &#8220;python setup.py install&#8221;)</h3>
</p>
<p>
<h3>Libdisassemble 2.0 win32 installer: <a href="http://winappdbg.sourceforge.net/blog/libdisassemble-2.0.win32.msi">libdisassemble-2.0.win32.msi</a></h3>
</p>
<p>
<h3>Libdisassemble 2.0 win64 installer: <a href="http://winappdbg.sourceforge.net/blog/libdisassemble-2.0.win-amd64.msi">libdisassemble-2.0.win-amd64.msi</a></h3>
</p>
<p>
<h3>Libdisassemble 2.0 source installer: <a href="http://winappdbg.sourceforge.net/blog/libdisassemble-2.0.zip">libdisassemble-2.0.zip</a> (run &#8220;python setup.py install&#8221;)</h3>
</p>
<p>
<h3>PyDasm precompiled binaries: <a href="http://winappdbg.sourceforge.net/blog/PyDasm-1.5-precompiled.zip">PyDasm-1.5-precompiled.zip</a> (run &#8220;python setup.py install&#8221;)</h3>
</p>
<p>
<h3>Pymsasid source installer: <a href="http://winappdbg.sourceforge.net/blog/pymsasid-0.3.1.zip">pymsasid-0.3.1.zip</a> (run &#8220;python setup.py install&#8221;)</h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/beaengine/'>BeaEngine</a>, <a href='http://breakingcode.wordpress.com/tag/disassembler/'>disassembler</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/winappdbg/'>WinAppDbg</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/536/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=536&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/04/08/quickpost-installer-for-beaenginepython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Heappie! + WinAppDbg</title>
		<link>http://breakingcode.wordpress.com/2012/03/18/heappie-winappdbg/</link>
		<comments>http://breakingcode.wordpress.com/2012/03/18/heappie-winappdbg/#comments</comments>
		<pubDate>Sun, 18 Mar 2012 18:35:58 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[WinAppDbg]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=501</guid>
		<description><![CDATA[Patched Heappie! to work with WinAppDbg as the backend when available. Added 64 bit support. Made fun of Anibal Sacco's name. All in all, a productive day. :)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=501&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">In case you missed it, <a title="Not to be confused with Juan Sacco." href="http://exploiting.wordpress.com/bio/" target="_blank">Aníbal Sacco</a> released a new tool called <a title="Put some Flower Power on your exploits!" href="http://exploiting.wordpress.com/2012/03/09/heappie-heap-spray-analysis-tool/" target="_blank">Heappie!</a> to analyze heap sprays in multiple platforms. It uses <strong>PyGame</strong> and <strong>PythonCard</strong> for the GUI and Kenshoto&#8217;s <strong>VTrace</strong> as the backend. It&#8217;s really cool, check it out <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span><a href="http://exploiting.files.wordpress.com/2012/02/hippievan_03-copia.jpg" title="Trippy screenshot, dude!"><img class="aligncenter" src="http://exploiting.files.wordpress.com/2012/02/hippievan_03-copia.jpg?w=497&amp;h=332" alt="Trippy screenshot, dude!" /></a></span></p>
<p><span style="font-size:120%;">Now, I never get tired of saying how great VTrace is. It&#8217;s written in Python, supports multiple platforms and quite comfortable to develop with. But alas, I tend to prefer my own debugger (call me biased if you wish!). So today I went ahead and added <a title="I bet you can't pronounce that without spitting a little." href="http://winappdbg.sourceforge.net" target="_blank">WinAppDbg</a> support to Heappie!. When WinAppDbg is installed, it&#8217;s chosen automatically as the backend. If not found, it falls back to VTrace. That way we don&#8217;t lose support for other platforms, since WinAppDbg naturally only works on Windows.</span></p>
<p><span style="font-size:120%;">This patch also adds support for <strong>64 bit</strong> versions of Windows, in case you were thinking this was just an exercise in self indulgence. Well, it <em>is</em> that, but not <em>just</em> that. Ahem.</span></p>
<h2>TL;DR</h2>
<p><span style="font-size:120%;">Just download the file above, go to Aníbal&#8217;s blog to learn how to use it, and exploit all the bugs! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </span></p>
<p><span><a href="http://winappdbg.sourceforge.net/blog/Heappie-WinAppDbg.zip" title="So many vulns, so little time."><img class="aligncenter" src="http://winappdbg.sourceforge.net/blog/ExploitAllTheBugs.jpg" alt="So many vulns, so little time." /></a></span></p>
<h2>Download</h2>
<h3><a href="http://winappdbg.sourceforge.net/blog/Heappie-WinAppDbg.zip">Heappie-WinAppDbg.zip</a></h3>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/exploit/'>exploit</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/winappdbg/'>WinAppDbg</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/501/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/501/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=501&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/03/18/heappie-winappdbg/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>

		<media:content url="http://exploiting.files.wordpress.com/2012/02/hippievan_03-copia.jpg?w=497&#38;h=332" medium="image">
			<media:title type="html">Trippy screenshot, dude!</media:title>
		</media:content>

		<media:content url="http://winappdbg.sourceforge.net/blog/ExploitAllTheBugs.jpg" medium="image">
			<media:title type="html">So many vulns, so little time.</media:title>
		</media:content>
	</item>
		<item>
		<title>Posting anonymously to Pastebin.com</title>
		<link>http://breakingcode.wordpress.com/2012/01/27/posting-anonymously-to-pastebin-com/</link>
		<comments>http://breakingcode.wordpress.com/2012/01/27/posting-anonymously-to-pastebin-com/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 18:58:53 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web applications]]></category>
		<category><![CDATA[anonymous]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tor]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=477</guid>
		<description><![CDATA[An easy way to send content anonymously to the Pastebin.com site, using Python and Tor.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=477&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:120%;">While going through some old code of mine to document it using Epydoc at a friend&#8217;s request, I found something funny. <a href="http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/">Some time ago</a> I made a quick and dirty script to access the Pastebin.com API from Python. Well, it turns out the API has changed quite a bit since then &#8211; most importantly, now it requires a <strong>mandatory API key</strong> that&#8217;s linked to a user account (which in turn, if you used OAuth, is linked to your Gmail address or Twitter feed). That means it&#8217;s <strong>no longer possible</strong> to post <strong>anonymously</strong> using the official API.</span></p>
<p><span style="font-size:120%;">Funny thing is, my <strong>old</strong> script was <strong>still working</strong>! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Apparently the folks at Pastebin have left the legacy API still running. The old documentation is gone though, and now even to read the <a href="http://pastebin.com/api">updated documentation</a> you need to log in&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">Now, this takes care of the API key problem, but there&#8217;s still the issue of Pastebin seeing your <strong>IP address</strong>. An HTTP <strong>proxy</strong> can fix that&#8230; provided you trust that proxy not to store your IP somewhere in the logs. The procedure is simple, just set the <em>HTTP_PROXY</em> environment variable to wherever your proxy is, and <i>voil&agrave;</i>! The standard Python module <a href="http://docs.python.org/library/urllib.html">urllib</a> will automatically connect through the proxy.</span></p>
<p><span style="font-size:120%;">If you don&#8217;t have a trusty HTTP proxy, the best way to go is through the <strong>Tor network</strong>. You&#8217;ll need to install the Tor service itself and the Privoxy HTTP proxy in your machine, then set the <em>HTTP_PROXY</em> variable to <em>127.0.0.1:8123</em>. <a href="https://trac.torproject.org/projects/tor/wiki/doc/TorifyHOWTO">This document</a> from the Tor Project explains it in detail.</span></p>
<p><span style="font-size:120%;">Once you&#8217;ve set up your proxy, download <a href="http://winappdbg.sourceforge.net/blog/pastebin.py">pastebin.py</a> and send a file to Pastebin like this:</span></p>
<p><span style="font-size:120%;"><em>
<pre>    $ python pastebin.py manifesto.txt
    manifesto.txt --&gt; http://pastebin.com/ixSetT5f</pre>
<p></em></span></p>
<p><span style="font-size:120%;">The script accepts multiple filenames as well. You can also set the syntax highlighting format (useful for source code, config files or logs) as follows:</span></p>
<p><span style="font-size:120%;"><em>
<pre>    python pastebin.py --format=apache /var/log/apache2/access.log /var/log/apache2/error.log</pre>
<p></em></span></p>
<p><span style="font-size:120%;">And set an expiration time, after which it gets automatically deleted. In the following example a SQL dump is uploaded and automatically deleted the next day:</span></p>
<p><span style="font-size:120%;"><em>
<pre>    python pastebin.py dump.sql --format=sql --expire=1D</pre>
<p></em></span></p>
<p><span style="font-size:120%;">So, that&#8217;s pretty much it. There&#8217;s a limit of 512Kb per file uploaded, in order to bypass this you&#8217;ll have to split the file into multiple pieces (something similar to <a href="http://breakingcode.wordpress.com/2010/01/14/having-fun-with-url-shorteners-part-2-parasitic-storage/">this</a> but using pastes instead of URLs). I may do it another day, but for now it&#8217;s left as an exercise to the reader. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">There&#8217;s one thing I don&#8217;t quite understand: why did the Pastebin folks think it was necessary to have a mandatory API key? Even if the legacy API had been shut down, it would still be possible to figure out how the web page was doing it and replicate it in Python. The API key being linked to the user account seems a bit strange too&#8230; Their intention might be to catch script kiddies uploading illegal stuff, but it may also be an attempt to do data mining on people&#8217;s posts. Who knows&#8230;</span></p>
<p>
<h2>Download</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pastebin.py">pastebin.py</a></h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/privacy/'>Privacy</a>, <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a>, <a href='http://breakingcode.wordpress.com/category/web-applications/'>Web applications</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/anonymous/'>anonymous</a>, <a href='http://breakingcode.wordpress.com/tag/api/'>API</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/privacy-2/'>privacy</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/tor/'>tor</a>, <a href='http://breakingcode.wordpress.com/tag/web/'>web</a>, <a href='http://breakingcode.wordpress.com/tag/webapp/'>webapp</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/477/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&#038;blog=5671286&#038;post=477&#038;subd=breakingcode&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/01/27/posting-anonymously-to-pastebin-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6e6bbb30843ad0853dcc7b82d046a6d?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
	</channel>
</rss>
