<?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; OpenSSL</title>
	<atom:link href="http://vierito.es/wordpress/tag/openssl/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>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 6.164 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 5.856 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>
	</channel>
</rss>

