WebページのURLと、ファイル ProgrammersHateProgramming2-sourcecode.php が与えられた。
WebページはProgrammersHateProgrammingと同様に、
文字列を送信して .php で終わるURLのページを作れるものだった。
ファイルからは、入力の文字列から <?php、?>、<?、flag をこの順番で消した後、
さらにcatやlsなどの文字列を消してページを作っているらしいことが読み取れた。
<?php を消した後に flag を消すので、<?php に flag を挟むことで <?php を作らせることができる。
また、passthru は消す対象に含まれておらず、実行するコマンドは文字列を分割することで消されるのを回避できる。
これを踏まえ、<flag?php passthru("l" . "s -al /"); を送信すると、
ルートディレクトリにファイル flag.php があることがわかった。
さらに、 <flag?php passthru("c" . "at /f" . "lag.php"); を送信することで、flagが得られた。
An URL of a web page and a file ProgrammersHateProgramming2-sourcecode.php were given.
The web page was accepting submission of strings and creating pages whose URL ends with .php like one in ProgrammersHateProgramming.
Reading the given file, I found that it first removes <?php, ?>, <?, and flag from the input string in this order,
and then removes strings like cat and ls to create pages.
Since it removes flag after removing <?php, we can have it create <?php by adding flag inside <?php.
Also, passthru was not a subject of removal and we can prevent commands to execute from being deleted by splitting the strings.
Based on this, I sent a string <flag?php passthru("l" . "s -al /"); and found that there is a file flag.php in the root directory.
After that, I obtained the flag by sending a string <flag?php passthru("c" . "at /f" . "lag.php");.