WebページのURLと、以下のファイルが与えられた。
An URL of a web page and these files were given:
index.php は、以下の処理をするものだった。
$_FILES['file'] が設定されている場合は、そのファイルをzipファイルとして展開する。$_GET['file'] が設定されている場合は、
realpath 関数で処理した結果が、空でも文字列 flag を含むものでもないかをチェックする。readfile 関数に渡す。
また、Dockerfile より、ファイル /flag.txt が用意されることが読み取れた。
What index.php does is:
$_FILES['file'] is set, unzip the file.$_GET['file'] is set:
realpath to the path and check if the result is not empty nor contains a string flag.readfile with the path.
Also, from the file Dockerfile, I found that there will be a file /flag.txt.
ここで、各関数の以下の性質を用いる。
realpath 関数は、渡されたパス中のシンボリックリンクを展開する。readfile 関数は、読み込むファイルをURLで指定できる。
読み込むファイルのパスとして file:///flag.txt を指定すると、
readfile 関数はこれをURLと解釈してファイル /flag.txt を読みに行く一方、
realpath 関数はこれをディレクトリ file: 内のファイル flag.txt と解釈する。
この flag.txt をシンボリックリンクにしておくことで、realpath の処理結果から文字列 flag を消し、readfile 関数を実行させることができる。
これを実行するため、まずWebページにファイルを送信するための以下のファイルを用意した。
I decided to use these characteristics of the functions:
realpath will expand symbolic links in the given path.readfile accepts an URL as the path of the file to read.
When I specify file:///flag.txt as the path of the file to read,
the functon readfile will treat this as an URL and read the file /flag.txt.
On the other hand, the function realpath will interpret this as the file flag.txt in the directory file:.
We can remove a string flag from the result of the function realpath to have it call the function readfile by preparing this flag.txt as a symbolic link.
To realize this, firstly I created this file for sending files to the web page:
さらに、file_flag.zip を作成した。
Then, I opened file_flag.zip using these connamds:
作成した file_flag.zip を send.html から送信した後、http://65.108.176.76:8200/?file=file:///flag.txt にアクセスすることで、flagが得られた。
I obtained the flag by sending the file file_flag.zip via send.html and accessing http://65.108.176.76:8200/?file=file:///flag.txt after that.