<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>It should work... &#187; programming</title>
	<atom:link href="http://vierito.es/wordpress/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://vierito.es/wordpress</link>
	<description>Cuando cualquier trasto es útil</description>
	<lastBuildDate>Sat, 09 Jul 2011 02:34:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Campus Party 2010 &#8211; Wargame Leftovers winner!</title>
		<link>http://vierito.es/wordpress/2010/08/30/campus-party-2010-wargame-leftovers-winner/</link>
		<comments>http://vierito.es/wordpress/2010/08/30/campus-party-2010-wargame-leftovers-winner/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 11:42:11 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[campus party]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[reversing]]></category>
		<category><![CDATA[wargame]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=862</guid>
		<description><![CDATA[Just a quick note and I&#8217;ll be back to my regular spanish written crappy blog. Uri from Int3pids won the challenge. Congratulations! Eloi, dreyer, earada, kachakil and roman_soft did a great job too, thanks to all the participants. Now you can find online the solution of Crypto02&#8211;Fuente original en http://vierito.es/wordpressSimilar Posts: Crypto04 challenge write-up from Campus [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note and I&#8217;ll be back to my regular spanish written crappy blog.</p>
<p>Uri from Int3pids won the challenge. Congratulations! <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2VzYW5mZWxpeA==">Eloi</a>, <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2RyZXllcmNpdG8=">dreyer</a>, <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2VhcmFkYQ==">earada</a>, <a title=\"kachakil\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2thY2hha2lsLmNvbQ==">kachakil</a> and <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL3JvbWFuX3NvZnQ=">roman_soft</a> did a great job too, thanks to all the participants.</p>
<p>Now you can find online the solution of <a title=\"Crypto02 Campus Party Write-up\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvY3AyMDEwd2FyZ2FtZS9zb2wtY3J5cHRvMDIucGhw">Crypto02</a><br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTAvMDQvMTkvY3J5cHRvMDQtY2hhbGxlbmdlLXdyaXRlLXVwLWZyb20tY2FtcHVzLXBhcnR5LWV1cm9wZS8=" rel=\"bookmark\" title=\"April 19, 2010\">Crypto04 challenge write-up from Campus Party Europe</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTEvMDEvMjIvYnJlYWtpbmctbGZzci1iYXNlZC1wc2V1ZG8tcmFuZG9tLW51bWJlci1nZW5lcmF0b3JzLw==" rel=\"bookmark\" title=\"January 22, 2011\">Breaking LFSR-based pseudo-random number generators</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTAvMDgvMDIvY2FtcHVzLXBhcnR5LTIwMTAtd2FyZ2FtZS1sZWZ0b3ZlcnMv" rel=\"bookmark\" title=\"August 2, 2010\">Campus Party 2010 &#8211; Wargame Leftovers</a></li>
</ul>
<p><!-- Similar Posts took 5.819 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=862" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2010/08/30/campus-party-2010-wargame-leftovers-winner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Campus Party 2010 &#8211; Wargame Leftovers</title>
		<link>http://vierito.es/wordpress/2010/08/02/campus-party-2010-wargame-leftovers/</link>
		<comments>http://vierito.es/wordpress/2010/08/02/campus-party-2010-wargame-leftovers/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 22:30:22 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[campus party]]></category>
		<category><![CDATA[wargame]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=856</guid>
		<description><![CDATA[Campus Party is over now, it was a great week. Here are two unsolved levels from the hacking wargame, they were available in the contest so we wanted to release them. Go, get them and have fun! First to solve both gets a $30 gift card for Amazon. All the info available at http://vierito.es/cp2010wargame/&#8211;Fuente original [...]]]></description>
			<content:encoded><![CDATA[<p>Campus Party is over now, it was a great week. Here are two unsolved levels from the hacking wargame, they were available in the contest so we wanted to release them.</p>
<p>Go, get them and have fun! First to solve both gets a $30 gift card for Amazon. All the info available at</p>
<p><a title=\"Campus Party 2010 wargame leftovers\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvY3AyMDEwd2FyZ2FtZS8=">http://vierito.es/cp2010wargame/</a><br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTEvMDEvMjIvYnJlYWtpbmctbGZzci1iYXNlZC1wc2V1ZG8tcmFuZG9tLW51bWJlci1nZW5lcmF0b3JzLw==" rel=\"bookmark\" title=\"January 22, 2011\">Breaking LFSR-based pseudo-random number generators</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTAvMDQvMTkvY3J5cHRvMDQtY2hhbGxlbmdlLXdyaXRlLXVwLWZyb20tY2FtcHVzLXBhcnR5LWV1cm9wZS8=" rel=\"bookmark\" title=\"April 19, 2010\">Crypto04 challenge write-up from Campus Party Europe</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTAvMDgvMzAvY2FtcHVzLXBhcnR5LTIwMTAtd2FyZ2FtZS1sZWZ0b3ZlcnMtd2lubmVyLw==" rel=\"bookmark\" title=\"August 30, 2010\">Campus Party 2010 &#8211; Wargame Leftovers winner!</a></li>
</ul>
<p><!-- Similar Posts took 32.813 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=856" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2010/08/02/campus-party-2010-wargame-leftovers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Historias de la cripta</title>
		<link>http://vierito.es/wordpress/2010/07/10/historias-de-la-cripta/</link>
		<comments>http://vierito.es/wordpress/2010/07/10/historias-de-la-cripta/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 17:20:15 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[criptografía]]></category>
		<category><![CDATA[Curso de Verano de Seguridad]]></category>
		<category><![CDATA[RSA]]></category>
		<category><![CDATA[side channel]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=846</guid>
		<description><![CDATA[El Maligno me lió para dar una charla en el III Curso de Verano de Seguridad en Valencia. El curso ha estado genial, tanto las ponencias como la gente que acudió, sin duda una gran oportunidad para pasar un buen rato con conocidos y nuevas caras. Mi charla la quise enfocar como una recopilación de [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEwLzA3L0hpc3Rvcmlhc19kZV9sYV9jcmlwdGFfc2xpZGUxLnBuZw=="><img class="aligncenter size-medium wp-image-850" title="Historias_de_la_cripta_slide" src="http://vierito.es/wordpress/wp-content/uploads/2010/07/Historias_de_la_cripta_slide1.png" alt="" /></a></p>
<p><a title=\"Chema Alonso\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VsbGFkb2RlbG1hbC5ibG9nc3BvdC5jb20v">El Maligno</a> me lió para dar una charla en el <a title=\"III Curso de Seguridad\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5pbmZvcm1hdGljYTY0LmNvbS9paWljdXJzb3ZlcmFuby8=">III Curso de Verano de Seguridad</a> en Valencia. El curso ha estado genial, tanto las ponencias como la gente que acudió, sin duda una gran oportunidad para pasar un buen rato con conocidos y nuevas caras.</p>
<p>Mi charla la quise enfocar como una recopilación de fallos comunes (algunos de ellos famosos) cuando nos toca tratar con criptografía. Es un tema un poco denso así que para darle un toque más curioso y divertido en la parte final incluí puntos decisivos a la hora de implementar criptografía en dispositivos embebidos en los que, debido a factores como el <em>side channel</em>, tenemos que tener en cuenta todo tipo de nuevas medidas.</p>
<p>Gracias a <a title=\"Eloi Sanfèlix\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5saW1pdGVkLWVudHJvcHkuY29tLw==">Eloi</a> y <a title=\"kuasar\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2t1YXNhci5lcy9ibG9nLw==">Bea</a> por echarme una mano <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Aquí os dejo la presentación de <a title=\"Historia de la cripta - Javi Moreno\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvSGlzdG9yaWFzX2RlX2xhX2NyaXB0YV8tX0phdmlfTW9yZW5vLnBkZg==">Historias de la cripta</a></p>
<p>Si tenéis dudas o preguntas podéis dejar comentarios aquí o usar twitter con el tag #cripta.</p>
<p>Keep hacking!<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDYvMTEvY3VhbmRvLW5vLXNlLXRpZW5lLWN1aWRhZG8tY29uLWxhLWNyaXB0b2dyYWZpYS8=" rel=\"bookmark\" title=\"June 11, 2009\">Cuando no se tiene cuidado con la criptografía&#8230;</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDQvMjkvY29uZmVyZW5jaWEtc29icmUtY3JpcHRvZ3JhZmlhLXktcmV0by8=" rel=\"bookmark\" title=\"April 29, 2009\">Conferencia sobre criptografía y reto</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDUvMDkvZ2FuYWRvcmVzLWRlbC1yZXRvLWRlLWNyaXB0b2dyYWZpYS8=" rel=\"bookmark\" title=\"May 9, 2009\">Ganadores del reto de criptografía</a></li>
</ul>
<p><!-- Similar Posts took 5.257 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=846" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2010/07/10/historias-de-la-cripta/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crypto04 challenge write-up from Campus Party Europe</title>
		<link>http://vierito.es/wordpress/2010/04/19/crypto04-challenge-write-up-from-campus-party-europe/</link>
		<comments>http://vierito.es/wordpress/2010/04/19/crypto04-challenge-write-up-from-campus-party-europe/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 23:01:20 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[campus party europe]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[fault injection]]></category>
		<category><![CDATA[glitching]]></category>
		<category><![CDATA[RSA]]></category>
		<category><![CDATA[RSA-CRT]]></category>
		<category><![CDATA[Sage]]></category>
		<category><![CDATA[wargame]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=800</guid>
		<description><![CDATA[Hey there! I usually write in spanish here but as the attendance at Campus Party Europe was pretty international I&#8217;ll do this one in english so anyone can understand it. All the information to try the challenge is at Eloi&#8217;s blog since he released it as challenge a couple of days ago. Before continuing I [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEwLzA0L0NhbXB1cy1QYXJ0eS1FdXJvcGUtTG9nby5qcGc="><img class="size-full wp-image-813   aligncenter" title="Campus-Party-Europe-Logo" src="http://vierito.es/wordpress/wp-content/uploads/2010/04/Campus-Party-Europe-Logo.jpg" alt="" width="250" height="119" /></a></p>
<p>Hey there! I usually write in spanish here but as the attendance at Campus Party Europe was pretty international I&#8217;ll do this one in english so anyone can understand it.</p>
<p>All the information to <a title=\"CP Europe Wargame Crypto04\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5saW1pdGVkLWVudHJvcHkuY29tL2NwZXUtd2FyZ2FtZS1jcnlwdG80">try the challenge</a> is at Eloi&#8217;s blog since he released it as challenge a couple of days ago. Before continuing I guess you either have played in the hacking contest at Campus Party Europe or already have read that post, if not&#8230; you are being late!</p>
<p>So, we receive 3 files: an AES encrypted file, a  public key file and a readme with some instructions and data.</p>
<p>From the readme, this are some hints to understand what&#8217;s going on here:</p>
<ul>
<li>It uses a cryptographic device that contains a 1024 bit modular exponentiation accelerator</li>
<li>A pair of RSA signatures over the same data, one of these signatures contains a fault injection</li>
</ul>
<p>From those hints we get that it is actually using the RSA-CRT algorithm, which is a RSA variation to reduce computational costs using the Chinese Remainder Theorem. The point is that instead of using the 2048 bit modular exponentation it splits them into two modular operations, aproximately half the size, make the calculations and then recombine the results as needed to obtain the regular RSA result. But here&#8217;s the trick, if we inject a fault in one of these two exponentiations, via power glitching for example, there&#8217;s a way to recover the private RSA key. The use of RSA-CRT is common in embedded devices such as smart cards, mainly because of the hardware limitations. You can read a post about it at Eloi&#8217;s blog, it&#8217;s in spanish though: <a title=\"RSA-CRT Fault Injection\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5saW1pdGVkLWVudHJvcHkuY29tL2ZhdWx0LWluamVjdGlvbi1hdGFxdWUtYS1yc2EtY3J0">RSA-CRT Fault Injection</a>.</p>
<p>RSA signs a message doing:</p>
<ul>
<li> s = m^d (mod n)</li>
</ul>
<p>RSA-CRT does:</p>
<ul>
<li>s1 = m^dq (mod q)</li>
<li>s2 = m^dp (mod p)</li>
<li>s = a*s1 + b*s2  (mod n) = m^d (mod n)</li>
<li>a being congruent to one modulo p and zero modulo q</li>
<li>b being congruent to zero modulo p and one modulo q</li>
</ul>
<p>Using the faulty signatures:</p>
<ul>
<li>s &#8211; s&#8217; = a*s1 &#8211; a*s1&#8242; will be congruent to zero modulo q</li>
<li>s &#8211; s&#8217; = b*s2 &#8211; b*s2&#8242; will not be congruent to zero modulo p</li>
</ul>
<p><span id="more-800"></span></p>
<p>Then if we calculate the greatest common divisor (using the <a title=\"Euclidean Algorithm\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9FdWNsaWRlYW5fYWxnb3JpdGht">Euclidean algorithm</a> for example) between c-c&#8217; and n ¡we will obtain the factor q! because c-c&#8217; is multiple of q but not p. Then with p = n / q we will have both prime factors used in RSA <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Now we have to implement the attack, we need to deal with really big integers so I first though of using Java and its BigInteger, Matlab or Sage. I do hate Java, Matlab would have been nice, usually it treats big integers as arrays and uses proper algorithms adapted to array calculations but Sage was going to be the easiest and quickest for me.</p>
<p>We have s1, s2 and the encrypted message. First we need to obtain the exponent and the modulus from the public.key file, let&#8217;s use openssl:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl rsa <span style="color: #660033;">-pubin</span> <span style="color: #660033;">-text</span> <span style="color: #660033;">-in</span> public.key
Modulus <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2048</span> bit<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
00:e8:<span style="color: #000000;">52</span>:<span style="color: #000000;">42</span>:<span style="color: #000000;">77</span>:0a:<span style="color: #000000;">66</span>:<span style="color: #000000;">69</span>:8c:<span style="color: #000000;">64</span>:<span style="color: #000000;">49</span>:<span style="color: #000000;">61</span>:5a:d4:8f:
<span style="color: #000000;">70</span>:e5:ff:7f:<span style="color: #000000;">49</span>:ca:<span style="color: #000000;">45</span>:<span style="color: #000000;">33</span>:<span style="color: #000000;">43</span>:7d:<span style="color: #000000;">85</span>:<span style="color: #000000;">36</span>:7e:1a:f3:
8f:<span style="color: #000000;">31</span>:aa:<span style="color: #000000;">35</span>:<span style="color: #000000;">94</span>:8e:b3:3f:<span style="color: #000000;">97</span>:<span style="color: #000000;">88</span>:f7:<span style="color: #000000;">16</span>:4a:1d:d5:
c3:<span style="color: #000000;">87</span>:5b:f8:6b:<span style="color: #000000;">69</span>:3b:d8:<span style="color: #c20cb9; font-weight: bold;">cc</span>:<span style="color: #000000;">82</span>:e2:cb:cb:d0:1c:
f7:d1:b4:<span style="color: #000000;">51</span>:ef:<span style="color: #000000;">67</span>:cb:<span style="color: #000000;">72</span>:<span style="color: #000000;">90</span>:fa:<span style="color: #000000;">79</span>:0e:e1:02:<span style="color: #000000;">24</span>:
e3:<span style="color: #000000;">72</span>:5b:<span style="color: #000000;">37</span>:b6:<span style="color: #c20cb9; font-weight: bold;">bc</span>:3d:<span style="color: #000000;">53</span>:<span style="color: #000000;">56</span>:da:9d:0f:ba:c1:e0:
6b:b2:6f:f2:<span style="color: #000000;">43</span>:03:d9:06:d3:c9:<span style="color: #000000;">66</span>:c8:1b:<span style="color: #000000;">19</span>:9a:
<span style="color: #000000;">78</span>:b9:ef:02:2b:0f:b9:<span style="color: #000000;">28</span>:e5:<span style="color: #000000;">82</span>:<span style="color: #7a0874; font-weight: bold;">fc</span>:0c:e0:<span style="color: #000000;">29</span>:<span style="color: #000000;">57</span>:
f6:b1:<span style="color: #000000;">64</span>:<span style="color: #000000;">21</span>:01:f9:2e:<span style="color: #000000;">83</span>:4a:ab:<span style="color: #000000;">47</span>:<span style="color: #000000;">24</span>:9e:e4:08:
c2:<span style="color: #000000;">91</span>:d3:<span style="color: #7a0874; font-weight: bold;">fc</span>:e8:<span style="color: #000000;">72</span>:c1:<span style="color: #000000;">44</span>:<span style="color: #000000;">69</span>:<span style="color: #000000;">12</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">37</span>:f4:da:<span style="color: #000000;">49</span>:
<span style="color: #000000;">28</span>:00:<span style="color: #000000;">75</span>:03:<span style="color: #000000;">36</span>:<span style="color: #000000;">47</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">69</span>:f4:e2:4b:4a:0e:3e:e5:
<span style="color: #000000;">15</span>:<span style="color: #000000;">85</span>:ae:<span style="color: #000000;">78</span>:<span style="color: #000000;">68</span>:<span style="color: #000000;">43</span>:a3:c0:<span style="color: #000000;">39</span>:<span style="color: #000000;">61</span>:c2:<span style="color: #000000;">12</span>:a1:e3:<span style="color: #000000;">94</span>:
d2:<span style="color: #000000;">71</span>:e8:<span style="color: #000000;">26</span>:<span style="color: #000000;">14</span>:c4:e7:aa:1d:5d:a4:<span style="color: #000000;">16</span>:01:1f:9b:
<span style="color: #000000;">40</span>:<span style="color: #000000;">81</span>:a8:e4:<span style="color: #000000;">70</span>:<span style="color: #000000;">65</span>:<span style="color: #000000;">75</span>:1a:de:de:<span style="color: #000000;">51</span>:d0:<span style="color: #000000;">90</span>:<span style="color: #000000;">97</span>:fb:
8a:<span style="color: #000000;">41</span>:ac:be:2e:<span style="color: #000000;">54</span>:5c:b6:d4:04:<span style="color: #000000;">40</span>:1d:<span style="color: #000000;">59</span>:<span style="color: #000000;">16</span>:c3:
f6:<span style="color: #000000;">86</span>:<span style="color: #000000;">16</span>:e9:<span style="color: #000000;">66</span>:<span style="color: #000000;">79</span>:b3:5f:<span style="color: #000000;">77</span>:<span style="color: #000000;">74</span>:a9:e4:<span style="color: #000000;">42</span>:b1:<span style="color: #000000;">98</span>:
<span style="color: #000000;">74</span>:<span style="color: #000000;">14</span>:b0:<span style="color: #000000;">22</span>:ee:06:f0:0f:ac:3d:<span style="color: #c20cb9; font-weight: bold;">dd</span>:b6:<span style="color: #000000;">14</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">43</span>:
e5:<span style="color: #000000;">53</span>
Exponent: <span style="color: #000000;">65537</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x10001<span style="color: #7a0874; font-weight: bold;">&#41;</span>
writing RSA key
<span style="color: #660033;">-----BEGIN</span> PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6FJCdwpmaYxkSWFa1I9w
5f9<span style="color: #000000; font-weight: bold;">/</span>ScpFM0N9hTZ+GvOPMao1lI6zP5eI9xZKHdXDh1v4a2k72MyC4svL0Bz30bRR
72fLcpD6eQ7hAiTjcls3trw9U1banQ+6weBrsm<span style="color: #000000; font-weight: bold;">/</span>yQwPZBtPJZsgbGZp4ue8CKw+<span style="color: #000000;">5</span>
KOWC<span style="color: #000000; font-weight: bold;">/</span>AzgKVf2sWQhAfkug0qrRySe5AjCkdP86HLBRGkSMTf02kkoAHUDNkcgafTi
S0oOPuUVha54aEOjwDlhwhKh45TScegmFMTnqh1dpBYBH5tAgajkcGV1Gt7eUdCQ
l<span style="color: #000000; font-weight: bold;">/</span>uKQay+LlRcttQEQB1ZFsP2hhbpZnmzX3d0qeRCsZh0FLAi7gbwD6w93bYUGUPl
UwIDAQAB
<span style="color: #660033;">-----END</span> PUBLIC KEY-----</pre></div></div>

<p>To copy the modulus it&#8217;s easier from here:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl rsa <span style="color: #660033;">-pubin</span> <span style="color: #660033;">-modulus</span> <span style="color: #660033;">-in</span> public.key
<span style="color: #007800;">Modulus</span>=E85242770A66698C6449615AD48F70E5FF7F49CA4533437D85367E1AF38F31AA35948EB33F9788F7164A1DD5C3875BF86B693BD8CC82E2CBCBD01CF7D1B451EF67CB7290FA790EE10224E3725B37B6BC3D5356DA9D0FBAC1E06BB26FF24303D906D3C966C81B199A78B9EF022B0FB928E582FC0CE02957F6B1642101F92E834AAB47249EE408C291D3FCE872C14469123137F4DA492800750336472069F4E24B4A0E3EE51585AE786843A3C03961C212A1E394D271E82614C4E7AA1D5DA416011F9B4081A8E47065751ADEDE51D09097FB8A41ACBE2E545CB6D404401D5916C3F68616E96679B35F7774A9E442B1987414B022EE06F00FAC3DDDB6141943E553
writing RSA key
<span style="color: #660033;">-----BEGIN</span> PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6FJCdwpmaYxkSWFa1I9w
5f9<span style="color: #000000; font-weight: bold;">/</span>ScpFM0N9hTZ+GvOPMao1lI6zP5eI9xZKHdXDh1v4a2k72MyC4svL0Bz30bRR
72fLcpD6eQ7hAiTjcls3trw9U1banQ+6weBrsm<span style="color: #000000; font-weight: bold;">/</span>yQwPZBtPJZsgbGZp4ue8CKw+<span style="color: #000000;">5</span>
KOWC<span style="color: #000000; font-weight: bold;">/</span>AzgKVf2sWQhAfkug0qrRySe5AjCkdP86HLBRGkSMTf02kkoAHUDNkcgafTi
S0oOPuUVha54aEOjwDlhwhKh45TScegmFMTnqh1dpBYBH5tAgajkcGV1Gt7eUdCQ
l<span style="color: #000000; font-weight: bold;">/</span>uKQay+LlRcttQEQB1ZFsP2hhbpZnmzX3d0qeRCsZh0FLAi7gbwD6w93bYUGUPl
UwIDAQAB
<span style="color: #660033;">-----END</span> PUBLIC KEY-----</pre></div></div>

<p>Now we have the modulus and exponent. So let&#8217;s start Sage and apply what we&#8217;ve seen before <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Load the values:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sage: s1 = 0x3ae81964c8ecf1524b47c42cb0ecd2a3b6768dccd55960d7ff0a998f839b8c312a2cd821c270ae961777dd4dd50aa631fe823a8afd914911adf69c1c6cfda3b3aed01dad372cfdd6e9f63a4cc39e1a455cbfd04dea72bf07c4790d5fec469198ce28113d6d38a7baced9d3c3695ab27cbc5ab434aa8d2b5f53f66a383e079ddaed485d4a2b446e410eafcadbba9f159494c28c4a19fd416dff90f8c141e96d8260f8e6e0901832e31899c48ce0cbdae6a24595a19a01e490c87e7b48860e09006920d8ef7384217358c6db90638d6e8cbc795a091240f24105d8f3b27fe4b98fe9a507e00590b4cded41777b1b8967b0f752231e0e856b8f0132bde30a6e082e
sage: s2 = 0x391e0340e5931a202012572ddacad877e5af3a1d846b70c1e64e3041f9ac0a3c7e8f82621df908eadca44fe777a6b1c799610be829e13ca233982fd268034addb5a79fa19f984631fdf3a61d32fc75ed77176c7a0b719504e804076dca66f10111aa124a7efe743ada75dda2ec53f3c28882a7724928685918261739f960a3648aa3eadc426181aa146a8ba0ff20f1c53de2113e0196af09595dc2ad1a0fe12096ff681f61363044615a7f72edf1f8c6531055e66c1e5f4498434c731d2308fecae46c779379ea3d7d7a5f1c2a0efeb5bc1b8a4af4fb21fce1dae943c27043e86642b3b1e6b889a31e7c4bc01bc2ebae4dc8432344532567d1d3df8b9bcafcbf
sage: encrypted = 0x19303a82cbc50a56dc22f9aafc554da2ea632e33bee1d33c35edb13269ba0fd2fa791744e86eda7fc1cb15433f1232f86a42afcd5470215ccf0d05096ce1b8f075e6dc45df74896345297fcc145a4765aeaea78babaa6441ead3a2e73b37931dc7c07d4e04b7115284c7c04c85a61c7e555194d0f4ee762d47a8aeec2efcd75ee45e3e6a65f876f9a67aa01016f3ce9552d8f0b50cc150c70333aa6ac3a4ac8860d2879cad8439566f0ffda32612cb75dd9c1b456a4e1828582f05932f495452f19d71f300f2f48b8c1f8cde1b1b8d8ada3f6ff506e10d5d18d91d61402bc36756a88196381ff795980eee932a179525264e3a968f0abe9edbe672560c41833a
sage: exponent = 0x10001
sage: modulus = 0xe85242770a66698c6449615ad48f70e5ff7f49ca4533437d85367e1af38f31aa35948eb33f9788f7164a1dd5c3875bf86b693bd8cc82e2cbcbd01cf7d1b451ef67cb7290fa790ee10224e3725b37b6bc3d5356da9d0fbac1e06bb26ff24303d906d3c966c81b199a78b9ef022b0fb928e582fc0ce02957f6b1642101f92e834aab47249ee408c291d3fce872c14469123137f4da492800750336472069f4e24b4a0e3ee51585ae786843a3c03961c212a1e394d271e82614c4e7aa1d5da416011f9b4081a8e47065751adede51d09097fb8a41acbe2e545cb6d404401d5916c3f68616e96679b35f7774a9e442b1987414b022ee06f00fac3dddb6141943e553</pre></div></div>

<p>Calculate q and p:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sage: q = gcd<span style="color: black;">&#40;</span>s1-s2,modulus<span style="color: black;">&#41;</span>
sage: p = modulus / q</pre></div></div>

<p>In Sage to work with modular arithmetics you need to declare a group and then use the variables in that group. First let&#8217;s calculate the private RSA key</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sage: G1 = IntegerModRing<span style="color: black;">&#40;</span>lcm<span style="color: black;">&#40;</span>q-<span style="color: #ff4500;">1</span>,p-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
sage: private_key = G1<span style="color: black;">&#40;</span>exponent<span style="color: black;">&#41;</span>^-<span style="color: #ff4500;">1</span></pre></div></div>

<p>And finally working in modulo &#8216;modulus&#8217; make the decryption to get the message:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sage: G2 = IntegerModRing<span style="color: black;">&#40;</span>modulus<span style="color: black;">&#41;</span>
sage: message = G2<span style="color: black;">&#40;</span>encrypted<span style="color: black;">&#41;</span>^G2<span style="color: black;">&#40;</span>private_key<span style="color: black;">&#41;</span>
sage: message
<span style="color: #ff4500;">333277202522695828352578908493424296965</span>
sage: <span style="color: #008000;">hex</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">333277202522695828352578908493424296965</span><span style="color: black;">&#41;</span>
<span style="color: #483d8b;">'fabadababecafedeadbeef0102030405'</span></pre></div></div>

<p>It&#8217;s a <a title=\"Fabada!\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2ZvdG9zLm11bmRvcmVjZXRhcy5uZXQvYWxidW1zL3VzZXJwaWNzLzExNDE2L2ZhYmFkYS4ufjAuSlBH">fabada</a> password! xD We now have the plaintext which is the AES key. Let&#8217;s use again openssl to decipher the file. The readme file says it&#8217;s AES in ECB mode with a 128 bit key. The key length it&#8217;s obvious but if we didn&#8217;t know the operation mode we could just try them all.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl enc <span style="color: #660033;">-d</span> <span style="color: #660033;">-aes-128-ecb</span> <span style="color: #660033;">-in</span> encrypted.aes <span style="color: #660033;">-out</span> unencrypted.file <span style="color: #660033;">-K</span> fabadababecafedeadbeef0102030405
$ <span style="color: #c20cb9; font-weight: bold;">file</span> unencrypted.file
unencrypted.file: PNG image, <span style="color: #000000;">124</span> x <span style="color: #000000;">124</span>, <span style="color: #000000;">8</span>-bit<span style="color: #000000; font-weight: bold;">/</span>color RGB, non-interlaced</pre></div></div>

<p>We can see that it worked like a charm: the file it&#8217;s a PNG image. The first thing you think when you see a PNG it&#8217;s uhmm&#8230; a bit of stego? thumbnails? LSB? Well, this one is just a QR Code.</p>
<p style="text-align: center;"><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEwLzA0L2ZvdG8ucG5n"><img class="size-full wp-image-809 aligncenter" title="foto" src="http://vierito.es/wordpress/wp-content/uploads/2010/04/foto.png" alt="" width="124" height="124" /></a></p>
<p>Using any QR decoder (I used <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3p4aW5nLm9yZy93L2RlY29kZS5qc3B4">http://zxing.org/w/decode.jspx</a> ) we get:</p>
<pre>Key: DoubleCheckYourCryptoResults</pre>
<p>Which is a funny final password since one of the common protections against fault injection attacks is to double-check all sensitive computations</p>
<p>Congratulations to <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2xpbWl0ZWQtZW50cm9weS5jb20=">Eloi</a> for this challenge! I found it one of best I&#8217;ve ever done because it has to do with real world attacks and crypto related maths, so it&#8217;s not just another cryptic puzzle where mostly you only have to use tools or need a smart guess.</p>
<p>I hope you liked it! <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Many thanks also to <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NlY3VyaXR5YnlkZWZhdWx0LmNvbQ==">SecurityByDefault</a> for an excelent wargame and congratulations to the winners:</p>
<ol>
<li>knx</li>
<li>FluxReiners</li>
<li>aw3a</li>
</ol>
<p><br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTEvMDEvMjIvYnJlYWtpbmctbGZzci1iYXNlZC1wc2V1ZG8tcmFuZG9tLW51bWJlci1nZW5lcmF0b3JzLw==" rel=\"bookmark\" title=\"January 22, 2011\">Breaking LFSR-based pseudo-random number generators</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDgvMjgvY3JhY2tlYWRvci1kZS1oYXNoZXMtbWQ1LWVuLWMteS1vcGVuc3NsLw==" rel=\"bookmark\" title=\"August 28, 2009\">Crackeador de hashes MD5 en C y OpenSSL</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTIvMjQvMjVjMy1ub3RoaW5nLXRvLWhpZGUv" rel=\"bookmark\" title=\"December 24, 2008\">25C3: Nothing to Hide</a></li>
</ul>
<p><!-- Similar Posts took 6.112 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=800" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2010/04/19/crypto04-challenge-write-up-from-campus-party-europe/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Descodificar tonos DTMF usando Matlab</title>
		<link>http://vierito.es/wordpress/2009/11/25/descodificar-tonos-dtmf-usando-matlab/</link>
		<comments>http://vierito.es/wordpress/2009/11/25/descodificar-tonos-dtmf-usando-matlab/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 01:16:50 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[DTMF]]></category>
		<category><![CDATA[FFT]]></category>
		<category><![CDATA[Fourier]]></category>
		<category><![CDATA[Matlab]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=710</guid>
		<description><![CDATA[Ya vimos como crear tonos DTMF usando Matlab y han pedido en un par de comentarios [1] [2] cómo se haría a la inversa, así que aquí va He cogido el script para generar los tonos del otro post y lo he cambiado para los pitidos duren 40ms (que se resume a cambiar que use [...]]]></description>
			<content:encoded><![CDATA[<p>Ya vimos como <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDEvMTUvbGxhbWFuZG8tcG9yLXRlbGVmb25vLWNvbi1tYXRsYWIv">crear tonos DTMF usando Matlab</a> y han pedido en un par de comentarios [<a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDEvMTUvbGxhbWFuZG8tcG9yLXRlbGVmb25vLWNvbi1tYXRsYWIvI2NvbW1lbnQtOTIw">1</a>] [<a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDEvMTUvbGxhbWFuZG8tcG9yLXRlbGVmb25vLWNvbi1tYXRsYWIvI2NvbW1lbnQtMTA5OQ==">2</a>] cómo se haría a la inversa, así que aquí va <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>He cogido el script para generar los tonos del otro post y lo he cambiado para los pitidos duren 40ms (que se resume a cambiar que use 320 muestras en lugar de 1200 para cada pitido o silencio), para que sea un poco más real. El wav que voy a usar será el siguiente: <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL3Jpbmcud2F2">ring.wav</a></p>
<p>Empezamos, ¿qué necesitamos? Cada pitido estará compuesto por una pareja de tonos así que para saber qué número es deberemos reconocer las dos frecuencias principales que tienen los pitidos, y conocer la frecuencia viene a ser lo mismo que saber el periodo.</p>
<p>Hace un tiempo hice una práctica de Tratamiento Digital de la Señal en la que se hacían cosas de estas, uno de los códigos no es mío, está indicado. El resto los hicimos <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21vdW5zdHJ1b2RlbGFzZ2FsbGV0YXMuYmxvZ3Nwb3QuY29t">Rafa</a> y yo en su día.</p>
<p>Aprovechándonos de la Transformada de Fourier:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>P,f<span style="color: #080;">&#93;</span>=periodograma<span style="color: #080;">&#40;</span>x,N<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">% [P f]=periodograma(x,N)</span>
<span style="color: #228B22;">% Calcula N muestras del periodograma de las muestras en x</span>
<span style="color: #228B22;">% N debe ser &gt; que length(x)</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% P: Periodograma propiamente</span>
<span style="color: #228B22;">% f frecuencias correspondientes</span>
&nbsp;
k=<span style="color: #33f;">0</span>:N-<span style="color: #33f;">1</span>;
f=k./N;
&nbsp;
L=<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>;
P=<span style="color: #33f;">1</span>/L*<span style="color: #080;">&#40;</span><span style="color: #0000FF;">fft</span><span style="color: #080;">&#40;</span>x,N<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>.^<span style="color: #33f;">2</span>;</pre></div></div>

<p>Pero lo propio será usar un programa que use <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9XaW5kb3dfZnVuY3Rpb24=">ventanas</a>  para su propósito:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>P,f<span style="color: #080;">&#93;</span>=periodmodif<span style="color: #080;">&#40;</span>x,ventana,N<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">% [P ,f]=periodmodif(x,ventana,N)</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% Calcula N muestras del periodograma modificado de las muestras en x</span>
<span style="color: #228B22;">% N debe ser &gt; que length(x)</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% P: Periodograma propiamente</span>
<span style="color: #228B22;">% f frecuencias correspondientes</span>
&nbsp;
<span style="color: #0000FF;">if</span> N &lt;= <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'N debe ser &gt; que length(x)'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">else</span>
   k=<span style="color: #33f;">0</span>:N-<span style="color: #33f;">1</span>;
   f=k./N;
&nbsp;
   L=<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>;
   m=<span style="color: #33f;">0</span>:L-<span style="color: #33f;">1</span>;
&nbsp;
   U=<span style="color: #33f;">1</span>/L*<span style="color: #080;">&#40;</span><span style="color: #0000FF;">sum</span><span style="color: #080;">&#40;</span>ventana<span style="color: #080;">&#40;</span>m+<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.^<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
   P=<span style="color: #33f;">1</span>/<span style="color: #080;">&#40;</span>L*U<span style="color: #080;">&#41;</span>*<span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">fft</span><span style="color: #080;">&#40;</span>x.*ventana,N<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>.^<span style="color: #33f;">2</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p>Cargamos el fichero <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL3Jpbmcud2F2">ring.wav</a></p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #080;">&#91;</span>x,fs,nbits<span style="color: #080;">&#93;</span>= <span style="color: #0000FF;">wavread</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'ring.wav'</span><span style="color: #080;">&#41;</span>
&gt;&gt; t=<span style="color: #33f;">0</span>:<span style="color: #33f;">1</span>/fs:<span style="color: #33f;">1</span>/fs*<span style="color: #080;">&#40;</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span></pre></div></div>

<p><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL3JpbmcucG5n"><img src="http://vierito.es/wordpress/wp-content/uploads/2009/11/ring-480x360.png" alt="ring" title="ring" width="480" height="360" class="aligncenter size-medium wp-image-719" /></a></p>
<p>Ahora tendremos que calcular de cuanto es nuestra ventana mínima. La separación mínima entre tonos es de 320 muestras (que además en este caso es la misma entre todos los tonos) luego la frecuencia digital será 320 / fs = 320/8000 = 0.04</p>
<p>Y aquí un poco de teoría sobre ventanas gracias a los <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3VzZXJzLmFsbGllZG1vZHMubmV0L35mYWx1Y28vYXB1bnRlc3Bhay8=">Apuntes de Pak</a>:</p>
<p><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL3ZlbnRhbmFzX0xURFNfcGFrLlBORw=="><img src="http://vierito.es/wordpress/wp-content/uploads/2009/11/ventanas_LTDS_pak.PNG" alt="ventanas_LTDS_pak" title="ventanas_LTDS_pak" width="463" height="548" class="aligncenter size-full wp-image-720" /></a></p>
<p>Pero no voy a aburriros con ella así que nos quedaremos en que vamos a usar una ventana tipo Hamming, luego necesitaremos una longitud de ventana L = 4 / resolución = 4 / 0.04 = 100 muestras</p>
<p>Ahora vamos a determinar los dígitos, y para ello vamos a hacer uso de la siguiente función para búscar máximos:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> p=buscapicosu<span style="color: #080;">&#40;</span>x,umbral<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%posi_picos=buscapicosu(x,umbral)</span>
<span style="color: #228B22;">% Busca los máximos locales de un vector mayores que un cierto umbral</span>
<span style="color: #228B22;">% umbral se expresa en % respecto al valor máximo del vector.</span>
<span style="color: #228B22;">% Ej. buscapicos(x,60) buscaria los picos mayores o iguales al 60% del</span>
<span style="color: #228B22;">% pico más alto</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% posi_picos son los indices del vector de entrada correspondientes a los picos.</span>
&nbsp;
<span style="color: #228B22;">% (C) Antonio Albiol , 2003</span>
&nbsp;
<span style="color: #228B22;">%Primero descarto los valores menores que el umbral</span>
&nbsp;
umbral=<span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#40;</span>:<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>*umbral/<span style="color: #33f;">100</span>;
&nbsp;
x=x.*<span style="color: #080;">&#40;</span>x&gt;umbral<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%Ahora buscaré los máximos</span>
&nbsp;
<span style="color: #228B22;">%Primero creo un vector con dos valores muy pequeños en los extremos</span>
xe=<span style="color: #080;">&#91;</span>-<span style="color: #0000FF;">inf</span>;x<span style="color: #080;">&#40;</span>:<span style="color: #080;">&#41;</span>;-<span style="color: #0000FF;">inf</span><span style="color: #080;">&#93;</span>;
&nbsp;
<span style="color: #228B22;">%Ahora calculo la derivada</span>
d1=<span style="color: #0000FF;">diff</span><span style="color: #080;">&#40;</span>xe<span style="color: #080;">&#41;</span>;
ld1=<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>d1<span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">%Ahora busco valores de la derivada de signo diferente consecutivos y que sean máximos</span>
p=<span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sign</span><span style="color: #080;">&#40;</span>d1<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>:ld1<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>.*<span style="color: #0000FF;">sign</span><span style="color: #080;">&#40;</span>d1<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #080;">&#40;</span>ld1-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>&lt;<span style="color: #33f;">0</span> &amp; <span style="color: #0000FF;">sign</span><span style="color: #080;">&#40;</span>d1<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:ld1-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>&gt;<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Cada pitido y cada silencio dura 320 muestras luego calculamos periodos en esas zonas. Vamos a por el primer dígito, con ventana Hamming de 100 y usando 1024 puntos:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #080;">&#91;</span>P,f<span style="color: #080;">&#93;</span>=periodmodif<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#40;</span><span style="color: #33f;">320</span>:<span style="color: #33f;">320</span>+<span style="color: #33f;">99</span><span style="color: #080;">&#41;</span>,hamming<span style="color: #080;">&#40;</span><span style="color: #33f;">100</span><span style="color: #080;">&#41;</span>,<span style="color: #33f;">1024</span><span style="color: #080;">&#41;</span>;
&gt;&gt; buscapicosu<span style="color: #080;">&#40;</span><span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span>P<span style="color: #080;">&#41;</span>,<span style="color: #33f;">50</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
   <span style="color: #33f;">110</span>
   <span style="color: #33f;">190</span>
   <span style="color: #33f;">836</span>
   <span style="color: #33f;">916</span></pre></div></div>

<p>En el espectro digital, de 0 a 1, veremos que las frecuencias se repiten en espejo a partir de 0.5. Luego la frecuencia 110 se corresponde con la 916, igualmente ocurre entre la de 190 y 836, son lo mismo. Así que sólo tenemos que ver a qué corresponden 110 y 190.</p>
<p>Nota a tener en cuenta: en las FFTs (Fast Fourier Transforms) el cálculo se hace mucho más rapido cuando N es una potencia de 2, por eso la elección de hacerlo en 1024 puntos no ha sido del todo al azar.</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #33f;">110</span>/<span style="color: #33f;">1024</span>*fs
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
  <span style="color: #33f;">859.3750</span>
&nbsp;
&gt;&gt; <span style="color: #33f;">190</span>/<span style="color: #33f;">1024</span>*fs
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
  1.4844e+003</pre></div></div>

<p>Nos vamos a la tablita y vemos con qué 2 valores más cercanos concuerdan 859.375 y 1484.4 Hz. Claramente sería con 852 y 1477 Hz que juntos corresponden con el dígito 9.</p>
<p><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzExL2R0bWYxLnBuZw=="><img src="http://vierito.es/wordpress/wp-content/uploads/2009/11/dtmf1.png" alt="dtmf1" title="dtmf1" width="485" height="189" class="aligncenter size-full wp-image-722" /></a></p>
<p>Y así con cada uno de los dígitos <img src='http://vierito.es/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Sé que estaría mucho mejor un script que hiciera todo el proceso entero y obtuviera qué número es de la tabla pero últimamente necesito días de 30 horas así os tendréis que conformar con esto. ¿A qué número he llamado?<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDEvMTUvbGxhbWFuZG8tcG9yLXRlbGVmb25vLWNvbi1tYXRsYWIv" rel=\"bookmark\" title=\"January 15, 2009\">Llamando por teléfono con Matlab</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDgvMTAvY3Vlc3Rpb24tZGUtb3B0aW1pemFjaW9uLw==" rel=\"bookmark\" title=\"August 10, 2009\">Cuestión de optimización</a></li>
</ul>
<p><!-- Similar Posts took 4.896 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=710" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/11/25/descodificar-tonos-dtmf-usando-matlab/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
<enclosure url="http://vierito.es/wordpress/wp-content/uploads/2009/11/ring.wav" length="12204" type="audio/x-wav" />
		</item>
		<item>
		<title>Port-Knocking y Crypt-Port-Knocking</title>
		<link>http://vierito.es/wordpress/2009/09/25/port-knocking-y-crypt-port-knocking/</link>
		<comments>http://vierito.es/wordpress/2009/09/25/port-knocking-y-crypt-port-knocking/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 16:28:05 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Crypt Port Knocking]]></category>
		<category><![CDATA[hping]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[Port Knocking]]></category>
		<category><![CDATA[Replay Attack]]></category>
		<category><![CDATA[Single Packet Authentication]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=687</guid>
		<description><![CDATA[Estaba curioseando por foros de Gentoo cuando me encontré un post interesante sobre una evolución del clásico Port-Knocking,  pero vayamos por pasos. Port-Knocking Cuando nosotros tenemos un servicio en un servidor, éste, escucha en uno o varios puertos las peticiones externas. Este puerto deberá estar abierto en el firewall para que se puedan efectuar estas [...]]]></description>
			<content:encoded><![CDATA[<p>Estaba curioseando por <a title=\"Gentoo Forums\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2ZvcnVtcy5nZW50b28ub3JnLw==">foros de Gentoo</a> cuando me encontré un post interesante sobre una <a title=\"Crytp Port Knocking\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2ZvcnVtcy5nZW50b28ub3JnL3ZpZXd0b3BpYy10LTY4Nzk1Ni5odG1s">evolución del clásico Port-Knocking</a>,  pero vayamos por pasos.</p>
<h3><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzA5L3ByaXNvbi5qcGc="></a></h3>
<p style="text-align: center;"><img class="size-full wp-image-688  aligncenter" title="prison" src="http://vierito.es/wordpress/wp-content/uploads/2009/09/prison.jpg" alt="prison" width="470" height="300" /></p>
<h2>Port-Knocking</h2>
<p>Cuando nosotros tenemos un servicio en un servidor, éste, escucha en uno o varios puertos las peticiones externas. Este puerto deberá estar abierto en el firewall para que se puedan efectuar estas conexiones. La idea del <strong>Port Knocking</strong> es que el puerto del servicio permanece cerrado y <strong>sólo se abrirá bajo una petición externa basada en un paquete o grupo de paquetes específicos</strong>, previamente conocidos por el cliente, que serán enviados al servidor. Es decir, yo tendría mi servidor ssh con el puerto 22 cerrado y cuando un cliente envíe un paquete con ciertas características a otro puerto entonces el puerto 22 se abriría temporalmente para ese cliente. De este modo permanecería <strong>escondido</strong> antes escaneos de puertos e intentos automatizados de fuerza bruta, por ejemplo. Este sistema se podría ir mejorando:</p>
<ul>
<li>que tenga que ser <strong>una secuencia</strong> de puertos y no uno sólo</li>
<li>que además tengan que ser unos <strong>puertos de origen específicos</strong></li>
<li>combinarlo con otras herramientas: <strong>Portsentry</strong>, denyhost, fail2ban (destaco la primera herramienta  ya que es una forma fácil de banear intentos de escaneos sin el uso de un IDS completo ni cortafuegos)</li>
<li>jugar con las FLAGs TCP y opciones poco comunes de los paquetes</li>
<li><strong>abrir el puerto sólo para la IP llamante</strong>, no todas</li>
<li>&lt;paranoic&gt;requerir una <strong>temporización</strong> determinada (algo elástica, claro está) entre en el envío de los paquetes&lt;/paranoic&gt;</li>
<li>y mil cosas que se nos puedan ocurrir</li>
</ul>
<p><span id="more-687"></span></p>
<p>Para estos menesteres existen varias herramientas pero todo suelen terminar siendo scripts que escuchan los puertos y van cambiando reglas del cortafuegos y los servicios. Pero no todo es bonito e ideal, imaginad que no tienes una <em>puerta trasera</em>, ¿qué ocurre si cae el servicio encargado de escuchar el portknocking? Te quedas tú sin poder acceder. Deberías dejarte una <em>IP blanca</em> por ejemplo, que siempre tuviera acceso al puerto sin mayor barrera. O tener otro servicio que compruebe si el primer servicio está online y haga de watchdog xD.</p>
<p>Pero ¿cuál es la debilidad clave un sistema así? <strong>Replay Attack</strong>. Me explico, si mi máquina está en una subred y otra máquina de esa subred ha sido comprometida, ésta podría estar usando un sniffer (tcpdump, wireshark) y capturar la secuencia usada para la apertura de puertos. Y aquí es donde entra lo que he venido a contar.</p>
<h2>Crypt-Port-Knocking</h2>
<p>Vamos a cortar por lo sano esa debilidad: <strong>Single Packet Authentication</strong>. Esta manera de proceder difiere en que vamos a llamar a un <strong>puerto aleatorio cada vez</strong> y la conexión con el servicio también se hará en un puerto aleatorio cada vez pero lo que es más importante añadiremos i<strong>nformación cifrada</strong> en el paquete gracias a <strong>OpenSSL</strong> con lo que se quiera hacer (en este caso usando <span>256-bit AES-cbc, se podría mejorar para ultraparanoicos™  usando un cifrado asimétrico</span> con GPG, por ejemplo). Podríamos pensar que para evitar ataques replay en la información cifrada se podría incluir datos variantes en el tiempo, cambios preacordados de la clave de cifrado, usar iteraciones en una función de hashing pero se complica el tema cuando hay muchos usuarios. Para ello, es mejor opción aprovechar que podemos tener 16bytes de datos aleatorios en el paquete que luego podemos identificar gracias a un hash del mismo e ignorar todos los paquetes duplicados. Para crear los paquetes a medida podremos usar <strong>hping</strong>.</p>
<p>Para hacer uso de las características del Single Packet Authentication el autor del post, BoneKracker, ha creado una serie de <strong>scripts en bash</strong>, formados por un cliente y un servidor de una forma bastante clara y transparente. <a title=\"Crytp Port Knocking\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2ZvcnVtcy5nZW50b28ub3JnL3ZpZXd0b3BpYy10LTY4Nzk1Ni5odG1s">Echadle un vistazo</a> que ahí está todo el código y con una explicación más extensa.<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTEvMjEvcGFyYS1sb3MtYW1hbnRlcy1kZS14a2NkLWxsZWdhLw==" rel=\"bookmark\" title=\"November 21, 2008\">Para los amantes de XKCD llega&#8230;</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDgvMTAvY3Vlc3Rpb24tZGUtb3B0aW1pemFjaW9uLw==" rel=\"bookmark\" title=\"August 10, 2009\">Cuestión de optimización</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDgvMjgvY3JhY2tlYWRvci1kZS1oYXNoZXMtbWQ1LWVuLWMteS1vcGVuc3NsLw==" rel=\"bookmark\" title=\"August 28, 2009\">Crackeador de hashes MD5 en C y OpenSSL</a></li>
</ul>
<p><!-- Similar Posts took 7.824 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=687" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/09/25/port-knocking-y-crypt-port-knocking/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Crackeador de hashes MD5 en C y OpenSSL</title>
		<link>http://vierito.es/wordpress/2009/08/28/crackeador-de-hashes-md5-en-c-y-openssl/</link>
		<comments>http://vierito.es/wordpress/2009/08/28/crackeador-de-hashes-md5-en-c-y-openssl/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 11:43:03 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[crackeador]]></category>
		<category><![CDATA[cracker]]></category>
		<category><![CDATA[cracking]]></category>
		<category><![CDATA[criptografía]]></category>
		<category><![CDATA[diccionario]]></category>
		<category><![CDATA[EVP_DigestInit]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[password cracking]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=642</guid>
		<description><![CDATA[Un hash es una función criptográfica de tipo resumen cuyo objetivo es identificar casi unívocamente un conjunto de datos. Pretende ser una función inyectiva, es decir, que para una salida (valor imagen) solo exista una entrada (valor origen) pero debido a que su salida está limitada en tamaño es posible que para entradas diferentes existan [...]]]></description>
			<content:encoded><![CDATA[<p>Un hash es una función criptográfica de tipo resumen cuyo objetivo es identificar <em>casi unívocamente</em> un conjunto de datos. Pretende ser una función inyectiva, es decir, que para una salida (valor imagen) solo exista una entrada (valor origen) pero debido a que su salida está limitada en tamaño es posible que para entradas diferentes existan claves resultantes iguales. Eso sería una colisión y una función hash deberá tener una salida pequeña equilibrada con su resistencia a colisiones. MD5 tiene una salida fija de 128 bits, lo que vienen siendo 32 dígitos en hexadecimal.</p>
<p>Primero de todo vamos a hacer un programa que nos permita calcular el hash md5 de un string que se le pase y luego ya pasaremos al crackeador.</p>
<p>Sería más fácil hacer un script en bash o perl gracias a la utilidad CLI de OpenSSL, a la hora de calcular un solo hash no importa mucho la velocidad pero si luego queremos hacer un pequeño crackeador no podemos partir de algo que ya sabemos que va a ser mucho más lento. Así que lo que vamos a usar es C y la librería de OpenSSL.</p>
<p>Si no sabemos por donde empezar un extracto del man:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ man md5
...
<span style="color: #202020;">SYNOPSIS</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/md2.h&gt;</span>
&nbsp;
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>MD5<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>d<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> n<span style="color: #339933;">,</span>
                         <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>md<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #993333;">int</span> MD5_Init<span style="color: #009900;">&#40;</span>MD5_CTX <span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> MD5_Update<span style="color: #009900;">&#40;</span>MD5_CTX <span style="color: #339933;">*</span>c<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>data<span style="color: #339933;">,</span>
                         <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> MD5_Final<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>md<span style="color: #339933;">,</span> MD5_CTX <span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #202020;">DESCRIPTION</span>
...
<span style="color: #202020;">Applications</span> should use the higher level functions EVP_DigestInit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> etc. <span style="color: #202020;">instead</span> of calling the hash functions directly.
...</pre></div></div>

<p><span id="more-642"></span><br />
Vemos que podríamos añadir esa librería y usar las funciones MD5_Init(), MD5_Update y MD5_Final pero ya nos avisan que deberíamos usar unas funciones de más alto nivel así que: <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5vcGVuc3NsLm9yZy9kb2NzL2NyeXB0by9FVlBfRGlnZXN0SW5pdC5odG1s">EVP_DigestInit</a></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ man EVP_DigestInit
...
<span style="color: #202020;">SYNOPSIS</span>
        <span style="color: #339933;">#include &lt;openssl/evp.h&gt;</span>
&nbsp;
        <span style="color: #993333;">void</span> EVP_MD_CTX_init<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        EVP_MD_CTX <span style="color: #339933;">*</span>EVP_MD_CTX_create<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #993333;">int</span> EVP_DigestInit_ex<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> EVP_MD <span style="color: #339933;">*</span>type<span style="color: #339933;">,</span> ENGINE <span style="color: #339933;">*</span>impl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> EVP_DigestUpdate<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>d<span style="color: #339933;">,</span> size_t cnt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> EVP_DigestFinal_ex<span style="color: #009900;">&#40;</span>EVP_MD_CTX <span style="color: #339933;">*</span>ctx<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>md<span style="color: #339933;">,</span>
               <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>De paso, aprovecho para desaconsejar el uso de MD5 a día de hoy y como mínimo usar SHA1 o incluso dejarte de monsergas y pasar a SHA256, SHA512.</p>
<p>He intentado que el programa sea bastante fácil de entender y seguir, ahí va:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/evp.h&gt;</span>
&nbsp;
<span style="color: #339933;">#ifdef DEBUG</span>
<span style="color: #339933;">#define DBG 1</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#define DBG 0</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#define MAX_SIZE_WORD 200</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>simple_digest<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>algth<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> len<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>olen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	EVP_MD <span style="color: #339933;">*</span>m<span style="color: #339933;">;</span>
	EVP_MD_CTX ctx<span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ret<span style="color: #339933;">;</span>
&nbsp;
	OpenSSL_add_all_digests <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EVP_MD<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> EVP_get_digestbyname<span style="color: #009900;">&#40;</span>algth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>EVP_MAX_MD_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	EVP_DigestInit<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestUpdate<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestFinal<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> ret<span style="color: #339933;">,</span> olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> hex_print<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buff<span style="color: #339933;">,</span><span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%02x&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&amp;</span><span style="color: #208080;">0xFF</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buff<span style="color: #009900;">&#91;</span>MAX_SIZE_WORD<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> olen<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: mymd5 word<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// copy arg string into a buffer</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> MAX_SIZE_WORD <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		strncpy<span style="color: #009900;">&#40;</span>buff<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// calculate string's md5 hash</span>
		out <span style="color: #339933;">=</span> simple_digest<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;md5&quot;</span><span style="color: #339933;">,</span>buff<span style="color: #339933;">,</span>strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,&amp;</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// print results	</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Word: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hash: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		hex_print<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Not computing hash<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>I can feel your dark side... ;)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compilamos y probamos:</p>
<pre>$ gcc mymd5.c -o mymd5 -l ssl
$ ./mymd5 passworddeelite
5b4f50aa173b977e4cd0850cf7c52bd0</pre>
<p>Podemos comprobar su correcto funcionamiento comparando con webs online que ofrecen utilidades para calcular hashes MD5 [<a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5taXJhY2xlc2FsYWQuY29tL3dlYnRvb2xzL21kNS5waHA=">1</a>], [<a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21kNS1oYXNoLW9ubGluZS53YXJheGUudXMv">2</a>].</p>
<p>Y ahora a por el crackeador. No vamos a intentar buscar colisiones sino a partir de un diccionario sacar la clave. Le pasaremos como parámetros un fichero con el hash y un diccionario con una palabra por línea.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/evp.h&gt;</span>
&nbsp;
<span style="color: #339933;">#ifdef DEBUG</span>
<span style="color: #339933;">#define DBG 1</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#define DBG 0</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#define MAX_SIZE_BUFF 200</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>simple_digest<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>algth<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> len<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>olen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	EVP_MD <span style="color: #339933;">*</span>m<span style="color: #339933;">;</span>
	EVP_MD_CTX ctx<span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ret<span style="color: #339933;">;</span>
&nbsp;
	OpenSSL_add_all_digests <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EVP_MD<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> EVP_get_digestbyname<span style="color: #009900;">&#40;</span>algth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>EVP_MAX_MD_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	EVP_DigestInit<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestUpdate<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EVP_DigestFinal<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ctx<span style="color: #339933;">,</span> ret<span style="color: #339933;">,</span> olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> hex_print<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buff<span style="color: #339933;">,</span><span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%02x&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&amp;</span><span style="color: #208080;">0xFF</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> strtohex<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>in<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">,</span><span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>in<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>in<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		out<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>strtol<span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span>NULL<span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #993333;">int</span> tries<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buff_words<span style="color: #009900;">&#91;</span>MAX_SIZE_BUFF<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> hash<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>line<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> len<span style="color: #339933;">=</span><span style="color: #0000dd;">100</span><span style="color: #339933;">,</span>read<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> olen<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>out<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: mymd5crack /path/to/hashfile /path/to/dictfile<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	FILE <span style="color: #339933;">*</span>hashfile<span style="color: #339933;">;</span>
	hashfile <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>hashfile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	FILE <span style="color: #339933;">*</span>dictfile<span style="color: #339933;">;</span>
	dictfile <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>dictfile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	read <span style="color: #339933;">=</span> getline<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>line<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>len<span style="color: #339933;">,</span> hashfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000dd;">33</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;ERROR: Invalid hash length %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	strtohex<span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span>hash<span style="color: #339933;">,</span><span style="color: #0000dd;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Input hash: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Input buffer from hash: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			hex_print<span style="color: #009900;">&#40;</span>hash<span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Read words in a loop</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>read <span style="color: #339933;">=</span> getline<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>line<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>len<span style="color: #339933;">,</span> dictfile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			tries<span style="color: #339933;">++;</span>	
&nbsp;
			<span style="color: #666666; font-style: italic;">//Copy word into buffer</span>
			strcpy<span style="color: #009900;">&#40;</span>buff_words<span style="color: #339933;">,</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span>
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Input buffer from dict: %s <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>buff_words<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// compute md5</span>
			out <span style="color: #339933;">=</span> simple_digest<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;md5&quot;</span><span style="color: #339933;">,</span>buff_words<span style="color: #339933;">,</span>strlen<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,&amp;</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>DBG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;For password %s MD5 is: &quot;</span><span style="color: #339933;">,</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				hex_print<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span>olen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//Compare computed md5 with hash</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>memcmp<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span>hash<span style="color: #339933;">,</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PASSWORD FOUND!! in %d tries: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>tries<span style="color: #339933;">,</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				fclose<span style="color: #009900;">&#40;</span>hashfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				fclose<span style="color: #009900;">&#40;</span>dictfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				free<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span>
					free<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>	
			<span style="color: #009900;">&#125;</span>
			free<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Words from dict too long... cough*, cough*...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Password not found in %d tries!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>tries<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span>
		free<span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fclose<span style="color: #009900;">&#40;</span>hashfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fclose<span style="color: #009900;">&#40;</span>dictfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y comprobamos su funcionamiento metiendo en /tmp/hash el hash obtenido anteriormente:</p>
<pre>$ gcc mymd5cracker.c -o mymd5cracker -l ssl
$ ./mymd5cracker /tmp/hash /tmp/dict
PASSWORD FOUND!! in 6 tries: passworddeelite</pre>
<p>Premio! Podéis ir en paz.</p>
<p>Para descargar <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzA4L215bWQ1LmM=">mymd5.c</a> y <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzA4L215bWQ1Y3JhY2tlci5j">mymd5cracker.c</a></p>
<p>Gracias a <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R1eGVkLnNlcnZlYmxvZy5uZXQ=">TuXeD</a> que siempre está ahí para echar una mano.<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDQvMTgvZGVzY2lmcmFuZG8tdW4tcmV0by1kZWwtZmJpLw==" rel=\"bookmark\" title=\"April 18, 2009\">Descifrando un reto del FBI</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDUvMjIvc29sdWNpb25lcy1kZWwtcmV0by1kZS1jcmlwdG9ncmFmaWEtcGFydGUtMi8=" rel=\"bookmark\" title=\"May 22, 2009\">Soluciones del reto de criptografía &#8211; Parte 2</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDkvMjUvcG9ydC1rbm9ja2luZy15LWNyeXB0LXBvcnQta25vY2tpbmcv" rel=\"bookmark\" title=\"September 25, 2009\">Port-Knocking y Crypt-Port-Knocking</a></li>
</ul>
<p><!-- Similar Posts took 14.779 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=642" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/08/28/crackeador-de-hashes-md5-en-c-y-openssl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cuestión de optimización</title>
		<link>http://vierito.es/wordpress/2009/08/10/cuestion-de-optimizacion/</link>
		<comments>http://vierito.es/wordpress/2009/08/10/cuestion-de-optimizacion/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 19:37:54 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Opinión]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[eficiencia]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[optimización]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=255</guid>
		<description><![CDATA[Y es que se ha perdido el romanticismo&#8230; xD A día de hoy contamos con ordenadores chorrecientas veces más rápidos que hace pocos años y cuando se programa haces pruebas con sistemas de 3GHz, varios MB de cache y 2GB de RAM mínimo y todo tira para adelante. Bueno, todo tira hasta cierto punto, tus [...]]]></description>
			<content:encoded><![CDATA[<p>Y es que se ha perdido el romanticismo&#8230; xD</p>
<p>A día de hoy contamos con ordenadores chorrecientas veces más rápidos que hace pocos años y cuando se programa haces pruebas con sistemas de 3GHz, varios MB de cache y 2GB de RAM mínimo y todo tira para adelante. Bueno, todo tira hasta cierto punto, tus programas luego se van a estar ejecutando juntos con otras decenas de programas o simplemente se van a estar ejecutando constantemente y vas a perder un gran porcentaje de la capacidad de proceso de cómo lo podrías estar haciendo.</p>
<p>Bueno, y es normal, cosas de la comodidad, <strong>yo el primero</strong>. Ahora te quedas tranquilo con que funcione, en los 80 tenía que funcionar y caber en 64kB de RAM. No digo que se programe peor (seguramente sí xD) pero ya no nos fijamos en muchos detalles que antes eran totalmente necesarios (la de trucos que usaba la gente para poder aprovechar el 100% del hardware del Commodore64) y ahora desperdiciamos por todos lados y al final <strong>sí que pasa factura</strong>. La gente que programe sistemas embebidos lo tiene muy claro aunque casi se va a acabar el asunto también ahí porque ya los procesadores de los móviles/PDAs/cosas_pequeñas tirán mucho.</p>
<p><span id="more-255"></span></p>
<p>Me he encontrado con programas que están al 100% de CPU en idle, con programas que daban su salida en unos 12~15 minutos cuando otro para el mismo propósito lo hacía en aproximadamente 1 segundo (no daré nombres xD), programas en los que notas el &#8216;refresco&#8217; de los elementos cuando lo usas cuando te sobra CPU para hacerlo bien, etc. Hay que intentar evitar marañas de bucles for anidados!</p>
<p>Al final todo pasa por conocer muy bien el lenguaje que usas, haber pasado horas y horas, pensar las cosas antes de hacerlas, incluso un poquito de sentido común, cosa que creo que es difícil de abstraer a veces cuando se programa.</p>
<p>Por ejemplo, en matlab es muy importante reservar el espacio para las variables antes y crear los vectores del tamaño que van a ser al final de las operaciones porque si aumentamos el tamaño de un vector[n], internamente lo que siempre hace es crear un nuevo vector[n+1] y copiar los datos del antiguo.</p>
<p>Hace unos meses me comentó un amigo que en el trabajo tenían un método númerico que disminuyó su tiempo de ejecución en más de un 20% (siendo su tiempo varias horas) al sustituir un resultado de una operación que siempre era el mismo por el valor guardado en una variable! Es de cajón pero hay que caer.</p>
<p>Y ahora vienen algunos ejemplos, por no meterme en un lenguaje tipo C en el que hay muchas posibilidades de hacer las cosas y hay que currarse más los ejemplo iré a algo más sencillo como es hacer scripts cerdos para administrar un máquinas o similares.</p>
<p>Un ejemplo sería un uso poco adecuado de las órdenes <em>cat, grep, ls, awk</em> y similares. Cuando manipulamos algo pequeño no pasa nada pero cuando se trata de varios ficheros logs y son decenas de MB pues la cosa empieza a tomar importancia.</p>
<p>Respecto a <em>grep</em> cuando una persona empieza y se plantea buscar una cadena lo primero que piensa es &#8216;muestro el archivo y luego saco las líneas coincidentes&#8217;:</p>
<p><code># cat tinyproxy.log | grep remote<br />
real    0m55.071s<br />
user    0m24.477s<br />
sys     0m0.727s</code></p>
<p>Luego descubres que en realidad lo puedes hacer &#8216;todo en uno&#8217; y es bastantes más rápido:</p>
<p><code># grep remote tinyproxy.log<br />
real    0m36.024s<br />
user    0m22.550s<br />
sys     0m0.527s</code></p>
<p>Luego, sin querer, entras en el man y te das cuenta de que existen varios tipos: <em>grep</em>, <em>egrep</em> (similar pero no idéntico a grep -E ) y  <em>fgrep</em> (idéntico a grep -F). Así que pruebas:</p>
<p><code># egrep remote tinyproxy.log<br />
real    0m55.122s<br />
user    0m25.029s<br />
sys     0m0.659s</code></p>
<p>Joder, vuelve a ser lento a pesar de no hacer un cat. ¿Por qué? Porque es una función más compleja.</p>
<ul>
<li>grep: soporta expresiones regulares básicas.</li>
<li>fgrep: no soporta expresiones regulares =&gt; el más rápido.</li>
<li>egrep: soporta expresiones regulares avanzadas =&gt; el más lento.</li>
</ul>
<p>Para los curiosos, el nombre grep viene de g/re/p y significa lo que hace tal cual, buscar una expresión regular y hacer print de las coincidencias. En realidad a una escala grande ni siquiera deberíamos usar <em>grep</em> sino <em>sed</em> que es más rápido.</p>
<p>Lo mucha gente desconoce es que hay otra manera de evitar el <em>cat </em>de antes y ganar tiempo, y es que en realidad las concatenaciones siempre están ahí&#8230; así que lo podríamos hacer del siguiente modo:</p>
<p><code># &lt;tinyproxy.log grep remote<br />
real    0m43.931s<br />
user    0m22.338s<br />
sys     0m0.578s</code></p>
<p>Del mismo modo estos conceptos se puede usar en otras órdenes</p>
<p><code># cat tinyproxy.log | wc -l<br />
104265</code></p>
<p>real    0m0.088s<br />
user    0m0.021s<br />
sys     0m0.053s</p>
<p><code># wc -l tinyproxy.log<br />
104265 tinyproxy.log</code></p>
<p>real    0m0.021s<br />
user    0m0.013s<br />
sys     0m0.006s</p>
<p>Y del mismo modo:</p>
<p><code># cat tinyproxy.log | tail -n 200<br />
real    0m0.121s<br />
user    0m0.026s<br />
sys     0m0.056s</code></p>
<p><code># tail -n 200 tinyproxy.log<br />
real    0m0.010s<br />
user    0m0.000s<br />
sys     0m0.003s</code></p>
<p>Cambiando de tercio también solemos usar <em>echo</em> más veces de las que toca. Por ejemplo si tenemos :</p>
<p><code>var="valor_o_resultado_de_una_evaluacion"<br />
command -options `echo $var`</code></p>
<p>en la mayoría de los casos podremos sustituirlo por:</p>
<p><code>var="valor_o_resultado_de_una_evaluacion"<br />
command -options $var</code></p>
<p>Y así mil chorradas. Por cierto, el que sólo se conozca la opción de awk para coger columnas le recomiendo que se mire manules que termina siendo muy útil.</p>
<p>Creo que este post lleva más de 6 meses en drafts y no he añadido nada (de hecho  tampoco tengo ganas), así que aunque es un tema que da mucho de sí ha quedado bastante descafeinado técnicamente, pero ajo y agua!<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMTEvMjUvZGVzY29kaWZpY2FyLXRvbm9zLWR0bWYtdXNhbmRvLW1hdGxhYi8=" rel=\"bookmark\" title=\"November 25, 2009\">Descodificar tonos DTMF usando Matlab</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDkvMjUvcG9ydC1rbm9ja2luZy15LWNyeXB0LXBvcnQta25vY2tpbmcv" rel=\"bookmark\" title=\"September 25, 2009\">Port-Knocking y Crypt-Port-Knocking</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMTEvMjEvcGFyYS1sb3MtYW1hbnRlcy1kZS14a2NkLWxsZWdhLw==" rel=\"bookmark\" title=\"November 21, 2008\">Para los amantes de XKCD llega&#8230;</a></li>
</ul>
<p><!-- Similar Posts took 6.354 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=255" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/08/10/cuestion-de-optimizacion/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>CFLAGS y libgcrypt</title>
		<link>http://vierito.es/wordpress/2009/06/19/cflags-y-libgcrypt/</link>
		<comments>http://vierito.es/wordpress/2009/06/19/cflags-y-libgcrypt/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 20:21:30 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[CFLAGS]]></category>
		<category><![CDATA[compilar]]></category>
		<category><![CDATA[CXXFLAGS]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[GnuPG]]></category>
		<category><![CDATA[libgcrypt]]></category>
		<category><![CDATA[safe cflags]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=479</guid>
		<description><![CDATA[Ya se sabe, cuando se tiene que &#8220;entregar&#8221; algo a tal hora, un ratito antes empezarán a salir fallos que hagan que no funcione. Cosas de Murphy. Estaba preparando la prueba 12 del reto cuando me encontré con un marrón que me costó darme cuenta 3horas de rayadas mentales diciendo &#8220;no puede ser, ¡si está [...]]]></description>
			<content:encoded><![CDATA[<p>Ya se sabe, cuando se tiene que &#8220;entregar&#8221; algo a tal hora, un ratito antes empezarán a salir fallos que hagan que no funcione. Cosas de Murphy. Estaba preparando la prueba 12 del reto cuando me encontré con un marrón que me costó darme cuenta 3horas de rayadas mentales diciendo &#8220;no puede ser, ¡si está bien!&#8221; Pero antes, una introducción para saber de qué va el asunto: las CFLAGS.</p>
<p><strong>¿Qué son las CFLAGS/CXXFLAGS?</strong></p>
<p>Son unas variables de entorno o unas variables en un Makefile que se le pasan al compilador para que compile el software aplicando un serie de optimizaciones. Herramientas como autoconf las cogerían del entorno para añadirlas a la sentencia que se usa al compilar. Las CFLAGS se usarían en C, y las CXXFLAGS en C++.</p>
<p>Según usemos un set distinto de CFLAGS los binarios de salida que nos dé el compilador podrán ser distintos partiendo de un mismo código fuente. Gracias a ellas podremos adecuar o intentar mejorar características de los binarios, ya sea para que sean más pequeños, más rápidos en ciertas arquitecturas u otras opciones. Para ello se podrán usar instrucciones específicas disponibles un procesador, podremos especificar por ejemplo que se &#8220;desenrrollen&#8221; bucles, etc.</p>
<p>Un ejemplo del primer caso sería usar instrucciones SSE3 disponibles en procesadores actuales pero no disponibles en un Pentium IV de primera generación. Para ello le pasaremos <code>-msse3</code><br />
<span id="more-479"></span></p>
<p>Un ejemplo del segundo caso sería, yo tengo un bucle que se ejecuta 1000 veces. Cogeríamos y, en ensamblador, tenemos un registro que se va decrementando, comprueba si lo ha hecho 1000 veces y si no, hace un salto para ejecutar el bucle de nuevo. Pues vamos a cambiar eso por &#8220;pegar&#8221; consecutivamente el código de dentro del bucle 1000 veces. Con eso nos ahorramos recodificaciones de punteros y cosas similares pero tendremos como inconvenientes que el binario será más grande. ¿Qué se ejecuta más rápido? ¿El código optimizado por no hacer esas recodificaciones o el código inicial porque se tarda menos en cargarlo al ser más pequeño? Eterna pregunta&#8230; pues depende, a veces uno, a veces el otro.</p>
<p>Por comodidad, para que no tener que pasarle 8 lineas de optimizaciones, de las cuales más de una no sabremos lo que hace y que algunas implican o excluyen otras, existen sets de optimizaciones: <code>-O, -O1, -O2, -O3, -Os</code>, etc. Eso es la letro &#8220;o&#8221; mayúscula seguida de un número, más allá del 3 no existe, se usaría -O3.</p>
<p>Por otro lado, a las arquitecturas existentes se les pone un nombre, para que cuando digamos qué arquitectura tiene nuestra máquina el compilador le aplique automáticamente lo que toca: <code>-march=athlon64, -march=pentium2, -march=pentium4, -march=prescott, -march=core2, </code>&#8230; Esta opción dependerá mucho de la versión de GCC que tengamos instalada, ya que dependiendo de lo nueva que sea tendrá soporte para nuevas arquitecturas o no, e incluso para una misma arquitectura dependiendo de si instalas un sistema de 32 o 64bits el nombre cambiará. Además está opción está íntimamente ligada con la variable CHOST que será del estilo: <code>i586-pc-linux-gnu, i686-pc-linux-gnu, x86_64-pc-linux-gnu</code>, etc.</p>
<p>La mayoría de las distribuciones que se usan son precompiladas, Debian/Ubuntu, RedHat, Mandriva, &#8230; y esto no es algo de lo que preocuparse pero esto cobra especialmente sentido en distros como Gentoo y LFS donde todo el código es compilado desde cero con las optimizaciones y opciones que se quieran, ajustadas al tipo de máquina que va a ejecutar el código.</p>
<p>Pero ya se sabe, la gente funciona del modo &#8220;a ver quien la tiene más larga&#8221;. Cuando Gentoo empezó a ganar terreno y adeptos con la versión 1.4  y la 2004 la gente se cascaba unas pedazos de CFLAGS que no tenían ni pies ni cabeza, ¡cuantas más le pase más guay!, ¡más rápido irá! ¡más todo! Estilo pajillero, el foro estaba lleno de hilos de discusión sobre las CFLAGS y que no sé quien se había puesto tales y podía viajar atrás en el tiempo con ellas. En realidad lo único que se consigue es tener como salida un código inestable, que puede funcionar mal y más lento. Por ejemplo, la opción <code>-ffast-math</code> además de no cumplir con el estándar hace que las raices negativas no existan en lugar de devolver números complejos. ¿y si compilamos octave/algo_tipo_matlab con <em>-ffast-math</em>? => fiesta del confeti.</p>
<p>Generalmente se recomienda usar <code>-O2 -pipe -fomit-frame-pointer</code> y poco más. La opción <em>-O3</em> se considera un poco insegura que ya de uvas a peras puede dar problemas. La opción <em>-pipe</em> en realidad no cambia el código de salida, sólo provoca que el compilador use tuberías entre las distintas etapas de una compilación en lugar de usar ficheros temporales, esto aumenta la velocidad de compilación pero puede provocar que en algunos sistemas donde el código ensamblador no pueda recibir de una tubería falle, algo poco común en realidad. La opción <em>-fomit-frame-pointer</em> reduce el tamaño del código bastante pero provoca que la depuración de código sea infinitamente más complicada, además, para gran parte de las arquitecturas, viene activada en el set -O2 así que no necesitaríamos ni ponerla xD</p>
<p>Por poner algunos ejemplos en las máquinas que tengo a mano uso:</p>
<p>AMD Ahtlon 3200+ (2GHz)<br />
<code>CHOST="x86_64-pc-linux-gnu"<br />
CFLAGS="-O2 -march=athlon64 -pipe -fomit-frame-pointer -msse3"</code></p>
<p>Intel Core Duo T2500 (2GHz)<br />
<code>CHOST="i686-pc-linux-gnu"<br />
CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer -msse3"</code></p>
<p>Intel Pentium4 (3.2GHz)<br />
<code>CHOST="i686-pc-linux-gnu"<br />
CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer -msse3"</code></p>
<p>Intel Pentium4 Celeron (2GHz)<br />
<code>CHOST="i686-pc-linux-gnu"<br />
CFLAGS="-O2 -march=i686 -pipe -fomit-frame-pointer"<br />
</code></p>
<p>Vamos, más simple y pobre imposible jejeje. Y ahora viene el tema, resulta que en el Athlon 3200+ de 64bits tenía -O3&#8230; yo ni me acordaba.</p>
<p>Quien no tenga ni amigos ni cosas que hacer que acuda al <code>man gcc</code> y se las estudie todas.</p>
<p><strong>El problema con libgcrypt</strong></p>
<p>Para la prueba 12, creé en mi portátil una par de pares de claves GPG para cifrar con clave asimétrica un mensaje, el objetivo de la prueba era recuperar la clave privada y la passphrase y a continuación descifrarlo. Al principio pensé hacerla más larga y que luego no estuviese enviado por quien decía ser y hubiera que encontrar más cosas pero bueno, lo deje en el primer stage, así que la clave pública del emisor ya no era ni necesaria.</p>
<p>Una vez creadas las clave y cifrado el mensaje procedí a probar que funcionaba&#8230;claro. Así que exporté las claves y las importé en el sobremesa (el Athlon). Procedo a descifrar y:<br />
<code>...<br />
AES-128 test encryption failed.<br />
...</code></p>
<p>Premio, ¿qué habré hecho mal? Venga a probar a importar de nuevo, crear de nuevo las claves, &#8230; Resulta que tenía versiones distintas de GnuPG en cada máquina, ¿afectará? O_o, no debería en absoluto pero bueno, compilo la misma versión, sigue fallando, creo otra vez la claves, me empiezo a desesperar, busco por internet, no encuentro nada, me bajo el código fuente donde sale esa cadena para ser mostrada, me lo empiezo a mirar para ver cuando y por qué sale. No veo nada raro, cambio a otra versión de libgcrypt, recompilo, más de lo mismo, sólo puede ser una cosa, que el algoritmo de AES no esté haciendo lo que toca, pero ¡el mismo código funciona en otra máquina!</p>
<p>Ya desesperadísimo a falta de 20 minutos para que demos comienzo el reto, la prueba 12 no funciona xD, genial. Asumiendo que el código es correcto sin bugs me meto en el make.conf y veo &#8220;<em>-O3</em>&#8220;, uhm, no me jodas, lo cambio por &#8220;<em>-O2</em>&#8221; y recompilo libgcrypt, que es el paquete que contiene la función con dicho código tocapelotas, y recompilo GnuPG, pruebo a descifrar, a la primera ¬¬</p>
<p>De normal cuando un paquete es propenso a funcionar mal por estas razones en el proceso de compilación te avisan de que no uses alguna optimización, éste no era el caso aunque después de lo visto quizá deberían avisarlo. O cambiarlo por <em>-O2</em> sin decir nada.</p>
<p>Así que ya sabéis, KISS (efe eeeeeeeeeeeeeeeeeeeeeeeeemeeeeeeee), <strong>Keep It Simple, Stupid!</strong><br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMDQvMTkvdGhlLW1hY2hpbmVzLw==" rel=\"bookmark\" title=\"April 19, 2008\">The Machines</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDgvMDMvMjgvZGVqYXItYm9uaXRvLXVuLXNlcnZlci1zc2gtcGFydGUtMS8=" rel=\"bookmark\" title=\"March 28, 2008\">Dejar bonito un server SSH &#8211; Parte 1</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDkvMTkvYXJkdWluby1tZWdhLXktbW9kdWxvLXhiZWUtaW5zdGFsYWNpb24tZW4tZ2VudG9vLw==" rel=\"bookmark\" title=\"September 19, 2009\">Arduino MEGA y módulo XBee &#8211; Instalación en gentoo</a></li>
</ul>
<p><!-- Similar Posts took 7.115 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=479" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/06/19/cflags-y-libgcrypt/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Cuando no se tiene cuidado con la criptografía&#8230;</title>
		<link>http://vierito.es/wordpress/2009/06/11/cuando-no-se-tiene-cuidado-con-la-criptografia/</link>
		<comments>http://vierito.es/wordpress/2009/06/11/cuando-no-se-tiene-cuidado-con-la-criptografia/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 23:50:35 +0000</pubDate>
		<dc:creator>vierito5</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[criptografía]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[GPGME]]></category>
		<category><![CDATA[keyczar]]></category>
		<category><![CDATA[Mifare]]></category>
		<category><![CDATA[side channel analysis]]></category>
		<category><![CDATA[timing attack]]></category>
		<category><![CDATA[wii]]></category>

		<guid isPermaLink="false">http://vierito.es/wordpress/?p=462</guid>
		<description><![CDATA[&#8230; puede ocurrir de todo. Cuanta razón tiene Nate Lawson cuando recomienda encarecidamente usar librerías de alto nivel cuando estemos usando criptografía. Ejemplos de ellas son GPGME (GnuPG Made Easy) y Keyczar, de la que hace poco el mismo autor sacó un timing attack de libro, irónicamente xD (para ver de qué va el Side [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; puede ocurrir de todo.</p>
<p style="text-align: center;"><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDA5LzA2L3RpbWluZ19hdHRhY2sucG5n"><img class="size-full wp-image-464 aligncenter" title="Timing Attack, imagen creada por Riscure" src="http://vierito.es/wordpress/wp-content/uploads/2009/06/timing_attack.png" alt="timing_attack" width="480" height="154" /></a></p>
<p>Cuanta razón tiene <a title=\"Rdist\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JkaXN0LnJvb3Qub3JnLzIwMDkvMDYvMTAvd2hlbi1jcnlwdG8tYXR0YWNrcy1zbGlkZXMtcG9zdGVkLw==">Nate Lawson</a> cuando recomienda encarecidamente usar librerías de alto nivel cuando estemos usando criptografía. Ejemplos de ellas son <a title=\"GPGME\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nbnVwZy5vcmcvZ3BnbWUuaHRtbA==">GPGME</a> (GnuPG Made Easy) y <a title=\"Keyczar\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5rZXljemFyLm9yZy8=">Keyczar</a>, de la que hace poco el mismo autor sacó un <a title=\"Timming Attack Keyczar\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JkaXN0LnJvb3Qub3JnLzIwMDkvMDUvMjgvdGltaW5nLWF0dGFjay1pbi1nb29nbGUta2V5Y3phci1saWJyYXJ5Lw==">timing attack de libro</a>, irónicamente xD (para ver de qué va el Side Channel <a title=\"TuXeD\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R1eGVkLnNlcnZlYmxvZy5uZXQ=">TuXeD</a> tiene unos cuantos posts interesantes, entre otros [<a title=\"Side Channel Analysis\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R1eGVkLnNlcnZlYmxvZy5uZXQvYXRhcXVlcy1hLXNtYXJ0LWNhcmRzLXNpZGUtY2hhbm5lbC1hbmFseXNpcy1p">1</a>] [<a title=\"Side Channel Analysis\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R1eGVkLnNlcnZlYmxvZy5uZXQvYXRhcXVlcy1hLXNtYXJ0LWNhcmRzLXNpZGUtY2hhbm5lbC1hbmFseXNpcy1paQ==">2</a>])</p>
<p>Si nos ponemos a buscar cagadas que haya hecho la gente en los últimos años veremos que se tropieza una y otra vez en las mismas piedras. Por eso jamás se deben implementar los algoritmos por nuestra cuenta reinventando la rueda&#8230; mal, y siempre deberemos usar código contrastado y revisado por terceros.</p>
<p>Muy recomendable la siguiente presentación:</p>
<p><a title=\"When Crypto Attacks\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5zbGlkZXNoYXJlLm5ldC9yb290bGFicy93aGVuLWNyeXB0by1hdHRhY2tzLXlhaG9vLTIwMDk=">http://www.slideshare.net/rootlabs/when-crypto-attacks-yahoo-2009</a></p>
<p>En la <a title=\"Conferencia Criptografía 2009\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5pZWVlLnVwdi5lcy9jcmlwdG8vY2hhcmxhL1NsaWRlc19DcmlwdG9fU2VjdXRlbDA5LnBkZg==">conferencia en la UPV (PDF)</a> de hace unas semanas ya lancé ideas sobre estas cosas con metidas de pata gordas, como la de <a title=\"Team Twiizers\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2V2ZW50cy5jY2MuZGUvY29uZ3Jlc3MvMjAwOC9GYWhycGxhbi9ldmVudHMvMjc5OS5lbi5odG1s">Nintendo Wii</a>, la de <a title=\"Karsten Nohl\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2V2ZW50cy5jY2MuZGUvY29uZ3Jlc3MvMjAwNy9GYWhycGxhbi9ldmVudHMvMjM3OC5lbi5odG1s">Mifare</a>, la de <a title=\"PRNG Debian OpenSSL\" href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5tZXRhc3Bsb2l0LmNvbS91c2Vycy9oZG0vdG9vbHMvZGViaWFuLW9wZW5zc2wv">Debian</a>, etc.<br/><br/><i>&#8211;<br/>Fuente original en <a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNz">http://vierito.es/wordpress</a></i><br/><br/><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDUvMjIvc29sdWNpb25lcy1kZWwtcmV0by1kZS1jcmlwdG9ncmFmaWEtcGFydGUtMi8=" rel=\"bookmark\" title=\"May 22, 2009\">Soluciones del reto de criptografía &#8211; Parte 2</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMTAvMDcvMTAvaGlzdG9yaWFzLWRlLWxhLWNyaXB0YS8=" rel=\"bookmark\" title=\"July 10, 2010\">Historias de la cripta</a></li>
<li><a href="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3ZpZXJpdG8uZXMvd29yZHByZXNzLzIwMDkvMDQvMTgvZGVzY2lmcmFuZG8tdW4tcmV0by1kZWwtZmJpLw==" rel=\"bookmark\" title=\"April 18, 2009\">Descifrando un reto del FBI</a></li>
</ul>
<p><!-- Similar Posts took 5.805 ms --></p>
 <img src="http://vierito.es/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=462" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://vierito.es/wordpress/2009/06/11/cuando-no-se-tiene-cuidado-con-la-criptografia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

